Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Requires termux-api-package #33.
This patch adds an interface for Android keystore. You can read all the features on that page, but I believe the main benefit of using it is extraction prevention.
In short, Android keystore allows the storage of cryptographic keys inside a secure hardware. The key is generated inside the chip, and it never leaves the hardware - actually the chip does not even have a function to export the secret key.
Even with root privileges, it is not possible to extract these keys.
Instead, the applications ask the chip to sign/verify/encrypt/decrypt a particular piece of data in behalf of them, and the hardware does this inside itself and outputs the result. Again, the secret key always stays inside the chip.
This script provides 5 commands:
(Note that the verify action is for convenience only, due to the way asymmetric encryption works anyone can do the verification given the public key.)
Example commands to test:
termux-keystore generate myAlias -a RSA -s 2048termux-keystore listecho "test file" >> testfiletermux-keystore sign myAlias SHA512withRSA < testfile > signaturetermux-keystore verify myAlias SHA512withRSA signature < testfile # should return trueecho "different file" >> differentfiletermux-keystore verify myAlias SHA512withRSA signature < differentfile # should return falseAlthough by itself this is a complete tool, the API becomes much more useful when combined with a middleware that I have created: tergent (short for termux-ssh-agent). This small application is a ssh-agent implementation that uses this backend to store the keys inside the chip. This provides the security of hardware-based tokens without the inconvenience of carrying a separate device - the chip acts as the secure component.
Thanks for reading, and looking forward to any comments.