Secure Remote Password protocol
The Secure Remote Password protocol is an augmented password-authenticated key agreement protocol, specifically designed to work around existing patents.
Like all PAKE protocols, an eavesdropper or man in the middle cannot obtain enough information to be able to brute force guess a password without further interactions with the parties for each guess. Furthermore, being an augmented PAKE protocol, the server does not store password-equivalent data. This means that an attacker who steals the server data cannot masquerade as the client unless they first perform a brute force search for the password.
In layman's terms, during SRP authentication, one party demonstrates to another party that they know the password, without sending the password itself nor any other information from which the password can be derived. The password never leaves the client and is unknown to the server.
Furthermore, the server also needs to know about the password in order to instigate the secure connection. This means that the server also authenticates itself to the client, without reliance on the user parsing complex URLs. This prevents Phishing.
Overview
The SRP protocol has a number of desirable properties: it allows a user to authenticate themselves to a server, it is resistant to dictionary attacks mounted by an eavesdropper, and it does not require a trusted third party. It effectively conveys a zero-knowledge password proof from the user to the server. In revision 6 of the protocol only one password can be guessed per connection attempt. One of the interesting properties of the protocol is that even if one or two of the cryptographic primitives it uses are attacked, it is still secure. The SRP protocol has been revised several times, and is currently at revision 6a.The SRP protocol creates a large private key shared between the two parties in a manner similar to Diffie–Hellman key exchange based on the client side having the user password and the server side having a cryptographic verifier derived from the password. The shared public key is derived from two random numbers, one generated by the client, and the other generated by the server, which are unique to the login attempt. In cases where encrypted communications as well as authentication are required, the SRP protocol is more secure than the alternative SSH protocol and faster than using Diffie–Hellman key exchange with signed messages. It is also independent of third parties, unlike Kerberos. The SRP protocol, version 3 is described in RFC 2945. SRP version 6 is also used for strong password authentication in SSL/TLS and other standards such as EAP and SAML, and is being standardized in IEEE P1363 and ISO/IEC 11770-4.
Protocol
The following notation is used in this description of the protocol, version 6:- q and N = 2q + 1 are chosen such that both are prime. N must be large enough so that computing discrete logarithms modulo N is infeasible.
- All arithmetic is performed in the ring of integers modulo N,. This means that below g should be read as gmod N
- g is a generator of the multiplicative group.
- H is a hash function; e.g., SHA-256.
- k is a parameter derived by both sides; in SRP-6, k = 3, while in SRP-6a it is derived from N and g : k = H. It is used to prevent a 2-for-1 guess when an active attacker impersonates the server.
- s is a small salt.
- is an identifying username.
- p is the user's password.
- v is the host's password verifier, v = g where at a minimum x = H. As x is only computed on the client it is free to choose a stronger algorithm. An implementation could choose to use x = H without affecting any steps required of the host. The standard defines x = H. Use of within x avoids a malicious server from being able to learn if .
- A and B are random one time ephemeral keys of the user and host respectively.
- | denotes concatenation.
First, to establish a password p with server Steve, client Carol picks a small random salt s, and computes x = H, v = g. Steve stores v and s, indexed by, as Carol's password verifier and salt. Carol must not share x with anybody, and must safely erase it at this step, because it is equivalent to the plaintext password p. This step is completed before the system is used as part of the user registration with Steve. Note that the salt s is shared and exchanged to negotiate a session key later so the value could be chosen by either side but is done by Carol so that she can register, s and v in a single registration request. The transmission and authentication of the registration request is not covered in SRP.
Then to perform a proof of password at a later date the following exchange protocol occurs:
- Carol → Steve: generate random value a; send and A = g
- Steve → Carol: generate random value b; send s and B = kv + g
- Both: u = H
- Carol: SCarol = = = =
- Carol: KCarol = H
- Steve: SSteve = = = = =
- Steve: KSteve = H = KCarol
- Carol → Steve: M1 = H. Steve verifies M1.
- Steve → Carol: M2 = H. Carol verifies M2.
Alternatively, in a password-only proof the calculation of K can be skipped and the shared S proven with:
- Carol → Steve: M1 = H. Steve verifies M1.
- Steve → Carol: M2 = H. Carol verifies M2.
The two parties also employ the following safeguards:
- Carol will abort if she receives B = 0 or u = 0.
- Steve will abort if he receives A = 0.
- Carol must show her proof of K first. If Steve detects that Carol's proof is incorrect, he must abort without showing his own proof of K
Implementation example in Python
- An example SRP authentication
- WARNING: Do not use for real cryptographic purposes beyond testing.
- WARNING: This below code misses important safeguards. It does not check A, B, and U are not zero.
- based on http://srp.stanford.edu/design.html
import random
def global_print -> None:
x = lambda s: .format
print) for name in names))
- Note: str converts as is, str will convert to ""
"""A one-way hash function."""
a = ':'.join
return int
def cryptrand:
return random.SystemRandom.getrandbits % N
- A large safe prime
- All arithmetic is done modulo N
4b:1b:a4:b8:1a:63:f9:74:8f:ed:2d:8a:41:0c:2f:
c2:1b:12:32:f0:d3:bf:a0:24:27:6c:fd:88:44:81:
97:aa:e4:86:a6:3b:fc:a7:b8:bf:77:54:df:b3:27:
c7:20:1f:6f:d1:7f:d7:fd:74:15:8b:d3:1c:e7:72:
c9:f5:f8:ab:58:45:48:a9:9a:75:9b:5a:2c:05:32:
16:2b:7b:62:18:e8:f1:42:bc:e2:c3:0d:77:84:68:
9a:48:3e:09:5e:70:16:18:43:79:13:a8:c3:9c:3d:
d0:d4:ca:3c:50:0b:88:5f:e3
N = int).replace
g = 2 # A generator modulo N
k = H # Multiplier parameter
global_print
- The server must first generate the password verifier
p = "password1234" # Password
s = cryptrand # Salt for the user
x = H # Private key
v = pow # Password verifier
global_print
a = cryptrand
A = pow
global_print # client->server
b = cryptrand
B = % N
global_print # server->client
u = H # Random scrambling parameter
global_print
x = H
S_c = pow
K_c = H
global_print
S_s = pow
K_s = H
global_print
M_c = H ^ H, H
global_print
- client->server ; server verifies M_c
M_s = H
global_print
- server->client ; client verifies M_s
Outputs
Implementations
- OpenSSL version 1.0.1 or later.
- Botan contains an implementation of SRP-6a
- TLS-SRP is a set of ciphersuites for transport layer security that uses SRP.
- SRP-6a implementation in JavaScript, open source, Mozilla Public License licensed.
- The includes a JavaScript implementation of the SRP protocol, open source, BSD licensed.
- provide a Java implementation licensed under the GNU General Public License with the "library exception", which permits its use as a library in conjunction with non-Free software.
- The Legion of the Bouncy Castle provides Java and C# implementations under the MIT License.
- is a Java library providing a verifier generator, client and server-side sessions. Includes interfaces for custom password key, client and server evidence message routines. No external dependencies. Released under the Apache 2.0 license.
- is a C++ implement base on MIRACL.
- is a C++ modular implementation currently works with OpenSSL.
- Json2Ldap provides SRP-6a authentication to LDAP directory servers.
- SRP-6a implementation in C.
- SRP-6a implementation in Perl.
- SRP-6a implementation in Python.
- SRP-6a implementation in pure Python3.
- Tools to implement Secure Remote Password authentication in Python. .
- web framework's Accounts system implements SRP for password authentication.
- SRP-6a implementation in Ruby.
- implementation of the Stanford SRP Protocol Design in JavaScript and PHP under the MIT License.
- SRP-6a implementation in PHP and JavaScript.
- SRP-6a implementation in JavaScript. Comes with compatible Java classes which use a demonstration app using Spring Security. There is also a demonstration application performing authentication to a PHP server. Released under the Apache License.
- implements SRP for key exchange.
- is a JavaScript client and server implementation of SRP.
- implementation in C# and Java.
- is an Objective-C implementation of SRP-6a.
- is a Go implementation of SRP-6a.
- is a TypeScript implementation of SRP-6a.
Manual pages
- : Point-to-Point Protocol Daemon
- : Simple SRP password tool
RFCs
- RFC 2944 - Telnet Authentication: SRP
- RFC 2945 - The SRP Authentication and Key Exchange System
- RFC 3720 - Internet Small Computer Systems Interface
- RFC 3723 - Securing Block Storage Protocols over IP
- RFC 3669 - Guidelines for Working Groups on Intellectual Property Issues
- RFC 5054 - Using the Secure Remote Password Protocol for TLS Authentication
Other links
- The EKE patents mentioned expired in 2011 and 2013.