Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor refactoring on existing SCRAMSHA1AuthMechanism #92

Merged
merged 1 commit into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines +2 to +3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, I realize this method has no senders and uses a variable that is not defined.
I will remove it.
@rydnr

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, in master

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"
}