HOME

TheInfoList



OR:

In cryptography, the Salted Challenge Response Authentication Mechanism (SCRAM) is a family of modern, password-based
challenge–response authentication In computer security, challenge–response authentication is a family of protocols in which one party presents a question ("challenge") and another party must provide a valid answer ("response") to be authenticated. The simplest example of a cha ...
mechanisms providing authentication of a user to a server. As it is specified for
Simple Authentication and Security Layer Simple Authentication and Security Layer (SASL) is a framework for authentication and data security in Internet protocols. It decouples authentication mechanisms from application protocols, in theory allowing any authentication mechanism supported ...
(SASL), it can be used for password-based logins to services like
SMTP The Simple Mail Transfer Protocol (SMTP) is an Internet standard communication protocol for electronic mail transmission. Mail servers and other message transfer agents use SMTP to send and receive mail messages. User-level email clients typical ...
and
IMAP In computing, the Internet Message Access Protocol (IMAP) is an Internet standard protocol used by email clients to retrieve email messages from a mail server over a TCP/IP connection. IMAP is defined by . IMAP was designed with the goal of per ...
(
e-mail Electronic mail (email or e-mail) is a method of exchanging messages ("mail") between people using electronic devices. Email was thus conceived as the electronic ( digital) version of, or counterpart to, mail, at a time when "mail" meant ...
),
XMPP Extensible Messaging and Presence Protocol (XMPP, originally named Jabber) is an open communication protocol designed for instant messaging (IM), presence information, and contact list maintenance. Based on XML (Extensible Markup Language), it ...
(chat), or
MongoDB MongoDB is a source-available cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas. MongoDB is developed by MongoDB Inc. and licensed under the Serve ...
(database). For XMPP, supporting it is mandatory.


Motivation

Alice wants to log into Bob's server. She needs to prove she is who she claims to be. For solving this authentication problem, Alice and Bob have agreed upon a password, which Alice knows, and which Bob knows how to verify. Now Alice could send her password over an unencrypted connection to Bob in a clear text form, for him to verify. That would however make the password accessible to Mallory, who is wiretapping the line. Alice and Bob could try to bypass this by encrypting the connection. However, Alice doesn't know whether the encryption was set up by Bob, and not by Mallory by doing a
man-in-the-middle attack In cryptography and computer security, a man-in-the-middle, monster-in-the-middle, machine-in-the-middle, monkey-in-the-middle, meddler-in-the-middle, manipulator-in-the-middle (MITM), person-in-the-middle (PITM) or adversary-in-the-middle (AiTM) ...
. Therefore, Alice sends a hashed version of her password instead, like in
CRAM-MD5 In cryptography, CRAM-MD5 is a challenge–response authentication mechanism (CRAM) based on the HMAC-MD5 algorithm. As one of the mechanisms supported by the Simple Authentication and Security Layer (SASL), it is often used in email software as pa ...
or
DIGEST-MD5 Digest access authentication is one of the agreed-upon methods a web server can use to negotiate credentials, such as username or password, with a user's web browser. This can be used to confirm the identity of a user before sending sensitive infor ...
. As it is a hash, Mallory doesn't get the password itself. And because the hash is salted with a challenge, Mallory could use it only for one login process. However, Alice wants to give some confidential information to Bob, and she wants to be sure it's Bob and not Mallory. For solving this, Bob has registered himself to a
certificate authority In cryptography, a certificate authority or certification authority (CA) is an entity that stores, signs, and issues digital certificates. A digital certificate certifies the ownership of a public key by the named subject of the certificate. This ...
(CA), which signed his certificate. Alice could solely rely on that signature system, but she knows it has weaknesses. To give her additional assurance that there is no man-in-the-middle attack, Bob creates a proof that he knows the password (or a salted hash thereof), and includes his certificate into this proof. This inclusion is called channel binding, as the
lower Lower may refer to: *Lower (surname) *Lower Township, New Jersey *Lower Receiver (firearms) *Lower Wick Lower Wick is a small hamlet located in the county of Gloucestershire, England. It is situated about five miles south west of Dursley, eight ...
encryption channel is 'bound' to the higher application channel. Alice then has an authentication of Bob, and Bob has authentication of Alice. Taken together, they have
mutual authentication Mutual authentication or two-way authentication (not to be confused with two-factor authentication) refers to two parties authenticating each other at the same time in an authentication protocol. It is a default mode of authentication in some proto ...
. DIGEST-MD5 already enabled mutual authentication, but it was often incorrectly implemented. When Mallory runs a man-in-the-middle attack and forges a CA signature, she could retrieve a hash of the password. But she couldn't impersonate Alice even for a single login session, as Alice included into her hash the encryption key of Mallory, resulting in a login-fail from Bob. To make a fully transparent attack, Mallory would need to know the password used by Alice, or the secret encryption key of Bob. Bob has heard of data breaches of server databases, and he decided that he doesn't want to store the passwords of his users in clear text. He has heard of the CRAM-MD5 and DIGEST-MD5 login schemes, but he knows, for offering these login schemes to his users, he would have to store weakly hashed, un-salted passwords. He doesn't like the idea, and therefore he chooses to demand the passwords in plain text. Then he can hash them with secure hashing schemes like
bcrypt bcrypt is a password-hashing function designed by Niels Provos and David Mazières, based on the Blowfish cipher and presented at USENIX in 1999. Besides incorporating a salt to protect against rainbow table attacks, bcrypt is an adaptive fu ...
,
scrypt In cryptography, scrypt (pronounced "ess crypt") is a password-based key derivation function created by Colin Percival in March 2009, originally for the Tarsnap online backup service. The algorithm was specifically designed to make it costly ...
or
PBKDF2 In cryptography, PBKDF1 and PBKDF2 (Password-Based Key Derivation Function 1 and 2) are key derivation functions with a sliding computational cost, used to reduce vulnerabilities of brute-force attacks. PBKDF2 is part of RSA Laboratories' Publ ...
, and salt them as he wants. However, then Bob and Alice would still face the problems described above. To solve this problem, they use SCRAM, where Bob can store his password in a salted format, using PBKDF2. During login, Bob sends Alice his salt and the iteration count of the PBKDF2 algorithm, and then Alice uses these to calculate the hashed password that Bob has in his database. All further calculations in SCRAM base on this value which both know.


