Skip to content

Commit

Permalink
Fix: encode WAMPCRA signature in base64
Browse files Browse the repository at this point in the history
  • Loading branch information
muzzammilshahid committed May 23, 2024
1 parent 41351c9 commit fac04a5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/src/auth/wampcra.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, dynamic> authExtra) : super(type, authID, authExtra);
WAMPCRAAuthenticator(this._secret, String authID, [Map<String, dynamic>? authExtra]) : super(type, authID, authExtra);

static const String type = "wampcra";
final String _secret;
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/auth/wampcra_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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", () {
Expand Down

0 comments on commit fac04a5

Please sign in to comment.