You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This script is designed to create a TPM Attestation Identity Key (AIK) and retrieve an AIK certificate for use with the Microsoft Azure Attestation service.
4
-
.NOTES
5
-
This script must be run from an Admin window.
6
-
.PARAMETERKeyName
7
-
Name of the key to be created.
8
-
.PARAMETERAclIdentity
9
-
Changes the ACL on the key so it can be read by the user/group specified by this parameter. This can be used to configure the account under which the MAA client executes so it does not have to be run with elevated permissions.
10
-
The script can also be used to configure the ACL on a previously created key.
11
-
.EXAMPLE
12
-
EnrollAik.ps1 MyOrgAik
13
-
=> Creates an AIK called "MyOrgAik" and enrolls it with Azure Certificate Services to get an associated AIK certificate.
14
-
.EXAMPLE
15
-
EnrollAik.ps1 MyOrgAik -AclIdentity TestAccount
16
-
=> Creates an AIK called "MyOrgAIK" and enrolls it with Azure Certificate Services to get an associated AIK certificate.
17
-
Additionally, grants read permission on the key to "TestAccount".
Write-Debug"Create AIK and request cert: $cmdLine"
52
-
$reqOutput=Invoke-Expression-Command $cmdLine
53
-
54
-
# If the key has been previously created certreq will return NTE_EXISTS. By allowing this or S_OK, the script can also ACL keys that have been previously created.
55
-
$NTE_KEY_EXISTS=-2146893809
56
-
if ($LASTEXITCODE-eq0-or$LASTEXITCODE-eq$NTE_KEY_EXISTS) {
57
-
PrettyPrintCapturedOutput $reqOutput
58
-
Write-Host"Key is available."-ForegroundColor Green
59
-
60
-
if ($AclIdentity) {
61
-
Write-Host"Granting read access to $AclIdentity..."-ForegroundColor Green
62
-
63
-
# Retrieve the disk location for the key
64
-
$cmdLine="certutil.exe -CSP TPM -key $KeyName"
65
-
Write-Debug"Find key location: $cmdLine"
66
-
$utilOutput=Invoke-Expression-Command $cmdLine
67
-
PrettyPrintCapturedOutput $utilOutput
68
-
69
-
if ($LASTEXITCODE-eq0) {
70
-
$keyPath=$utilOutput[2].trim()
71
-
if (-not($keyPath-like"$($env:ProgramData)\Microsoft\Crypto\PCPKSP\*")) {
72
-
Write-Error"The format of CertUtil output doesn't match the expected value and might have changed."
73
-
Write-Error"Please adjust the script accordingly to ensure the proper file is ACL'd correctly for read access."
# Apply new rule to object (setting same ACL multiple times has no effect, so no need to check if rule is already set)
87
-
$acl.SetAccessRule($fileSystemAccessRule)
88
-
Set-Acl-Path $keyPath-AclObject $acl
89
-
90
-
$acl=Get-Acl-path $keyPath
91
-
Write-Debug ($acl.Access|Format-List|out-string)
92
-
Write-Host"Key is accessible by $AclIdentity now."-ForegroundColor Green
93
-
}
94
-
else {
95
-
Write-Error"Unexpected return from certutil ($($LASTEXITCODE)) when searching for $KeyName. The key has *not* been ACL'd."
96
-
PrettyPrintCapturedOutput $utilOutput-isError
97
-
}
98
-
}
99
-
}
100
-
else {
101
-
# CertReq failed, print output to user
102
-
PrettyPrintCapturedOutput $reqOutput-isError
1
+
<#
2
+
.DESCRIPTION
3
+
This script is designed to create a TPM Attestation Identity Key (AIK) and retrieve an AIK certificate for use with the Microsoft Azure Attestation service.
4
+
.NOTES
5
+
This script must be run from an Admin window.
6
+
.PARAMETERKeyName
7
+
Name of the key to be created.
8
+
.PARAMETERAclIdentity
9
+
Changes the ACL on the key so it can be read by the user/group specified by this parameter. This can be used to configure the account under which the MAA client executes so it does not have to be run with elevated permissions.
10
+
The script can also be used to configure the ACL on a previously created key.
11
+
.PARAMETERAclIdentitySid
12
+
Changes the ACL on the key so it can be read by the SID specified by this parameter. This can be used to configure the account under which the MAA client executes so it does not have to be run with elevated permissions.
13
+
The script can also be used to configure the ACL on a previously created key.
14
+
.EXAMPLE
15
+
EnrollAik.ps1 MyOrgAik
16
+
=> Creates an AIK called "MyOrgAik" and enrolls it with Azure Certificate Services to get an associated AIK certificate.
17
+
.EXAMPLE
18
+
EnrollAik.ps1 MyOrgAik -AclIdentity TestAccount
19
+
=> Creates an AIK called "MyOrgAIK" and enrolls it with Azure Certificate Services to get an associated AIK certificate.
20
+
Additionally, grants read permission on the key to "TestAccount".
Write-Debug"Create AIK and request cert: $cmdLine"
61
+
$reqOutput=Invoke-Expression-Command $cmdLine
62
+
63
+
# If the key has been previously created certreq will return NTE_EXISTS. By allowing this or S_OK, the script can also ACL keys that have been previously created.
64
+
$NTE_KEY_EXISTS=-2146893809
65
+
if ($LASTEXITCODE-eq0-or$LASTEXITCODE-eq$NTE_KEY_EXISTS) {
66
+
PrettyPrintCapturedOutput $reqOutput
67
+
Write-Host"Key is available."-ForegroundColor Green
Copy file name to clipboardExpand all lines: README.md
+4-1Lines changed: 4 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,10 @@ This sample creates a TPM key named "att_sample_key" which is attested by Micros
26
26
27
27
* An AIK named "att_sample_aik" must be available. Run the EnrollAik.ps1 script to create the key and retrieve an AIK certificate for it (notice that the command below allows the key to be accessed by all users on the machine):
[^1]: Some Windows built-in security group names may be localized. EnrollAik.ps1 also accepts a SID to grant permissions to a key: `EnrollAik.ps1 att_sample_aik -AclIdentitySid S-1-5-32-545` (allows the key to be accessed by all users on the machine). More information about Windows security groups can be found [here](https://learn.microsoft.com/en-us/windows-server/identity/ad-ds/manage/understand-security-groups). Well-known SIDs are listed [here](https://learn.microsoft.com/en-us/windows/win32/secauthz/well-known-sids).
0 commit comments