challenge method

  1. @override
Future<Authenticate> challenge(
  1. Extra? extra
)
override

This method is called by the session if the router returns the challenge or the challenges extra respectively. This method proceeds the cra authentication process and creates an authentication message according to the wamp specification

Implementation

@override
Future<Authenticate> challenge(Extra? extra) {
  var authenticate = Authenticate();
  if (extra == null || extra.challenge == null) {
    final error = Error(MessageTypes.codeChallenge, -1,
        HashMap<String, Object>(), Error.authorizationFailed);
    error.details['reason'] =
        'No challenge or secret given, wrong router response';
    return Future.error(error);
  }

  Uint8List key;
  if (extra.salt == null) {
    key = Uint8List.fromList(secret.codeUnits);
  } else {
    key = deriveKey(secret, extra.salt!.codeUnits,
        iterations: extra.iterations == null || extra.iterations! <= 0
            ? defaultIterations
            : extra.iterations!,
        keylen: extra.keyLen == null || extra.keyLen! <= 0
            ? defaultKeyLength
            : extra.keyLen!);
  }

  authenticate.signature = encodeHmac(
      Uint8List.fromList(base64.encode(key).codeUnits),
      extra.keyLen == null || extra.keyLen! <= 0
          ? defaultKeyLength
          : extra.keyLen!,
      Uint8List.fromList(extra.challenge!.codeUnits));
  return Future.value(authenticate);
}