Skip to content

Commit e13f433

Browse files
committed
First improvements to module
1 parent 90dc014 commit e13f433

File tree

12 files changed

+315
-136
lines changed

12 files changed

+315
-136
lines changed

.github/CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
If you'd like to contribute to this project, please review the [Contribution Guidelines](https://github.com/powershell/SChannelDsc/wiki/Contributing%20to%20SChannelDsc).
1+
If you'd like to contribute to this project, please review the [Contribution Guidelines](https://github.com/Microsoft/SChannelDsc/wiki/Contributing%20to%20SChannelDsc).

.github/PULL_REQUEST_TEMPLATE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Thanks for submitting a Pull Request (PR) to this project.
33
Your contribution to this project is greatly appreciated!
44
5-
Please make sure you have read the [Contribution Guidelines](https://github.com/PowerShell/SChannelDsc/wiki/Contributing%20to%20SChannelDsc).
5+
Please make sure you have read the [Contribution Guidelines](https://github.com/Microsoft/SChannelDsc/wiki/Contributing%20to%20SChannelDsc).
66
77
Please prefix the PR title with the resource name,
88
e.g. 'ResourceName: My short description'.

Modules/SChannelDsc/DSCResources/MSFT_Cipher/MSFT_Cipher.psm1

+24-23
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,30 @@ function Get-TargetResource
2424
param
2525
(
2626
[Parameter(Mandatory = $true)]
27-
[ValidateSet("AES 128/128","AES 256/256","DES 56/56","NULL","RC2 128/128","RC2 40/128","RC2 56/128","RC4 128/128","RC4 40/128","RC4 56/128","RC4 64/128","Triple DES 168")]
27+
[ValidateSet('AES 128/128','AES 256/256','DES 56/56','NULL','RC2 128/128','RC2 40/128','RC2 56/128','RC4 128/128','RC4 40/128','RC4 56/128','RC4 64/128','Triple DES 168')]
2828
[System.String]
2929
$Cipher,
3030

3131
[Parameter()]
32-
[ValidateSet("Present","Absent")]
32+
[ValidateSet('Present','Absent')]
3333
[System.String]
34-
$Ensure = "Present"
34+
$Ensure = 'Present'
3535
)
3636

3737
$RootKey = 'HKLM:SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers'
38-
$Key = $RootKey + "\" + $cipher
39-
if (Test-SchannelItem -itemKey $Key -enable $true)
38+
$Key = $RootKey + '\' + $cipher
39+
if ((Test-SChannelItem -itemKey $Key -enable $true) -eq $true)
4040
{
41-
$Result = "Present"
41+
$Result = 'Present'
4242
}
4343
else
4444
{
45-
$Result = "Absent"
45+
$Result = 'Absent'
4646
}
4747

4848
$returnValue = @{
49-
Cipher = [System.String]$Cipher
50-
Ensure = [System.String]$Result
49+
Cipher = [System.String]$Cipher
50+
Ensure = [System.String]$Result
5151
}
5252

5353
$returnValue
@@ -59,28 +59,28 @@ function Set-TargetResource
5959
param
6060
(
6161
[Parameter(Mandatory = $true)]
62-
[ValidateSet("AES 128/128","AES 256/256","DES 56/56","NULL","RC2 128/128","RC2 40/128","RC2 56/128","RC4 128/128","RC4 40/128","RC4 56/128","RC4 64/128","Triple DES 168")]
62+
[ValidateSet('AES 128/128','AES 256/256','DES 56/56','NULL','RC2 128/128','RC2 40/128','RC2 56/128','RC4 128/128','RC4 40/128','RC4 56/128','RC4 64/128','Triple DES 168')]
6363
[System.String]
6464
$Cipher,
6565

6666
[Parameter()]
67-
[ValidateSet("Present","Absent")]
67+
[ValidateSet('Present','Absent')]
6868
[System.String]
69-
$Ensure = "Present"
69+
$Ensure = 'Present'
7070
)
7171

7272
$RootKey = 'HKLM:SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers'
73-
$Key = $RootKey + "\" + $cipher
73+
$Key = $RootKey + '\' + $cipher
7474

75-
if ($Ensure -eq "Present")
75+
if ($Ensure -eq 'Present')
7676
{
7777
Write-Verbose -Message ($LocalizedData.ItemEnable -f 'Cipher', $Cipher)
78-
Switch-SchannelItem -itemKey $Key -enable $true
78+
Switch-SChannelItem -itemKey $Key -enable $true
7979
}
8080
else
8181
{
8282
Write-Verbose -Message ($LocalizedData.ItemDisable -f 'Cipher', $Cipher)
83-
Switch-SchannelItem -itemKey $Key -enable $false
83+
Switch-SChannelItem -itemKey $Key -enable $false
8484
}
8585
}
8686

@@ -91,29 +91,30 @@ function Test-TargetResource
9191
param
9292
(
9393
[Parameter(Mandatory = $true)]
94-
[ValidateSet("AES 128/128","AES 256/256","DES 56/56","NULL","RC2 128/128","RC2 40/128","RC2 56/128","RC4 128/128","RC4 40/128","RC4 56/128","RC4 64/128","Triple DES 168")]
94+
[ValidateSet('AES 128/128','AES 256/256','DES 56/56','NULL','RC2 128/128','RC2 40/128','RC2 56/128','RC4 128/128','RC4 40/128','RC4 56/128','RC4 64/128','Triple DES 168')]
9595
[System.String]
9696
$Cipher,
9797

9898
[Parameter()]
99-
[ValidateSet("Present","Absent")]
99+
[ValidateSet('Present','Absent')]
100100
[System.String]
101-
$Ensure = "Present"
101+
$Ensure = 'Present'
102102
)
103103

104104
$RootKey = 'HKLM:SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers'
105-
$Key = $RootKey + "\" + $cipher
105+
$Key = $RootKey + '\' + $cipher
106106
$currentCipher = Get-TargetResource @PSBoundParameters
107107
$Compliant = $false
108108

109-
$ErrorActionPreference = "SilentlyContinue"
109+
$ErrorActionPreference = 'SilentlyContinue'
110110
Write-Verbose -Message ($LocalizedData.ItemTest -f 'Cipher', $Cipher)
111-
if ($currentCipher.Ensure -eq $Ensure -and (Get-ItemProperty -Path $Key -Name Enabled))
111+
if ($currentCipher.Ensure -eq $Ensure -and `
112+
(Get-ItemProperty -Path $Key -Name Enabled))
112113
{
113114
$Compliant = $true
114115
}
115116

116-
if ($Compliant)
117+
if ($Compliant -eq $true)
117118
{
118119
Write-Verbose -Message ($LocalizedData.ItemCompliant -f 'Cipher', $Cipher)
119120
}

Modules/SChannelDsc/DSCResources/MSFT_CipherSuites/MSFT_CipherSuites.psm1

+25-10
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@ function Get-TargetResource
2121
[OutputType([System.Collections.Hashtable])]
2222
param
2323
(
24+
[Parameter(Mandatory = $true)]
25+
[ValidateSet("Yes")]
26+
[System.String]
27+
$IsSingleInstance,
28+
2429
[Parameter()]
2530
[System.String[]]
2631
$CipherSuitesOrder,
2732

28-
[Parameter(Mandatory = $true)]
33+
[Parameter()]
2934
[ValidateSet("Present","Absent")]
3035
[System.String]
3136
$Ensure = "Present"
@@ -34,7 +39,7 @@ function Get-TargetResource
3439
$itemKey = 'HKLM:\SOFTWARE\Policies\Microsoft\Cryptography\Configuration\SSL\00010002'
3540
$item = Get-ItemProperty -Path $itemKey -ErrorAction SilentlyContinue
3641

37-
if ($item)
42+
if ($null -ne $item)
3843
{
3944
$Ensure = 'Present'
4045
$Order = (Get-ItemPropertyValue -Path $itemKey -Name Functions -ErrorAction SilentlyContinue).Split(',')
@@ -57,27 +62,32 @@ function Set-TargetResource
5762
[CmdletBinding()]
5863
param
5964
(
65+
[Parameter(Mandatory = $true)]
66+
[ValidateSet("Yes")]
67+
[System.String]
68+
$IsSingleInstance,
69+
6070
[Parameter()]
6171
[System.String[]]
6272
$CipherSuitesOrder,
6373

64-
[Parameter(Mandatory = $true)]
74+
[Parameter()]
6575
[ValidateSet("Present","Absent")]
6676
[System.String]
6777
$Ensure = "Present"
6878
)
6979

70-
if ($Ensure -eq "Present")
80+
if ($Ensure -eq 'Present')
7181
{
72-
Write-Verbose -Message ($LocalizedData.ItemEnable -f "CipherSuites" , $Ensure)
82+
Write-Verbose -Message ($LocalizedData.ItemEnable -f 'CipherSuites' , $Ensure)
7383
$itemKey = 'HKLM:\SOFTWARE\Policies\Microsoft\Cryptography\Configuration\SSL\00010002'
7484
$cipherSuitesAsString = [string]::join(',', $cipherSuitesOrder)
7585
New-Item $itemKey -Force
7686
New-ItemProperty -Path $itemKey -Name 'Functions' -Value $cipherSuitesAsString -PropertyType 'String' -Force | Out-Null
7787
}
7888
else
7989
{
80-
Write-Verbose -Message ($LocalizedData.ItemDisable -f "CipherSuites" , $Ensure)
90+
Write-Verbose -Message ($LocalizedData.ItemDisable -f 'CipherSuites' , $Ensure)
8191
$itemKey = 'HKLM:\SOFTWARE\Policies\Microsoft\Cryptography\Configuration\SSL\'
8292
Remove-Item $itemKey -Force
8393
}
@@ -89,22 +99,27 @@ function Test-TargetResource
8999
[OutputType([System.Boolean])]
90100
param
91101
(
102+
[Parameter(Mandatory = $true)]
103+
[ValidateSet("Yes")]
104+
[System.String]
105+
$IsSingleInstance,
106+
92107
[Parameter()]
93108
[System.String[]]
94109
$CipherSuitesOrder,
95110

96-
[Parameter(Mandatory = $true)]
111+
[Parameter()]
97112
[ValidateSet("Present","Absent")]
98113
[System.String]
99114
$Ensure = "Present"
100115
)
101116

102117
$cipherSuites = Get-TargetResource @PSBoundParameters
103-
if ($CipherSuitesOrder)
118+
if ($null -ne $CipherSuitesOrder)
104119
{
105120
$cipherSuitesAsString = [string]::join(',', $cipherSuitesOrder)
106121
}
107-
if ($cipherSuites.CipherSuitesOrder)
122+
if ($null -ne $cipherSuites.CipherSuitesOrder)
108123
{
109124
$currentSuitesOrderAsString = [string]::join(',', $cipherSuites.CipherSuitesOrder)
110125
}
@@ -124,7 +139,7 @@ function Test-TargetResource
124139
$Compliant = $true
125140
}
126141

127-
if ($Compliant)
142+
if ($Compliant -eq $true)
128143
{
129144
Write-Verbose -Message ($LocalizedData.ItemCompliant -f "CipherSuitesOrder" , $Ensure)
130145
}

Modules/SChannelDsc/DSCResources/MSFT_CipherSuites/MSFT_CipherSuites.schema.mof

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
[ClassVersion("1.0.0.0"), FriendlyName("CipherSuites")]
33
class MSFT_CipherSuites : OMI_BaseResource
44
{
5+
[Key, ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance;
56
[Write] String CipherSuitesOrder[];
6-
[Key, ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure;
7+
[Write, ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure;
78
};
89

Modules/SChannelDsc/DSCResources/MSFT_Hash/MSFT_Hash.psm1

+23-22
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Import-Module -Name "$PSScriptRoot\..\Helper.psm1"
44
# Localized messages
55
data LocalizedData
66
{
7-
# culture="en-US"
7+
# culture='en-US'
88
ConvertFrom-StringData -StringData @'
99
ProtocolNotCompliant = Protocol {0} not compliant.
1010
ProtocolCompliant = Protocol {0} compliant.
@@ -24,25 +24,25 @@ function Get-TargetResource
2424
param
2525
(
2626
[Parameter(Mandatory = $true)]
27-
[ValidateSet("MD5","SHA","SHA256","SHA384","SHA512")]
27+
[ValidateSet('MD5','SHA','SHA256','SHA384','SHA512')]
2828
[System.String]
2929
$Hash,
3030

3131
[Parameter()]
32-
[ValidateSet("Present","Absent")]
32+
[ValidateSet('Present','Absent')]
3333
[System.String]
34-
$Ensure = "Present"
34+
$Ensure = 'Present'
3535
)
3636

3737
$RootKey = 'HKLM:SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Hashes'
38-
$Key = $RootKey + "\" + $Hash
39-
if (Test-SchannelItem -itemKey $Key -enable $true)
38+
$Key = $RootKey + '\' + $Hash
39+
if ((Test-SChannelItem -itemKey $Key -enable $true) -eq $true)
4040
{
41-
$Result = "Present"
41+
$Result = 'Present'
4242
}
4343
else
4444
{
45-
$Result = "Absent"
45+
$Result = 'Absent'
4646
}
4747

4848
$returnValue = @{
@@ -59,28 +59,28 @@ function Set-TargetResource
5959
param
6060
(
6161
[Parameter(Mandatory = $true)]
62-
[ValidateSet("MD5","SHA","SHA256","SHA384","SHA512")]
62+
[ValidateSet('MD5','SHA','SHA256','SHA384','SHA512')]
6363
[System.String]
6464
$Hash,
6565

6666
[Parameter()]
67-
[ValidateSet("Present","Absent")]
67+
[ValidateSet('Present','Absent')]
6868
[System.String]
69-
$Ensure = "Present"
69+
$Ensure = 'Present'
7070
)
7171

7272
$RootKey = 'HKLM:SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Hashes'
73-
$Key = $RootKey + "\" + $Hash
73+
$Key = $RootKey + '\' + $Hash
7474

75-
if ($Ensure -eq "Present")
75+
if ($Ensure -eq 'Present')
7676
{
7777
Write-Verbose -Message ($LocalizedData.ItemEnable -f 'Hash', $Hash)
78-
Switch-SchannelItem -itemKey $Key -enable $true
78+
Switch-SChannelItem -itemKey $Key -enable $true
7979
}
8080
else
8181
{
8282
Write-Verbose -Message ($LocalizedData.ItemDisable -f 'Hash', $Hash)
83-
Switch-SchannelItem -itemKey $Key -enable $false
83+
Switch-SChannelItem -itemKey $Key -enable $false
8484
}
8585
}
8686

@@ -91,28 +91,29 @@ function Test-TargetResource
9191
param
9292
(
9393
[Parameter(Mandatory = $true)]
94-
[ValidateSet("MD5","SHA","SHA256","SHA384","SHA512")]
94+
[ValidateSet('MD5','SHA','SHA256','SHA384','SHA512')]
9595
[System.String]
9696
$Hash,
9797

9898
[Parameter()]
99-
[ValidateSet("Present","Absent")]
99+
[ValidateSet('Present','Absent')]
100100
[System.String]
101-
$Ensure = "Present"
101+
$Ensure = 'Present'
102102
)
103103
$RootKey = 'HKLM:SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Hashes'
104-
$Key = $RootKey + "\" + $Hash
104+
$Key = $RootKey + '\' + $Hash
105105
$currentHash = Get-TargetResource @PSBoundParameters
106106
$Compliant = $false
107107

108-
$ErrorActionPreference = "SilentlyContinue"
108+
$ErrorActionPreference = 'SilentlyContinue'
109109
Write-Verbose -Message ($LocalizedData.ItemTest -f 'Cipher', $Cipher)
110-
if ($currentHash.Ensure -eq $Ensure -and (Get-ItemProperty -Path $Key -Name Enabled))
110+
if ($currentHash.Ensure -eq $Ensure -and `
111+
(Get-ItemProperty -Path $Key -Name Enabled))
111112
{
112113
$Compliant = $true
113114
}
114115

115-
if ($Compliant)
116+
if ($Compliant -eq $true)
116117
{
117118
Write-Verbose -Message ($LocalizedData.ItemCompliant -f 'Hash', $Hash)
118119
}

0 commit comments

Comments
 (0)