0
$\begingroup$

Trying to write a PKCS#12 integrity function as in RFC 7292.

See certificate below (generated with openSSL), password = "123456".

  1. I compared with mbed TLS and it looks good, but could someone confirm that the computed key from salt (0xCFA02B24583B9EE36C508C7FFB875FE652AD797F), password and iterations (100000) using SHA1 is actually 0xB988D43E0B9CF2B84D837A3DD3FCEDFA826D9E1D?

  2. RFC 7292 states that "If the PFX PDU is to be authenticated with HMAC, then an HMAC with SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, or SHA-512/256 is computed on the contents of the Data in T (i.e., excluding the OCTET STRING tag and length bytes). In this example, Data should be 0x308209F7308205AE0609...3092DCC53A93ECFE3D (2555 bytes).

With this chunk, the computed HMAC is different from the expected one (0xE897CBC69CA16B9EA7C717708DACAA8223D55E0F). Am I using the correct byte string for Data? Is there simple a test case in C somewhere that I can compile to compare step by step values with a debugger?

Thanks.

Certificate

MIIKVQIBAzCCCg4GCSqGSIb3DQEHAaCCCf8Eggn7MIIJ9zCCBa4GCSqGSIb3DQEHAaCCBZ8EggWbMIIFlzCCBZMGCyqGSIb3DQEMCgECoIIFQDCCBTwwZgYJKoZIhvcNAQUNMFkwOAYJKoZIhvcNAQUMMCsEFJWf1ydRHZI9JZsnuNTSBJB+1BR5AgInEAIBIDAMBggqhkiG9w0CCQUAMB0GCWCGSAFlAwQBKgQQZnFscCtS1OxpkGpn8CQlpwSCBNCikY16/khORlbwsz7ifaTj3ue6rCpMETqUuV0GgqFf1Tuc5T54u15QdJZD15XT0eVMzbglN35KVm6A58nW72Ymv2BIwvJK7jPm3z0ugPm6At9fv8B3y1CSl4d7VHRjzT1kYGso5BNwFmXmowi30DK0X1FqwSMJo+q7EdVfy67vbvYFJpqkigX3KpMscZLFDyFb+m1hsLFsb2y9BmC7mpVblfRkO5gTzjzPWaVempJ2znSQ8dG29EACLVwb4X/hEJkhLyp2prVyqOg80Z5b9BNQ4ury0hiAmtrxJ7CU9ijlej0fzSSh9fnZKxF4juh7HCIFWE/WYBD515LE+p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oCIwwLkajCFpT/cY/OAVtOqjs5ERwKgQPrxvhxoAdh+3ZvMt1FV20AhOADpVSmq6jXd0RGnazuam3RkKAJp3lnj/rrMxurxyhWAwk10zlWxlr4HOzRBat8OeUaWe/Vv7UXt46s4QRy7Ja/HDTRdBCTjW+gkJDXzvIV7IDd3JY+9do+xibmFa6nt05UM87/MqYwPQMZznJIUI1jxBsxhlbjI8laitUef9LIMRPtuLrJhQHcKj6SkdEEKvRIbLh7OJQ5pXx48NES4tX2l6Bf/cwUPkEjgU7ziU04E4Q0qt10z9q+CE155CYKFC5Furw7solmsElGdHAgGNQL/xH3uwn8DTd1pNy2INK2tnNzxyM8E+oIA4sBqgNfMA+b/DtTQ5Ju7id36wlYcFz1R9S6f+wrQpymg0CGGkWdRqvzGhVZH4GRWzrYxB90D0nt+mQWI2AqhUuIobqGed+Vm1ajhn53JD2gnKIkMHkFMLBONpTSycfQdNrUucaEhTM+v1ruxYfhqdrh8uidMDu9Z0JconRu9lTrPdTg0pBQ74KN+nM1MT2xaEe7QTFzxhxtvebAuUMIKufANY/0U8N6kOpMsa9/R38UiJApCPLV71KYB2t6LL6WIpKB9V+lRyQYIvn79P8QW97MoVim19KAwH0i9t3rMqtT2psP2JkwoVk+gh5LSqXrSCW4ZmZGLMwktzFOpPs/j0wPjAhMAkGBSsOAwIaBQAEFOiXy8acoWuep8cXcI2sqoIj1V4PBBTPoCskWDue42xQjH/7h1/mUq15fwIDAYag

$\endgroup$
3
  • 1
    $\begingroup$ Implementation issues (writing or debugging code) that don't affect or involve the underlying crypto algorithms or attacks aren't considered ontopic here, but: the correct derived MAC key is A760BBE69A30C5286BEDB7FF4EEE04AA6BEC9B91 (and you do have the correct data). @Maarten: the keybag and certbag encryption are PBES2 with PBKDF2/HmacSHA256(32bytes)/10k, but the integrity check (MAC) derivation is indeed SHA1(20bytes)/100k. $\endgroup$ Commented Aug 18 at 1:22
  • $\begingroup$ Ah, wow, that was hiding in plain sight. Commonly they are over the same passphrase right? So that would completely negate the 100k if the 10k can be calculated instead (?). I'm losing track of what happens within P12, I think I had a better grip when I was myself working with it. $\endgroup$
    – Maarten Bodewes
    Commented Aug 18 at 1:45
  • $\begingroup$ @dave_thompson_085: my mistake for the wrong location, I should have posted in Stack Overflow. Thanks for the MAC key, I need to understand why my mbedTLS and personal implementations are incorrect. $\endgroup$
    – Klubo
    Commented Aug 18 at 9:30

1 Answer 1

0
$\begingroup$

Here is the explanation for the different values with the computed key.

The original password needs to be expanded as required by RFC 7292 in annex B.1. In this case, "123456" becomes 0, '1', 0, '2', 0, '3', 0, '4', 0, '5', 0, '6', 0, 0.

The key is then as provided by Dave Thompson (A760BBE69A30C5286BEDB7FF4EEE04AA6BEC9B91) and the HMAC as extracted from the certificate (E897CBC69CA16B9EA7C717708DACAA8223D55E0F).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.