ChaCha20-Poly1305 decryption with empty message and fake tag is successful
Categories
(NSS :: Libraries, defect, P1)
Tracking
(Not tracked)
People
(Reporter: jallmann, Assigned: kjacobs)
References
Details
(Whiteboard: wycheproof)
Attachments
(1 file)
Comment 1•7 years ago
|
||
| Reporter | ||
Comment 2•7 years ago
|
||
Comment 3•7 years ago
|
||
Comment 4•7 years ago
|
||
Comment 5•7 years ago
|
||
Comment 6•6 years ago
|
||
Targeting NSS 3.43 for this.
| Assignee | ||
Comment 7•6 years ago
|
||
The current implementation follows behavior described in PKCS11 ("1. If pBUF is NULL_PTR...") [0].
The test allocates an output decrypted vector of size plainTextBytes, i.e. zero. The vector.data() call then returns a NULL pointer, which NSC_Decrypt interprets as a request for the output size, rather than an actual decryption. For comparison, the AES-GCM unit test allocates the decrypted output vector with size cipherTextBytes (which in this case would be 16 - just the tag). Production uses of PK11_Decrypt() seem to correctly account for this and prevent NULL from being passed in (whether intentional or not...)
The correct (per-spec) fix is to change the test [1] to allocate cipherTextBytes for decryption output.
FWIW, Windows APIs [2] behave the same way, and mention AEAD Decrypt handling:
- If output
pBufis NULL, it's a request for the plaintext size - Else if output
pBufand inputpCtxtare both NULL, AND mechanism is AEAD, it's a decrypt/authenticate on a zero-length ciphertext* - Else Error
*In PKCS11 case for AEAD decryption, the tag is appended to the ciphertext (in Windows API it's in a separate struct).. Thus the decryption input should never be NULL (though we don't enforce it at the PK11 layer).
I have a patch for this, with the NULL check mentioned, being tested.
[2] - https://docs.microsoft.com/en-us/windows/desktop/api/bcrypt/nf-bcrypt-bcryptdecrypt
| Assignee | ||
Updated•6 years ago
|
| Assignee | ||
Comment 8•6 years ago
|
||
Comment 9•6 years ago
|
||
mt, I'd like to get your eyes on this analysis, too. Kevin walked me through the code paths for TLS1.3 and SSL3 and I agree that we don't seem to have a path that would result in a null buffer as an input, so it does look like this is a test design error to me, too, but given the consequences, I'd appreciate a second opinion.
Comment 10•6 years ago
|
||
https://searchfox.org/nss/rev/e0bab5ba1837523ba9eb361b7502cb5076867283/lib/ssl/tls13con.c#5359 shows that we're safe in TLS 1.3, because we won't pass a zero-length input to PK11_Decrypt.
https://searchfox.org/nss/rev/e0bab5ba1837523ba9eb361b7502cb5076867283/lib/ssl/ssl3con.c#12312 shows the same check, albeit with a more complicated setup.
So TLS is fine.
The effect of failing to produce input should always be to fail. The effect of failing to produce an output buffer is exactly as Kevin has described.
I'll put some more comments on the bug.
Comment 11•6 years ago
|
||
Thanks, mt. OK, so we agree that this is not a security bug at all.
(Assuming no one disagrees with that statement, I'll unhide the bug tomorrow).
Comment 12•6 years ago
|
||
Yes, there are no security implications. Unhide at will.
Updated•6 years ago
|
Comment 13•6 years ago
|
||
Description
•