challenge method
Called when the router sends a challenge (CHALLENGE frame).
Implementation
@override
Future<Authenticate> challenge(Extra extra) async {
_ensureUsable();
final generation = ++_attemptGeneration;
await _cancelTaskOnly();
_clearExpectedVerifier();
await AbstractAuthentication.streamAddAwaited<Extra>(
_challengeStreamController,
extra,
);
final helloNonce = _helloNonce;
final authId = _authid;
final serverNonce = extra.nonce;
if (serverNonce == null ||
helloNonce == null ||
serverNonce.length < helloNonce.length ||
!serverNonce.startsWith(helloNonce)) {
throw Exception('Wrong nonce');
}
if (authId == null) throw StateError('SCRAM authid is required');
_validateChallenge(extra);
final authExtra = HashMap<String, Object?>()
..['nonce'] = serverNonce
..['channel_binding'] = null
..['cbind_data'] = null;
final signature = await _createSignatureAsync(
authId,
helloNonce,
extra,
authExtra,
generation,
);
if (_attemptGeneration != generation || _disposed) {
throw const ScramKeyDerivationCancelledException();
}
return Authenticate()
..extra = authExtra
..signature = signature;
}