Crates.io | easy-srp |
lib.rs | easy-srp |
version | 0.3.0 |
source | src |
created_at | 2024-08-26 22:10:52.81672 |
updated_at | 2024-08-29 22:01:22.663132 |
description | easy-srp wraps the rust srp crate and provides an easy to use API. |
homepage | |
repository | https://codeberg.org/nanobot248/easy-srp.git |
max_upload_size | |
id | 1352665 |
size | 34,317 |
srp
for easy usageThe srp crate provides the means for using
SRP6a athentication.
This crate wraps the srp
crate to make the authentication workflows
more obvious easy to use.
This is done via the following means:
Workflow
structs for the 3 typical workflows:
step#
with increasing number #
, so it is obvious in
which phase of the authentication the method needs to be called.features
client
: Include client classes (ClientAuthenticationWorkflow
,
ClientRegistrationWorkflow
, ...).server
: Include server classes (ServerAuthenticationWorkflow
, etc.)base64
: Include the base64 crate
and provide base64
serialization for various byte array parameters.serialization
: Include the serde crate
and add Serialize
and Deserialize
to various structs. This also
enables the base64
feature.js
: This crate uses the getrandom
crate for generating random numbers (salt, client/server ephemeral key).
getrandom
supports a variety of platforms, including web browsers (in
WebAssembly). If easy-srp
is used inside the browser, use the js
feature to make getrandom
use the Crypto.getRandomValues()
JavaScript
method for random number generation.username
and password
salt
verifier
from the above credentialsusername
, salt
and verifier
to the server via
a secure channel.Client | Server | |
---|---|---|
(username, pub_a) |
-> | |
<- | (salt, pub_b) |
|
(proof_a) |
-> | |
<- | (proof_b) |
a
and derices its public key pub_a
a
for this authentication session.(username, pub_a)
to the server.(salt, verifier)
for username
.pub_a
for this authentication session.b
and derives its public
key pub_b
.(salt, pub_b)
to the client.proof_a
and sends (proof_a)
to the server.proof_a
proof_b
and sends it to the clientproof_b
SHA256
use sha2::Sha256;
use easy_srp::groups::G_4096;
use easy_srp::client::{ClientRegistrationWorkflow, GenerateVerifierParams};
let verifier_wf = ClientRegistrationWorkflow::<Sha256>::new(&G_4096);
let username = "lorem".to_string();
let password = "ipsum".to_string();
let verifier = verifier_wf.generate_verifier(GenerateVerifierParams {
username: username.clone(),
password: password.clone(),
salt: None
}).expect("could not generate verifier.");
In this example, the step#_on_server(...)
methods are just placeholders
to show what data needs to be sent to the server and what data the server
needs to reply with.
use sha2::Sha256;
use easy_srp::groups::G_4096;
use easy_srp::client::{ClientAuthenticationWorkflow, ClientStep1Result,
ClientStep3Result, ClientStep3Params}
let username = "someuser";
let password = "somepassword";
let client_wf = crate::client::ClientAuthenticationWorkflow::<Sha256>::new(&G_4096);
// compute ephemeral key of the client:
let step1_result: ClientStep1Result = client_wf.step1().expect("could not compute step1");
// send username and step1_result.client_public_a to the server and get salt and server_public_a
let (salt, server_public_b) = step2_on_server(username, step1_result.client_public_a);
let step3_result: ClientStep3Result<Sha256> = client_wf.step3(ClientStep3Params {
client_a: step1_result.client_private_a.as_slice(),
username: username.clone(),
password: password.clone(),
salt,
server_public_b
}).expect("could not compute step3");
let server_proof = step4_on_server(step3_result.proof());
step3_result.verify_server(server_proof).expect("invalid server proof.");
let key = step3_result.key();
In this example, the step#_on_client(...)
methods are placeholders to show
what data needs to be sent to/received from the client.
The retrieve_stored_credentials(username)
method is a placeholder to
demonstrate that salt
and stored_verifier
(the verifier saved in the
user registration process) need to be looked up given the username.
use sha2::Sha256;
use easy_srp::groups::G_4096;
// receive username and client ephemeral public key from client
let (username, client_public_a) = step1_on_client();
let (salt, stored_verifier) = retrieve_stored_credentials(username);
let server_wf = crate::server::ServerAuthenticationWorkflow::<Sha256>::new(test_group);
let step2_result: ServerStep2Result = server_wf.step2(ServerStep2Params {
stored_verifier: verifier.verifier.as_slice()
}).expect("could not compute step2");
let step4_result: ServerStep4Result<Sha256> = server_wf.step4(ServerStep4Params {
client_public_a: step1_result.client_public_a.as_slice(),
server_private_b: step2_result.server_private_b.as_slice(),
stored_verifier: verifier.verifier.as_slice(),
client_proof: step3_result.proof()
}).expect("could not compute step4");
// verify the client proof before sending any encrypted data (including the
// server proof) to the client.
step4_result.verify_client(step3_result.proof())
.expect("could not verify client.");
let key = step4_result.key();
The following dependencies are included intentionally (aka directly):
srp
)base64
)serde
)Additional dependencies may be included transitively.
This project is licensed under the BSD-3-Clause license. See LICENSE.txt for the full license.