finalizeSession method
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.findByName(negotiation['asymmetric'])!,
symmetric: CryptoAlgorithm.findByName(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();
}