Functions/Get-NDESCertificate.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
<#
    .SYNOPSIS
    Requests a Certificate from an NDES Server via the SCEP Protocol.
    This works on Windows 8.1 and newer Operating Systems.
 
    .PARAMETER ComputerName
    Specifies the Host Name or IP Address of the NDES Server.
    If using SSL, this must match the NDES Server's identity as specified in its SSL Server Certificate.
 
    .PARAMETER MachineContext
    By default, the Key for Certificate Request gets created in the current User's Context.
    By specifying this Parameter, it will be created as a Machine Key.
    You must execute the Command with Elevation (Run as Administrator) then.
 
    .PARAMETER Subject
    Specifies the Subject DN for the Certificate.
    May be left empty if you specify a DnsName, Upn or IP instead.
 
    .PARAMETER Dns
    Specifies one or more DNS Names to be written into the Subject Alternative Name (SAN) Extension of the Certificate Request.
    May be left Empty if you specify a Subject, Upn or IP instead.
 
    .PARAMETER Upn
    Specifies one or more User Principal Names to be written into the Subject Alternative Name (SAN) Extension of the Certificate Request.
    May be left Empty if you specify a Subject, DnsName or IP instead.
 
    .PARAMETER Email
    Specifies one or more E-Mail addresses (RFC 822) to be written into the Subject Alternative Name (SAN) Extension of the Certificate Request.
    May be left Empty if you specify a Subject, DnsName, Upn or IP instead.
 
    .PARAMETER IP
    Specifies or more IP Addresses to be written into the Subject Alternative Name (SAN) Extension of the Certificate Request.
    May be left Empty if you specify a Subject, DnsName or Upn instead.
 
    .PARAMETER ChallengePassword
    Specifies the Challenge Password used to authenticate to the NDES Server.
    Not necessary if the NDES Server doesn't require a Password, or if you specify a SigningCert.
 
    .PARAMETER SigningCert
    Specifies the Signing Certificate used to sign the SCEP Certificate Request.
    Can be passed to the Command via the Pipeline.
    Use this when you already have a Certificate issued by the NDES Server and just want to renew it.
    Subject Information will be taken from this Certificate as otherwise NDES would deny the Request if there is a mismatch.
 
    .PARAMETER Ksp
    Specifies the Cryptographic Service Provider (CSP) or Key Storage Provider (KSP) to be used for the Private Key of the Certificate.
    You can specify any CSP or KSP that is installed on the System.
    Defaults to the Microsoft Software Key Storage Provider.
 
    .PARAMETER KeyAlgorithm
    Specifies the Algorithm to be used when creating the Key Pair.
    Defaults to "RSA".
 
    .PARAMETER KeyLength
    Specifies the Key Length for the Key pair of the Certificate.
    Gets applied only when KeyAlgorithm is "RSA".
    Defaults to 3072 Bits.
 
    .PARAMETER PrivateKeyExportable
    Specifies if the Private Key of the Certificate shall be marked as exportable.
    Defaults to the Key being not marked as exportable.
 
    .PARAMETER UseSSL
    Forces the connection to use SSL Encryption. Not necessary from a security perspective,
    as the SCEP Message's confidential partsd are encrypted with the NDES RA Certificates anyway.
 
    .PARAMETER Port
    Specifies the Network Port of the NDES Server to be used.
    Only necessary if your NDES Server is running on a non-default Port for some reason.
    Defaults to Port 80 without SSL and 443 with SSL.
 
    .PARAMETER Method
    Specifies if the Certificate Submission shall be done with HTTP "GET" or "POST".
    Defaults to "POST".
 
    .OUTPUTS
    System.Security.Cryptography.X509Certificates.X509Certificate. Returns the issued Certificate returned by the NDES Server.
#>

