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

Set-CertificateExtension problem with naming constraint and certificate policies extensions #1

Closed
jalliot opened this Issue Jun 13, 2016 · 3 comments

Comments

Projects
None yet
2 participants
@jalliot
Copy link

jalliot commented Jun 13, 2016

Hello Vadims,

There seems to be a bug in the Set-CertificateExtension function with some extensions types only.
The function works perfectly in most cases for me but with the naming constraint and certificate policies extensions, I have to rely on a mix of your PSPKI library and certutil -setextension instead.

Here is a sample script where I took random data to reproduce the problem (you must have at least one pending request of course):

$policy1Qualifier = New-Object System.Security.Cryptography.X509Certificates.X509PolicyQualifier 'http://example.com'
$policy1QualifierCollection = New-Object System.Security.Cryptography.X509Certificates.X509PolicyQualifierCollection
[void] $policy1QualifierCollection.Add($policy1Qualifier)
$policy1 = New-Object System.Security.Cryptography.X509Certificates.X509CertificatePolicy '1.3.6.1.4.1.6334.1.0',$policy1QualifierCollection

$policy2Qualifier = New-Object System.Security.Cryptography.X509Certificates.X509PolicyQualifier 'http://example.com'
$policy2QualifierCollection = New-Object System.Security.Cryptography.X509Certificates.X509PolicyQualifierCollection
[void] $policy2QualifierCollection.Add($policy2Qualifier)
$policy2 = New-Object System.Security.Cryptography.X509Certificates.X509CertificatePolicy '1.3.6.1.4.1.6334.1.1',$policy2QualifierCollection

$policiesCollection = New-Object System.Security.Cryptography.X509Certificates.X509CertificatePolicyCollection
[void] $policiesCollection.Add($policy1)
[void] $policiesCollection.Add($policy2)
$policiesExtension = New-Object System.Security.Cryptography.X509Certificates.X509CertificatePoliciesExtension $policiesCollection,$false


$permittedSubtree = New-Object System.Security.Cryptography.X509Certificates.X509AlternativeNameCollection
$dnsType = [System.Security.Cryptography.X509Certificates.X509AlternativeNamesEnum]::DnsName
$corpDomains = New-Object System.Security.Cryptography.X509Certificates.X509AlternativeName $dnsType,'.local'
$excludedSubtree = New-Object System.Security.Cryptography.X509Certificates.X509AlternativeNameCollection
[void] $excludedSubtree.Add($corpDomains)
$nameConstraintExt = New-Object System.Security.Cryptography.X509Certificates.X509NameConstraintsExtension $permittedSubtree,$excludedSubtree
$nameConstraintExt.Critical = $false

$extCollection = New-Object System.Security.Cryptography.X509Certificates.X509ExtensionCollection
[void] $extCollection.Add($policiesExtension)
[void] $extCollection.Add($nameConstraintExt)

Connect-CertificationAuthority | Get-PendingRequest | Set-CertificateExtension -Extension $extCollection -Verbose

For the certificate policies extension, I have an error.
For the naming constraint extension, the extension is added to the request but the actual DnsName in the excluded subtree is an empty string.

If I export both extensions to a binary file and then use certutil -setextension with that file, then it works.
I have a working workaround so this is not a high-priority bug but I hate having to fallback to certutil :)

@Crypt32

This comment has been minimized.

Copy link
Owner

Crypt32 commented Jun 13, 2016

If you are using PKI.Core.dll from official PSPKI module release, then this issue is now fixed. It is known issue. I found that the problem appears when byte length is odd. This is already fixed in sources: Crypt32/pkix.net@0b4b612
If necessary, you can compile DLL from sources and check if the issue is resolved for you.

This month I'm taking exam session at university and really don't have much time to release all fixes I made.

@jalliot

This comment has been minimized.

Copy link

jalliot commented Jun 14, 2016

I won't be able to test anytime soon but it is not really urgent since using certutil -setextension does work in the meantime.
I'll wait for the proper release.
Thank you ;)

@Crypt32

This comment has been minimized.

Copy link
Owner

Crypt32 commented Aug 8, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment