Skip to content

Commit ca7ccdc

Browse files
committed
feat: bitwarden encrypted import
1 parent b8a8d04 commit ca7ccdc

3 files changed

Lines changed: 60 additions & 18 deletions

File tree

package-lock.json

Lines changed: 29 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
"barekit:link-ios-addons": "node node_modules/react-native-bare-kit/ios/link.mjs",
2020
"pods:install": "cd ios && pod install",
2121
"test": "jest",
22-
"bundle:android": "bare-pack -p android --linked --defer sentry-bare --out bundles/app-android.bundle.js node_modules/@tetherto/pearpass-lib-vault-core/src/worklet/app.js",
23-
"bundle:ios": "bare-pack -p ios --linked --defer sentry-bare --out bundles/app-ios.bundle.js node_modules/@tetherto/pearpass-lib-vault-core/src/worklet/app.js",
24-
"bundle:autofill": "bare-pack --target ios --target android --linked --defer sentry-bare --out bundles/autofill.bundle node_modules/@tetherto/pearpass-lib-vault-core/src/worklet/app-ipc.js",
22+
"bundle:android": "bare-pack -p android --linked --defer sentry-bare --defer @tetherto/swarmconf --out bundles/app-android.bundle.js node_modules/@tetherto/pearpass-lib-vault-core/src/worklet/app.js",
23+
"bundle:ios": "bare-pack -p ios --linked --defer sentry-bare --defer @tetherto/swarmconf --out bundles/app-ios.bundle.js node_modules/@tetherto/pearpass-lib-vault-core/src/worklet/app.js",
24+
"bundle:autofill": "bare-pack --target ios --target android --linked --defer sentry-bare --defer @tetherto/swarmconf --out bundles/autofill.bundle node_modules/@tetherto/pearpass-lib-vault-core/src/worklet/app-ipc.js",
2525
"bundle-bare": "npm run bundle:android && npm run bundle:ios && npm run bundle:autofill",
26-
"bundle:android:nightly": "bare-pack -p android --linked --out bundles/app-android.bundle.js node_modules/@tetherto/pearpass-lib-vault-core/src/worklet/app.js",
27-
"bundle:ios:nightly": "bare-pack -p ios --linked --out bundles/app-ios.bundle.js node_modules/@tetherto/pearpass-lib-vault-core/src/worklet/app.js",
28-
"bundle:autofill:nightly": "bare-pack --target ios --target android --linked --out bundles/autofill.bundle node_modules/@tetherto/pearpass-lib-vault-core/src/worklet/app-ipc.js",
26+
"bundle:android:nightly": "bare-pack -p android --linked --defer @tetherto/swarmconf --out bundles/app-android.bundle.js node_modules/@tetherto/pearpass-lib-vault-core/src/worklet/app.js",
27+
"bundle:ios:nightly": "bare-pack -p ios --linked --defer @tetherto/swarmconf --out bundles/app-ios.bundle.js node_modules/@tetherto/pearpass-lib-vault-core/src/worklet/app.js",
28+
"bundle:autofill:nightly": "bare-pack --target ios --target android --linked --defer @tetherto/swarmconf --out bundles/autofill.bundle node_modules/@tetherto/pearpass-lib-vault-core/src/worklet/app-ipc.js",
2929
"bundle-bare:nightly": "npm run bundle:android:nightly && npm run bundle:ios:nightly && npm run bundle:autofill:nightly",
3030
"lingui:extract": "lingui extract",
3131
"lingui:compile": "lingui compile",

src/screens/ImportItems/index.tsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useForm } from '@tetherto/pear-apps-lib-ui-react-hooks'
44
import { Validator } from '@tetherto/pear-apps-utils-validator'
55
import { MAX_IMPORT_RECORDS } from '@tetherto/pearpass-lib-constants'
66
import {
7+
decryptBitwardenJson,
78
decryptKeePassKdbx,
89
parse1PasswordData,
910
parseBitwardenData,
@@ -34,11 +35,12 @@ import {
3435
decryptExportData,
3536
useCreateRecord
3637
} from '@tetherto/pearpass-lib-vault'
38+
import { pearpassVaultClient } from '@tetherto/pearpass-lib-vault/src/instances'
3739
import { useCallback, useState } from 'react'
3840
import { ActivityIndicator, Linking, Pressable, View } from 'react-native'
3941
import Toast from 'react-native-toast-message'
40-
import { BackScreenHeader } from 'src/containers/ScreenHeader/BackScreenHeader'
4142
import { Layout } from 'src/containers/Layout'
43+
import { BackScreenHeader } from 'src/containers/ScreenHeader/BackScreenHeader'
4244
import { useAutoLockContext } from 'src/context/AutoLockContext'
4345
import { useHapticFeedback } from 'src/hooks/useHapticFeedback'
4446
import { readFileContent } from '../Settings/TabImport/utils/readFileContent'
@@ -281,7 +283,28 @@ export const ImportItems = () => {
281283
const encryptedData = JSON.parse(fileContent as string)
282284
dataToProcess = await decryptExportData(encryptedData, password)
283285
}
284-
} catch {
286+
287+
if (
288+
resolvedType === ImportOptionType.Bitwarden &&
289+
JSON.parse(fileContent as string).encrypted
290+
) {
291+
if (!password) {
292+
throw new Error('Password is required for encrypted files')
293+
}
294+
295+
dataToProcess = await decryptBitwardenJson(
296+
fileContent as string,
297+
password,
298+
{
299+
decryptViaWorklet:
300+
pearpassVaultClient.decryptBitwardenExport.bind(
301+
pearpassVaultClient
302+
)
303+
}
304+
)
305+
}
306+
} catch (err) {
307+
console.log('[bw-import] decrypt failed:', err)
285308
throw new Error(
286309
'Failed to decrypt file. Please check your password and try again.'
287310
)

0 commit comments

Comments
 (0)