fix(mobile): workspaces keychain
This commit is contained in:
@@ -8,7 +8,8 @@
|
|||||||
"no-console": "warn",
|
"no-console": "warn",
|
||||||
"@typescript-eslint/no-explicit-any": "warn",
|
"@typescript-eslint/no-explicit-any": "warn",
|
||||||
"@typescript-eslint/no-var-requires": "off",
|
"@typescript-eslint/no-var-requires": "off",
|
||||||
"eqeqeq": ["off"]
|
"eqeqeq": ["off"],
|
||||||
|
"no-void": ["off"]
|
||||||
},
|
},
|
||||||
"ignorePatterns": ["metro.config.js"]
|
"ignorePatterns": ["metro.config.js"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,11 +11,12 @@
|
|||||||
"ios-dev": "react-native run-ios --scheme StandardNotesDev",
|
"ios-dev": "react-native run-ios --scheme StandardNotesDev",
|
||||||
"ios-prod": "react-native run-ios --scheme StandardNotes",
|
"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-*",
|
"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",
|
"lint:fix": "yarn lint --fix",
|
||||||
"format": "prettier ./src",
|
"format": "prettier ./src",
|
||||||
"format:fix": "yarn format --write",
|
"format:fix": "yarn format --write",
|
||||||
"build": "yarn android:bundle && yarn install:pods",
|
"build": "yarn android:bundle && yarn install:pods",
|
||||||
|
"pods": "yarn install:pods",
|
||||||
"tsc": "tsc --noEmit",
|
"tsc": "tsc --noEmit",
|
||||||
"start": "react-native start",
|
"start": "react-native start",
|
||||||
"install:pods": "yarn pod-install ios",
|
"install:pods": "yarn pod-install ios",
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
ApplicationIdentifier,
|
ApplicationIdentifier,
|
||||||
DeviceInterface,
|
DeviceInterface,
|
||||||
Environment,
|
Environment,
|
||||||
|
LegacyMobileKeychainStructure,
|
||||||
LegacyRawKeychainValue,
|
LegacyRawKeychainValue,
|
||||||
NamespacedRootKeyInKeychain,
|
NamespacedRootKeyInKeychain,
|
||||||
RawKeychainValue,
|
RawKeychainValue,
|
||||||
@@ -30,6 +31,12 @@ const isLegacyIdentifier = function (identifier: ApplicationIdentifier) {
|
|||||||
return identifier && identifier === LEGACY_IDENTIFIER
|
return identifier && identifier === LEGACY_IDENTIFIER
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isLegacyMobileKeychain(
|
||||||
|
x: LegacyMobileKeychainStructure | RawKeychainValue,
|
||||||
|
): x is LegacyMobileKeychainStructure {
|
||||||
|
return x.ak != undefined
|
||||||
|
}
|
||||||
|
|
||||||
const showLoadFailForItemIds = (failedItemIds: string[]) => {
|
const showLoadFailForItemIds = (failedItemIds: string[]) => {
|
||||||
let text =
|
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'
|
'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> {
|
): Promise<NamespacedRootKeyInKeychain | undefined> {
|
||||||
const keychain = await this.getRawKeychainValue()
|
const keychain = await this.getRawKeychainValue()
|
||||||
|
|
||||||
if (isLegacyIdentifier(identifier)) {
|
|
||||||
return keychain as unknown as NamespacedRootKeyInKeychain
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!keychain) {
|
if (!keychain) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return keychain[identifier]
|
const namespacedValue = keychain[identifier]
|
||||||
|
|
||||||
|
if (!namespacedValue && isLegacyIdentifier(identifier)) {
|
||||||
|
return keychain as unknown as NamespacedRootKeyInKeychain
|
||||||
|
}
|
||||||
|
|
||||||
|
return namespacedValue
|
||||||
}
|
}
|
||||||
|
|
||||||
async setNamespacedKeychainValue(
|
async setNamespacedKeychainValue(
|
||||||
value: NamespacedRootKeyInKeychain,
|
value: NamespacedRootKeyInKeychain,
|
||||||
identifier: ApplicationIdentifier,
|
identifier: ApplicationIdentifier,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (isLegacyIdentifier(identifier)) {
|
|
||||||
await Keychain.setKeys(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
let keychain = await this.getRawKeychainValue()
|
let keychain = await this.getRawKeychainValue()
|
||||||
|
|
||||||
if (!keychain) {
|
if (!keychain) {
|
||||||
@@ -259,16 +264,17 @@ export class MobileDeviceInterface implements DeviceInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async clearNamespacedKeychainValue(identifier: ApplicationIdentifier): Promise<void> {
|
async clearNamespacedKeychainValue(identifier: ApplicationIdentifier): Promise<void> {
|
||||||
if (isLegacyIdentifier(identifier)) {
|
|
||||||
await this.clearRawKeychainValue()
|
|
||||||
}
|
|
||||||
|
|
||||||
const keychain = await this.getRawKeychainValue()
|
const keychain = await this.getRawKeychainValue()
|
||||||
|
|
||||||
if (!keychain) {
|
if (!keychain) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!keychain[identifier] && isLegacyIdentifier(identifier) && isLegacyMobileKeychain(keychain)) {
|
||||||
|
await this.clearRawKeychainValue()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
delete keychain[identifier]
|
delete keychain[identifier]
|
||||||
await Keychain.setKeys(keychain)
|
await Keychain.setKeys(keychain)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user