processFrame20 method

void processFrame20(
  1. UdpAddress? sourceAddress,
  2. Uint8List frame
)

Implementation

void processFrame20(UdpAddress? sourceAddress, Uint8List frame) {
  String localAddress = addressForPublicKey(keyPair.publicKey);
  Uint8List nonce = frame.sublist(8, 8 + 16);
  Uint8List nonceHash = Uint8List.fromList(sha256.convert(nonce).bytes);
  String requestedAddress = utf8.decode(frame.sublist(8 + 16));
  if (requestedAddress != localAddress) {
    return; // This is not my address
  }
  // Send my public key
  Uint8List publicKeyBS = encodePublicKeyToPKIX(keyPair.publicKey);
  Uint8List signature = rsaSign(keyPair.privateKey, nonceHash);
  Uint8List response = Uint8List(0);
  response.addAll(frame.sublist(0, 8));
  response[0] = 0x21;
  response.addAll(nonce);
  response.addAll(signature);
  response.addAll(publicKeyBS);
  sendFrame(sourceAddress, [response], this);
}