1 /*
2 * Copyright (c) 2020 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/ztest.h>
8 #include "manifest9_simple_decode.h"
9 #include "zcbor_print.h"
10
11
12 /* draft-ietf-suit-manifest-09 Example B.2 */
13 uint8_t test_vector2[] = {
14 0xa2, 0x02, 0x58, 0x92, 0x81, 0x58, 0x8f, 0xd2, 0x84, 0x43,
15 0xa1, 0x01, 0x26, 0xa0, 0x58, 0x44, 0x82, 0x02, 0x58, 0x40,
16 0x39, 0x38, 0x37, 0x65, 0x65, 0x63, 0x38, 0x35, 0x66, 0x61,
17 0x39, 0x39, 0x66, 0x64, 0x33, 0x31, 0x64, 0x33, 0x33, 0x32,
18 0x33, 0x38, 0x31, 0x62, 0x39, 0x38, 0x31, 0x30, 0x66, 0x39,
19 0x30, 0x62, 0x30, 0x35, 0x63, 0x32, 0x65, 0x30, 0x64, 0x34,
20 0x66, 0x32, 0x38, 0x34, 0x61, 0x36, 0x66, 0x34, 0x32, 0x31,
21 0x31, 0x32, 0x30, 0x37, 0x65, 0x64, 0x30, 0x30, 0x66, 0x66,
22 0x66, 0x37, 0x35, 0x30, 0x58, 0x40, 0x49, 0x31, 0xdf, 0x82,
23 0xe1, 0x53, 0xbf, 0x1e, 0x3a, 0xf5, 0xa5, 0x98, 0x00, 0x21,
24 0x6d, 0x8a, 0x47, 0xc3, 0x3a, 0x37, 0x83, 0x9e, 0x7d, 0x63,
25 0xd9, 0xf5, 0x26, 0xfd, 0x36, 0x9a, 0xa8, 0x35, 0x9d, 0xaa,
26 0xe1, 0x8f, 0x76, 0x19, 0xc9, 0x59, 0x12, 0x3e, 0x7f, 0x7f,
27 0x92, 0x8e, 0xe9, 0x2a, 0x98, 0x93, 0xaf, 0xed, 0xd3, 0x5d,
28 0x06, 0xa9, 0x36, 0xd6, 0xed, 0x3d, 0x58, 0x43, 0xbf, 0x2a,
29 0x03, 0x58, 0x94, 0xa5, 0x01, 0x01, 0x02, 0x01, 0x03, 0x58,
30 0x5f, 0xa2, 0x02, 0x81, 0x81, 0x41, 0x00, 0x04, 0x58, 0x56,
31 0x86, 0x14, 0xa4, 0x01, 0x50, 0xfa, 0x6b, 0x4a, 0x53, 0xd5,
32 0xad, 0x5f, 0xdf, 0xbe, 0x9d, 0xe6, 0x63, 0xe4, 0xd4, 0x1f,
33 0xfe, 0x02, 0x50, 0x14, 0x92, 0xaf, 0x14, 0x25, 0x69, 0x5e,
34 0x48, 0xbf, 0x42, 0x9b, 0x2d, 0x51, 0xf2, 0xab, 0x45, 0x03,
35 0x58, 0x24, 0x82, 0x02, 0x58, 0x20, 0x00, 0x11, 0x22, 0x33,
36 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd,
37 0xee, 0xff, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
38 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x0e, 0x19,
39 0x87, 0xd0, 0x01, 0x0f, 0x02, 0x0f, 0x09, 0x58, 0x25, 0x86,
40 0x13, 0xa1, 0x15, 0x78, 0x1b, 0x68, 0x74, 0x74, 0x70, 0x3a,
41 0x2f, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e,
42 0x63, 0x6f, 0x6d, 0x2f, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x62,
43 0x69, 0x6e, 0x15, 0x02, 0x03, 0x0f, 0x0a, 0x43, 0x82, 0x03,
44 0x0f
45 };
46
47 uint8_t test_vector5[] = {
48 0xa2, 0x02, 0x58, 0x92, 0x81, 0x58, 0x8f, 0xd2, 0x84, 0x43,
49 0xa1, 0x01, 0x26, 0xa0, 0x58, 0x44, 0x82, 0x02, 0x58, 0x40,
50 0x32, 0x31, 0x30, 0x62, 0x31, 0x32, 0x38, 0x35, 0x30, 0x63,
51 0x32, 0x33, 0x39, 0x30, 0x39, 0x31, 0x64, 0x38, 0x65, 0x38,
52 0x32, 0x63, 0x30, 0x65, 0x39, 0x65, 0x39, 0x31, 0x30, 0x36,
53 0x36, 0x32, 0x62, 0x36, 0x38, 0x61, 0x63, 0x38, 0x34, 0x32,
54 0x34, 0x35, 0x38, 0x61, 0x36, 0x34, 0x31, 0x38, 0x65, 0x33,
55 0x33, 0x66, 0x36, 0x37, 0x30, 0x31, 0x65, 0x64, 0x35, 0x38,
56 0x33, 0x34, 0x32, 0x63, 0x58, 0x40, 0xb5, 0xb8, 0xcb, 0x30,
57 0xc2, 0xbb, 0xb6, 0x46, 0xc4, 0xd3, 0x24, 0x26, 0xd7, 0x27,
58 0x68, 0x66, 0x8d, 0x6d, 0x6a, 0xf5, 0x4c, 0x26, 0xac, 0x46,
59 0xc4, 0x02, 0x0c, 0xa3, 0x7a, 0xda, 0x47, 0xb9, 0x46, 0x83,
60 0x40, 0xb4, 0xd0, 0xb2, 0xdd, 0xd1, 0x5d, 0xb8, 0x24, 0xa7,
61 0xe6, 0xb0, 0xbc, 0x23, 0x3e, 0x75, 0x39, 0x40, 0xdf, 0xb7,
62 0x13, 0x1f, 0xa1, 0x45, 0xdd, 0xc4, 0x56, 0xda, 0x3c, 0xf6,
63 0x03, 0x59, 0x01, 0x03, 0xa6, 0x01, 0x01, 0x02, 0x05, 0x03,
64 0x58, 0x95, 0xa2, 0x02, 0x82, 0x81, 0x41, 0x00, 0x81, 0x41,
65 0x01, 0x04, 0x58, 0x89, 0x8c, 0x0c, 0x00, 0x14, 0xa4, 0x01,
66 0x50, 0xfa, 0x6b, 0x4a, 0x53, 0xd5, 0xad, 0x5f, 0xdf, 0xbe,
67 0x9d, 0xe6, 0x63, 0xe4, 0xd4, 0x1f, 0xfe, 0x02, 0x50, 0x14,
68 0x92, 0xaf, 0x14, 0x25, 0x69, 0x5e, 0x48, 0xbf, 0x42, 0x9b,
69 0x2d, 0x51, 0xf2, 0xab, 0x45, 0x03, 0x58, 0x24, 0x82, 0x02,
70 0x58, 0x20, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
71 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x01, 0x23,
72 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98,
73 0x76, 0x54, 0x32, 0x10, 0x0e, 0x19, 0x87, 0xd0, 0x01, 0x0f,
74 0x02, 0x0f, 0x0c, 0x01, 0x14, 0xa2, 0x03, 0x58, 0x24, 0x82,
75 0x02, 0x58, 0x20, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd,
76 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x00,
77 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa,
78 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x0e, 0x1a, 0x00, 0x01, 0x2c,
79 0x22, 0x09, 0x58, 0x4f, 0x90, 0x0c, 0x00, 0x13, 0xa1, 0x15,
80 0x78, 0x1c, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x65,
81 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d,
82 0x2f, 0x66, 0x69, 0x6c, 0x65, 0x31, 0x2e, 0x62, 0x69, 0x6e,
83 0x15, 0x02, 0x03, 0x0f, 0x0c, 0x01, 0x13, 0xa1, 0x15, 0x78,
84 0x1c, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x65, 0x78,
85 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x2f,
86 0x66, 0x69, 0x6c, 0x65, 0x32, 0x2e, 0x62, 0x69, 0x6e, 0x15,
87 0x02, 0x03, 0x0f, 0x0a, 0x49, 0x88, 0x0c, 0x00, 0x03, 0x0f,
88 0x0c, 0x01, 0x03, 0x0f, 0x0c, 0x47, 0x86, 0x0c, 0x00, 0x17,
89 0x02, 0x17, 0x02
90 };
91
92 static struct SUIT_Envelope envelope1;
93 static struct SUIT_Manifest manifest;
94
ZTEST(cbor_decode_test7,test_suit9_simple2)95 ZTEST(cbor_decode_test7, test_suit9_simple2)
96 {
97 int res;
98
99 zcbor_log("test_vector at: 0x%zx\r\n", (size_t)test_vector2);
100 zcbor_log("test_vector end at: 0x%zx\r\n",
101 ((size_t)test_vector2) + sizeof(test_vector2));
102 memset(&envelope1, 0, sizeof(envelope1));
103 res = cbor_decode_SUIT_Envelope(test_vector2,
104 sizeof(test_vector2), &envelope1, NULL);
105 zassert_equal(ZCBOR_SUCCESS, res, "top-level decoding failed.");
106
107 res = cbor_decode_SUIT_Manifest(
108 envelope1.SUIT_Envelope_suit_manifest.value,
109 envelope1.SUIT_Envelope_suit_manifest.len, &manifest, NULL);
110
111 zassert_equal(ZCBOR_SUCCESS, res, "manifest decoding failed.");
112 }
113
114
ZTEST(cbor_decode_test7,test_suit9_simple5)115 ZTEST(cbor_decode_test7, test_suit9_simple5)
116 {
117 int res;
118
119 zcbor_log("test_vector at: 0x%zx\r\n", (size_t)test_vector5);
120 zcbor_log("test_vector end at: 0x%zx\r\n",
121 ((size_t)test_vector5) + sizeof(test_vector5));
122 memset(&envelope1, 0, sizeof(envelope1));
123 res = cbor_decode_SUIT_Envelope(test_vector5,
124 sizeof(test_vector5), &envelope1, NULL);
125 zassert_equal(ZCBOR_SUCCESS, res, "top-level decoding failed.");
126
127 res = cbor_decode_SUIT_Manifest(
128 envelope1.SUIT_Envelope_suit_manifest.value,
129 envelope1.SUIT_Envelope_suit_manifest.len, &manifest, NULL);
130
131 zassert_equal(ZCBOR_SUCCESS, res, "manifest decoding failed.");
132 }
133
134 ZTEST_SUITE(cbor_decode_test7, NULL, NULL, NULL, NULL, NULL);
135