fix(mobile): workspaces keychain

This commit is contained in:
Mo
2022-06-22 07:15:37 -05:00
parent d833df1b74
commit 112ef2a2c8
3 changed files with 23 additions and 15 deletions

View File

@@ -8,7 +8,8 @@
"no-console": "warn",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-var-requires": "off",
"eqeqeq": ["off"]
"eqeqeq": ["off"],
"no-void": ["off"]
},
"ignorePatterns": ["metro.config.js"]
}

View File

@@ -11,11 +11,12 @@
"ios-dev": "react-native run-ios --scheme StandardNotesDev",
"ios-prod": "react-native run-ios --scheme StandardNotes",
"clear-cache": "watchman watch-del-all && rm -rf $TMPDIR/react-native-packager-cache-* && rm -rf $TMPDIR/metro-bundler-cache-*",
"lint": "yarn eslint . --ext .ts,.tsx",
"lint": "yarn tsc && yarn eslint . --ext .ts,.tsx",
"lint:fix": "yarn lint --fix",
"format": "prettier ./src",
"format:fix": "yarn format --write",
"build": "yarn android:bundle && yarn install:pods",
"pods": "yarn install:pods",
"tsc": "tsc --noEmit",
"start": "react-native start",
"install:pods": "yarn pod-install ios",

View File

@@ -5,6 +5,7 @@ import {
ApplicationIdentifier,
DeviceInterface,
Environment,
LegacyMobileKeychainStructure,
LegacyRawKeychainValue,
NamespacedRootKeyInKeychain,
RawKeychainValue,
@@ -30,6 +31,12 @@ const isLegacyIdentifier = function (identifier: ApplicationIdentifier) {
return identifier && identifier === LEGACY_IDENTIFIER
}
function isLegacyMobileKeychain(
x: LegacyMobileKeychainStructure | RawKeychainValue,
): x is LegacyMobileKeychainStructure {
return x.ak != undefined
}
const showLoadFailForItemIds = (failedItemIds: string[]) => {
let text =
'The following items could not be loaded. This may happen if you are in low-memory conditions, or if the note is very large in size. We recommend breaking up large notes into smaller chunks using the desktop or web app.\n\nItems:\n'
@@ -227,25 +234,23 @@ export class MobileDeviceInterface implements DeviceInterface {
): Promise<NamespacedRootKeyInKeychain | undefined> {
const keychain = await this.getRawKeychainValue()
if (isLegacyIdentifier(identifier)) {
return keychain as unknown as NamespacedRootKeyInKeychain
}
if (!keychain) {
return
}
return keychain[identifier]
const namespacedValue = keychain[identifier]
if (!namespacedValue && isLegacyIdentifier(identifier)) {
return keychain as unknown as NamespacedRootKeyInKeychain
}
return namespacedValue
}
async setNamespacedKeychainValue(
value: NamespacedRootKeyInKeychain,
identifier: ApplicationIdentifier,
): Promise<void> {
if (isLegacyIdentifier(identifier)) {
await Keychain.setKeys(value)
}
let keychain = await this.getRawKeychainValue()
if (!keychain) {
@@ -259,16 +264,17 @@ export class MobileDeviceInterface implements DeviceInterface {
}
async clearNamespacedKeychainValue(identifier: ApplicationIdentifier): Promise<void> {
if (isLegacyIdentifier(identifier)) {
await this.clearRawKeychainValue()
}
const keychain = await this.getRawKeychainValue()
if (!keychain) {
return
}
if (!keychain[identifier] && isLegacyIdentifier(identifier) && isLegacyMobileKeychain(keychain)) {
await this.clearRawKeychainValue()
return
}
delete keychain[identifier]
await Keychain.setKeys(keychain)
}