Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 1 | # ----------------------------------------------------------------------------- |
Mate Toth-Pal | 6e1d774 | 2025-04-17 11:00:09 +0200 | [diff] [blame] | 2 | # Copyright (c) 2019-2025, Arm Limited. All rights reserved. |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | # ----------------------------------------------------------------------------- |
| 7 | |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 8 | """Unittests for iat-verifier using PSAIoTProfile1TokenVerifier""" |
| 9 | |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 10 | import os |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 11 | import unittest |
| 12 | |
Thomas Fossati | f4e1ca3 | 2024-08-16 16:01:31 +0000 | [diff] [blame] | 13 | from pycose.algorithms import Es256, Es384 |
| 14 | |
Mate Toth-Pal | 1cb66cd | 2022-04-26 15:40:07 +0200 | [diff] [blame] | 15 | from iatverifier.psa_iot_profile1_token_verifier import PSAIoTProfile1TokenVerifier |
Mate Toth-Pal | 5ebca51 | 2022-03-24 16:45:51 +0100 | [diff] [blame] | 16 | from iatverifier.cca_token_verifier import CCATokenVerifier, CCAPlatformTokenVerifier |
Mate Toth-Pal | b2508d5 | 2022-04-30 14:10:06 +0200 | [diff] [blame] | 17 | from iatverifier.util import read_keyfile |
Mate Toth-Pal | 5ebca51 | 2022-03-24 16:45:51 +0100 | [diff] [blame] | 18 | from iatverifier.attest_token_verifier import AttestationClaim, VerifierConfiguration |
| 19 | from iatverifier.attest_token_verifier import AttestationTokenVerifier |
Mate Toth-Pal | b2508d5 | 2022-04-30 14:10:06 +0200 | [diff] [blame] | 20 | from test_utils import create_and_read_iat, read_iat, create_token_tmp_file |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 21 | |
| 22 | |
| 23 | THIS_DIR = os.path.dirname(__file__) |
| 24 | |
| 25 | DATA_DIR = os.path.join(THIS_DIR, 'data') |
| 26 | KEYFILE = os.path.join(DATA_DIR, 'key.pem') |
Mate Toth-Pal | 5ebca51 | 2022-03-24 16:45:51 +0100 | [diff] [blame] | 27 | KEYFILE_CCA_PLAT = os.path.join(DATA_DIR, 'cca_platform.pem') |
| 28 | KEYFILE_CCA_REALM = os.path.join(DATA_DIR, 'cca_realm.pem') |
Mate Toth-Pal | b21ae52 | 2022-09-01 12:02:21 +0200 | [diff] [blame] | 29 | KEYFILE_CCA_REALM2= os.path.join(DATA_DIR, 'cca_realm2.pem') |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 30 | KEYFILE_ALT = os.path.join(DATA_DIR, 'key-alt.pem') |
| 31 | |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 32 | class TestIatVerifier(unittest.TestCase): |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 33 | """A class used for testing iat-verifier. |
| 34 | |
| 35 | This class uses the claim and token definitions for PSA Attestation Token""" |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 36 | |
| 37 | def setUp(self): |
| 38 | self.config = VerifierConfiguration() |
| 39 | |
| 40 | def test_validate_signature(self): |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 41 | """Testing Signature validation""" |
| 42 | method=AttestationTokenVerifier.SIGN_METHOD_SIGN1 |
Thomas Fossati | f4e1ca3 | 2024-08-16 16:01:31 +0000 | [diff] [blame] | 43 | cose_alg=Es256 |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 44 | |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 45 | signing_key = read_keyfile(KEYFILE, method) |
| 46 | verifier_good_sig = PSAIoTProfile1TokenVerifier( |
| 47 | method=method, |
| 48 | cose_alg=cose_alg, |
| 49 | signing_key=signing_key, |
| 50 | configuration=self.config) |
Mate Toth-Pal | b2508d5 | 2022-04-30 14:10:06 +0200 | [diff] [blame] | 51 | good_sig = create_token_tmp_file(DATA_DIR, 'valid-iat.yaml', verifier_good_sig) |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 52 | |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 53 | signing_key = read_keyfile(KEYFILE_ALT, method) |
| 54 | verifier_bad_sig = PSAIoTProfile1TokenVerifier( |
| 55 | method=method, |
| 56 | cose_alg=cose_alg, |
| 57 | signing_key=signing_key, |
| 58 | configuration=self.config) |
Mate Toth-Pal | b2508d5 | 2022-04-30 14:10:06 +0200 | [diff] [blame] | 59 | bad_sig = create_token_tmp_file(DATA_DIR, 'valid-iat.yaml', verifier_bad_sig) |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 60 | |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 61 | #dump_file_binary(good_sig) |
| 62 | |
| 63 | with open(good_sig, 'rb') as wfh: |
Mate Toth-Pal | c7404e9 | 2022-07-15 11:11:13 +0200 | [diff] [blame] | 64 | token_item = verifier_good_sig.parse_token( |
| 65 | token=wfh.read(), |
Mate Toth-Pal | c7404e9 | 2022-07-15 11:11:13 +0200 | [diff] [blame] | 66 | lower_case_key=False) |
| 67 | token_item.verify() |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 68 | |
| 69 | with self.assertRaises(ValueError) as test_ctx: |
| 70 | with open(bad_sig, 'rb') as wfh: |
Mate Toth-Pal | c7404e9 | 2022-07-15 11:11:13 +0200 | [diff] [blame] | 71 | token_item = verifier_good_sig.parse_token( |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 72 | token=wfh.read(), |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 73 | lower_case_key=False) |
Mate Toth-Pal | c7404e9 | 2022-07-15 11:11:13 +0200 | [diff] [blame] | 74 | token_item.verify() |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 75 | |
| 76 | self.assertIn('Bad signature', test_ctx.exception.args[0]) |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 77 | |
| 78 | def test_validate_iat_structure(self): |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 79 | """Testing IAT structure validation""" |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 80 | keep_going_conf = VerifierConfiguration(keep_going=True) |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 81 | method=AttestationTokenVerifier.SIGN_METHOD_SIGN1 |
Thomas Fossati | f4e1ca3 | 2024-08-16 16:01:31 +0000 | [diff] [blame] | 82 | cose_alg=Es256 |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 83 | signing_key = read_keyfile(KEYFILE, method) |
Mate Toth-Pal | 5ebca51 | 2022-03-24 16:45:51 +0100 | [diff] [blame] | 84 | realm_token_key = read_keyfile(KEYFILE_CCA_REALM, method) |
Mate Toth-Pal | b21ae52 | 2022-09-01 12:02:21 +0200 | [diff] [blame] | 85 | realm_token_key2 = read_keyfile(KEYFILE_CCA_REALM2, method) |
Mate Toth-Pal | 5ebca51 | 2022-03-24 16:45:51 +0100 | [diff] [blame] | 86 | platform_token_key = read_keyfile(KEYFILE_CCA_PLAT, method) |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 87 | |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 88 | create_and_read_iat( |
Mate Toth-Pal | b2508d5 | 2022-04-30 14:10:06 +0200 | [diff] [blame] | 89 | DATA_DIR, |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 90 | 'valid-iat.yaml', |
Mate Toth-Pal | 5ebca51 | 2022-03-24 16:45:51 +0100 | [diff] [blame] | 91 | PSAIoTProfile1TokenVerifier( |
| 92 | method=method, |
| 93 | cose_alg=cose_alg, |
| 94 | signing_key=signing_key, |
| 95 | configuration=self.config)) |
Mate Toth-Pal | b21ae52 | 2022-09-01 12:02:21 +0200 | [diff] [blame] | 96 | |
Mate Toth-Pal | 5ebca51 | 2022-03-24 16:45:51 +0100 | [diff] [blame] | 97 | create_and_read_iat( |
| 98 | DATA_DIR, |
| 99 | 'valid-cca-token.yaml', |
| 100 | CCATokenVerifier( |
| 101 | realm_token_method=method, |
Thomas Fossati | f4e1ca3 | 2024-08-16 16:01:31 +0000 | [diff] [blame] | 102 | realm_token_cose_alg=Es384, |
Mate Toth-Pal | 5ebca51 | 2022-03-24 16:45:51 +0100 | [diff] [blame] | 103 | realm_token_key=realm_token_key, |
| 104 | platform_token_method=method, |
Thomas Fossati | f4e1ca3 | 2024-08-16 16:01:31 +0000 | [diff] [blame] | 105 | platform_token_cose_alg=Es384, |
Mate Toth-Pal | 5ebca51 | 2022-03-24 16:45:51 +0100 | [diff] [blame] | 106 | platform_token_key=platform_token_key, |
| 107 | configuration=self.config)) |
| 108 | |
| 109 | create_and_read_iat( |
| 110 | DATA_DIR, |
| 111 | 'cca_platform_token.yaml', |
| 112 | CCAPlatformTokenVerifier( |
| 113 | method=method, |
Thomas Fossati | f4e1ca3 | 2024-08-16 16:01:31 +0000 | [diff] [blame] | 114 | cose_alg=Es384, |
Mate Toth-Pal | 5ebca51 | 2022-03-24 16:45:51 +0100 | [diff] [blame] | 115 | signing_key=platform_token_key, |
| 116 | configuration=self.config, |
Mate Toth-Pal | 6e1d774 | 2025-04-17 11:00:09 +0200 | [diff] [blame] | 117 | necessity=AttestationClaim.MANDATORY, |
| 118 | has_type_indicator=False)) |
| 119 | |
| 120 | create_and_read_iat( |
| 121 | DATA_DIR, |
| 122 | 'cca_platform_token.yaml', |
| 123 | CCAPlatformTokenVerifier( |
| 124 | method=method, |
| 125 | cose_alg=Es384, |
| 126 | signing_key=platform_token_key, |
| 127 | configuration=self.config, |
| 128 | necessity=AttestationClaim.MANDATORY, |
| 129 | has_type_indicator=True)) |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 130 | |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 131 | with self.assertRaises(ValueError) as test_ctx: |
| 132 | create_and_read_iat( |
Mate Toth-Pal | b21ae52 | 2022-09-01 12:02:21 +0200 | [diff] [blame] | 133 | DATA_DIR, |
Mate Toth-Pal | c5dbad0 | 2022-09-01 22:17:26 +0200 | [diff] [blame] | 134 | 'cca-invalid-plat-challenge.yaml', |
| 135 | CCATokenVerifier( |
| 136 | realm_token_method=method, |
Thomas Fossati | f4e1ca3 | 2024-08-16 16:01:31 +0000 | [diff] [blame] | 137 | realm_token_cose_alg=Es384, |
Mate Toth-Pal | c5dbad0 | 2022-09-01 22:17:26 +0200 | [diff] [blame] | 138 | realm_token_key=realm_token_key, |
| 139 | platform_token_method=method, |
Thomas Fossati | f4e1ca3 | 2024-08-16 16:01:31 +0000 | [diff] [blame] | 140 | platform_token_cose_alg=Es384, |
Mate Toth-Pal | c5dbad0 | 2022-09-01 22:17:26 +0200 | [diff] [blame] | 141 | platform_token_key=platform_token_key, |
| 142 | configuration=self.config)) |
| 143 | self.assertIn("Invalid CCA_PLATFORM_CHALLENGE byte at 16: 0x00 instead of 0xe4", test_ctx.exception.args[0]) |
| 144 | |
| 145 | with self.assertRaises(ValueError) as test_ctx: |
| 146 | create_and_read_iat( |
| 147 | DATA_DIR, |
Mate Toth-Pal | b21ae52 | 2022-09-01 12:02:21 +0200 | [diff] [blame] | 148 | 'valid-cca-token.yaml', |
| 149 | CCATokenVerifier( |
| 150 | realm_token_method=method, |
Thomas Fossati | f4e1ca3 | 2024-08-16 16:01:31 +0000 | [diff] [blame] | 151 | realm_token_cose_alg=Es384, |
Mate Toth-Pal | b21ae52 | 2022-09-01 12:02:21 +0200 | [diff] [blame] | 152 | realm_token_key=realm_token_key2, |
| 153 | platform_token_method=method, |
Thomas Fossati | f4e1ca3 | 2024-08-16 16:01:31 +0000 | [diff] [blame] | 154 | platform_token_cose_alg=Es384, |
Mate Toth-Pal | b21ae52 | 2022-09-01 12:02:21 +0200 | [diff] [blame] | 155 | platform_token_key=platform_token_key, |
| 156 | configuration=self.config)) |
| 157 | self.assertIn("Realm signature doesn't match Realm Public Key claim in Realm token", test_ctx.exception.args[0]) |
| 158 | |
| 159 | with self.assertRaises(ValueError) as test_ctx: |
| 160 | create_and_read_iat( |
Mate Toth-Pal | b2508d5 | 2022-04-30 14:10:06 +0200 | [diff] [blame] | 161 | DATA_DIR, |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 162 | 'invalid-profile-id.yaml', |
| 163 | PSAIoTProfile1TokenVerifier(method=method, |
| 164 | cose_alg=cose_alg, |
| 165 | signing_key=signing_key, |
| 166 | configuration=self.config)) |
| 167 | self.assertIn('Invalid PROFILE_ID', test_ctx.exception.args[0]) |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 168 | |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 169 | with self.assertRaises(ValueError) as test_ctx: |
| 170 | read_iat( |
Mate Toth-Pal | b2508d5 | 2022-04-30 14:10:06 +0200 | [diff] [blame] | 171 | DATA_DIR, |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 172 | 'malformed.cbor', |
| 173 | PSAIoTProfile1TokenVerifier(method=method, |
| 174 | cose_alg=cose_alg, |
| 175 | signing_key=signing_key, |
| 176 | configuration=self.config)) |
| 177 | self.assertIn('Bad COSE', test_ctx.exception.args[0]) |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 178 | |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 179 | with self.assertRaises(ValueError) as test_ctx: |
| 180 | create_and_read_iat( |
Mate Toth-Pal | b2508d5 | 2022-04-30 14:10:06 +0200 | [diff] [blame] | 181 | DATA_DIR, |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 182 | 'missing-claim.yaml', |
| 183 | PSAIoTProfile1TokenVerifier(method=method, |
| 184 | cose_alg=cose_alg, |
| 185 | signing_key=signing_key, |
| 186 | configuration=self.config)) |
| 187 | self.assertIn('missing MANDATORY claim', test_ctx.exception.args[0]) |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 188 | |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 189 | with self.assertRaises(ValueError) as test_ctx: |
| 190 | create_and_read_iat( |
Mate Toth-Pal | b2508d5 | 2022-04-30 14:10:06 +0200 | [diff] [blame] | 191 | DATA_DIR, |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 192 | 'submod-missing-claim.yaml', |
| 193 | PSAIoTProfile1TokenVerifier(method=method, |
| 194 | cose_alg=cose_alg, |
| 195 | signing_key=signing_key, |
| 196 | configuration=self.config)) |
| 197 | self.assertIn('missing MANDATORY claim', test_ctx.exception.args[0]) |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 198 | |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 199 | with self.assertRaises(ValueError) as test_ctx: |
| 200 | create_and_read_iat( |
Mate Toth-Pal | b2508d5 | 2022-04-30 14:10:06 +0200 | [diff] [blame] | 201 | DATA_DIR, |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 202 | 'missing-sw-comps.yaml', |
| 203 | PSAIoTProfile1TokenVerifier(method=method, |
| 204 | cose_alg=cose_alg, |
| 205 | signing_key=signing_key, |
| 206 | configuration=self.config)) |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 207 | self.assertIn('NO_MEASUREMENTS claim is not present', |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 208 | test_ctx.exception.args[0]) |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 209 | |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 210 | with self.assertLogs() as test_ctx: |
| 211 | create_and_read_iat( |
Mate Toth-Pal | b2508d5 | 2022-04-30 14:10:06 +0200 | [diff] [blame] | 212 | DATA_DIR, |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 213 | 'missing-signer-id.yaml', |
| 214 | PSAIoTProfile1TokenVerifier(method=method, |
| 215 | cose_alg=cose_alg, |
| 216 | signing_key=signing_key, |
| 217 | configuration=self.config)) |
Mate Toth-Pal | d10a914 | 2022-04-28 15:34:13 +0200 | [diff] [blame] | 218 | self.assertIn('Missing RECOMMENDED claim "SIGNER_ID" from SW_COMPONENTS', |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 219 | test_ctx.records[0].getMessage()) |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 220 | |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 221 | with self.assertLogs() as test_ctx: |
| 222 | create_and_read_iat( |
Mate Toth-Pal | b2508d5 | 2022-04-30 14:10:06 +0200 | [diff] [blame] | 223 | DATA_DIR, |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 224 | 'invalid-type-length.yaml', |
| 225 | PSAIoTProfile1TokenVerifier(method=method, |
| 226 | cose_alg=cose_alg, |
| 227 | signing_key=signing_key, |
| 228 | configuration=keep_going_conf)) |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 229 | self.assertIn("Invalid PROFILE_ID: must be a(n) <class 'str'>: found <class 'int'>", |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 230 | test_ctx.records[0].getMessage()) |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 231 | self.assertIn("Invalid SIGNER_ID: must be a(n) <class 'bytes'>: found <class 'str'>", |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 232 | test_ctx.records[1].getMessage()) |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 233 | self.assertIn("Invalid SIGNER_ID length: must be at least 32 bytes, found 12 bytes", |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 234 | test_ctx.records[2].getMessage()) |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 235 | self.assertIn("Invalid MEASUREMENT length: must be at least 32 bytes, found 28 bytes", |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 236 | test_ctx.records[3].getMessage()) |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 237 | |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 238 | with self.assertLogs() as test_ctx: |
| 239 | create_and_read_iat( |
Mate Toth-Pal | b2508d5 | 2022-04-30 14:10:06 +0200 | [diff] [blame] | 240 | DATA_DIR, |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 241 | 'invalid-hw-version.yaml', |
Tamas Ban | 8ac8d17 | 2022-07-04 13:01:08 +0200 | [diff] [blame] | 242 | PSAIoTProfile1TokenVerifier( |
| 243 | method=method, |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 244 | cose_alg=cose_alg, |
| 245 | signing_key=signing_key, |
| 246 | configuration=keep_going_conf)) |
Tamas Ban | 8ac8d17 | 2022-07-04 13:01:08 +0200 | [diff] [blame] | 247 | self.assertIn("Invalid HARDWARE_VERSION length; " |
| 248 | "must be 19 characters, found 10 characters", |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 249 | test_ctx.records[0].getMessage()) |
Tamas Ban | 8ac8d17 | 2022-07-04 13:01:08 +0200 | [diff] [blame] | 250 | self.assertIn("Invalid character at position 1", |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 251 | test_ctx.records[1].getMessage()) |
Tamas Ban | 8ac8d17 | 2022-07-04 13:01:08 +0200 | [diff] [blame] | 252 | self.assertIn("Invalid character - at position 4", |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 253 | test_ctx.records[2].getMessage()) |
Tamas Ban | 8ac8d17 | 2022-07-04 13:01:08 +0200 | [diff] [blame] | 254 | self.assertIn("Invalid character a at position 10", |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 255 | test_ctx.records[3].getMessage()) |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 256 | |
| 257 | def test_binary_string_decoding(self): |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 258 | """Test binary_string decoding""" |
| 259 | method=AttestationTokenVerifier.SIGN_METHOD_SIGN1 |
Thomas Fossati | f4e1ca3 | 2024-08-16 16:01:31 +0000 | [diff] [blame] | 260 | cose_alg=Es256 |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 261 | signing_key = read_keyfile(KEYFILE, method) |
| 262 | iat = create_and_read_iat( |
Mate Toth-Pal | b2508d5 | 2022-04-30 14:10:06 +0200 | [diff] [blame] | 263 | DATA_DIR, |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 264 | 'valid-iat.yaml', |
| 265 | PSAIoTProfile1TokenVerifier(method=method, |
| 266 | cose_alg=cose_alg, |
| 267 | signing_key=signing_key, |
Mate Toth-Pal | c7404e9 | 2022-07-15 11:11:13 +0200 | [diff] [blame] | 268 | configuration=self.config)).get_token_map() |
Mate Toth-Pal | 916a3de | 2024-05-03 09:34:41 +0200 | [diff] [blame] | 269 | self.assertEqual(iat['SECURITY_LIFECYCLE'], 'sl_secured_3000') |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 270 | |
| 271 | def test_security_lifecycle_decoding(self): |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 272 | """Test security lifecycle decoding""" |
| 273 | method=AttestationTokenVerifier.SIGN_METHOD_SIGN1 |
Thomas Fossati | f4e1ca3 | 2024-08-16 16:01:31 +0000 | [diff] [blame] | 274 | cose_alg=Es256 |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 275 | signing_key = read_keyfile(KEYFILE, method) |
| 276 | iat = create_and_read_iat( |
Mate Toth-Pal | b2508d5 | 2022-04-30 14:10:06 +0200 | [diff] [blame] | 277 | DATA_DIR, |
Mate Toth-Pal | b9057ff | 2022-04-29 16:03:21 +0200 | [diff] [blame] | 278 | 'valid-iat.yaml', |
| 279 | PSAIoTProfile1TokenVerifier(method=method, |
| 280 | cose_alg=cose_alg, |
| 281 | signing_key=signing_key, |
Mate Toth-Pal | c7404e9 | 2022-07-15 11:11:13 +0200 | [diff] [blame] | 282 | configuration=self.config)).get_token_map() |
Mate Toth-Pal | 916a3de | 2024-05-03 09:34:41 +0200 | [diff] [blame] | 283 | self.assertEqual(iat['SECURITY_LIFECYCLE'], 'sl_secured_3000') |
Thomas Fossati | 5ebf483 | 2024-08-26 09:30:05 +0000 | [diff] [blame] | 284 | |
| 285 | def test_profiles(self): |
| 286 | """ |
| 287 | Test that both legacy and new profiles are handled correctly. |
| 288 | In particular, ensure that the different RAK encodings are accommodated, |
| 289 | and that use of legacy profiles triggers a warning. |
| 290 | """ |
| 291 | method=AttestationTokenVerifier.SIGN_METHOD_SIGN1 |
| 292 | realm_token_key = read_keyfile(KEYFILE_CCA_REALM, method) |
| 293 | platform_token_key = read_keyfile(KEYFILE_CCA_PLAT, method) |
| 294 | |
| 295 | # change directory here to make !inc work |
| 296 | os.chdir(DATA_DIR) |
| 297 | |
| 298 | create_and_read_iat( |
| 299 | '.', |
| 300 | 'cca_example_token.yaml', |
| 301 | CCATokenVerifier( |
| 302 | realm_token_method=method, |
| 303 | realm_token_cose_alg=Es384, |
| 304 | realm_token_key=realm_token_key, |
| 305 | platform_token_method=method, |
| 306 | platform_token_cose_alg=Es384, |
| 307 | platform_token_key=platform_token_key, |
| 308 | configuration=self.config |
| 309 | ) |
| 310 | ) |
| 311 | |
| 312 | with self.assertLogs() as test_ctx: |
| 313 | create_and_read_iat( |
| 314 | '.', |
| 315 | 'cca_example_token_legacy.yaml', |
| 316 | CCATokenVerifier( |
| 317 | realm_token_method=method, |
| 318 | realm_token_cose_alg=Es384, |
| 319 | realm_token_key=realm_token_key, |
| 320 | platform_token_method=method, |
| 321 | platform_token_cose_alg=Es384, |
| 322 | platform_token_key=platform_token_key, |
| 323 | configuration=self.config |
| 324 | ) |
| 325 | ) |
| 326 | self.assertIn('legacy profile http://arm.com/CCA-SSD/1.0.0 is deprecated', |
| 327 | test_ctx.records[0].getMessage()) |