|
| 1 | +<# |
| 2 | + .SYNOPSIS |
| 3 | + The `AdcsAuthorityInformationAccess` DSC resource is used to configure the |
| 4 | + URIs in the Authority Information Access and Online Responder OCSP extensions. |
| 5 | +
|
| 6 | + .DESCRIPTION |
| 7 | + This resource can be used to configure the URIs in the Authority Information |
| 8 | + Access and Online Responder OCSP extensions of certificates issued by an |
| 9 | + Active Directory Certificate Authority. |
| 10 | +
|
| 11 | + .PARAMETER IsSingleInstance |
| 12 | + Specifies the resource is a single instance, the value must be 'Yes'. |
| 13 | +
|
| 14 | + .PARAMETER AiaUri |
| 15 | + Specifies the list of URIs that should be included in the AIA extension of |
| 16 | + the issued certificate. |
| 17 | +
|
| 18 | + .PARAMETER OcspUri |
| 19 | + Specifies the list of URIs that should be included in the Online Responder |
| 20 | + OCSP extension of the issued certificate. |
| 21 | +
|
| 22 | + .PARAMETER AllowRestartService |
| 23 | + Allows the Certificate Authority service to be restarted if changes are made. |
| 24 | +
|
| 25 | + .PARAMETER Reasons |
| 26 | + Returns the reason a property is not in desired state. |
| 27 | +
|
| 28 | + .NOTES |
| 29 | + Used Functions: |
| 30 | + Name | Module |
| 31 | + --------------------------------- |-------------------------- |
| 32 | + Add-CAAuthorityInformationAccess | AdcsAdministration |
| 33 | + Remove-CAAuthorityInformationAccess | AdcsAdministration |
| 34 | + Assert-Module | DscResource.Common |
| 35 | + Assert-BoundParameter | DscResource.Common |
| 36 | + Get-CaAiaUriList | ActiveDirectoryCSDsc |
| 37 | + Restart-ServiceIfExists | ActiveDirectoryCSDsc.Common |
| 38 | +#> |
| 39 | + |
| 40 | +[DscResource()] |
| 41 | +class AdcsAuthorityInformationAccess : ResourceBase |
| 42 | +{ |
| 43 | + [DscProperty(Key)] |
| 44 | + [System.String] |
| 45 | + $IsSingleInstance = 'Yes' |
| 46 | + |
| 47 | + [DscProperty()] |
| 48 | + [System.String[]] |
| 49 | + $AiaUri |
| 50 | + |
| 51 | + [DscProperty()] |
| 52 | + [System.String[]] |
| 53 | + $OcspUri |
| 54 | + |
| 55 | + [DscProperty()] |
| 56 | + [Nullable[System.Boolean]] |
| 57 | + $AllowRestartService |
| 58 | + |
| 59 | + [DscProperty(NotConfigurable)] |
| 60 | + [AdcsReason[]] |
| 61 | + $Reasons |
| 62 | + |
| 63 | + AdcsAuthorityInformationAccess () : base ($PSScriptRoot) |
| 64 | + { |
| 65 | + # These properties will not be enforced. |
| 66 | + $this.ExcludeDscProperties = @( |
| 67 | + 'IsSingleInstance' |
| 68 | + 'AllowRestartService' |
| 69 | + ) |
| 70 | + } |
| 71 | + |
| 72 | + [AdcsAuthorityInformationAccess] Get() |
| 73 | + { |
| 74 | + # Call the base method to return the properties. |
| 75 | + return ([ResourceBase] $this).Get() |
| 76 | + } |
| 77 | + |
| 78 | + # Base method Get() calls this method to get the current state as a Hashtable. |
| 79 | + [System.Collections.Hashtable] GetCurrentState([System.Collections.Hashtable] $properties) |
| 80 | + { |
| 81 | + $state = @{} |
| 82 | + |
| 83 | + $AiaList = [System.String[]] (Get-CaAiaUriList -ExtensionType 'AddToCertificateAia') |
| 84 | + $OcspList = [System.String[]] (Get-CaAiaUriList -ExtensionType 'AddToCertificateOcsp') |
| 85 | + |
| 86 | + if ($AiaList -or $OcspList) |
| 87 | + { |
| 88 | + $state = @{ |
| 89 | + IsSingleInstance = $properties.IsSingleInstance |
| 90 | + AiaUri = $AiaList |
| 91 | + OcspUri = $OcspList |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + return $state |
| 96 | + } |
| 97 | + |
| 98 | + [void] Set() |
| 99 | + { |
| 100 | + # Call the base method to enforce the properties. |
| 101 | + ([ResourceBase] $this).Set() |
| 102 | + } |
| 103 | + |
| 104 | + <# |
| 105 | + Base method Set() call this method with the properties that should be |
| 106 | + enforced and that are not in desired state. |
| 107 | + #> |
| 108 | + hidden [void] Modify([System.Collections.Hashtable] $properties) |
| 109 | + { |
| 110 | + $RestartRequired = $false |
| 111 | + |
| 112 | + if ($properties.ContainsKey('AiaUri')) |
| 113 | + { |
| 114 | + # Get the array number of the entry |
| 115 | + $index = [System.Array]::IndexOf($this.PropertiesNotInDesiredState.Property, 'AiaUri') |
| 116 | + |
| 117 | + # Add any missing AIA URIs |
| 118 | + foreach ($desiredAiaUri in $this.PropertiesNotInDesiredState[$index].ExpectedValue) |
| 119 | + { |
| 120 | + if ($desiredAiaUri -notin $this.PropertiesNotInDesiredState[$index].ActualValue) |
| 121 | + { |
| 122 | + Write-Debug -Message ($this.localizedData.AddingAdcsAiaUriMessage -f 'AIA', $desiredAiaUri) |
| 123 | + |
| 124 | + Add-CAAuthorityInformationAccess -Uri $desiredAiaUri -AddToCertificateAia -Force -Verbose:$false |
| 125 | + |
| 126 | + $RestartRequired = $true |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | + # Remove any AIA URIs that aren't required |
| 131 | + foreach ($currentAiaUri in $this.PropertiesNotInDesiredState[$index].ActualValue) |
| 132 | + { |
| 133 | + if ($currentAiaUri -notin $this.PropertiesNotInDesiredState[$index].ExpectedValue) |
| 134 | + { |
| 135 | + Write-Debug -Message ($this.localizedData.RemovingAdcsAiaUriMessage -f 'AIA', $currentAiaUri) |
| 136 | + |
| 137 | + Remove-CAAuthorityInformationAccess -Uri $currentAiaUri -AddToCertificateAia -Force -Verbose:$false |
| 138 | + |
| 139 | + $RestartRequired = $true |
| 140 | + } |
| 141 | + } |
| 142 | + } |
| 143 | + |
| 144 | + if ($properties.ContainsKey('OcspUri')) |
| 145 | + { |
| 146 | + # Get the array number of the entry |
| 147 | + $index = [System.Array]::IndexOf($this.PropertiesNotInDesiredState.Property, 'OcspUri') |
| 148 | + |
| 149 | + # Add any missing OCSP URIs |
| 150 | + foreach ($desiredOcspUri in $this.PropertiesNotInDesiredState[$index].ExpectedValue) |
| 151 | + { |
| 152 | + if ($desiredOcspUri -notin $this.PropertiesNotInDesiredState[$index].ActualValue) |
| 153 | + { |
| 154 | + Write-Debug -Message ($this.localizedData.AddingAdcsAiaUriMessage -f 'OCSP', $desiredOcspUri) |
| 155 | + |
| 156 | + Add-CAAuthorityInformationAccess -Uri $desiredOcspUri -AddToCertificateOcsp -Force -Verbose:$false |
| 157 | + |
| 158 | + $RestartRequired = $true |
| 159 | + } |
| 160 | + } |
| 161 | + |
| 162 | + # Remove any OCSP URIs that aren't required |
| 163 | + foreach ($currentOcspUri in $this.PropertiesNotInDesiredState[$index].ActualValue) |
| 164 | + { |
| 165 | + if ($currentOcspUri -notin $this.PropertiesNotInDesiredState[$index].ExpectedValue) |
| 166 | + { |
| 167 | + Write-Debug -Message ($this.localizedData.RemovingAdcsAiaUriMessage -f 'OCSP', $currentOcspUri) |
| 168 | + |
| 169 | + Remove-CAAuthorityInformationAccess -Uri $currentOcspUri -AddToCertificateOcsp -Force -Verbose:$false |
| 170 | + |
| 171 | + $RestartRequired = $true |
| 172 | + } |
| 173 | + } |
| 174 | + } |
| 175 | + |
| 176 | + if ($RestartRequired -and $this.AllowRestartService) |
| 177 | + { |
| 178 | + Write-Debug -Message $this.localizedData.RestartingCertSvcMessage |
| 179 | + |
| 180 | + $null = Restart-ServiceIfExists -Name 'CertSvc' -Verbose:$false |
| 181 | + } |
| 182 | + } |
| 183 | + |
| 184 | + [System.Boolean] Test() |
| 185 | + { |
| 186 | + # Call the base method to test all of the properties that should be enforced. |
| 187 | + return ([ResourceBase] $this).Test() |
| 188 | + } |
| 189 | + |
| 190 | + <# |
| 191 | + Base method Assert() call this method with the properties that was assigned |
| 192 | + a value. |
| 193 | + #> |
| 194 | + hidden [void] AssertProperties([System.Collections.Hashtable] $properties) |
| 195 | + { |
| 196 | + Assert-Module -ModuleName 'ADCSAdministration' |
| 197 | + |
| 198 | + $assertBoundParameterParameters = @{ |
| 199 | + BoundParameterList = $properties |
| 200 | + RequiredParameter = @( |
| 201 | + 'AiaUri' |
| 202 | + 'OcspUri' |
| 203 | + ) |
| 204 | + RequiredBehavior = 'Any' |
| 205 | + } |
| 206 | + |
| 207 | + Assert-BoundParameter @assertBoundParameterParameters |
| 208 | + } |
| 209 | +} |
0 commit comments