Protocol overview

Although all clients and servers have to support the
SHA-1 In cryptography, SHA-1 (Secure Hash Algorithm 1) is a cryptographically broken but still widely used hash function which takes an input and produces a 160-bit (20-byte) hash value known as a message digest – typically rendered as 40 hexadecima ...
hashing algorithm, SCRAM is, unlike
CRAM-MD5 In cryptography, CRAM-MD5 is a challenge–response authentication mechanism (CRAM) based on the HMAC-MD5 algorithm. As one of the mechanisms supported by the Simple Authentication and Security Layer (SASL), it is often used in email software as pa ...
or
DIGEST-MD5 Digest access authentication is one of the agreed-upon methods a web server can use to negotiate credentials, such as username or password, with a user's web browser. This can be used to confirm the identity of a user before sending sensitive infor ...
, independent from the underlying hash function. All hash functions defined by th
IANA
can be used instead. As mentioned in the Motivation section, SCRAM uses the
PBKDF2 In cryptography, PBKDF1 and PBKDF2 (Password-Based Key Derivation Function 1 and 2) are key derivation functions with a sliding computational cost, used to reduce vulnerabilities of brute-force attacks. PBKDF2 is part of RSA Laboratories' Publ ...
mechanism, which increases the strength against
brute-force attacks In cryptography, a brute-force attack consists of an attacker submitting many passwords or passphrases with the hope of eventually guessing correctly. The attacker systematically checks all possible passwords and passphrases until the correct ...
, when a data leak has happened on the server. Let H be the selected hash function, given by the name of the algorithm advertised by the server and chosen by the client. 'SCRAM-SHA-1' for instance, uses SHA-1 as hash function.


Password-based derived key, or salted password

The client derives a key, or salted password, from the password, a salt, and a number of computational iterations as follows: : ''SaltedPassword'' = Hi(''password'', ''salt'', ''iteration-count'') =
PBKDF2 In cryptography, PBKDF1 and PBKDF2 (Password-Based Key Derivation Function 1 and 2) are key derivation functions with a sliding computational cost, used to reduce vulnerabilities of brute-force attacks. PBKDF2 is part of RSA Laboratories' Publ ...
(
HMAC In cryptography, an HMAC (sometimes expanded as either keyed-hash message authentication code or hash-based message authentication code) is a specific type of message authentication code (MAC) involving a cryptographic hash function and a secret ...
, ''password'', ''salt'', ''iteration-count'', ''output length of ''H)
.


Messages

RFC 5802 names four consecutive messages between server and client: ; ''client-first'': The ''client-first'' message consists of a GS2 header (comprising a channel binding flag, and optional name for authorization information), the desired ''username'', and a randomly generated client nonce ''c-nonce''. ; ''server-first'': The server appends to this client nonce its own nonce ''s-nonce'', and adds it to the ''server-first'' message, which also contains a ''salt'' used by the server for salting the user's password hash, and an iteration count ''iteration-count''. ; ''client-final'': After that the client sends the ''client-final'' message containing ''channel-binding'', the GS2 header and channel binding data encoded in base64, the concatenation of the client and the server nonce, and the client proof, ''proof''. ; ''server-final'' : The communication closes with the ''server-final'' message, which contains the server signature, ''verifier''.


Proofs

