Skip to content

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

Update family sharing name decryption flow (#2159)

Leendert de Borst51493244e210
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/settings/FamilySharingSettings.tsx b/apps/browser-extension/src/entrypoints/popup/pages/settings/FamilySharingSettings.tsx
index 72e2392a7..c43efbad1 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/settings/FamilySharingSettings.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/settings/FamilySharingSettings.tsx
@@ -65,7 +65,7 @@ const FamilySharingSettings: React.FC = () => {
try {
const loaded = await SharingService.getOverview(webApi);
setOverview(loaded);
- setInvitationNames(sqliteClient ? await SharingService.openInvitationNames(sqliteClient, loaded.receivedInvitations) : {});
+ setInvitationNames(await SharingService.openInvitationNames(loaded.receivedInvitations));
setVaultNames(sqliteClient ? multiManifestRendering.displayNames(sqliteClient) : {});
setError(null);
} catch {
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 25890754b..61e90568f 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
@@ -349,6 +349,16 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
promise.resolve(vaultStore.database.getPersonalManifestId())
}
+ /**
+ * Decrypt an invitation's vault name with the session account private key; null when the session holds none that opens it.
+ * @param encryptedName The base64 RSA-OAEP ciphertext of the name
+ * @param promise The promise to resolve
+ */
+ @ReactMethod
+ override fun decryptInvitationName(encryptedName: String, promise: Promise) {
+ promise.resolve(vaultStore.decryptWithAccountPrivateKey(encryptedName))
+ }
+
/**
* Resolve and store the vault key right after login from the unlock key (see VaultStore.resolveVaultKey).
* Resolves with the stored key; rejects with the native error code when the chain does not open or the session is gone.
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 33b4039dd..2d3642b2b 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
@@ -12,6 +12,8 @@ import net.aliasvault.app.vaultstore.models.StoreVaultResult
import net.aliasvault.app.vaultstore.models.TotpCode
import net.aliasvault.app.vaultstore.models.VaultMutationScope
import net.aliasvault.app.vaultstore.storageprovider.StorageProvider
+import uniffi.aliasvault_core.VaultException
+import uniffi.aliasvault_core.rsaDecrypt
import kotlin.coroutines.resume
/**
@@ -250,6 +252,20 @@ class VaultStore(
internal val accountPrivateKey: String?
get() = crypto.accountPrivateKey
+ /**
+ * Decrypt base64 RSA-OAEP ciphertext with the session's account private key as UTF-8 text, or null when the session
+ * holds no private key or it does not open the ciphertext.
+ */
+ fun decryptWithAccountPrivateKey(base64Ciphertext: String): String? {
+ val privateKey = accountPrivateKey ?: return null
+ return try {
+ rsaDecrypt(base64Ciphertext, privateKey).toString(Charsets.UTF_8)
+ } catch (e: VaultException) {
+ Log.w(TAG, "The account private key did not open the ciphertext", e)
+ null
+ }
+ }
+
/**
* Derive a key from a password using Argon2Id.
*/
diff --git a/apps/mobile-app/app/(tabs)/settings/family-sharing.tsx b/apps/mobile-app/app/(tabs)/settings/family-sharing.tsx
index 968363afd..dd2762d33 100644
--- a/apps/mobile-app/app/(tabs)/settings/family-sharing.tsx
+++ b/apps/mobile-app/app/(tabs)/settings/family-sharing.tsx
@@ -49,7 +49,6 @@ export default function FamilySharingScreen(): React.ReactNode {
const [overview, setOverview] = useState<GroupOverviewResponse | null>(null);
const [vaultNames, setVaultNames] = useState<Record<string, string>>({});
- const [invitationNames, setInvitationNames] = useState<Record<string, string>>({});
const [error, setError] = useState<string | null>(null);
const [notice, setNotice] = useState<string | null>(null);
const [busy, setBusy] = useState(false);
@@ -58,6 +57,7 @@ export default function FamilySharingScreen(): React.ReactNode {
const [expandedRosters, setExpandedRosters] = useState<Record<string, boolean>>({});
const [newVaultNames, setNewVaultNames] = useState<Record<string, string>>({});
const [pendingVaultRename, setPendingVaultRename] = useState<{ group: GroupInfo; manifest: SharedManifestInfo } | null>(null);
+ const [invitationNames, setInvitationNames] = useState<Record<string, string>>({});
/**
* Load the families, their shared folders and the open invitations, plus the names this vault has for them.
@@ -66,12 +66,12 @@ export default function FamilySharingScreen(): React.ReactNode {
try {
const loaded = await SharingService.getOverview(webApi);
setOverview(loaded);
+ setInvitationNames(await SharingService.openInvitationNames(loaded.receivedInvitations, encryptedName => NativeVaultManager.decryptInvitationName(encryptedName)));
if (sqliteClient) {
// A shared vault is shown as a top-level folder.
const folders = await sqliteClient.folders.getAll();
setVaultNames(Object.fromEntries(folders.filter(folder => multiManifestRendering.isVirtualFolder(folder)).map(folder => [folder.Id.toLowerCase(), folder.Name])));
- setInvitationNames(await SharingService.openInvitationNamesWith(async publicKey => (await sqliteClient.encryptionKeys.getAccountKeypair(publicKey))?.PrivateKey ?? null, loaded.receivedInvitations));
}
setError(null);
diff --git a/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm b/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm
index 12232b8b4..2a3facc92 100644
--- a/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm
+++ b/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm
@@ -133,6 +133,10 @@
[vaultManager getPersonalManifestId:resolve rejecter:reject];
}
+- (void)decryptInvitationName:(NSString *)encryptedName resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
+ [vaultManager decryptInvitationName:encryptedName resolver:resolve rejecter:reject];
+}
+
- (void)unlockVault:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
[vaultManager unlockVault:resolve rejecter:reject];
}
diff --git a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
index 3dddb0fbd..32d625298 100644
--- a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
+++ b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
@@ -141,6 +141,14 @@ public class VaultManager: NSObject {
resolve(vaultStore.getPersonalManifestId())
}
+ /// Decrypt an invitation's vault name with the session account private key; nil when the session holds none that opens it.
+ @objc
+ func decryptInvitationName(_ encryptedName: String,
+ resolver resolve: @escaping RCTPromiseResolveBlock,
+ rejecter reject: @escaping RCTPromiseRejectBlock) {
+ resolve(vaultStore.decryptWithAccountPrivateKey(encryptedName))
+ }
+
/// Resolve and store the vault key right after login from the password-derived key (see VaultStore.resolveVaultKey).
@objc
func resolveVaultKey(_ base64DerivedKey: String,
diff --git a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Crypto.swift b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Crypto.swift
index d9c726dc2..a954c3de3 100644
--- a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Crypto.swift
+++ b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Crypto.swift
@@ -141,6 +141,15 @@ extension VaultStore {
return (vaultEncryptionKey, accountPrivateKey)
}
+ /// Decrypt base64 RSA-OAEP ciphertext with the session's account private key as UTF-8 text, or nil when the session holds
+ /// no private key or it does not open the ciphertext.
+ public func decryptWithAccountPrivateKey(_ base64Ciphertext: String) -> String? {
+ guard let privateKey = accountPrivateKey, let plaintext = try? RustCoreFramework.rsaDecrypt(base64Ciphertext: base64Ciphertext, privateKeyJwk: privateKey) else {
+ return nil
+ }
+ return String(data: plaintext, encoding: .utf8)
+ }
+
/// Decrypt a wrapped key with the given key.
private func unwrapKey(_ base64Blob: String, with key: Data) throws -> Data {
guard let blob = Data(base64Encoded: base64Blob) else {
diff --git a/apps/mobile-app/specs/NativeVaultManager.ts b/apps/mobile-app/specs/NativeVaultManager.ts
index bd4fe2ed8..0ee0aeafc 100644
--- a/apps/mobile-app/specs/NativeVaultManager.ts
+++ b/apps/mobile-app/specs/NativeVaultManager.ts
@@ -76,6 +76,7 @@ export interface Spec extends TurboModule {
getAccountKeyChain(): Promise<string | null>;
resolveVaultKey(base64DerivedKey: string): Promise<string>;
getPersonalManifestId(): Promise<string | null>;
+ decryptInvitationName(encryptedName: string): Promise<string | null>;
hasEncryptedDatabase(): Promise<boolean>;
getEncryptedDatabase(): Promise<string | null>;
diff --git a/core/client/src/sharing/SharingService.ts b/core/client/src/sharing/SharingService.ts
index 5e7ebb173..d9beb2c0b 100644
--- a/core/client/src/sharing/SharingService.ts
+++ b/core/client/src/sharing/SharingService.ts
@@ -7,7 +7,6 @@ import { getPlatform } from '../platform/ClientPlatform';
import { devWarn } from '../platform/Logger';
import type { WebApiService } from '../api/WebApiService';
-import type { SqliteClient } from '../database/SqliteClient';
/**
* Vault sharing logic. A shared manifest is a non-personal VaultManifest server-side, owned by a group and encrypted with its own VEK.
@@ -25,9 +24,9 @@ export type SharingApi = Pick<WebApiService, 'get' | 'post' | 'delete'>;
export type SrpChallengeResponder = (challenge: DeleteSharedManifestInitiateResponse) => Promise<DeleteSharedManifestRequest>;
/**
- * Finds the private key that opens something encrypted for the given public key, or null when this client holds none.
+ * Decrypts a vault name encrypted into an invitation for the given public key, or returns null when this session holds no key that opens it.
*/
-export type PrivateKeyResolver = (publicKey: string) => Promise<string | null>;
+export type InvitationNameDecryptor = (encryptedName: string, recipientPublicKey: string) => Promise<string | null>;
/**
* A manifest's VEK as this account holds it.
@@ -63,21 +62,12 @@ export class SharingService {
/**
* Decrypt the vault names encrypted into the invitations addressed to this account.
- * @param sqliteClient - the open local vault, which holds this account's superseded private keys.
* @param invitations - the invitations as served by the API.
+ * @param decryptName - decrypts one name; defaults to the session account private key this realm holds. The mobile app
+ * passes a native call instead, as its private key never leaves the native layer.
* @returns The name of each invitation's vault, keyed by invitation id; invitations whose name will not open are left out.
*/
- public static async openInvitationNames(sqliteClient: SqliteClient, invitations: ReceivedManifestInvitation[]): Promise<Record<string, string>> {
- return this.openInvitationNamesWith(publicKey => this.resolveGrantPrivateKey(sqliteClient, publicKey), invitations);
- }
-
- /**
- * Decrypt the vault names encrypted into the invitations addressed to this account, for a host that keeps its keys elsewhere.
- * @param resolvePrivateKey - finds the private key for the public key an invitation was encrypted for.
- * @param invitations - the invitations as served by the API.
- * @returns The name of each invitation's vault, keyed by invitation id; invitations whose name will not open are left out.
- */
- public static async openInvitationNamesWith(resolvePrivateKey: PrivateKeyResolver, invitations: ReceivedManifestInvitation[]): Promise<Record<string, string>> {
+ public static async openInvitationNames(invitations: ReceivedManifestInvitation[], decryptName: InvitationNameDecryptor = (name, key) => this.decryptWithSessionKey(name, key)): Promise<Record<string, string>> {
const names: Record<string, string> = {};
for (const invitation of invitations) {
@@ -85,14 +75,13 @@ export class SharingService {
continue;
}
- const privateKey = await resolvePrivateKey(invitation.recipientPublicKey);
- if (!privateKey) {
- devWarn(`[Sharing] No account key in this vault decrypts the name encrypted into invitation ${invitation.id}.`);
- continue;
- }
-
try {
- names[invitation.id] = new TextDecoder().decode(await EncryptionUtility.decryptWithPrivateKey(invitation.encryptedName, privateKey));
+ const name = await decryptName(invitation.encryptedName, invitation.recipientPublicKey);
+ if (name === null) {
+ devWarn(`[Sharing] This session holds no account private key that decrypts the name encrypted into invitation ${invitation.id}.`);
+ continue;
+ }
+ names[invitation.id] = name;
} catch (error) {
devWarn(`[Sharing] Failed to decrypt the name encrypted into invitation ${invitation.id}.`, error);
}
@@ -178,19 +167,20 @@ export class SharingService {
}
/**
- * The private key that opens a grant made out to `publicKey`.
- * @param sqliteClient - the open local vault.
- * @param publicKey - the public half the grant was encrypted for.
+ * Decrypt something encrypted for `publicKey` with the account private key of this session.
+ * @param ciphertext - the base64 RSA-OAEP ciphertext.
+ * @param publicKey - the public half it was encrypted for.
+ * @returns The UTF-8 plaintext, or null when this session holds no private key for `publicKey`.
*/
- private static async resolveGrantPrivateKey(sqliteClient: SqliteClient, publicKey: string): Promise<string | null> {
- if (await VaultKeyService.getAccountPublicKey() === publicKey) {
- const sessionPrivateKey = await VaultKeyService.getSessionAccountPrivateKey();
- if (sessionPrivateKey) {
- return sessionPrivateKey;
- }
+ private static async decryptWithSessionKey(ciphertext: string, publicKey: string): Promise<string | null> {
+ if (await VaultKeyService.getAccountPublicKey() !== publicKey) {
+ return null;
}
-
- return sqliteClient.encryptionKeys.getAccountKeypair(publicKey)?.PrivateKey ?? null;
+ const privateKey = await VaultKeyService.getSessionAccountPrivateKey();
+ if (!privateKey) {
+ return null;
+ }
+ return new TextDecoder().decode(await EncryptionUtility.decryptWithPrivateKey(ciphertext, privateKey));
}
}