Skip to content

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

Replace argon2id react native with native iOS implementation to satisfy Xcode 26 reqs (#1241)

Leendert de Borst81a515573451
diff --git a/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm b/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm
index 0656caceb..98729eb65 100644
--- a/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm
+++ b/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm
@@ -133,6 +133,10 @@
[vaultManager setCurrentVaultRevisionNumber:revisionNumber resolver:resolve rejecter:reject];
}
+- (void)deriveKeyFromPassword:(NSString *)password salt:(NSString *)salt encryptionType:(NSString *)encryptionType encryptionSettings:(NSString *)encryptionSettings resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
+ [vaultManager deriveKeyFromPassword:password salt:salt encryptionType:encryptionType encryptionSettings:encryptionSettings resolver:resolve rejecter:reject];
+}
+
- (void)openAutofillSettingsPage:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
[vaultManager openAutofillSettingsPage:resolve rejecter:reject];
}
diff --git a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
index c804bf7d8..0382f51a1 100644
--- a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
+++ b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
@@ -367,6 +367,25 @@ public class VaultManager: NSObject {
}
}
+ @objc
+ func deriveKeyFromPassword(_ password: String,
+ salt: String,
+ encryptionType: String,
+ encryptionSettings: String,
+ resolver resolve: @escaping RCTPromiseResolveBlock,
+ rejecter reject: @escaping RCTPromiseRejectBlock) {
+ do {
+ let derivedKey = try vaultStore.deriveKeyFromPassword(password,
+ salt: salt,
+ encryptionType: encryptionType,
+ encryptionSettings: encryptionSettings)
+ // Return the derived key as base64 encoded string
+ resolve(derivedKey.base64EncodedString())
+ } catch {
+ reject("ARGON2_ERROR", "Failed to derive key from password: \(error.localizedDescription)", error)
+ }
+ }
+
@objc
func openAutofillSettingsPage(_ resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) {
diff --git a/apps/mobile-app/ios/Podfile b/apps/mobile-app/ios/Podfile
index 8fb3f05b0..b826a5a59 100644
--- a/apps/mobile-app/ios/Podfile
+++ b/apps/mobile-app/ios/Podfile
@@ -18,6 +18,7 @@ target 'AliasVault' do
pod 'SQLite.swift', '~> 0.14.0'
pod 'SwiftLint', :configurations => ['Debug']
pod 'Macaw', '~> 0.9.7'
+ pod 'SignalArgon2', '~> 1.3.2'
pod 'ExpoModulesCore', :path => '../node_modules/expo-modules-core'
if ENV['EXPO_USE_COMMUNITY_AUTOLINKING'] == '1'
@@ -79,14 +80,17 @@ end
target 'Autofill' do
pod 'SQLite.swift', '~> 0.14.0'
pod 'Macaw', '~> 0.9.7'
+ pod 'SignalArgon2', '~> 1.3.2'
end
target 'VaultStoreKit' do
pod 'SQLite.swift', '~> 0.14.0'
+ pod 'SignalArgon2', '~> 1.3.2'
end
target 'VaultStoreKitTests' do
pod 'SQLite.swift', '~> 0.14.0'
+ pod 'SignalArgon2', '~> 1.3.2'
end
target 'VaultUI' do
diff --git a/apps/mobile-app/ios/Podfile.lock b/apps/mobile-app/ios/Podfile.lock
index c4e93bc7e..baccef976 100644
--- a/apps/mobile-app/ios/Podfile.lock
+++ b/apps/mobile-app/ios/Podfile.lock
@@ -1,6 +1,5 @@
PODS:
- boost (1.84.0)
- - CatCrypto (0.3.2)
- DoubleConversion (1.1.6)
- EXConstants (17.1.7):
- ExpoModulesCore
@@ -2217,9 +2216,6 @@ PODS:
- React-logger (= 0.79.6)
- React-perflogger (= 0.79.6)
- React-utils (= 0.79.6)
- - RNArgon2 (2.0.1):
- - CatCrypto
- - React-Core
- RNCAsyncStorage (2.1.2):
- DoubleConversion
- glog
@@ -2492,6 +2488,7 @@ PODS:
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
+ - SignalArgon2 (1.3.2)
- SocketRocket (0.7.1)
- SQLite.swift (0.14.1):
- SQLite.swift/standard (= 0.14.1)
@@ -2609,21 +2606,21 @@ DEPENDENCIES:
- ReactAppDependencyProvider (from `build/generated/ios`)
- ReactCodegen (from `build/generated/ios`)
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
- - RNArgon2 (from `../node_modules/react-native-argon2`)
- "RNCAsyncStorage (from `../node_modules/@react-native-async-storage/async-storage`)"
- RNGestureHandler (from `../node_modules/react-native-gesture-handler`)
- RNReanimated (from `../node_modules/react-native-reanimated`)
- RNScreens (from `../node_modules/react-native-screens`)
- RNSVG (from `../node_modules/react-native-svg`)
+ - SignalArgon2 (~> 1.3.2)
- SQLite.swift (~> 0.14.0)
- SwiftLint
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)
SPEC REPOS:
trunk:
- - CatCrypto
- Macaw
- OpenSSL-Universal
+ - SignalArgon2
- SocketRocket
- SQLite.swift
- SwiftLint
@@ -2841,8 +2838,6 @@ EXTERNAL SOURCES:
:path: build/generated/ios
ReactCommon:
:path: "../node_modules/react-native/ReactCommon"
- RNArgon2:
- :path: "../node_modules/react-native-argon2"
RNCAsyncStorage:
:path: "../node_modules/@react-native-async-storage/async-storage"
RNGestureHandler:
@@ -2858,7 +2853,6 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
boost: 1dca942403ed9342f98334bf4c3621f011aa7946
- CatCrypto: a477899b6be4954e75be4897e732da098cc0a5a8
DoubleConversion: f16ae600a246532c4020132d54af21d0ddb2a385
EXConstants: 98bcf0f22b820f9b28f9fee55ff2daededadd2f8
EXJSONUtils: 1d3e4590438c3ee593684186007028a14b3686cd
@@ -2965,18 +2959,18 @@ SPEC CHECKSUMS:
ReactAppDependencyProvider: ae0be24eb18014a031b4b220cb3973d07c3cbaf8
ReactCodegen: a09f5c12174828282e5003f0d63b2871dd8b4b75
ReactCommon: 44c86ec3ace664c0f33b7a2ac89aced8304ef25e
- RNArgon2: 708e188b7a4d4ec8baf62463927c47abef453a94
RNCAsyncStorage: 39c42c1e478e1f5166d1db52b5055e090e85ad66
RNGestureHandler: 7d0931a61d7ba0259f32db0ba7d0963c3ed15d2b
RNReanimated: 2313402fe27fecb7237619e9c6fcee3177f08a65
RNScreens: f0678748c5310b49a3f920f1485f5ec477afd345
RNSVG: 794f269526df9ddc1f79b3d1a202b619df0368e3
+ SignalArgon2: 1c24183835ca861e6af06631c18b1671cdf35571
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
SQLite.swift: 2992550ebf3c5b268bf4352603e3df87d2a4ed72
SwiftLint: 3d48e2fb2a3468fdaccf049e5e755df22fb40c2c
SWXMLHash: dd733a457e9c4fe93b1538654057aefae4acb382
Yoga: dc7c21200195acacb62fa920c588e7c2106de45e
-PODFILE CHECKSUM: 9254f97341788b3995b61300689a0fff1692f333
+PODFILE CHECKSUM: ac288e273086bafdd610cafff08ccca0d164f7c3
COCOAPODS: 1.16.2
diff --git a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Crypto.swift b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Crypto.swift
index 5e8534c67..c598845e7 100644
--- a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Crypto.swift
+++ b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Crypto.swift
@@ -2,9 +2,55 @@ import Foundation
import CryptoKit
import LocalAuthentication
import Security
+import SignalArgon2
/// Extension for the VaultStore class to handle encryption/decryption
extension VaultStore {
+ /// Derives a key from a password using Argon2Id
+ public func deriveKeyFromPassword(_ password: String,
+ salt: String,
+ encryptionType: String,
+ encryptionSettings: String) throws -> Data {
+ guard encryptionType == "Argon2Id" else {
+ throw NSError(domain: "VaultStore", code: 13, userInfo: [NSLocalizedDescriptionKey: "Unsupported encryption type: \(encryptionType)"])
+ }
+
+ // Parse encryption settings JSON
+ guard let settingsData = encryptionSettings.data(using: .utf8),
+ let settings = try? JSONSerialization.jsonObject(with: settingsData, options: []) as? [String: Any],
+ let iterations = settings["Iterations"] as? UInt32,
+ let memorySize = settings["MemorySize"] as? UInt32,
+ let parallelism = settings["DegreeOfParallelism"] as? UInt32 else {
+ throw NSError(domain: "VaultStore", code: 14, userInfo: [NSLocalizedDescriptionKey: "Invalid encryption settings"])
+ }
+
+ // Convert password and salt to Data
+ guard let passwordData = password.data(using: .utf8) else {
+ throw NSError(domain: "VaultStore", code: 16, userInfo: [NSLocalizedDescriptionKey: "Invalid password"])
+ }
+
+ guard let saltData = salt.data(using: .utf8) else {
+ throw NSError(domain: "VaultStore", code: 15, userInfo: [NSLocalizedDescriptionKey: "Invalid salt"])
+ }
+
+ // Use SignalArgon2 to hash the password via Argon2id
+ guard let derivedKeyTuple = try? Argon2.hash(
+ iterations: iterations,
+ memoryInKiB: memorySize,
+ threads: parallelism,
+ password: passwordData,
+ salt: saltData,
+ desiredLength: 32,
+ variant: .id,
+ version: .v13
+ ) else {
+ throw NSError(domain: "VaultStore", code: 17, userInfo: [NSLocalizedDescriptionKey: "Argon2 hashing failed"])
+ }
+
+ // Return only the raw Data from the tuple
+ return derivedKeyTuple.raw
+ }
+
/// Store the encryption key - the key used to encrypt and decrypt the vault
public func storeEncryptionKey(base64Key: String) throws {
guard let keyData = Data(base64Encoded: base64Key) else {
diff --git a/apps/mobile-app/package-lock.json b/apps/mobile-app/package-lock.json
index 21bba6f9e..7bcc06059 100644
--- a/apps/mobile-app/package-lock.json
+++ b/apps/mobile-app/package-lock.json
@@ -45,7 +45,6 @@
"react-i18next": "^15.6.0",
"react-native": "~0.79.6",
"react-native-aes-gcm-crypto": "^0.2.2",
- "react-native-argon2": "^2.0.1",
"react-native-context-menu-view": "^1.19.0",
"react-native-edge-to-edge": "1.6.0",
"react-native-gesture-handler": "~2.24.0",
@@ -14729,12 +14728,6 @@
"react-native": "*"
}
},
- "node_modules/react-native-argon2": {
- "version": "2.0.1",
- "resolved": "https://registry.npmjs.org/react-native-argon2/-/react-native-argon2-2.0.1.tgz",
- "integrity": "sha512-/iOi0S+VVgS1gQGtQgL4ZxUVS4gz6Lav3bgIbtNmr9KbOunnBYzP6/yBe/XxkbpXvasHDwdQnuppOH/nuOBn7w==",
- "license": "MIT"
- },
"node_modules/react-native-context-menu-view": {
"version": "1.19.0",
"resolved": "https://registry.npmjs.org/react-native-context-menu-view/-/react-native-context-menu-view-1.19.0.tgz",
diff --git a/apps/mobile-app/package.json b/apps/mobile-app/package.json
index b50cb12ed..2e66a8181 100644
--- a/apps/mobile-app/package.json
+++ b/apps/mobile-app/package.json
@@ -66,7 +66,6 @@
"react-i18next": "^15.6.0",
"react-native": "~0.79.6",
"react-native-aes-gcm-crypto": "^0.2.2",
- "react-native-argon2": "^2.0.1",
"react-native-context-menu-view": "^1.19.0",
"react-native-edge-to-edge": "1.6.0",
"react-native-gesture-handler": "~2.24.0",
diff --git a/apps/mobile-app/specs/NativeVaultManager.ts b/apps/mobile-app/specs/NativeVaultManager.ts
index 421f1e10c..00200fe7d 100644
--- a/apps/mobile-app/specs/NativeVaultManager.ts
+++ b/apps/mobile-app/specs/NativeVaultManager.ts
@@ -12,6 +12,9 @@ export interface Spec extends TurboModule {
getVaultMetadata(): Promise<string>;
unlockVault(): Promise<boolean>;
+ // Cryptography operations
+ deriveKeyFromPassword(password: string, salt: string, encryptionType: string, encryptionSettings: string): Promise<string>;
+
// Database operations
storeDatabase(base64EncryptedDb: string): Promise<void>;
storeMetadata(metadata: string): Promise<void>;
@@ -37,15 +40,15 @@ export interface Spec extends TurboModule {
getAutoLockTimeout(): Promise<number>;
getAuthMethods(): Promise<string[]>;
openAutofillSettingsPage(): Promise<void>;
-
+
// Clipboard management
clearClipboardAfterDelay(delayInSeconds: number): Promise<void>;
copyToClipboardWithExpiration(text: string, expirationSeconds: number): Promise<void>;
-
+
// Exact alarm permission management
canScheduleExactAlarms(): Promise<boolean>;
requestExactAlarmPermission(): Promise<string>;
-
+
// Battery optimization management
isIgnoringBatteryOptimizations(): Promise<boolean>;
requestIgnoreBatteryOptimizations(): Promise<string>;
diff --git a/apps/mobile-app/utils/EncryptionUtility.tsx b/apps/mobile-app/utils/EncryptionUtility.tsx
index ae53dd8ee..1308d27d5 100644
--- a/apps/mobile-app/utils/EncryptionUtility.tsx
+++ b/apps/mobile-app/utils/EncryptionUtility.tsx
@@ -1,8 +1,8 @@
import { Buffer } from 'buffer';
import AesGcmCrypto from 'react-native-aes-gcm-crypto';
-import argon2 from 'react-native-argon2';
+import NativeVaultManager from '@/specs/NativeVaultManager';
import type { EncryptionKey } from '@/utils/dist/shared/models/vault';
import type { Email, MailboxEmail } from '@/utils/dist/shared/models/webapi';
@@ -22,30 +22,22 @@ class EncryptionUtility {
encryptionType: string = 'Argon2Id',
encryptionSettings: string = '{"Iterations":2,"MemorySize":19456,"DegreeOfParallelism":1}'
): Promise<Uint8Array> {
- const settings = JSON.parse(encryptionSettings);
-
try {
- if (encryptionType !== 'Argon2Id') {
- throw new Error('Unsupported encryption type: ' + encryptionType);
- }
-
- const result = await argon2(
+ // Call the native method to derive the key via Argon2id
+ const base64Key = await NativeVaultManager.deriveKeyFromPassword(
password,
salt,
- {
- iterations: settings.Iterations,
- memory: settings.MemorySize,
- parallelism: settings.DegreeOfParallelism,
- hashLength: 32,
- mode: 'argon2id'
- }
+ encryptionType,
+ encryptionSettings
);
- // Convert the hex string to Uint8Array
- const bytes = new Uint8Array(32);
- for (let i = 0; i < 32; i++) {
- bytes[i] = parseInt(result.rawHash.substring(i * 2, i * 2 + 2), 16);
+ // Convert base64 string to Uint8Array
+ const binaryString = atob(base64Key);
+ const bytes = new Uint8Array(binaryString.length);
+ for (let i = 0; i < binaryString.length; i++) {
+ bytes[i] = binaryString.charCodeAt(i);
}
+
return bytes;
} catch (error) {
console.error('Argon2 hashing failed:', error);