Skip to content

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

Update Rust core bindings (#2469)

Leendert de Borst86ee7d5826fc
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/NativeVaultManager.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/NativeVaultManager.kt
index 4218b60c5..353830602 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/NativeVaultManager.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/NativeVaultManager.kt
@@ -243,7 +243,7 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
/**
* Open a session in memory with the unlock key, without keystore persistence.
- * Use this to test if a password-derived key is valid before persisting.
+ * Use this to test if a key is valid before persisting.
* @param base64UnlockKey The unlock key as a base64 encoded string
* @param promise The promise to resolve
*/
@@ -864,7 +864,7 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
* Derive a key from a password using Argon2Id.
* @param password The password to derive from
* @param salt The salt to use
- * @param encryptionType The type of encryption (should be "Argon2Id")
+ * @param encryptionType The type of encryption ("Argon2Id" or "Argon2IdHkdf")
* @param encryptionSettings JSON string with encryption parameters
* @param promise The promise to resolve
*/
@@ -1972,39 +1972,6 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
}
}
- /**
- * Answer a server's SRP challenge with the unlock key of the open session (see VaultStore.deriveSrpProof).
- * @param salt The salt the initiate call returned.
- * @param srpIdentity The SRP identity the initiate call returned.
- * @param serverEphemeral The server public ephemeral the initiate call returned.
- * @param promise The promise to resolve with the client public ephemeral and session proof.
- */
- @ReactMethod
- override fun deriveSrpProof(salt: String, srpIdentity: String, serverEphemeral: String, promise: Promise) {
- vaultStore.deriveSrpProof(
- salt,
- srpIdentity,
- serverEphemeral,
- object : CryptoOperationCallback {
- override fun onSuccess(result: String) {
- val proof = JSONObject(result)
- val resultMap = Arguments.createMap().apply {
- putString("clientPublicEphemeral", proof.getString("clientPublicEphemeral"))
- putString("clientSessionProof", proof.getString("clientSessionProof"))
- }
- promise.resolve(resultMap)
- }
-
- override fun onError(e: Exception) {
- Log.e(TAG, "Error deriving the SRP proof", e)
- promise.reject("SRP_PROOF_ERROR", "Failed to derive the SRP proof: ${e.message}", e)
- }
- },
- )
- }
-
- // MARK: - Sync State Management
-
/**
* Get the sync state (isDirty, mutationSequence, serverRevision, isSyncing).
* @param promise The promise to resolve.
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/RustCoreDispatcher.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/RustCoreDispatcher.kt
index 22211a144..ec28afe4a 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/RustCoreDispatcher.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/RustCoreDispatcher.kt
@@ -3,8 +3,11 @@ package net.aliasvault.app.nativevaultmanager
import android.util.Base64
import org.json.JSONArray
import org.json.JSONObject
+import uniffi.aliasvault_core.KeyChainException
import uniffi.aliasvault_core.argon2DeriveKey
import uniffi.aliasvault_core.decodeEmailSource
+import uniffi.aliasvault_core.deriveKek
+import uniffi.aliasvault_core.deriveSrpPasswordHash
import uniffi.aliasvault_core.extractDomain
import uniffi.aliasvault_core.extractEmailAttachment
import uniffi.aliasvault_core.extractRootDomain
@@ -20,6 +23,7 @@ import uniffi.aliasvault_core.getIdentityLanguages
import uniffi.aliasvault_core.getSyncableTableNames
import uniffi.aliasvault_core.isRelatedOriginAllowed
import uniffi.aliasvault_core.isRpIdAllowedForHost
+import uniffi.aliasvault_core.openAccountKeyChain
import uniffi.aliasvault_core.parseEmailSource
import uniffi.aliasvault_core.pruneVaultJson
import uniffi.aliasvault_core.selectFaviconTarget
@@ -77,6 +81,9 @@ object RustCoreDispatcher {
"extractEmailAttachment" -> json(extractEmailAttachment(args.bytes(0), args.uint(1), args.optionalBytes(2)))
"argon2DeriveKey" -> json(argon2DeriveKey(args.string(0), args.string(1), args.string(2)))
+ "deriveKek" -> json(deriveKek(args.bytes(0)))
+ "deriveSrpPasswordHash" -> json(deriveSrpPasswordHash(args.bytes(0), args.string(1)))
+ "openAccountKeyChain" -> openKeyChain(args.bytes(0), args.string(1), args.string(2), args.optionalString(3))
"srpGenerateSalt" -> json(srpGenerateSalt())
"srpDerivePrivateKey" -> json(srpDerivePrivateKey(args.string(0), args.string(1), args.string(2)))
@@ -131,6 +138,24 @@ object RustCoreDispatcher {
/** JSON-encode a list of strings. */
private fun json(values: List<String>): String = JSONArray(values).toString()
+ /** Open a key chain and report the outcome as the `KeyChainOpenResult` JSON the client core expects. */
+ @Suppress("SwallowedException") // A failure is reported as its status, not thrown.
+ private fun openKeyChain(storedKey: ByteArray, encryptedAccountKey: String, encryptedVek: String, encryptedAccountPrivateKey: String?): String {
+ val result = JSONObject()
+ try {
+ val keys = openAccountKeyChain(storedKey, encryptedAccountKey, encryptedVek, encryptedAccountPrivateKey)
+ result.put("status", "opened")
+ .put("vaultEncryptionKey", Base64.encodeToString(keys.vaultEncryptionKey, Base64.NO_WRAP))
+ .put("accountKey", Base64.encodeToString(keys.accountKey, Base64.NO_WRAP))
+ .put("accountPrivateKey", keys.accountPrivateKey ?: JSONObject.NULL)
+ } catch (e: KeyChainException.UnlockKeyRejected) {
+ result.put("status", "unlockKeyRejected")
+ } catch (e: KeyChainException.KeyChainUnreadable) {
+ result.put("status", "keyChainUnreadable").put("message", e.message ?: "")
+ }
+ return result.toString()
+ }
+
/** JSON-encode raw bytes as a base64 string. */
private fun json(bytes: ByteArray): String = json(Base64.encodeToString(bytes, Base64.NO_WRAP))
}
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/passwordunlock/PasswordUnlockActivity.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/passwordunlock/PasswordUnlockActivity.kt
index 8185e2d92..ac8df772b 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/passwordunlock/PasswordUnlockActivity.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/passwordunlock/PasswordUnlockActivity.kt
@@ -50,7 +50,7 @@ class PasswordUnlockActivity : AppCompatActivity() {
/** Result code for max attempts reached - user has been logged out. */
const val RESULT_MAX_ATTEMPTS_REACHED = Activity.RESULT_FIRST_USER + 1
- /** Intent extra key for the unlock key, the password-derived KEK (returned on success). */
+ /** Intent extra key for the unlock key, the password's Argon2id output (returned on success). */
const val EXTRA_UNLOCK_KEY = "unlock_key"
/** Intent extra key for custom title (optional). */
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.kt
index 0732f53af..b02cd7ca4 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.kt
@@ -204,13 +204,6 @@ class VaultStore(
crypto.getUnlockKey(callback, auth.getAuthMethods())
}
- /**
- * Answer a server's SRP challenge with the unlock key of the open session (see VaultCrypto.deriveSrpProof).
- */
- fun deriveSrpProof(salt: String, srpIdentity: String, serverEphemeral: String, callback: CryptoOperationCallback) {
- crypto.deriveSrpProof(salt, srpIdentity, serverEphemeral, callback, auth.getAuthMethods())
- }
-
/**
* Check if biometric authentication is enabled and available.
*/
@@ -302,7 +295,7 @@ class VaultStore(
val encryptionType = paramsJson.getString("encryptionType")
val encryptionSettings = paramsJson.getString("encryptionSettings")
- // Derive the KEK from the password and unwrap the chain; a wrong password fails the unwrap.
+ // Derive the unlock key from the password and open the chain; a wrong password fails to open it.
val derivedKey = crypto.deriveKeyFromPassword(password, salt, encryptionType, encryptionSettings)
val vaultEncryptionKey = crypto.openAccountKeyChain(derivedKey).vaultEncryptionKey
@@ -949,7 +942,7 @@ class VaultStore(
}
/**
- * Unlock with PIN. Returns the unlock key the PIN protects, to open the session with.
+ * Unlock with PIN. Returns the key the PIN protects, to open the session with.
*/
@Throws(Exception::class)
fun unlockWithPin(pinValue: String): String {
diff --git a/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm b/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm
index a9096049c..2d0b07227 100644
--- a/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm
+++ b/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm
@@ -365,10 +365,6 @@
[vaultManager authenticateUser:title subtitle:subtitle allowedMethods:allowedMethods buttonText:buttonText recentUnlockGraceSeconds:recentUnlockGraceSeconds resolver:resolve rejecter:reject];
}
-- (void)deriveSrpProof:(NSString *)salt srpIdentity:(NSString *)srpIdentity serverEphemeral:(NSString *)serverEphemeral resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
- [vaultManager deriveSrpProof:salt srpIdentity:srpIdentity serverEphemeral:serverEphemeral resolver:resolve rejecter:reject];
-}
-
// MARK: - QR Code Scanner
- (void)scanQRCode:(NSArray<NSString *> *)prefixes statusText:(NSString *)statusText resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
diff --git a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
index bc35a533b..136456883 100644
--- a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
+++ b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
@@ -62,8 +62,8 @@ public class VaultManager: NSObject {
}
}
- /// Open a session in memory with the unlock key (the password-derived KEK), without keychain persistence.
- /// Use this to test if a password-derived key is valid before persisting.
+ /// Open a session in memory with the unlock key or stored key, without keychain persistence.
+ /// Use this to test if a key is valid before persisting.
@objc
func storeUnlockKeyInMemory(_ base64UnlockKey: String,
resolver resolve: @escaping RCTPromiseResolveBlock,
@@ -76,7 +76,7 @@ public class VaultManager: NSObject {
}
}
- /// Open a session with the unlock key (the password-derived KEK) AND persist it to keychain if Face ID is enabled.
+ /// Open a session with the unlock key or stored key AND persist the stored key to keychain if Face ID is enabled.
@objc
func storeUnlockKey(_ base64UnlockKey: String,
resolver resolve: @escaping RCTPromiseResolveBlock,
@@ -1417,28 +1417,6 @@ public class VaultManager: NSObject {
}
}
- /// Answer a server's SRP challenge with the unlock key of the open session (see VaultStore.deriveSrpProof).
- @objc
- func deriveSrpProof(_ salt: String,
- srpIdentity: String,
- serverEphemeral: String,
- resolver resolve: @escaping RCTPromiseResolveBlock,
- rejecter reject: @escaping RCTPromiseRejectBlock) {
- DispatchQueue.global(qos: .userInitiated).async { [weak self] in
- guard let self = self else {
- reject("INTERNAL_ERROR", "VaultManager instance deallocated", nil)
- return
- }
-
- do {
- let proof = try self.vaultStore.deriveSrpProof(salt: salt, srpIdentity: srpIdentity, serverEphemeral: serverEphemeral)
- resolve(["clientPublicEphemeral": proof.clientPublicEphemeral, "clientSessionProof": proof.clientSessionProof])
- } catch {
- reject("SRP_PROOF_ERROR", "Failed to derive the SRP proof: \(error.localizedDescription)", error)
- }
- }
- }
-
// MARK: - Sync State Management
@objc
@@ -1595,6 +1573,11 @@ private enum RustCoreDispatcher {
case "argon2DeriveKey":
return try json(bytes: try RustCoreFramework.argon2DeriveKey(password: try args.string(0), salt: try args.string(1), encryptionSettings: try args.string(2)))
+ case "deriveKek": return try json(bytes: RustCoreFramework.deriveKek(unlockKey: try args.data(0)))
+ case "deriveSrpPasswordHash": return try json(try RustCoreFramework.deriveSrpPasswordHash(unlockKey: try args.data(0), encryptionType: try args.string(1)))
+ case "openAccountKeyChain":
+ let storedKey = try args.data(0)
+ return try openKeyChain(storedKey: storedKey, encryptedAccountKey: try args.string(1), encryptedVek: try args.string(2), encryptedAccountPrivateKey: args.optionalString(3))
case "srpGenerateSalt": return try json(RustCoreFramework.srpGenerateSalt())
case "srpDerivePrivateKey":
@@ -1631,6 +1614,25 @@ private enum RustCoreDispatcher {
}
/// JSON-encode raw bytes as a base64 string.
+ /// Open a key chain and report the outcome as the `KeyChainOpenResult` JSON the client core expects.
+ private static func openKeyChain(storedKey: Data, encryptedAccountKey: String, encryptedVek: String, encryptedAccountPrivateKey: String?) throws -> String {
+ do {
+ let keys = try RustCoreFramework.openAccountKeyChain(
+ storedKey: storedKey, encryptedAccountKey: encryptedAccountKey, encryptedVek: encryptedVek, encryptedAccountPrivateKey: encryptedAccountPrivateKey
+ )
+ return try json([
+ "status": "opened",
+ "vaultEncryptionKey": keys.vaultEncryptionKey.base64EncodedString(),
+ "accountKey": keys.accountKey.base64EncodedString(),
+ "accountPrivateKey": keys.accountPrivateKey as Any? ?? NSNull()
+ ])
+ } catch KeyChainError.UnlockKeyRejected {
+ return try json(["status": "unlockKeyRejected"])
+ } catch KeyChainError.KeyChainUnreadable(let message) {
+ return try json(["status": "keyChainUnreadable", "message": message])
+ }
+ }
+
private static func json(bytes: Data) throws -> String {
return try json(bytes.base64EncodedString())
}
diff --git a/apps/mobile-app/ios/VaultStoreKit/VaultStore+PublicKeyCrypto.swift b/apps/mobile-app/ios/VaultStoreKit/VaultStore+PublicKeyCrypto.swift
index 118b4df97..a12cc87c0 100644
--- a/apps/mobile-app/ios/VaultStoreKit/VaultStore+PublicKeyCrypto.swift
+++ b/apps/mobile-app/ios/VaultStoreKit/VaultStore+PublicKeyCrypto.swift
@@ -3,7 +3,7 @@ import Security
/// Extension for the VaultStore class to handle RSA public key encryption
extension VaultStore {
- /// Encrypts the unlock key (the password-derived KEK) using an RSA public key for mobile login
+ /// Encrypts the session's stored key using an RSA public key for mobile login
/// The receiving client opens the account key chain with it.
/// - Parameter publicKeyJWK: The RSA public key in JWK format (JSON string)
/// - Returns: The encrypted unlock key
diff --git a/apps/mobile-app/ios/VaultStoreKit/VaultStore.swift b/apps/mobile-app/ios/VaultStoreKit/VaultStore.swift
index d0c5520ac..2126379b0 100644
--- a/apps/mobile-app/ios/VaultStoreKit/VaultStore.swift
+++ b/apps/mobile-app/ios/VaultStoreKit/VaultStore.swift
@@ -32,8 +32,8 @@ public class VaultStore {
/// The live vault, held in the Rust core's memory. Nil while vault is locked.
internal var dbConnection: SqliteMemoryDatabase?
- /// The unlock key: the password-derived KEK. The one secret the unlocked session holds in memory, and the key the
- /// unlock methods (keychain, PIN) protect. Every other key is derived from it and the cached account key chain.
+ /// The stored key: the one secret the unlocked session holds in memory, and the key the unlock methods (keychain,
+ /// PIN) protect. Every other key is derived from it and the cached account key chain.
internal var unlockKey: Data?
/// The encryption key for the vault, derived from the unlock key. Nil while the vault is locked.
@@ -46,8 +46,8 @@ public class VaultStore {
return sessionKeys?.accountPrivateKey
}
- /// What the unlock key opens in the cached account key chain.
- private var sessionKeys: (vaultEncryptionKey: Data, accountPrivateKey: String?)? {
+ /// What the stored key opens in the cached account key chain.
+ private var sessionKeys: SessionKeys? {
guard let unlockKey = unlockKey else {
return nil
}
diff --git a/apps/mobile-app/platform/NativeRustCore.ts b/apps/mobile-app/platform/NativeRustCore.ts
index 2bc91662b..2c0a732ef 100644
--- a/apps/mobile-app/platform/NativeRustCore.ts
+++ b/apps/mobile-app/platform/NativeRustCore.ts
@@ -57,6 +57,9 @@ export const nativeRustCore: IRustCore = {
extractEmailAttachment: (source, index, detachedBody) => callForBytes('extractEmailAttachment', base64(source), index, detachedBody ? base64(detachedBody) : null),
argon2DeriveKey: (password, salt, encryptionSettings) => callForBytes('argon2DeriveKey', password, salt, encryptionSettings),
+ deriveKek: (unlockKeyBase64) => call('deriveKek', unlockKeyBase64),
+ deriveSrpPasswordHash: (unlockKeyBase64, encryptionType) => call('deriveSrpPasswordHash', unlockKeyBase64, encryptionType),
+ openAccountKeyChain: (storedKey, encryptedAccountKey, encryptedVek, encryptedAccountPrivateKey) => call('openAccountKeyChain', storedKey, encryptedAccountKey, encryptedVek, encryptedAccountPrivateKey),
srpGenerateSalt: () => call('srpGenerateSalt'),
srpDerivePrivateKey: (salt, identity, passwordHash) => call('srpDerivePrivateKey', salt, identity, passwordHash),
diff --git a/apps/mobile-app/specs/NativeVaultManager.ts b/apps/mobile-app/specs/NativeVaultManager.ts
index 46b5482b8..dedd8c4e0 100644
--- a/apps/mobile-app/specs/NativeVaultManager.ts
+++ b/apps/mobile-app/specs/NativeVaultManager.ts
@@ -149,9 +149,6 @@ export interface Spec extends TurboModule {
// recentUnlockGraceSeconds: If > 0, skip the prompt when a successful biometric or PIN unlock happened within this many seconds ago. Pass 0 to always prompt.
authenticateUser(title: string | null, subtitle: string | null, allowedMethods: string[] | null, buttonText: string | null, recentUnlockGraceSeconds: number): Promise<boolean>;
- // Answer a server's SRP challenge with the available unlock key.
- deriveSrpProof(salt: string, srpIdentity: string, serverEphemeral: string): Promise<{ clientPublicEphemeral: string; clientSessionProof: string }>;
-
// QR code scanner
// Scan a QR code and return the scanned data. Returns null if cancelled or failed.
// If prefixes is provided, only QR codes starting with one of these prefixes will be accepted.
diff --git a/core/client/src/rust/RustCore.ts b/core/client/src/rust/RustCore.ts
index dfe15bafe..0f19781c7 100644
--- a/core/client/src/rust/RustCore.ts
+++ b/core/client/src/rust/RustCore.ts
@@ -12,7 +12,7 @@ import { deviceLanguage } from '../platform/DeviceLanguage';
import { AutofillMatchingMode } from './RustCoreTypes';
import type { IRustCore } from './RustCoreBinding';
-import type { CodecCanonicalized, CodecCanonicalizeInput, FaviconTarget, IdentityNameInput, IdentityRequest, ParsedEmail } from './RustCoreTypes';
+import type { CodecCanonicalized, CodecCanonicalizeInput, FaviconTarget, IdentityNameInput, IdentityRequest, KeyChainOpenResult, ParsedEmail } from './RustCoreTypes';
import type { Identity } from '@aliasvault/models/identity';
import type { Item, PasswordSettings } from '@aliasvault/models/vault';
@@ -181,6 +181,20 @@ export async function argon2DeriveKey(password: string, salt: string, encryption
return rustCore().argon2DeriveKey(password, salt, encryptionSettings);
}
+/**
+ * The KEK (base64) that wraps the Account Key, derived from the unlock key (base64).
+ */
+export async function deriveKek(unlockKeyBase64: string): Promise<string> {
+ return rustCore().deriveKek(unlockKeyBase64);
+}
+
+/**
+ * Open a key chain with a stored key: the Account Key, or an unlock key that is then replaced by the Account Key.
+ */
+export async function openAccountKeyChain(storedKey: string, encryptedAccountKey: string, encryptedVek: string, encryptedAccountPrivateKey: string | null): Promise<KeyChainOpenResult> {
+ return rustCore().openAccountKeyChain(storedKey, encryptedAccountKey, encryptedVek, encryptedAccountPrivateKey);
+}
+
/**
* Generate a random 32-byte seed as a 64-character hex string, suitable for the
* `seed` argument of {@link generatePassword}.
diff --git a/core/client/src/rust/RustCoreBinding.ts b/core/client/src/rust/RustCoreBinding.ts
index 0134f0a58..0b2f7a57e 100644
--- a/core/client/src/rust/RustCoreBinding.ts
+++ b/core/client/src/rust/RustCoreBinding.ts
@@ -1,4 +1,4 @@
-import type { CodecCanonicalized, CodecCanonicalizeInput, FaviconTarget, FilterCredentialsInput, FilterCredentialsOutput, ParsedEmail, SrpEphemeral, SrpSession } from './RustCoreTypes';
+import type { CodecCanonicalized, CodecCanonicalizeInput, FaviconTarget, FilterCredentialsInput, FilterCredentialsOutput, KeyChainOpenResult, ParsedEmail, SrpEphemeral, SrpSession } from './RustCoreTypes';
/**
* One running operation of the Rust vault sync engine.
@@ -41,6 +41,9 @@ export interface IRustCore {
extractEmailAttachment(source: Uint8Array, index: number, detachedBody?: Uint8Array): Promise<Uint8Array>;
argon2DeriveKey(password: string, salt: string, encryptionSettings: string): Promise<Uint8Array>;
+ deriveKek(unlockKeyBase64: string): Promise<string>;
+ deriveSrpPasswordHash(unlockKeyBase64: string, encryptionType: string): Promise<string>;
+ openAccountKeyChain(storedKey: string, encryptedAccountKey: string, encryptedVek: string, encryptedAccountPrivateKey: string | null): Promise<KeyChainOpenResult>;
srpGenerateSalt(): Promise<string>;
srpDerivePrivateKey(salt: string, identity: string, passwordHash: string): Promise<string>;
diff --git a/core/client/src/rust/RustCoreTypes.ts b/core/client/src/rust/RustCoreTypes.ts
index 4da61e281..2b8e394ab 100644
--- a/core/client/src/rust/RustCoreTypes.ts
+++ b/core/client/src/rust/RustCoreTypes.ts
@@ -80,6 +80,15 @@ export type SrpSession = {
key: string;
};
+/**
+ * The outcome of opening a key chain with a stored key (the Rust `open_account_key_chain`). Keys are base64; on
+ * success `accountKey` is what the caller stores in place of the key it passed in.
+ */
+export type KeyChainOpenResult =
+ | { status: 'opened'; vaultEncryptionKey: string; accountKey: string; accountPrivateKey: string | null }
+ | { status: 'unlockKeyRejected' }
+ | { status: 'keyChainUnreadable'; message: string };
+
/*
* Vault codec (manifest-v1 storage format).
*/
diff --git a/core/client/src/rust/WasmRustCore.ts b/core/client/src/rust/WasmRustCore.ts
index fd45fc668..e9b479e70 100644
--- a/core/client/src/rust/WasmRustCore.ts
+++ b/core/client/src/rust/WasmRustCore.ts
@@ -6,7 +6,7 @@ import initWasm, * as core from '../../wasm/aliasvault_core.js';
import { yieldToPaint } from '../utilities/YieldToPaint';
import type { IRustCore, IVaultSyncSession } from './RustCoreBinding';
-import type { CodecCanonicalized, CodecCanonicalizeInput, FaviconTarget, FilterCredentialsInput, FilterCredentialsOutput, ParsedEmail, SrpEphemeral, SrpSession } from './RustCoreTypes';
+import type { CodecCanonicalized, CodecCanonicalizeInput, FaviconTarget, FilterCredentialsInput, FilterCredentialsOutput, KeyChainOpenResult, ParsedEmail, SrpEphemeral, SrpSession } from './RustCoreTypes';
/**
* Where the host gets the `.wasm` binary from: bytes, or a fetch response for streaming instantiation.
@@ -75,6 +75,10 @@ export function createWasmRustCore(loadWasm: WasmLoader): IRustCore {
await yieldToPaint();
return ready(() => core.argon2DeriveKey(password, salt, encryptionSettings));
},
+ deriveKek: (unlockKeyBase64): Promise<string> => ready(() => core.deriveKek(unlockKeyBase64)),
+ deriveSrpPasswordHash: (unlockKeyBase64, encryptionType): Promise<string> => ready(() => core.deriveSrpPasswordHash(unlockKeyBase64, encryptionType)),
+ openAccountKeyChain: (storedKey, encryptedAccountKey, encryptedVek, encryptedAccountPrivateKey): Promise<KeyChainOpenResult> =>
+ ready(() => core.openAccountKeyChain(storedKey, encryptedAccountKey, encryptedVek, encryptedAccountPrivateKey ?? undefined) as KeyChainOpenResult),
srpGenerateSalt: (): Promise<string> => ready(() => core.srpGenerateSalt()),
srpDerivePrivateKey: (salt, identity, passwordHash): Promise<string> => ready(() => core.srpDerivePrivateKey(salt, identity, passwordHash)),