Class: Mongo::Auth::ScramConversationBase Private
- Inherits:
-
SaslConversationBase
- Object
- ConversationBase
- SaslConversationBase
- Mongo::Auth::ScramConversationBase
- Defined in:
- lib/mongo/auth/scram_conversation_base.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Defines common behavior around authentication conversations between the client and the server.
Direct Known Subclasses
Mongo::Auth::Scram256::Conversation, Mongo::Auth::Scram::Conversation
Constant Summary collapse
- MIN_ITER_COUNT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The minimum iteration count for SCRAM-SHA-1 and SCRAM-SHA-256.
4096
Constants inherited from SaslConversationBase
Mongo::Auth::SaslConversationBase::CLIENT_CONTINUE_MESSAGE, Mongo::Auth::SaslConversationBase::CLIENT_FIRST_MESSAGE
Instance Attribute Summary collapse
-
#client_nonce ⇒ String
readonly
private
Client_nonce The client nonce.
-
#id ⇒ Integer
readonly
private
Get the id of the conversation.
Attributes inherited from ConversationBase
Instance Method Summary collapse
-
#continue(reply_document, connection) ⇒ Protocol::Message
private
Continue the SCRAM conversation.
-
#finalize(connection) ⇒ Protocol::Message
private
Finalize the SCRAM conversation.
-
#initialize(user, connection, client_nonce: nil) ⇒ ScramConversationBase
constructor
private
Create the new conversation.
-
#process_continue_response(reply_document) ⇒ Object
private
Processes the second response from the server.
-
#server_verified? ⇒ true | fase
private
Whether the client verified the ServerSignature from the server.
-
#speculative_auth_document ⇒ Hash | nil
private
Returns the hash to provide to the server in the handshake as value of the speculativeAuthenticate key.
Methods inherited from SaslConversationBase
Methods inherited from ConversationBase
#build_message, #validate_external_auth_source
Constructor Details
#initialize(user, connection, client_nonce: nil) ⇒ ScramConversationBase
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create the new conversation.
38 39 40 41 |
# File 'lib/mongo/auth/scram_conversation_base.rb', line 38 def initialize(user, connection, client_nonce: nil) super @client_nonce = client_nonce || SecureRandom.base64 end |
Instance Attribute Details
#client_nonce ⇒ String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns client_nonce The client nonce.
44 45 46 |
# File 'lib/mongo/auth/scram_conversation_base.rb', line 44 def client_nonce @client_nonce end |
#id ⇒ Integer (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get the id of the conversation.
52 53 54 |
# File 'lib/mongo/auth/scram_conversation_base.rb', line 52 def id @id end |
Instance Method Details
#continue(reply_document, connection) ⇒ Protocol::Message
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Continue the SCRAM conversation. This sends the client final message to the server after setting the reply from the previous server communication.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/mongo/auth/scram_conversation_base.rb', line 73 def continue(reply_document, connection) @id = reply_document['conversationId'] payload_data = reply_document['payload'].data parsed_data = parse_payload(payload_data) @server_nonce = parsed_data.fetch('r') @salt = Base64.strict_decode64(parsed_data.fetch('s')) @iterations = parsed_data.fetch('i').to_i.tap do |i| if i < MIN_ITER_COUNT raise Error::InsufficientIterationCount.new( Error::InsufficientIterationCount.(MIN_ITER_COUNT, i)) end end @auth_message = "#{},#{payload_data},#{without_proof}" validate_server_nonce! selector = CLIENT_CONTINUE_MESSAGE.merge( payload: , conversationId: id, ) (connection, user.auth_source, selector) end |
#finalize(connection) ⇒ Protocol::Message
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Finalize the SCRAM conversation. This is meant to be iterated until the provided reply indicates the conversation is finished.
111 112 113 114 115 116 117 |
# File 'lib/mongo/auth/scram_conversation_base.rb', line 111 def finalize(connection) selector = CLIENT_CONTINUE_MESSAGE.merge( payload: , conversationId: id, ) (connection, user.auth_source, selector) end |
#process_continue_response(reply_document) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Processes the second response from the server.
100 101 102 103 |
# File 'lib/mongo/auth/scram_conversation_base.rb', line 100 def process_continue_response(reply_document) payload_data = parse_payload(reply_document['payload'].data) check_server_signature(payload_data) end |
#server_verified? ⇒ true | fase
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Whether the client verified the ServerSignature from the server.
59 60 61 |
# File 'lib/mongo/auth/scram_conversation_base.rb', line 59 def server_verified? !!@server_verified end |
#speculative_auth_document ⇒ Hash | nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the hash to provide to the server in the handshake as value of the speculativeAuthenticate key.
If the auth mechanism does not support speculative authentication, this method returns nil.
126 127 128 |
# File 'lib/mongo/auth/scram_conversation_base.rb', line 126 def speculative_auth_document client_first_document.merge(db: user.auth_source) end |