Skip to content

Commit

Permalink
possible scram auth more coberage
Browse files Browse the repository at this point in the history
  • Loading branch information
Andris Balodis committed Apr 30, 2021
1 parent 67a38b6 commit acb5d23
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 15 deletions.
3 changes: 1 addition & 2 deletions lib/src/authentication/cryptosign_authentication.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ class CryptosignAuthentication extends AbstractAuthentication {
}
var authenticate = Authenticate();

authenticate.extra = HashMap<String, dynamic>();
authenticate.extra!['channel_binding'] = channelBinding;
authenticate.extra['channel_binding'] = channelBinding;
var binaryChallenge = hexToBin(extra.challenge);
authenticate.signature =
privateKey.sign(binaryChallenge).encode(HexCoder.instance);
Expand Down
8 changes: 4 additions & 4 deletions lib/src/authentication/scram_authentication.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ class ScramAuthentication extends AbstractAuthentication {
var authenticate = Authenticate();

authenticate.extra = HashMap<String, Object>();
authenticate.extra!['nonce'] = extra.nonce;
authenticate.extra!['channel_binding'] = null;
authenticate.extra!['cbind_data'] = null;
authenticate.extra['nonce'] = extra.nonce;
authenticate.extra['channel_binding'] = null;
authenticate.extra['cbind_data'] = null;
if (extra.kdf == KDF_PBKDF2) {
authenticate.signature =
challengePBKDF2(_authid!, _helloNonce!, extra, HashMap<String, dynamic>.from(authenticate.extra!));
challengePBKDF2(_authid!, _helloNonce!, extra, HashMap<String, dynamic>.from(authenticate.extra));
}
if (authenticate.signature == null) {
return Future.error(
Expand Down
2 changes: 1 addition & 1 deletion lib/src/message/authenticate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'message_types.dart';
/// The WAMP Authenticate massage
class Authenticate extends AbstractMessage {
String? signature;
Map<String, dynamic>? extra;
Map<String, dynamic> extra = {};

/// Creates a WAMP Authentication message with a [signature] that was
/// cryptographically created by an authentication method of this package
Expand Down
2 changes: 1 addition & 1 deletion lib/src/serializer/msgpack/serializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class Serializer extends AbstractSerializer {
return Uint8List.fromList([147] +
msgpack_dart.serialize(MessageTypes.CODE_AUTHENTICATE) +
msgpack_dart.serialize(message.signature ?? '') +
msgpack_dart.serialize(message.extra ?? '{}'));
msgpack_dart.serialize(message.extra));
}
if (message is Register) {
return Uint8List.fromList([148] +
Expand Down
6 changes: 3 additions & 3 deletions test/authentication/scram_authentication_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ void main() {
challengeExtra2.nonce = authMethod.helloNonce! + 'nonce';
var authenticate = await authMethod.challenge(challengeExtra2);
expect(authenticate.signature, isNotNull);
expect(authenticate.extra!['nonce'],
expect(authenticate.extra['nonce'],
equals(challengeExtra2.nonce = authMethod.helloNonce! + 'nonce'));
expect(authenticate.extra!['channel_binding'], isNull);
expect(authenticate.extra!['cbind_data'], isNull);
expect(authenticate.extra['channel_binding'], isNull);
expect(authenticate.extra['cbind_data'], isNull);
});
test('timedout challenge', () async {
final authMethod = ScramAuthentication(secret,
Expand Down
3 changes: 1 addition & 2 deletions test/serializer/json/serializer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ void main() {
equals(
'[${MessageTypes.CODE_AUTHENTICATE},"${"someSignature"}",{}]'));
var authenticate = Authenticate.signature('someSignature');
authenticate.extra = HashMap<String, Object>();
authenticate.extra!['nonce'] = 'abc';
authenticate.extra['nonce'] = 'abc';
expect(
serializer.serializeToString(authenticate),
equals(
Expand Down
3 changes: 1 addition & 2 deletions test/serializer/msgpack/serializer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ void main() {
110, 97, 116, 117, 114, 101, 162, 123, 125
])));
var authenticate = Authenticate.signature('someSignature');
authenticate.extra = HashMap<String, Object>();
authenticate.extra!['nonce'] = 'abc';
authenticate.extra['nonce'] = 'abc';
expect(
serializer.serialize(authenticate),
equals(Uint8List.fromList([
Expand Down

0 comments on commit acb5d23

Please sign in to comment.