Class: Mongo::Auth::SCRAM::Conversation
- Inherits:
-
Object
- Object
- Mongo::Auth::SCRAM::Conversation
- Defined in:
- lib/mongo/auth/scram/conversation.rb
Overview
Defines behaviour around a single SCRAM-SHA-1 conversation between the client and server.
Constant Summary collapse
- CLIENT_CONTINUE_MESSAGE =
The base client continue message.
{ saslContinue: 1 }.freeze
- CLIENT_FIRST_MESSAGE =
The base client first message.
{ saslStart: 1, autoAuthorize: 1 }.freeze
- CLIENT_KEY =
The client key string.
'Client Key'.freeze
- DIGEST =
The digest to use for encryption.
OpenSSL::Digest::SHA1.new.freeze
- DONE =
The key for the done field in the responses.
'done'.freeze
- ID =
The conversation id field.
'conversationId'.freeze
- ITERATIONS =
The iterations key in the responses.
/i=(\d+)/.freeze
- PAYLOAD =
The payload field.
'payload'.freeze
- RNONCE =
The rnonce key in the responses.
/r=([^,]*)/.freeze
- SALT =
The salt key in the responses.
/s=([^,]*)/.freeze
- SERVER_KEY =
The server key string.
'Server Key'.freeze
- VERIFIER =
The server signature verifier in the response.
/v=([^,]*)/.freeze
Instance Attribute Summary collapse
-
#nonce ⇒ String
readonly
Nonce The initial user nonce.
-
#reply ⇒ Protocol::Reply
readonly
Reply The current reply in the conversation.
-
#user ⇒ User
readonly
User The user for the conversation.
Instance Method Summary collapse
-
#continue(reply) ⇒ Protocol::Query
Continue the SCRAM conversation.
-
#finalize(reply) ⇒ Protocol::Query
Finalize the SCRAM conversation.
-
#id ⇒ Integer
Get the id of the conversation.
-
#initialize(user) ⇒ Conversation
constructor
Create the new conversation.
-
#start ⇒ Protocol::Query
Start the SCRAM conversation.
Constructor Details
#initialize(user) ⇒ Conversation
Create the new conversation.
181 182 183 184 |
# File 'lib/mongo/auth/scram/conversation.rb', line 181 def initialize(user) @user = user @nonce = SecureRandom.base64 end |
Instance Attribute Details
#nonce ⇒ String (readonly)
Returns nonce The initial user nonce.
89 90 91 |
# File 'lib/mongo/auth/scram/conversation.rb', line 89 def nonce @nonce end |
#reply ⇒ Protocol::Reply (readonly)
Returns reply The current reply in the conversation.
93 94 95 |
# File 'lib/mongo/auth/scram/conversation.rb', line 93 def reply @reply end |
#user ⇒ User (readonly)
Returns user The user for the conversation.
96 97 98 |
# File 'lib/mongo/auth/scram/conversation.rb', line 96 def user @user end |
Instance Method Details
#continue(reply) ⇒ Protocol::Query
Continue the SCRAM conversation. This sends the client final message to the server after setting the reply from the previous server communication.
111 112 113 114 115 116 117 118 119 |
# File 'lib/mongo/auth/scram/conversation.rb', line 111 def continue(reply) (reply) Protocol::Query.new( user.auth_source, Database::COMMAND, CLIENT_CONTINUE_MESSAGE.merge(payload: , conversationId: id), limit: -1 ) end |
#finalize(reply) ⇒ Protocol::Query
Finalize the SCRAM conversation. This is meant to be iterated until the provided reply indicates the conversation is finished.
133 134 135 136 137 138 139 140 141 |
# File 'lib/mongo/auth/scram/conversation.rb', line 133 def finalize(reply) (reply) Protocol::Query.new( user.auth_source, Database::COMMAND, CLIENT_CONTINUE_MESSAGE.merge(payload: , conversationId: id), limit: -1 ) end |
#id ⇒ Integer
Get the id of the conversation.
169 170 171 |
# File 'lib/mongo/auth/scram/conversation.rb', line 169 def id reply.documents[0][ID] end |
#start ⇒ Protocol::Query
Start the SCRAM conversation. This returns the first message that needs to be send to the server.
152 153 154 155 156 157 158 159 |
# File 'lib/mongo/auth/scram/conversation.rb', line 152 def start Protocol::Query.new( user.auth_source, Database::COMMAND, CLIENT_FIRST_MESSAGE.merge(payload: , mechanism: SCRAM::MECHANISM), limit: -1 ) end |