Skip to content

Commit 5590bc3

Browse files
New-DbaComputerCertificate - Add DocumentEncryptionCert switch for Always Encrypted (#10264)
1 parent 152fec1 commit 5590bc3

2 files changed

Lines changed: 48 additions & 3 deletions

File tree

public/New-DbaComputerCertificate.ps1

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ function New-DbaComputerCertificate {
8888
Useful for development environments or when no domain CA is available.
8989
Self-signed certificates will generate trust warnings unless manually added to client trust stores.
9090
91+
.PARAMETER DocumentEncryptionCert
92+
Creates a certificate suitable for use as a Column Master Key for Always Encrypted.
93+
When specified, the certificate uses KeyEncipherment key usage and includes the
94+
Document Encryption (1.3.6.1.4.1.311.10.3.11) and IKE Intermediate (1.3.6.1.5.5.8.2.2)
95+
Extended Key Usage OIDs required by Always Encrypted, instead of the default Server
96+
Authentication OID (1.3.6.1.5.5.7.3.1).
97+
9198
.PARAMETER HashAlgorithm
9299
Specifies the cryptographic hash algorithm used for certificate signing.
93100
Defaults to "Sha256" which meets current industry security standards for production environments.
@@ -180,6 +187,13 @@ function New-DbaComputerCertificate {
180187
181188
Creates a self-signed certificate using the SHA256 hashing algorithm that does not expire for 5 years
182189
190+
.EXAMPLE
191+
PS C:\> New-DbaComputerCertificate -SelfSigned -DocumentEncryptionCert
192+
193+
Creates a self-signed certificate suitable for use as a Column Master Key for Always Encrypted.
194+
The certificate includes the Document Encryption and IKE Intermediate Extended Key Usage OIDs
195+
required by SQL Server Always Encrypted.
196+
183197
#>
184198
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = "Low")]
185199
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseOutputTypeCorrectly", "", Justification = "PSSA Rule Ignored by BOH")]
@@ -201,6 +215,7 @@ function New-DbaComputerCertificate {
201215
[string[]]$Flag = @("Exportable", "PersistKeySet"),
202216
[string[]]$Dns,
203217
[switch]$SelfSigned,
218+
[switch]$DocumentEncryptionCert,
204219
[switch]$EnableException,
205220
[ValidateSet("Sha256", "sha384", "sha512")]
206221
[string]$HashAlgorithm = "Sha256",
@@ -400,9 +415,16 @@ function New-DbaComputerCertificate {
400415
Add-Content $certCfg "RequestType = PKCS10"
401416
}
402417
Add-Content $certCfg "HashAlgorithm = $HashAlgorithm"
403-
Add-Content $certCfg "KeyUsage = 0xa0"
404-
Add-Content $certCfg "[EnhancedKeyUsageExtension]"
405-
Add-Content $certCfg "OID=1.3.6.1.5.5.7.3.1"
418+
if ($DocumentEncryptionCert) {
419+
Add-Content $certCfg "KeyUsage = 0x20"
420+
Add-Content $certCfg "[EnhancedKeyUsageExtension]"
421+
Add-Content $certCfg "OID=1.3.6.1.5.5.8.2.2"
422+
Add-Content $certCfg "OID=1.3.6.1.4.1.311.10.3.11"
423+
} else {
424+
Add-Content $certCfg "KeyUsage = 0xa0"
425+
Add-Content $certCfg "[EnhancedKeyUsageExtension]"
426+
Add-Content $certCfg "OID=1.3.6.1.5.5.7.3.1"
427+
}
406428
Add-Content $certCfg "[Extensions]"
407429
Add-Content $certCfg $san
408430
Add-Content $certCfg "Critical=2.5.29.17"

tests/New-DbaComputerCertificate.Tests.ps1

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Describe $CommandName -Tag UnitTests {
2525
"Flag",
2626
"Dns",
2727
"SelfSigned",
28+
"DocumentEncryptionCert",
2829
"EnableException",
2930
"HashAlgorithm",
3031
"MonthsValid"
@@ -80,5 +81,27 @@ if (-not $env:appveyor) {
8081
$customCert.NotAfter -match ((Get-Date).Date).AddMonths(60) | Should -BeTrue
8182
}
8283
}
84+
85+
Context "Can generate a document encryption certificate for Always Encrypted" {
86+
BeforeAll {
87+
$documentCert = New-DbaComputerCertificate -SelfSigned -DocumentEncryptionCert -EnableException
88+
}
89+
90+
AfterAll {
91+
Remove-DbaComputerCertificate -Thumbprint $documentCert.Thumbprint
92+
}
93+
94+
It "Returns the Document Encryption EKU OID" {
95+
"$($documentCert.EnhancedKeyUsageList)" -match "1\.3\.6\.1\.4\.1\.311\.10\.3\.11" | Should -BeTrue
96+
}
97+
98+
It "Returns the IKE Intermediate EKU OID" {
99+
"$($documentCert.EnhancedKeyUsageList)" -match "1\.3\.6\.1\.5\.5\.8\.2\.2" | Should -BeTrue
100+
}
101+
102+
It "Does not include the Server Authentication EKU OID" {
103+
"$($documentCert.EnhancedKeyUsageList)" -match "1\.3\.6\.1\.5\.5\.7\.3\.1" | Should -BeFalse
104+
}
105+
}
83106
}
84107
}

0 commit comments

Comments
 (0)