Function Get-NDESCertificate {

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$True)]
        [String]
        $ComputerName,

        [Alias("Machine")]
        [Parameter(
            ParameterSetName="NewRequest",
            Mandatory=$False
            )]
        [Switch]
        $MachineContext = $False,

        [Parameter(
            ParameterSetName="NewRequest",
            Mandatory=$False
            )]
        [ValidateNotNullOrEmpty()]
        [String]
        $Subject,

        [Parameter(
            ParameterSetName="NewRequest",
            Mandatory=$False
            )]
        [Alias("DnsName")]
        [ValidateNotNullOrEmpty()]
        [ValidateScript({
            $_ | ForEach-Object -Process {
            [System.Uri]::CheckHostName($_) -eq [System.UriHostnameType]::Dns
            }
        })]
        [String[]]
        $Dns,

        [Parameter(
            ParameterSetName="NewRequest",
            Mandatory=$False
            )]
        [Alias("UserPrincipalName")]
        [ValidateNotNullOrEmpty()]
        [mailaddress[]]
        $Upn,

        [Parameter(
            ParameterSetName="NewRequest",
            Mandatory=$False
            )]
        [Alias("RFC822Name")]
        [Alias("E-Mail")]
        [ValidateNotNullOrEmpty()]
        [mailaddress[]]
        $Email,

        [Alias("IPAddress")]
        [Parameter(Mandatory=$False)]
        [ValidateNotNullOrEmpty()]
        [System.Net.IPAddress[]]
        $IP,

        [Parameter(
            ParameterSetName="NewRequest",
            Mandatory=$False
            )]
        [ValidateNotNullOrEmpty()]
        [String]
        $ChallengePassword,

        [Parameter(
            ParameterSetName="RenewalRequest",
            ValuefromPipeline = $True,
            Mandatory=$False
            )]
        [ValidateScript({($_.HasPrivateKey) -and ($null -ne $_.PSParentPath)})]
        [System.Security.Cryptography.X509Certificates.X509Certificate2]
        $SigningCert,

        [Alias("KeyStorageProvider")]
        [Parameter(Mandatory=$False)]
        [ValidateScript({
            $Ksp = $_
            [bool](Get-KeyStorageProvider | Where-Object { $_.Name -eq $Ksp })}
        )]
        [String]
        $Ksp = "Microsoft Software Key Storage Provider",

        [Parameter(Mandatory=$False)]
        [ValidateSet(
            "RSA",
            "ECDSA_P256",
            "ECDSA_P384",
            "ECDSA_P521",
            "ECDH_P256",
            "ECDH_P384",
            "ECDH_P521"
            )]
        [String]
        $KeyAlgorithm = "RSA",

        [Alias("KeySize")]
        [Parameter(Mandatory=$False)]
        [ValidateSet(512,1024,2048,3072,4096,8192)]
        [Int]
        $KeyLength = 3072,

        [Alias("Exportable")]
        [Parameter(Mandatory=$False)]
        [Switch]
        $PrivateKeyExportable = $False,

        [Alias("SSL")]
        [Parameter(Mandatory=$False)]
        [Switch]
        $UseSSL = $False,

        [Parameter(Mandatory=$False)]
        [ValidateRange(1,65535)]
        [Int]
        $Port,

        [Parameter(Mandatory=$False)]
        [ValidateSet("GET","POST")]
        [String]
        $Method = "POST",

        [Parameter(Mandatory=$False)]
        [ValidateNotNullOrEmpty()]
        [String]
        $Suffix = "certsrv/mscep/mscep.dll"
    )

    begin  {

        Add-Type -AssemblyName System.Security

        # This hides the Status Indicators of the Invoke-WebRequest Calls later on
        $ProgressPreference = 'SilentlyContinue'

        # Assembling the Configuration String, which is the SCEP URL in this Case
        If ($UseSSL)
            { $Protocol = "https" }
        Else 
            { $Protocol = "http" }

        If ($Port)
            { $PortString = ":$($Port)" }
        Else
            { $PortString = [String]::Empty }

        $ConfigString = "$($Protocol)://$($ComputerName)$($PortString)/$($Suffix)/pkiclient.exe"

        Write-Verbose -Message "Configuration String: $ConfigString"

        # SCEP GetCACaps Operation
        Try {
            $GetCACaps = (Invoke-WebRequest -uri "$($ConfigString)?operation=GetCACaps").Content
        }
        Catch {
            Write-Error -Message $PSItem.Exception.Message
            return
        }

        # SCEP GetCACert Operation
        Try {
            $GetCACert = (Invoke-WebRequest -uri "$($ConfigString)?operation=GetCACert").Content

            # Decoding the CMS (PKCS#7 Message that was returned from the NDES Server)
            $Pkcs7CaCert = New-Object System.Security.Cryptography.Pkcs.SignedCms
            $Pkcs7CaCert.Decode($GetCACert)
        }
        Catch {
            Write-Error -Message $PSItem.Exception.Message
            return
        }

    }

    process {

        # Skip pipeline processing if the preparation steps failed
        If (-not $GetCACaps) { return }
        If (-not $Pkcs7CaCert.Certificates) { return }

        # Ensuring the Code will be executed on a supported Operating System
        # Operating Systems prior to Windows 8.1 don't contain the IX509SCEPEnrollment Interface
        If ([int32](Get-WmiObject Win32_OperatingSystem).BuildNumber -lt $BUILD_NUMBER_WINDOWS_8_1) {
            Write-Error -Message "This must be executed on Windows 8.1/Windows Server 2012 R2 or newer!"
            return 
        }

        # Ensuring we work with Elevation when messing with the Computer Certificate Store
        # As we want to inherit Key Settings from the Signing Certificate, we must also check its Certificate Store
        If ($MachineContext.IsPresent -or ($SigningCert -and ($SigningCert.PSParentPath -match "Machine"))) {

            If (-not (
                [Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()
                ).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
                Write-Error -Message "This must be run with Elevation (Run as Administrator) when using the Machine Context!" 
                return
            }
        }

        $CertificateRequestPkcs10 = New-Object -ComObject "X509Enrollment.CX509CertificateRequestPkcs10"

        # Determining if we create an entirely new Certificate Request or inherit Settings from an old one
        If ($SigningCert) {

            # Certificate Renewal Request

            If ($GetCACaps -match "Renewal") {

                $InheritOptions =  $X509RequestInheritOptions.InheritDefault
                $InheritOptions += $X509RequestInheritOptions.InheritSubjectAltNameFlag
                $InheritOptions += $X509RequestInheritOptions.InheritExtensionsFlag
                $InheritOptions += $X509RequestInheritOptions.InheritSubjectFlag

                $CertificateRequestPkcs10.InitializeFromCertificate(
                    [int]($SigningCert.PSParentPath -match "Machine")+1,
                    [Convert]::ToBase64String($SigningCert.RawData),
                    $EncodingType.XCN_CRYPT_STRING_BASE64,
                    $InheritOptions
                )

                
                # Configuring the private Key of the Certificate
                $CertificateRequestPkcs10.PrivateKey.Length = $KeyLength
                $CertificateRequestPkcs10.PrivateKey.ExportPolicy = [int]($PrivateKeyExportable.IsPresent)
                $CertificateRequestPkcs10.PrivateKey.ProviderName = $Ksp

                <#
                    https://tools.ietf.org/html/draft-nourse-scep-23#section-2.3
                    A client that is performing certificate renewal as per Appendix D
                    SHOULD send an empty challenge password (i.e. use the empty string as
                    the challenge password) but MAY send the originally distributed
                    challenge password in the challengePassword attribute.
                #>

                $CertificateRequestPkcs10.ChallengePassword = [String]::Empty

            }
            Else {
                Write-Error -Message "The Server does not support Renewal!"
                return
            }

        }
        Else {

            # New Certificate Request

            If ((-not $Dns) -and (-not $Upn) -and (-not $Email) -and (-not $IP) -and (-not $Subject)) {
                Write-Error -Message "You must provide an Identity, either in Form ob a Subject or Subject Alternative Name!"
                return
            }


            # We first create the Private Key
            # https://docs.microsoft.com/en-us/windows/win32/api/certenroll/nn-certenroll-ix509privatekey
            # Setting the Provider Attribute on the CertRequest Object afterwards seems not to work with Key Storage Providers...why?
            $PrivateKey = New-Object -ComObject 'X509Enrollment.CX509PrivateKey'
            
            $PrivateKey.ProviderName = $Ksp

            $PrivateKey.MachineContext = [int]($MachineContext.IsPresent)
            $PrivateKey.ExportPolicy = [int]($PrivateKeyExportable.IsPresent)

            If ($KeyAlgorithm -ne "RSA") {

                $Algorithm = New-Object -ComObject 'X509Enrollment.CObjectId'
    
                # https://docs.microsoft.com/en-us/windows/win32/api/certenroll/nf-certenroll-iobjectid-initializefromalgorithmname
                $Algorithm.InitializeFromAlgorithmName(
                    $ObjectIdGroupId.XCN_CRYPT_PUBKEY_ALG_OID_GROUP_ID,
                    $ObjectIdPublicKeyFlags.XCN_CRYPT_OID_INFO_PUBKEY_ANY,
                    $AlgorithmFlags.AlgorithmFlagsNone,
                    $KeyAlgorithm
                )
    
                # https://docs.microsoft.com/en-us/windows/win32/api/certenroll/nf-certenroll-ix509privatekey-put_algorithm
                $PrivateKey.Algorithm = $Algorithm
    
                [void]([System.Runtime.Interopservices.Marshal]::ReleaseComObject($Algorithm))
            }
    
            # Key Length is only relevant when Key Type is "RSA"
            If ($KeyAlgorithm -eq "RSA") {
    
                $PrivateKey.Length = $KeyLength
            }
    
            Try {
                $PrivateKey.Create()
            }
            Catch {
                [void]([System.Runtime.Interopservices.Marshal]::ReleaseComObject($PrivateKey))
                Write-Error -Message $PSItem.Exception.Message
                return
            }

            $CertificateRequestPkcs10.InitializeFromPrivateKey(
                [int]($MachineContext.IsPresent)+1,
                $PrivateKey, 
                [String]::Empty
            )

            Try {
                # To Do: implement Validation of the Subject RDN
                $SubjectDnObject = New-Object -ComObject "X509Enrollment.CX500DistinguishedName"
                $SubjectDnObject.Encode($Subject)
                $CertificateRequestPkcs10.Subject = $SubjectDnObject
            }
            Catch {
                Write-Error -Message "Invalid Subject DN supplied!"
                return
            }

            # Set the Subject Alternative Names Extension if specified as Argument
            If ($Upn -or $Email -or $Dns -or $IP) {

                $SubjectAlternativeNamesExtension = New-Object -ComObject X509Enrollment.CX509ExtensionAlternativeNames
                $Sans = New-Object -ComObject X509Enrollment.CAlternativeNames
        
                # https://msdn.microsoft.com/en-us/library/aa374981(VS.85).aspx

                Foreach ($Entry in $Upn) {

                    $AlternativeNameObject = New-Object -ComObject X509Enrollment.CAlternativeName
                    $AlternativeNameObject.InitializeFromString(
                        $AlternativeNameType.XCN_CERT_ALT_NAME_USER_PRINCIPLE_NAME, 
                        $Entry
                    )
                    $Sans.Add($AlternativeNameObject)
                    [void]([System.Runtime.Interopservices.Marshal]::ReleaseComObject($AlternativeNameObject))
    
                }

                Foreach ($Entry in $Email) {
            
                    $AlternativeNameObject = New-Object -ComObject X509Enrollment.CAlternativeName
                    $AlternativeNameObject.InitializeFromString(
                        $AlternativeNameType.XCN_CERT_ALT_NAME_RFC822_NAME, 
                        $Entry
                    )
                    $Sans.Add($AlternativeNameObject)
                    [void]([System.Runtime.Interopservices.Marshal]::ReleaseComObject($AlternativeNameObject))
    
                }
    
                Foreach ($Entry in $Dns) {

                    $AlternativeNameObject = New-Object -ComObject X509Enrollment.CAlternativeName
                    $AlternativeNameObject.InitializeFromString(
                        $AlternativeNameType.XCN_CERT_ALT_NAME_DNS_NAME,
                        $Entry
                    )
                    $Sans.Add($AlternativeNameObject)
                    [void]([System.Runtime.Interopservices.Marshal]::ReleaseComObject($AlternativeNameObject))
    
                }

                Foreach ($Entry in $IP) {

                    $AlternativeNameObject = New-Object -ComObject X509Enrollment.CAlternativeName
                    $AlternativeNameObject.InitializeFromRawData(
                        $AlternativeNameType.XCN_CERT_ALT_NAME_IP_ADDRESS,
                        $EncodingType.XCN_CRYPT_STRING_BASE64,
                        [Convert]::ToBase64String($Entry.GetAddressBytes())
                    )
                    $Sans.Add($AlternativeNameObject)
                    [void]([System.Runtime.Interopservices.Marshal]::ReleaseComObject($AlternativeNameObject))
    
                }
                
                $SubjectAlternativeNamesExtension.Critical = $True
                $SubjectAlternativeNamesExtension.InitializeEncode($Sans)
        
                # Adding the Extension to the Certificate
                $CertificateRequestPkcs10.X509Extensions.Add($SubjectAlternativeNamesExtension)
        
            }

            If ($ChallengePassword) {
                <#
                    https://tools.ietf.org/html/draft-nourse-scep-23#section-2.2
                    PKCS#10 [RFC2986] specifies a PKCS#9 [RFC2985] challengePassword
                    attribute to be sent as part of the enrollment request. Inclusion of
                    the challengePassword by the SCEP client is OPTIONAL and allows for
                    unauthenticated authorization of enrollment requests.
                #>

                $CertificateRequestPkcs10.ChallengePassword = $ChallengePassword
            }

        }

        <#
            Identify the Root CA Certificate that was delivered with the Chain
            https://tools.ietf.org/html/rfc5280#section-6.1
            A certificate is self-issued if the same DN appears in the subject and issuer fields
        #>

        $RootCaCert = $Pkcs7CaCert.Certificates | Where-Object { $_.Subject -eq $_.Issuer }

        # Initialize the IX509SCEPEnrollment Interface
        # https://docs.microsoft.com/en-us/windows/win32/api/certenroll/nn-certenroll-ix509scepenrollment
        $SCEPEnrollmentInterface = New-Object -ComObject "X509Enrollment.CX509SCEPEnrollment"

        # Let's try to build a SCEP Enrollment Message now...

        Try {

            # https://docs.microsoft.com/en-us/windows/win32/api/certenroll/nf-certenroll-ix509scepenrollment-initialize
            $SCEPEnrollmentInterface.Initialize(
                $CertificateRequestPkcs10,
                (Get-CertificateHash -Bytes $RootCaCert.RawData -HashAlgorithm "MD5"),
                $EncodingType.XCN_CRYPT_STRING_HEX,
                [Convert]::ToBase64String($GetCACert),
                $EncodingType.XCN_CRYPT_STRING_BASE64
            )

        }
        Catch {
            Write-Error -Message $PSItem.Exception.Message
            return
        }

        # Sets the preferred hash and encryption algorithms for the request.
        # If you do not set this property, then the default hash and encryption algorithms will be used.
        # https://docs.microsoft.com/en-us/windows/win32/api/certenroll/nf-certenroll-ix509scepenrollment-put_servercapabilities
        $SCEPEnrollmentInterface.ServerCapabilities = $GetCACaps

        <#
            https://tools.ietf.org/html/draft-nourse-scep-23#section-2.2
            If the requester does not have an appropriate existing
            certificate, then a locally generated self-signed certificate
            MUST be used instead. The self-signed certificate MUST use the
            same subject name as in the PKCS#10 request.
 
            https://docs.microsoft.com/en-us/windows/win32/api/certenroll/nf-certenroll-ix509scepenrollment-put_signercertificate
            To create a renewal request, you must set this property prior to calling the CreateRequestMessage method.
            Otherwise, the CreateRequestMessage method will create a new request and generate a self-signed certificate
            using the same private key as the inner PKCSV10 reqeust.
        #>

        If ($SigningCert) {

            $SignerCertificate = New-Object -ComObject 'X509Enrollment.CSignerCertificate'

            # https://docs.microsoft.com/en-us/windows/win32/api/certenroll/nf-certenroll-isignercertificate-initialize
            $SignerCertificate.Initialize(
                [int]($SigningCert.PSParentPath -match "Machine"),
                $X509PrivateKeyVerify.VerifyNone, # We did this already during Parameter Validation
                $EncodingType.XCN_CRYPT_STRING_BASE64,
                [Convert]::ToBase64String($SigningCert.RawData)
            )
            $SCEPEnrollmentInterface.SignerCertificate = $SignerCertificate
        }

        # Building the PKCS7 Message for the SCEP Enrollment
        # https://docs.microsoft.com/en-us/windows/win32/api/certenroll/nf-certenroll-ix509scepenrollment-createrequestmessage
        $SCEPRequestMessage = $SCEPEnrollmentInterface.CreateRequestMessage(
            $EncodingType.XCN_CRYPT_STRING_BASE64
            )
        
        # Submission to the NDES Server
        Try {

            If ($Method -eq "POST") {

                If ($GetCACaps -match "POSTPKIOperation") {
                    $SCEPResponse = Invoke-WebRequest `
                        -Body ([Convert]::FromBase64String($SCEPRequestMessage)) `
                        -Method 'POST' `
                        -Uri "$($ConfigString)?operation=PKIOperation" `
                        -Headers @{'Content-Type' = 'application/x-pki-message'}
                }
                Else {
                    Write-Warning -Message "The Server indicates that it doesnt support the 'POST' Method. Falling back to 'GET'."
                    $Method = "GET"
                }
            }

            If ($Method -eq "GET") {
                $SCEPResponse = Invoke-WebRequest `
                    -Method 'GET' `
                    -Uri "$($ConfigString)?operation=PKIOperation&message=$([uri]::EscapeDataString($SCEPRequestMessage))" `
                    -Headers @{'Content-Type' = 'application/x-pki-message'}
            }

            $SCEPResponse = [Convert]::ToBase64String($ScepResponse.Content)

        }
        Catch {
            Write-Error -Message $PSItem.Exception.Message
            return
        }
        
        Try {

            # Process a response message and return the disposition of the message.
            # https://docs.microsoft.com/en-us/windows/win32/api/certenroll/nf-certenroll-ix509scepenrollment-processresponsemessage
            $Disposition = $SCEPEnrollmentInterface.ProcessResponseMessage(
                $SCEPResponse,
                $EncodingType.XCN_CRYPT_STRING_BASE64
                )

            # https://docs.microsoft.com/en-us/windows/win32/api/certpol/ne-certpol-x509scepdisposition
            Switch ($Disposition) {

                $X509SCEPDisposition.SCEPDispositionFailure {

                    $ErrorMessage = ''
                    $ErrorMessage += "The NDES Server rejected the Certificate Request!`n"

                    # The Failinfo Method is only present in Windows 10
                    # Windows 8.1 / 2012 R2 Users therefore won't get any fancy error message, sadly
                    If ([int32](Get-WmiObject Win32_OperatingSystem).BuildNumber -ge $BUILD_NUMBER_WINDOWS_10) {

                        $FailInfo = ($SCEPFailInfo | Where-Object { $_.Code -eq $SCEPEnrollmentInterface.FailInfo() })

                        $ErrorMessage += "SCEP Failure Information: $($FailInfo.Message) ($($FailInfo.Code)) $($FailInfo.Description)`n"
                        $ErrorMessage += "Additional Information returned by the Server: $($SCEPEnrollmentInterface.Status().Text)`n"

                        If ($SCEPEnrollmentInterface.Status().Text -match $NDESErrorCode.CERT_E_WRONG_USAGE) {
                            $ErrorMessage += "Possible reason(s): The Challenge Password has been used already."
                        }

                        If ($SCEPEnrollmentInterface.Status().Text -match $NDESErrorCode.TRUST_E_CERT_SIGNATURE) {
                            $ErrorMessage += "Possible reason(s): The NDES Server requires a Challenge Password but none was supplied."
                        }

                        If ($SCEPEnrollmentInterface.Status().Text -match $NDESErrorCode.ERROR_NOT_FOUND) {
                            $ErrorMessage += "Possible reason(s): The Challenge Password supplied is unknown to the NDES Server, or it has been used already."
                        }

                        If ($SCEPEnrollmentInterface.Status().Text -match $NDESErrorCode.CERTSRV_E_BAD_REQUESTSUBJECT) {
                            $ErrorMessage += "Possible reason(s): The CA denied your request because an invalid Subject was requested."
                        }

                        If ($SCEPEnrollmentInterface.Status().Text -match $NDESErrorCode.RPC_S_SERVER_UNAVAILABLE) {
                            $ErrorMessage += "Possible reason(s): The NDES Server was unable to contact the Certification Authority."
                        }
                    }

                    Write-Error -Message $ErrorMessage

                }

                $X509SCEPDisposition.SCEPDispositionPending {
                    Write-Warning -Message "The Enrollment was successful with Status ScepDispositionPending, which is not yet implemented!"
                }

                $X509SCEPDisposition.SCEPDispositionPendingChallenge {
                    Write-Warning -Message  "The Enrollment was successful with Status ScepDispositionPendingChallenge, which is not yet implemented!"
                }

                $X509SCEPDisposition.SCEPDispositionUnknown {
                    Write-Error -Message "The Enrollment failed for an unknown Reason."
                }

                $X509SCEPDisposition.SCEPDispositionSuccess {

                    # We load the Certificate into an X509Certificate2 Object
                    # https://docs.microsoft.com/en-us/windows/win32/api/certenroll/nf-certenroll-ix509scepenrollment-get_certificate
                    $CertificateObject = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
                    $CertificateObject.Import(
                        [Convert]::FromBase64String(
                            $SCEPEnrollmentInterface.Certificate($EncodingType.XCN_CRYPT_STRING_BASE64)
                            )
                        )

                    # Return the resulting Certificate
                    If ($MachineContext.IsPresent -or ($SigningCert -and ($SigningCert.PSParentPath -match "Machine"))) {
                        Get-ChildItem -Path "Cert:\LocalMachine\My\$($CertificateObject.Thumbprint)"
                    }
                    Else {
                        Get-ChildItem -Path "Cert:\CurrentUser\My\$($CertificateObject.Thumbprint)"
                    }
                }

            }

        }
        Catch {
            Write-Error -Message $PSItem.Exception.Message
            return  
        }

        # Cleaning up the COM Objects, avoiding any User Errors to be reported
        $CertificateRequestPkcs10,
        $SubjectDnObject,
        $SubjectAlternativeNamesExtension,
        $Sans,
        $SCEPEnrollmentInterface,
        $SignerCertificate | ForEach-Object -Process {

            Try {
                [void]([System.Runtime.Interopservices.Marshal]::ReleaseComObject($_))
            }
            Catch {
                # we don't want to return anything here
            }
        }
    }

    end {}
}
# SIG # Begin signature block
# MIIk6gYJKoZIhvcNAQcCoIIk2zCCJNcCAQExDzANBglghkgBZQMEAgEFADB5Bgor
# BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG
# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCCHrM1ZqWq2FG1d
# FBhhsGjuVBHRzdsmtOmeKVNU2GuFz6CCHqwwggVAMIIEKKADAgECAhEAjyqX/F4u
# bPBaKM2QGtlbKTANBgkqhkiG9w0BAQsFADB8MQswCQYDVQQGEwJHQjEbMBkGA1UE
# CBMSR3JlYXRlciBNYW5jaGVzdGVyMRAwDgYDVQQHEwdTYWxmb3JkMRgwFgYDVQQK
# Ew9TZWN0aWdvIExpbWl0ZWQxJDAiBgNVBAMTG1NlY3RpZ28gUlNBIENvZGUgU2ln
# bmluZyBDQTAeFw0yMDExMjAwMDAwMDBaFw0yMzExMjAyMzU5NTlaMIGHMQswCQY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