Skip to content

X509CertificateLoader can't load public key from pfx file without password #115137

Closed
@jhudsoncedaron

Description

@jhudsoncedaron

Description

This should work but doesn't.

Console.WriteLine(System.Security.Cryptography.X509Certificates.X509CertificateLoader.LoadPkcs12(System.IO.File.ReadAllBytes("test.pfx"),
			null, 0, new System.Security.Cryptography.X509Certificates.Pkcs12LoaderLimits { IgnorePrivateKeys = true, IgnoreEncryptedAuthSafes = true } ));

I haven't been able to actually remove the private key from the pfx file so I won't be uploading it; however this pfx file is unusual; on examining it on strings it's obvious the public key side is not encrypted.

You can generate one of these yourself: export a key from Windows certificate manager; uncheck enable certificate privacy.

$ strings test.pfx 
0J0)
o<H>
Gm&-
|*lT
Me('
tZLm1
]J}jc
DTah
!<>@
Dh>{
\~tj
:}\II
	localhost0
231121155232Z
281121000000Z0
	localhost0
d*'d2
|i| 
:080
	localhost0
}i~h
M`12
KDSK
090705
.S-1-5-21-2569210111-3594215139-1303219835-11740
T#Ou_
^Z)Va
HG}V
0K0/0
 NTn~
~}U|a>\

(Yes the certificate really is for localhost)

Reproduction Steps

  1. Export a pfx file without certificate privacy
  2. copy it to another machine
  3. try to read the public key using the code fragment above; from a discussion on the breaking change; this call is supposed to work

Expected behavior

Get X509Certificate2 class back without a private key

Actual behavior

throws

Regression?

Kind of

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions