conorpp / u2f-zero

U2F USB token optimized for physical security, affordability, and style
Other
2.41k stars 200 forks source link

Prevent extraction of secret keys #66

Closed artemist closed 6 years ago

artemist commented 6 years ago

Currently, the ECC keys calculated with the HMAC of the secret and the handle are extractable by recording the I2C traffic between the EFM8UB1 and the ATECC508A. The code that calculates and transfers the handle-specific private key is here: https://github.com/conorpp/u2f-zero/blob/36c9f9ecd50a68322fd60f9ab06b40a4cbacb38d/firmware/src/u2f_atecc.c#L300-L321

There are a few options to fix this:

I would recommend changing the readme for now, and preventing this attack later. I will attempt to get the datasheet for the ATECC508A to see if it is possible.

darconeous commented 6 years ago

I would be surprised if the ATECC508A is capable of generating a private key from the output from an internal HMAC operation without the private key material making a round trip. (I must admit I'm puzzled as to why the industry insists on all parts like this have the data sheets released only under NDA, but I digress)

The fact that most (all?) of these devices are not even encapsulated makes it possible for this attack to be performed without physically damaging the token.

I would recommend changing the readme for now, and preventing this attack later.

+1

conorpp commented 6 years ago

The HMAC response (ATECC -> EFM8) is XOR'd with a 32-byte key (by the ATECC) that is generated at programming time and it known to both devices. It is unmasked at line 318 of your code snippet.

atecc_privwrite will similarly wrap it with a different 32-byte key and the ATECC will unwrap it.

So an adversary can only observe R ^ K on the I2C bus, where R is a fixed random number and K is a secret key. I believe this is fine but I appreciate any feedback.

conorpp commented 6 years ago

@darconeous Security IC manufacturers usually have implicit NDA and commercial requirements for who can use the ICs because if someone finds a flaw, it's really expensive to fix. I guess red tape can prolong the discovery of a flaw. Infineon is dealing with this right now.

artemist commented 6 years ago

Oh, I did not realize that RMASK and WMASK were generated per-device. I can't think of any attacks that would allow you to use K ^ R and K ^ W to get private keys assuming that HMAC is a PRF and the ECDLP holds. However, this does reduce the security to an attacker's inability to read from the MCU flash. I'll look into the documentation to see if there are any ways past the EFM8 flask lock.

Alternatively, the MCU could keep only the first 4 bytes of RMASK and WMASK, which is all that is necessary to format the key, from what I can understand. The rest of the key would be HMAC ^ RMASK ^ WMASK, so the private key would be different than just taking the HMAC, but the MCU would not need to know what it is.

darconeous commented 6 years ago

Ah, I remember that mechanism now from when I was reviewing the algorithm. It seemed sufficient to me at the time. I'm embarrassed I forgot about that.

Security IC manufacturers usually have implicit NDA and commercial requirements for who can use the ICs because if someone finds a flaw, it's really expensive to fix. I guess red tape can prolong the discovery of a flaw. Infineon is dealing with this right now.

Of course, by prolonging the discovery of the flaw, they made it much more expensive than it would have been to fix otherwise.

Off topic, but my gut feeling is that there are two additional reasons:

szszszsz commented 6 years ago

Hi! Is this still valid? Masking with random rkey/wkey seems to be enough to protect from originally reported issue (extracting secrets via eavesdropping the I2C).

darconeous commented 6 years ago

Resolved to my satisfaction. For what it's worth.

As long as there is no way for an attacker to control or guess the bits that are being wrapped with the XOR, then it seems safe.

conorpp commented 6 years ago

Closing, thanks!