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
Export certificate fails under some circumstances #38864
As part of working on an improvement to dotnet-dev-certs, the export functionality will fail in some cases and will leave an array full of 0s instead of the value of the exported certificate.
I've tried to create a minimal repro project but I have not been able to do so. If you want to reproduce it, you can clone the branch and debug with the following command.
This is not blocking us since it is not a command we expect users to run manually and tooling would not run this combination of flags, but it would be good if we get to the bottom of why this is not working properly.
In your case, you're calling export twice, once with the password to get the private key, and one again to get just the public part. After the first call, it cleans up at the end by disposing and zeroing things, including the internal rawdata of the certificate PAL.
Fix for now would be to not Array.Clear the result of Export only when the content type is Cert since it only contains the public part of the certificate.
This seems undesirable, so I will submit a PR to fix this here as well.
Following the breadcrumbs, I assume this is only happening on macOS? Looks like all of the other PALs return new arrays from ICertificatePalCore.RawData, but that one returns a field.
Presumably that means both Export(Cert) and RawData need tests that call it twice and Assert.NotSame on the two results.
Activity
Dotnet-GitSync-Bot commentedon Jul 7, 2020
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
vcsjones commentedon Jul 7, 2020
I'll take a look. /cc @bartonjs for labels.
vcsjones commentedon Jul 7, 2020
The problem is that
Export(X509ContentType.Cert)hands out the underlyingbyte[]of the PAL, instead of a copy likeRawData. Minimal repro on macOS:@javiercn
In your case, you're calling export twice, once with the password to get the private key, and one again to get just the public part. After the first call, it cleans up at the end by disposing and zeroing things, including the internal rawdata of the certificate PAL.
Fix for now would be to not
Array.Clearthe result ofExportonly when the content type isCertsince it only contains the public part of the certificate.This seems undesirable, so I will submit a PR to fix this here as well.
javiercn commentedon Jul 7, 2020
@vcsjones thanks for the quick turnaround!
If this is fixed before 5.0 I'm fine just waiting for the actual fix in corefx.
vcsjones commentedon Jul 7, 2020
Interestingly, this reproduces in Core 3.1, so it isn't a regression.
bartonjs commentedon Jul 7, 2020
Following the breadcrumbs, I assume this is only happening on macOS? Looks like all of the other PALs return new arrays from ICertificatePalCore.RawData, but that one returns a field.
Presumably that means both Export(Cert) and RawData need tests that call it twice and Assert.NotSame on the two results.
javiercn commentedon Jul 7, 2020
Yep, at least windows is fine
vcsjones commentedon Jul 7, 2020
Yes, does not reproduce on Linux or Windows.
vcsjones commentedon Jul 7, 2020
@bartonjs Poking around more at this, there are other properties that exhibit similar behavior. For example, properties of type
X500DistinguishedName:This actually reproduces on Linux as well.
Should these be addressed similarly?
bartonjs commentedon Jul 7, 2020
Yes, please 😦