termux-api icon indicating copy to clipboard operation
termux-api copied to clipboard

KeyStoreAPI Upgrade (Encrypt/Decrypt + more)

Open EduardDurech opened this issue 3 years ago • 2 comments

Fixes #550, resolves #246 Requires https://github.com/termux/termux-api-package/pull/161 and https://github.com/termux/termux-app/pull/3043

  • Receiver receives context, sent to list, delete, encrypt, and decrypt for shared preferences

  • listKeys is now listData and supports showing secret keys and preferences

  • printKey supports secret keys and more KeyInfo parameters

  • deleteKey is now deleteData and supports deleting preferences

  • deleteData deletes all key-associated preferences upon deletion

  • generateKey supports more key parameters (mode, padding, purposes, unlocked, invalidate, auths)

  • generateKey supports secret keys

  • generateKey refactored

  • encryptData added

  • encryptData supports Keystore Ciphers

  • encryptData supports reading from path or stdin

  • encryptData supports writing to shared preferences or stdout

  • encryptData writes output in the form [IV.length][IV][Encrypted Data], if IV.length is 0 then IV omitted

  • encryptedData never exposes data to Strings, stays as byte arrays and is flushed with zeroes after use

  • encryptedData supports a quiet flag so encrypted data does not show in stdout

  • encryptedData supports multiple shared preferences stored as a JSON with a key, value pair

  • encryptedData encodes output to Base64

  • decryptData added

  • decryptData supports Keystore Ciphers

  • decryptData supports reading from path, shared preferences, or stdin

  • decryptData supports writing to stdout

  • decryptData reads output in the form [IV.length][IV][Encrypted Data], if IV.length is 0 then IV omitted

  • decryptedData never exposes data to Strings, stays as byte arrays and is flushed with zeroes after use

  • decryptedData supports a quiet flag so decrypted data does not show in stdout

  • decryptedData supports reading from JSON shared preferences with a key, value pair

  • decryptedData encodes output to Base64

  • decomposeBinary (for purposes and authorizations)

  • getPrefsJSON and setPrefJSON (preferences as JSON)

  • getIVSpec (support different AlgorithmParameterSpecs)

  • getKey (get Public or Secret key for encryption, Private or Secret key for decryption)

  • readFile (also supports Android < 8.0)

  • Replaced ECGenParameterSpec and RSAKeyGenParameterSpec with AlgorithmParameterSpec

  • Removed unnecessary imports and casts

EduardDurech avatar Sep 29 '22 18:09 EduardDurech

Getting build error with latest commit Added activity.finish(). Build succeeds when removing this commit.

/home/runner/work/termux-api/termux-api/app/src/main/java/com/termux/api/apis/FingerprintAPI.java:122: error: cannot find symbol if (context instanceof Activity) ((Activity) context).finish(); ^

TermuxMonet avatar Apr 14 '23 23:04 TermuxMonet

Getting build error with latest commit Added activity.finish(). Build succeeds when removing this commit.

/home/runner/work/termux-api/termux-api/app/src/main/java/com/termux/api/apis/FingerprintAPI.java:122: error: cannot find symbol if (context instanceof Activity) ((Activity) context).finish(); ^

Unfortunately, I'm too busy to work on this, when I had built it last year it was fine, not sure if there's a conflict with a new API version, but all this part of the code does is close the fingerprint fragment activity once finished, as it left an overlay, the discussion is here https://github.com/termux/termux-api/issues/550#issuecomment-1287785719 and the comments proceeding (including my hidden ones, I did that just for brevity)

I'm not sure I understand the error though, cannot find symbol? is it referring to context? That should be passed in the postFingerprintResult method definition, otherwise it would be Activity, but that's a protected word, no?

Where exactly was the ^ pointing to? Or was it in-line as you showed? If that's the case it seems like an odd error, could be a tab-representation problem

EduardDurech avatar Oct 02 '23 21:10 EduardDurech