Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .yarn/patches/react-native-test-app-npm-4.2.1-866b46545f.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index f0e3634e693478c417f5d0edf18c1fa9f6398c21..5c2191ee6aec6e7e7cae404897cce03504396436 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -12,7 +12,8 @@

<application
android:name=".TestApp"
- android:allowBackup="true"
+ android:allowBackup="false"
+ android:fullBackupContent="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
2 changes: 2 additions & 0 deletions KeychainExample/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ const styles = StyleSheet.create({
fontWeight: '200',
textAlign: 'center',
marginBottom: 20,
color: '#000',
},
field: {
marginVertical: 5,
Expand All @@ -319,6 +320,7 @@ const styles = StyleSheet.create({
fontWeight: '500',
fontSize: 15,
marginBottom: 5,
color: '#000',
},
input: {
color: '#000',
Expand Down
3 changes: 0 additions & 3 deletions android/src/main/java/com/oblador/keychain/KeychainModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.module.annotations.ReactModule
import com.oblador.keychain.cipherStorage.CipherCache
import com.oblador.keychain.cipherStorage.CipherStorage
import com.oblador.keychain.cipherStorage.CipherStorage.DecryptionResult
import com.oblador.keychain.cipherStorage.CipherStorageBase
Expand Down Expand Up @@ -157,8 +156,6 @@ class KeychainModule(reactContext: ReactApplicationContext) :
if (coroutineScope.isActive) {
coroutineScope.cancel("$KEYCHAIN_MODULE has been destroyed.")
}
// Clean up cipher cache
CipherCache.clearCache()
}

/** {@inheritDoc} */
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.security.keystore.KeyGenParameterSpec
import android.security.keystore.KeyInfo
import android.security.keystore.UserNotAuthenticatedException
import android.util.Log
import androidx.annotation.VisibleForTesting
import com.oblador.keychain.DeviceAvailability
import com.oblador.keychain.SecurityLevel
import com.oblador.keychain.cipherStorage.CipherStorageBase.DecryptBytesHandler
Expand Down Expand Up @@ -159,8 +158,8 @@ abstract class CipherStorageBase(protected val applicationContext: Context) : Ci

/** Get cipher instance and cache it for any next call. */
@Throws(NoSuchAlgorithmException::class, NoSuchPaddingException::class)
fun getCachedInstance(): Cipher {
return CipherCache.getCipher(getEncryptionTransformation())
fun getCipher(): Cipher {
return Cipher.getInstance(getEncryptionTransformation())
}

/** Check requirements to the security level. */
Expand Down Expand Up @@ -302,7 +301,7 @@ abstract class CipherStorageBase(protected val applicationContext: Context) : Ci
value: String,
handler: EncryptStringHandler?
): ByteArray {
val cipher = getCachedInstance()
val cipher = getCipher()
try {
ByteArrayOutputStream().use { output ->
if (handler != null) {
Expand Down Expand Up @@ -334,7 +333,7 @@ abstract class CipherStorageBase(protected val applicationContext: Context) : Ci
bytes: ByteArray,
handler: DecryptBytesHandler?
): String {
val cipher = getCachedInstance()
val cipher = getCipher()
try {
ByteArrayInputStream(bytes).use { input ->
ByteArrayOutputStream().use { output ->
Expand All @@ -353,8 +352,8 @@ abstract class CipherStorageBase(protected val applicationContext: Context) : Ci
e is javax.crypto.AEADBadTagException -> {
throw CryptoFailedException(
"Decryption failed: Authentication tag verification failed. " +
"This usually indicates that the encrypted data was modified, corrupted, " +
"or is being decrypted with the wrong key.",
"This usually indicates that the encrypted data was modified, corrupted, " +
"or is being decrypted with the wrong key.",
e
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class CipherStorageKeystoreAesCbc(reactContext: ReactApplicationContext) :
bytes: ByteArray,
handler: DecryptBytesHandler?
): String {
val cipher = getCachedInstance()
val cipher = getCipher()

return try {
// read the initialization vector from bytes array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,12 @@ class CipherStorageKeystoreAesGcm(

/** Save Initialization vector to output stream. */
val encrypt = EncryptStringHandler { cipher, key, output ->
cipher.init(Cipher.ENCRYPT_MODE, key)
val iv = cipher.iv
output.write(iv, 0, iv.size)
cipher.init(Cipher.ENCRYPT_MODE, key)
val iv = cipher.iv
if (iv.size != IV_LENGTH) {
throw CryptoFailedException("IV length mismatch: expected ${IV_LENGTH}, got ${iv.size}")
}
output.write(iv, 0, iv.size)
}

/** Read initialization vector from input stream and configure cipher by it. */
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,8 @@
}
]
]
},
"resolutions": {
"[email protected]": "patch:react-native-test-app@npm%3A4.2.1#./.yarn/patches/react-native-test-app-npm-4.2.1-866b46545f.patch"
}
}
37 changes: 37 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16172,6 +16172,43 @@ __metadata:
languageName: node
linkType: hard

"react-native-test-app@patch:react-native-test-app@npm%3A4.2.1#./.yarn/patches/react-native-test-app-npm-4.2.1-866b46545f.patch::locator=react-native-keychain%40workspace%3A.":
version: 4.2.1
resolution: "react-native-test-app@patch:react-native-test-app@npm%3A4.2.1#./.yarn/patches/react-native-test-app-npm-4.2.1-866b46545f.patch::version=4.2.1&hash=faaa1b&locator=react-native-keychain%40workspace%3A."
dependencies:
"@rnx-kit/react-native-host": ^0.5.4
"@rnx-kit/tools-react-native": ^2.1.0
ajv: ^8.0.0
cliui: ^8.0.0
fast-xml-parser: ^4.0.0
prompts: ^2.4.0
semver: ^7.3.5
uuid: ^11.0.0
peerDependencies:
"@callstack/react-native-visionos": 0.73 - 0.77
"@expo/config-plugins": ">=5.0"
react: 18.1 - 19.0
react-native: 0.70 - 0.78 || >=0.79.0-0 <0.79.0
react-native-macos: ^0.0.0-0 || 0.71 - 0.77
react-native-windows: ^0.0.0-0 || 0.70 - 0.77
peerDependenciesMeta:
"@callstack/react-native-visionos":
optional: true
"@expo/config-plugins":
optional: true
react-native-macos:
optional: true
react-native-windows:
optional: true
bin:
configure-test-app: scripts/configure.mjs
init: scripts/init.mjs
init-test-app: scripts/init.mjs
install-windows-test-app: windows/test-app.mjs
checksum: 26f6bfcfcf0646afadb73582895bc1a1b8ed9c4ba445dd61cb06942f9c880aec33197cf24290fc164e568f4a392c8953666ab49a263c34eb5dcdfe7ccd8878a2
languageName: node
linkType: hard

"react-native@npm:0.77.1, react-native@npm:^0.77.1":
version: 0.77.1
resolution: "react-native@npm:0.77.1"
Expand Down