Skip to content

Commit

Permalink
This is a minor refactoring on existing SCRAMSHA1AuthMechanism.
Browse files Browse the repository at this point in the history
Common logic is moved to a new parent class SCRAMSHAAuthMechanism. Descendant classes SCRAMSHA1AuthMechanism and SCRAMSHA256AuthMechanism only customize the hash function to use.

This PR doesn't implement the handshake mentioned in pharo-nosql#87.
  • Loading branch information
Jose San Leandro committed Dec 22, 2020
1 parent 79cb81f commit 6bccf51
Show file tree
Hide file tree
Showing 30 changed files with 99 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
description
^ 'Challenge Response'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
isAbstract
^ false
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
description
^ self subclassResponsibility
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
isAbstract
^ true
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
description
^ 'No authentication'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
isAbstract
^ false
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
operations
authenticateUsername: user password: pass forcedDatabase: aDatabase
11 changes: 11 additions & 0 deletions mc/Mongo-Core.package/NoAuthMechanism.class/properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"commentStamp" : "",
"super" : "MongoAuthMechanism",
"category" : "Mongo-Core-Auth",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [ ],
"name" : "NoAuthMechanism",
"type" : "normal"
}
1 change: 1 addition & 0 deletions mc/Mongo-Core.package/SCRAMAuthMechanism.class/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I implement SCRAM-SHA1 auth mechanism
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
authenticateAgainstAdmin
overrideDB := true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
testing
isAbstract
^ true
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authenticateUsername: username password: password forcedDatabase: database
firstBare := 'n=' , username , ',r=' , nonce.
op := OrderedIdentityDictionary new
add: #saslStart -> 1;
add: #mechanism -> 'SCRAM-SHA-1';
add: #mechanism -> self mechanismName;
add: #payload -> ('n,,' , firstBare) asByteArray;
add: #autoAuthorize -> 1;
yourself.
Expand All @@ -21,16 +21,16 @@ authenticateUsername: username password: password forcedDatabase: database
ifFalse: [ ^ false "Server returned an invalid nonce." ].
without_proof := 'c=biws,r=' , rnonce.
derivedKey := PBKDF2 new
hashFunction: SHA1;
hashFunction: self hashFunction;
password: (self digestUsername: username password: password);
salt: salt base64Decoded;
iterations: iterations asInteger;
length: 20;
deriveKey.
clientKey := (HMAC on: SHA1 new)
clientKey := (HMAC on: self hashFunction new)
key: derivedKey;
digestMessage: 'Client Key'.
storedKey := SHA1 hashMessage: clientKey.
storedKey := self hashFunction hashMessage: clientKey.
authMsg := ','
join:
{firstBare.
Expand All @@ -53,10 +53,10 @@ authenticateUsername: username password: password forcedDatabase: database
on: MongoCommandError
do: [ ^ false ].
parsed := self parseScramResponse: (resp at: #payload).
serverKey := (HMAC on: SHA1 new)
serverKey := (HMAC on: self hashFunction new)
key: derivedKey;
digestMessage: 'Server Key'.
serverSig := ((HMAC on: SHA1 new)
serverSig := ((HMAC on: self hashFunction new)
key: serverKey;
digestMessage: authMsg) base64Encoded.
(parsed at: #v) = serverSig
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
operations
hashFunction
^ self subclassResponsibility
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
operations
mechanismName
^ self subclassResponsibility
11 changes: 11 additions & 0 deletions mc/Mongo-Core.package/SCRAMAuthMechanism.class/properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"commentStamp" : "mikefilonov 6/11/2017 12:24",
"super" : "MongoAuthMechanism",
"category" : "Mongo-Core-Auth",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [ ],
"name" : "SCRAMAuthMechanism",
"type" : "normal"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
I implement the SCRAM-SHA1 authentication mechanism.

See: https://docs.mongodb.com/v4.0/core/security-scram/
See: https://docs.mongodb.com/v4.0/core/security-scram/
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
description
^ 'SCRAM-SHA-1'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
isAbstract
^ false
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
operations
hashFunction
^ SHA1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
operations
mechanismName
^ 'SCRAM-SHA-1'
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"commentStamp" : "MartinDias 10/23/2020 07:50",
"super" : "MongoAuthMechanism",
"super" : "SCRAMAuthMechanism",
"category" : "Mongo-Core-Auth",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [ ],
"name" : "SCRAMSHA1AuthMechanism",
"type" : "normal"
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
description
^ 'SCRAM-SHA-256'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
isAbstract
^ false
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
operations
hashFunction
^ SHA256
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
operations
mechanismName
^ 'SCRAM-SHA-256'
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"commentStamp" : "",
"super" : "SCRAMAuthMechanism",
"category" : "Mongo-Core-Auth",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [ ],
"name" : "SCRAMSHA256AuthMechanism",
"type" : "normal"
}

0 comments on commit 6bccf51

Please sign in to comment.