-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Crypto] fix KMS signing bug for long messages #318
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! LGTM
Sorry the naive question but why not always pre-hash ? This way you can also support SHA3 |
@bluesign |
If I understand correctly, hash is the "weakest link" here it means.
Here I think we differ. In Flow use case, other use cases I am not sure, only attack is to confuse Transaction with Hash. (which is only possible here actually ) So I specially craft a Transaction, which looks innocent, but transaction canonical form will be equal to the hash of my evil transaction. But in this case minimum Flow Transaction Payload length but more importantly transaction domain tag prevent those attacks. ( I cannot send hash to HSM at the first place when in transaction (plaintext) mode without domain tag ) |
I agree that on Flow a hash (32 bytes) cannot be confused as a signable transaction payload (at least 32 bytes DST + other data).
I don't think I understood the attack path though. Can you please formulate it differently ? The added security by hashing on HSM is mainly to guarantee that the hashing computation and signable hash are trusted. This avoids the HSM signing some hash sent from outside. An attack may still tamper with the original message on the application device, but at least it can't tamper with the hash itself, hence reducing the tampering window. |
Regarding SHA3 support: In theory, it is possible to pre-hash using SHA3 and only process the following steps on HSM as you mentioned. For now we restricted the support to SHA2 for consistency because the ECDSA keys generated on KMS specify the hashing algo and for now only include SHA2. |
I was thinking more on what is feeling not ok for me, I think I figured it out. ( After a lot of coffee ) Consider a system with flow-go-sdk: ( let's say a web REST service for signing getting arbitrary transaction data ) User - Service - KMS - Flow Network: let's say service is super dummy and just passing data to KMS. ( or let's say simply exposing KMS methods to web, which just validating byte array is a Transaction ) We have 1 method: Collision case ( on SHA ) can be ignored as this is not our concern ( as it will be similar bad in KMS as ours ), that leaves us with bad implementation on hashing algorithm. (causing a prefix collision attack, preimage attack etc ) in case of pre-image attack: In case of prefix collision attack: So sending KSM here is obviously has benefits. ( for prefix collision attack) But now, when we add the size limit (65536), aren't we back to square one ? Considering hashing algorithm is buggy and vulnerable to preimage attack, as we can choose p1 and p2 in preimage attack, and only search for m1 and m2, we can keep both payloads over 65536 easily. PS: I think we can most likely say that Transaction structure is not vulnerable to the preimage attack but it is not relevant in this discussion. |
I see what kind of issues you were considering.
I would consider the method as Reusing the same flow you described: User - Service - KMS - Network, we should first assume the network (the party that verifies signatures) is using a secure hash function Now we're comparing:
In both options, KMS does not check the data it receives corresponds to a valid transaction. The service is the party that is supposed to guarantee that. Let's call We can also make the assumption that KMS implements the same
I think there is no need in this case to consider the collision properties of (2) has less windows than (1) to trick the service, as it reduces the attack window to changing |
FYI, it seems to me that AWS HSM interface does not allow pre-hashing when signing (had a quick look at the API so I might be wrong) https://docs.aws.amazon.com/cloudhsm/latest/userguide/key_mgmt_util-sign.html |
Iirc the hsm also includes a tighter limit on payload size. |
https://docs.aws.amazon.com/cloudhsm/latest/userguide/pkcs11-mechanisms.html#mech3-2
@pgebheim correct they seem to do 16kb max |
Closes: #317
Description
Fixes a bug when messages signed by Google KMS are longer than 65536 bytes.
If the message is longer than the KMS limit, pre-hash the message outside KMS.
For contributor use:
master
branchFiles changed
in the Github PR explorer