finalizeSession method

  1. @override
Future<SecureSession> finalizeSession(
  1. Map<String, dynamic> responseMessage
)
override

Finalizes the session establishment process. Called by the initiator after receiving the response.

Implementation

@override
Future<SecureSession> finalizeSession(Map<String, dynamic> responseMessage) async {
  if (_keyExchange == null) {
    throw StateError('Session not initiated');
  }

  // Parse remote capabilities and negotiation result
  final remoteCapabilities = _negotiator.parseHandshakeMessage(responseMessage);
  final negotiation = responseMessage['negotiation'];

  _negotiationResult = NegotiationResult(
    keyExchange: KeyExchangeAlgorithm.values
        .firstWhere((e) => e.name == negotiation['keyExchange']),
    asymmetric: CryptoAlgorithm.values
        .firstWhere((e) => e.name == negotiation['asymmetric']),
    symmetric: CryptoAlgorithm.values
        .firstWhere((e) => e.name == negotiation['symmetric']),
    localPeerId: 'local',
    remotePeerId: remoteCapabilities.peerId,
    isInitiator: true,
  );

  // Calculate shared secret with responder's public key
  final responderPublicKey = responseMessage['keyExchangeData']['publicKey'];
  _sharedSecret = _keyExchange!.generateSharedSecret(responderPublicKey);

  return _createSecureSession();
}