-
-
Notifications
You must be signed in to change notification settings - Fork 775
Add CMS_verify() method. #1393
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
Add CMS_verify() method. #1393
Conversation
openssl/src/cms.rs
Outdated
/// [`CMS_verify`]: https://www.openssl.org/docs/manmaster/man3/CMS_verify.html | ||
pub fn verify( | ||
&mut self, | ||
certs: Option<&Stack<X509>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should take a &StackRef
, not &Stack
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to &StackRef.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did a commit not get pushed? I still see &Stack<X509>
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry. Editing error.
A test fails on one of the architectures. I am working on it. #0 X509_STORE_get_by_subject (vs=vs@entry=0x7fa5071f6ed0, type=type@entry=1, name=name@entry=0x7fa4a0002220, ret=ret@entry=0x7fa5071f6de0) at x509_lu.c:293 |
openssl/src/cms.rs
Outdated
/// OpenSSL documentation at [`CMS_verify`] | ||
/// | ||
/// [`CMS_verify`]: https://www.openssl.org/docs/manmaster/man3/CMS_verify.html | ||
#[allow(clippy::redundant_clone)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is being redundantly cloned?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*out_data = out_bio.get_buf().to_vec().clone();
I believe that the clone is not redundant, because the source object is not released by rust code but by OpenSSL (see the next comment].
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vec owns its memory. There is no difference between the one created by to_vec and the one created by clone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I got confused by slice::into_vec(] documentation.
openssl/src/cms.rs
Outdated
) -> Result<(), ErrorStack> { | ||
unsafe { | ||
let certs_ptr = certs.map_or(ptr::null_mut(), |p| p.as_ptr()); | ||
if store.is_none() && !flags.contains(CMSOptions::NO_SIGNER_CERT_VERIFY) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does OpenSSL crash if this condition isn't met?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it does, but not always. Only one of the tests on CI failed (see #1393 (comment) ) probably because input checks are not sufficient in older versions of OpenSSL.
openssl/src/cms.rs
Outdated
))?; | ||
|
||
if let Some(out_data) = output_data { | ||
*out_data = out_bio.get_buf().to_vec().clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This clone appears to be unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think than out_bio.get_buf() returns an address in the memory managed by OpenSSL which is released when out_bio is dropped. to_vec() creates a new vector from the existing memory (no copy or clone). Therefore the vector needs to be cloned.
/// [`CMS_verify`]: https://www.openssl.org/docs/manmaster/man3/CMS_verify.html | ||
pub fn verify( | ||
&mut self, | ||
certs: Option<&StackRef<X509>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The man page for CMS_verify doesn't talk about certs and store being allowed to be null at all - maybe they should just be required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The man page (https://www.openssl.org/docs/manmaster/man3/CMS_verify.html) mentions a null certs parameter in this sentence:
...An attempt is made to locate all the signing certificate(s), first looking in the certs parameter (if it is not NULL) ...
and there is the option CMS_NO_SIGNER_CERT_VERIFY which disables certificate verification altogether.
Therefore, I think the optional parameters make sense. Nevertheless, the distinction is just a formal one, because the caller can always create an empty vector or an empty store. If you insist, I can change them to required, just let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah good find. Keeping certs
nullable seems fine, but I'd lean towards requiring store
since its nullability isn't mentioned in the docs and at least in 1.0.1 they assume it's present (I'd also hope people aren't using NO_SIGNER_CERT_VERIFY too often!).
Hi, |
Sorry - github doesn't notify for force pushes :( It looks like some random commits got somehow pulled into the PR. You may need to do some branch surgery. |
Hi, |
@sladecek What happened to this PR? Actually I just saw the diff in this PR + status "closed" so I assumed the PR was merged already and was then wondering why I was unable to call the method... 🤔 |
I deleted the PR because the maintainer didn't answer for a long time and the branch was outdated. |
Not sure how much I time I have over the next weeks but would having CMS_verify would be really helpful. Would you mind resubmitting the code? I could also take your comit and try to get the code included into rust-openssl if you don't have time to do that. |
Hi,
the patch is almost a year old, so I need to update it first.
Unfortunately, I am leaving for a 14-day vacation. I will look at it in
October.
Ladislav
…On Sat, Sep 18, 2021 at 3:40 PM Felix Schwarz ***@***.***> wrote:
Not sure how much I time I have over the next weeks but would having
CMS_verify would be really helpful. Would you mind resubmitting the code? I
could also take your comit and try to get the code included into
rust-openssl if you don't have time to do that.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1393 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABDGV7J2Y5GOHNXZZAJ4E3TUCSJFNANCNFSM4VAHPL6Q>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
--
Ladislav Sládeček
|
Hi @sladecek It would be really useful to have this functionality and the APIs included in https://github.com/sfackler/rust-openssl/pull/1034/files for implementing singing of Linux Kernel Modules in rust. Do you know if this is still being worked on? |
Here is my PR Ladislav |
Hi,
I need CMS verification for my project.
I found the method in PR #1034 from Jan 2019 by ur0. The PR contained several other methods and waited for tests to be finished. I submit only the CMS_verify() method. A test for both signing and verification was added.
Regards
Ladislav