liftric / kvault Goto Github PK
View Code? Open in Web Editor NEWSecure key-value storage for Kotlin Multiplatform projects.
License: MIT License
Secure key-value storage for Kotlin Multiplatform projects.
License: MIT License
Info
I'm using KVault (version 1.2.1) for a Kotlin Multiplatform project.
kVault iOS main part creates many memory leaks in our project. Most of the leaked objects have a type of CFDictionaryCreateMutable. Here are the places of the leaks:
> KVault/kvault/src/iosMain/kotlin/com/liftric/kvault/KVault.kt:188
> KVault/kvault/src/iosMain/kotlin/com/liftric/kvault/KVault.kt:174
> KVault/kvault/src/iosMain/kotlin/com/liftric/kvault/KVault.kt:176
> KVault/kvault/src/iosMain/kotlin/com/liftric/kvault/KVault.kt:28
> KVault/kvault/src/iosMain/kotlin/com/liftric/kvault/KVault.kt:158
> KVault/kvault/src/iosMain/kotlin/com/liftric/kvault/KVault.kt:176
> KVault/kvault/src/iosMain/kotlin/com/liftric/kvault/KVault.kt:116
> KVault/kvault/src/iosMain/kotlin/com/liftric/kvault/KVault.kt:162
...
and so on. I think the problem occurs because of these CF[TYPE]s.
Please note that kVault does not create any memory leaks in Android.
### Expected behavior
kVault shouldn't create any memory leaks in iOS.
Hello,
When I want to read a string immediately after writing the sting to Kvault, it continues to return null. Is the KmmPreference.putString(key, value)
method working asynchronously? Is there a lock mechanism for this?
Thank you
Thank you for your previous fix about the issue. Although new updated version seems to fix the significant number of leaks, there are still remaining leaks. Here are the places of the leaks:
> KVault/kvault/src/iosMain/kotlin/com/liftric/kvault/KVault.kt:46
> KVault/kvault/src/iosMain/kotlin/com/liftric/kvault/KVault.kt:196
> KVault/kvault/src/iosMain/kotlin/com/liftric/kvault/KVault.kt:240
> KVault/kvault/src/iosMain/kotlin/com/liftric/kvault/KVault.kt:254
> KVault/kvault/src/iosMain/kotlin/com/liftric/kvault/KVault.kt:256
> KVault/kvault/src/iosMain/kotlin/com/liftric/kvault/KVault.kt:268
May be using weak references could resolve this problem.
### Expected behavior
kVault shouldn't create any memory leaks in iOS.
Correct me if I wrong.
I can see the minSDK is 21, but the dependency androidx.security:security-crypto:1.1.0-alpha03 is using minSDK 23.
What happens if the device API 21 runs an app that uses Kvault? Does encrypt function work well?
The KDoc is targeting the iOS keychain. Change wording to something generally, and add platform specific documentation.
Write remaining test case for the clear method. It has to be tested with two KVault's that have different identifiers (serviceName) โ this should only delete the items from one KVault.
Works in praxis as expected. Though add this for completeness.
I have not been able to try out this project successfully. When I add the line "implementation("com.liftric:kvault:1.7.0")" to my apps build.gradle.kts I get a taskExecutionException. Any ideas to why the first step doesnt work?
This source of the error is:
Incompatible abi version. The current default is '1.4.2', found '1.5.0'. The library produced by 1.5.20 compiler?
I tried 1.5.30 as well, but the error remains.
To eliminate the need to initialise KVault from both platforms we have to give the Android implementation a default context. Preferably by a non-hacky way.
I am not able to run the Kotlin tests on the iOS simulator (arm64). Is this a known issue?
kotlin.AssertionError at null:-1
com.liftric.kvault.KVaultTest.testDeleteObject FAILED
kotlin.AssertionError at null:-1
com.liftric.kvault.KVaultTest.testExistsObject FAILED
kotlin.AssertionError at null:-1
com.liftric.kvault.KVaultTest.testOverride FAILED
kotlin.AssertionError at null:-1
com.liftric.kvault.KVaultTest.testSetGetAll FAILED
kotlin.AssertionError at null:-1
com.liftric.kvault.KVaultTest.testSetGetBoolean FAILED
kotlin.AssertionError at null:-1
com.liftric.kvault.KVaultTest.testSetGetData FAILED
kotlin.AssertionError at null:-1
com.liftric.kvault.KVaultTest.testSetGetDouble FAILED
kotlin.AssertionError at null:-1
com.liftric.kvault.KVaultTest.testSetGetFloat FAILED
kotlin.AssertionError at null:-1
com.liftric.kvault.KVaultTest.testSetGetInt FAILED
kotlin.AssertionError at null:-1
com.liftric.kvault.KVaultTest.testSetGetLong FAILED
kotlin.AssertionError at null:-1
com.liftric.kvault.KVaultTest.testSetGetString FAILED
kotlin.AssertionError at null:-1
Keep running into this error that gets fix after I change the file name: so I basically have a counter that I have to update in order to fix it, do you know why this could be happening?
single { KVault(get(), fileName = "fileName:1") }
0: system/security/keystore2/src/operation.rs:426: Finish failed.
1: Error::Km(r#VERIFICATION_FAILED)) (public error code: 10 internal Keystore code: -30)
at android.security.KeyStore2.getKeyStoreException(KeyStore2.java:386)
at android.security.KeyStoreOperation.handleExceptions(KeyStoreOperation.java:78)
at android.security.KeyStoreOperation.finish(KeyStoreOperation.java:128)
at android.security.keystore2.KeyStoreCryptoOperationChunkedStreamer$MainDataStream.finish(KeyStoreCryptoOperationChunkedStreamer.java:228)
at android.security.keystore2.KeyStoreCryptoOperationChunkedStreamer.doFinal(KeyStoreCryptoOperationChunkedStreamer.java:181)
at android.security.keystore2.AndroidKeyStoreAuthenticatedAESCipherSpi$BufferAllOutputUntilDoFinalStreamer.doFinal(AndroidKeyStoreAuthenticatedAESCipherSpi.java:396)
at android.security.keystore2.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:618)
For android, you have to pass the android context to KVault. How do I add the context to KVault from inside the shared module? Can you provide an example for this? This isn't really an issue, it's just unclear how to do it based on the documentation.
Think about temporary solution for iOS testing as long as the test target (klib) is not able to execute ktor on main thread: you are either stuck in mutation exception due to frozen thread or endless blocking.
SharedPreference provides two ways to write changes i.e., commit()
and apply()
. Where commit()
is a synchronous call and can block Mainthread. Whereas apply()
write in-memory first followed by asynchronously to the disk.
More details on apply() can be found here.
Can we add option to use apply() by introducing a new API KVault.setAsync(... , ...)
?
Hey, your library is exactly what I was looking for! Unfortunately, it was a bit hard for me to find out. What do you think about adding it to some KMM library lists?
For example:
https://github.com/AAkira/Kotlin-Multiplatform-Libraries
https://github.com/icerockdev/libs.kmp.icerock.dev
That would make it much easier to find it :)
Hello
Is there an example for template for implementing this in iOS?
Do i need to enable KeyChain permissions in some way?
Hi looking on Android implementation of KVault it looks like its API does not allow custom sharedPreferences name.
encSharedPrefs = EncryptedSharedPreferences.create(
context,
"secure-shared-preferences",
masterKey,
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
)
The "secure-shared-preferences" is hardcoded. Is it possible to add a second argument to KVault constructor with default value, so that at least there will be an option to give a unique fileName.
Is there a way KVault could support storing binary data in the secure storage? iOS's keychain supports storing raw bytes. It doesn't look like EncryptedSharedPreferences
on Android can store bytes, but you could encode it as Base64 on Android to support it on that side.
First of all, great project!
I'm in need of the latest version of master, specifically this config: https://github.com/Liftric/KVault/blob/master/src/iosMain/kotlin/com/liftric/kvault/KVault.kt#L22
Is there anything specifically blocking you from releasing a new version with this code?
Will JS target support be added?
I have added KMM dependency in my code using given commands. But when am trying run the code in ios. Code returns an error:
error: Could not find "/Users/vivu/.gradle/caches/modules-2/files-2.1/com.liftric/kvault-iosx64/1.12.0/6429d98f1faefbf70ea32b3b296a41ece3a6084c/kvault.klib" in [/Users/vivu/Desktop/Wits_cloud-communication-poc/cloud-communication-poc/iosApp/Pods, /Users/vivu/.konan/klib, /Users/vivu/.konan/kotlin-native-prebuilt-macos-x86_64-1.8.21/klib/common, /Users/vivu/.konan/kotlin-native-prebuilt-macos-x86_64-1.8.21/klib/platform/ios_x64]
error: Compilation finished with errors
FAILURE: Build failed with an exception.
Please help me to get the solution.
Thanks in Advance
Needs a way to retrieve all currently stored keys.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.