TheMysteriousX / SNMPv3-Hash-Generator

Apache License 2.0
13 stars 5 forks source link

Generated MD5 keys are invalid #2

Closed c-po closed 4 years ago

c-po commented 4 years ago

First of all I want to thank you for this implementation.

I noticed then when using your library and comparing the generated output to the examples in the RFC the MD5 implementation seems to be off. I can not generate the expected key: https://tools.ietf.org/html/rfc3414#appendix-A.3.1

>>> Hashgen.kdf('maplesyrup').hex()
'9fb5cc0381497b3793528939ff788d5d79145211'

It should be 9faf3283884e92834ebc9847d8edd963 but it rather returns the SHA1 value as kdf() ignoes the requested hash -> https://github.com/TheMysteriousX/SNMPv3-Hash-Generator/blob/master/snmpv3_hashgen/hashgen.py#L27

Also specifying --hash md5 on the command-line will render:

Traceback (most recent call last):
  File "/usr/local/bin/snmpv3-hashgen", line 10, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.7/dist-packages/scripts/snmpv3_hashgen.py", line 54, in main
    esxi = format_esxi(user, Kul_auth, Kul_priv, mode, hash)
  File "/usr/local/lib/python3.7/dist-packages/scripts/snmpv3_hashgen.py", line 25, in format_esxi
    return f"{user}/{hash(Kul_auth)}/{hash(Kul_priv)}/{mode}"
TypeError: 'staticmethod' object is not callable
TheMysteriousX commented 4 years ago

Thanks for the info - this should be fixed, it was a couple of logic errors. I'll throw the updated version on PyPI later.

Glad you've found it useful.

c-po commented 4 years ago

Yes - it was very much usefull in understanding the SNMPv3 hash voodoo. Thanks for publishing.