-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
X509Certificate2/CommonCrypto: Unable to open PKCS#12 files with no password and valid MAC #23635
Comments
/cc @bartonjs |
@bartonjs Is this a known compatibility issue? |
As a FYI for others who may hit the same issue, here's code that may act as a workaround based on BouncyCastle. Pkcs12Store store = new Pkcs12Store();;
using (Stream stream = File.OpenRead(filename))
{
store.Load(stream, new char[] {});
}
var keyAlias = store.Aliases.Cast<string>().SingleOrDefault(a => store.IsKeyEntry(a));
var key = (RsaPrivateCrtKeyParameters)store.GetKey(keyAlias).Key;
var bouncyCertificate = store.GetCertificate(keyAlias).Certificate;
var certificate = new X509Certificate2(DotNetUtilities.ToX509Certificate(bouncyCertificate));
var parameters = DotNetUtilities.ToRSAParameters(key);
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
rsa.ImportParameters(parameters);
certificate = RSACertificateExtensions.CopyWithPrivateKey(certificate, rsa);
return certificate; |
Is any triage planned on this issue? At least bug/non bug decision |
cc @bartonjs .. |
Based on testing I did in the past, Apple cannot read a PFX that contains non-encrypted keys. So while this is a bug, it's probably not something that we would work around in .NET without a very compelling argument (like it being a key distribution model by a government CA, or something like that); but rather something which ideally would be resolved by Apple (https://bugreport.apple.com/, for SecItemImport). What's the scenario here? Where are these PFX files coming from? |
* Remove file polling only, and leave the COMPlus_* functionality. * Fix bug/typo introduced with dotnet/coreclr#21718 Signed-off-by: dotnet-bot <[email protected]>
* Remove file polling only, and leave the COMPlus_* functionality. * Fix bug/typo introduced with dotnet/coreclr#21718 Signed-off-by: dotnet-bot <[email protected]>
* Adding ClientCertificateCredential to Azure.Idenity * fixing test assertion * adding cert with password to work around https://github.com/dotnet/corefx/issues/24225
Work around dotnet/runtime#23635
If you have a PKCS#12 file which is not protected with a password, and which does have a MAC entry, opening the file will work on Windows and Linux but fails on Mac (which use CommonCrypto).
This is a regression on macOS as this worked with .NET Core 1.x (when using OpenSSL) and no longer works with .NET Core 2.0.
The following unit test reproduces the behavior:
The test passes on Windows & Linux but fails on macOS with the following error message:
my_pkcs12.pfx
can be generated using the following script, use an empty password when prompted:This is not the same as #18254, that one was about p12 stores where the MAC is absent; in this case there is a valid MAC.
The text was updated successfully, but these errors were encountered: