setup0Response method

Future<SessionData?> setup0Response(
  1. SessionData responseData
)

Implementation

Future<SessionData?> setup0Response(SessionData responseData) async {
  SessionData setupResp = responseData;
  if (setupResp.secVer != SecSchemeVersion.SecScheme1) {
    throw Exception('Invalid sec scheme');
  }
  devicePublicKey = SimplePublicKey(setupResp.sec1.sr0.devicePubkey,
      type: KeyPairType.x25519);
  deviceRandom = Uint8List.fromList(setupResp.sec1.sr0.deviceRandom);

  logger.i('setup0Response:Device public key ${devicePublicKey.toString()}');
  logger.i('setup0Response:Device random ${deviceRandom.toString()}');

  final sharedKey = await algorithm.sharedSecretKey(
      keyPair: clientKey, remotePublicKey: devicePublicKey);

  await sharedKey.extractBytes().then((sharedSecret) async {
    Uint8List sharedKeyBytes;
    logger.i(
        'setup0Response: Shared key calculated: ${sharedSecret.toString()}');
      var sink = Sha256().newHashSink();
      sink.add(utf8.encode(pop));
      sink.close();
      final hash = await sink.hash();
      sharedKeyBytes = _xor(
          Uint8List.fromList(sharedSecret), Uint8List.fromList(hash.bytes));
      logger.i(
          'setup0Response: pop: $pop, hash: ${hash.bytes.toString()} sharedK: ${sharedKeyBytes.toString()}');

    await crypt.init(sharedKeyBytes, deviceRandom);
    logger.i(
        'setup0Response: cipherSecretKey: ${sharedKeyBytes.toString()} cipherNonce: ${deviceRandom.toString()}');
    return setupResp;
  });
  return null;
}