openssl cms -verify doesn't work with external certificate
The issue I'm investigating is part of a larger context, and it turns out the problem I encountered in this specific test case is rather silly: I was using the wrong parameter to indicate the signing cert. One shouldn't use -signer
to indicate the signing certificate when verifying, but -certfile
:
$ openssl cms -verify -CAfile ca-crt.pem -inform der -certfile server-crt.pem -in sample.cms-der -nointern
Verification successful
And it works with SMIME as well:
$ openssl smime -verify -CAfile ca-crt.pem -inform der -certfile server-crt.pem -in sample.cms-der -nointern
Verification successful
I would typically delete the question altogether, but maybe somebody will find this useful in the future.
Unable to get SignerCertificate from CMSSigned data
You're missing to add the certificates to your signature data structure, this is probably why you're getting the signerInformation
but you're not getting the certificates using Collection certs = certStore.getCertificates( s.getSID() );
. To solve this add the certificates to your CMSSignedData
using addCertificates()
method:
gen.addSignerInfoGenerator(
new JcaSignerInfoGeneratorBuilder(
new JcaDigestCalculatorProviderBuilder().setProvider("BC").build())
.build(sha1Signer, certificate));
// use this to add the certificates to your signature
gen.addCertificates(certs);
signedData = gen.generate(cmsBytes, true);
Hope this helps,
Related Topics
How to Dynamically Hide Navigation Back Button in Swiftui
Using Nsdate to Get Date for Easter
Add a File Generated by Run Script into The Test Target Compilation List in Xcode
Xcode 6.1 Swift Extensions - Sourcekit Service Crash
Error Combining Nscalendarunit with or (Pipe) in Swift 2.0
Is There an Firebase Realtime Database Equivalent to The Increment Method Available in Firestore
Do Protocols Have an Effect on The Retain Count
Switch Statement Where Value Is Int But Case Can Contain Array
Swiftui Change on Multilevel Children Published Object Change
[Core Data]: Threw While Encoding a Value. with Userinfo of (Null)
Swift 3 Custom Extension of Ns Measurement? Ex. Sheeps to Goats
Pass Custom Parameter to UIbutton #Selector Swift 3
Swiftui Section from Attribute of a Struct
Support Arkit in Lower End Devices
Apple's Swift Compiler Complains of Partial Application When Creating Extension Method on Array