You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
new X509Certificate2(byte[]) should return the signing cert for PKCS#7 on Unix #15073
The Windows code supports reading a PKCS#7 signed or PKCS#7 signed-and-enveloped structure; but in single certificate mode it doesn't return certs[0], it returns the certificate which signed the structure.
My test files (produced by Windows (certmgr.msc and X509Certificate2Collection::Export)) aren't signed, so Windows emits an exception (new CryptographicException(ErrorCode.CRYPT_E_SIGNER_NOT_FOUND)).
Without a sample to see what's going on here, it's hard to make compatible behavior. So, for now, the Unix implementation will just throw, even if it could have worked.
Reacted by Stefan Hausotte, stukselbax, Filip Navara, Daryl Zuniga, Kalyxt, Mattias Beimers and evm2556
Moving to Future, it's just getting a bit late to plumb this down (and a lot of tests need to be defined to ensure that we're behaving the same way as in our Windows black-box implementation... zero signers, multiple signers, igner-cert-not-included, hybridized values, etc)
The workaround for caller code which knows it's getting a PKCS7 is to just load it into the SignedCms class. This is the naive approach (only works for one signer, when the signer cert is present)
SignedCmscms=newSignedCms();cms.Decode(bytes);SignerInfoCollectionsigners=cms.SignerInfos;if(signers.Count!=1){thrownewCryptographicException("Wrong number of signers.");}returnsigners[0].Certificate??thrownewCryptograpicException("Signer cert was not present");
I was playing with decoding Authenticode, which is also supposed to be supported. Turns out most of the plumbing code is already present in CoreFX (no error handling, just PoC):
var peReader = new PEReader(new MemoryStream(smallspcexe));
// TODO: Check for non-PE files
var certDirectory = peReader.PEHeaders.PEHeader.CertificateTableDirectory;
// TODO: Check for no certificate table
var certData = peReader.GetEntireImage().GetContent(certDirectory.RelativeVirtualAddress, certDirectory.Size);
// TODO: Handle different certificate types (X.509, PKCS#7) and read the length (ie. multiple certificates)
var certData2 = new byte[certData.Length - 8];
certData.CopyTo(8, certData2, 0, certData2.Length);
var certType = X509Certificate2.GetCertContentType(certData2);
var x509 = new X509Certificate2(certData2);
and it boils down to reading PKCS#7 certificates. The last constructor fails with an exception.
Hello, my project based on linux relying on reading cert from PKCS#7 signed file, which is not working atm. Is this going to be fixed in upcoming .NET Core versions (3.0) or what is the situation around this? I would greatly appreciate any info about this issue and its future.
Any updates on the issue regarding the version it will most likely be fixed in? It's not fixed in 3.1 and was already an issue in 2.0.
If someone points me to a starting point, I could try to implement it myself and do PR. Never worked with the dotnet repo, so any hints are welcome.
I've been hitting this issue (I think), reading up on it, and am wondering if someone can confirm that I'm understanding the implications correctly.
Does this imply that there is currently no cross-platform way in .NET to sign files or verify file signatures? In this case, files signed in Windows can't be verified on Unix/Linux?
Does this imply that there is currently no cross-platform way in .NET to sign files or verify file signatures? In this case, files signed in Windows can't be verified on Unix/Linux?
If you mean a file signed with Windows Authenticode, then correct - .NET does not provide an API to verify Authenticode signatures.
But new X509Certificate2(byte[]) on Windows does not do that either. It returns the signing cert, or the first cert-looking thing it can find in the file, but it does not actually check the signature.
Thanks. Part of what I was struggling to determine was if all code signing in Windows was Authenticode or not as a lot of info just refers to 'digital signature'. In any case, I think it's safe to say that Window's signtool.exe is Authenticode.
Quite right, getting the cert from the file isn't validating the cert, that was a subsequent step I was taking. I just wanted to be sure that my actual goal of validating the file wasn't possible some other way that didn't necessitate actually having the cert object itself.
what is the status of this? as we think we experience invalid exports of PKCS#7 in .net 7 and seeing this makes me believe things are not fully implemented yet?
If we do cert.export(pkcs7 this does not work, doesn't seem to be supported?
If we put it in a collection and export it the file is about 30% smaller and when importing it it isn't valid (can't debug it is being loaded into an external device).
@bartonjs I think we can close this as "won't fix". I don't think we are going to add any new functionality to the X509Certificate constructors, and the "right" way to get certs out of a PKCS#7/CMS is to use SignedCms.
Activity
danmoseley commentedon Feb 28, 2017
Marking Future explicitly because we have decided thisi s not necessary for 2.0.
bartonjs commentedon Mar 20, 2018
Moving to Future, it's just getting a bit late to plumb this down (and a lot of tests need to be defined to ensure that we're behaving the same way as in our Windows black-box implementation... zero signers, multiple signers, igner-cert-not-included, hybridized values, etc)
The workaround for caller code which knows it's getting a PKCS7 is to just load it into the SignedCms class. This is the naive approach (only works for one signer, when the signer cert is present)
filipnavara commentedon Jun 22, 2018
I was playing with decoding Authenticode, which is also supposed to be supported. Turns out most of the plumbing code is already present in CoreFX (no error handling, just PoC):
and it boils down to reading PKCS#7 certificates. The last constructor fails with an exception.
kygagner commentedon Jul 2, 2018
We need to be able to verify Authenticode signatures on managed DLLs in Linux for licensing enforcement.
Kalyxt commentedon Jun 11, 2019
Hello, my project based on linux relying on reading cert from PKCS#7 signed file, which is not working atm. Is this going to be fixed in upcoming .NET Core versions (3.0) or what is the situation around this? I would greatly appreciate any info about this issue and its future.
secana commentedon Jun 11, 2019
@Kalyxt Maybe https://github.com/secana/PeNet can do what you want (I'm the author). The PeNet library is able to extract the cert from signed files on Windows, Linux and Mac.
Kalyxt commentedon Jun 11, 2019
Thanks! This is exactly what I was looking for. I've tested it on win and linux-arm.
bartonjs commentedon Jun 11, 2019
No, there's not a lot of time left in the 3.0 release and I'm already over committed. (Though PRs are welcome if someone wants to contribute a fix...)
secana commentedon Dec 20, 2019
Any updates on the issue regarding the version it will most likely be fixed in? It's not fixed in 3.1 and was already an issue in 2.0.
If someone points me to a starting point, I could try to implement it myself and do PR. Never worked with the dotnet repo, so any hints are welcome.
bartonjs commentedon Dec 20, 2019
I'll go ahead and mark it as 5 (aka "next version"). If you want to give it a try,
runtime/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Unix/PkcsFormatReader.cs
Lines 226 to 236 in 4f9ae42
[OuterLoop]or just a manual test.If you just want the functionality but aren't too keen on playing with pointers, that's fine... it'll still get taken care of this release.
14 remaining items
NGame1 commentedon Jul 13, 2022
@jeffhandley
OMG! After about 7 years of opening this issue. Again is it postponed?
No way!
et1975 commentedon Jan 26, 2023
@jeffhandley This issue was in the 7.0.0 bucket that's now marked as completed. Is the fix in .NET 7?
vcsjones commentedon Jan 26, 2023
No. This is currently marked "Future" and still open. This did not get complete for 7.0.
bryandam commentedon Aug 11, 2023
I've been hitting this issue (I think), reading up on it, and am wondering if someone can confirm that I'm understanding the implications correctly.
Does this imply that there is currently no cross-platform way in .NET to sign files or verify file signatures? In this case, files signed in Windows can't be verified on Unix/Linux?
vcsjones commentedon Aug 11, 2023
If you mean a file signed with Windows Authenticode, then correct - .NET does not provide an API to verify Authenticode signatures.
But
new X509Certificate2(byte[])on Windows does not do that either. It returns the signing cert, or the first cert-looking thing it can find in the file, but it does not actually check the signature.bryandam commentedon Aug 11, 2023
Thanks. Part of what I was struggling to determine was if all code signing in Windows was Authenticode or not as a lot of info just refers to 'digital signature'. In any case, I think it's safe to say that Window's signtool.exe is Authenticode.
Quite right, getting the cert from the file isn't validating the cert, that was a subsequent step I was taking. I just wanted to be sure that my actual goal of validating the file wasn't possible some other way that didn't necessitate actually having the cert object itself.
wstaelens commentedon Nov 27, 2023
what is the status of this? as we think we experience invalid exports of PKCS#7 in .net 7 and seeing this makes me believe things are not fully implemented yet?
vcsjones commentedon Nov 27, 2023
This issue is specifically about importing a PKCS#7 blob from
X509Certificate{2}and it has not been implemented.@wstaelens do you have a code snippet of what is not working for you?
wstaelens commentedon Nov 28, 2023
@vcsjones We tried several things. Maybe missing something, not sure how to get it working.
If we do
cert.export(pkcs7this does not work, doesn't seem to be supported?If we put it in a collection and export it the file is about 30% smaller and when importing it it isn't valid (can't debug it is being loaded into an external device).
vcsjones commentedon Sep 17, 2024
@bartonjs I think we can close this as "won't fix". I don't think we are going to add any new functionality to the X509Certificate constructors, and the "right" way to get certs out of a PKCS#7/CMS is to use
SignedCms.bartonjs commentedon Sep 17, 2024
Yeah, we probably shouldn't be adding features to
[Obsolete]members (unless we get a compelling compat/square-the-circle scenario).