1 /*
2 * lws-api-test-jose - RFC8152 cose_key tests
3 *
4 * Written in 2010-2021 by Andy Green <andy@warmcat.com>
5 *
6 * This file is made available under the Creative Commons CC0 1.0
7 * Universal Public Domain Dedication.
8 *
9 * Raw key CBOR created from descriptions at
10 *
11 * https://github.com/cose-wg/Examples/blob/master/KeySet.txt
12 */
13
14 #include <libwebsockets.h>
15 #include <stdlib.h>
16 #include <fcntl.h>
17
18 static int
key_import_cb(struct lws_cose_key * s,void * user)19 key_import_cb(struct lws_cose_key *s, void *user)
20 {
21 lwsl_notice("%s: key type %lld\n", __func__, (long long)s->kty);
22
23 return 0;
24 }
25
26 static const uint8_t
27 cose_key1[] = {
28 0xa6, 0x01, 0x02, 0x02, 0x62,
29 0x31, 0x31, 0x20, 0x01, 0x21,
30 0x58, 0x20, 0xba, 0xc5, 0xb1,
31 0x1c, 0xad, 0x8f, 0x99, 0xf9,
32 0xc7, 0x2b, 0x05, 0xcf, 0x4b,
33 0x9e, 0x26, 0xd2, 0x44, 0xdc,
34 0x18, 0x9f, 0x74, 0x52, 0x28,
35 0x25, 0x5a, 0x21, 0x9a, 0x86,
36 0xd6, 0xa0, 0x9e, 0xff, 0x22,
37 0x58, 0x20, 0x20, 0x13, 0x8b,
38 0xf8, 0x2d, 0xc1, 0xb6, 0xd5,
39 0x62, 0xbe, 0x0f, 0xa5, 0x4a,
40 0xb7, 0x80, 0x4a, 0x3a, 0x64,
41 0xb6, 0xd7, 0x2c, 0xcf, 0xed,
42 0x6b, 0x6f, 0xb6, 0xed, 0x28,
43 0xbb, 0xfc, 0x11, 0x7e, 0x23,
44 0x58, 0x20, 0x57, 0xc9, 0x20,
45 0x77, 0x66, 0x41, 0x46, 0xe8,
46 0x76, 0x76, 0x0c, 0x95, 0x20,
47 0xd0, 0x54, 0xaa, 0x93, 0xc3,
48 0xaf, 0xb0, 0x4e, 0x30, 0x67,
49 0x05, 0xdb, 0x60, 0x90, 0x30,
50 0x85, 0x07, 0xb4, 0xd3 },
51 cose_key2[] = {
52 0xa6, 0x01, 0x02, 0x02, 0x78,
53 0x24, 0x6d, 0x65, 0x72, 0x69,
54 0x61, 0x64, 0x6f, 0x63, 0x2e,
55 0x62, 0x72, 0x61, 0x6e, 0x64,
56 0x79, 0x62, 0x75, 0x63, 0x6b,
57 0x40, 0x62, 0x75, 0x63, 0x6b,
58 0x6c, 0x61, 0x6e, 0x64, 0x2e,
59 0x65, 0x78, 0x61, 0x6d, 0x70,
60 0x6c, 0x65, 0x20, 0x01, 0x21,
61 0x58, 0x20, 0x65, 0xed, 0xa5,
62 0xa1, 0x25, 0x77, 0xc2, 0xba,
63 0xe8, 0x29, 0x43, 0x7f, 0xe3,
64 0x38, 0x70, 0x1a, 0x10, 0xaa,
65 0xa3, 0x75, 0xe1, 0xbb, 0x5b,
66 0x5d, 0xe1, 0x08, 0xde, 0x43,
67 0x9c, 0x08, 0x55, 0x1d, 0x22,
68 0x58, 0x20, 0x1e, 0x52, 0xed,
69 0x75, 0x70, 0x11, 0x63, 0xf7,
70 0xf9, 0xe4, 0x0d, 0xdf, 0x9f,
71 0x34, 0x1b, 0x3d, 0xc9, 0xba,
72 0x86, 0x0a, 0xf7, 0xe0, 0xca,
73 0x7c, 0xa7, 0xe9, 0xee, 0xcd,
74 0x00, 0x84, 0xd1, 0x9c, 0x23,
75 0x58, 0x20, 0xaf, 0xf9, 0x07,
76 0xc9, 0x9f, 0x9a, 0xd3, 0xaa,
77 0xe6, 0xc4, 0xcd, 0xf2, 0x11,
78 0x22, 0xbc, 0xe2, 0xbd, 0x68,
79 0xb5, 0x28, 0x3e, 0x69, 0x07,
80 0x15, 0x4a, 0xd9, 0x11, 0x84,
81 0x0f, 0xa2, 0x08, 0xcf },
82
83 cose_key3[] = { 0xa3, 0x01, 0x04, 0x02, 0x6a,
84 0x6f, 0x75, 0x72, 0x2d, 0x73,
85 0x65, 0x63, 0x72, 0x65, 0x74,
86 0x20, 0x58, 0x20, 0x84, 0x9b,
87 0x57, 0x21, 0x9d, 0xae, 0x48,
88 0xde, 0x64, 0x6d, 0x07, 0xdb,
89 0xb5, 0x33, 0x56, 0x6e, 0x97,
90 0x66, 0x86, 0x45, 0x7c, 0x14,
91 0x91, 0xbe, 0x3a, 0x76, 0xdc,
92 0xea, 0x6c, 0x42, 0x71, 0x88 },
93
94 cose_key4[] = { 0xa6, 0x01, 0x02, 0x02, 0x78,
95 0x1e, 0x62, 0x69, 0x6c, 0x62,
96 0x6f, 0x2e, 0x62, 0x61, 0x67,
97 0x67, 0x69, 0x6e, 0x73, 0x40,
98 0x68, 0x6f, 0x62, 0x62, 0x69,
99 0x74, 0x6f, 0x6e, 0x2e, 0x65,
100 0x78, 0x61, 0x6d, 0x70, 0x6c,
101 0x65, 0x20, 0x03, 0x21, 0x58,
102 0x42, 0x00, 0x72, 0x99, 0x2c,
103 0xb3, 0xac, 0x08, 0xec, 0xf3,
104 0xe5, 0xc6, 0x3d, 0xed, 0xec,
105 0x0d, 0x51, 0xa8, 0xc1, 0xf7,
106 0x9e, 0xf2, 0xf8, 0x2f, 0x94,
107 0xf3, 0xc7, 0x37, 0xbf, 0x5d,
108 0xe7, 0x98, 0x66, 0x71, 0xea,
109 0xc6, 0x25, 0xfe, 0x82, 0x57,
110 0xbb, 0xd0, 0x39, 0x46, 0x44,
111 0xca, 0xaa, 0x3a, 0xaf, 0x8f,
112 0x27, 0xa4, 0x58, 0x5f, 0xbb,
113 0xca, 0xd0, 0xf2, 0x45, 0x76,
114 0x20, 0x08, 0x5e, 0x5c, 0x8f,
115 0x42, 0xad, 0x22, 0x58, 0x42,
116 0x01, 0xdc, 0xa6, 0x94, 0x7b,
117 0xce, 0x88, 0xbc, 0x57, 0x90,
118 0x48, 0x5a, 0xc9, 0x74, 0x27,
119 0x34, 0x2b, 0xc3, 0x5f, 0x88,
120 0x7d, 0x86, 0xd6, 0x5a, 0x08,
121 0x93, 0x77, 0xe2, 0x47, 0xe6,
122 0x0b, 0xaa, 0x55, 0xe4, 0xe8,
123 0x50, 0x1e, 0x2a, 0xda, 0x57,
124 0x24, 0xac, 0x51, 0xd6, 0x90,
125 0x90, 0x08, 0x03, 0x3e, 0xbc,
126 0x10, 0xac, 0x99, 0x9b, 0x9d,
127 0x7f, 0x5c, 0xc2, 0x51, 0x9f,
128 0x3f, 0xe1, 0xea, 0x1d, 0x94,
129 0x75, 0x23, 0x58, 0x42, 0x00,
130 0x08, 0x51, 0x38, 0xdd, 0xab,
131 0xf5, 0xca, 0x97, 0x5f, 0x58,
132 0x60, 0xf9, 0x1a, 0x08, 0xe9,
133 0x1d, 0x6d, 0x5f, 0x9a, 0x76,
134 0xad, 0x40, 0x18, 0x76, 0x6a,
135 0x47, 0x66, 0x80, 0xb5, 0x5c,
136 0xd3, 0x39, 0xe8, 0xab, 0x6c,
137 0x72, 0xb5, 0xfa, 0xcd, 0xb2,
138 0xa2, 0xa5, 0x0a, 0xc2, 0x5b,
139 0xd0, 0x86, 0x64, 0x7d, 0xd3,
140 0xe2, 0xe6, 0xe9, 0x9e, 0x84,
141 0xca, 0x2c, 0x36, 0x09, 0xfd,
142 0xf1, 0x77, 0xfe, 0xb2, 0x6d },
143 cose_key5[] = { 0xa3, 0x01, 0x04, 0x02, 0x6b,
144 0x6f, 0x75, 0x72, 0x2d, 0x73,
145 0x65, 0x63, 0x72, 0x65, 0x74,
146 0x32, 0x20, 0x50, 0x84, 0x9b,
147 0x57, 0x86, 0x45, 0x7c, 0x14,
148 0x91, 0xbe, 0x3a, 0x76, 0xdc,
149 0xea, 0x6c, 0x42, 0x71 },
150
151 cose_key6[] = { 0xa6, 0x01, 0x02, 0x02, 0x78,
152 0x21, 0x70, 0x65, 0x72, 0x65,
153 0x67, 0x72, 0x69, 0x6e, 0x2e,
154 0x74, 0x6f, 0x6f, 0x6b, 0x40,
155 0x74, 0x75, 0x63, 0x6b, 0x62,
156 0x6f, 0x72, 0x6f, 0x75, 0x67,
157 0x68, 0x2e, 0x65, 0x78, 0x61,
158 0x6d, 0x70, 0x6c, 0x65, 0x20,
159 0x01, 0x21, 0x58, 0x20, 0x98,
160 0xf5, 0x0a, 0x4f, 0xf6, 0xc0,
161 0x58, 0x61, 0xc8, 0x86, 0x0d,
162 0x13, 0xa6, 0x38, 0xea, 0x56,
163 0xc3, 0xf5, 0xad, 0x75, 0x90,
164 0xbb, 0xfb, 0xf0, 0x54, 0xe1,
165 0xc7, 0xb4, 0xd9, 0x1d, 0x62,
166 0x80, 0x22, 0x58, 0x20, 0xf0,
167 0x14, 0x00, 0xb0, 0x89, 0x86,
168 0x78, 0x04, 0xb8, 0xe9, 0xfc,
169 0x96, 0xc3, 0x93, 0x21, 0x61,
170 0xf1, 0x93, 0x4f, 0x42, 0x23,
171 0x06, 0x91, 0x70, 0xd9, 0x24,
172 0xb7, 0xe0, 0x3b, 0xf8, 0x22,
173 0xbb, 0x23, 0x58, 0x20, 0x02,
174 0xd1, 0xf7, 0xe6, 0xf2, 0x6c,
175 0x43, 0xd4, 0x86, 0x8d, 0x87,
176 0xce, 0xb2, 0x35, 0x31, 0x61,
177 0x74, 0x0a, 0xac, 0xf1, 0xf7,
178 0x16, 0x36, 0x47, 0x98, 0x4b,
179 0x52, 0x2a, 0x84, 0x8d, 0xf1,
180 0xc3 },
181 cose_key7[] = { 0xa3, 0x01, 0x04, 0x02, 0x58,
182 0x24, 0x30, 0x31, 0x38, 0x63,
183 0x30, 0x61, 0x65, 0x35, 0x2d,
184 0x34, 0x64, 0x39, 0x62, 0x2d,
185 0x34, 0x37, 0x31, 0x62, 0x2d,
186 0x62, 0x66, 0x64, 0x36, 0x2d,
187 0x65, 0x65, 0x66, 0x33, 0x31,
188 0x34, 0x62, 0x63, 0x37, 0x30,
189 0x33, 0x37, 0x20, 0x58, 0x20,
190 0x84, 0x9b, 0x57, 0x21, 0x9d,
191 0xae, 0x48, 0xde, 0x64, 0x6d,
192 0x07, 0xdb, 0xb5, 0x33, 0x56,
193 0x6e, 0x97, 0x66, 0x86, 0x45,
194 0x7c, 0x14, 0x91, 0xbe, 0x3a,
195 0x76, 0xdc, 0xea, 0x6c, 0x42,
196 0x71, 0x88 },
197
198 cose_key8[] = {
199 /* kid "sec-48" for hmac 384 */
200
201 0xa3, 0x01, 0x04, 0x02, 0x66,
202 0x73, 0x65, 0x63, 0x2d, 0x34,
203 0x38, 0x20, 0x58, 0x30, 0x84,
204 0x9b, 0x57, 0x21, 0x9d, 0xae,
205 0x48, 0xde, 0x64, 0x6d, 0x07,
206 0xdb, 0xb5, 0x33, 0x56, 0x6e,
207 0x97, 0x66, 0x86, 0x45, 0x7c,
208 0x14, 0x91, 0xbe, 0x3a, 0x76,
209 0xdc, 0xea, 0x6c, 0x42, 0x71,
210 0x88, 0x00, 0x11, 0x22, 0x33,
211 0x77, 0x88, 0x99, 0xaa, 0x21,
212 0x22, 0x23, 0x24, 0x25, 0x26,
213 0x27, 0x28
214 },
215
216 cose_key9[] = {
217 /* kid "sec-64" for hmac 512 */
218
219 0xa3, 0x01, 0x04, 0x02, 0x46,
220 0x73, 0x65, 0x63, 0x2d, 0x36,
221 0x34, 0x20, 0x58, 0x40, 0x84,
222 0x9b, 0x57, 0x21, 0x9d, 0xae,
223 0x48, 0xde, 0x64, 0x6d, 0x07,
224 0xdb, 0xb5, 0x33, 0x56, 0x6e,
225 0x97, 0x66, 0x86, 0x45, 0x7c,
226 0x14, 0x91, 0xbe, 0x3a, 0x76,
227 0xdc, 0xea, 0x6c, 0x42, 0x71,
228 0x88, 0x00, 0x11, 0x22, 0x33,
229 0x77, 0x88, 0x99, 0xaa, 0x21,
230 0x22, 0x23, 0x24, 0x25, 0x26,
231 0x27, 0x28, 0xaa, 0xbb, 0xcc,
232 0xdd, 0xee, 0xff, 0xa5, 0xa6,
233 0xa7, 0xa8, 0xa9, 0xa0, 0xb1,
234 0xb2, 0xb3, 0xb4,
235 },
236
237 cose_key10[] = { /* kid "11" (again) ed22519 OKP key */
238 0xa5, 0x01, 0x01, 0x02, 0x42,
239 0x31, 0x31, 0x20, 0x06, 0x21,
240 0x58, 0x20, 0xd7, 0x5a, 0x98,
241 0x01, 0x82, 0xb1, 0x0a, 0xb7,
242 0xd5, 0x4b, 0xfe, 0xd3, 0xc9,
243 0x64, 0x07, 0x3a, 0x0e, 0xe1,
244 0x72, 0xf3, 0xda, 0xa6, 0x23,
245 0x25, 0xaf, 0x02, 0x1a, 0x68,
246 0xf7, 0x07, 0x51, 0x1a, 0x23,
247 0x58, 0x20, 0x9d, 0x61, 0xb1,
248 0x9d, 0xef, 0xfd, 0x5a, 0x60,
249 0xba, 0x84, 0x4a, 0xf4, 0x92,
250 0xec, 0x2c, 0xc4, 0x44, 0x49,
251 0xc5, 0x69, 0x7b, 0x32, 0x69,
252 0x19, 0x70, 0x3b, 0xac, 0x03,
253 0x1c, 0xae, 0x7f, 0x60
254 },
255
256 cose_key_set1[] = {
257
258 0x89,
259
260 0xa6, 0x01, 0x02, 0x02, 0x42,
261 0x31, 0x31, 0x20, 0x01, 0x21,
262 0x58, 0x20, 0xba, 0xc5, 0xb1,
263 0x1c, 0xad, 0x8f, 0x99, 0xf9,
264 0xc7, 0x2b, 0x05, 0xcf, 0x4b,
265 0x9e, 0x26, 0xd2, 0x44, 0xdc,
266 0x18, 0x9f, 0x74, 0x52, 0x28,
267 0x25, 0x5a, 0x21, 0x9a, 0x86,
268 0xd6, 0xa0, 0x9e, 0xff, 0x22,
269 0x58, 0x20, 0x20, 0x13, 0x8b,
270 0xf8, 0x2d, 0xc1, 0xb6, 0xd5,
271 0x62, 0xbe, 0x0f, 0xa5, 0x4a,
272 0xb7, 0x80, 0x4a, 0x3a, 0x64,
273 0xb6, 0xd7, 0x2c, 0xcf, 0xed,
274 0x6b, 0x6f, 0xb6, 0xed, 0x28,
275 0xbb, 0xfc, 0x11, 0x7e, 0x23,
276 0x58, 0x20, 0x57, 0xc9, 0x20,
277 0x77, 0x66, 0x41, 0x46, 0xe8,
278 0x76, 0x76, 0x0c, 0x95, 0x20,
279 0xd0, 0x54, 0xaa, 0x93, 0xc3,
280 0xaf, 0xb0, 0x4e, 0x30, 0x67,
281 0x05, 0xdb, 0x60, 0x90, 0x30,
282 0x85, 0x07, 0xb4, 0xd3,
283
284 0xa6, 0x01, 0x02, 0x02, 0x58,
285 0x24, 0x6d, 0x65, 0x72, 0x69,
286 0x61, 0x64, 0x6f, 0x63, 0x2e,
287 0x62, 0x72, 0x61, 0x6e, 0x64,
288 0x79, 0x62, 0x75, 0x63, 0x6b,
289 0x40, 0x62, 0x75, 0x63, 0x6b,
290 0x6c, 0x61, 0x6e, 0x64, 0x2e,
291 0x65, 0x78, 0x61, 0x6d, 0x70,
292 0x6c, 0x65, 0x20, 0x01, 0x21,
293 0x58, 0x20, 0x65, 0xed, 0xa5,
294 0xa1, 0x25, 0x77, 0xc2, 0xba,
295 0xe8, 0x29, 0x43, 0x7f, 0xe3,
296 0x38, 0x70, 0x1a, 0x10, 0xaa,
297 0xa3, 0x75, 0xe1, 0xbb, 0x5b,
298 0x5d, 0xe1, 0x08, 0xde, 0x43,
299 0x9c, 0x08, 0x55, 0x1d, 0x22,
300 0x58, 0x20, 0x1e, 0x52, 0xed,
301 0x75, 0x70, 0x11, 0x63, 0xf7,
302 0xf9, 0xe4, 0x0d, 0xdf, 0x9f,
303 0x34, 0x1b, 0x3d, 0xc9, 0xba,
304 0x86, 0x0a, 0xf7, 0xe0, 0xca,
305 0x7c, 0xa7, 0xe9, 0xee, 0xcd,
306 0x00, 0x84, 0xd1, 0x9c, 0x23,
307 0x58, 0x20, 0xaf, 0xf9, 0x07,
308 0xc9, 0x9f, 0x9a, 0xd3, 0xaa,
309 0xe6, 0xc4, 0xcd, 0xf2, 0x11,
310 0x22, 0xbc, 0xe2, 0xbd, 0x68,
311 0xb5, 0x28, 0x3e, 0x69, 0x07,
312 0x15, 0x4a, 0xd9, 0x11, 0x84,
313 0x0f, 0xa2, 0x08, 0xcf,
314
315 0xa3, 0x01, 0x04, 0x02, 0x4a,
316 0x6f, 0x75, 0x72, 0x2d, 0x73,
317 0x65, 0x63, 0x72, 0x65, 0x74,
318 0x20, 0x58, 0x20, 0x84, 0x9b,
319 0x57, 0x21, 0x9d, 0xae, 0x48,
320 0xde, 0x64, 0x6d, 0x07, 0xdb,
321 0xb5, 0x33, 0x56, 0x6e, 0x97,
322 0x66, 0x86, 0x45, 0x7c, 0x14,
323 0x91, 0xbe, 0x3a, 0x76, 0xdc,
324 0xea, 0x6c, 0x42, 0x71, 0x88,
325
326 0xa6, 0x01, 0x02, 0x02, 0x58,
327 0x1e, 0x62, 0x69, 0x6c, 0x62,
328 0x6f, 0x2e, 0x62, 0x61, 0x67,
329 0x67, 0x69, 0x6e, 0x73, 0x40,
330 0x68, 0x6f, 0x62, 0x62, 0x69,
331 0x74, 0x6f, 0x6e, 0x2e, 0x65,
332 0x78, 0x61, 0x6d, 0x70, 0x6c,
333 0x65, 0x20, 0x03, 0x21, 0x58,
334 0x42, 0x00, 0x72, 0x99, 0x2c,
335 0xb3, 0xac, 0x08, 0xec, 0xf3,
336 0xe5, 0xc6, 0x3d, 0xed, 0xec,
337 0x0d, 0x51, 0xa8, 0xc1, 0xf7,
338 0x9e, 0xf2, 0xf8, 0x2f, 0x94,
339 0xf3, 0xc7, 0x37, 0xbf, 0x5d,
340 0xe7, 0x98, 0x66, 0x71, 0xea,
341 0xc6, 0x25, 0xfe, 0x82, 0x57,
342 0xbb, 0xd0, 0x39, 0x46, 0x44,
343 0xca, 0xaa, 0x3a, 0xaf, 0x8f,
344 0x27, 0xa4, 0x58, 0x5f, 0xbb,
345 0xca, 0xd0, 0xf2, 0x45, 0x76,
346 0x20, 0x08, 0x5e, 0x5c, 0x8f,
347 0x42, 0xad, 0x22, 0x58, 0x42,
348 0x01, 0xdc, 0xa6, 0x94, 0x7b,
349 0xce, 0x88, 0xbc, 0x57, 0x90,
350 0x48, 0x5a, 0xc9, 0x74, 0x27,
351 0x34, 0x2b, 0xc3, 0x5f, 0x88,
352 0x7d, 0x86, 0xd6, 0x5a, 0x08,
353 0x93, 0x77, 0xe2, 0x47, 0xe6,
354 0x0b, 0xaa, 0x55, 0xe4, 0xe8,
355 0x50, 0x1e, 0x2a, 0xda, 0x57,
356 0x24, 0xac, 0x51, 0xd6, 0x90,
357 0x90, 0x08, 0x03, 0x3e, 0xbc,
358 0x10, 0xac, 0x99, 0x9b, 0x9d,
359 0x7f, 0x5c, 0xc2, 0x51, 0x9f,
360 0x3f, 0xe1, 0xea, 0x1d, 0x94,
361 0x75, 0x23, 0x58, 0x42, 0x00,
362 0x08, 0x51, 0x38, 0xdd, 0xab,
363 0xf5, 0xca, 0x97, 0x5f, 0x58,
364 0x60, 0xf9, 0x1a, 0x08, 0xe9,
365 0x1d, 0x6d, 0x5f, 0x9a, 0x76,
366 0xad, 0x40, 0x18, 0x76, 0x6a,
367 0x47, 0x66, 0x80, 0xb5, 0x5c,
368 0xd3, 0x39, 0xe8, 0xab, 0x6c,
369 0x72, 0xb5, 0xfa, 0xcd, 0xb2,
370 0xa2, 0xa5, 0x0a, 0xc2, 0x5b,
371 0xd0, 0x86, 0x64, 0x7d, 0xd3,
372 0xe2, 0xe6, 0xe9, 0x9e, 0x84,
373 0xca, 0x2c, 0x36, 0x09, 0xfd,
374 0xf1, 0x77, 0xfe, 0xb2, 0x6d,
375
376 0xa3, 0x01, 0x04, 0x02, 0x4b,
377 0x6f, 0x75, 0x72, 0x2d, 0x73,
378 0x65, 0x63, 0x72, 0x65, 0x74,
379 0x32, 0x20, 0x50, 0x84, 0x9b,
380 0x57, 0x86, 0x45, 0x7c, 0x14,
381 0x91, 0xbe, 0x3a, 0x76, 0xdc,
382 0xea, 0x6c, 0x42, 0x71,
383
384 0xa6, 0x01, 0x02, 0x02, 0x58,
385 0x21, 0x70, 0x65, 0x72, 0x65,
386 0x67, 0x72, 0x69, 0x6e, 0x2e,
387 0x74, 0x6f, 0x6f, 0x6b, 0x40,
388 0x74, 0x75, 0x63, 0x6b, 0x62,
389 0x6f, 0x72, 0x6f, 0x75, 0x67,
390 0x68, 0x2e, 0x65, 0x78, 0x61,
391 0x6d, 0x70, 0x6c, 0x65, 0x20,
392 0x01, 0x21, 0x58, 0x20, 0x98,
393 0xf5, 0x0a, 0x4f, 0xf6, 0xc0,
394 0x58, 0x61, 0xc8, 0x86, 0x0d,
395 0x13, 0xa6, 0x38, 0xea, 0x56,
396 0xc3, 0xf5, 0xad, 0x75, 0x90,
397 0xbb, 0xfb, 0xf0, 0x54, 0xe1,
398 0xc7, 0xb4, 0xd9, 0x1d, 0x62,
399 0x80, 0x22, 0x58, 0x20, 0xf0,
400 0x14, 0x00, 0xb0, 0x89, 0x86,
401 0x78, 0x04, 0xb8, 0xe9, 0xfc,
402 0x96, 0xc3, 0x93, 0x21, 0x61,
403 0xf1, 0x93, 0x4f, 0x42, 0x23,
404 0x06, 0x91, 0x70, 0xd9, 0x24,
405 0xb7, 0xe0, 0x3b, 0xf8, 0x22,
406 0xbb, 0x23, 0x58, 0x20, 0x02,
407 0xd1, 0xf7, 0xe6, 0xf2, 0x6c,
408 0x43, 0xd4, 0x86, 0x8d, 0x87,
409 0xce, 0xb2, 0x35, 0x31, 0x61,
410 0x74, 0x0a, 0xac, 0xf1, 0xf7,
411 0x16, 0x36, 0x47, 0x98, 0x4b,
412 0x52, 0x2a, 0x84, 0x8d, 0xf1,
413 0xc3,
414
415 0xa3, 0x01, 0x04, 0x02, 0x58,
416 0x24, 0x30, 0x31, 0x38, 0x63,
417 0x30, 0x61, 0x65, 0x35, 0x2d,
418 0x34, 0x64, 0x39, 0x62, 0x2d,
419 0x34, 0x37, 0x31, 0x62, 0x2d,
420 0x62, 0x66, 0x64, 0x36, 0x2d,
421 0x65, 0x65, 0x66, 0x33, 0x31,
422 0x34, 0x62, 0x63, 0x37, 0x30,
423 0x33, 0x37, 0x04, 0x58, 0x20,
424 0x84, 0x9b, 0x57, 0x21, 0x9d,
425 0xae, 0x48, 0xde, 0x64, 0x6d,
426 0x07, 0xdb, 0xb5, 0x33, 0x56,
427 0x6e, 0x97, 0x66, 0x86, 0x45,
428 0x7c, 0x14, 0x91, 0xbe, 0x3a,
429 0x76, 0xdc, 0xea, 0x6c, 0x42,
430 0x71, 0x88,
431
432 /* kid "sec-48" for hmac 384 */
433
434 0xa3, 0x01, 0x04, 0x02, 0x46,
435 0x73, 0x65, 0x63, 0x2d, 0x34,
436 0x38, 0x20, 0x58, 0x30, 0x84,
437 0x9b, 0x57, 0x21, 0x9d, 0xae,
438 0x48, 0xde, 0x64, 0x6d, 0x07,
439 0xdb, 0xb5, 0x33, 0x56, 0x6e,
440 0x97, 0x66, 0x86, 0x45, 0x7c,
441 0x14, 0x91, 0xbe, 0x3a, 0x76,
442 0xdc, 0xea, 0x6c, 0x42, 0x71,
443 0x88, 0x00, 0x11, 0x22, 0x33,
444 0x77, 0x88, 0x99, 0xaa, 0x21,
445 0x22, 0x23, 0x24, 0x25, 0x26,
446 0x27, 0x28,
447
448 /* kid "sec-64" for hmac 512 */
449
450 0xa3, 0x01, 0x04, 0x02, 0x46,
451 0x73, 0x65, 0x63, 0x2d, 0x36,
452 0x34, 0x20, 0x58, 0x40, 0x84,
453 0x9b, 0x57, 0x21, 0x9d, 0xae,
454 0x48, 0xde, 0x64, 0x6d, 0x07,
455 0xdb, 0xb5, 0x33, 0x56, 0x6e,
456 0x97, 0x66, 0x86, 0x45, 0x7c,
457 0x14, 0x91, 0xbe, 0x3a, 0x76,
458 0xdc, 0xea, 0x6c, 0x42, 0x71,
459 0x88, 0x00, 0x11, 0x22, 0x33,
460 0x77, 0x88, 0x99, 0xaa, 0x21,
461 0x22, 0x23, 0x24, 0x25, 0x26,
462 0x27, 0x28, 0xaa, 0xbb, 0xcc,
463 0xdd, 0xee, 0xff, 0xa5, 0xa6,
464 0xa7, 0xa8, 0xa9, 0xa0, 0xb1,
465 0xb2, 0xb3, 0xb4,
466 }
467 ;
468
469 struct keyinfo {
470 const uint8_t *set;
471 size_t len;
472 };
473
474 struct keyinfo keyset1 = { cose_key_set1, sizeof(cose_key_set1) },
475 key3 = { cose_key3, sizeof(cose_key3) },
476 key8 = { cose_key8, sizeof(cose_key8) },
477 key9 = { cose_key9, sizeof(cose_key9) },
478 key10 = { cose_key10, sizeof(cose_key10) }
479 ;
480
481 /* key pieces */
482
483 static const uint8_t
484 key1_x[] = { 0xba, 0xc5, 0xb1, 0x1c, 0xad,
485 0x8f, 0x99, 0xf9, 0xc7, 0x2b,
486 0x05, 0xcf, 0x4b, 0x9e, 0x26,
487 0xd2, 0x44, 0xdc, 0x18, 0x9f,
488 0x74, 0x52, 0x28, 0x25, 0x5a,
489 0x21, 0x9a, 0x86, 0xd6, 0xa0,
490 0x9e, 0xff },
491 key1_y[] = { 0x20, 0x13, 0x8b, 0xf8, 0x2d,
492 0xc1, 0xb6, 0xd5, 0x62, 0xbe,
493 0x0f, 0xa5, 0x4a, 0xb7, 0x80,
494 0x4a, 0x3a, 0x64, 0xb6, 0xd7,
495 0x2c, 0xcf, 0xed, 0x6b, 0x6f,
496 0xb6, 0xed, 0x28, 0xbb, 0xfc,
497 0x11, 0x7e },
498 key1_d[] = { 0x57, 0xc9, 0x20, 0x77, 0x66,
499 0x41, 0x46, 0xe8, 0x76, 0x76,
500 0x0c, 0x95, 0x20, 0xd0, 0x54,
501 0xaa, 0x93, 0xc3, 0xaf, 0xb0,
502 0x4e, 0x30, 0x67, 0x05, 0xdb,
503 0x60, 0x90, 0x30, 0x85, 0x07,
504 0xb4, 0xd3 },
505
506 key2_x[] = { 0x65, 0xed, 0xa5, 0xa1, 0x25,
507 0x77, 0xc2, 0xba, 0xe8, 0x29,
508 0x43, 0x7f, 0xe3, 0x38, 0x70,
509 0x1a, 0x10, 0xaa, 0xa3, 0x75,
510 0xe1, 0xbb, 0x5b, 0x5d, 0xe1,
511 0x08, 0xde, 0x43, 0x9c, 0x08,
512 0x55, 0x1d },
513 key2_y[] = { 0x1e, 0x52, 0xed, 0x75, 0x70,
514 0x11, 0x63, 0xf7, 0xf9, 0xe4,
515 0x0d, 0xdf, 0x9f, 0x34, 0x1b,
516 0x3d, 0xc9, 0xba, 0x86, 0x0a,
517 0xf7, 0xe0, 0xca, 0x7c, 0xa7,
518 0xe9, 0xee, 0xcd, 0x00, 0x84,
519 0xd1, 0x9c },
520 key2_d[] = { 0xaf, 0xf9, 0x07, 0xc9, 0x9f,
521 0x9a, 0xd3, 0xaa, 0xe6, 0xc4,
522 0xcd, 0xf2, 0x11, 0x22, 0xbc,
523 0xe2, 0xbd, 0x68, 0xb5, 0x28,
524 0x3e, 0x69, 0x07, 0x15, 0x4a,
525 0xd9, 0x11, 0x84, 0x0f, 0xa2,
526 0x08, 0xcf },
527
528 key3_k[] = { 0x84, 0x9b, 0x57, 0x21, 0x9d,
529 0xae, 0x48, 0xde, 0x64, 0x6d,
530 0x07, 0xdb, 0xb5, 0x33, 0x56,
531 0x6e, 0x97, 0x66, 0x86, 0x45,
532 0x7c, 0x14, 0x91, 0xbe, 0x3a,
533 0x76, 0xdc, 0xea, 0x6c, 0x42,
534 0x71, 0x88 },
535
536 key4_x[] = { 0x00, 0x72, 0x99, 0x2c, 0xb3,
537 0xac, 0x08, 0xec, 0xf3, 0xe5,
538 0xc6, 0x3d, 0xed, 0xec, 0x0d,
539 0x51, 0xa8, 0xc1, 0xf7, 0x9e,
540 0xf2, 0xf8, 0x2f, 0x94, 0xf3,
541 0xc7, 0x37, 0xbf, 0x5d, 0xe7,
542 0x98, 0x66, 0x71, 0xea, 0xc6,
543 0x25, 0xfe, 0x82, 0x57, 0xbb,
544 0xd0, 0x39, 0x46, 0x44, 0xca,
545 0xaa, 0x3a, 0xaf, 0x8f, 0x27,
546 0xa4, 0x58, 0x5f, 0xbb, 0xca,
547 0xd0, 0xf2, 0x45, 0x76, 0x20,
548 0x08, 0x5e, 0x5c, 0x8f, 0x42,
549 0xad },
550 key4_y[] = { 0x01, 0xdc, 0xa6, 0x94, 0x7b,
551 0xce, 0x88, 0xbc, 0x57, 0x90,
552 0x48, 0x5a, 0xc9, 0x74, 0x27,
553 0x34, 0x2b, 0xc3, 0x5f, 0x88,
554 0x7d, 0x86, 0xd6, 0x5a, 0x08,
555 0x93, 0x77, 0xe2, 0x47, 0xe6,
556 0x0b, 0xaa, 0x55, 0xe4, 0xe8,
557 0x50, 0x1e, 0x2a, 0xda, 0x57,
558 0x24, 0xac, 0x51, 0xd6, 0x90,
559 0x90, 0x08, 0x03, 0x3e, 0xbc,
560 0x10, 0xac, 0x99, 0x9b, 0x9d,
561 0x7f, 0x5c, 0xc2, 0x51, 0x9f,
562 0x3f, 0xe1, 0xea, 0x1d, 0x94,
563 0x75 },
564 key4_d[] = { 0x00, 0x08, 0x51, 0x38, 0xdd,
565 0xab, 0xf5, 0xca, 0x97, 0x5f,
566 0x58, 0x60, 0xf9, 0x1a, 0x08,
567 0xe9, 0x1d, 0x6d, 0x5f, 0x9a,
568 0x76, 0xad, 0x40, 0x18, 0x76,
569 0x6a, 0x47, 0x66, 0x80, 0xb5,
570 0x5c, 0xd3, 0x39, 0xe8, 0xab,
571 0x6c, 0x72, 0xb5, 0xfa, 0xcd,
572 0xb2, 0xa2, 0xa5, 0x0a, 0xc2,
573 0x5b, 0xd0, 0x86, 0x64, 0x7d,
574 0xd3, 0xe2, 0xe6, 0xe9, 0x9e,
575 0x84, 0xca, 0x2c, 0x36, 0x09,
576 0xfd, 0xf1, 0x77, 0xfe, 0xb2,
577 0x6d },
578 key5_k[] = { 0x84, 0x9b, 0x57, 0x86, 0x45,
579 0x7c, 0x14, 0x91, 0xbe, 0x3a,
580 0x76, 0xdc, 0xea, 0x6c, 0x42,
581 0x71 },
582
583 key6_x[] = { 0x98, 0xf5, 0x0a, 0x4f, 0xf6,
584 0xc0, 0x58, 0x61, 0xc8, 0x86,
585 0x0d, 0x13, 0xa6, 0x38, 0xea,
586 0x56, 0xc3, 0xf5, 0xad, 0x75,
587 0x90, 0xbb, 0xfb, 0xf0, 0x54,
588 0xe1, 0xc7, 0xb4, 0xd9, 0x1d,
589 0x62, 0x80 },
590 key6_y[] = { 0xf0, 0x14, 0x00, 0xb0, 0x89,
591 0x86, 0x78, 0x04, 0xb8, 0xe9,
592 0xfc, 0x96, 0xc3, 0x93, 0x21,
593 0x61, 0xf1, 0x93, 0x4f, 0x42,
594 0x23, 0x06, 0x91, 0x70, 0xd9,
595 0x24, 0xb7, 0xe0, 0x3b, 0xf8,
596 0x22, 0xbb },
597 key6_d[] = { 0x02, 0xd1, 0xf7, 0xe6, 0xf2,
598 0x6c, 0x43, 0xd4, 0x86, 0x8d,
599 0x87, 0xce, 0xb2, 0x35, 0x31,
600 0x61, 0x74, 0x0a, 0xac, 0xf1,
601 0xf7, 0x16, 0x36, 0x47, 0x98,
602 0x4b, 0x52, 0x2a, 0x84, 0x8d,
603 0xf1, 0xc3 },
604
605 key7_k[] = { 0x84, 0x9b, 0x57, 0x21, 0x9d,
606 0xae, 0x48, 0xde, 0x64, 0x6d,
607 0x07, 0xdb, 0xb5, 0x33, 0x56,
608 0x6e, 0x97, 0x66, 0x86, 0x45,
609 0x7c, 0x14, 0x91, 0xbe, 0x3a,
610 0x76, 0xdc, 0xea, 0x6c, 0x42,
611 0x71, 0x88 },
612
613 key8_k[] = { 0x84, 0x9b, 0x57, 0x21, 0x9d,
614 0xae, 0x48, 0xde, 0x64, 0x6d,
615 0x07, 0xdb, 0xb5, 0x33, 0x56,
616 0x6e, 0x97, 0x66, 0x86, 0x45,
617 0x7c, 0x14, 0x91, 0xbe, 0x3a,
618 0x76, 0xdc, 0xea, 0x6c, 0x42,
619 0x71, 0x88, 0x00, 0x11, 0x22,
620 0x33, 0x77, 0x88, 0x99, 0xaa,
621 0x21, 0x22, 0x23, 0x24, 0x25,
622 0x26, 0x27, 0x28 },
623
624 key9_k[] = { 0x84, 0x9b, 0x57, 0x21, 0x9d,
625 0xae, 0x48, 0xde, 0x64, 0x6d,
626 0x07, 0xdb, 0xb5, 0x33, 0x56,
627 0x6e, 0x97, 0x66, 0x86, 0x45,
628 0x7c, 0x14, 0x91, 0xbe, 0x3a,
629 0x76, 0xdc, 0xea, 0x6c, 0x42,
630 0x71, 0x88, 0x00, 0x11, 0x22,
631 0x33, 0x77, 0x88, 0x99, 0xaa,
632 0x21, 0x22, 0x23, 0x24, 0x25,
633 0x26, 0x27, 0x28, 0xaa, 0xbb,
634 0xcc, 0xdd, 0xee, 0xff, 0xa5,
635 0xa6, 0xa7, 0xa8, 0xa9, 0xa0,
636 0xb1, 0xb2, 0xb3, 0xb4 }
637 #if 0
638 ,
639 key10_x[] = {
640 0xd7, 0x5a, 0x98, 0x01, 0x82,
641 0xb1, 0x0a, 0xb7, 0xd5, 0x4b,
642 0xfe, 0xd3, 0xc9, 0x64, 0x07,
643 0x3a, 0x0e, 0xe1, 0x72, 0xf3,
644 0xda, 0xa6, 0x23, 0x25, 0xaf,
645 0x02, 0x1a, 0x68, 0xf7, 0x07,
646 0x51, 0x1a
647 }, key10_d[] = {
648 0x9d, 0x61, 0xb1, 0x9d, 0xef,
649 0xfd, 0x5a, 0x60, 0xba, 0x84,
650 0x4a, 0xf4, 0x92, 0xec, 0x2c,
651 0xc4, 0x44, 0x49, 0xc5, 0x69,
652 0x7b, 0x32, 0x69, 0x19, 0x70,
653 0x3b, 0xac, 0x03, 0x1c, 0xae,
654 0x7f, 0x60
655 }
656 #endif
657 ;
658
659 int
test_cose_keys(struct lws_context * context)660 test_cose_keys(struct lws_context *context)
661 {
662 struct lws_cose_key *ck;
663 lws_dll2_owner_t set;
664 lws_lec_pctx_t wc;
665 uint8_t buf[4096];
666 int n;
667
668 #if 0
669 {
670 int fd = open("set1.cks",
671 LWS_O_CREAT | LWS_O_TRUNC | LWS_O_WRONLY, 0600);
672
673 if (fd >= 0) {
674 write(fd, cose_key_set1, sizeof(cose_key_set1));
675 close(fd);
676 }
677 }
678 #endif
679
680 #if 0
681 lws_lec_pctx_t wx;
682 uint8_t dump[8192];
683
684 lws_lec_init(&wx, buf, sizeof(buf));
685
686 if (lws_lec_printf(&wx,
687 "{%d:%d, %d:%.*b, %d:%d, %d:%.*b, %d:%.*b}",
688 LWSCOSE_WKK_KTY, LWSCOSE_WKKTV_OKP,
689 LWSCOSE_WKK_KID, 2, "11",
690 LWSCOSE_WKOKP_CRV, LWSCOSE_WKEC_ED25519,
691 LWSCOSE_WKECKP_X, (int)sizeof(key10_x), key10_x,
692 // LWSCOSE_WKECKP_Y, (int)sizeof(key6_y), key6_y,
693 LWSCOSE_WKECKP_D, (int)sizeof(key10_d), key10_d) !=
694 LWS_LECPCTX_RET_FINISHED)
695 return 1;
696
697 lws_hex_from_byte_array(buf, wx.used, (char *)dump, sizeof(dump));
698 puts((const char *)dump);
699 #endif
700 #if 0
701 lws_lec_pctx_t wx;
702 uint8_t dump[8192];
703
704 lws_lec_init(&wx, buf, sizeof(buf));
705
706 if (lws_lec_printf(&wx,
707 "{%d:%d, %d:%.*b, %d:%.*b}",
708 LWSCOSE_WKK_KTY, LWSCOSE_WKKTV_SYMMETRIC,
709 LWSCOSE_WKK_KID, 6, "sec-64",
710 -1, (int)sizeof(key9_k), key9_k) !=
711 LWS_LECPCTX_RET_FINISHED)
712 return 1;
713
714 lws_hex_from_byte_array(buf, wx.used, (char *)dump, sizeof(dump));
715 puts((const char *)dump);
716 #endif
717
718 /* key1 import */
719
720 lwsl_user("%s: key 1 import\n", __func__);
721
722 ck = lws_cose_key_import(NULL, key_import_cb, NULL, cose_key1, sizeof(cose_key1));
723 if (!ck)
724 return 1;
725
726 if (ck->kty != LWSCOSE_WKKTV_EC2 ||
727 ck->gencrypto_kty != LWS_GENCRYPTO_KTY_EC ||
728 ck->e[LWS_GENCRYPTO_EC_KEYEL_X].len != sizeof(key1_x) ||
729 ck->e[LWS_GENCRYPTO_EC_KEYEL_Y].len != sizeof(key1_y) ||
730 ck->e[LWS_GENCRYPTO_EC_KEYEL_D].len != sizeof(key1_d) ||
731 memcmp(ck->e[LWS_GENCRYPTO_EC_KEYEL_X].buf, key1_x, sizeof(key1_x)) ||
732 memcmp(ck->e[LWS_GENCRYPTO_EC_KEYEL_Y].buf, key1_y, sizeof(key1_y)) ||
733 memcmp(ck->e[LWS_GENCRYPTO_EC_KEYEL_D].buf, key1_d, sizeof(key1_d)))
734 goto bail;
735
736 // lws_cose_key_dump(ck);
737
738 /* key 1 export */
739
740 lwsl_user("%s: key 1 export\n", __func__);
741
742 lws_lec_init(&wc, buf, sizeof(buf));
743 n = (int)lws_cose_key_export(ck, &wc, LWSJWKF_EXPORT_PRIVATE);
744 lws_cose_key_destroy(&ck);
745 if (n != LWS_LECPCTX_RET_FINISHED)
746 goto bail;
747
748 // lwsl_hexdump_notice(buf, wc.used);
749
750 /* key2 import */
751
752 lwsl_user("%s: key 2 import\n", __func__);
753
754 ck = lws_cose_key_import(NULL, NULL, NULL, cose_key2, sizeof(cose_key2));
755 if (!ck)
756 return 1;
757
758 if (ck->kty != LWSCOSE_WKKTV_EC2 ||
759 ck->gencrypto_kty != LWS_GENCRYPTO_KTY_EC ||
760 ck->e[LWS_GENCRYPTO_EC_KEYEL_X].len != sizeof(key2_x) ||
761 ck->e[LWS_GENCRYPTO_EC_KEYEL_Y].len != sizeof(key2_y) ||
762 ck->e[LWS_GENCRYPTO_EC_KEYEL_D].len != sizeof(key2_d) ||
763 memcmp(ck->e[LWS_GENCRYPTO_EC_KEYEL_X].buf, key2_x, sizeof(key2_x)) ||
764 memcmp(ck->e[LWS_GENCRYPTO_EC_KEYEL_Y].buf, key2_y, sizeof(key2_y)) ||
765 memcmp(ck->e[LWS_GENCRYPTO_EC_KEYEL_D].buf, key2_d, sizeof(key2_d)))
766 goto bail;
767
768 lws_cose_key_destroy(&ck);
769
770 /* key3 import */
771
772 lwsl_user("%s: key 3 import\n", __func__);
773
774 ck = lws_cose_key_import(NULL, NULL, NULL, cose_key3, sizeof(cose_key3));
775 if (!ck) {
776 lwsl_err("%s: key 3 import failed\n", __func__);
777 goto bail;
778 }
779
780 if (ck->kty != LWSCOSE_WKKTV_SYMMETRIC ||
781 ck->gencrypto_kty != LWS_GENCRYPTO_KTY_OCT ||
782 ck->e[LWS_GENCRYPTO_OCT_KEYEL_K].len != sizeof(key3_k) ||
783 memcmp(ck->e[LWS_GENCRYPTO_OCT_KEYEL_K].buf, key3_k, sizeof(key3_k))) {
784 lwsl_err("%s: key 3 checks failed %d %d %d\n", __func__,
785 (int)ck->kty, (int)ck->gencrypto_kty,
786 (int)ck->e[LWS_GENCRYPTO_OCT_KEYEL_K].len);
787 goto bail;
788 }
789
790 lws_cose_key_destroy(&ck);
791
792 /* key4 import */
793
794 lwsl_user("%s: key 4 import\n", __func__);
795
796 ck = lws_cose_key_import(NULL, NULL, NULL, cose_key4, sizeof(cose_key4));
797 if (!ck)
798 return 1;
799
800 if (ck->kty != LWSCOSE_WKKTV_EC2 ||
801 ck->gencrypto_kty != LWS_GENCRYPTO_KTY_EC ||
802 ck->e[LWS_GENCRYPTO_EC_KEYEL_X].len != sizeof(key4_x) ||
803 ck->e[LWS_GENCRYPTO_EC_KEYEL_Y].len != sizeof(key4_y) ||
804 ck->e[LWS_GENCRYPTO_EC_KEYEL_D].len != sizeof(key4_d) ||
805 memcmp(ck->e[LWS_GENCRYPTO_EC_KEYEL_X].buf, key4_x, sizeof(key4_x)) ||
806 memcmp(ck->e[LWS_GENCRYPTO_EC_KEYEL_Y].buf, key4_y, sizeof(key4_y)) ||
807 memcmp(ck->e[LWS_GENCRYPTO_EC_KEYEL_D].buf, key4_d, sizeof(key4_d)))
808 goto bail;
809
810 lws_cose_key_destroy(&ck);
811
812 /* key5 import */
813
814 lwsl_user("%s: key 5 import\n", __func__);
815
816 ck = lws_cose_key_import(NULL, NULL, NULL, cose_key5, sizeof(cose_key5));
817 if (!ck)
818 return 1;
819
820 if (ck->kty != LWSCOSE_WKKTV_SYMMETRIC ||
821 ck->gencrypto_kty != LWS_GENCRYPTO_KTY_OCT ||
822 ck->e[LWS_GENCRYPTO_OCT_KEYEL_K].len != sizeof(key5_k) ||
823 memcmp(ck->e[LWS_GENCRYPTO_OCT_KEYEL_K].buf, key5_k, sizeof(key5_k)))
824 goto bail;
825
826 lws_cose_key_destroy(&ck);
827
828 /* key6 import */
829
830 lwsl_user("%s: key 6 import\n", __func__);
831
832 ck = lws_cose_key_import(NULL, NULL, NULL, cose_key6, sizeof(cose_key6));
833 if (!ck)
834 return 1;
835
836 if (ck->kty != LWSCOSE_WKKTV_EC2 ||
837 ck->gencrypto_kty != LWS_GENCRYPTO_KTY_EC ||
838 ck->e[LWS_GENCRYPTO_EC_KEYEL_X].len != sizeof(key6_x) ||
839 ck->e[LWS_GENCRYPTO_EC_KEYEL_Y].len != sizeof(key6_y) ||
840 ck->e[LWS_GENCRYPTO_EC_KEYEL_D].len != sizeof(key6_d) ||
841 memcmp(ck->e[LWS_GENCRYPTO_EC_KEYEL_X].buf, key6_x, sizeof(key6_x)) ||
842 memcmp(ck->e[LWS_GENCRYPTO_EC_KEYEL_Y].buf, key6_y, sizeof(key6_y)) ||
843 memcmp(ck->e[LWS_GENCRYPTO_EC_KEYEL_D].buf, key6_d, sizeof(key6_d)))
844 goto bail;
845
846 lws_cose_key_destroy(&ck);
847
848 /* key7 import */
849
850 lwsl_user("%s: key 7 import\n", __func__);
851
852 ck = lws_cose_key_import(NULL, NULL, NULL, cose_key7, sizeof(cose_key7));
853 if (!ck)
854 return 1;
855
856 if (ck->kty != LWSCOSE_WKKTV_SYMMETRIC ||
857 ck->gencrypto_kty != LWS_GENCRYPTO_KTY_OCT ||
858 ck->e[LWS_GENCRYPTO_OCT_KEYEL_K].len != sizeof(key7_k) ||
859 memcmp(ck->e[LWS_GENCRYPTO_OCT_KEYEL_K].buf, key7_k, sizeof(key7_k)))
860 goto bail;
861
862 lws_cose_key_destroy(&ck);
863
864 /* key8 import */
865
866 lwsl_user("%s: key 8 import\n", __func__);
867
868 ck = lws_cose_key_import(NULL, NULL, NULL, cose_key8, sizeof(cose_key8));
869 if (!ck)
870 return 1;
871
872 if (ck->kty != LWSCOSE_WKKTV_SYMMETRIC ||
873 ck->gencrypto_kty != LWS_GENCRYPTO_KTY_OCT ||
874 ck->e[LWS_GENCRYPTO_OCT_KEYEL_K].len != sizeof(key8_k) ||
875 memcmp(ck->e[LWS_GENCRYPTO_OCT_KEYEL_K].buf, key8_k, sizeof(key8_k)))
876 goto bail;
877
878 lws_cose_key_destroy(&ck);
879
880 /* key9 import */
881
882 lwsl_user("%s: key 9 import\n", __func__);
883
884 ck = lws_cose_key_import(NULL, NULL, NULL, cose_key9, sizeof(cose_key9));
885 if (!ck) {
886 lwsl_err("%s: cose9 import fail\n", __func__);
887 goto bail;
888 }
889
890 if (ck->kty != LWSCOSE_WKKTV_SYMMETRIC ||
891 ck->gencrypto_kty != LWS_GENCRYPTO_KTY_OCT ||
892 ck->e[LWS_GENCRYPTO_OCT_KEYEL_K].len != sizeof(key9_k) ||
893 memcmp(ck->e[LWS_GENCRYPTO_OCT_KEYEL_K].buf, key9_k, sizeof(key9_k))) {
894 lwsl_notice("%s: key9 check fails\n", __func__);
895 goto bail;
896 }
897
898 lws_cose_key_destroy(&ck);
899
900 /* key set 1 */
901
902 lwsl_user("%s: key_set1\n", __func__);
903 lws_dll2_owner_clear(&set);
904 ck = lws_cose_key_import(&set, NULL, NULL, cose_key_set1, sizeof(cose_key_set1));
905 if (!ck)
906 return 1;
907
908 lws_cose_key_set_destroy(&set);
909
910 /* generate */
911
912 ck = lws_cose_key_generate(context, LWSCOSE_WKKTV_EC2,
913 (1 << LWSCOSE_WKKO_SIGN) |
914 (1 << LWSCOSE_WKKO_VERIFY) |
915 (1 << LWSCOSE_WKKO_ENCRYPT) |
916 (1 << LWSCOSE_WKKO_DECRYPT),
917 0, "P-256", (const uint8_t *)"the-keyid", 9);
918 if (!ck)
919 return 1;
920
921 // lws_cose_key_dump(ck);
922
923 lws_cose_key_destroy(&ck);
924
925 return 0;
926
927 bail:
928 lwsl_err("%s: selftest failed ++++++++++++++++++++\n", __func__);
929
930 return 1;
931 }
932