Skip to content
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

LoadPkcs12 returns wrong error message if certificate has wrong key usage #367

Closed
Eneuman opened this issue Jan 14, 2018 · 1 comment
Closed
Labels
enhancement New feature or request

Comments

@Eneuman
Copy link

Eneuman commented Jan 14, 2018

I got stuck on this problem until I checked the source code.
Maby add another error message to this?

On this line

if (PrivateKey == null)

The code checkes if it has found a private key, if not it returns "The stream does not contain a private key".

But on this line, it skips all certificates that doesnt have the correct key usage.

if (flags != X509KeyUsageFlags.None && (flags & SecureMimeContext.DigitalSignatureKeyUsageFlags) == 0)

So if you use a self signed certificate, that contains a private key, but has the wrong usage, you get the wrong error message :(

To reproduce, create a key like this and try and sign with it:

New-SelfSignedCertificate -Type Custom -Subject "CN=TestCertificate" -KeyUsage DataEncipherment -KeyAlgorithm RSA -KeyLength 2048 -SmimeCapabilities -CertStoreLocation "Cert:\CurrentUser\My"

@jstedfast
Copy link
Owner

I’ll look into it.

jstedfast added a commit that referenced this issue Jan 15, 2018
@jstedfast jstedfast added the enhancement New feature or request label Jan 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants