Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Replace react-native-quick-crypto dependency (#2473)
Leendert de Borst08df38e5d750
diff --git a/apps/mobile-app/android/app/build.gradle b/apps/mobile-app/android/app/build.gradleindex 6423b97fa..4db26618e 100644--- a/apps/mobile-app/android/app/build.gradle+++ b/apps/mobile-app/android/app/build.gradle@@ -218,6 +218,12 @@ dependencies {}}+ // Raise vulnerable transitive dependencies of Expo modules (gson via expo-log-box, commons-io via expo-file-system and expo-document-picker)+ constraints {+ implementation("com.google.code.gson:gson:2.14.0")+ implementation("commons-io:commons-io:2.22.0")+ }+// Test dependencies (unit tests)testImplementation 'junit:junit:4.13.2'testImplementation 'org.mockito:mockito-core:4.0.0'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.ktindex 8cb168465..bdbafc5bc 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@@ -26,6 +26,7 @@ import uniffi.aliasvault_core.isRpIdAllowedForHostimport uniffi.aliasvault_core.openAccountKeyChainimport uniffi.aliasvault_core.parseEmailSourceimport uniffi.aliasvault_core.reencryptAccountKeyJson+import uniffi.aliasvault_core.rsaDecryptimport uniffi.aliasvault_core.selectFaviconTargetimport uniffi.aliasvault_core.srpDerivePrivateKeyimport uniffi.aliasvault_core.srpDeriveSession@@ -79,6 +80,7 @@ object RustCoreDispatcher {"parseEmailSource" -> parseEmailSource(args.bytes(0))"decodeEmailSource" -> json(decodeEmailSource(args.bytes(0)))"extractEmailAttachment" -> json(extractEmailAttachment(args.bytes(0), args.uint(1), args.optionalBytes(2)))+ "rsaDecrypt" -> json(rsaDecrypt(args.string(0), args.string(1)))"argon2DeriveKey" -> json(argon2DeriveKey(args.string(0), args.string(1), args.string(2)))"deriveSrpPasswordHash" -> json(deriveSrpPasswordHash(args.bytes(0), args.string(1)))diff --git a/apps/mobile-app/app/(tabs)/emails/[id].tsx b/apps/mobile-app/app/(tabs)/emails/[id].tsxindex 74dd099a1..ae4d221cf 100644--- a/apps/mobile-app/app/(tabs)/emails/[id].tsx+++ b/apps/mobile-app/app/(tabs)/emails/[id].tsx@@ -1,7 +1,6 @@import { Buffer } from 'buffer';-import { getEmailAttachmentBytes } from '@aliasvault/client/email/EmailAttachments';-import { decodeEmailSource, type ParsedEmailAttachment } from '@aliasvault/client/rust/RustCore';+import { decodeEmailSource, extractEmailAttachment, type ParsedEmailAttachment } from '@aliasvault/client/rust/RustCore';import { Ionicons } from '@expo/vector-icons';import { Paths } from 'expo-file-system';import { useLocalSearchParams, useRouter, useNavigation, Stack } from 'expo-router';@@ -187,7 +186,9 @@ export default function EmailDetailsScreen() : React.ReactNode {}const encryptionKeys = await dbContext.sqliteClient.encryptionKeys.getAll();- const decryptedBytes = await getEmailAttachmentBytes(webApi, email, encryptionKeys, sourceBytes, index, attachment.detached ? attachment.partIndex : null);+ const encryptedPart = attachment.detached ? await webApi.downloadBlob(`Email/${email.id}/parts/${attachment.partIndex}`) : null;+ const detachedBody = encryptedPart ? await EncryptionUtility.decryptAttachment(encryptedPart, email, encryptionKeys) : undefined;+ const decryptedBytes = await extractEmailAttachment(sourceBytes, index, detachedBody);const tempFile = getFileForFilename(Paths.cache, attachment.filename);if (tempFile.exists) {diff --git a/apps/mobile-app/app/_layout.tsx b/apps/mobile-app/app/_layout.tsxindex efc394802..910a78a44 100644--- a/apps/mobile-app/app/_layout.tsx+++ b/apps/mobile-app/app/_layout.tsx@@ -4,10 +4,9 @@ import * as SplashScreen from 'expo-splash-screen';import { useEffect, useRef } from 'react';import { Linking, Platform } from 'react-native';import 'react-native-reanimated';-import 'react-native-get-random-values';import { GestureHandlerRootView } from 'react-native-gesture-handler';-import { install } from 'react-native-quick-crypto';+import '@/platform/CryptoPolyfill';import '@/platform/MobilePlatform';import { resolveDeepLink } from '@/utils/DeepLinkResolver';import { clearExportDirectories } from '@/utils/FileUtility';@@ -29,11 +28,6 @@ import { runStartupMigrations } from '@/migrations';SplashScreen.preventAutoHideAsync();-/*- * Install react-native-quick-crypto synchronously at module load.- */-install();-/*** Root layout navigation.*/diff --git a/apps/mobile-app/context/AuthContext.tsx b/apps/mobile-app/context/AuthContext.tsxindex 7b2ab23c0..b41075621 100644--- a/apps/mobile-app/context/AuthContext.tsx+++ b/apps/mobile-app/context/AuthContext.tsx@@ -163,7 +163,6 @@ export const AuthProvider: React.FC<{// Clear auth tokens and session in native layer (preserves vault data)await NativeVaultManager.clearAuthTokens();await NativeVaultManager.clearSession();- EncryptionUtility.clearRsaPrivateKeyCache();// Clear from AsyncStorage (for backward compatibility)// TODO: Remove AsyncStorage cleanup in future version 0.25.0+diff --git a/apps/mobile-app/context/DbContext.tsx b/apps/mobile-app/context/DbContext.tsxindex 11e87f51a..2eadcc6a9 100644--- a/apps/mobile-app/context/DbContext.tsx+++ b/apps/mobile-app/context/DbContext.tsx@@ -2,7 +2,6 @@ import React, { createContext, useContext, useState, useEffect, useCallback, useimport type { UnlockKeyDerivationParams, VaultMetadata } from '@aliasvault/models/metadata';import { hasUserVisibleScope, type VaultMutationScope } from '@aliasvault/client/sync/VaultMutationScope';-import EncryptionUtility from '@/utils/EncryptionUtility';import SqliteClient from '@/utils/SqliteClient';import NativeVaultManager from '@/specs/NativeVaultManager';@@ -191,7 +190,6 @@ export const DbProvider: React.FC<{ children: React.ReactNode }> = ({ children }* Clear database and remove from native module, called when logging out.*/const clearDatabase = useCallback(() : void => {- EncryptionUtility.clearRsaPrivateKeyCache();setDbInitialized(false);NativeVaultManager.clearVault();}, []);diff --git a/apps/mobile-app/context/NavigationContext.tsx b/apps/mobile-app/context/NavigationContext.tsxindex 71a2a5e0f..287532386 100644--- a/apps/mobile-app/context/NavigationContext.tsx+++ b/apps/mobile-app/context/NavigationContext.tsx@@ -3,7 +3,6 @@ import React, { createContext, useCallback, useContext, useEffect, useMemo, useRimport { AppState } from 'react-native';import NativeVaultManager from '@/specs/NativeVaultManager';-import EncryptionUtility from '@/utils/EncryptionUtility';type NavigationContextType = {/**@@ -191,8 +190,6 @@ export const NavigationProvider: React.FC<{ children: React.ReactNode }> = ({ ch// Check if vault is unlocked.const isUnlocked = await isVaultUnlocked();if (!isUnlocked) {- EncryptionUtility.clearRsaPrivateKeyCache();-// Get current full URL including query paramsconst currentRoute = lastRouteRef.current;if (currentRoute?.path) {diff --git a/apps/mobile-app/ios/AliasVault.xcodeproj/project.pbxproj b/apps/mobile-app/ios/AliasVault.xcodeproj/project.pbxprojindex 55d803ad6..3f0553261 100644--- a/apps/mobile-app/ios/AliasVault.xcodeproj/project.pbxproj+++ b/apps/mobile-app/ios/AliasVault.xcodeproj/project.pbxproj@@ -1259,7 +1259,6 @@inputPaths = ("${PODS_ROOT}/Target Support Files/Pods-AliasVault/Pods-AliasVault-frameworks.sh","${PODS_XCFRAMEWORKS_BUILD_DIR}/ExpoModulesJSI/ExpoModulesJSI.framework/ExpoModulesJSI",- "${PODS_XCFRAMEWORKS_BUILD_DIR}/OpenSSL-Universal/OpenSSL.framework/OpenSSL","${PODS_XCFRAMEWORKS_BUILD_DIR}/React-Core-prebuilt/React.framework/React","${PODS_XCFRAMEWORKS_BUILD_DIR}/ReactNativeDependencies/ReactNativeDependencies.framework/ReactNativeDependencies","${PODS_XCFRAMEWORKS_BUILD_DIR}/hermes-engine/Pre-built/hermesvm.framework/hermesvm",@@ -1267,7 +1266,6 @@name = "[CP] Embed Pods Frameworks";outputPaths = ("${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ExpoModulesJSI.framework",- "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/OpenSSL.framework","${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/React.framework","${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ReactNativeDependencies.framework","${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/hermesvm.framework",diff --git a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swiftindex 50458405f..94a9434ec 100644--- a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift+++ b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift@@ -1593,6 +1593,7 @@ private enum RustCoreDispatcher {case "decodeEmailSource": return try json(bytes: try RustCoreFramework.decodeEmailSource(source: try args.data(0)))case "extractEmailAttachment":return try json(bytes: try RustCoreFramework.extractEmailAttachment(source: try args.data(0), index: try args.uint32(1), detachedBody: try args.optionalData(2)))+ case "rsaDecrypt": return try json(bytes: try RustCoreFramework.rsaDecrypt(base64Ciphertext: try args.string(0), privateKeyJwk: try args.string(1)))case "argon2DeriveKey":return try json(bytes: try RustCoreFramework.argon2DeriveKey(password: try args.string(0), salt: try args.string(1), encryptionSettings: try args.string(2)))diff --git a/apps/mobile-app/ios/Podfile.lock b/apps/mobile-app/ios/Podfile.lockindex d6811d4e4..4eb1a9cdb 100644--- a/apps/mobile-app/ios/Podfile.lock+++ b/apps/mobile-app/ios/Podfile.lock@@ -113,7 +113,6 @@ PODS:- hermes-engine/Pre-built (250829098.0.10)- Macaw (0.9.10):- SWXMLHash- - OpenSSL-Universal (3.6.5000)- RCTDeprecation (0.85.3)- RCTRequired (0.85.3)- RCTSwiftUI (0.85.3)@@ -1519,52 +1518,6 @@ PODS:- React- react-native-get-random-values (1.11.0):- React-Core- - react-native-quick-base64 (3.0.0):- - hermes-engine- - RCTRequired- - RCTTypeSafety- - React-Core- - React-Core-prebuilt- - React-debug- - React-Fabric- - React-featureflags- - React-graphics- - React-ImageManager- - React-jsi- - React-NativeModulesApple- - React-RCTFabric- - React-renderercss- - React-rendererdebug- - React-utils- - ReactCodegen- - ReactCommon/turbomodule/bridging- - ReactCommon/turbomodule/core- - ReactNativeDependencies- - Yoga- - react-native-quick-crypto (0.7.17):- - hermes-engine- - OpenSSL-Universal- - RCTRequired- - RCTTypeSafety- - React- - React-Core- - React-Core-prebuilt- - React-debug- - React-Fabric- - React-featureflags- - React-graphics- - React-ImageManager- - React-jsi- - React-NativeModulesApple- - React-RCTFabric- - React-renderercss- - React-rendererdebug- - React-utils- - ReactCodegen- - ReactCommon/turbomodule/bridging- - ReactCommon/turbomodule/core- - ReactNativeDependencies- - Yoga- react-native-safe-area-context (5.7.0):- hermes-engine- RCTRequired@@ -2402,7 +2355,6 @@ DEPENDENCIES:- FBLazyVector (from `../node_modules/react-native/Libraries/FBLazyVector`)- hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`)- Macaw (~> 0.9.7)- - OpenSSL-Universal (from `https://raw.githubusercontent.com/krzyzanowskim/OpenSSL/3.6.5000/OpenSSL-Universal.podspec`)- RCTDeprecation (from `../node_modules/react-native/ReactApple/Libraries/RCTFoundation/RCTDeprecation`)- RCTRequired (from `../node_modules/react-native/Libraries/Required`)- RCTSwiftUI (from `../node_modules/react-native/ReactApple/RCTSwiftUI`)@@ -2444,8 +2396,6 @@ DEPENDENCIES:- react-native-aes-gcm-crypto (from `../node_modules/react-native-aes-gcm-crypto`)- react-native-context-menu-view (from `../node_modules/react-native-context-menu-view`)- react-native-get-random-values (from `../node_modules/react-native-get-random-values`)- - react-native-quick-base64 (from `../node_modules/react-native-quick-base64`)- - react-native-quick-crypto (from `../node_modules/react-native-quick-crypto`)- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)- "react-native-slider (from `../node_modules/@react-native-community/slider`)"- react-native-webview (from `../node_modules/react-native-webview`)@@ -2558,8 +2508,6 @@ EXTERNAL SOURCES:hermes-engine::podspec: "../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec":tag: hermes-v250829098.0.10- OpenSSL-Universal:- :podspec: https://raw.githubusercontent.com/krzyzanowskim/OpenSSL/3.6.5000/OpenSSL-Universal.podspecRCTDeprecation::path: "../node_modules/react-native/ReactApple/Libraries/RCTFoundation/RCTDeprecation"RCTRequired:@@ -2640,10 +2588,6 @@ EXTERNAL SOURCES::path: "../node_modules/react-native-context-menu-view"react-native-get-random-values::path: "../node_modules/react-native-get-random-values"- react-native-quick-base64:- :path: "../node_modules/react-native-quick-base64"- react-native-quick-crypto:- :path: "../node_modules/react-native-quick-crypto"react-native-safe-area-context::path: "../node_modules/react-native-safe-area-context"react-native-slider:@@ -2764,7 +2708,6 @@ SPEC CHECKSUMS:FBLazyVector: 24e62c765683b8d89006a88a2c8f5cf019f0074dhermes-engine: f684a01742a30bb5d7332da47aa184074d8ae9b4Macaw: 7af8ea57aa2cab35b4a52a45e6f85eea753ea9ae- OpenSSL-Universal: 3e13305702e4e724410c7290e0c7dd78ad3c56f4RCTDeprecation: a4c521821fab57cbb125b36effe84d897d0dfa12RCTRequired: 9f3a7e5645d4bc3f551593de7550bb66ab6e42bcRCTSwiftUI: 239ed2eb9e73de5a6f518810630f0c95e01c8702@@ -2805,8 +2748,6 @@ SPEC CHECKSUMS:react-native-aes-gcm-crypto: d572dd7a69f31c539bb8309b3a829bfa3bfad244react-native-context-menu-view: da39a4612c1294d651907162529cfba8421e9b89react-native-get-random-values: d16467cf726c618e9c7a8c3c39c31faa2244bbba- react-native-quick-base64: 53393ee5ea472a7486e6652ad3d7a640ebf6ebda- react-native-quick-crypto: 4cda9f23b60fa731cae94007a3569a6a0443dc41react-native-safe-area-context: 6b4966397ada0f7dd481e4486a2ef936834861a1react-native-slider: 08ecfc4e9cc16cc388a56dd9caeca51b55cd9bb7react-native-webview: 2da09bdea1aeb6c46e27dd94632e21059cade6c1@@ -2854,6 +2795,6 @@ SPEC CHECKSUMS:SWXMLHash: dd733a457e9c4fe93b1538654057aefae4acb382Yoga: 77dfa8673de2874e1855002ae59c68b8be9b007b-PODFILE CHECKSUM: c6996460e83f68ca37df65dc9a758b89bb097d49+PODFILE CHECKSUM: 97a422feed2574ce375469b50618d6ab651962d8COCOAPODS: 1.16.2diff --git a/apps/mobile-app/package-lock.json b/apps/mobile-app/package-lock.jsonindex e2c69ce1d..1c8785588 100644--- a/apps/mobile-app/package-lock.json+++ b/apps/mobile-app/package-lock.json@@ -15,9 +15,11 @@"@aliasvault/vault": "file:../../core/vault","@expo/vector-icons": "^15.0.2","@hookform/resolvers": "^5.0.1",+ "@noble/hashes": "^2.4.0","@react-native-async-storage/async-storage": "2.2.0","@react-native-community/slider": "5.2.0","@types/jsrsasign": "^10.5.15",+ "buffer": "^6.0.3","expo": "^56.0.4","expo-blur": "~56.0.3","expo-clipboard": "~56.0.3",@@ -53,7 +55,6 @@"react-native-get-random-values": "^1.11.0","react-native-image-zoom-viewer": "^3.0.1","react-native-qrcode-svg": "^6.3.21",- "react-native-quick-crypto": "^0.7.13","react-native-reanimated": "4.3.1","react-native-safe-area-context": "~5.7.0","react-native-screens": "4.25.2",@@ -1273,30 +1274,6 @@"node": ">=6.9.0"}},- "node_modules/@craftzdog/react-native-buffer": {- "version": "6.1.2",- "resolved": "https://registry.npmjs.org/@craftzdog/react-native-buffer/-/react-native-buffer-6.1.2.tgz",- "integrity": "sha512-KV1HitN05FHLLDG7Zb/yftDsa+mKBYBzFMQ0PMldvUicq6vWOtAvz9mDavt7Fzozh+WNqORE+yFDkkdWysZ/SA==",- "funding": [- {- "type": "github",- "url": "https://github.com/sponsors/feross"- },- {- "type": "patreon",- "url": "https://www.patreon.com/feross"- },- {- "type": "consulting",- "url": "https://feross.org/support"- }- ],- "license": "MIT",- "dependencies": {- "ieee754": "^1.2.1",- "react-native-quick-base64": "^3.0.0"- }- },"node_modules/@egjs/hammerjs": {"version": "2.0.17","resolved": "https://registry.npmjs.org/@egjs/hammerjs/-/hammerjs-2.0.17.tgz",@@ -2857,6 +2834,18 @@"@emnapi/runtime": "^1.7.1"}},+ "node_modules/@noble/hashes": {+ "version": "2.4.0",+ "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-2.4.0.tgz",+ "integrity": "sha512-X5XaVWZIBCT7HHZGm5I7ZQXDwLG+bGXuSrMQAW+7Zvl87h1kmc1ZB1VSRJcpUfoUrGQp4Fkoxm5kZ+Ms+aW+eA==",+ "license": "MIT",+ "engines": {+ "node": ">= 20.19.0"+ },+ "funding": {+ "url": "https://paulmillr.com/funding/"+ }+ },"node_modules/@nodable/entities": {"version": "3.1.0","resolved": "https://registry.npmjs.org/@nodable/entities/-/entities-3.1.0.tgz",@@ -5577,6 +5566,7 @@"version": "1.0.7","resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz","integrity": "sha512-wvUjBtSGN7+7SjNpq/9M2Tg350UZD3q62IFZLbRAR1bSMlCo1ZaeW+BJ+D090e4hIIZLBcTDWe4Mh4jvUDajzQ==",+ "dev": true,"license": "MIT","dependencies": {"possible-typed-array-names": "^1.0.0"@@ -5787,6 +5777,31 @@"readable-stream": "^3.4.0"}},+ "node_modules/bl/node_modules/buffer": {+ "version": "5.7.1",+ "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",+ "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",+ "devOptional": true,+ "funding": [+ {+ "type": "github",+ "url": "https://github.com/sponsors/feross"+ },+ {+ "type": "patreon",+ "url": "https://www.patreon.com/feross"+ },+ {+ "type": "consulting",+ "url": "https://feross.org/support"+ }+ ],+ "license": "MIT",+ "dependencies": {+ "base64-js": "^1.3.1",+ "ieee754": "^1.1.13"+ }+ },"node_modules/body-parser": {"version": "2.3.0","resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.3.0.tgz",@@ -5905,10 +5920,9 @@}},"node_modules/buffer": {- "version": "5.7.1",- "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",- "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",- "devOptional": true,+ "version": "6.0.3",+ "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz",+ "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==","funding": [{"type": "github",@@ -5926,7 +5940,7 @@"license": "MIT","dependencies": {"base64-js": "^1.3.1",- "ieee754": "^1.1.13"+ "ieee754": "^1.2.1"}},"node_modules/buffer-from": {@@ -5948,6 +5962,7 @@"version": "1.0.9","resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.9.tgz","integrity": "sha512-a/hy+pNsFUTR+Iz8TCJvXudKVLAnz/DyeSUo10I5yvFDQJBFU2s9uqQpoSrJlroHUKoKqzg+epxyP9lqFdzfBQ==",+ "dev": true,"license": "MIT","dependencies": {"call-bind-apply-helpers": "^1.0.2",@@ -5966,6 +5981,7 @@"version": "1.0.2","resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz","integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",+ "devOptional": true,"license": "MIT","dependencies": {"es-errors": "^1.3.0",@@ -5979,6 +5995,7 @@"version": "1.0.4","resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz","integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==",+ "devOptional": true,"license": "MIT","dependencies": {"call-bind-apply-helpers": "^1.0.2",@@ -6642,6 +6659,7 @@"version": "1.1.4","resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz","integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==",+ "dev": true,"license": "MIT","dependencies": {"es-define-property": "^1.0.0",@@ -6829,6 +6847,7 @@"version": "1.0.1","resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz","integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",+ "devOptional": true,"license": "MIT","dependencies": {"call-bind-apply-helpers": "^1.0.1",@@ -7011,6 +7030,7 @@"version": "1.0.1","resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz","integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",+ "devOptional": true,"license": "MIT","engines": {"node": ">= 0.4"@@ -7057,6 +7077,7 @@"version": "1.1.2","resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.2.tgz","integrity": "sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==",+ "devOptional": true,"license": "MIT","dependencies": {"es-errors": "^1.3.0"@@ -7689,15 +7710,6 @@"node": ">=6"}},- "node_modules/events": {- "version": "3.3.0",- "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz",- "integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==",- "license": "MIT",- "engines": {- "node": ">=0.8.x"- }- },"node_modules/execa": {"version": "5.1.1","resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz",@@ -8514,6 +8526,7 @@"version": "0.3.5","resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.5.tgz","integrity": "sha512-dKx12eRCVIzqCxFGplyFKJMPvLEWgmNtUrpTiJIR5u97zEhRG8ySrtboPHZXx7daLxQVrl643cTzbab2tkQjxg==",+ "dev": true,"license": "MIT","dependencies": {"is-callable": "^1.2.7"@@ -8593,6 +8606,7 @@"version": "2.0.1","resolved": "https://registry.npmjs.org/generator-function/-/generator-function-2.0.1.tgz","integrity": "sha512-SFdFmIJi+ybC0vjlHN0ZGVGHc3lgE0DxPAT0djjVg+kjOnSqclqmj0KQ7ykTOLP6YxoqOvuAODGdcHJn+43q3g==",+ "dev": true,"license": "MIT","engines": {"node": ">= 0.4"@@ -8620,6 +8634,7 @@"version": "1.3.0","resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz","integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",+ "devOptional": true,"license": "MIT","dependencies": {"call-bind-apply-helpers": "^1.0.2",@@ -8653,6 +8668,7 @@"version": "1.0.1","resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz","integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",+ "devOptional": true,"license": "MIT","dependencies": {"dunder-proto": "^1.0.1",@@ -8815,6 +8831,7 @@"version": "1.2.0","resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz","integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",+ "devOptional": true,"license": "MIT","engines": {"node": ">= 0.4"@@ -8855,6 +8872,7 @@"version": "1.0.2","resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz","integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==",+ "dev": true,"license": "MIT","dependencies": {"es-define-property": "^1.0.0"@@ -8883,6 +8901,7 @@"version": "1.1.0","resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz","integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",+ "devOptional": true,"license": "MIT","engines": {"node": ">= 0.4"@@ -8895,6 +8914,7 @@"version": "1.0.2","resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz","integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==",+ "dev": true,"license": "MIT","dependencies": {"has-symbols": "^1.0.3"@@ -9218,22 +9238,6 @@"loose-envify": "^1.0.0"}},- "node_modules/is-arguments": {- "version": "1.2.0",- "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.2.0.tgz",- "integrity": "sha512-7bVbi0huj/wrIAOzb8U1aszg9kdi3KN/CyU19CTI7tAoZYEZoL9yCDXpbXN+uPsuWnP02cyug1gleqq+TU+YCA==",- "license": "MIT",- "dependencies": {- "call-bound": "^1.0.2",- "has-tostringtag": "^1.0.2"- },- "engines": {- "node": ">= 0.4"- },- "funding": {- "url": "https://github.com/sponsors/ljharb"- }- },"node_modules/is-array-buffer": {"version": "3.0.5","resolved": "https://registry.npmjs.org/is-array-buffer/-/is-array-buffer-3.0.5.tgz",@@ -9338,6 +9342,7 @@"version": "1.2.7","resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz","integrity": "sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==",+ "dev": true,"license": "MIT","engines": {"node": ">= 0.4"@@ -9451,6 +9456,7 @@"version": "1.1.2","resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.1.2.tgz","integrity": "sha512-upqt1SkGkODW9tsGNG5mtXTXtECizwtS2kA161M+gJPc1xdb/Ax629af6YrTwcOeQHbewrPNlE5Dx7kzvXTizA==",+ "dev": true,"license": "MIT","dependencies": {"call-bound": "^1.0.4",@@ -9563,6 +9569,7 @@"version": "1.2.1","resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.2.1.tgz","integrity": "sha512-MjYsKHO5O7mCsmRGxWcLWheFqN9DJ/2TmngvjKXihe6efViPqc274+Fx/4fYj/r03+ESvBdTXK0V6tA3rgez1g==",+ "dev": true,"license": "MIT","dependencies": {"call-bound": "^1.0.2",@@ -9658,6 +9665,7 @@"version": "1.1.15","resolved": "https://registry.npmjs.org/is-typed-array/-/is-typed-array-1.1.15.tgz","integrity": "sha512-p3EcsicXjit7SaskXHs1hA91QxgTw46Fv6EFKKGS5DRFLD8yKnohjF3hxoju94b/OcMZoQukzpPpBE9uLVKzgQ==",+ "dev": true,"license": "MIT","dependencies": {"which-typed-array": "^1.1.16"@@ -10668,6 +10676,7 @@"version": "1.1.0","resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz","integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",+ "devOptional": true,"license": "MIT","engines": {"node": ">= 0.4"@@ -11944,6 +11953,7 @@"version": "1.1.0","resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.1.0.tgz","integrity": "sha512-/+5VFTchJDoVj3bhoqi6UeymcD00DAwb1nJwamzPvHEszJ4FpF6SNNbUbOS8yI56qHzdV8eK0qEfOSiodkTdxg==",+ "dev": true,"license": "MIT","engines": {"node": ">= 0.4"@@ -12028,15 +12038,6 @@"node": "^14.17.0 || ^16.13.0 || >=18.0.0"}},- "node_modules/process": {- "version": "0.11.10",- "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz",- "integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==",- "license": "MIT",- "engines": {- "node": ">= 0.6.0"- }- },"node_modules/progress": {"version": "2.0.3","resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz",@@ -12672,76 +12673,6 @@"react-native-svg": ">=14.0.0"}},- "node_modules/react-native-quick-base64": {- "version": "3.0.0",- "resolved": "https://registry.npmjs.org/react-native-quick-base64/-/react-native-quick-base64-3.0.0.tgz",- "integrity": "sha512-gnJhA4a/QIGrptZQJv0hLLne8yyJPkdXtn33LHEzq3nhzsv+jRhrxr07wYwYX+CKCRXmuNkZ3Wo7LapSrFVmQg==",- "license": "MIT",- "workspaces": [- "example"- ],- "peerDependencies": {- "react": "*",- "react-native": "*"- }- },- "node_modules/react-native-quick-crypto": {- "version": "0.7.17",- "resolved": "https://registry.npmjs.org/react-native-quick-crypto/-/react-native-quick-crypto-0.7.17.tgz",- "integrity": "sha512-cJzp6oA/dM1lujt+Rwtn46Mgcs3w9F/0oQvNz1jcADc/AXktveAOUTzzKrDMxyg6YPziCYnoqMDzHBo6OLSU1g==",- "license": "MIT",- "workspaces": [- ".",- "example"- ],- "dependencies": {- "@craftzdog/react-native-buffer": "^6.0.5",- "events": "^3.3.0",- "readable-stream": "^4.5.2",- "string_decoder": "^1.3.0",- "util": "^0.12.5"- }- },- "node_modules/react-native-quick-crypto/node_modules/buffer": {- "version": "6.0.3",- "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz",- "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==",- "funding": [- {- "type": "github",- "url": "https://github.com/sponsors/feross"- },- {- "type": "patreon",- "url": "https://www.patreon.com/feross"- },- {- "type": "consulting",- "url": "https://feross.org/support"- }- ],- "license": "MIT",- "dependencies": {- "base64-js": "^1.3.1",- "ieee754": "^1.2.1"- }- },- "node_modules/react-native-quick-crypto/node_modules/readable-stream": {- "version": "4.7.0",- "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.7.0.tgz",- "integrity": "sha512-oIGGmcpTLwPga8Bn6/Z75SVaH1z5dUut2ibSyAMVhmUggWpmDn2dapB0n7f8nwaSiRtepAsfJyfXIO5DCVAODg==",- "license": "MIT",- "dependencies": {- "abort-controller": "^3.0.0",- "buffer": "^6.0.3",- "events": "^3.3.0",- "process": "^0.11.10",- "string_decoder": "^1.3.0"- },- "engines": {- "node": "^12.22.0 || ^14.17.0 || >=16.0.0"- }- },"node_modules/react-native-reanimated": {"version": "4.3.1","resolved": "https://registry.npmjs.org/react-native-reanimated/-/react-native-reanimated-4.3.1.tgz",@@ -13335,6 +13266,7 @@"version": "1.1.0","resolved": "https://registry.npmjs.org/safe-regex-test/-/safe-regex-test-1.1.0.tgz","integrity": "sha512-x/+Cz4YrimQxQccJf5mKEbIa1NzeCRNI5Ecl/ekmlYaampdNLPalVyIcCZNNH3MvmqBugV5TMYZXv0ljslUlaw==",+ "dev": true,"license": "MIT","dependencies": {"call-bound": "^1.0.2",@@ -13628,6 +13560,7 @@"version": "1.2.2","resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz","integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==",+ "dev": true,"license": "MIT","dependencies": {"define-data-property": "^1.1.4",@@ -14066,6 +13999,7 @@"version": "1.3.0","resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz","integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==",+ "devOptional": true,"license": "MIT","dependencies": {"safe-buffer": "~5.2.0"@@ -14972,19 +14906,6 @@"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"}},- "node_modules/util": {- "version": "0.12.5",- "resolved": "https://registry.npmjs.org/util/-/util-0.12.5.tgz",- "integrity": "sha512-kZf/K6hEIrWHI6XqOFUiiMa+79wE/D8Q+NCNAWclkyg3b4d2k7s0QGepNjiABc+aR3N1PAyHL7p6UcLY6LmrnA==",- "license": "MIT",- "dependencies": {- "inherits": "^2.0.3",- "is-arguments": "^1.0.4",- "is-generator-function": "^1.0.7",- "is-typed-array": "^1.1.3",- "which-typed-array": "^1.1.2"- }- },"node_modules/util-deprecate": {"version": "1.0.2","resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",@@ -15485,6 +15406,7 @@"version": "1.1.20","resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.20.tgz","integrity": "sha512-LYfpUkmqwl0h9A2HL09Mms427Q1RZWuOHsukfVcKRq9q95iQxdw0ix1JQrqbcDR9PH1QDwf5Qo8OZb5lksZ8Xg==",+ "dev": true,"license": "MIT","dependencies": {"available-typed-arrays": "^1.0.7",diff --git a/apps/mobile-app/package.json b/apps/mobile-app/package.jsonindex db1e6c0eb..5d742526b 100644--- a/apps/mobile-app/package.json+++ b/apps/mobile-app/package.json@@ -33,9 +33,11 @@"@aliasvault/vault": "file:../../core/vault","@expo/vector-icons": "^15.0.2","@hookform/resolvers": "^5.0.1",+ "@noble/hashes": "^2.4.0","@react-native-async-storage/async-storage": "2.2.0","@react-native-community/slider": "5.2.0","@types/jsrsasign": "^10.5.15",+ "buffer": "^6.0.3","expo": "^56.0.4","expo-blur": "~56.0.3","expo-clipboard": "~56.0.3",@@ -71,7 +73,6 @@"react-native-get-random-values": "^1.11.0","react-native-image-zoom-viewer": "^3.0.1","react-native-qrcode-svg": "^6.3.21",- "react-native-quick-crypto": "^0.7.13","react-native-reanimated": "4.3.1","react-native-safe-area-context": "~5.7.0","react-native-screens": "4.25.2",diff --git a/apps/mobile-app/platform/CryptoPolyfill.ts b/apps/mobile-app/platform/CryptoPolyfill.tsnew file mode 100644index 000000000..6831a1e02--- /dev/null+++ b/apps/mobile-app/platform/CryptoPolyfill.ts@@ -0,0 +1,40 @@+import 'react-native-get-random-values';+import { sha256 } from '@noble/hashes/sha2.js';++/*+ * The part of Web Crypto the client core calls that Hermes lacks: randomUUID and the SHA-256 digest.+ * getRandomValues comes from react-native-get-random-values.+ */+type MobileCrypto = {+ getRandomValues<T extends ArrayBufferView | null>(array: T): T;+ randomUUID?: () => string;+ subtle?: { digest: (algorithm: AlgorithmIdentifier, data: BufferSource) => Promise<ArrayBuffer> };+};++const mobileCrypto = globalThis.crypto as unknown as MobileCrypto;++/**+ * A random (version 4) UUID.+ */+function randomUUID(): string {+ const bytes = mobileCrypto.getRandomValues(new Uint8Array(16));+ bytes[6] = (bytes[6] & 0x0f) | 0x40;+ bytes[8] = (bytes[8] & 0x3f) | 0x80;+ const hex = Array.from(bytes, b => b.toString(16).padStart(2, '0')).join('');+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;+}++/**+ * The SHA-256 digest of `data`; other algorithms are not supported.+ */+async function digest(algorithm: AlgorithmIdentifier, data: BufferSource): Promise<ArrayBuffer> {+ const name = typeof algorithm === 'string' ? algorithm : algorithm.name;+ if (name.toUpperCase() !== 'SHA-256') {+ throw new Error(`Unsupported digest algorithm: ${name}`);+ }+ const bytes = ArrayBuffer.isView(data) ? new Uint8Array(data.buffer, data.byteOffset, data.byteLength) : new Uint8Array(data);+ return sha256(bytes).buffer as ArrayBuffer;+}++mobileCrypto.randomUUID ??= randomUUID;+mobileCrypto.subtle ??= { digest };diff --git a/apps/mobile-app/platform/NativeRustCore.ts b/apps/mobile-app/platform/NativeRustCore.tsindex 5a4b6ea2c..4a34682b6 100644--- a/apps/mobile-app/platform/NativeRustCore.ts+++ b/apps/mobile-app/platform/NativeRustCore.ts@@ -80,3 +80,10 @@ export const nativeRustCore: IRustCore = {createVaultSyncSession: () => Promise.reject(new Error('The vault sync engine is driven natively on mobile and has no JavaScript session.')),};++/**+ * RSA-OAEP-256 decrypt base64 ciphertext with a JWK private key. Mobile only.+ */+export function rsaDecrypt(base64Ciphertext: string, privateKeyJwk: string): Promise<Uint8Array> {+ return callForBytes('rsaDecrypt', base64Ciphertext, privateKeyJwk);+}diff --git a/apps/mobile-app/utils/EncryptionUtility.ts b/apps/mobile-app/utils/EncryptionUtility.tsindex e95896070..52df0f807 100644--- a/apps/mobile-app/utils/EncryptionUtility.ts+++ b/apps/mobile-app/utils/EncryptionUtility.ts@@ -3,6 +3,7 @@ import { Buffer } from 'buffer';import { gunzipSync, strFromU8 } from 'fflate';import AesGcmCrypto from 'react-native-aes-gcm-crypto';+import { rsaDecrypt } from '@/platform/NativeRustCore';import NativeVaultManager from '@/specs/NativeVaultManager';import type { EncryptionKey } from '@aliasvault/models/vault';import type { Email, EmailDecryptionKey, MailboxEmail } from '@aliasvault/models/webapi';@@ -32,8 +33,6 @@ export type DecryptedEmail = {* - RSA-OAEP asymmetric encryption/decryption*/class EncryptionUtility {- private static rsaPrivateKeyCache = new Map<string, Promise<CryptoKey>>();-/*** Derives a key from a password using Argon2Id*/@@ -128,27 +127,18 @@ class EncryptionUtility {return encryptedBytes;}- const key = await crypto.subtle.importKey(- "raw",- Uint8Array.from(atob(base64Key), c => c.charCodeAt(0)),- {- name: "AES-GCM",- length: 256,- },- false,- ["decrypt"]- );-const iv = encryptedBytes.slice(0, 12);- const ciphertext = encryptedBytes.slice(12);-- const decrypted = await crypto.subtle.decrypt(- { name: "AES-GCM", iv },- key,- ciphertext+ const tag = encryptedBytes.slice(-16);+ const content = encryptedBytes.slice(12, -16);++ const decryptedBase64 = await AesGcmCrypto.decrypt(+ Buffer.from(content).toString('base64'),+ base64Key,+ Buffer.from(iv).toString('hex'),+ Buffer.from(tag).toString('hex'),+ true);-- return new Uint8Array(decrypted);+ return new Uint8Array(Buffer.from(decryptedBase64, 'base64'));}/**@@ -170,133 +160,6 @@ class EncryptionUtility {return Buffer.from(decryptedBytes).toString('utf8');}- /**- * Generates a new RSA key pair for asymmetric encryption- */- public static async generateRsaKeyPair(): Promise<{ publicKey: string, privateKey: string }> {- /*- * TODO: this method is currently unused. When we enable the app to actually generate keys, check if the key pair is- * generated in the correct format where private key is in expected JWK format that the WASM app already outputs.- */- const keyPair = await crypto.subtle.generateKey(- {- name: "RSA-OAEP",- modulusLength: 2048,- publicExponent: new Uint8Array([1, 0, 1]),- hash: "SHA-256",- },- true,- ["encrypt", "decrypt"]- );-- const publicKey = await crypto.subtle.exportKey("jwk", keyPair.publicKey);- const privateKey = await crypto.subtle.exportKey("jwk", keyPair.privateKey);-- return {- publicKey: JSON.stringify(publicKey),- privateKey: JSON.stringify(privateKey)- };- }-- /**- * Encrypts data using RSA-OAEP asymmetric encryption with a public key- */- public static async encryptWithPublicKey(plaintext: string, publicKey: string): Promise<string> {- const publicKeyObj = await crypto.subtle.importKey(- "jwk",- JSON.parse(publicKey),- {- name: "RSA-OAEP",- hash: "SHA-256",- },- false,- ["encrypt"]- );-- const encodedPlaintext = new TextEncoder().encode(plaintext);- const cipherBuffer = await crypto.subtle.encrypt(- {- name: "RSA-OAEP"- },- publicKeyObj,- encodedPlaintext- );-- return btoa(String.fromCharCode.apply(null, Array.from(new Uint8Array(cipherBuffer))));- }-- /**- * Decrypts data using RSA-OAEP asymmetric encryption with a private key- */- public static async decryptWithPrivateKey(ciphertext: string, privateKey: string): Promise<Uint8Array> {- try {- const privateKeyObj = await EncryptionUtility.importPrivateKey(privateKey);-- return await EncryptionUtility.decryptWithPrivateKeyObject(ciphertext, privateKeyObj);- } catch (error) {- console.error('RSA decryption failed:', error);- throw new Error(`Failed to decrypt: ${error instanceof Error ? error.message : 'Unknown error'}`);- }- }-- /**- * Decrypts data using RSA-OAEP asymmetric encryption with a CryptoKey private key.- */- public static async decryptWithPrivateKeyObject(ciphertext: string, privateKey: CryptoKey): Promise<Uint8Array> {- const cipherBuffer = Uint8Array.from(atob(ciphertext), c => c.charCodeAt(0));- const plaintextBuffer = await crypto.subtle.decrypt(- {- name: "RSA-OAEP",- },- privateKey,- cipherBuffer- );-- return new Uint8Array(plaintextBuffer);- }-- /**- * Clears cached RSA private keys when the in-memory vault is locked or reset.- */- public static clearRsaPrivateKeyCache(): void {- EncryptionUtility.rsaPrivateKeyCache.clear();- }-- /**- * Imports an RSA-OAEP private key as non-extractable.- */- private static async importPrivateKey(privateKey: string): Promise<CryptoKey> {- return await crypto.subtle.importKey(- "jwk",- JSON.parse(privateKey),- {- name: "RSA-OAEP",- hash: "SHA-256",- },- false,- ["decrypt"]- );- }-- /**- * Returns the cached non-extractable private key matching an email encryption public key.- */- private static async getPrivateKeyObject(encryptionKey: EncryptionKey): Promise<CryptoKey> {- const cachedPrivateKey = EncryptionUtility.rsaPrivateKeyCache.get(encryptionKey.PublicKey);-- if (cachedPrivateKey) {- return await cachedPrivateKey;- }-- const privateKey = EncryptionUtility.importPrivateKey(encryptionKey.PrivateKey).catch(error => {- EncryptionUtility.rsaPrivateKeyCache.delete(encryptionKey.PublicKey);- throw error;- });-- EncryptionUtility.rsaPrivateKeyCache.set(encryptionKey.PublicKey, privateKey);- return await privateKey;- }-/*** Finds the decryption key of an email's symmetric key that one of the locally held keypairs can open. An email* carries one decryption key per manifest keypair the caller holds; it names its public key by index into the@@ -319,8 +182,7 @@ class EncryptionUtility {*/private static async resolveEmailSymmetricKey(decryptionKeys: EmailDecryptionKey[], publicKeys: string[], encryptionKeys: EncryptionKey[]): Promise<string> {const match = EncryptionUtility.resolveEmailDecryptionKey(decryptionKeys, publicKeys, encryptionKeys);- const privateKey = await EncryptionUtility.getPrivateKeyObject(match.encryptionKey);- const symmetricKey = await EncryptionUtility.decryptWithPrivateKeyObject(match.encryptedSymmetricKey, privateKey);+ const symmetricKey = await rsaDecrypt(match.encryptedSymmetricKey, match.encryptionKey.PrivateKey);return Buffer.from(symmetricKey).toString('base64');}