Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Make basic SRP flow work (#43)

Leendert de Borste316836ee5f1
diff --git a/src/AliasVault.Shared/AliasVault.Shared.csproj b/src/AliasVault.Shared/AliasVault.Shared.csproj
index d56a6ba10..ec688bbed 100644
--- a/src/AliasVault.Shared/AliasVault.Shared.csproj
+++ b/src/AliasVault.Shared/AliasVault.Shared.csproj
@@ -8,7 +8,7 @@
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DocumentationFile>bin\Debug\net8.0\AliasVault.Shared.xml</DocumentationFile>
- <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
+ <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
diff --git a/src/Tests/AliasVault.UnitTests/CryptographyTests.cs b/src/Tests/AliasVault.UnitTests/CryptographyTests.cs
index 2ea5857be..ed7849534 100644
--- a/src/Tests/AliasVault.UnitTests/CryptographyTests.cs
+++ b/src/Tests/AliasVault.UnitTests/CryptographyTests.cs
@@ -78,7 +78,7 @@ public class CryptographyTests
/// Test the SRP authentication flow to ensure it works correctly.
/// </summary>
[Test]
- public void TestSRPAuthentication()
+ public void TestSrpAuthentication()
{
var email = "[email protected]";
var password = "myPassword";
@@ -92,24 +92,25 @@ public class CryptographyTests
// Convert to string
string passwordHashString = BitConverter.ToString(passwordHash).Replace("-", string.Empty);
- // Client generates a salt and verifier.
+ // Signup: client generates a salt and verifier.
string salt = Cryptography.Srp.GenerateSalt()!;
- string verifier = Cryptography.Srp.GenerateVerifier(email, passwordHashString, salt);
+ string privateKey = Cryptography.Srp.DerivePrivateKey(salt, email, passwordHashString);
+ string verifier = Cryptography.Srp.GenerateVerifier(privateKey);
// Login -----------------------------------
// 1. Client generates an ephemeral value.
- var clientEphemeral = Cryptography.Srp.GenerateEphemeral();
+ var clientEphemeral = Cryptography.Srp.GenerateEphemeralClient();
// --> Then client sends request to server.
// 2. Server retrieves salt and verifier from database.
// Then server generates an ephemeral value as well.
- var serverEphemeral = Cryptography.Srp.GenerateEphemeral();
+ var serverEphemeral = Cryptography.Srp.GenerateEphemeralServer(verifier);
// --> Send serverEphemeral.Public to client.
// 3. Client derives shared session key.
- var clientSession = Cryptography.Srp.DeriveSessionClient(passwordHashString, clientEphemeral.Secret, serverEphemeral.Public, salt, email);
+ var clientSession = Cryptography.Srp.DeriveSessionClient(privateKey, clientEphemeral.Secret, serverEphemeral.Public, salt, email);
// --> send session.Proof to server.
@@ -120,5 +121,8 @@ public class CryptographyTests
// 5. Client verifies the proof.
Cryptography.Srp.VerifySession(clientEphemeral.Public, clientSession, serverSession.Proof);
+
+ // Ensure the keys match.
+ Assert.That(clientSession.Key, Is.EqualTo(serverSession.Key));
}
}
diff --git a/src/Utilities/Cryptography/Srp.cs b/src/Utilities/Cryptography/Srp.cs
index 958887a74..898c9a012 100644
--- a/src/Utilities/Cryptography/Srp.cs
+++ b/src/Utilities/Cryptography/Srp.cs
@@ -30,41 +30,61 @@ public class Srp
/// <summary>
/// Generate a verifier for a user.
/// </summary>
- /// <param name="email">Email.</param>
- /// <param name="passwordHash">Hash as output of Argon2id.</param>
- /// <param name="salt">Salt.</param>
+ /// <param name="privateKey">Hash as output of Argon2id.</param>
/// <returns>Verifier as string.</returns>
- public static string GenerateVerifier(string email, string passwordHash, string salt)
+ public static string GenerateVerifier(string privateKey)
{
var client = new SrpClient();
- var privateKey = client.DerivePrivateKey(salt, email, passwordHash);
var verifier = client.DeriveVerifier(privateKey);
return verifier;
}
+ /// <summary>
+ /// Derive a private key for a user.
+ /// </summary>
+ /// <param name="salt">Salt.</param>
+ /// <param name="email">Email.</param>
+ /// <param name="passwordHash">PasswordHash.</param>
+ /// <returns>Private key as string.</returns>
+ public static string DerivePrivateKey(string salt, string email, string passwordHash)
+ {
+ var client = new SrpClient();
+ return client.DerivePrivateKey(salt, email, passwordHash);
+ }
+
/// <summary>
/// Generate an ephemeral value for the client.
/// </summary>
/// <returns>Ephemeral as string.</returns>
- public static SrpEphemeral GenerateEphemeral()
+ public static SrpEphemeral GenerateEphemeralClient()
{
var client = new SrpClient();
return client.GenerateEphemeral();
}
+ /// <summary>
+ /// Generate an ephemeral value for the client.
+ /// </summary>
+ /// <param name="verifier">Verifier.</param>
+ /// <returns>Ephemeral as string.</returns>
+ public static SrpEphemeral GenerateEphemeralServer(string verifier)
+ {
+ var server = new SrpServer();
+ return server.GenerateEphemeral(verifier);
+ }
+
/// <summary>
/// Derive a shared session key on the client side.
/// </summary>
- /// <param name="passwordHash">Password hash.</param>
+ /// <param name="privateKey">Password hash.</param>
/// <param name="clientEphemeralSecret">Client ephemeral secret.</param>
/// <param name="serverPublicEphemeral">Server public ephemeral.</param>
/// <param name="salt">Salt.</param>
/// <param name="email">Email.</param>
/// <returns>session.</returns>
- public static SrpSession DeriveSessionClient(string passwordHash, string clientEphemeralSecret, string serverPublicEphemeral, string salt, string email)
+ public static SrpSession DeriveSessionClient(string privateKey, string clientEphemeralSecret, string serverPublicEphemeral, string salt, string email)
{
var client = new SrpClient();
- var privateKey = client.DerivePrivateKey(salt, email, passwordHash);
return client.DeriveSession(
clientEphemeralSecret,
serverPublicEphemeral,