Skip to content

Commit a2dbab0

Browse files
committed
Improved the README.md
1 parent d20c112 commit a2dbab0

File tree

1 file changed

+155
-1
lines changed

1 file changed

+155
-1
lines changed

README.md

+155-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,119 @@ dotnet add package srp
1818

1919
## Usage
2020

21-
TODO
21+
### Signing up
22+
23+
To create an account, a client provides the following three values:
24+
25+
* Identifier (username or email)
26+
* Salt
27+
* Verifier
28+
29+
The salt and verifier are calculated as follows:
30+
31+
```c#
32+
using SecureRemotePassword;
33+
34+
// a user enters his name and password
35+
var userName = "alice";
36+
var password = "password123";
37+
38+
var client = new SrpClient();
39+
var salt = srp.GenerateSalt();
40+
var privateKey = srp.DerivePrivateKey(salt, userName, password);
41+
var verifier = srp.DeriveVerifier(privateKey);
42+
43+
// send userName, salt and verifier to server
44+
```
45+
46+
### Logging in
47+
48+
Authentication involves several steps:
49+
50+
#### 1. Client → Server: I, A
51+
52+
The client generates an ephemeral secret/public value pair and sends the
53+
public value and user name to server:
54+
55+
```c#
56+
using SecureRemotePassword;
57+
58+
// a user enters his name
59+
var userName = "alice";
60+
61+
var client = new SrpClient();
62+
var clientEphemeral = client.GenerateEphemeral();
63+
64+
// send userName and clientEphemeral.Public to server
65+
```
66+
67+
#### 2. Server → Client: s, B
68+
69+
The server retrieves `salt` and `verifier` from the database using the
70+
client-provided `userName`. Then it generates its own ephemeral secret/public
71+
value pair:
72+
73+
```c#
74+
using SecureRemotePassword;
75+
76+
// retrieved from the database
77+
var salt = "beb25379...";
78+
var verifier = "7e273de8...";
79+
80+
var server = new SrpServer();
81+
var serverEphemeral = server.GenerateEphemeral();
82+
83+
// store serverEphemeral.Secret for later use
84+
// send salt and serverEphemeral.Public to the client
85+
```
86+
87+
#### 3. Client → Server: M1
88+
89+
The client derives the shared session key and a proof of it to provide to the server:
90+
91+
```c#
92+
using SecureRemotePassword;
93+
94+
// a user enters his password
95+
var password = "password123";
96+
97+
var client = new SrpClient();
98+
var privateKey = client.DerivePrivateKey(salt, userName, password);
99+
var clientSession = client.DeriveSession(clientEphemeral.Secret,
100+
serverPublicEphemeral, salt, userName, privateKey);
101+
102+
// send clientSession.Proof to the server
103+
```
104+
105+
#### 4. Server → Client: M2
106+
107+
The server derives the shared session key and verifies that the client has the
108+
same key using the provided proof value:
109+
110+
```c#
111+
using SecureRemotePassword;
112+
113+
// get the serverEphemeral.Secret stored in step 2
114+
var serverSecretEphemeral = "e487cb59...";
115+
116+
var server = new SrpServer();
117+
var serverSession = server.DeriveSession(serverSecretEphemeral,
118+
clientPublicEphemeral, salt, userName, verifier, clientSessionProof);
119+
120+
// send serverSession.Proof to the client
121+
```
122+
123+
#### 5. Client verifies M2
124+
125+
Finally, the client verifies that the server has derived the same session key
126+
using the server's proof value:
127+
128+
```c#
129+
using SecureRemotePassword;
130+
131+
var client = new SrpClient();
132+
client.VerifySession(clientEphemeral.Public, clientSession, serverSessionProof);
133+
```
22134

23135
## Authentication at a glance
24136

@@ -43,6 +155,48 @@ client.VerifySession(clientEphemeral.Public, clientSession, serverSession.Proof)
43155
Assert.AreEqual(clientSession.Key, serverSession.Key);
44156
```
45157

158+
## Custom protocol parameters
159+
160+
This SRP-6a implementation uses `sha256` hash function and 2048-bit group values
161+
by default. Any class derived from `HashAlgorithm` can be used as `H`.
162+
Customizing the parameters is easy:
163+
164+
```c#
165+
using System.Security.Cryptography;
166+
using SecureRemotePassword;
167+
168+
// use predefined 4096-bit group with SHA512 hash function
169+
var customParams = SrpParameters.Create4096<SHA512>();
170+
```
171+
172+
`SrpParameters` has helper methods for all predefined groups from RFC5054:
173+
`Create1024<SHA1>()`, etc.
174+
175+
It's also possible to specify custom values of `N` and `g`:
176+
177+
```c#
178+
var N = "D4C7F8A2B32C11B8FBA9581EC4BA...";
179+
var customParams = SrpParameters.Create<SHA1>(N, "02");
180+
```
181+
182+
Custom SRP parameters are then passed to `SrpClient` and `SrpServer` constructors.
183+
Make sure to use the same parameters on both sides:
184+
185+
```c#
186+
var client = new SrpClient(customParams);
187+
var server = new SrpServer(customParams);
188+
```
189+
190+
## Compatibility with other implementations
191+
192+
`srp.net` is designed to be compatible with other implementations hosted
193+
in [secure-remote-password](https://github.com/secure-remote-password/) organization.
194+
It's also compatible with these libraries:
195+
196+
* Javascript: [secure-remote-password](https://npmjs.com/package/secure-remote-password) npm package by [Linus Unnebäck](https://github.com/LinusU/secure-remote-password)
197+
* Python: [srptools](https://pypi.org/project/srptools/) by [Igor Starikov](https://github.com/idlesign/srptools)
198+
* Swift: [SRP for Swift](http://boukehaarsma.nl/SRP/master/) by [Bouke Haarsma](https://github.com/Bouke/SRP)
199+
46200
## References
47201

48202
* [Secure Remote Password protocol](http://srp.stanford.edu/), [documentation](http://srp.stanford.edu/doc.html), [wikipedia](http://en.wikipedia.org/wiki/Secure_remote_password_protocol)

0 commit comments

Comments
 (0)