handleMSG_KEXDH_REPLY method

void handleMSG_KEXDH_REPLY(
  1. int packetId,
  2. Uint8List packet
)

Implementation

void handleMSG_KEXDH_REPLY(int packetId, Uint8List packet) {
  if (state != SSHTransportState.FIRST_KEXREPLY &&
      state != SSHTransportState.KEXREPLY) {
    throw FormatException('$hostport: unexpected state $state');
  }
  if (guessedS && !guessedRightS) {
    guessedS = false;
    if (print != null) {
      print('$hostport: server guessed wrong, ignoring packet');
    }
    return;
  }

  Uint8List fingerprint;
  if (packetId == MSG_KEX_ECDH_REPLY.ID &&
      KEX.x25519DiffieHellman(kexMethod)) {
    fingerprint = handleX25519MSG_KEX_ECDH_REPLY(
            MSG_KEX_ECDH_REPLY()..deserialize(packetS)) ??
        fingerprint;
  } else if (packetId == MSG_KEXDH_REPLY.ID &&
      KEX.ellipticCurveDiffieHellman(kexMethod)) {
    fingerprint = handleEcDhMSG_KEX_ECDH_REPLY(
            MSG_KEX_ECDH_REPLY()..deserialize(packetS)) ??
        fingerprint;
  } else if (packetId == MSG_KEXDH_REPLY.ID &&
      KEX.diffieHellmanGroupExchange(kexMethod)) {
    handleDhGroupMSG_KEX_DH_GEX_GROUP(
        MSG_KEX_DH_GEX_GROUP()..deserialize(packetS));
    return;
  } else {
    fingerprint =
        handleDhMSG_KEXDH_REPLY(MSG_KEXDH_REPLY()..deserialize(packetS)) ??
            fingerprint;
  }

  if (state == SSHTransportState.FIRST_KEXREPLY) {
    if (acceptHostFingerprint != null) {
      acceptedHostkey = acceptHostFingerprint(hostkeyType, fingerprint);
    } else {
      acceptedHostkey = true;
    }
  }

  sendNewKeys();
}