diff --git a/lib/src/auth/wampcra.dart b/lib/src/auth/wampcra.dart index e48b9aa..beff6e3 100644 --- a/lib/src/auth/wampcra.dart +++ b/lib/src/auth/wampcra.dart @@ -7,7 +7,7 @@ import "package:wampproto/messages.dart"; import "package:wampproto/src/auth/auth.dart"; class WAMPCRAAuthenticator extends IClientAuthenticator { - WAMPCRAAuthenticator(this._secret, String authID, Map authExtra) : super(type, authID, authExtra); + WAMPCRAAuthenticator(this._secret, String authID, [Map? authExtra]) : super(type, authID, authExtra); static const String type = "wampcra"; final String _secret; @@ -47,7 +47,8 @@ String generateWampCRAChallenge(int sessionID, String authID, String authRole, S } String signWampCRAChallenge(String challenge, Uint8List key) { - return Hmac(sha256, key).convert(utf8.encode(challenge)).toString(); + final signature = Hmac(sha256, key).convert(utf8.encode(challenge)); + return base64.encode(signature.bytes); } bool verifyWampCRASignature(String signature, String challenge, Uint8List key) { diff --git a/test/auth/wampcra_test.dart b/test/auth/wampcra_test.dart index 5a027c0..48d8cff 100644 --- a/test/auth/wampcra_test.dart +++ b/test/auth/wampcra_test.dart @@ -9,7 +9,7 @@ void main() { const craChallenge = '{"nonce":"cdcb3b12d56e12825be99f38f55ba43f","authprovider":"provider","authid":"foo",' '"authrole":"admin","authmethod":"wampcra","session":123,"timestamp":"2024-05-07T09:25:13.307Z"}'; const key = "6d9b906ad60d1f4dd796dbadcc2e2252310565ccdc6fe10b289df5684faf2a46"; - const validSignature = "0c854bddb2acfc48bdd5e4326339f352a12c893997ef4e413445ee89c3698bc0"; + const validSignature = "DIVL3bKs/Ei91eQyYznzUqEsiTmX705BNEXuicNpi8A="; group("WAMPCRAAuthenticator", () { test("authenticate", () {