-
Notifications
You must be signed in to change notification settings - Fork 535
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
Support DSA signatures of SHA-HMAC output objects #414
Comments
Most probably you are instantiating As an alternative, I suggest you create the signing object with |
I will try that, and I will evaluate just that, I hope it doesn't break everything, thanks for the heads up! |
@Legrandin I'm not 100% sure of my conclusions so I don't dare open an invalid bug report, I'll comment on this closed ticket instead so you can check how wrong I am about what follows: I've tried what you suggested, not yet checked the protocol implications but I'm trying to get the code working in the first place. The issue is triggerred by the deterministic-rfc6979' DSS signature of a HMAC object. I get the following exception:
made clearer by manually removing the try except from pycryptodome/lib/Crypto/Hash/HMAC.py Line 70 in 6fb4ca4
which then gives us the exact line:
I nearly lost my mind, but then found that during the signature attempt, completely unrelated to my HMAC object, pycryptodome internally constructs some HMAC in compute_nonce: pycryptodome/lib/Crypto/Signature/DSS.py Line 215 in 39626a5
This and the few following calls to HMAC.new() all provide, as a third parameter the mhash variable, which actually contains the input data object and HMAC.new() expects this third parameter to be a digestmod (for example a SHA256 object). This can only work when the input data happens to be a valid digestmod object. The good news is the HMAC object does actually contain a reference to its hashing primitive under the ._digestmod attribute, which would actually work as a way to pass along the right object inside compute_nonce but naked hash objects don't have such a self-referencing ._digestmod attribute, thus blindly adding ._digestmod to the HMAC instanciations would break naked hash deterministic signatures. As this does not appear to be a trivial fix in term of design I can't provide a PR, I'm not sure what design would be best :( I hope my understanding is correct this time around, if not sorry for wasting your time again on this issue :) |
Hello,
I've been working at a ridiculous slow pace on porting the python OTRv3-ish implementation over at pure-python-otr from pycrypto to your great library.
I've hit a roadlock recently with DSA signatures, as I'm required to sign the output of a HMAC-sha construct. However, your current code does not allow for that, sadly.
I understand and am completely behind the idea if having OIDs to check we're not doing cryptocrap accidentally, but I am seeing here:
pycryptodome/lib/Crypto/Hash/HMAC.py
Line 46 in 6fb4ca4
that HMAC objects do not have any kind of OIDs, which is actually a shame as elsewhere you do sort of associate them with one:
pycryptodome/lib/Crypto/IO/_PBES.py
Line 57 in 41300af
There, the OID of SHA256HMAC() is "1.2.840.113549.2.9"
However, the validation for DSA signatures is as follow:
https://github.com/Legrandin/pycryptodome/blob/master/lib/Crypto/Signature/DSS.py#L279
Thus, I of course hit the error:
Signing HMAC outputs appears to be impossible in the current state of the library, and as I discuss it here: python-otr/pure-python-otr#68 (comment) it's leaving me stuck with pycrypto, which is a maintenance nightmare for distributions downstream :(
I do understand that fixing this would require a bit of a rework, but I think DSA signature of HMAC outputs is a legitimate usecase, if not for OTR, for other people who might need such a construct in the future.
If I can be of any assistance in helping out with the effort, please let me know, if I trusted myself with such a rework I would have attempted a pull request, but I would hate to f* something up :/
The text was updated successfully, but these errors were encountered: