Skip to content

Commit 72ba701

Browse files
New-DbaComputerCertificate: Update security defaults to industry standards (#10167)
1 parent be1c993 commit 72ba701

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

public/New-DbaComputerCertificate.ps1

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function New-DbaComputerCertificate {
66
.DESCRIPTION
77
Creates a new computer certificate - self-signed or signed by an Active Directory CA, using the Web Server certificate.
88
9-
By default, a key with a length of 1024 and a friendly name of the machines FQDN is generated.
9+
By default, a key with a length of 2048 bits and a friendly name of "SQL Server" is generated.
1010
1111
This command was originally intended to help automate the process so that SSL certificates can be available for enforcing encryption on connections.
1212
@@ -59,8 +59,8 @@ function New-DbaComputerCertificate {
5959
6060
.PARAMETER KeyLength
6161
Specifies the RSA key size in bits for the certificate's private key.
62-
Defaults to 1024 bits, though 2048 or 4096 bits provide better security for production environments.
63-
Longer keys provide stronger encryption but may slightly impact performance during SSL handshakes.
62+
Defaults to 2048 bits which meets current industry security standards for production environments.
63+
4096 bits can be used for high-security environments, though it may slightly impact performance during SSL handshakes.
6464
6565
.PARAMETER Store
6666
Specifies the certificate store location where the certificate will be installed.
@@ -90,8 +90,8 @@ function New-DbaComputerCertificate {
9090
9191
.PARAMETER HashAlgorithm
9292
Specifies the cryptographic hash algorithm used for certificate signing.
93-
Defaults to "sha1" for compatibility, though "Sha256" or higher is recommended for production security.
94-
Modern browsers and applications prefer SHA-256 or higher; avoid MD5 and MD4 for security reasons.
93+
Defaults to "Sha256" which meets current industry security standards for production environments.
94+
SHA-384 and SHA-512 provide even stronger security for high-security environments.
9595
9696
.PARAMETER MonthsValid
9797
Specifies how many months the self-signed certificate remains valid from the creation date.
@@ -149,12 +149,12 @@ function New-DbaComputerCertificate {
149149
.EXAMPLE
150150
PS C:\> New-DbaComputerCertificate
151151
152-
Creates a computer certificate signed by the local domain CA for the local machine with the keylength of 1024.
152+
Creates a computer certificate signed by the local domain CA for the local machine with the keylength of 2048 and SHA-256 hashing.
153153
154154
.EXAMPLE
155155
PS C:\> New-DbaComputerCertificate -ComputerName Server1
156156
157-
Creates a computer certificate signed by the local domain CA _on the local machine_ for server1 with the keylength of 1024.
157+
Creates a computer certificate signed by the local domain CA _on the local machine_ for server1 with the keylength of 2048 and SHA-256 hashing.
158158
159159
The certificate is then copied to the new machine over WinRM and imported.
160160
@@ -194,16 +194,16 @@ function New-DbaComputerCertificate {
194194
[securestring]$SecurePassword,
195195
[string]$FriendlyName = "SQL Server",
196196
[string]$CertificateTemplate = "WebServer",
197-
[int]$KeyLength = 1024,
197+
[int]$KeyLength = 2048,
198198
[string]$Store = "LocalMachine",
199199
[string]$Folder = "My",
200200
[ValidateSet("EphemeralKeySet", "Exportable", "PersistKeySet", "UserProtected", "NonExportable")]
201201
[string[]]$Flag = @("Exportable", "PersistKeySet"),
202202
[string[]]$Dns,
203203
[switch]$SelfSigned,
204204
[switch]$EnableException,
205-
[ValidateSet("Sha256", "sha384", "sha512", "sha1", "md5", "md4", "md2")]
206-
[string]$HashAlgorithm = "sha1",
205+
[ValidateSet("Sha256", "sha384", "sha512")]
206+
[string]$HashAlgorithm = "Sha256",
207207
[int]$MonthsValid = 12
208208
)
209209
begin {
@@ -378,7 +378,12 @@ function New-DbaComputerCertificate {
378378
Add-Content $certCfg "Subject = ""CN=$fqdn"""
379379
Add-Content $certCfg "KeySpec = 1"
380380
Add-Content $certCfg "KeyLength = $KeyLength"
381-
Add-Content $certCfg "Exportable = TRUE"
381+
# Set Exportable based on Flag parameter - if NonExportable is specified, set to FALSE
382+
if ("NonExportable" -in $Flag) {
383+
Add-Content $certCfg "Exportable = FALSE"
384+
} else {
385+
Add-Content $certCfg "Exportable = TRUE"
386+
}
382387
Add-Content $certCfg "MachineKeySet = TRUE"
383388
Add-Content $certCfg "FriendlyName=""$FriendlyName"""
384389
Add-Content $certCfg "SMIME = False"

tests/New-DbaComputerCertificate.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ if (-not $env:appveyor) {
5555
}
5656

5757
It "Returns the right default encryption algorithm" {
58-
"$(($defaultCert | Select-Object @{n="SignatureAlgorithm";e={$PSItem.SignatureAlgorithm.FriendlyName}})).SignatureAlgorithm)" -match "sha1RSA" | Should -BeTrue
58+
"$(($defaultCert | Select-Object @{n="SignatureAlgorithm";e={$PSItem.SignatureAlgorithm.FriendlyName}})).SignatureAlgorithm)" -match "sha256RSA" | Should -BeTrue
5959
}
6060

6161
It "Returns the right default one year expiry date" {

0 commit comments

Comments
 (0)