Skip to content

3.1.0

Choose a tag to compare

@ioannisa ioannisa released this 23 Aug 23:22
· 31 commits to main since this release

KSafe no longer depends on a third-party cryptography library — on any platform. Drop-in upgrade: existing data is untouched, nothing migrates.

implementation("eu.anifantakis:ksafe:3.1.0")
implementation("eu.anifantakis:ksafe-compose:3.1.0")     // optional
implementation("eu.anifantakis:ksafe-biometrics:3.1.0")  // optional

New

  • Own Apple CryptoKit bridge — dev.whyoleg.cryptography is gone. Apple still does the crypto; the wrapper (and its transitive IrLinkageError risk) disappeared. iosArm64 footprint: 13 artifacts / 3.7 MB → 1 / 16 KB. Old ciphertext verified byte-compatible on a physical iPhone, 286 device tests green.
  • Mode-typed views — KSafePlain, KSafeEncrypted, KSafeHardwareIsolated: the write mode becomes a type, not an argument. Own section below. 👇
  • Interrupted key rotation resumes automatically on the next KSafe instance — same generation, even under Policy.Never. Entries skipped by a completed rotation (e.g. device locked) are retried on later instances with a bounded budget: KSafeConfig(keyRotationRetryAttempts = 3). 📖 docs/KEY_ROTATION.md
  • Typed AES key strength — KSafeConfig(aesKeySize = KSafeAesKeySize.BITS_128) (default BITS_256); WebCrypto now honours it too. New key material only; existing keys keep their size until rotateKeys().

Mode-typed views: KSafePlain / KSafeEncrypted / KSafeHardwareIsolated

When one store holds both preferences and secrets, the per-call mode = argument is a convention — and one forgotten argument silently writes with the wrong protection. The three view types turn that convention into a compiler rule: each wraps an existing KSafe instance and freezes the write mode at construction. No member of these types takes a mode parameter, so a call site can't store a secret in plaintext — or encrypt a trivial preference — by picking the wrong argument.

val prefs = KSafePlain(ksafe)            // or: ksafe.plain
val vault = KSafeHardwareIsolated(ksafe) // or: ksafe.hardwareIsolated

prefs.putDirect("theme", "dark")         // always Plain — nothing to forget
vault.put("master_key", secret)          // always requests StrongBox / Secure Enclave

var theme by prefs("dark")               // delegate: key = property name, writes Plain
val pin by vault.asWritableFlow("", key = "pin")   // .set() writes hardware-isolated

The full write surface is covered — put/putDirect, the by view(...) delegate, asFlow/asWritableFlow/asStateFlow/asMutableStateFlow/getStateFlow, and via :ksafe-compose both mutableStateOf and rememberKSafeState — so the guarantee has no gap where writes actually happen.

In Koin, the types replace stringly named(...) qualifiers. One store, distinct injectable views:

single { KSafe(context = androidApplication(), fileName = "app") }
single { KSafePlain(get()) }
single { KSafeHardwareIsolated(get()) }

class SettingsRepository(private val prefs: KSafePlain)          // writes always Plain
class AuthRepository(private val vault: KSafeHardwareIsolated)   // writes always request SE/StrongBox

All views over one instance share the same file, key namespace and cache — mixed-mode entries keep working, and a value written through one view is immediately visible through any other. KSafeEncrypted/KSafeHardwareIsolated also freeze the unlock policy: KSafeEncrypted(ksafe, requireUnlockedDevice = true) makes every write through that view strict, while the default constructor inherits the instance's configured policy.

Three honest boundaries:

  • Write-side only — reads stay mode-free and auto-detect each entry's protection.
  • KSafeHardwareIsolated requests, it doesn't guarantee — without StrongBox / Secure Enclave the write degrades to the documented next-best custody and reports it via protectionInfo.
  • Store-scoped operations aren't on the views (rotateKeys, clearAll, close, protectionInfo, …) — call them on the underlying instance, exposed as view.ksafe.

📖 docs/USAGE.md

Breaking / Deprecated

  • Removed: Apple-only obtainAesGcm() — its return type came from the removed dependency. Replacement in your code: CryptographyProvider.CryptoKit.get(AES.GCM).
  • Deprecated: KSafeConfig.keySize: Int → aesKeySize (removal in 4.0.0; old spelling still works).
  • KSafeConfig.component1() changed shape — only destructuring a config needs a rebuild.

Fixes

  • Android/JVM: an encrypt in flight across clearAll() no longer re-persists the wiped key — the write survives and cryptographic erasure holds.
  • Web: a write torn by process death can no longer read back as the previous entry's bytes; reads return your default instead.
  • rotateKeys() now retires superseded master keys that a torn write used to pin alive forever.
  • Biometrics: a caller queued behind a same-scope prompt no longer gets a redundant prompt; Apple now serializes concurrent prompts like every other platform.

Details: CHANGELOG.md

Full Changelog: 3.0.0...3.1.0