Some ASN.1 Templates for key agreement in NSS are incorrect
Categories
(NSS :: Libraries, defect, P4)
Tracking
(Not tracked)
People
(Reporter: dcooper16, Assigned: rrelyea)
References
Details
(Whiteboard: [SMIME-ECC])
Attachments
(5 files, 5 obsolete files)
Updated•14 years ago
|
Comment 1•14 years ago
|
||
Updated•14 years ago
|
Comment 2•14 years ago
|
||
Comment 3•14 years ago
|
||
Reporter | ||
Comment 4•14 years ago
|
||
Reporter | ||
Comment 5•14 years ago
|
||
Reporter | ||
Comment 6•14 years ago
|
||
Reporter | ||
Comment 7•14 years ago
|
||
Updated•14 years ago
|
Reporter | ||
Comment 10•14 years ago
|
||
Comment 11•14 years ago
|
||
Reporter | ||
Comment 12•13 years ago
|
||
Updated•12 years ago
|
Updated•12 years ago
|
Reporter | ||
Comment 13•6 years ago
|
||
This is a patch to correct some errors in the Templates for CMS -- particularly the parts used for key agreement. It was originally submitted several years ago, but review of it stopped for some reason. I have not made any changes to the patch, I just updated it so that it can be applied to the current NSS code.
Comment 15•6 years ago
|
||
This isn't easy to review and be certain about the results. How could we be certain that it doesn't introduce any regressions? We have a set of CMS test messages and Thunderbird tests them. If the tests still pass, can we be certain it doesn't introduce regressions?
I think we need automated tests cases for the class of CMS messages that you are fixing. The tests should fail with the existing code, and work with your new code. How could we get those? Could you describe the messages we need to produce? Someone will have to extend the tests in nss/tests/smime/
Reporter | ||
Comment 16•6 years ago
|
||
(In reply to Kai Engert (:kaie:) from comment #15)
This isn't easy to review and be certain about the results. How could we be certain that it doesn't introduce any regressions? We have a set of CMS test messages and Thunderbird tests them. If the tests still pass, can we be certain it doesn't introduce regressions?
Certainly it should be carefully reviewed before it is accepted. However, I do not believe it is an overly large concern for two reasons:
-
The changes in the templates are only related to the parts of the ASN.1 used with key agreement, which isn't yet fully supported. So, my guess is that the parts of the templates the patch changes haven't been used.
-
For most of the changes, it is very easy to see by looking at the ASN.1 in RFC 5652 that the current templates are wrong.
I think we need automated tests cases for the class of CMS messages that you are fixing. The tests should fail with the existing code, and work with your new code. How could we get those? Could you describe the messages we need to produce? Someone will have to extend the tests in nss/tests/smime/
This patch is a start. It adds one new set of tests in which a message is encrypted for a recipient with an elliptic curve key, the resulting file is decrypted, and then the result is compared against the original plaintext.
This patch also modifies the test involving sending an encrypted message to multiple recipients so that one of the recipients has an elliptic curve key.
I see that the nss/tests directory includes a few uses of OpenSSL. Perhaps some more tests could be added that involve (1) encrypting a message using OpenSSL and then decrypting the result using cmsutil and (2) encrypting a message using cmsutil and then decrypting the result using OpenSSL.
(Note that the ECDH tests in this patch will only work if the patch to fix bug #676118 is also applied.)
Reporter | ||
Comment 17•5 years ago
|
||
Comment 18•5 years ago
|
||
Just to set expectations here - I have basically no background in these ASN.1 updates, and thus these reviews are not straightforward to me. Friday I'm tagging NSS_3_47_BETA1 with a release the following week, so I expect to start looking at these in earnest for NSS 3.48.
Reporter | ||
Comment 19•5 years ago
|
||
(In reply to J.C. Jones [:jcj] (he/him) from comment #18)
Just to set expectations here - I have basically no background in these ASN.1 updates, and thus these reviews are not straightforward to me. Friday I'm tagging NSS_3_47_BETA1 with a release the following week, so I expect to start looking at these in earnest for NSS 3.48.
That's okay. I understand that everyone wants to be certain that this patch doesn't accidentally break any existing code in the process of fixing the templates for key agreement algorithms. From my point of view, I think it would be great if this bug and bug #676118 could be addressed in time for the fixes to appear in Thunderbird 76, which I am guessing will be released around August 2020. I don't know when the fixes would to need to make it into NSS for that to happen.
If there is anything I can do to help with the review of these patches, please let me know.
Comment 20•3 years ago
|
||
The bug assignee is inactive on Bugzilla, so the assignee is being reset.
Updated•2 years ago
|
Updated•1 year ago
|
Comment 21•1 year ago
|
||
Comment 22•1 year ago
|
||
Comment on attachment 9090787 [details] [diff] [review]
Patch to correct Templates for key agreement in smime/cmsasn.c
Replaced by https://phabricator.services.mozilla.com/D204654
Comment 23•1 year ago
|
||
Comment on attachment 9091128 [details] [diff] [review]
ECDH S/MIME tests
Merged into https://phabricator.services.mozilla.com/D164332
so we have only one patch for all tests.
Comment 24•1 year ago
|
||
r=kaie on David's template patch plus code formatting fixes. I'll land it.
Comment 25•1 year ago
|
||
Updated•1 year ago
|
Assignee | ||
Comment 26•6 months ago
|
||
NSSCMSKeyAgreeRecipientInfo is a public structure included in the union of NSSCMSRecipientInfo. The change was to an unused structure, so in general, it was fine, but it was to the largest existing struct in the union, which changes the sized of NSSCMSRecipientInfo, and moves around the later points in a non-opaque public structure which is used in public APIs. This breaks NSS ABI.
The solution is to create a fixed structure that is identical to the old NSSCMSKeyAgreeRecipientInfo and include it as a dummy max value in the Union. Note the comment above NSSCMSRecipientInfo.
Assignee | ||
Comment 27•6 months ago
|
||
OK, that solution won't work because the new structure is bigger.
We need a solution soon. This is holding up us shipping NSS in RHEL (sigh). Kai is this referenced at all in Thunderbird?
Assignee | ||
Comment 28•6 months ago
|
||
OK, it turns out reverting the cmst.h change that caused the breakage is actually pretty straightforward. since the item is allocated out of the arena pool, we can just tell the Decoder that it refers to pointer. In the encrypt case, we change the allocate of data to allocating a full SECITEM.
Assignee | ||
Updated•6 months ago
|
Assignee | ||
Comment 29•6 months ago
|
||
since I needed a patch for RHEL anyway, I'll take this bug and attach the patch once it passes our tests.
Comment 30•6 months ago
|
||
I'm investigating.
The change in size was reported in the NSS automatic checking of ABI changes, and was accepted in
https://hg.mozilla.org/projects/nss/rev/97e4f6f65af5f632f79ece17c32f3ee962191e85
The report had mentioned a change of size in the sub-type, but that was missed.
Yes Thunderbird uses this type for S/MIME, and the Thunderbird version 128 that uses the modified NSS type has already been publicly released.
This is unfortunate.
Can we investigate whether any known applications would indeed be affected by this change?
It would only affect applications that are using NSS libsmime, and which read or modify the respective members of the structure.
In Thunderbird, I can find only one place where type NSSCMSRecipientInfo is used.
A pointer to that type is obtained as the result of calling NSS_CMSRecipientInfo_Create,
and the result is not inspected, not modified,
but only passed on to NSS_CMSEnvelopedData_AddRecipient.
In other words, for Thunderbird, we'd be certain that only new code that knows about the new size and layout, is used to process the data.
I think this also means, if Red Hat requires that the change gets reverted, and a different implementation is used, then it wouldn't be a problem for Thunderbird.
Comment 31•6 months ago
|
||
Likewise, the outer type NSSCMSEnvelopedData is also used in an opaque way, only.
An instance is obtained by calling NSS_CMSEnvelopedData_Create,
and the result pointer is passed on to calls to NSS_CMSContentInfo_SetContent_EnvelopedData, NSS_CMSEnvelopedData_GetContentInfo, NSS_CMSEnvelopedData_AddRecipient, but never inspected or modified by the application code.
Comment 32•6 months ago
|
||
Fedora has already shipped the ABI change, because it's at version 3.103
Have you heard of anyone complaining about bugs related to the NSS S/MIME library during the past months, when NSS was upgraded to version 3.101 ?
If your suggested solution is to revert the ABI change and use a different implementation, this would also be done on Fedora, I assume.
Comment 33•6 months ago
|
||
Bob, did you already decide what to do?
Assignee | ||
Comment 34•6 months ago
|
||
Yes, I think we should revert the ABI. We don't have ABI guarrentees in S/MIME, but we do in RHEL. I now have a patch that reverts the ABI change while preservering the core change from this bug. (basically a small change to the template a couple of changes to the callers that use the structure). I'll attach it here soon. We were in a middle of a RHEL release, so I needed to get that our and fixed first.
Assignee | ||
Comment 35•6 months ago
|
||
We currently have the structures in a public header, and it's returned by some public functions. I've verified that Thunderbird and Firefox don't reference the structures, but we should look a moving those private so we can be more free with changes to them. If we do that with ifdefs we can drop them from new RHEL and evenutally drop the public versions completely.
The main issue with the change was the structure increased in size, and the structure that was changed was the controlling size in a union to a structure that is returned by public functions. There were fields after the union, and the structure itself is often used in arrays, so the change had some potential issues if anyone actually used it.
Assignee | ||
Comment 36•6 months ago
|
||
Heres the patch for preview I'll create a phabricator version once I get some breathing room.
Description
•