Loading...
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 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | # SPDX-License-Identifier: GPL-2.0+ # Copyright (c) 2019, Linaro Limited # Author: AKASHI Takahiro <takahiro.akashi@linaro.org> # # U-Boot UEFI: Variable Authentication Test """ This test verifies variable authentication """ import pytest @pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('efi_secure_boot') @pytest.mark.buildconfigspec('cmd_fat') @pytest.mark.buildconfigspec('cmd_nvedit_efi') @pytest.mark.slow @pytest.mark.restart class TestEfiAuthVar(object): def test_efi_var_auth1(self, ubman, efi_boot_env): """ Test Case 1 - Install signature database """ ubman.restart_uboot() disk_img = efi_boot_env with ubman.log.section('Test Case 1a'): # Test Case 1a, Initial secure state output = ubman.run_command_list([ 'host bind 0 %s' % disk_img, 'printenv -e -v SecureBoot']) assert '00000000: 00' in ''.join(output) output = ubman.run_command( 'printenv -e -v SetupMode') assert '00000000: 01' in output with ubman.log.section('Test Case 1b'): # Test Case 1b, PK without AUTHENTICATED_WRITE_ACCESS output = ubman.run_command_list([ 'fatload host 0:1 4000000 PK.auth', 'setenv -e -nv -bs -rt -i 4000000:$filesize PK']) assert 'Failed to set EFI variable' in ''.join(output) with ubman.log.section('Test Case 1c'): # Test Case 1c, install PK output = ubman.run_command_list([ 'fatload host 0:1 4000000 PK.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK', 'printenv -e -v PK']) assert 'PK:' in ''.join(output) output = ubman.run_command( 'printenv -e -v SecureBoot') assert '00000000: 01' in output output = ubman.run_command( 'printenv -e -v SetupMode') assert '00000000: 00' in output with ubman.log.section('Test Case 1d'): # Test Case 1d, db/dbx without KEK output = ubman.run_command_list([ 'fatload host 0:1 4000000 db.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db']) assert 'Failed to set EFI variable' in ''.join(output) output = ubman.run_command_list([ 'fatload host 0:1 4000000 db.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx']) assert 'Failed to set EFI variable' in ''.join(output) with ubman.log.section('Test Case 1e'): # Test Case 1e, install KEK output = ubman.run_command_list([ 'fatload host 0:1 4000000 KEK.auth', 'setenv -e -nv -bs -rt -i 4000000:$filesize KEK']) assert 'Failed to set EFI variable' in ''.join(output) output = ubman.run_command_list([ 'fatload host 0:1 4000000 KEK.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK', 'printenv -e -v KEK']) assert 'KEK:' in ''.join(output) output = ubman.run_command( 'printenv -e -v SecureBoot') assert '00000000: 01' in output with ubman.log.section('Test Case 1f'): # Test Case 1f, install db output = ubman.run_command_list([ 'fatload host 0:1 4000000 db.auth', 'setenv -e -nv -bs -rt -i 4000000:$filesize db']) assert 'Failed to set EFI variable' in ''.join(output) output = ubman.run_command_list([ 'fatload host 0:1 4000000 db.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', 'printenv -e -v -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) assert 'Failed to set EFI variable' not in ''.join(output) assert 'db:' in ''.join(output) output = ubman.run_command( 'printenv -e -v SecureBoot') assert '00000000: 01' in output with ubman.log.section('Test Case 1g'): # Test Case 1g, install dbx output = ubman.run_command_list([ 'fatload host 0:1 4000000 dbx.auth', 'setenv -e -nv -bs -rt -i 4000000:$filesize dbx']) assert 'Failed to set EFI variable' in ''.join(output) output = ubman.run_command_list([ 'fatload host 0:1 4000000 dbx.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx', 'printenv -e -v -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f dbx']) assert 'Failed to set EFI variable' not in ''.join(output) assert 'dbx:' in ''.join(output) output = ubman.run_command( 'printenv -e -v SecureBoot') assert '00000000: 01' in output def test_efi_var_auth2(self, ubman, efi_boot_env): """ Test Case 2 - Update database by overwriting """ ubman.restart_uboot() disk_img = efi_boot_env with ubman.log.section('Test Case 2a'): # Test Case 2a, update without AUTHENTICATED_WRITE_ACCESS output = ubman.run_command_list([ 'host bind 0 %s' % disk_img, 'fatload host 0:1 4000000 PK.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK', 'fatload host 0:1 4000000 KEK.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK', 'fatload host 0:1 4000000 db.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', 'printenv -e -v -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) assert 'Failed to set EFI variable' not in ''.join(output) assert 'db:' in ''.join(output) output = ubman.run_command_list([ 'fatload host 0:1 4000000 db1.auth', 'setenv -e -nv -bs -rt -i 4000000:$filesize db']) assert 'Failed to set EFI variable' in ''.join(output) with ubman.log.section('Test Case 2b'): # Test Case 2b, update without correct signature output = ubman.run_command_list([ 'fatload host 0:1 4000000 db.esl', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db']) assert 'Failed to set EFI variable' in ''.join(output) with ubman.log.section('Test Case 2c'): # Test Case 2c, update with correct signature output = ubman.run_command_list([ 'fatload host 0:1 4000000 db1.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', 'printenv -e -v -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) assert 'Failed to set EFI variable' not in ''.join(output) assert 'db:' in ''.join(output) def test_efi_var_auth3(self, ubman, efi_boot_env): """ Test Case 3 - Append database """ ubman.restart_uboot() disk_img = efi_boot_env with ubman.log.section('Test Case 3a'): # Test Case 3a, update without AUTHENTICATED_WRITE_ACCESS output = ubman.run_command_list([ 'host bind 0 %s' % disk_img, 'fatload host 0:1 4000000 PK.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK', 'fatload host 0:1 4000000 KEK.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK', 'fatload host 0:1 4000000 db.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', 'printenv -e -v -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) assert 'Failed to set EFI variable' not in ''.join(output) assert 'db:' in ''.join(output) output = ubman.run_command_list([ 'fatload host 0:1 4000000 db2.auth', 'setenv -e -nv -bs -rt -a -i 4000000:$filesize db']) assert 'Failed to set EFI variable' in ''.join(output) with ubman.log.section('Test Case 3b'): # Test Case 3b, update without correct signature output = ubman.run_command_list([ 'fatload host 0:1 4000000 db.esl', 'setenv -e -nv -bs -rt -at -a -i 4000000:$filesize db']) assert 'Failed to set EFI variable' in ''.join(output) with ubman.log.section('Test Case 3c'): # Test Case 3c, update with correct signature output = ubman.run_command_list([ 'fatload host 0:1 4000000 db2.auth', 'setenv -e -nv -bs -rt -at -a -i 4000000:$filesize db', 'printenv -e -v -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) assert 'Failed to set EFI variable' not in ''.join(output) assert 'db:' in ''.join(output) def test_efi_var_auth4(self, ubman, efi_boot_env): """ Test Case 4 - Delete database without authentication """ ubman.restart_uboot() disk_img = efi_boot_env with ubman.log.section('Test Case 4a'): # Test Case 4a, update without AUTHENTICATED_WRITE_ACCESS output = ubman.run_command_list([ 'host bind 0 %s' % disk_img, 'fatload host 0:1 4000000 PK.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK', 'fatload host 0:1 4000000 KEK.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK', 'fatload host 0:1 4000000 db.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', 'printenv -e -v -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) assert 'Failed to set EFI variable' not in ''.join(output) assert 'db:' in ''.join(output) output = ubman.run_command_list([ 'setenv -e -nv -bs -rt db', 'printenv -e -v -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) assert 'Failed to set EFI variable' in ''.join(output) assert 'db:' in ''.join(output) with ubman.log.section('Test Case 4b'): # Test Case 4b, update without correct signature/data output = ubman.run_command_list([ 'setenv -e -nv -bs -rt -at db', 'printenv -e -v -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) assert 'Failed to set EFI variable' in ''.join(output) assert 'db:' in ''.join(output) def test_efi_var_auth5(self, ubman, efi_boot_env): """ Test Case 5 - Uninstall(delete) PK """ ubman.restart_uboot() disk_img = efi_boot_env with ubman.log.section('Test Case 5a'): # Test Case 5a, Uninstall PK without correct signature output = ubman.run_command_list([ 'host bind 0 %s' % disk_img, 'fatload host 0:1 4000000 PK.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK', 'fatload host 0:1 4000000 KEK.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK', 'fatload host 0:1 4000000 db.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', 'printenv -e -v PK']) assert 'Failed to set EFI variable' not in ''.join(output) assert 'PK:' in ''.join(output) output = ubman.run_command_list([ 'fatload host 0:1 4000000 PK_null.esl', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK', 'printenv -e -v PK']) assert 'Failed to set EFI variable' in ''.join(output) assert 'PK:' in ''.join(output) with ubman.log.section('Test Case 5b'): # Test Case 5b, Uninstall PK with correct signature output = ubman.run_command_list([ 'fatload host 0:1 4000000 PK_null.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK', 'printenv -e -v PK']) assert 'Failed to set EFI variable' not in ''.join(output) assert '\"PK\" not defined' in ''.join(output) output = ubman.run_command( 'printenv -e -v SecureBoot') assert '00000000: 00' in output output = ubman.run_command( 'printenv -e -v SetupMode') assert '00000000: 01' in output |