remko / age-plugin-se

Age plugin for Apple's Secure Enclave
MIT License
120 stars 4 forks source link

Help understanding encryption safety #6

Open jld-adriano opened 3 months ago

jld-adriano commented 3 months ago

Hey, need some help to understand what exactly is encrypted and where. For example

Would it be safe to keep an identity encrypted with my current-biometry in a public repo? I'm assuming noone could actually use it unless they both have access to my laptop AND my biometry.

Or of course, if there is some vulnerability in the encryption algorithm itself

Not sure if this is the best medium to ask, but thanks in advance

remko commented 2 months ago

This is probably the best medium to ask.

age-plugin-se uses SecureEnclave.P256.KeyAgreement.PrivateKey to construct private keys. The age identity is an encoding of the dataRepresentation of the private key. Unfortunately, there currently doesn't seem to be any detailed description of what the properties of these private keys and their data representation are (or I haven't found it at least), so all I can give is anecdotal evidence.

I'm assuming noone could actually use it unless they both have access to my laptop AND my biometry.

That seems to correspond to my assumption. Moreover, it seems that a private key without any protection (biometry or passcode) is also not usable on the same machine as a different user. I don't know what happens to the key's validity if you wipe your machine and restore it from backup.

That said, I tend to keep my secret keys private.

If someone can find a more definitive answer with pointers to documentation, that would be very welcome.

CodeWithShreyans commented 4 weeks ago

So the "private key" output to the file is not actually a private key but the private key is stored in the SE?

remko commented 4 weeks ago

@CodeWithShreyans No, that doesn't sound correct. No private keys are stored in the SE, otherwise storage could run out when generating keys. The SE generates a private key, encrypts it, and outputs the encrypted data. Only that specific SE can decrypt the private key and use it for operations.

CodeWithShreyans commented 4 weeks ago
image
remko commented 4 weeks ago

@CodeWithShreyans Right, that confirms what I said.

Also, from this article:

When you protect a private key with the Secure Enclave, you never handle the plain-text key, making it difficult for the key to become compromised. Instead, you instruct the Secure Enclave to create and encode the key, and later to decode and perform operations with it.

CodeWithShreyans commented 4 weeks ago

oh that's interesting

well I learned something new today