-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateamipk.ps1
238 lines (214 loc) · 11.4 KB
/
updateamipk.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
param (
[Parameter()]
[switch]$confirm
)
[byte[]] $windowsoempk =
0xbb,0x90,0x87,0xd5,0x3e,0x70,0x27,0x57,0xe6,0xf5,0xbc,0xce,0x7e,0xd9,0xca,0x76,
0xac,0x47,0xab,0xd5,0xe6,0x0e,0x03,0x96,0xbd,0x38,0x01,0x63,0x39,0x84,0x96,0x23,
0x8f,0xb0,0x93,0x5f,0x7b,0x11,0x53,0x65,0xe2,0xb2,0x68,0x07,0x17,0xb1,0x07,0x28,
0x1c,0x0a,0xa9,0x5d,0x43,0x16,0x60,0x5f,0x46,0xbf,0xe0,0x9c,0x39,0x46,0xcd,0xe1,
0xde,0x7a,0x69,0xb5,0xa9,0x6d,0xd1,0x58,0x81,0x8d,0x80,0x43,0x20,0x25,0x6b,0xa4,
0x73,0x6e,0x07,0xcc,0x1f,0x5c,0x0d,0x21,0xd0,0xbe,0x49,0xb9,0x3b,0xd7,0x9d,0xc4,
0x3b,0x77,0x6f,0xd7,0x80,0xfe,0xbf,0xce,0x75,0xf0,0xe6,0x27,0x7c,0x01,0x5a,0xef,
0xf9,0x75,0x20,0xbe,0x36,0x4b,0xca,0xd9,0x27,0x69,0x81,0x0e,0x05,0xec,0x69,0xa4,
0x6f,0x39,0xf9,0x75,0x1f,0x0e,0x8b,0xf4,0xf1,0x94,0x41,0x28,0xfa,0x68,0xbe,0x8b,
0x32,0xe2,0x85,0xb7,0xe5,0xb7,0xc4,0xc5,0xf3,0xdb,0x47,0xa4,0xa4,0xb4,0xf9,0x78,
0x24,0xf9,0xfe,0xed,0x74,0x9c,0x15,0xd8,0x61,0xeb,0xec,0xff,0xdc,0x74,0xb4,0x93,
0x9f,0xb5,0x0a,0xbf,0x3e,0x74,0xed,0x13,0x1b,0x39,0x8d,0xdb,0x38,0x7d,0x27,0x9f,
0xfd,0x51,0xfb,0x24,0xda,0x92,0x4c,0x3b,0x66,0x1f,0xa3,0x7f,0xa0,0xc6,0xee,0xba,
0x0c,0x17,0xf1,0x90,0x8f,0x39,0x4a,0x94,0x4c,0x26,0x03,0x6a,0xd3,0x8a,0x27,0xe6,
0x3b,0x42,0x3f,0x27,0x08,0xe8,0xbf,0xbb,0x9c,0xf2,0xff,0xec,0x06,0x09,0xd8,0xd2,
0x59,0x49,0x98,0xe7,0x50,0x45,0x39,0x90,0xb1,0x34,0x7b,0xcb,0x66,0x6c,0x5a,0xc1
[byte[]] $amitestpk00 =
0xE7,0x36,0x7B,0x20,0x92,0xBA,0x7F,0xAA,0xA3,0xF6,0x0E,0x49,0x08,0x87,0xF5,0x1C,
0x11,0x33,0xBA,0x5D,0xF8,0x9B,0x5C,0xED,0xC7,0x90,0xE4,0xF3,0x41,0x02,0x06,0x41,
0xF9,0x17,0x1E,0x52,0xAA,0x99,0x1A,0xB4,0x8A,0x5A,0x56,0xEE,0x5B,0xEF,0x77,0x59,
0x07,0x10,0x6E,0x91,0x6F,0xF7,0x91,0x61,0x4D,0xFA,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f,
0x4d,0x0d,0x37,0x47,0xad,0xa9,0x92,0x7a,0x14,0xe5,0x62,0xd1,0x22,0x7d,0xaf,0x03,
0x25,0x6d,0xb0,0x64,0xe6,0xcf,0xf6,0x5e,0x88,0xf6,0xae,0xf5,0x07,0x84,0x82,0x9f,
0x4c,0x0d,0x57,0x2f,0x55,0xf7,0x79,0x30,0x54,0x61,0x69,0xef,0x8c,0x93,0x8f,0xee,
0xe4,0x74,0xe6,0x29,0xc2,0x2c,0x1a,0xef,0x19,0x78,0x42,0xd7,0xf0,0xdd,0x13,0x35,
0x3a,0xf1,0x65,0xbb,0xfc,0x11,0xa4,0x7e,0x74,0x3f,0x12,0xff,0xdc,0xbf,0xbd,0xe8,
0x1f,0x1a,0xb4,0xa3,0x90,0x74,0xcf,0x20,0x92,0xeb,0x39,0x63,0xb5,0xb0,0xa3,0xe9
$amitestpk00path = ".\AmiTestPk00.p7"
$amitestpk01path = ".\AmiTestPk01.p7"
$amitestpk02path = ".\AmiTestPk02.p7"
$amitestpk03path = ".\AmiTestPk03.p7"
$KnownAmiTestPK = @(
@($amitestpk00, $amitestpk00path),
@($amitestpk01, $amitestpk01path),
@($amitestpk02, $amitestpk02path),
@($amitestpk03, $amitestpk03path)
)
$global:AmiTestPkPath = $null
function Verify-WindowsOemPk
{
$pkinbyte = (Get-SecureBootUEFI -Name pk).Bytes
$pkinhexstring = ($pkinbyte | ForEach-Object ToString X2) -join ''
$windowsoempkstring = ($windowsoempk | ForEach-Object ToString X2) -join ''
if ($pkinhexstring -Match $windowsoempkstring)
{
return $true
}
return $false
}
function Verify-AmiTestPk
{
$pkinbyte = (Get-SecureBootUEFI -Name pk).Bytes
$pkinhexstring = ($pkinbyte | ForEach-Object ToString X2) -join ''
foreach($key in $KnownAmiTestPK)
{
$amitestpkstring = ($key[0] | ForEach-Object ToString X2) -join ''
if ($pkinhexstring -Match $amitestpkstring)
{
$global:AmiTestPkPath = $key[1]
return $true
}
}
return $false
}
if ($confirm)
{
if (Verify-AmiTestPk)
{
Write-Output "[INFO] AMI Test key found in PK. AMI PK update is needed."
}
if (Verify-WindowsOemPk)
{
Write-Output "[INFO] Windows OEM PK already exists in PK."
}
else
{
Write-Output "[INFO] Windows OEM PK not found in PK."
}
Write-Output "[INFO] Exiting: 0"
exit 0
}
Write-Output "[INFO] Verifying if AMI Test cert is in PK..."
if (!(Verify-AmiTestPk) -or ($global:AmiTestPkPath -eq $null))
{
Write-Output "[INFO] AMI Test key not found in PK. No need for update."
Write-Output "[INFO] Exiting: 0"
exit 0
}
Write-Output "[INFO] Verified AMI Test cert in PK."
$content = ".\Ami-windowspk_content.bin"
$signature = $global:AmiTestPkPath
Write-Output "[INFO] Verifying required files present under the directory..."
if (!(Test-Path -Path $content) -or !(Test-Path -Path $signature))
{
Write-Output "[ERROR] Required files not found under the current path."
Write-Output "[ERROR] Exiting: 1"
exit 1
}
Write-Output "[INFO] Verified."
Write-Output "[INFO] Checking Bitlocker status..."
$operatingsystemvolume = Get-BitlockerVolume | where {$_.VolumeType -eq "OperatingSystem" -and $_.ProtectionStatus -eq "On"}
$bitlockersuspended = $null
if ($operatingsystemvolume)
{
Write-Output "[INFO] Bitlocker is enabled on OS volume. Temporarily suspending until next boot."
$mountpoint = $operatingsystemvolume.MountPoint
Suspend-Bitlocker -MountPoint $mountpoint -RebootCount 1
if(Get-BitlockerVolume | where {$_.VolumeType -eq "OperatingSystem" -and $_.ProtectionStatus -eq "On"})
{
Write-Output "[INFO] Second attempt..."
$DebugPreference = "Continue"
Suspend-Bitlocker -MountPoint $mountpoint -RebootCount 1
$DebugPreference = "SilentlyContinue"
if(Get-BitlockerVolume | where {$_.VolumeType -eq "OperatingSystem" -and $_.ProtectionStatus -eq "On"})
{
Write-Output "[ERROR] Failed suspending Bitlocker."
Write-Output "[ERROR] Exiting: 1"
exit 1
}
}
Write-Output "[INFO] Bitlocker is suspended on Operating System volume."
$bitlockersuspended = $mountpoint
}
else
{
Write-Output "[INFO] Bitlocker is not enabled on Operating System volume."
}
Write-Output "[INFO] Attempting set PK..."
$uefivar = Set-SecureBootUefi -Name PK -ContentFilePath $content -SignedFilePath $signature -Time 2024-12-31T23:56:59Z
if ($uefivar)
{
Write-Output "[INFO] Set PK command completed. Reboot is required for PK update to take effect."
Write-Output "[INFO] Now force restarting computer..."
Restart-Computer -force
}
else{
Write-Output "[ERROR] Failed setting PK variable."
if ($bitlockersuspended -ne $null)
{
Write-Output "[INFO] Bitlocker was previously suspended. Resuming Bitlocker protection..."
Resume-Bitlocker -Mountpoint $bitlockersuspended
if(Get-BitlockerVolume | where {$_.VolumeType -eq "OperatingSystem" -and $_.ProtectionStatus -eq "On"})
{
Write-Output "[INFO] Success."
Write-Output "[INFO] Exiting: 0"
exit 0
}
Write-Output "[ERROR] Failed resuming Bitlocker. Please resume Bitlocker manually from Bitlocker Drive Encryption setting page."
}
Write-Output "[ERROR] Exiting: 1"
exit 1
}