The client and the server prove to each other they have the same ''Auth'' variable, consisting of: :''Auth'' = ''client-first-without-header'' + , + ''server-first'' + , + ''client-final-without-proof'' (concatenated with commas) More concretely, this takes the form: := r=''cnonce'', 'extensions'',=''cnonce''‖''snonce'',s=''salt'',i=''iterationcount'', 'extensions'',=base64(''channelflag'', =''authzid''!--mandatory comma repetition intended-->,''channelbinding''),r=''cnonce''‖''snonce'' ''extensions''/code> The proofs are calculated as follows: :''ClientKey'' = HMAC(''SaltedPassword'', 'Client Key') :''ServerKey'' = HMAC(''SaltedPassword'', 'Server Key') :''ClientProof'' = ''p'' = ''ClientKey'' XOR HMAC(H(''ClientKey''), ''Auth'') :''ServerSignature'' = ''v'' = HMAC(''ServerKey'', ''Auth'') where the
XOR Exclusive or or exclusive disjunction is a logical operation that is true if and only if its arguments differ (one is true, the other is false). It is symbolized by the prefix operator J and by the infix operators XOR ( or ), EOR, EXOR, , ...
operation is applied to byte strings of the same length, H(''ClientKey'') is a normal hash of ''ClientKey''. 'Client Key' and 'Server Key' are verbatim strings. The server can authorize the client by computing ClientKey from ClientProof and then comparing H(ClientKey) with the stored value. The client can authorize the server by computing and comparing ServerSignature directly.


Stored password

The server stores only the username, ''salt'', ''iteration-count'', H(''ClientKey''), ''ServerKey''. The server has transient access to ''ClientKey'' as it is recovered from the client proof, having been encrypted with H(''ClientKey''). The client needs only the ''password''.


Channel binding

The term ''channel binding'' describes the
man-in-the-middle attack In cryptography and computer security, a man-in-the-middle, monster-in-the-middle, machine-in-the-middle, monkey-in-the-middle, meddler-in-the-middle, manipulator-in-the-middle (MITM), person-in-the-middle (PITM) or adversary-in-the-middle (AiTM) ...
prevention strategy to 'bind' an
application layer An application layer is an abstraction layer that specifies the shared communications protocols and Interface (computing), interface methods used by Host (network), hosts in a communications network. An ''application layer'' abstraction is speci ...
, which provides mutual authentication, to a lower (mostly encryption) layer, ensuring that the endpoints of a connection are the same in both layers. There are two general directions for channel binding: ''unique'' and ''endpoint'' channel binding. The first ensures that a specific connection is used, the second that the endpoints are the same. There are several channel binding types, where every single type has a ''channel binding unique prefix''. Every channel binding type specifies the content of the ''channel binding data'', which provides unique information over the channel and the endpoints. For instance, for the ''tls-server-end-point'' channel binding, it is the server's TLS certificate. An example use case of channel binding with SCRAM as application layer, could be with
Transport Layer Security Transport Layer Security (TLS) is a cryptographic protocol designed to provide communications security over a computer network. The protocol is widely used in applications such as email, instant messaging, and voice over IP, but its use in securi ...
(TLS) as lower layer. TLS protects from passive eavesdropping, as the communication is encrypted. However, if the client doesn't authenticate the server (e.g. by verifying the server's certificate), this doesn't prevent man-in-the-middle attacks. For this, the endpoints need to assure their identities to each other, which can be provided by SCRAM. The ''gs2-cbind-flag'' SCRAM variable specifies whether the client supports channel binding or not, or thinks the server doesn't support channel binding, and ''c-bind-input'' contains the ''gs2-cbind-flag'' together with the ''channel binding unique prefix'' and the ''channel binding data'' themselves. Channel binding is optional in SCRAM, and the ''gs2-cbind-flag'' variable prevents from
downgrade attack A downgrade attack, also called a bidding-down attack or version rollback attack, is a form of cryptographic attack on a computer system or communications protocol that makes it abandon a high-quality mode of operation (e.g. an encrypted connec ...
s. When a server supports channel binding, it adds the character sequence '-PLUS' to the advertised SCRAM algorithm name.


Strengths

* Strong password storage: When implemented in a right way, the server can store the passwords in a salted, iterated hash format, making offline attacks harder, and decreasing the impact of database breaches. * Simplicity: Implementing SCRAM is easier than DIGEST-MD5. * International interoperability: the RFC requires
UTF-8 UTF-8 is a variable-width encoding, variable-length character encoding used for electronic communication. Defined by the Unicode Standard, the name is derived from ''Unicode'' (or ''Universal Coded Character Set'') ''Transformation Format 8-bit'' ...
to be used for usernames and passwords, unlike CRAM-MD5. * Because only the salted and hashed version of a password is used in the whole login process, and the salt on the server doesn't change, a client storing passwords can store the hashed versions, and not expose the clear text password to attackers. Such hashed versions are bound to one server, which makes this useful on password reuse.


References


External links

* , SCRAM for SASL and GSS-API * , SCRAM-SHA-256 and SCRAM-SHA-256-PLUS * {{IETF RFC, 7804, link=no, SCRAM in HTTP
GNU Network Security Labyrinth
(presentation similar to
Motivation Motivation is the reason for which humans and other animals initiate, continue, or terminate a behavior at a given time. Motivational states are commonly understood as forces acting within the agent that create a disposition to engage in goal-dire ...
section) Cryptographic protocols