createSignature method
Calculates the client proof according to the WAMP-SCRAM specs where
authId
is the username that has already been saslpreped with Saslprep.saslprep(input)
and helloNonce
is a randomly generated nonce according
to the WAMP-SCRAM specs. The keylength is 32 according to the WAMP-SCRAM specs
Implementation
String createSignature(String authId, String helloNonce, Extra extra,
HashMap<String, Object?> authExtra) {
if (!_reuseClientKey || _clientKey == null) {
late Uint8List saltedPassword;
if (extra.kdf == kdfPbkdf2) {
saltedPassword = CraAuthentication.deriveKey(
_secret!,
extra.salt == null
? CraAuthentication.defaultKeySalt
: base64.decode(extra.salt!),
iterations: extra.iterations!,
keylen: defaultKeyLength);
} else if (extra.kdf == kdfArgon) {
saltedPassword = Uint8List(32);
Argon2BytesGenerator()
..init(Argon2Parameters(Argon2Parameters.ARGON2_id,
Uint8List.fromList(base64.decode(extra.salt!)),
desiredKeyLength: defaultKeyLength,
iterations: extra.iterations ?? 1000,
memory: extra.memory ?? 100,
version: Argon2Parameters.ARGON2_VERSION_13))
..deriveKey(
Uint8List.fromList(_secret!.codeUnits), 0, saltedPassword, 0);
}
_clientKey = CraAuthentication.encodeByteHmac(
saltedPassword, defaultKeyLength, 'Client Key'.codeUnits);
if (!_firstClientKeyCompleter.isCompleted) {
_firstClientKeyCompleter.complete(_clientKey);
}
}
var storedKey = SHA256Digest().process(Uint8List.fromList(_clientKey!));
var clientSignature = CraAuthentication.encodeByteHmac(
storedKey,
defaultKeyLength,
createAuthMessage(authId, helloNonce, authExtra, extra).codeUnits);
var signature = [
for (int i = 0; i < _clientKey!.length; i++)
_clientKey![i] ^ clientSignature[i]
];
return base64.encode(signature);
}