]> git.proxmox.com Git - ceph.git/blob - ceph/src/libkmip/tests.c
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / libkmip / tests.c
1 /* Copyright (c) 2018 The Johns Hopkins University/Applied Physics Laboratory
2 * All Rights Reserved.
3 *
4 * This file is dual licensed under the terms of the Apache 2.0 License and
5 * the BSD 3-Clause License. See the LICENSE file in the root of this
6 * repository for more information.
7 */
8
9 #include <stdio.h>
10 #include <string.h>
11 #include "kmip.h"
12
13
14
15 #define TEST_PASSED(A, B) \
16 do \
17 { \
18 printf("PASS - %s\n", (B)); \
19 (A)->tests_passed++; \
20 return(0); \
21 } while(0)
22
23 #define TEST_FAILED(A, B, C) \
24 do \
25 { \
26 printf("FAIL - %s @ L%d\n", (B), (C)); \
27 (A)->tests_failed++; \
28 return(1); \
29 } while(0)
30
31 #define TRACK_TEST(A) ((A)->test_count++)
32
33
34 typedef struct test_tracker
35 {
36 uint16 test_count;
37 uint16 tests_failed;
38 uint16 tests_passed;
39 } TestTracker;
40
41
42 int
43 report_encoding_test_result(
44 TestTracker *tracker,
45 struct kmip *ctx,
46 const uint8 *expected,
47 const uint8 *observed,
48 int result,
49 const char *function)
50 {
51 if(result == KMIP_OK)
52 {
53 for(size_t i = 0; i < ctx->size; i++)
54 {
55 if(expected[i] != observed[i])
56 {
57 printf("FAIL - %s\n", function);
58 printf("- byte mismatch at: %zu (exp: %X, obs: %X)\n",
59 i, expected[i], observed[i]);
60 for(size_t j = 0; j < ctx->size; j++)
61 {
62 printf("- %zu: %X - %X\n", j, expected[j], observed[j]);
63 }
64 tracker->tests_failed++;
65 return(1);
66 }
67 }
68
69 TEST_PASSED(tracker, function);
70 }
71 else
72 {
73 printf("FAIL - %s\n", function);
74 if(result == KMIP_ERROR_BUFFER_FULL)
75 {
76 printf("- context buffer is full\n");
77 }
78 kmip_print_stack_trace(ctx);
79 tracker->tests_failed++;
80 return(1);
81 }
82 }
83
84 int
85 report_decoding_test_result(
86 TestTracker *tracker,
87 struct kmip *ctx,
88 int comparison,
89 int result,
90 const char *function)
91 {
92 if(result == KMIP_OK)
93 {
94 if(comparison)
95 {
96 TEST_PASSED(tracker, function);
97 }
98 else
99 {
100 printf("FAIL - %s\n", function);
101 printf("- compared objects are not identical\n");
102 tracker->tests_failed++;
103 return(1);
104 }
105 }
106 else
107 {
108 printf("FAIL - %s\n", function);
109 if(result == KMIP_ERROR_BUFFER_FULL)
110 {
111 printf("- context buffer is underfull\n");
112 }
113 kmip_print_stack_trace(ctx);
114 tracker->tests_failed++;
115 return(1);
116 }
117 }
118
119 int
120 report_result(TestTracker *tracker, int observed, int expected, const char *function)
121 {
122 if(observed == expected)
123 {
124 TEST_PASSED(tracker, function);
125 }
126 else
127 {
128 printf("FAIL - %s\n", function);
129 tracker->tests_failed++;
130 return(1);
131 }
132 }
133
134 int
135 test_linked_list_push(TestTracker *tracker)
136 {
137 TRACK_TEST(tracker);
138
139 LinkedList list = {0};
140
141 LinkedListItem a = {0};
142 LinkedListItem b = {0};
143 LinkedListItem c = {0};
144
145 if(list.head != NULL || list.tail != NULL || list.size != 0)
146 {
147 TEST_FAILED(tracker, __func__, __LINE__);
148 }
149
150 kmip_linked_list_push(&list, &a);
151
152 if(list.head != &a || list.tail != &a || list.size != 1)
153 {
154 TEST_FAILED(tracker, __func__, __LINE__);
155 }
156
157 kmip_linked_list_push(&list, &b);
158
159 if(list.head != &b || list.tail != &a || list.size != 2)
160 {
161 TEST_FAILED(tracker, __func__, __LINE__);
162 }
163
164 kmip_linked_list_push(&list, &c);
165
166 if(list.head != &c || list.tail != &a || list.size != 3)
167 {
168 TEST_FAILED(tracker, __func__, __LINE__);
169 }
170
171 LinkedListItem *curr = list.head;
172 if(curr != &c || curr->next != &b || curr->prev != NULL)
173 {
174 TEST_FAILED(tracker, __func__, __LINE__);
175 }
176 curr = curr->next;
177 if(curr != &b || curr->next != &a || curr->prev != &c)
178 {
179 TEST_FAILED(tracker, __func__, __LINE__);
180 }
181 curr = curr->next;
182 if(curr != &a || curr->next != NULL || curr->prev != &b)
183 {
184 TEST_FAILED(tracker, __func__, __LINE__);
185 }
186
187 TEST_PASSED(tracker, __func__);
188 }
189
190 int
191 test_linked_list_pop(TestTracker *tracker)
192 {
193 TRACK_TEST(tracker);
194
195 LinkedList list = {0};
196
197 if(list.head != NULL || list.tail != NULL || list.size != 0)
198 {
199 TEST_FAILED(tracker, __func__, __LINE__);
200 }
201
202 LinkedListItem *item = kmip_linked_list_pop(&list);
203
204 if(item != NULL || list.head != NULL || list.tail != NULL || list.size != 0)
205 {
206 TEST_FAILED(tracker, __func__, __LINE__);
207 }
208
209 LinkedListItem a = {0};
210 LinkedListItem b = {0};
211 LinkedListItem c = {0};
212
213 a.next = &b;
214 a.prev = NULL;
215 b.next = &c;
216 b.prev = &a;
217 c.next = NULL;
218 c.prev = &b;
219
220 list.head = &a;
221 list.tail = &c;
222 list.size = 3;
223
224 item = kmip_linked_list_pop(&list);
225
226 if(item != &a || list.head != &b || list.tail != &c || list.size != 2)
227 {
228 TEST_FAILED(tracker, __func__, __LINE__);
229 }
230
231 item = kmip_linked_list_pop(&list);
232
233 if(item != &b || list.head != &c || list.tail != &c || list.size != 1)
234 {
235 TEST_FAILED(tracker, __func__, __LINE__);
236 }
237
238 item = kmip_linked_list_pop(&list);
239
240 if(item != &c || list.head != NULL || list.tail != NULL || list.size != 0)
241 {
242 TEST_FAILED(tracker, __func__, __LINE__);
243 }
244
245 TEST_PASSED(tracker, __func__);
246 }
247
248 int
249 test_linked_list_enqueue(TestTracker *tracker)
250 {
251 TRACK_TEST(tracker);
252
253 LinkedList list = {0};
254
255 LinkedListItem a = {0};
256 LinkedListItem b = {0};
257 LinkedListItem c = {0};
258
259 if(list.head != NULL || list.tail != NULL || list.size != 0)
260 {
261 TEST_FAILED(tracker, __func__, __LINE__);
262 }
263
264 kmip_linked_list_enqueue(&list, &a);
265
266 if(list.head != &a || list.tail != &a || list.size != 1)
267 {
268 TEST_FAILED(tracker, __func__, __LINE__);
269 }
270
271 kmip_linked_list_enqueue(&list, &b);
272
273 if(list.head != &a || list.tail != &b || list.size != 2)
274 {
275 TEST_FAILED(tracker, __func__, __LINE__);
276 }
277
278 kmip_linked_list_enqueue(&list, &c);
279
280 if(list.head != &a || list.tail != &c || list.size != 3)
281 {
282 TEST_FAILED(tracker, __func__, __LINE__);
283 }
284
285 LinkedListItem *curr = list.head;
286 if(curr != &a || curr->next != &b || curr->prev != NULL)
287 {
288 TEST_FAILED(tracker, __func__, __LINE__);
289 }
290 curr = curr->next;
291 if(curr != &b || curr->next != &c || curr->prev != &a)
292 {
293 TEST_FAILED(tracker, __func__, __LINE__);
294 }
295 curr = curr->next;
296 if(curr != &c || curr->next != NULL || curr->prev != &b)
297 {
298 TEST_FAILED(tracker, __func__, __LINE__);
299 }
300
301 TEST_PASSED(tracker, __func__);
302 }
303
304 int
305 test_buffer_full_and_resize(TestTracker *tracker)
306 {
307 TRACK_TEST(tracker);
308
309 uint8 expected[40] = {
310 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20,
311 0x42, 0x00, 0x6A, 0x02, 0x00, 0x00, 0x00, 0x04,
312 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
313 0x42, 0x00, 0x6B, 0x02, 0x00, 0x00, 0x00, 0x04,
314 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
315 };
316
317 uint8 too_small[30] = {0};
318 uint8 large_enough[40] = {0};
319 struct kmip ctx = {0};
320 kmip_init(&ctx, too_small, ARRAY_LENGTH(too_small), KMIP_1_0);
321
322 struct protocol_version pv = {0};
323 pv.major = 1;
324 pv.minor = 0;
325
326 int result = kmip_encode_protocol_version(&ctx, &pv);
327
328 if(result == KMIP_ERROR_BUFFER_FULL)
329 {
330 kmip_reset(&ctx);
331 kmip_set_buffer(&ctx, large_enough, ARRAY_LENGTH(large_enough));
332
333 result = kmip_encode_protocol_version(&ctx, &pv);
334 result = report_encoding_test_result(
335 tracker,
336 &ctx,
337 expected,
338 large_enough,
339 result,
340 __func__);
341
342 kmip_destroy(&ctx);
343
344 return(result);
345 }
346 else
347 {
348 printf("FAIL - %s\n", __func__);
349 printf("- expected buffer full\n");
350
351 kmip_destroy(&ctx);
352 tracker->tests_failed++;
353 return(1);
354 }
355 }
356
357 int
358 test_is_tag_next(TestTracker *tracker)
359 {
360 TRACK_TEST(tracker);
361
362 uint8 encoding[3] = {0x42, 0x00, 0x08};
363
364 struct kmip ctx = {0};
365 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
366
367 uint8 *before = ctx.index;
368 int result = 0;
369
370 if(kmip_is_tag_next(&ctx, KMIP_TAG_ATTRIBUTE) == KMIP_FALSE)
371 {
372 printf("FAIL - %s\n", __func__);
373 printf("- expected tag is not next\n");
374 tracker->tests_failed++;
375 result = 1;
376 }
377
378 uint8 *after = ctx.index;
379
380 if(before != after)
381 {
382 printf("FAIL - %s\n", __func__);
383 printf("- tag checking modifies context buffer index\n");
384 tracker->tests_failed++;
385 result = 1;
386 }
387
388 kmip_destroy(&ctx);
389
390 if(result == 0)
391 {
392 printf("PASS - %s\n", __func__);
393 tracker->tests_passed++;
394 }
395
396 return(result);
397 }
398
399 int
400 test_get_num_items_next(TestTracker *tracker)
401 {
402 TRACK_TEST(tracker);
403
404 uint8 encoding[168] = {
405 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
406 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x17,
407 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
408 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x41, 0x6C,
409 0x67, 0x6F, 0x72, 0x69, 0x74, 0x68, 0x6D, 0x00,
410 0x42, 0x00, 0x0B, 0x05, 0x00, 0x00, 0x00, 0x04,
411 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
412 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
413 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x14,
414 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
415 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x4C, 0x65,
416 0x6E, 0x67, 0x74, 0x68, 0x00, 0x00, 0x00, 0x00,
417 0x42, 0x00, 0x0B, 0x02, 0x00, 0x00, 0x00, 0x04,
418 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
419 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
420 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x18,
421 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
422 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x55, 0x73,
423 0x61, 0x67, 0x65, 0x20, 0x4D, 0x61, 0x73, 0x6B,
424 0x42, 0x00, 0x0B, 0x02, 0x00, 0x00, 0x00, 0x04,
425 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00
426 };
427
428 struct kmip ctx = {0};
429 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
430
431 uint8 *before = ctx.index;
432 int result = 0;
433 int count = 0;
434
435 count = kmip_get_num_items_next(&ctx, KMIP_TAG_ATTRIBUTE);
436 if(count != 3)
437 {
438 printf("FAIL - %s\n", __func__);
439 printf("- expected item count not found (exp. 3, obs. %d)\n",
440 count);
441 tracker->tests_failed++;
442 result = 1;
443 }
444
445 uint8 *after = ctx.index;
446
447 if(before != after)
448 {
449 printf("FAIL - %s\n", __func__);
450 printf("- item count checking modifies context buffer index\n");
451 tracker->tests_failed++;
452 result = 1;
453 }
454
455 kmip_destroy(&ctx);
456
457 if(result == 0)
458 {
459 printf("PASS - %s\n", __func__);
460 tracker->tests_passed++;
461 }
462
463 return(result);
464 }
465
466 int
467 test_get_num_items_next_with_partial_item(TestTracker *tracker)
468 {
469 TRACK_TEST(tracker);
470
471 uint8 encoding[136] = {
472 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
473 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x14,
474 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
475 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x4C, 0x65,
476 0x6E, 0x67, 0x74, 0x68, 0x00, 0x00, 0x00, 0x00,
477 0x42, 0x00, 0x0B, 0x02, 0x00, 0x00, 0x00, 0x04,
478 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
479 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
480 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x18,
481 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
482 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x55, 0x73,
483 0x61, 0x67, 0x65, 0x20, 0x4D, 0x61, 0x73, 0x6B,
484 0x42, 0x00, 0x0B, 0x02, 0x00, 0x00, 0x00, 0x04,
485 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00,
486 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
487 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x18,
488 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72
489 };
490
491 struct kmip ctx = {0};
492 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
493
494 uint8 *before = ctx.index;
495 int result = 0;
496 int count = 0;
497
498 count = kmip_get_num_items_next(&ctx, KMIP_TAG_ATTRIBUTE);
499 if(count != 2)
500 {
501 printf("FAIL - %s\n", __func__);
502 printf("- expected item count not found (exp. 2, obs. %d)\n",
503 count);
504 tracker->tests_failed++;
505 result = 1;
506 }
507
508 uint8 *after = ctx.index;
509
510 if(before != after)
511 {
512 printf("FAIL - %s\n", __func__);
513 printf("- item count checking modifies context buffer index\n");
514 tracker->tests_failed++;
515 result = 1;
516 }
517
518 kmip_destroy(&ctx);
519
520 if(result == 0)
521 {
522 printf("PASS - %s\n", __func__);
523 tracker->tests_passed++;
524 }
525
526 return(result);
527 }
528
529 int
530 test_get_num_items_next_with_mismatch_item(TestTracker *tracker)
531 {
532 TRACK_TEST(tracker);
533
534 uint8 encoding[80] = {
535 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
536 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x18,
537 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
538 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x55, 0x73,
539 0x61, 0x67, 0x65, 0x20, 0x4D, 0x61, 0x73, 0x6B,
540 0x42, 0x00, 0x0B, 0x02, 0x00, 0x00, 0x00, 0x04,
541 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00,
542 0x42, 0x00, 0x20, 0x01, 0x00, 0x00, 0x00, 0x30,
543 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x18,
544 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72
545 };
546
547 struct kmip ctx = {0};
548 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
549
550 uint8 *before = ctx.index;
551 int result = 0;
552 int count = 0;
553
554 count = kmip_get_num_items_next(&ctx, KMIP_TAG_ATTRIBUTE);
555 if(count != 1)
556 {
557 printf("FAIL - %s\n", __func__);
558 printf("- expected item count not found (exp. 1, obs. %d)\n",
559 count);
560 tracker->tests_failed++;
561 result = 1;
562 }
563
564 uint8 *after = ctx.index;
565
566 if(before != after)
567 {
568 printf("FAIL - %s\n", __func__);
569 printf("- item count checking modifies context buffer index\n");
570 tracker->tests_failed++;
571 result = 1;
572 }
573
574 kmip_destroy(&ctx);
575
576 if(result == 0)
577 {
578 printf("PASS - %s\n", __func__);
579 tracker->tests_passed++;
580 }
581
582 return(result);
583 }
584
585 int
586 test_get_num_items_next_with_no_matches(TestTracker *tracker)
587 {
588 TRACK_TEST(tracker);
589
590 uint8 encoding[80] = {
591 0x42, 0x00, 0x20, 0x01, 0x00, 0x00, 0x00, 0x30,
592 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x18,
593 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
594 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x55, 0x73,
595 0x61, 0x67, 0x65, 0x20, 0x4D, 0x61, 0x73, 0x6B,
596 0x42, 0x00, 0x0B, 0x02, 0x00, 0x00, 0x00, 0x04,
597 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00,
598 0x42, 0x00, 0x20, 0x01, 0x00, 0x00, 0x00, 0x30,
599 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x18,
600 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72
601 };
602
603 struct kmip ctx = {0};
604 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
605
606 uint8 *before = ctx.index;
607 int result = 0;
608 int count = 0;
609
610 count = kmip_get_num_items_next(&ctx, KMIP_TAG_ATTRIBUTE);
611 if(count != 0)
612 {
613 printf("FAIL - %s\n", __func__);
614 printf("- expected item count not found (exp. 0, obs. %d)\n",
615 count);
616 tracker->tests_failed++;
617 result = 1;
618 }
619
620 uint8 *after = ctx.index;
621
622 if(before != after)
623 {
624 printf("FAIL - %s\n", __func__);
625 printf("- item count checking modifies context buffer index\n");
626 tracker->tests_failed++;
627 result = 1;
628 }
629
630 kmip_destroy(&ctx);
631
632 if(result == 0)
633 {
634 printf("PASS - %s\n", __func__);
635 tracker->tests_passed++;
636 }
637
638 return(result);
639 }
640
641 int
642 test_get_num_items_next_with_non_structures(TestTracker *tracker)
643 {
644 TRACK_TEST(tracker);
645
646 uint8 encoding[144] = {
647 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x26,
648 0x31, 0x30, 0x30, 0x31, 0x38, 0x32, 0x64, 0x35,
649 0x2D, 0x37, 0x32, 0x62, 0x38, 0x2D, 0x34, 0x37,
650 0x61, 0x61, 0x2D, 0x38, 0x33, 0x38, 0x33, 0x2D,
651 0x34, 0x64, 0x39, 0x37, 0x64, 0x35, 0x31, 0x32,
652 0x65, 0x39, 0x38, 0x61, 0x11, 0x11, 0x00, 0x00,
653 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x25,
654 0x31, 0x30, 0x30, 0x31, 0x38, 0x32, 0x64, 0x35,
655 0x2D, 0x37, 0x32, 0x62, 0x38, 0x2D, 0x34, 0x37,
656 0x61, 0x61, 0x2D, 0x38, 0x33, 0x38, 0x33, 0x2D,
657 0x34, 0x64, 0x39, 0x37, 0x64, 0x35, 0x31, 0x32,
658 0x65, 0x39, 0x38, 0x61, 0x11, 0x00, 0x00, 0x00,
659 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
660 0x31, 0x30, 0x30, 0x31, 0x38, 0x32, 0x64, 0x35,
661 0x2D, 0x37, 0x32, 0x62, 0x38, 0x2D, 0x34, 0x37,
662 0x61, 0x61, 0x2D, 0x38, 0x33, 0x38, 0x33, 0x2D,
663 0x34, 0x64, 0x39, 0x37, 0x64, 0x35, 0x31, 0x32,
664 0x65, 0x39, 0x38, 0x61, 0x00, 0x00, 0x00, 0x00
665 };
666
667 struct kmip ctx = {0};
668 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
669
670 uint8 *before = ctx.index;
671 int result = 0;
672 int count = 0;
673
674 count = kmip_get_num_items_next(&ctx, KMIP_TAG_UNIQUE_IDENTIFIER);
675 if(count != 3)
676 {
677 printf("FAIL - %s\n", __func__);
678 printf("- expected item count not found (exp. 3, obs. %d)\n",
679 count);
680 tracker->tests_failed++;
681 result = 1;
682 }
683
684 uint8 *after = ctx.index;
685
686 if(before != after)
687 {
688 printf("FAIL - %s\n", __func__);
689 printf("- item count checking modifies context buffer index\n");
690 tracker->tests_failed++;
691 result = 1;
692 }
693
694 kmip_destroy(&ctx);
695
696 if(result == 0)
697 {
698 printf("PASS - %s\n", __func__);
699 tracker->tests_passed++;
700 }
701
702 return(result);
703 }
704
705 int
706 test_buffer_bytes_left(TestTracker *tracker)
707 {
708 TRACK_TEST(tracker);
709
710 uint8 a[1] = {0x42};
711 uint8 b[3] = {0x42, 0x00, 0x08};
712 uint8 c[5] = {0x42, 0x00, 0x53, 0x01, 0x00};
713
714 KMIP ctx = {0};
715 kmip_init(&ctx, a, ARRAY_LENGTH(a), KMIP_1_0);
716
717 if(BUFFER_BYTES_LEFT(&ctx) != 1)
718 {
719 kmip_destroy(&ctx);
720 TEST_FAILED(tracker, __func__, __LINE__);
721 }
722
723 kmip_destroy(&ctx);
724 kmip_init(&ctx, b, ARRAY_LENGTH(b), KMIP_1_0);
725
726 if(BUFFER_BYTES_LEFT(&ctx) != 3)
727 {
728 kmip_destroy(&ctx);
729 TEST_FAILED(tracker, __func__, __LINE__);
730 }
731
732 kmip_destroy(&ctx);
733 kmip_init(&ctx, c, ARRAY_LENGTH(c), KMIP_1_0);
734
735 if(BUFFER_BYTES_LEFT(&ctx) != 5)
736 {
737 kmip_destroy(&ctx);
738 TEST_FAILED(tracker, __func__, __LINE__);
739 }
740
741 kmip_destroy(&ctx);
742
743 TEST_PASSED(tracker, __func__);
744 }
745
746 int
747 test_get_num_attributes_next(TestTracker *tracker)
748 {
749 TRACK_TEST(tracker);
750
751 /* Need to build an encoding with one of each type of support
752 attribute. Verify that this function returns the correct
753 count.
754
755 Need to build an encoding with bad attribute length? Handle
756 weird corner cases?
757 */
758 TEST_FAILED(tracker, __func__, __LINE__);
759 }
760
761 int
762 test_peek_tag(TestTracker *tracker)
763 {
764 TRACK_TEST(tracker);
765
766 /* Build an encoding with an arbitrary tag value. Verify that this
767 function reads and returns this tag value without changing the
768 context buffer.
769 */
770
771 uint8 underfull_encoding[1] = {0x42};
772 uint8 full_encoding[3] = {0x42, 0x00, 0x08};
773 uint8 overfull_encoding[5] = {0x42, 0x00, 0x53, 0x01, 0x00};
774
775 uint32 tag = 0;
776 uint8 *prev_buffer = NULL;
777 uint8 *prev_index = NULL;
778 size_t prev_size = 0;
779 KMIP ctx = {0};
780 kmip_init(&ctx, underfull_encoding, ARRAY_LENGTH(underfull_encoding), KMIP_1_0);
781
782 prev_buffer = ctx.buffer;
783 prev_index = ctx.index;
784 prev_size = ctx.size;
785 tag = kmip_peek_tag(&ctx);
786 if(tag != 0 || ctx.buffer != prev_buffer || ctx.index != prev_index || ctx.size != prev_size)
787 {
788 TEST_FAILED(tracker, __func__, __LINE__);
789 }
790
791 kmip_destroy(&ctx);
792 kmip_init(&ctx, full_encoding, ARRAY_LENGTH(full_encoding), KMIP_1_0);
793
794 prev_buffer = ctx.buffer;
795 prev_index = ctx.index;
796 prev_size = ctx.size;
797 tag = kmip_peek_tag(&ctx);
798 if(tag != KMIP_TAG_ATTRIBUTE || ctx.buffer != prev_buffer || ctx.index != prev_index || ctx.size != prev_size)
799 {
800 TEST_FAILED(tracker, __func__, __LINE__);
801 }
802
803 kmip_destroy(&ctx);
804 kmip_init(&ctx, overfull_encoding, ARRAY_LENGTH(overfull_encoding), KMIP_1_0);
805
806 prev_buffer = ctx.buffer;
807 prev_index = ctx.index;
808 prev_size = ctx.size;
809 tag = kmip_peek_tag(&ctx);
810 if(tag != KMIP_TAG_NAME || ctx.buffer != prev_buffer || ctx.index != prev_index || ctx.size != prev_size)
811 {
812 TEST_FAILED(tracker, __func__, __LINE__);
813 }
814
815 kmip_destroy(&ctx);
816
817 TEST_PASSED(tracker, __func__);
818 }
819
820 int
821 test_is_attribute_tag(TestTracker *tracker)
822 {
823 TRACK_TEST(tracker);
824
825 if(!kmip_is_attribute_tag(KMIP_TAG_UNIQUE_IDENTIFIER))
826 {
827 TEST_FAILED(tracker, __func__, __LINE__);
828 }
829 if(!kmip_is_attribute_tag(KMIP_TAG_NAME))
830 {
831 TEST_FAILED(tracker, __func__, __LINE__);
832 }
833 if(!kmip_is_attribute_tag(KMIP_TAG_OBJECT_TYPE))
834 {
835 TEST_FAILED(tracker, __func__, __LINE__);
836 }
837 if(!kmip_is_attribute_tag(KMIP_TAG_CRYPTOGRAPHIC_ALGORITHM))
838 {
839 TEST_FAILED(tracker, __func__, __LINE__);
840 }
841 if(!kmip_is_attribute_tag(KMIP_TAG_CRYPTOGRAPHIC_LENGTH))
842 {
843 TEST_FAILED(tracker, __func__, __LINE__);
844 }
845 if(!kmip_is_attribute_tag(KMIP_TAG_CRYPTOGRAPHIC_PARAMETERS))
846 {
847 TEST_FAILED(tracker, __func__, __LINE__);
848 }
849 if(!kmip_is_attribute_tag(KMIP_TAG_CRYPTOGRAPHIC_DOMAIN_PARAMETERS))
850 {
851 TEST_FAILED(tracker, __func__, __LINE__);
852 }
853 if(!kmip_is_attribute_tag(KMIP_TAG_CERTIFICATE_TYPE))
854 {
855 TEST_FAILED(tracker, __func__, __LINE__);
856 }
857 if(!kmip_is_attribute_tag(KMIP_TAG_CERTIFICATE_LENGTH))
858 {
859 TEST_FAILED(tracker, __func__, __LINE__);
860 }
861 if(!kmip_is_attribute_tag(KMIP_TAG_X509_CERTIFICATE_IDENTIFIER))
862 {
863 TEST_FAILED(tracker, __func__, __LINE__);
864 }
865 if(!kmip_is_attribute_tag(KMIP_TAG_X509_CERTIFICATE_SUBJECT))
866 {
867 TEST_FAILED(tracker, __func__, __LINE__);
868 }
869 if(!kmip_is_attribute_tag(KMIP_TAG_X509_CERTIFICATE_ISSUER))
870 {
871 TEST_FAILED(tracker, __func__, __LINE__);
872 }
873 if(!kmip_is_attribute_tag(KMIP_TAG_CERTIFICATE_IDENTIFIER))
874 {
875 TEST_FAILED(tracker, __func__, __LINE__);
876 }
877 if(!kmip_is_attribute_tag(KMIP_TAG_CERTIFICATE_SUBJECT))
878 {
879 TEST_FAILED(tracker, __func__, __LINE__);
880 }
881 if(!kmip_is_attribute_tag(KMIP_TAG_CERTIFICATE_ISSUER))
882 {
883 TEST_FAILED(tracker, __func__, __LINE__);
884 }
885 if(!kmip_is_attribute_tag(KMIP_TAG_DIGITAL_SIGNATURE_ALGORITHM))
886 {
887 TEST_FAILED(tracker, __func__, __LINE__);
888 }
889 if(!kmip_is_attribute_tag(KMIP_TAG_DIGEST))
890 {
891 TEST_FAILED(tracker, __func__, __LINE__);
892 }
893 if(!kmip_is_attribute_tag(KMIP_TAG_OPERATION_POLICY_NAME))
894 {
895 TEST_FAILED(tracker, __func__, __LINE__);
896 }
897 if(!kmip_is_attribute_tag(KMIP_TAG_CRYPTOGRAPHIC_USAGE_MASK))
898 {
899 TEST_FAILED(tracker, __func__, __LINE__);
900 }
901 if(!kmip_is_attribute_tag(KMIP_TAG_LEASE_TIME))
902 {
903 TEST_FAILED(tracker, __func__, __LINE__);
904 }
905 if(!kmip_is_attribute_tag(KMIP_TAG_USAGE_LIMITS))
906 {
907 TEST_FAILED(tracker, __func__, __LINE__);
908 }
909 if(!kmip_is_attribute_tag(KMIP_TAG_STATE))
910 {
911 TEST_FAILED(tracker, __func__, __LINE__);
912 }
913 if(!kmip_is_attribute_tag(KMIP_TAG_INITIAL_DATE))
914 {
915 TEST_FAILED(tracker, __func__, __LINE__);
916 }
917 if(!kmip_is_attribute_tag(KMIP_TAG_ACTIVATION_DATE))
918 {
919 TEST_FAILED(tracker, __func__, __LINE__);
920 }
921 if(!kmip_is_attribute_tag(KMIP_TAG_PROCESS_START_DATE))
922 {
923 TEST_FAILED(tracker, __func__, __LINE__);
924 }
925 if(!kmip_is_attribute_tag(KMIP_TAG_PROTECT_STOP_DATE))
926 {
927 TEST_FAILED(tracker, __func__, __LINE__);
928 }
929 if(!kmip_is_attribute_tag(KMIP_TAG_DEACTIVATION_DATE))
930 {
931 TEST_FAILED(tracker, __func__, __LINE__);
932 }
933 if(!kmip_is_attribute_tag(KMIP_TAG_DESTROY_DATE))
934 {
935 TEST_FAILED(tracker, __func__, __LINE__);
936 }
937 if(!kmip_is_attribute_tag(KMIP_TAG_COMPROMISE_OCCURRENCE_DATE))
938 {
939 TEST_FAILED(tracker, __func__, __LINE__);
940 }
941 if(!kmip_is_attribute_tag(KMIP_TAG_COMPROMISE_DATE))
942 {
943 TEST_FAILED(tracker, __func__, __LINE__);
944 }
945 if(!kmip_is_attribute_tag(KMIP_TAG_REVOCATION_REASON))
946 {
947 TEST_FAILED(tracker, __func__, __LINE__);
948 }
949 if(!kmip_is_attribute_tag(KMIP_TAG_ARCHIVE_DATE))
950 {
951 TEST_FAILED(tracker, __func__, __LINE__);
952 }
953 if(!kmip_is_attribute_tag(KMIP_TAG_OBJECT_GROUP))
954 {
955 TEST_FAILED(tracker, __func__, __LINE__);
956 }
957 if(!kmip_is_attribute_tag(KMIP_TAG_FRESH))
958 {
959 TEST_FAILED(tracker, __func__, __LINE__);
960 }
961 if(!kmip_is_attribute_tag(KMIP_TAG_LINK))
962 {
963 TEST_FAILED(tracker, __func__, __LINE__);
964 }
965 if(!kmip_is_attribute_tag(KMIP_TAG_APPLICATION_SPECIFIC_INFORMATION))
966 {
967 TEST_FAILED(tracker, __func__, __LINE__);
968 }
969 if(!kmip_is_attribute_tag(KMIP_TAG_CONTACT_INFORMATION))
970 {
971 TEST_FAILED(tracker, __func__, __LINE__);
972 }
973 if(!kmip_is_attribute_tag(KMIP_TAG_LAST_CHANGE_DATE))
974 {
975 TEST_FAILED(tracker, __func__, __LINE__);
976 }
977 if(!kmip_is_attribute_tag(KMIP_TAG_ALTERNATIVE_NAME))
978 {
979 TEST_FAILED(tracker, __func__, __LINE__);
980 }
981 if(!kmip_is_attribute_tag(KMIP_TAG_KEY_VALUE_PRESENT))
982 {
983 TEST_FAILED(tracker, __func__, __LINE__);
984 }
985 if(!kmip_is_attribute_tag(KMIP_TAG_KEY_VALUE_LOCATION))
986 {
987 TEST_FAILED(tracker, __func__, __LINE__);
988 }
989 if(!kmip_is_attribute_tag(KMIP_TAG_ORIGINAL_CREATION_DATE))
990 {
991 TEST_FAILED(tracker, __func__, __LINE__);
992 }
993 if(!kmip_is_attribute_tag(KMIP_TAG_RANDOM_NUMBER_GENERATOR))
994 {
995 TEST_FAILED(tracker, __func__, __LINE__);
996 }
997 if(!kmip_is_attribute_tag(KMIP_TAG_PKCS_12_FRIENDLY_NAME))
998 {
999 TEST_FAILED(tracker, __func__, __LINE__);
1000 }
1001 if(!kmip_is_attribute_tag(KMIP_TAG_DESCRIPTION))
1002 {
1003 TEST_FAILED(tracker, __func__, __LINE__);
1004 }
1005 if(!kmip_is_attribute_tag(KMIP_TAG_COMMENT))
1006 {
1007 TEST_FAILED(tracker, __func__, __LINE__);
1008 }
1009 if(!kmip_is_attribute_tag(KMIP_TAG_SENSITIVE))
1010 {
1011 TEST_FAILED(tracker, __func__, __LINE__);
1012 }
1013 if(!kmip_is_attribute_tag(KMIP_TAG_ALWAYS_SENSITIVE))
1014 {
1015 TEST_FAILED(tracker, __func__, __LINE__);
1016 }
1017 if(!kmip_is_attribute_tag(KMIP_TAG_EXTRACTABLE))
1018 {
1019 TEST_FAILED(tracker, __func__, __LINE__);
1020 }
1021 if(!kmip_is_attribute_tag(KMIP_TAG_NEVER_EXTRACTABLE))
1022 {
1023 TEST_FAILED(tracker, __func__, __LINE__);
1024 }
1025 if(!kmip_is_attribute_tag(KMIP_TAG_KEY_FORMAT_TYPE))
1026 {
1027 TEST_FAILED(tracker, __func__, __LINE__);
1028 }
1029
1030 if(kmip_is_attribute_tag(KMIP_TAG_REQUEST_MESSAGE))
1031 {
1032 TEST_FAILED(tracker, __func__, __LINE__);
1033 }
1034
1035 TEST_PASSED(tracker, __func__);
1036 }
1037
1038 int
1039 test_get_enum_string_index(TestTracker *tracker)
1040 {
1041 TRACK_TEST(tracker);
1042
1043 if(kmip_get_enum_string_index(KMIP_TAG_UNIQUE_IDENTIFIER) != 0)
1044 {
1045 TEST_FAILED(tracker, __func__, __LINE__);
1046 }
1047
1048 if(kmip_get_enum_string_index(KMIP_TAG_NAME) != 1)
1049 {
1050 TEST_FAILED(tracker, __func__, __LINE__);
1051 }
1052
1053 if(kmip_get_enum_string_index(KMIP_TAG_OBJECT_TYPE) != 2)
1054 {
1055 TEST_FAILED(tracker, __func__, __LINE__);
1056 }
1057
1058 if(kmip_get_enum_string_index(KMIP_TAG_CRYPTOGRAPHIC_ALGORITHM) != 3)
1059 {
1060 TEST_FAILED(tracker, __func__, __LINE__);
1061 }
1062
1063 if(kmip_get_enum_string_index(KMIP_TAG_CRYPTOGRAPHIC_LENGTH) != 4)
1064 {
1065 TEST_FAILED(tracker, __func__, __LINE__);
1066 }
1067
1068 if(kmip_get_enum_string_index(KMIP_TAG_CRYPTOGRAPHIC_PARAMETERS) != 5)
1069 {
1070 TEST_FAILED(tracker, __func__, __LINE__);
1071 }
1072
1073 if(kmip_get_enum_string_index(KMIP_TAG_CRYPTOGRAPHIC_DOMAIN_PARAMETERS) != 6)
1074 {
1075 TEST_FAILED(tracker, __func__, __LINE__);
1076 }
1077
1078 if(kmip_get_enum_string_index(KMIP_TAG_CERTIFICATE_TYPE) != 7)
1079 {
1080 TEST_FAILED(tracker, __func__, __LINE__);
1081 }
1082
1083 if(kmip_get_enum_string_index(KMIP_TAG_CERTIFICATE_LENGTH) != 8)
1084 {
1085 TEST_FAILED(tracker, __func__, __LINE__);
1086 }
1087
1088 if(kmip_get_enum_string_index(KMIP_TAG_X509_CERTIFICATE_IDENTIFIER) != 9)
1089 {
1090 TEST_FAILED(tracker, __func__, __LINE__);
1091 }
1092
1093 if(kmip_get_enum_string_index(KMIP_TAG_X509_CERTIFICATE_SUBJECT) != 10)
1094 {
1095 TEST_FAILED(tracker, __func__, __LINE__);
1096 }
1097
1098 if(kmip_get_enum_string_index(KMIP_TAG_X509_CERTIFICATE_ISSUER) != 11)
1099 {
1100 TEST_FAILED(tracker, __func__, __LINE__);
1101 }
1102
1103 if(kmip_get_enum_string_index(KMIP_TAG_CERTIFICATE_IDENTIFIER) != 12)
1104 {
1105 TEST_FAILED(tracker, __func__, __LINE__);
1106 }
1107
1108 if(kmip_get_enum_string_index(KMIP_TAG_CERTIFICATE_SUBJECT) != 13)
1109 {
1110 TEST_FAILED(tracker, __func__, __LINE__);
1111 }
1112
1113 if(kmip_get_enum_string_index(KMIP_TAG_CERTIFICATE_ISSUER) != 14)
1114 {
1115 TEST_FAILED(tracker, __func__, __LINE__);
1116 }
1117
1118 if(kmip_get_enum_string_index(KMIP_TAG_DIGITAL_SIGNATURE_ALGORITHM) != 15)
1119 {
1120 TEST_FAILED(tracker, __func__, __LINE__);
1121 }
1122
1123 if(kmip_get_enum_string_index(KMIP_TAG_DIGEST) != 16)
1124 {
1125 TEST_FAILED(tracker, __func__, __LINE__);
1126 }
1127
1128 if(kmip_get_enum_string_index(KMIP_TAG_OPERATION_POLICY_NAME) != 17)
1129 {
1130 TEST_FAILED(tracker, __func__, __LINE__);
1131 }
1132
1133 if(kmip_get_enum_string_index(KMIP_TAG_CRYPTOGRAPHIC_USAGE_MASK) != 18)
1134 {
1135 TEST_FAILED(tracker, __func__, __LINE__);
1136 }
1137
1138 if(kmip_get_enum_string_index(KMIP_TAG_LEASE_TIME) != 19)
1139 {
1140 TEST_FAILED(tracker, __func__, __LINE__);
1141 }
1142
1143 if(kmip_get_enum_string_index(KMIP_TAG_USAGE_LIMITS) != 20)
1144 {
1145 TEST_FAILED(tracker, __func__, __LINE__);
1146 }
1147
1148 if(kmip_get_enum_string_index(KMIP_TAG_STATE) != 21)
1149 {
1150 TEST_FAILED(tracker, __func__, __LINE__);
1151 }
1152
1153 if(kmip_get_enum_string_index(KMIP_TAG_INITIAL_DATE) != 22)
1154 {
1155 TEST_FAILED(tracker, __func__, __LINE__);
1156 }
1157
1158 if(kmip_get_enum_string_index(KMIP_TAG_ACTIVATION_DATE) != 23)
1159 {
1160 TEST_FAILED(tracker, __func__, __LINE__);
1161 }
1162
1163 if(kmip_get_enum_string_index(KMIP_TAG_PROCESS_START_DATE) != 24)
1164 {
1165 TEST_FAILED(tracker, __func__, __LINE__);
1166 }
1167
1168 if(kmip_get_enum_string_index(KMIP_TAG_PROTECT_STOP_DATE) != 25)
1169 {
1170 TEST_FAILED(tracker, __func__, __LINE__);
1171 }
1172
1173 if(kmip_get_enum_string_index(KMIP_TAG_DEACTIVATION_DATE) != 26)
1174 {
1175 TEST_FAILED(tracker, __func__, __LINE__);
1176 }
1177
1178 if(kmip_get_enum_string_index(KMIP_TAG_DESTROY_DATE) != 27)
1179 {
1180 TEST_FAILED(tracker, __func__, __LINE__);
1181 }
1182
1183 if(kmip_get_enum_string_index(KMIP_TAG_COMPROMISE_OCCURRENCE_DATE) != 28)
1184 {
1185 TEST_FAILED(tracker, __func__, __LINE__);
1186 }
1187
1188 if(kmip_get_enum_string_index(KMIP_TAG_COMPROMISE_DATE) != 29)
1189 {
1190 TEST_FAILED(tracker, __func__, __LINE__);
1191 }
1192
1193 if(kmip_get_enum_string_index(KMIP_TAG_REVOCATION_REASON) != 30)
1194 {
1195 TEST_FAILED(tracker, __func__, __LINE__);
1196 }
1197
1198 if(kmip_get_enum_string_index(KMIP_TAG_ARCHIVE_DATE) != 31)
1199 {
1200 TEST_FAILED(tracker, __func__, __LINE__);
1201 }
1202
1203 if(kmip_get_enum_string_index(KMIP_TAG_OBJECT_GROUP) != 32)
1204 {
1205 TEST_FAILED(tracker, __func__, __LINE__);
1206 }
1207
1208 if(kmip_get_enum_string_index(KMIP_TAG_FRESH) != 33)
1209 {
1210 TEST_FAILED(tracker, __func__, __LINE__);
1211 }
1212
1213 if(kmip_get_enum_string_index(KMIP_TAG_LINK) != 34)
1214 {
1215 TEST_FAILED(tracker, __func__, __LINE__);
1216 }
1217
1218 if(kmip_get_enum_string_index(KMIP_TAG_APPLICATION_SPECIFIC_INFORMATION) != 35)
1219 {
1220 TEST_FAILED(tracker, __func__, __LINE__);
1221 }
1222
1223 if(kmip_get_enum_string_index(KMIP_TAG_CONTACT_INFORMATION) != 36)
1224 {
1225 TEST_FAILED(tracker, __func__, __LINE__);
1226 }
1227
1228 if(kmip_get_enum_string_index(KMIP_TAG_LAST_CHANGE_DATE) != 37)
1229 {
1230 TEST_FAILED(tracker, __func__, __LINE__);
1231 }
1232
1233 if(kmip_get_enum_string_index(KMIP_TAG_ALTERNATIVE_NAME) != 38)
1234 {
1235 TEST_FAILED(tracker, __func__, __LINE__);
1236 }
1237
1238 if(kmip_get_enum_string_index(KMIP_TAG_KEY_VALUE_PRESENT) != 39)
1239 {
1240 TEST_FAILED(tracker, __func__, __LINE__);
1241 }
1242
1243 if(kmip_get_enum_string_index(KMIP_TAG_KEY_VALUE_LOCATION) != 40)
1244 {
1245 TEST_FAILED(tracker, __func__, __LINE__);
1246 }
1247
1248 if(kmip_get_enum_string_index(KMIP_TAG_ORIGINAL_CREATION_DATE) != 41)
1249 {
1250 TEST_FAILED(tracker, __func__, __LINE__);
1251 }
1252
1253 if(kmip_get_enum_string_index(KMIP_TAG_RANDOM_NUMBER_GENERATOR) != 42)
1254 {
1255 TEST_FAILED(tracker, __func__, __LINE__);
1256 }
1257
1258 if(kmip_get_enum_string_index(KMIP_TAG_PKCS_12_FRIENDLY_NAME) != 43)
1259 {
1260 TEST_FAILED(tracker, __func__, __LINE__);
1261 }
1262
1263 if(kmip_get_enum_string_index(KMIP_TAG_DESCRIPTION) != 44)
1264 {
1265 TEST_FAILED(tracker, __func__, __LINE__);
1266 }
1267
1268 if(kmip_get_enum_string_index(KMIP_TAG_COMMENT) != 45)
1269 {
1270 TEST_FAILED(tracker, __func__, __LINE__);
1271 }
1272
1273 if(kmip_get_enum_string_index(KMIP_TAG_SENSITIVE) != 46)
1274 {
1275 TEST_FAILED(tracker, __func__, __LINE__);
1276 }
1277
1278 if(kmip_get_enum_string_index(KMIP_TAG_ALWAYS_SENSITIVE) != 47)
1279 {
1280 TEST_FAILED(tracker, __func__, __LINE__);
1281 }
1282
1283 if(kmip_get_enum_string_index(KMIP_TAG_EXTRACTABLE) != 48)
1284 {
1285 TEST_FAILED(tracker, __func__, __LINE__);
1286 }
1287
1288 if(kmip_get_enum_string_index(KMIP_TAG_NEVER_EXTRACTABLE) != 49)
1289 {
1290 TEST_FAILED(tracker, __func__, __LINE__);
1291 }
1292
1293 if(kmip_get_enum_string_index(KMIP_TAG_KEY_FORMAT_TYPE) != 50)
1294 {
1295 TEST_FAILED(tracker, __func__, __LINE__);
1296 }
1297
1298 if(kmip_get_enum_string_index(-1) != 51)
1299 {
1300 TEST_FAILED(tracker, __func__, __LINE__);
1301 }
1302
1303 TEST_PASSED(tracker, __func__);
1304 }
1305
1306 int
1307 test_check_enum_value_protection_storage_masks(TestTracker *tracker)
1308 {
1309 TRACK_TEST(tracker);
1310
1311 enum kmip_version v = KMIP_2_0;
1312 enum tag t = KMIP_TAG_PROTECTION_STORAGE_MASK;
1313
1314 if(kmip_check_enum_value(v, t, KMIP_PROTECT_SOFTWARE) != KMIP_OK)
1315 {
1316 TEST_FAILED(tracker, __func__, __LINE__);
1317 }
1318
1319 if(kmip_check_enum_value(v, t, KMIP_PROTECT_HARDWARE) != KMIP_OK)
1320 {
1321 TEST_FAILED(tracker, __func__, __LINE__);
1322 }
1323
1324 if(kmip_check_enum_value(v, t, KMIP_PROTECT_ON_PROCESSOR) != KMIP_OK)
1325 {
1326 TEST_FAILED(tracker, __func__, __LINE__);
1327 }
1328
1329 if(kmip_check_enum_value(v, t, KMIP_PROTECT_ON_SYSTEM) != KMIP_OK)
1330 {
1331 TEST_FAILED(tracker, __func__, __LINE__);
1332 }
1333
1334 if(kmip_check_enum_value(v, t, KMIP_PROTECT_OFF_SYSTEM) != KMIP_OK)
1335 {
1336 TEST_FAILED(tracker, __func__, __LINE__);
1337 }
1338
1339 if(kmip_check_enum_value(v, t, KMIP_PROTECT_HYPERVISOR) != KMIP_OK)
1340 {
1341 TEST_FAILED(tracker, __func__, __LINE__);
1342 }
1343
1344 if(kmip_check_enum_value(v, t, KMIP_PROTECT_OPERATING_SYSTEM) != KMIP_OK)
1345 {
1346 TEST_FAILED(tracker, __func__, __LINE__);
1347 }
1348
1349 if(kmip_check_enum_value(v, t, KMIP_PROTECT_CONTAINER) != KMIP_OK)
1350 {
1351 TEST_FAILED(tracker, __func__, __LINE__);
1352 }
1353
1354 if(kmip_check_enum_value(v, t, KMIP_PROTECT_ON_PREMISES) != KMIP_OK)
1355 {
1356 TEST_FAILED(tracker, __func__, __LINE__);
1357 }
1358
1359 if(kmip_check_enum_value(v, t, KMIP_PROTECT_OFF_PREMISES) != KMIP_OK)
1360 {
1361 TEST_FAILED(tracker, __func__, __LINE__);
1362 }
1363
1364 if(kmip_check_enum_value(v, t, KMIP_PROTECT_SELF_MANAGED) != KMIP_OK)
1365 {
1366 TEST_FAILED(tracker, __func__, __LINE__);
1367 }
1368
1369 if(kmip_check_enum_value(v, t, KMIP_PROTECT_OUTSOURCED) != KMIP_OK)
1370 {
1371 TEST_FAILED(tracker, __func__, __LINE__);
1372 }
1373
1374 if(kmip_check_enum_value(v, t, KMIP_PROTECT_VALIDATED) != KMIP_OK)
1375 {
1376 TEST_FAILED(tracker, __func__, __LINE__);
1377 }
1378
1379 if(kmip_check_enum_value(v, t, KMIP_PROTECT_SAME_JURISDICTION) != KMIP_OK)
1380 {
1381 TEST_FAILED(tracker, __func__, __LINE__);
1382 }
1383
1384 v = KMIP_1_4;
1385
1386 if(kmip_check_enum_value(v, t, KMIP_PROTECT_SOFTWARE) != KMIP_INVALID_FOR_VERSION)
1387 {
1388 TEST_FAILED(tracker, __func__, __LINE__);
1389 }
1390
1391 if(kmip_check_enum_value(v, t, KMIP_PROTECT_HARDWARE) != KMIP_INVALID_FOR_VERSION)
1392 {
1393 TEST_FAILED(tracker, __func__, __LINE__);
1394 }
1395
1396 if(kmip_check_enum_value(v, t, KMIP_PROTECT_ON_PROCESSOR) != KMIP_INVALID_FOR_VERSION)
1397 {
1398 TEST_FAILED(tracker, __func__, __LINE__);
1399 }
1400
1401 if(kmip_check_enum_value(v, t, KMIP_PROTECT_ON_SYSTEM) != KMIP_INVALID_FOR_VERSION)
1402 {
1403 TEST_FAILED(tracker, __func__, __LINE__);
1404 }
1405
1406 if(kmip_check_enum_value(v, t, KMIP_PROTECT_OFF_SYSTEM) != KMIP_INVALID_FOR_VERSION)
1407 {
1408 TEST_FAILED(tracker, __func__, __LINE__);
1409 }
1410
1411 if(kmip_check_enum_value(v, t, KMIP_PROTECT_HYPERVISOR) != KMIP_INVALID_FOR_VERSION)
1412 {
1413 TEST_FAILED(tracker, __func__, __LINE__);
1414 }
1415
1416 if(kmip_check_enum_value(v, t, KMIP_PROTECT_OPERATING_SYSTEM) != KMIP_INVALID_FOR_VERSION)
1417 {
1418 TEST_FAILED(tracker, __func__, __LINE__);
1419 }
1420
1421 if(kmip_check_enum_value(v, t, KMIP_PROTECT_CONTAINER) != KMIP_INVALID_FOR_VERSION)
1422 {
1423 TEST_FAILED(tracker, __func__, __LINE__);
1424 }
1425
1426 if(kmip_check_enum_value(v, t, KMIP_PROTECT_ON_PREMISES) != KMIP_INVALID_FOR_VERSION)
1427 {
1428 TEST_FAILED(tracker, __func__, __LINE__);
1429 }
1430
1431 if(kmip_check_enum_value(v, t, KMIP_PROTECT_OFF_PREMISES) != KMIP_INVALID_FOR_VERSION)
1432 {
1433 TEST_FAILED(tracker, __func__, __LINE__);
1434 }
1435
1436 if(kmip_check_enum_value(v, t, KMIP_PROTECT_SELF_MANAGED) != KMIP_INVALID_FOR_VERSION)
1437 {
1438 TEST_FAILED(tracker, __func__, __LINE__);
1439 }
1440
1441 if(kmip_check_enum_value(v, t, KMIP_PROTECT_OUTSOURCED) != KMIP_INVALID_FOR_VERSION)
1442 {
1443 TEST_FAILED(tracker, __func__, __LINE__);
1444 }
1445
1446 if(kmip_check_enum_value(v, t, KMIP_PROTECT_VALIDATED) != KMIP_INVALID_FOR_VERSION)
1447 {
1448 TEST_FAILED(tracker, __func__, __LINE__);
1449 }
1450
1451 if(kmip_check_enum_value(v, t, KMIP_PROTECT_SAME_JURISDICTION) != KMIP_INVALID_FOR_VERSION)
1452 {
1453 TEST_FAILED(tracker, __func__, __LINE__);
1454 }
1455
1456 if(kmip_check_enum_value(v, t, -1) != KMIP_ENUM_MISMATCH)
1457 {
1458 TEST_FAILED(tracker, __func__, __LINE__);
1459 }
1460
1461 TEST_PASSED(tracker, __func__);
1462 }
1463
1464 int
1465 test_init_protocol_version(TestTracker *tracker)
1466 {
1467 TRACK_TEST(tracker);
1468
1469 kmip_init_protocol_version(NULL, KMIP_1_0);
1470
1471 ProtocolVersion pv = {0};
1472
1473 if(pv.major != 0)
1474 TEST_FAILED(tracker, __func__, __LINE__);
1475 if(pv.minor != 0)
1476 TEST_FAILED(tracker, __func__, __LINE__);
1477
1478 kmip_init_protocol_version(&pv, KMIP_1_0);
1479
1480 if(pv.major != 1)
1481 TEST_FAILED(tracker, __func__, __LINE__);
1482 if(pv.minor != 0)
1483 TEST_FAILED(tracker, __func__, __LINE__);
1484
1485 kmip_init_protocol_version(&pv, KMIP_1_1);
1486
1487 if(pv.major != 1)
1488 TEST_FAILED(tracker, __func__, __LINE__);
1489 if(pv.minor != 1)
1490 TEST_FAILED(tracker, __func__, __LINE__);
1491
1492 kmip_init_protocol_version(&pv, KMIP_1_2);
1493
1494 if(pv.major != 1)
1495 TEST_FAILED(tracker, __func__, __LINE__);
1496 if(pv.minor != 2)
1497 TEST_FAILED(tracker, __func__, __LINE__);
1498
1499 kmip_init_protocol_version(&pv, KMIP_1_3);
1500
1501 if(pv.major != 1)
1502 TEST_FAILED(tracker, __func__, __LINE__);
1503 if(pv.minor != 3)
1504 TEST_FAILED(tracker, __func__, __LINE__);
1505
1506 kmip_init_protocol_version(&pv, KMIP_1_4);
1507
1508 if(pv.major != 1)
1509 TEST_FAILED(tracker, __func__, __LINE__);
1510 if(pv.minor != 4)
1511 TEST_FAILED(tracker, __func__, __LINE__);
1512
1513 kmip_init_protocol_version(&pv, KMIP_2_0);
1514
1515 if(pv.major != 2)
1516 TEST_FAILED(tracker, __func__, __LINE__);
1517 if(pv.minor != 0)
1518 TEST_FAILED(tracker, __func__, __LINE__);
1519
1520 TEST_PASSED(tracker, __func__);
1521 }
1522
1523 int
1524 test_init_request_batch_item(TestTracker *tracker)
1525 {
1526 TRACK_TEST(tracker);
1527
1528 kmip_init_request_batch_item(NULL);
1529
1530 RequestBatchItem rbi = {0};
1531
1532 if(rbi.operation != 0)
1533 TEST_FAILED(tracker, __func__, __LINE__);
1534 if(rbi.unique_batch_item_id != NULL)
1535 TEST_FAILED(tracker, __func__, __LINE__);
1536 if(rbi.request_payload != NULL)
1537 TEST_FAILED(tracker, __func__, __LINE__);
1538 if(rbi.ephemeral != 0)
1539 TEST_FAILED(tracker, __func__, __LINE__);
1540
1541 kmip_init_request_batch_item(&rbi);
1542
1543 if(rbi.operation != 0)
1544 TEST_FAILED(tracker, __func__, __LINE__);
1545 if(rbi.unique_batch_item_id != NULL)
1546 TEST_FAILED(tracker, __func__, __LINE__);
1547 if(rbi.request_payload != NULL)
1548 TEST_FAILED(tracker, __func__, __LINE__);
1549 if(rbi.ephemeral != KMIP_UNSET)
1550 TEST_FAILED(tracker, __func__, __LINE__);
1551
1552 TEST_PASSED(tracker, __func__);
1553 }
1554
1555 int
1556 test_print_attributes(TestTracker *tracker)
1557 {
1558 TRACK_TEST(tracker);
1559
1560 /* For now this will probably be left as a placeholder for a
1561 future test. Ideally the print functions would output to
1562 an arbitrary buffer so that we can verify that they are
1563 correctly displaying structure content and formatting.
1564 Since they currently use printf directly, this may be hard
1565 to do in the short term.
1566 */
1567 TEST_FAILED(tracker, __func__, __LINE__);
1568 }
1569
1570 int
1571 test_free_attributes(TestTracker *tracker)
1572 {
1573 TRACK_TEST(tracker);
1574
1575 /* Build a dynamically allocated Attributes structure. Free it
1576 with this function. Verify that all internal pointers and
1577 fields are correctly nullified.
1578
1579 Ideally, hook into the free function managed by the context
1580 and use that hook to verify that the correct free calls are
1581 made on the internal Attributes structure pointers. This
1582 may require more infrastructure work than currently exists.
1583 */
1584 TEST_FAILED(tracker, __func__, __LINE__);
1585 }
1586
1587 int
1588 test_compare_attributes(TestTracker *tracker)
1589 {
1590 TRACK_TEST(tracker);
1591
1592 /* Build two separate identical Attributes structures. Compare
1593 them with this function and confirm they match.
1594
1595 Build two separate different Attributes structures. Compare
1596 them with this function and confirm they do not match. This
1597 may require multiple rounds, changing different parts of the
1598 underlying Attributes structure. It may make more sense to
1599 split this into multiple test functions.
1600 */
1601 TEST_FAILED(tracker, __func__, __LINE__);
1602 }
1603
1604 int
1605 test_deep_copy_int32(TestTracker *tracker)
1606 {
1607 TRACK_TEST(tracker);
1608
1609 int32 expected = 42;
1610 int32 *observed = NULL;
1611
1612 observed = kmip_deep_copy_int32(NULL, NULL);
1613 if(observed != NULL)
1614 TEST_FAILED(tracker, __func__, __LINE__);
1615
1616 KMIP ctx = {0};
1617 kmip_init(&ctx, NULL, 0, KMIP_1_0);
1618
1619 observed = kmip_deep_copy_int32(&ctx, NULL);
1620 if(observed != NULL)
1621 {
1622 kmip_destroy(&ctx);
1623 TEST_FAILED(tracker, __func__, __LINE__);
1624 }
1625
1626 observed = kmip_deep_copy_int32(&ctx, &expected);
1627 if(observed == NULL)
1628 {
1629 kmip_destroy(&ctx);
1630 TEST_FAILED(tracker, __func__, __LINE__);
1631 }
1632 if(*observed != expected)
1633 {
1634 kmip_print_integer(expected);
1635 kmip_print_integer(*observed);
1636 ctx.free_func(ctx.state, observed);
1637 kmip_destroy(&ctx);
1638 TEST_FAILED(tracker, __func__, __LINE__);
1639 }
1640
1641 ctx.free_func(ctx.state, observed);
1642 kmip_destroy(&ctx);
1643
1644 TEST_PASSED(tracker, __func__);
1645 }
1646
1647 int
1648 test_deep_copy_text_string(TestTracker *tracker)
1649 {
1650 TRACK_TEST(tracker);
1651
1652 TextString expected = {0};
1653 expected.value = "example";
1654 expected.size = 7;
1655 TextString *observed = NULL;
1656
1657 observed = kmip_deep_copy_text_string(NULL, NULL);
1658 if(observed != NULL)
1659 TEST_FAILED(tracker, __func__, __LINE__);
1660
1661 KMIP ctx = {0};
1662 kmip_init(&ctx, NULL, 0, KMIP_1_0);
1663
1664 observed = kmip_deep_copy_text_string(&ctx, NULL);
1665 if(observed != NULL)
1666 {
1667 kmip_destroy(&ctx);
1668 TEST_FAILED(tracker, __func__, __LINE__);
1669 }
1670
1671 observed = kmip_deep_copy_text_string(&ctx, &expected);
1672 if(observed == NULL)
1673 {
1674 kmip_destroy(&ctx);
1675 TEST_FAILED(tracker, __func__, __LINE__);
1676 }
1677 if(!kmip_compare_text_string(&expected, observed))
1678 {
1679 kmip_print_text_string(1, "Name Value", &expected);
1680 kmip_print_text_string(1, "Name Value", observed);
1681 kmip_free_text_string(&ctx, observed);
1682 ctx.free_func(ctx.state, observed);
1683 kmip_destroy(&ctx);
1684 TEST_FAILED(tracker, __func__, __LINE__);
1685 }
1686
1687 kmip_free_text_string(&ctx, observed);
1688 ctx.free_func(ctx.state, observed);
1689 kmip_destroy(&ctx);
1690
1691 TEST_PASSED(tracker, __func__);
1692 }
1693
1694 int
1695 test_deep_copy_name(TestTracker *tracker)
1696 {
1697 TRACK_TEST(tracker);
1698
1699 TextString value = {0};
1700 value.value = "example";
1701 value.size = 7;
1702 Name expected = {0};
1703 expected.value = &value;
1704 expected.type = KMIP_NAME_UNINTERPRETED_TEXT_STRING;
1705 Name *observed = NULL;
1706
1707 observed = kmip_deep_copy_name(NULL, NULL);
1708 if(observed != NULL)
1709 TEST_FAILED(tracker, __func__, __LINE__);
1710
1711 KMIP ctx = {0};
1712 kmip_init(&ctx, NULL, 0, KMIP_1_0);
1713
1714 observed = kmip_deep_copy_name(&ctx, NULL);
1715 if(observed != NULL)
1716 {
1717 kmip_destroy(&ctx);
1718 TEST_FAILED(tracker, __func__, __LINE__);
1719 }
1720
1721 observed = kmip_deep_copy_name(&ctx, &expected);
1722 if(observed == NULL)
1723 {
1724 kmip_destroy(&ctx);
1725 TEST_FAILED(tracker, __func__, __LINE__);
1726 }
1727 if(!kmip_compare_name(&expected, observed))
1728 {
1729 kmip_print_name(1, &expected);
1730 kmip_print_name(1, observed);
1731 kmip_free_name(&ctx, observed);
1732 ctx.free_func(ctx.state, observed);
1733 kmip_destroy(&ctx);
1734 TEST_FAILED(tracker, __func__, __LINE__);
1735 }
1736
1737 kmip_free_name(&ctx, observed);
1738 ctx.free_func(ctx.state, observed);
1739 kmip_destroy(&ctx);
1740
1741 TEST_PASSED(tracker, __func__);
1742 }
1743
1744 int
1745 test_deep_copy_attribute(TestTracker *tracker)
1746 {
1747 TRACK_TEST(tracker);
1748
1749 Attribute expected = {0};
1750 kmip_init_attribute(&expected);
1751 Attribute *observed = NULL;
1752
1753 observed = kmip_deep_copy_attribute(NULL, NULL);
1754 if(observed != NULL)
1755 TEST_FAILED(tracker, __func__, __LINE__);
1756
1757 KMIP ctx = {0};
1758 kmip_init(&ctx, NULL, 0, KMIP_1_0);
1759
1760 observed = kmip_deep_copy_attribute(&ctx, NULL);
1761 if(observed != NULL)
1762 {
1763 kmip_destroy(&ctx);
1764 TEST_FAILED(tracker, __func__, __LINE__);
1765 }
1766
1767 /* Test deep copying an "empty" attribute. */
1768 observed = kmip_deep_copy_attribute(&ctx, &expected);
1769 if(observed == NULL)
1770 {
1771 kmip_destroy(&ctx);
1772 TEST_FAILED(tracker, __func__, __LINE__);
1773 }
1774 if(!kmip_compare_attribute(&expected, observed))
1775 {
1776 kmip_print_attribute(1, &expected);
1777 kmip_print_attribute(1, observed);
1778 kmip_free_attribute(&ctx, observed);
1779 ctx.free_func(ctx.state, observed);
1780 kmip_destroy(&ctx);
1781 TEST_FAILED(tracker, __func__, __LINE__);
1782 }
1783
1784 kmip_free_attribute(&ctx, observed);
1785 ctx.free_func(ctx.state, observed);
1786
1787 /* Test deep copying a Unique Identifier attribute. */
1788 TextString uuid = {0};
1789 uuid.value = "49a1ca88-6bea-4fb2-b450-7e58802c3038";
1790 uuid.size = 36;
1791 expected.type = KMIP_ATTR_UNIQUE_IDENTIFIER;
1792 expected.value = &uuid;
1793
1794 observed = kmip_deep_copy_attribute(&ctx, &expected);
1795 if(observed == NULL)
1796 {
1797 kmip_destroy(&ctx);
1798 TEST_FAILED(tracker, __func__, __LINE__);
1799 }
1800 if(!kmip_compare_attribute(&expected, observed))
1801 {
1802 kmip_print_attribute(1, &expected);
1803 kmip_print_attribute(1, observed);
1804 kmip_free_attribute(&ctx, observed);
1805 ctx.free_func(ctx.state, observed);
1806 kmip_destroy(&ctx);
1807 TEST_FAILED(tracker, __func__, __LINE__);
1808 }
1809
1810 kmip_free_attribute(&ctx, observed);
1811 ctx.free_func(ctx.state, observed);
1812
1813 /* Test deep copying an Operation Policy Name attribute. */
1814 TextString policy = {0};
1815 policy.value = "default";
1816 policy.size = 7;
1817 expected.type = KMIP_ATTR_OPERATION_POLICY_NAME;
1818 expected.value = &policy;
1819
1820 observed = kmip_deep_copy_attribute(&ctx, &expected);
1821 if(observed == NULL)
1822 {
1823 kmip_destroy(&ctx);
1824 TEST_FAILED(tracker, __func__, __LINE__);
1825 }
1826 if(!kmip_compare_attribute(&expected, observed))
1827 {
1828 kmip_print_attribute(1, &expected);
1829 kmip_print_attribute(1, observed);
1830 kmip_free_attribute(&ctx, observed);
1831 ctx.free_func(ctx.state, observed);
1832 kmip_destroy(&ctx);
1833 TEST_FAILED(tracker, __func__, __LINE__);
1834 }
1835
1836 kmip_free_attribute(&ctx, observed);
1837 ctx.free_func(ctx.state, observed);
1838
1839 /* Test deep copying a Name attribute. */
1840 TextString name_value = {0};
1841 name_value.value = "example";
1842 name_value.size = 7;
1843 Name name = {0};
1844 name.value = &name_value;
1845 name.type = KMIP_NAME_UNINTERPRETED_TEXT_STRING;
1846 expected.type = KMIP_ATTR_NAME;
1847 expected.value = &name;
1848
1849 observed = kmip_deep_copy_attribute(&ctx, &expected);
1850 if(observed == NULL)
1851 {
1852 kmip_destroy(&ctx);
1853 TEST_FAILED(tracker, __func__, __LINE__);
1854 }
1855 if(!kmip_compare_attribute(&expected, observed))
1856 {
1857 kmip_print_attribute(1, &expected);
1858 kmip_print_attribute(1, observed);
1859 kmip_free_attribute(&ctx, observed);
1860 ctx.free_func(ctx.state, observed);
1861 kmip_destroy(&ctx);
1862 TEST_FAILED(tracker, __func__, __LINE__);
1863 }
1864
1865 kmip_free_attribute(&ctx, observed);
1866 ctx.free_func(ctx.state, observed);
1867
1868 /* Test deep copying an Object Type attribute. */
1869 enum object_type object_type = KMIP_OBJTYPE_SYMMETRIC_KEY;
1870 expected.type = KMIP_ATTR_OBJECT_TYPE;
1871 expected.value = &object_type;
1872
1873 observed = kmip_deep_copy_attribute(&ctx, &expected);
1874 if(observed == NULL)
1875 {
1876 kmip_destroy(&ctx);
1877 TEST_FAILED(tracker, __func__, __LINE__);
1878 }
1879 if(!kmip_compare_attribute(&expected, observed))
1880 {
1881 kmip_print_attribute(1, &expected);
1882 kmip_print_attribute(1, observed);
1883 kmip_free_attribute(&ctx, observed);
1884 ctx.free_func(ctx.state, observed);
1885 kmip_destroy(&ctx);
1886 TEST_FAILED(tracker, __func__, __LINE__);
1887 }
1888
1889 kmip_free_attribute(&ctx, observed);
1890 ctx.free_func(ctx.state, observed);
1891
1892 /* Test deep copying a Cryptographic Algorithm attribute. */
1893 enum cryptographic_algorithm cryptographic_algorithm = KMIP_CRYPTOALG_AES;
1894 expected.type = KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM;
1895 expected.value = &cryptographic_algorithm;
1896
1897 observed = kmip_deep_copy_attribute(&ctx, &expected);
1898 if(observed == NULL)
1899 {
1900 kmip_destroy(&ctx);
1901 TEST_FAILED(tracker, __func__, __LINE__);
1902 }
1903 if(!kmip_compare_attribute(&expected, observed))
1904 {
1905 kmip_print_attribute(1, &expected);
1906 kmip_print_attribute(1, observed);
1907 kmip_free_attribute(&ctx, observed);
1908 ctx.free_func(ctx.state, observed);
1909 kmip_destroy(&ctx);
1910 TEST_FAILED(tracker, __func__, __LINE__);
1911 }
1912
1913 kmip_free_attribute(&ctx, observed);
1914 ctx.free_func(ctx.state, observed);
1915
1916 /* Test deep copying a Cryptographic Length attribute. */
1917 int32 cryptographic_length = 256;
1918 expected.type = KMIP_ATTR_CRYPTOGRAPHIC_LENGTH;
1919 expected.value = &cryptographic_length;
1920
1921 observed = kmip_deep_copy_attribute(&ctx, &expected);
1922 if(observed == NULL)
1923 {
1924 kmip_destroy(&ctx);
1925 TEST_FAILED(tracker, __func__, __LINE__);
1926 }
1927 if(!kmip_compare_attribute(&expected, observed))
1928 {
1929 kmip_print_attribute(1, &expected);
1930 kmip_print_attribute(1, observed);
1931 kmip_free_attribute(&ctx, observed);
1932 ctx.free_func(ctx.state, observed);
1933 kmip_destroy(&ctx);
1934 TEST_FAILED(tracker, __func__, __LINE__);
1935 }
1936
1937 kmip_free_attribute(&ctx, observed);
1938 ctx.free_func(ctx.state, observed);
1939
1940 /* Test deep copying a Cryptographic Usage Mask attribute. */
1941 int32 cryptographic_usage_mask = KMIP_CRYPTOMASK_ENCRYPT | KMIP_CRYPTOMASK_DECRYPT;
1942 expected.type = KMIP_ATTR_CRYPTOGRAPHIC_USAGE_MASK;
1943 expected.value = &cryptographic_usage_mask;
1944
1945 observed = kmip_deep_copy_attribute(&ctx, &expected);
1946 if(observed == NULL)
1947 {
1948 kmip_destroy(&ctx);
1949 TEST_FAILED(tracker, __func__, __LINE__);
1950 }
1951 if(!kmip_compare_attribute(&expected, observed))
1952 {
1953 kmip_print_attribute(1, &expected);
1954 kmip_print_attribute(1, observed);
1955 kmip_free_attribute(&ctx, observed);
1956 ctx.free_func(ctx.state, observed);
1957 kmip_destroy(&ctx);
1958 TEST_FAILED(tracker, __func__, __LINE__);
1959 }
1960
1961 kmip_free_attribute(&ctx, observed);
1962 ctx.free_func(ctx.state, observed);
1963
1964 /* Test deep copying a State attribute. */
1965 enum state state = KMIP_STATE_ACTIVE;
1966 expected.type = KMIP_ATTR_STATE;
1967 expected.value = &state;
1968
1969 observed = kmip_deep_copy_attribute(&ctx, &expected);
1970 if(observed == NULL)
1971 {
1972 kmip_destroy(&ctx);
1973 TEST_FAILED(tracker, __func__, __LINE__);
1974 }
1975 if(!kmip_compare_attribute(&expected, observed))
1976 {
1977 kmip_print_attribute(1, &expected);
1978 kmip_print_attribute(1, observed);
1979 kmip_free_attribute(&ctx, observed);
1980 ctx.free_func(ctx.state, observed);
1981 kmip_destroy(&ctx);
1982 TEST_FAILED(tracker, __func__, __LINE__);
1983 }
1984
1985 kmip_free_attribute(&ctx, observed);
1986 ctx.free_func(ctx.state, observed);
1987 kmip_destroy(&ctx);
1988
1989 TEST_PASSED(tracker, __func__);
1990 }
1991
1992 int
1993 test_decode_int8_be(TestTracker *tracker)
1994 {
1995 TRACK_TEST(tracker);
1996
1997 uint8 encoding[1] = {0x42};
1998
1999 struct kmip ctx = {0};
2000 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
2001
2002 int8 value = 0;
2003
2004 int result = kmip_decode_int8_be(&ctx, &value);
2005 result = report_decoding_test_result(
2006 tracker,
2007 &ctx,
2008 value == 0x42,
2009 result,
2010 __func__);
2011 kmip_destroy(&ctx);
2012 return(result);
2013 }
2014
2015 int
2016 test_decode_int32_be(TestTracker *tracker)
2017 {
2018 TRACK_TEST(tracker);
2019
2020 uint8 encoding[4] = {0x11, 0x22, 0x33, 0x44};
2021
2022 struct kmip ctx = {0};
2023 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
2024
2025 int32 expected = 0x11223344;
2026 int32 observed = 0;
2027
2028 int result = kmip_decode_int32_be(&ctx, &observed);
2029 result = report_decoding_test_result(
2030 tracker,
2031 &ctx,
2032 observed == expected,
2033 result,
2034 __func__);
2035 kmip_destroy(&ctx);
2036 return(result);
2037 }
2038
2039 int
2040 test_decode_int64_be(TestTracker *tracker)
2041 {
2042 TRACK_TEST(tracker);
2043
2044 uint8 encoding[8] = {
2045 0x01, 0xB6, 0x9B, 0x4B, 0xA5, 0x74, 0x92, 0x00
2046 };
2047
2048 struct kmip ctx = {0};
2049 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
2050
2051 int64 expected = 0x01B69B4BA5749200;
2052 int64 observed = 0;
2053
2054 int result = kmip_decode_int64_be(&ctx, &observed);
2055 result = report_decoding_test_result(
2056 tracker,
2057 &ctx,
2058 observed == expected,
2059 result,
2060 __func__);
2061 kmip_destroy(&ctx);
2062 return(result);
2063 }
2064
2065 int
2066 test_encode_integer(TestTracker *tracker)
2067 {
2068 TRACK_TEST(tracker);
2069
2070 uint8 expected[16] = {
2071 0x42, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04,
2072 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00
2073 };
2074
2075 uint8 observed[16] = {0};
2076 struct kmip ctx = {0};
2077 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
2078
2079 int result = kmip_encode_integer(&ctx, KMIP_TAG_DEFAULT, 8);
2080 result = report_encoding_test_result(
2081 tracker,
2082 &ctx,
2083 expected,
2084 observed,
2085 result,
2086 __func__);
2087 kmip_destroy(&ctx);
2088 return(result);
2089 }
2090
2091 int
2092 test_decode_integer(TestTracker *tracker)
2093 {
2094 TRACK_TEST(tracker);
2095
2096 uint8 encoding[16] = {
2097 0x42, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04,
2098 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00
2099 };
2100
2101 struct kmip ctx = {0};
2102 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
2103
2104 int32 expected = 8;
2105 int32 observed = 0;
2106
2107 int result = kmip_decode_integer(&ctx, KMIP_TAG_DEFAULT, &observed);
2108 result = report_decoding_test_result(
2109 tracker,
2110 &ctx,
2111 observed == expected,
2112 result,
2113 __func__);
2114 kmip_destroy(&ctx);
2115 return(result);
2116 }
2117
2118 int
2119 test_encode_long(TestTracker *tracker)
2120 {
2121 TRACK_TEST(tracker);
2122
2123 uint8 expected[16] = {
2124 0x42, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08,
2125 0x01, 0xB6, 0x9B, 0x4B, 0xA5, 0x74, 0x92, 0x00
2126 };
2127
2128 uint8 observed[16] = {0};
2129 struct kmip ctx = {0};
2130 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
2131
2132 int result = kmip_encode_long(&ctx, KMIP_TAG_DEFAULT, 123456789000000000);
2133 result = report_encoding_test_result(
2134 tracker,
2135 &ctx,
2136 expected,
2137 observed,
2138 result,
2139 __func__);
2140 kmip_destroy(&ctx);
2141 return(result);
2142 }
2143
2144 int
2145 test_decode_long(TestTracker *tracker)
2146 {
2147 TRACK_TEST(tracker);
2148
2149 uint8 encoding[16] = {
2150 0x42, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08,
2151 0x01, 0xB6, 0x9B, 0x4B, 0xA5, 0x74, 0x92, 0x00
2152 };
2153
2154 struct kmip ctx = {0};
2155 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
2156
2157 int64 expected = 0x01B69B4BA5749200;
2158 int64 observed = 0;
2159
2160 int result = kmip_decode_long(&ctx, KMIP_TAG_DEFAULT, &observed);
2161 result = report_decoding_test_result(
2162 tracker,
2163 &ctx,
2164 observed == expected,
2165 result,
2166 __func__);
2167 kmip_destroy(&ctx);
2168 return(result);
2169 }
2170
2171 int
2172 test_encode_enum(TestTracker *tracker)
2173 {
2174 TRACK_TEST(tracker);
2175
2176 uint8 expected[16] = {
2177 0x42, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04,
2178 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00
2179 };
2180
2181 uint8 observed[16] = {0};
2182 struct kmip ctx = {0};
2183 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
2184
2185 int result = kmip_encode_enum(&ctx, KMIP_TAG_DEFAULT, KMIP_CRYPTOALG_AES);
2186 result = report_encoding_test_result(
2187 tracker,
2188 &ctx,
2189 expected,
2190 observed,
2191 result,
2192 __func__);
2193 kmip_destroy(&ctx);
2194 return(result);
2195 }
2196
2197 int
2198 test_decode_enum(TestTracker *tracker)
2199 {
2200 TRACK_TEST(tracker);
2201
2202 uint8 encoding[16] = {
2203 0x42, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04,
2204 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00
2205 };
2206
2207 struct kmip ctx = {0};
2208 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
2209
2210 enum cryptographic_algorithm expected = KMIP_CRYPTOALG_AES;
2211 enum cryptographic_algorithm observed = 0;
2212
2213 int result = kmip_decode_enum(&ctx, KMIP_TAG_DEFAULT, &observed);
2214 result = report_decoding_test_result(
2215 tracker,
2216 &ctx,
2217 observed == expected,
2218 result,
2219 __func__);
2220 kmip_destroy(&ctx);
2221 return(result);
2222 }
2223
2224 int
2225 test_encode_bool(TestTracker *tracker)
2226 {
2227 TRACK_TEST(tracker);
2228
2229 uint8 expected[16] = {
2230 0x42, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x08,
2231 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
2232 };
2233
2234 uint8 observed[16] = {0};
2235 struct kmip ctx = {0};
2236 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
2237
2238 int result = kmip_encode_bool(&ctx, KMIP_TAG_DEFAULT, KMIP_TRUE);
2239 result = report_encoding_test_result(
2240 tracker,
2241 &ctx,
2242 expected,
2243 observed,
2244 result,
2245 __func__);
2246 kmip_destroy(&ctx);
2247 return(result);
2248 }
2249
2250 int
2251 test_decode_bool(TestTracker *tracker)
2252 {
2253 TRACK_TEST(tracker);
2254
2255 uint8 encoding[16] = {
2256 0x42, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x08,
2257 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
2258 };
2259
2260 struct kmip ctx = {0};
2261 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
2262
2263 bool32 expected = KMIP_TRUE;
2264 bool32 observed = 0;
2265
2266 int result = kmip_decode_bool(&ctx, KMIP_TAG_DEFAULT, &observed);
2267 result = report_decoding_test_result(
2268 tracker,
2269 &ctx,
2270 observed == expected,
2271 result,
2272 __func__);
2273 kmip_destroy(&ctx);
2274 return(result);
2275 }
2276
2277 int
2278 test_encode_text_string(TestTracker *tracker)
2279 {
2280 TRACK_TEST(tracker);
2281
2282 uint8 expected[24] = {
2283 0x42, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x0B,
2284 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F,
2285 0x72, 0x6C, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00
2286 };
2287
2288 uint8 observed[24] = {0};
2289 struct kmip ctx = {0};
2290 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
2291
2292 struct text_string example = {0};
2293 example.value = "Hello World";
2294 example.size = 11;
2295
2296 int result = kmip_encode_text_string(&ctx, KMIP_TAG_DEFAULT, &example);
2297 result = report_encoding_test_result(
2298 tracker,
2299 &ctx,
2300 expected,
2301 observed,
2302 result,
2303 __func__);
2304 kmip_destroy(&ctx);
2305 return(result);
2306 }
2307
2308 int
2309 test_decode_text_string(TestTracker *tracker)
2310 {
2311 TRACK_TEST(tracker);
2312
2313 uint8 encoding[24] = {
2314 0x42, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x0B,
2315 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F,
2316 0x72, 0x6C, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00
2317 };
2318
2319 struct kmip ctx = {0};
2320 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
2321
2322 struct text_string expected = {0};
2323 expected.value = "Hello World";
2324 expected.size = 11;
2325 struct text_string observed = {0};
2326
2327 int result = kmip_decode_text_string(&ctx, KMIP_TAG_DEFAULT, &observed);
2328 result = report_decoding_test_result(
2329 tracker,
2330 &ctx,
2331 kmip_compare_text_string(&expected, &observed),
2332 result,
2333 __func__);
2334 kmip_free_text_string(&ctx, &observed);
2335 kmip_destroy(&ctx);
2336 return(result);
2337 }
2338
2339 int
2340 test_encode_byte_string(TestTracker *tracker)
2341 {
2342 TRACK_TEST(tracker);
2343
2344 uint8 expected[16] = {
2345 0x42, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x03,
2346 0x01, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00
2347 };
2348
2349 uint8 observed[16] = {0};
2350 struct kmip ctx = {0};
2351 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
2352 uint8 str[3] = {0x01, 0x02, 0x03};
2353
2354 struct byte_string example = {0};
2355 example.value = str;
2356 example.size = 3;
2357
2358 int result = kmip_encode_byte_string(&ctx, KMIP_TAG_DEFAULT, &example);
2359 result = report_encoding_test_result(
2360 tracker,
2361 &ctx,
2362 expected,
2363 observed,
2364 result,
2365 __func__);
2366 kmip_destroy(&ctx);
2367 return(result);
2368 }
2369
2370 int
2371 test_decode_byte_string(TestTracker *tracker)
2372 {
2373 TRACK_TEST(tracker);
2374
2375 uint8 encoding[16] = {
2376 0x42, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x03,
2377 0x01, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00
2378 };
2379
2380 struct kmip ctx = {0};
2381 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
2382
2383 uint8 str[3] = {0x01, 0x02, 0x03};
2384
2385 struct byte_string expected = {0};
2386 expected.value = str;
2387 expected.size = 3;
2388 struct byte_string observed = {0};
2389
2390 int result = kmip_decode_byte_string(&ctx, KMIP_TAG_DEFAULT, &observed);
2391 result = report_decoding_test_result(
2392 tracker,
2393 &ctx,
2394 kmip_compare_byte_string(&expected, &observed),
2395 result,
2396 __func__);
2397 kmip_free_byte_string(&ctx, &observed);
2398 kmip_destroy(&ctx);
2399 return(result);
2400 }
2401
2402 int
2403 test_encode_date_time(TestTracker *tracker)
2404 {
2405 TRACK_TEST(tracker);
2406
2407 uint8 expected[16] = {
2408 0x42, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x08,
2409 0x00, 0x00, 0x00, 0x00, 0x47, 0xDA, 0x67, 0xF8
2410 };
2411
2412 uint8 observed[16] = {0};
2413 struct kmip ctx = {0};
2414 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
2415
2416 int result = kmip_encode_date_time(&ctx, KMIP_TAG_DEFAULT, 1205495800);
2417 result = report_encoding_test_result(
2418 tracker,
2419 &ctx,
2420 expected,
2421 observed,
2422 result,
2423 __func__);
2424 kmip_destroy(&ctx);
2425 return(result);
2426 }
2427
2428 int
2429 test_decode_date_time(TestTracker *tracker)
2430 {
2431 TRACK_TEST(tracker);
2432
2433 uint8 encoding[16] = {
2434 0x42, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x08,
2435 0x00, 0x00, 0x00, 0x00, 0x47, 0xDA, 0x67, 0xF8
2436 };
2437
2438 struct kmip ctx = {0};
2439 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
2440
2441 uint64 expected = 1205495800;
2442 uint64 observed = 0;
2443
2444 int result = kmip_decode_date_time(&ctx, KMIP_TAG_DEFAULT, &observed);
2445 result = report_decoding_test_result(
2446 tracker,
2447 &ctx,
2448 observed == expected,
2449 result,
2450 __func__);
2451 kmip_destroy(&ctx);
2452 return(result);
2453 }
2454
2455 int
2456 test_encode_interval(TestTracker *tracker)
2457 {
2458 TRACK_TEST(tracker);
2459
2460 uint8 expected[16] = {
2461 0x42, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x04,
2462 0x00, 0x0D, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00
2463 };
2464
2465 uint8 observed[16] = {0};
2466 struct kmip ctx = {0};
2467 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
2468
2469 int result = kmip_encode_interval(&ctx, KMIP_TAG_DEFAULT, 864000);
2470 result = report_encoding_test_result(
2471 tracker,
2472 &ctx,
2473 expected,
2474 observed,
2475 result,
2476 __func__);
2477 kmip_destroy(&ctx);
2478 return(result);
2479 }
2480
2481 int
2482 test_decode_interval(TestTracker *tracker)
2483 {
2484 TRACK_TEST(tracker);
2485
2486 uint8 encoding[16] = {
2487 0x42, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x04,
2488 0x00, 0x0D, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00
2489 };
2490
2491 struct kmip ctx = {0};
2492 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
2493
2494 uint32 expected = 864000;
2495 uint32 observed = 0;
2496
2497 int result = kmip_decode_interval(&ctx, KMIP_TAG_DEFAULT, &observed);
2498 result = report_decoding_test_result(
2499 tracker,
2500 &ctx,
2501 observed == expected,
2502 result,
2503 __func__);
2504 kmip_destroy(&ctx);
2505 return(result);
2506 }
2507
2508 int
2509 test_encode_name(TestTracker *tracker)
2510 {
2511 TRACK_TEST(tracker);
2512
2513 uint8 expected[48] = {
2514 0x42, 0x00, 0x53, 0x01, 0x00, 0x00, 0x00, 0x28,
2515 0x42, 0x00, 0x55, 0x07, 0x00, 0x00, 0x00, 0x09,
2516 0x54, 0x65, 0x6D, 0x70, 0x6C, 0x61, 0x74, 0x65,
2517 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2518 0x42, 0x00, 0x54, 0x05, 0x00, 0x00, 0x00, 0x04,
2519 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
2520 };
2521
2522 uint8 observed[48] = {0};
2523 struct kmip ctx = {0};
2524 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
2525
2526 struct text_string value = {0};
2527 value.value = "Template1";
2528 value.size = 9;
2529
2530 struct name n = {0};
2531 n.value = &value;
2532 n.type = KMIP_NAME_UNINTERPRETED_TEXT_STRING;
2533
2534 int result = kmip_encode_name(&ctx, &n);
2535 result = report_encoding_test_result(
2536 tracker,
2537 &ctx,
2538 expected,
2539 observed,
2540 result,
2541 __func__);
2542 kmip_destroy(&ctx);
2543 return(result);
2544 }
2545
2546 int
2547 test_decode_name(TestTracker *tracker)
2548 {
2549 TRACK_TEST(tracker);
2550
2551 uint8 encoding[48] = {
2552 0x42, 0x00, 0x53, 0x01, 0x00, 0x00, 0x00, 0x28,
2553 0x42, 0x00, 0x55, 0x07, 0x00, 0x00, 0x00, 0x09,
2554 0x54, 0x65, 0x6D, 0x70, 0x6C, 0x61, 0x74, 0x65,
2555 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2556 0x42, 0x00, 0x54, 0x05, 0x00, 0x00, 0x00, 0x04,
2557 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
2558 };
2559
2560 struct kmip ctx = {0};
2561 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
2562
2563 struct text_string value = {0};
2564 value.value = "Template1";
2565 value.size = 9;
2566
2567 struct name expected = {0};
2568 expected.value = &value;
2569 expected.type = KMIP_NAME_UNINTERPRETED_TEXT_STRING;
2570 struct name observed = {0};
2571
2572 int result = kmip_decode_name(&ctx, &observed);
2573 result = report_decoding_test_result(
2574 tracker,
2575 &ctx,
2576 kmip_compare_name(&expected, &observed),
2577 result,
2578 __func__);
2579 kmip_free_name(&ctx, &observed);
2580 kmip_destroy(&ctx);
2581 return(result);
2582 }
2583
2584 int
2585 test_encode_protection_storage_masks(TestTracker *tracker)
2586 {
2587 TRACK_TEST(tracker);
2588
2589 /* This encoding matches the following set of values:
2590 * Protection Storage Masks
2591 * Protection Storage Mask
2592 * Software
2593 * Hardware
2594 * On Processor
2595 * On System
2596 * Off System
2597 * Hypervisor
2598 * Operating System
2599 * Container
2600 * On Premises
2601 * Off Premises
2602 * Self Managed
2603 * Outsourced
2604 * Validated
2605 * Same Jurisdiction
2606 * Protection Storage Mask
2607 * Software
2608 * Hardware
2609 */
2610 uint8 expected[40] = {
2611 0x42, 0x01, 0x5F, 0x01, 0x00, 0x00, 0x00, 0x20,
2612 0x42, 0x01, 0x5E, 0x02, 0x00, 0x00, 0x00, 0x04,
2613 0x00, 0x00, 0x3F, 0xFF, 0x00, 0x00, 0x00, 0x00,
2614 0x42, 0x01, 0x5E, 0x02, 0x00, 0x00, 0x00, 0x04,
2615 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00
2616 };
2617
2618 uint8 observed[40] = {0};
2619 KMIP ctx = {0};
2620 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_2_0);
2621
2622 LinkedList list = {0};
2623 LinkedListItem item_1 = {0};
2624 int32 mask_1 = 0x3FFF;
2625 item_1.data = &mask_1;
2626
2627 LinkedListItem item_2 = {0};
2628 int32 mask_2 = 0x0003;
2629 item_2.data = &mask_2;
2630
2631 kmip_linked_list_enqueue(&list, &item_1);
2632 kmip_linked_list_enqueue(&list, &item_2);
2633
2634 ProtectionStorageMasks psm = {0};
2635 psm.masks = &list;
2636
2637 int result = kmip_encode_protection_storage_masks(&ctx, &psm);
2638 result = report_encoding_test_result(tracker, &ctx, expected, observed, result, __func__);
2639
2640 kmip_destroy(&ctx);
2641
2642 return(result);
2643 }
2644
2645 int
2646 test_decode_protection_storage_masks(TestTracker *tracker)
2647 {
2648 TRACK_TEST(tracker);
2649
2650 /* This encoding matches the following set of values:
2651 * Protection Storage Masks
2652 * Protection Storage Mask
2653 * Software
2654 * Hardware
2655 * On Processor
2656 * On System
2657 * Off System
2658 * Hypervisor
2659 * Operating System
2660 * Container
2661 * On Premises
2662 * Off Premises
2663 * Self Managed
2664 * Outsourced
2665 * Validated
2666 * Same Jurisdiction
2667 * Protection Storage Mask
2668 * Software
2669 * Hardware
2670 */
2671 uint8 encoding[40] = {
2672 0x42, 0x01, 0x5F, 0x01, 0x00, 0x00, 0x00, 0x20,
2673 0x42, 0x01, 0x5E, 0x02, 0x00, 0x00, 0x00, 0x04,
2674 0x00, 0x00, 0x3F, 0xFF, 0x00, 0x00, 0x00, 0x00,
2675 0x42, 0x01, 0x5E, 0x02, 0x00, 0x00, 0x00, 0x04,
2676 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00
2677 };
2678
2679 KMIP ctx = {0};
2680 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_2_0);
2681
2682 LinkedList list = {0};
2683 LinkedListItem item_1 = {0};
2684 int32 mask_1 = 0x3FFF;
2685 item_1.data = &mask_1;
2686
2687 LinkedListItem item_2 = {0};
2688 int32 mask_2 = 0x0003;
2689 item_2.data = &mask_2;
2690
2691 kmip_linked_list_enqueue(&list, &item_1);
2692 kmip_linked_list_enqueue(&list, &item_2);
2693
2694 ProtectionStorageMasks expected = {0};
2695 expected.masks = &list;
2696
2697 ProtectionStorageMasks observed = {0};
2698 int result = kmip_decode_protection_storage_masks(&ctx, &observed);
2699 int comparison = kmip_compare_protection_storage_masks(&expected, &observed);
2700 if(!comparison)
2701 {
2702 kmip_print_protection_storage_masks(1, &expected);
2703 kmip_print_protection_storage_masks(1, &observed);
2704 }
2705 result = report_decoding_test_result(tracker, &ctx, comparison, result, __func__);
2706
2707 kmip_free_protection_storage_masks(&ctx, &observed);
2708 kmip_destroy(&ctx);
2709
2710 return(result);
2711 }
2712
2713 int
2714 test_encode_attribute_unique_identifier(TestTracker *tracker)
2715 {
2716 TRACK_TEST(tracker);
2717
2718 uint8 expected[88] = {
2719 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x50,
2720 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x11,
2721 0x55, 0x6E, 0x69, 0x71, 0x75, 0x65, 0x20, 0x49,
2722 0x64, 0x65, 0x6E, 0x74, 0x69, 0x66, 0x69, 0x65,
2723 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2724 0x42, 0x00, 0x0B, 0x07, 0x00, 0x00, 0x00, 0x24,
2725 0x34, 0x39, 0x61, 0x31, 0x63, 0x61, 0x38, 0x38,
2726 0x2D, 0x36, 0x62, 0x65, 0x61, 0x2D, 0x34, 0x66,
2727 0x62, 0x32, 0x2D, 0x62, 0x34, 0x35, 0x30, 0x2D,
2728 0x37, 0x65, 0x35, 0x38, 0x38, 0x30, 0x32, 0x63,
2729 0x33, 0x30, 0x33, 0x38, 0x00, 0x00, 0x00, 0x00
2730 };
2731
2732 uint8 observed[88] = {0};
2733 struct kmip ctx = {0};
2734 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
2735
2736 struct text_string uuid = {0};
2737 uuid.value = "49a1ca88-6bea-4fb2-b450-7e58802c3038";
2738 uuid.size = 36;
2739
2740 struct attribute attr = {0};
2741 kmip_init_attribute(&attr);
2742
2743 attr.type = KMIP_ATTR_UNIQUE_IDENTIFIER;
2744 attr.value = &uuid;
2745
2746 int result = kmip_encode_attribute(&ctx, &attr);
2747 result = report_encoding_test_result(
2748 tracker,
2749 &ctx,
2750 expected,
2751 observed,
2752 result,
2753 __func__);
2754 kmip_destroy(&ctx);
2755 return(result);
2756 }
2757
2758 int
2759 test_decode_attribute_unique_identifier(TestTracker *tracker)
2760 {
2761 TRACK_TEST(tracker);
2762
2763 uint8 encoding[88] = {
2764 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x50,
2765 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x11,
2766 0x55, 0x6E, 0x69, 0x71, 0x75, 0x65, 0x20, 0x49,
2767 0x64, 0x65, 0x6E, 0x74, 0x69, 0x66, 0x69, 0x65,
2768 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2769 0x42, 0x00, 0x0B, 0x07, 0x00, 0x00, 0x00, 0x24,
2770 0x34, 0x39, 0x61, 0x31, 0x63, 0x61, 0x38, 0x38,
2771 0x2D, 0x36, 0x62, 0x65, 0x61, 0x2D, 0x34, 0x66,
2772 0x62, 0x32, 0x2D, 0x62, 0x34, 0x35, 0x30, 0x2D,
2773 0x37, 0x65, 0x35, 0x38, 0x38, 0x30, 0x32, 0x63,
2774 0x33, 0x30, 0x33, 0x38, 0x00, 0x00, 0x00, 0x00
2775 };
2776
2777 struct kmip ctx = {0};
2778 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
2779
2780 struct text_string uuid = {0};
2781 uuid.value = "49a1ca88-6bea-4fb2-b450-7e58802c3038";
2782 uuid.size = 36;
2783
2784 struct attribute expected = {0};
2785 kmip_init_attribute(&expected);
2786 expected.type = KMIP_ATTR_UNIQUE_IDENTIFIER;
2787 expected.value = &uuid;
2788 struct attribute observed = {0};
2789 kmip_init_attribute(&observed);
2790
2791 int result = kmip_decode_attribute(&ctx, &observed);
2792 result = report_decoding_test_result(
2793 tracker,
2794 &ctx,
2795 kmip_compare_attribute(&expected, &observed),
2796 result,
2797 __func__);
2798 kmip_free_attribute(&ctx, &observed);
2799 kmip_destroy(&ctx);
2800 return(result);
2801 }
2802
2803 int
2804 test_encode_attribute_name(TestTracker *tracker)
2805 {
2806 TRACK_TEST(tracker);
2807
2808 uint8 expected[72] = {
2809 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x40,
2810 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x04,
2811 0x4E, 0x61, 0x6D, 0x65, 0x00, 0x00, 0x00, 0x00,
2812 0x42, 0x00, 0x0B, 0x01, 0x00, 0x00, 0x00, 0x28,
2813 0x42, 0x00, 0x55, 0x07, 0x00, 0x00, 0x00, 0x09,
2814 0x54, 0x65, 0x6D, 0x70, 0x6C, 0x61, 0x74, 0x65,
2815 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2816 0x42, 0x00, 0x54, 0x05, 0x00, 0x00, 0x00, 0x04,
2817 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
2818 };
2819
2820 uint8 observed[72] = {0};
2821 struct kmip ctx = {0};
2822 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
2823
2824 struct text_string value = {0};
2825 value.value = "Template1";
2826 value.size = 9;
2827
2828 struct name n = {0};
2829 n.value = &value;
2830 n.type = KMIP_NAME_UNINTERPRETED_TEXT_STRING;
2831
2832 struct attribute attr = {0};
2833 kmip_init_attribute(&attr);
2834
2835 attr.type = KMIP_ATTR_NAME;
2836 attr.value = &n;
2837
2838 int result = kmip_encode_attribute(&ctx, &attr);
2839 result = report_encoding_test_result(
2840 tracker,
2841 &ctx,
2842 expected,
2843 observed,
2844 result,
2845 __func__);
2846 kmip_destroy(&ctx);
2847 return(result);
2848 }
2849
2850 int
2851 test_decode_attribute_name(TestTracker *tracker)
2852 {
2853 TRACK_TEST(tracker);
2854
2855 uint8 encoding[72] = {
2856 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x40,
2857 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x04,
2858 0x4E, 0x61, 0x6D, 0x65, 0x00, 0x00, 0x00, 0x00,
2859 0x42, 0x00, 0x0B, 0x01, 0x00, 0x00, 0x00, 0x28,
2860 0x42, 0x00, 0x55, 0x07, 0x00, 0x00, 0x00, 0x09,
2861 0x54, 0x65, 0x6D, 0x70, 0x6C, 0x61, 0x74, 0x65,
2862 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2863 0x42, 0x00, 0x54, 0x05, 0x00, 0x00, 0x00, 0x04,
2864 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
2865 };
2866
2867 struct kmip ctx = {0};
2868 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
2869
2870 struct text_string value = {0};
2871 value.value = "Template1";
2872 value.size = 9;
2873
2874 struct name n = {0};
2875 n.value = &value;
2876 n.type = KMIP_NAME_UNINTERPRETED_TEXT_STRING;
2877
2878 struct attribute expected = {0};
2879 kmip_init_attribute(&expected);
2880 expected.type = KMIP_ATTR_NAME;
2881 expected.value = &n;
2882 struct attribute observed = {0};
2883 kmip_init_attribute(&observed);
2884
2885 int result = kmip_decode_attribute(&ctx, &observed);
2886 result = report_decoding_test_result(
2887 tracker,
2888 &ctx,
2889 kmip_compare_attribute(&expected, &observed),
2890 result,
2891 __func__);
2892 kmip_free_attribute(&ctx, &observed);
2893 kmip_destroy(&ctx);
2894 return(result);
2895 }
2896
2897 int
2898 test_encode_attribute_object_type(TestTracker *tracker)
2899 {
2900 TRACK_TEST(tracker);
2901
2902 uint8 expected[48] = {
2903 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x28,
2904 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x0B,
2905 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x20, 0x54,
2906 0x79, 0x70, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00,
2907 0x42, 0x00, 0x0B, 0x05, 0x00, 0x00, 0x00, 0x04,
2908 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00
2909 };
2910
2911 uint8 observed[48] = {0};
2912 struct kmip ctx = {0};
2913 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
2914
2915 enum object_type t = KMIP_OBJTYPE_SYMMETRIC_KEY;
2916 struct attribute attr = {0};
2917 kmip_init_attribute(&attr);
2918
2919 attr.type = KMIP_ATTR_OBJECT_TYPE;
2920 attr.value = &t;
2921
2922 int result = kmip_encode_attribute(&ctx, &attr);
2923 result = report_encoding_test_result(
2924 tracker,
2925 &ctx,
2926 expected,
2927 observed,
2928 result,
2929 __func__);
2930 kmip_destroy(&ctx);
2931 return(result);
2932 }
2933
2934 int
2935 test_decode_attribute_object_type(TestTracker *tracker)
2936 {
2937 TRACK_TEST(tracker);
2938
2939 uint8 encoding[48] = {
2940 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x28,
2941 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x0B,
2942 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x20, 0x54,
2943 0x79, 0x70, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00,
2944 0x42, 0x00, 0x0B, 0x05, 0x00, 0x00, 0x00, 0x04,
2945 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00
2946 };
2947
2948 struct kmip ctx = {0};
2949 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
2950
2951 enum object_type t = KMIP_OBJTYPE_SYMMETRIC_KEY;
2952 struct attribute expected = {0};
2953 kmip_init_attribute(&expected);
2954 expected.type = KMIP_ATTR_OBJECT_TYPE;
2955 expected.value = &t;
2956 struct attribute observed = {0};
2957 kmip_init_attribute(&observed);
2958
2959 int result = kmip_decode_attribute(&ctx, &observed);
2960 result = report_decoding_test_result(
2961 tracker,
2962 &ctx,
2963 kmip_compare_attribute(&expected, &observed),
2964 result,
2965 __func__);
2966 kmip_free_attribute(&ctx, &observed);
2967 kmip_destroy(&ctx);
2968 return(result);
2969 }
2970
2971 int
2972 test_encode_attribute_cryptographic_algorithm(TestTracker *tracker)
2973 {
2974 TRACK_TEST(tracker);
2975
2976 uint8 expected[56] = {
2977 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
2978 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x17,
2979 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
2980 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x41, 0x6C,
2981 0x67, 0x6F, 0x72, 0x69, 0x74, 0x68, 0x6D, 0x00,
2982 0x42, 0x00, 0x0B, 0x05, 0x00, 0x00, 0x00, 0x04,
2983 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00
2984 };
2985
2986 uint8 observed[56] = {0};
2987 struct kmip ctx = {0};
2988 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
2989
2990 enum cryptographic_algorithm a = KMIP_CRYPTOALG_AES;
2991 struct attribute attr = {0};
2992 kmip_init_attribute(&attr);
2993
2994 attr.type = KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM;
2995 attr.value = &a;
2996
2997 int result = kmip_encode_attribute(&ctx, &attr);
2998 result = report_encoding_test_result(
2999 tracker,
3000 &ctx,
3001 expected,
3002 observed,
3003 result,
3004 __func__);
3005 kmip_destroy(&ctx);
3006 return(result);
3007 }
3008
3009 int
3010 test_decode_attribute_cryptographic_algorithm(TestTracker *tracker)
3011 {
3012 TRACK_TEST(tracker);
3013
3014 uint8 encoding[56] = {
3015 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
3016 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x17,
3017 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
3018 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x41, 0x6C,
3019 0x67, 0x6F, 0x72, 0x69, 0x74, 0x68, 0x6D, 0x00,
3020 0x42, 0x00, 0x0B, 0x05, 0x00, 0x00, 0x00, 0x04,
3021 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00
3022 };
3023
3024 struct kmip ctx = {0};
3025 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
3026
3027 enum cryptographic_algorithm a = KMIP_CRYPTOALG_AES;
3028 struct attribute expected = {0};
3029 kmip_init_attribute(&expected);
3030 expected.type = KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM;
3031 expected.value = &a;
3032 struct attribute observed = {0};
3033 kmip_init_attribute(&observed);
3034
3035 int result = kmip_decode_attribute(&ctx, &observed);
3036 result = report_decoding_test_result(
3037 tracker,
3038 &ctx,
3039 kmip_compare_attribute(&expected, &observed),
3040 result,
3041 __func__);
3042 kmip_free_attribute(&ctx, &observed);
3043 kmip_destroy(&ctx);
3044 return(result);
3045 }
3046
3047 int
3048 test_encode_attribute_cryptographic_length(TestTracker *tracker)
3049 {
3050 TRACK_TEST(tracker);
3051
3052 uint8 expected[56] = {
3053 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
3054 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x14,
3055 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
3056 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x4C, 0x65,
3057 0x6E, 0x67, 0x74, 0x68, 0x00, 0x00, 0x00, 0x00,
3058 0x42, 0x00, 0x0B, 0x02, 0x00, 0x00, 0x00, 0x04,
3059 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00
3060 };
3061
3062 uint8 observed[56] = {0};
3063 struct kmip ctx = {0};
3064 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
3065
3066 int32 length = 128;
3067 struct attribute attr = {0};
3068 kmip_init_attribute(&attr);
3069
3070 attr.type = KMIP_ATTR_CRYPTOGRAPHIC_LENGTH;
3071 attr.value = &length;
3072
3073 int result = kmip_encode_attribute(&ctx, &attr);
3074 result = report_encoding_test_result(
3075 tracker,
3076 &ctx,
3077 expected,
3078 observed,
3079 result,
3080 __func__);
3081 kmip_destroy(&ctx);
3082 return(result);
3083 }
3084
3085 int
3086 test_decode_attribute_cryptographic_length(TestTracker *tracker)
3087 {
3088 TRACK_TEST(tracker);
3089
3090 uint8 encoding[56] = {
3091 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
3092 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x14,
3093 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
3094 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x4C, 0x65,
3095 0x6E, 0x67, 0x74, 0x68, 0x00, 0x00, 0x00, 0x00,
3096 0x42, 0x00, 0x0B, 0x02, 0x00, 0x00, 0x00, 0x04,
3097 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00
3098 };
3099
3100 struct kmip ctx = {0};
3101 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
3102
3103 int32 length = 128;
3104 struct attribute expected = {0};
3105 kmip_init_attribute(&expected);
3106 expected.type = KMIP_ATTR_CRYPTOGRAPHIC_LENGTH;
3107 expected.value = &length;
3108 struct attribute observed = {0};
3109 kmip_init_attribute(&observed);
3110
3111 int result = kmip_decode_attribute(&ctx, &observed);
3112 result = report_decoding_test_result(
3113 tracker,
3114 &ctx,
3115 kmip_compare_attribute(&expected, &observed),
3116 result,
3117 __func__);
3118 kmip_free_attribute(&ctx, &observed);
3119 kmip_destroy(&ctx);
3120 return(result);
3121 }
3122
3123 int
3124 test_encode_attribute_operation_policy_name(TestTracker *tracker)
3125 {
3126 TRACK_TEST(tracker);
3127
3128 uint8 expected[56] = {
3129 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
3130 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x15,
3131 0x4F, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6F,
3132 0x6E, 0x20, 0x50, 0x6F, 0x6C, 0x69, 0x63, 0x79,
3133 0x20, 0x4E, 0x61, 0x6D, 0x65, 0x00, 0x00, 0x00,
3134 0x42, 0x00, 0x0B, 0x07, 0x00, 0x00, 0x00, 0x07,
3135 0x64, 0x65, 0x66, 0x61, 0x75, 0x6C, 0x74, 0x00
3136 };
3137
3138 uint8 observed[56] = {0};
3139 struct kmip ctx = {0};
3140 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
3141
3142 struct text_string policy = {0};
3143 policy.value = "default";
3144 policy.size = 7;
3145
3146 struct attribute attr = {0};
3147 kmip_init_attribute(&attr);
3148
3149 attr.type = KMIP_ATTR_OPERATION_POLICY_NAME;
3150 attr.value = &policy;
3151
3152 int result = kmip_encode_attribute(&ctx, &attr);
3153 result = report_encoding_test_result(
3154 tracker,
3155 &ctx,
3156 expected,
3157 observed,
3158 result,
3159 __func__);
3160 kmip_destroy(&ctx);
3161 return(result);
3162 }
3163
3164 int
3165 test_decode_attribute_operation_policy_name(TestTracker *tracker)
3166 {
3167 TRACK_TEST(tracker);
3168
3169 uint8 encoding[56] = {
3170 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
3171 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x15,
3172 0x4F, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6F,
3173 0x6E, 0x20, 0x50, 0x6F, 0x6C, 0x69, 0x63, 0x79,
3174 0x20, 0x4E, 0x61, 0x6D, 0x65, 0x00, 0x00, 0x00,
3175 0x42, 0x00, 0x0B, 0x07, 0x00, 0x00, 0x00, 0x07,
3176 0x64, 0x65, 0x66, 0x61, 0x75, 0x6C, 0x74, 0x00
3177 };
3178
3179 struct kmip ctx = {0};
3180 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
3181
3182 struct text_string policy = {0};
3183 policy.value = "default";
3184 policy.size = 7;
3185
3186 struct attribute expected = {0};
3187 kmip_init_attribute(&expected);
3188 expected.type = KMIP_ATTR_OPERATION_POLICY_NAME;
3189 expected.value = &policy;
3190 struct attribute observed = {0};
3191 kmip_init_attribute(&observed);
3192
3193 int result = kmip_decode_attribute(&ctx, &observed);
3194 result = report_decoding_test_result(
3195 tracker,
3196 &ctx,
3197 kmip_compare_attribute(&expected, &observed),
3198 result,
3199 __func__);
3200 kmip_free_attribute(&ctx, &observed);
3201 kmip_destroy(&ctx);
3202 return(result);
3203 }
3204
3205 int
3206 test_encode_attribute_cryptographic_usage_mask(TestTracker *tracker)
3207 {
3208 TRACK_TEST(tracker);
3209
3210 uint8 expected[56] = {
3211 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
3212 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x18,
3213 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
3214 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x55, 0x73,
3215 0x61, 0x67, 0x65, 0x20, 0x4D, 0x61, 0x73, 0x6B,
3216 0x42, 0x00, 0x0B, 0x02, 0x00, 0x00, 0x00, 0x04,
3217 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00
3218 };
3219
3220 uint8 observed[56] = {0};
3221 struct kmip ctx = {0};
3222 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
3223
3224 int32 mask = KMIP_CRYPTOMASK_ENCRYPT | KMIP_CRYPTOMASK_DECRYPT;
3225 struct attribute attr = {0};
3226 kmip_init_attribute(&attr);
3227
3228 attr.type = KMIP_ATTR_CRYPTOGRAPHIC_USAGE_MASK;
3229 attr.value = &mask;
3230
3231 int result = kmip_encode_attribute(&ctx, &attr);
3232 result = report_encoding_test_result(
3233 tracker,
3234 &ctx,
3235 expected,
3236 observed,
3237 result,
3238 __func__);
3239 kmip_destroy(&ctx);
3240 return(result);
3241 }
3242
3243 int
3244 test_decode_attribute_cryptographic_usage_mask(TestTracker *tracker)
3245 {
3246 TRACK_TEST(tracker);
3247
3248 uint8 encoding[56] = {
3249 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
3250 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x18,
3251 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
3252 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x55, 0x73,
3253 0x61, 0x67, 0x65, 0x20, 0x4D, 0x61, 0x73, 0x6B,
3254 0x42, 0x00, 0x0B, 0x02, 0x00, 0x00, 0x00, 0x04,
3255 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00
3256 };
3257
3258 struct kmip ctx = {0};
3259 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
3260
3261 int32 mask = KMIP_CRYPTOMASK_ENCRYPT | KMIP_CRYPTOMASK_DECRYPT;
3262 struct attribute expected = {0};
3263 kmip_init_attribute(&expected);
3264 expected.type = KMIP_ATTR_CRYPTOGRAPHIC_USAGE_MASK;
3265 expected.value = &mask;
3266 struct attribute observed = {0};
3267 kmip_init_attribute(&observed);
3268
3269 int result = kmip_decode_attribute(&ctx, &observed);
3270 result = report_decoding_test_result(
3271 tracker,
3272 &ctx,
3273 kmip_compare_attribute(&expected, &observed),
3274 result,
3275 __func__);
3276 kmip_free_attribute(&ctx, &observed);
3277 kmip_destroy(&ctx);
3278 return(result);
3279 }
3280
3281 int
3282 test_encode_attribute_state(TestTracker *tracker)
3283 {
3284 TRACK_TEST(tracker);
3285
3286 uint8 expected[40] = {
3287 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x20,
3288 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x05,
3289 0x53, 0x74, 0x61, 0x74, 0x65, 0x00, 0x00, 0x00,
3290 0x42, 0x00, 0x0B, 0x05, 0x00, 0x00, 0x00, 0x04,
3291 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
3292 };
3293
3294 uint8 observed[40] = {0};
3295 struct kmip ctx = {0};
3296 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
3297
3298 enum state s = KMIP_STATE_PRE_ACTIVE;
3299 struct attribute attr = {0};
3300 kmip_init_attribute(&attr);
3301
3302 attr.type = KMIP_ATTR_STATE;
3303 attr.value = &s;
3304
3305 int result = kmip_encode_attribute(&ctx, &attr);
3306 result = report_encoding_test_result(
3307 tracker,
3308 &ctx,
3309 expected,
3310 observed,
3311 result,
3312 __func__);
3313 kmip_destroy(&ctx);
3314 return(result);
3315 }
3316
3317 int
3318 test_decode_attribute_state(TestTracker *tracker)
3319 {
3320 TRACK_TEST(tracker);
3321
3322 uint8 encoding[40] = {
3323 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x20,
3324 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x05,
3325 0x53, 0x74, 0x61, 0x74, 0x65, 0x00, 0x00, 0x00,
3326 0x42, 0x00, 0x0B, 0x05, 0x00, 0x00, 0x00, 0x04,
3327 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
3328 };
3329
3330 struct kmip ctx = {0};
3331 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
3332
3333 enum state s = KMIP_STATE_PRE_ACTIVE;
3334 struct attribute expected = {0};
3335 kmip_init_attribute(&expected);
3336 expected.type = KMIP_ATTR_STATE;
3337 expected.value = &s;
3338 struct attribute observed = {0};
3339 kmip_init_attribute(&observed);
3340
3341 int result = kmip_decode_attribute(&ctx, &observed);
3342 result = report_decoding_test_result(
3343 tracker,
3344 &ctx,
3345 kmip_compare_attribute(&expected, &observed),
3346 result,
3347 __func__);
3348 kmip_free_attribute(&ctx, &observed);
3349 kmip_destroy(&ctx);
3350 return(result);
3351 }
3352
3353 int
3354 test_encode_protocol_version(TestTracker *tracker)
3355 {
3356 TRACK_TEST(tracker);
3357
3358 uint8 expected[40] = {
3359 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20,
3360 0x42, 0x00, 0x6A, 0x02, 0x00, 0x00, 0x00, 0x04,
3361 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
3362 0x42, 0x00, 0x6B, 0x02, 0x00, 0x00, 0x00, 0x04,
3363 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
3364 };
3365
3366 uint8 observed[40] = {0};
3367 struct kmip ctx = {0};
3368 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
3369
3370 struct protocol_version pv = {0};
3371 pv.major = 1;
3372 pv.minor = 0;
3373
3374 int result = kmip_encode_protocol_version(&ctx, &pv);
3375 result = report_encoding_test_result(
3376 tracker,
3377 &ctx,
3378 expected,
3379 observed,
3380 result,
3381 __func__);
3382 kmip_destroy(&ctx);
3383 return(result);
3384 }
3385
3386 int
3387 test_decode_protocol_version(TestTracker *tracker)
3388 {
3389 TRACK_TEST(tracker);
3390
3391 uint8 encoding[40] = {
3392 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20,
3393 0x42, 0x00, 0x6A, 0x02, 0x00, 0x00, 0x00, 0x04,
3394 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
3395 0x42, 0x00, 0x6B, 0x02, 0x00, 0x00, 0x00, 0x04,
3396 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
3397 };
3398
3399 struct kmip ctx = {0};
3400 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
3401
3402 struct protocol_version expected = {0};
3403 expected.major = 1;
3404 expected.minor = 0;
3405 struct protocol_version observed = {0};
3406
3407 int result = kmip_decode_protocol_version(&ctx, &observed);
3408 result = report_decoding_test_result(
3409 tracker,
3410 &ctx,
3411 kmip_compare_protocol_version(&expected, &observed),
3412 result,
3413 __func__);
3414 kmip_destroy(&ctx);
3415 return(result);
3416 }
3417
3418 int
3419 test_encode_cryptographic_parameters(TestTracker *tracker)
3420 {
3421 TRACK_TEST(tracker);
3422
3423 uint8 expected[72] = {
3424 0x42, 0x00, 0x2B, 0x01, 0x00, 0x00, 0x00, 0x40,
3425 0x42, 0x00, 0x11, 0x05, 0x00, 0x00, 0x00, 0x04,
3426 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
3427 0x42, 0x00, 0x5F, 0x05, 0x00, 0x00, 0x00, 0x04,
3428 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
3429 0x42, 0x00, 0x38, 0x05, 0x00, 0x00, 0x00, 0x04,
3430 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
3431 0x42, 0x00, 0x83, 0x05, 0x00, 0x00, 0x00, 0x04,
3432 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x00
3433 };
3434
3435 uint8 observed[72] = {0};
3436 struct kmip ctx = {0};
3437 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
3438
3439 struct cryptographic_parameters cp = {0};
3440 cp.block_cipher_mode = KMIP_BLOCK_CBC;
3441 cp.padding_method = KMIP_PAD_PKCS5;
3442 cp.hashing_algorithm = KMIP_HASH_SHA1;
3443 cp.key_role_type = KMIP_ROLE_KEK;
3444
3445 int result = kmip_encode_cryptographic_parameters(&ctx, &cp);
3446 result = report_encoding_test_result(
3447 tracker,
3448 &ctx,
3449 expected,
3450 observed,
3451 result,
3452 __func__);
3453 kmip_destroy(&ctx);
3454 return(result);
3455 }
3456
3457 int
3458 test_decode_cryptographic_parameters(TestTracker *tracker)
3459 {
3460 TRACK_TEST(tracker);
3461
3462 uint8 encoding[72] = {
3463 0x42, 0x00, 0x2B, 0x01, 0x00, 0x00, 0x00, 0x40,
3464 0x42, 0x00, 0x11, 0x05, 0x00, 0x00, 0x00, 0x04,
3465 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
3466 0x42, 0x00, 0x5F, 0x05, 0x00, 0x00, 0x00, 0x04,
3467 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
3468 0x42, 0x00, 0x38, 0x05, 0x00, 0x00, 0x00, 0x04,
3469 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
3470 0x42, 0x00, 0x83, 0x05, 0x00, 0x00, 0x00, 0x04,
3471 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x00
3472 };
3473
3474 struct kmip ctx = {0};
3475 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
3476
3477 struct cryptographic_parameters expected = {0};
3478 kmip_init_cryptographic_parameters(&expected);
3479 expected.block_cipher_mode = KMIP_BLOCK_CBC;
3480 expected.padding_method = KMIP_PAD_PKCS5;
3481 expected.hashing_algorithm = KMIP_HASH_SHA1;
3482 expected.key_role_type = KMIP_ROLE_KEK;
3483 struct cryptographic_parameters observed = {0};
3484 kmip_init_cryptographic_parameters(&observed);
3485
3486 int result = kmip_decode_cryptographic_parameters(&ctx, &observed);
3487 result = report_decoding_test_result(
3488 tracker,
3489 &ctx,
3490 kmip_compare_cryptographic_parameters(&expected, &observed),
3491 result,
3492 __func__);
3493 kmip_free_cryptographic_parameters(&ctx, &observed);
3494 kmip_destroy(&ctx);
3495 return(result);
3496 }
3497
3498 int
3499 test_encode_encryption_key_information(TestTracker *tracker)
3500 {
3501 TRACK_TEST(tracker);
3502
3503 uint8 expected[80] = {
3504 0x42, 0x00, 0x36, 0x01, 0x00, 0x00, 0x00, 0x48,
3505 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
3506 0x31, 0x30, 0x30, 0x31, 0x38, 0x32, 0x64, 0x35,
3507 0x2D, 0x37, 0x32, 0x62, 0x38, 0x2D, 0x34, 0x37,
3508 0x61, 0x61, 0x2D, 0x38, 0x33, 0x38, 0x33, 0x2D,
3509 0x34, 0x64, 0x39, 0x37, 0x64, 0x35, 0x31, 0x32,
3510 0x65, 0x39, 0x38, 0x61, 0x00, 0x00, 0x00, 0x00,
3511 0x42, 0x00, 0x2B, 0x01, 0x00, 0x00, 0x00, 0x10,
3512 0x42, 0x00, 0x11, 0x05, 0x00, 0x00, 0x00, 0x04,
3513 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00
3514 };
3515
3516 uint8 observed[80] = {0};
3517 struct kmip ctx = {0};
3518 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
3519
3520 struct text_string uuid = {0};
3521 uuid.value = "100182d5-72b8-47aa-8383-4d97d512e98a";
3522 uuid.size = 36;
3523
3524 struct cryptographic_parameters cp = {0};
3525 cp.block_cipher_mode = KMIP_BLOCK_NIST_KEY_WRAP;
3526
3527 struct encryption_key_information eki = {0};
3528 eki.unique_identifier = &uuid;
3529 eki.cryptographic_parameters = &cp;
3530
3531 int result = kmip_encode_encryption_key_information(&ctx, &eki);
3532 result = report_encoding_test_result(
3533 tracker,
3534 &ctx,
3535 expected,
3536 observed,
3537 result,
3538 __func__);
3539 kmip_destroy(&ctx);
3540 return(result);
3541 }
3542
3543 int
3544 test_decode_encryption_key_information(TestTracker *tracker)
3545 {
3546 TRACK_TEST(tracker);
3547
3548 uint8 encoding[80] = {
3549 0x42, 0x00, 0x36, 0x01, 0x00, 0x00, 0x00, 0x48,
3550 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
3551 0x31, 0x30, 0x30, 0x31, 0x38, 0x32, 0x64, 0x35,
3552 0x2D, 0x37, 0x32, 0x62, 0x38, 0x2D, 0x34, 0x37,
3553 0x61, 0x61, 0x2D, 0x38, 0x33, 0x38, 0x33, 0x2D,
3554 0x34, 0x64, 0x39, 0x37, 0x64, 0x35, 0x31, 0x32,
3555 0x65, 0x39, 0x38, 0x61, 0x00, 0x00, 0x00, 0x00,
3556 0x42, 0x00, 0x2B, 0x01, 0x00, 0x00, 0x00, 0x10,
3557 0x42, 0x00, 0x11, 0x05, 0x00, 0x00, 0x00, 0x04,
3558 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00
3559 };
3560
3561 struct kmip ctx = {0};
3562 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
3563
3564 struct text_string uuid = {0};
3565 uuid.value = "100182d5-72b8-47aa-8383-4d97d512e98a";
3566 uuid.size = 36;
3567
3568 struct cryptographic_parameters cp = {0};
3569 kmip_init_cryptographic_parameters(&cp);
3570
3571 cp.block_cipher_mode = KMIP_BLOCK_NIST_KEY_WRAP;
3572
3573 struct encryption_key_information expected = {0};
3574 expected.unique_identifier = &uuid;
3575 expected.cryptographic_parameters = &cp;
3576
3577 struct encryption_key_information observed = {0};
3578
3579 int result = kmip_decode_encryption_key_information(&ctx, &observed);
3580 result = report_decoding_test_result(
3581 tracker,
3582 &ctx,
3583 kmip_compare_encryption_key_information(&expected, &observed),
3584 result,
3585 __func__);
3586 kmip_free_encryption_key_information(&ctx, &observed);
3587 kmip_destroy(&ctx);
3588 return(result);
3589 }
3590
3591 int
3592 test_encode_mac_signature_key_information(TestTracker *tracker)
3593 {
3594 TRACK_TEST(tracker);
3595
3596 uint8 expected[80] = {
3597 0x42, 0x00, 0x4E, 0x01, 0x00, 0x00, 0x00, 0x48,
3598 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
3599 0x31, 0x30, 0x30, 0x31, 0x38, 0x32, 0x64, 0x35,
3600 0x2D, 0x37, 0x32, 0x62, 0x38, 0x2D, 0x34, 0x37,
3601 0x61, 0x61, 0x2D, 0x38, 0x33, 0x38, 0x33, 0x2D,
3602 0x34, 0x64, 0x39, 0x37, 0x64, 0x35, 0x31, 0x32,
3603 0x65, 0x39, 0x38, 0x61, 0x00, 0x00, 0x00, 0x00,
3604 0x42, 0x00, 0x2B, 0x01, 0x00, 0x00, 0x00, 0x10,
3605 0x42, 0x00, 0x11, 0x05, 0x00, 0x00, 0x00, 0x04,
3606 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00
3607 };
3608
3609 uint8 observed[80] = {0};
3610 struct kmip ctx = {0};
3611 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
3612
3613 struct text_string uuid = {0};
3614 uuid.value = "100182d5-72b8-47aa-8383-4d97d512e98a";
3615 uuid.size = 36;
3616
3617 struct cryptographic_parameters cp = {0};
3618 cp.block_cipher_mode = KMIP_BLOCK_NIST_KEY_WRAP;
3619
3620 struct mac_signature_key_information mski = {0};
3621 mski.unique_identifier = &uuid;
3622 mski.cryptographic_parameters = &cp;
3623
3624 int result = kmip_encode_mac_signature_key_information(&ctx, &mski);
3625 result = report_encoding_test_result(
3626 tracker,
3627 &ctx,
3628 expected,
3629 observed,
3630 result,
3631 __func__);
3632 kmip_destroy(&ctx);
3633 return(result);
3634 }
3635
3636 int
3637 test_decode_mac_signature_key_information(TestTracker *tracker)
3638 {
3639 TRACK_TEST(tracker);
3640
3641 uint8 encoding[80] = {
3642 0x42, 0x00, 0x4E, 0x01, 0x00, 0x00, 0x00, 0x48,
3643 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
3644 0x31, 0x30, 0x30, 0x31, 0x38, 0x32, 0x64, 0x35,
3645 0x2D, 0x37, 0x32, 0x62, 0x38, 0x2D, 0x34, 0x37,
3646 0x61, 0x61, 0x2D, 0x38, 0x33, 0x38, 0x33, 0x2D,
3647 0x34, 0x64, 0x39, 0x37, 0x64, 0x35, 0x31, 0x32,
3648 0x65, 0x39, 0x38, 0x61, 0x00, 0x00, 0x00, 0x00,
3649 0x42, 0x00, 0x2B, 0x01, 0x00, 0x00, 0x00, 0x10,
3650 0x42, 0x00, 0x11, 0x05, 0x00, 0x00, 0x00, 0x04,
3651 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00
3652 };
3653
3654 struct kmip ctx = {0};
3655 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
3656
3657 struct text_string uuid = {0};
3658 uuid.value = "100182d5-72b8-47aa-8383-4d97d512e98a";
3659 uuid.size = 36;
3660
3661 struct cryptographic_parameters cp = {0};
3662 kmip_init_cryptographic_parameters(&cp);
3663
3664 cp.block_cipher_mode = KMIP_BLOCK_NIST_KEY_WRAP;
3665
3666 struct mac_signature_key_information expected = {0};
3667 expected.unique_identifier = &uuid;
3668 expected.cryptographic_parameters = &cp;
3669
3670 struct mac_signature_key_information observed = {0};
3671
3672 int result = kmip_decode_mac_signature_key_information(&ctx, &observed);
3673 result = report_decoding_test_result(
3674 tracker,
3675 &ctx,
3676 kmip_compare_mac_signature_key_information(&expected, &observed),
3677 result,
3678 __func__);
3679 kmip_free_mac_signature_key_information(&ctx, &observed);
3680 kmip_destroy(&ctx);
3681 return(result);
3682 }
3683
3684 int
3685 test_encode_key_wrapping_data(TestTracker *tracker)
3686 {
3687 TRACK_TEST(tracker);
3688
3689 uint8 expected[104] = {
3690 0x42, 0x00, 0x46, 0x01, 0x00, 0x00, 0x00, 0x60,
3691 0x42, 0x00, 0x9E, 0x05, 0x00, 0x00, 0x00, 0x04,
3692 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
3693 0x42, 0x00, 0x36, 0x01, 0x00, 0x00, 0x00, 0x48,
3694 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
3695 0x31, 0x30, 0x30, 0x31, 0x38, 0x32, 0x64, 0x35,
3696 0x2D, 0x37, 0x32, 0x62, 0x38, 0x2D, 0x34, 0x37,
3697 0x61, 0x61, 0x2D, 0x38, 0x33, 0x38, 0x33, 0x2D,
3698 0x34, 0x64, 0x39, 0x37, 0x64, 0x35, 0x31, 0x32,
3699 0x65, 0x39, 0x38, 0x61, 0x00, 0x00, 0x00, 0x00,
3700 0x42, 0x00, 0x2B, 0x01, 0x00, 0x00, 0x00, 0x10,
3701 0x42, 0x00, 0x11, 0x05, 0x00, 0x00, 0x00, 0x04,
3702 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00
3703 };
3704
3705 uint8 observed[104] = {0};
3706 struct kmip ctx = {0};
3707 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
3708
3709 struct text_string uuid = {0};
3710 uuid.value = "100182d5-72b8-47aa-8383-4d97d512e98a";
3711 uuid.size = 36;
3712
3713 struct cryptographic_parameters cp = {0};
3714 cp.block_cipher_mode = KMIP_BLOCK_NIST_KEY_WRAP;
3715
3716 struct encryption_key_information eki = {0};
3717 eki.unique_identifier = &uuid;
3718 eki.cryptographic_parameters = &cp;
3719
3720 struct key_wrapping_data kwd = {0};
3721 kwd.wrapping_method = KMIP_WRAP_ENCRYPT;
3722 kwd.encryption_key_info = &eki;
3723
3724 int result = kmip_encode_key_wrapping_data(&ctx, &kwd);
3725 result = report_encoding_test_result(
3726 tracker,
3727 &ctx,
3728 expected,
3729 observed,
3730 result,
3731 __func__);
3732 kmip_destroy(&ctx);
3733 return(result);
3734 }
3735
3736 int
3737 test_decode_key_wrapping_data(TestTracker *tracker)
3738 {
3739 TRACK_TEST(tracker);
3740
3741 uint8 encoding[104] = {
3742 0x42, 0x00, 0x46, 0x01, 0x00, 0x00, 0x00, 0x60,
3743 0x42, 0x00, 0x9E, 0x05, 0x00, 0x00, 0x00, 0x04,
3744 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
3745 0x42, 0x00, 0x36, 0x01, 0x00, 0x00, 0x00, 0x48,
3746 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
3747 0x31, 0x30, 0x30, 0x31, 0x38, 0x32, 0x64, 0x35,
3748 0x2D, 0x37, 0x32, 0x62, 0x38, 0x2D, 0x34, 0x37,
3749 0x61, 0x61, 0x2D, 0x38, 0x33, 0x38, 0x33, 0x2D,
3750 0x34, 0x64, 0x39, 0x37, 0x64, 0x35, 0x31, 0x32,
3751 0x65, 0x39, 0x38, 0x61, 0x00, 0x00, 0x00, 0x00,
3752 0x42, 0x00, 0x2B, 0x01, 0x00, 0x00, 0x00, 0x10,
3753 0x42, 0x00, 0x11, 0x05, 0x00, 0x00, 0x00, 0x04,
3754 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00
3755 };
3756
3757 struct kmip ctx = {0};
3758 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
3759
3760 struct text_string uuid = {0};
3761 uuid.value = "100182d5-72b8-47aa-8383-4d97d512e98a";
3762 uuid.size = 36;
3763
3764 struct cryptographic_parameters cp = {0};
3765 kmip_init_cryptographic_parameters(&cp);
3766
3767 cp.block_cipher_mode = KMIP_BLOCK_NIST_KEY_WRAP;
3768
3769 struct encryption_key_information eki = {0};
3770 eki.unique_identifier = &uuid;
3771 eki.cryptographic_parameters = &cp;
3772
3773 struct key_wrapping_data expected = {0};
3774 expected.wrapping_method = KMIP_WRAP_ENCRYPT;
3775 expected.encryption_key_info = &eki;
3776
3777 struct key_wrapping_data observed = {0};
3778
3779 int result = kmip_decode_key_wrapping_data(&ctx, &observed);
3780 result = report_decoding_test_result(
3781 tracker,
3782 &ctx,
3783 kmip_compare_key_wrapping_data(&expected, &observed),
3784 result,
3785 __func__);
3786 kmip_free_key_wrapping_data(&ctx, &observed);
3787 kmip_destroy(&ctx);
3788 return(result);
3789 }
3790
3791 int
3792 test_encode_key_material_byte_string(TestTracker *tracker)
3793 {
3794 TRACK_TEST(tracker);
3795
3796 uint8 expected[24] = {
3797 0x42, 0x00, 0x43, 0x08, 0x00, 0x00, 0x00, 0x10,
3798 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
3799 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
3800 };
3801
3802 uint8 observed[24] = {0};
3803 struct kmip ctx = {0};
3804 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
3805
3806 uint8 value[16] = {
3807 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
3808 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
3809 };
3810 struct byte_string key = {0};
3811 key.value = value;
3812 key.size = ARRAY_LENGTH(value);
3813
3814 int result = kmip_encode_key_material(&ctx, KMIP_KEYFORMAT_RAW, &key);
3815 result = report_encoding_test_result(
3816 tracker,
3817 &ctx,
3818 expected,
3819 observed,
3820 result,
3821 __func__);
3822 kmip_destroy(&ctx);
3823 return(result);
3824 }
3825
3826 int
3827 test_decode_key_material_byte_string(TestTracker *tracker)
3828 {
3829 TRACK_TEST(tracker);
3830
3831 uint8 encoding[24] = {
3832 0x42, 0x00, 0x43, 0x08, 0x00, 0x00, 0x00, 0x10,
3833 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
3834 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
3835 };
3836
3837 struct kmip ctx = {0};
3838 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
3839
3840 uint8 value[16] = {
3841 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
3842 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
3843 };
3844 struct byte_string expected = {0};
3845 expected.value = value;
3846 expected.size = ARRAY_LENGTH(value);
3847
3848 struct byte_string *expected_ptr = &expected;
3849 struct byte_string *observed_ptr = NULL;
3850
3851 int result = kmip_decode_key_material(
3852 &ctx,
3853 KMIP_KEYFORMAT_RAW,
3854 (void**)&observed_ptr);
3855 result = report_decoding_test_result(
3856 tracker,
3857 &ctx,
3858 kmip_compare_key_material(KMIP_KEYFORMAT_RAW, (void**)&expected_ptr, (void**)&observed_ptr),
3859 result,
3860 __func__);
3861 kmip_free_key_material(&ctx, KMIP_KEYFORMAT_RAW, (void**)&observed_ptr);
3862 kmip_destroy(&ctx);
3863 return(result);
3864 }
3865
3866 int
3867 test_encode_key_material_transparent_symmetric_key(TestTracker *tracker)
3868 {
3869 TRACK_TEST(tracker);
3870
3871 uint8 expected[48] = {
3872 0x42, 0x00, 0x43, 0x01, 0x00, 0x00, 0x00, 0x28,
3873 0x42, 0x00, 0x3F, 0x08, 0x00, 0x00, 0x00, 0x20,
3874 0x00, 0x00, 0x11, 0x11, 0x22, 0x22, 0x33, 0x33,
3875 0x44, 0x44, 0x55, 0x55, 0x66, 0x66, 0x77, 0x77,
3876 0x88, 0x88, 0x99, 0x99, 0xAA, 0xAA, 0xBB, 0xBB,
3877 0xCC, 0xCC, 0xDD, 0xDD, 0xEE, 0xEE, 0xFF, 0xFF
3878 };
3879
3880 uint8 observed[48] = {0};
3881 struct kmip ctx = {0};
3882 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
3883
3884 uint8 value[32] = {
3885 0x00, 0x00, 0x11, 0x11, 0x22, 0x22, 0x33, 0x33,
3886 0x44, 0x44, 0x55, 0x55, 0x66, 0x66, 0x77, 0x77,
3887 0x88, 0x88, 0x99, 0x99, 0xAA, 0xAA, 0xBB, 0xBB,
3888 0xCC, 0xCC, 0xDD, 0xDD, 0xEE, 0xEE, 0xFF, 0xFF
3889 };
3890 struct byte_string key = {0};
3891 key.value = value;
3892 key.size = ARRAY_LENGTH(value);
3893 struct transparent_symmetric_key tsk = {0};
3894 tsk.key = &key;
3895
3896 int result = kmip_encode_key_material(&ctx, KMIP_KEYFORMAT_TRANS_SYMMETRIC_KEY, &tsk);
3897 result = report_encoding_test_result(
3898 tracker,
3899 &ctx,
3900 expected,
3901 observed,
3902 result,
3903 __func__);
3904 kmip_destroy(&ctx);
3905 return(result);
3906 }
3907
3908 int
3909 test_decode_key_material_transparent_symmetric_key(TestTracker *tracker)
3910 {
3911 TRACK_TEST(tracker);
3912
3913 uint8 encoding[48] = {
3914 0x42, 0x00, 0x43, 0x01, 0x00, 0x00, 0x00, 0x28,
3915 0x42, 0x00, 0x3F, 0x08, 0x00, 0x00, 0x00, 0x20,
3916 0x00, 0x00, 0x11, 0x11, 0x22, 0x22, 0x33, 0x33,
3917 0x44, 0x44, 0x55, 0x55, 0x66, 0x66, 0x77, 0x77,
3918 0x88, 0x88, 0x99, 0x99, 0xAA, 0xAA, 0xBB, 0xBB,
3919 0xCC, 0xCC, 0xDD, 0xDD, 0xEE, 0xEE, 0xFF, 0xFF
3920 };
3921
3922 struct kmip ctx = {0};
3923 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
3924
3925 uint8 value[32] = {
3926 0x00, 0x00, 0x11, 0x11, 0x22, 0x22, 0x33, 0x33,
3927 0x44, 0x44, 0x55, 0x55, 0x66, 0x66, 0x77, 0x77,
3928 0x88, 0x88, 0x99, 0x99, 0xAA, 0xAA, 0xBB, 0xBB,
3929 0xCC, 0xCC, 0xDD, 0xDD, 0xEE, 0xEE, 0xFF, 0xFF
3930 };
3931 struct byte_string key = {0};
3932 key.value = value;
3933 key.size = ARRAY_LENGTH(value);
3934 struct transparent_symmetric_key expected = {0};
3935 expected.key = &key;
3936
3937 struct transparent_symmetric_key *expected_ptr = &expected;
3938 struct transparent_symmetric_key *observed_ptr = NULL;
3939
3940 int result = kmip_decode_key_material(
3941 &ctx,
3942 KMIP_KEYFORMAT_TRANS_SYMMETRIC_KEY,
3943 (void**)&observed_ptr);
3944 result = report_decoding_test_result(
3945 tracker,
3946 &ctx,
3947 kmip_compare_key_material(KMIP_KEYFORMAT_TRANS_SYMMETRIC_KEY, (void**)&expected_ptr, (void**)&observed_ptr),
3948 result,
3949 __func__);
3950 kmip_free_key_material(
3951 &ctx,
3952 KMIP_KEYFORMAT_TRANS_SYMMETRIC_KEY,
3953 (void**)&observed_ptr);
3954 kmip_destroy(&ctx);
3955 return(result);
3956 }
3957
3958 int
3959 test_encode_key_value(TestTracker *tracker)
3960 {
3961 TRACK_TEST(tracker);
3962
3963 uint8 expected[32] = {
3964 0x42, 0x00, 0x45, 0x01, 0x00, 0x00, 0x00, 0x18,
3965 0x42, 0x00, 0x43, 0x08, 0x00, 0x00, 0x00, 0x10,
3966 0xD3, 0x51, 0x91, 0x0F, 0x1D, 0x79, 0x34, 0xD6,
3967 0xE2, 0xAE, 0x17, 0x57, 0x65, 0x64, 0xE2, 0xBC
3968 };
3969
3970 uint8 observed[32] = {0};
3971 struct kmip ctx = {0};
3972 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
3973
3974 uint8 value[16] = {
3975 0xD3, 0x51, 0x91, 0x0F, 0x1D, 0x79, 0x34, 0xD6,
3976 0xE2, 0xAE, 0x17, 0x57, 0x65, 0x64, 0xE2, 0xBC
3977 };
3978 struct byte_string key = {0};
3979 key.value = value;
3980 key.size = ARRAY_LENGTH(value);
3981
3982 struct key_value kv = {0};
3983 kv.key_material = &key;
3984
3985 int result = kmip_encode_key_value(&ctx, KMIP_KEYFORMAT_RAW, &kv);
3986 result = report_encoding_test_result(
3987 tracker,
3988 &ctx,
3989 expected,
3990 observed,
3991 result,
3992 __func__);
3993 kmip_destroy(&ctx);
3994 return(result);
3995 }
3996
3997 int
3998 test_decode_key_value(TestTracker *tracker)
3999 {
4000 TRACK_TEST(tracker);
4001
4002 uint8 encoding[32] = {
4003 0x42, 0x00, 0x45, 0x01, 0x00, 0x00, 0x00, 0x18,
4004 0x42, 0x00, 0x43, 0x08, 0x00, 0x00, 0x00, 0x10,
4005 0xD3, 0x51, 0x91, 0x0F, 0x1D, 0x79, 0x34, 0xD6,
4006 0xE2, 0xAE, 0x17, 0x57, 0x65, 0x64, 0xE2, 0xBC
4007 };
4008
4009 struct kmip ctx = {0};
4010 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
4011
4012 uint8 value[16] = {
4013 0xD3, 0x51, 0x91, 0x0F, 0x1D, 0x79, 0x34, 0xD6,
4014 0xE2, 0xAE, 0x17, 0x57, 0x65, 0x64, 0xE2, 0xBC
4015 };
4016 struct byte_string key = {0};
4017 key.value = value;
4018 key.size = ARRAY_LENGTH(value);
4019
4020 struct key_value expected = {0};
4021 expected.key_material = &key;
4022 struct key_value observed = {0};
4023
4024 int result = kmip_decode_key_value(&ctx, KMIP_KEYFORMAT_RAW, &observed);
4025 result = report_decoding_test_result(
4026 tracker,
4027 &ctx,
4028 kmip_compare_key_value(KMIP_KEYFORMAT_RAW, &expected, &observed),
4029 result,
4030 __func__);
4031 kmip_free_key_value(&ctx, KMIP_KEYFORMAT_RAW, &observed);
4032 kmip_destroy(&ctx);
4033 return(result);
4034 }
4035
4036 int
4037 test_encode_key_value_with_attributes(TestTracker *tracker)
4038 {
4039 TRACK_TEST(tracker);
4040
4041 uint8 expected[144] = {
4042 0x42, 0x00, 0x45, 0x01, 0x00, 0x00, 0x00, 0x88,
4043 0x42, 0x00, 0x43, 0x08, 0x00, 0x00, 0x00, 0x10,
4044 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
4045 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
4046 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
4047 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x17,
4048 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
4049 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x41, 0x6C,
4050 0x67, 0x6F, 0x72, 0x69, 0x74, 0x68, 0x6D, 0x00,
4051 0x42, 0x00, 0x0B, 0x05, 0x00, 0x00, 0x00, 0x04,
4052 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
4053 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
4054 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x14,
4055 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
4056 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x4C, 0x65,
4057 0x6E, 0x67, 0x74, 0x68, 0x00, 0x00, 0x00, 0x00,
4058 0x42, 0x00, 0x0B, 0x02, 0x00, 0x00, 0x00, 0x04,
4059 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00
4060 };
4061
4062 uint8 observed[144] = {0};
4063 struct kmip ctx = {0};
4064 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
4065
4066 uint8 value[16] = {
4067 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
4068 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
4069 };
4070 struct byte_string key = {0};
4071 key.value = value;
4072 key.size = ARRAY_LENGTH(value);
4073
4074 struct attribute attributes[2] = {0};
4075 for(int i = 0; i < 2; i++)
4076 {
4077 kmip_init_attribute(&attributes[i]);
4078 }
4079
4080 enum cryptographic_algorithm ca = KMIP_CRYPTOALG_AES;
4081 int length = 128;
4082 attributes[0].type = KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM;
4083 attributes[0].value = &ca;
4084 attributes[1].type = KMIP_ATTR_CRYPTOGRAPHIC_LENGTH;
4085 attributes[1].value = &length;
4086
4087 struct key_value kv = {0};
4088 kv.key_material = &key;
4089 kv.attributes = attributes;
4090 kv.attribute_count = ARRAY_LENGTH(attributes);
4091
4092 int result = kmip_encode_key_value(&ctx, KMIP_KEYFORMAT_RAW, &kv);
4093 result = report_encoding_test_result(
4094 tracker,
4095 &ctx,
4096 expected,
4097 observed,
4098 result,
4099 __func__);
4100 kmip_destroy(&ctx);
4101 return(result);
4102 }
4103
4104 int
4105 test_decode_key_value_with_attributes(TestTracker *tracker)
4106 {
4107 TRACK_TEST(tracker);
4108
4109 uint8 encoding[144] = {
4110 0x42, 0x00, 0x45, 0x01, 0x00, 0x00, 0x00, 0x88,
4111 0x42, 0x00, 0x43, 0x08, 0x00, 0x00, 0x00, 0x10,
4112 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
4113 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
4114 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
4115 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x17,
4116 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
4117 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x41, 0x6C,
4118 0x67, 0x6F, 0x72, 0x69, 0x74, 0x68, 0x6D, 0x00,
4119 0x42, 0x00, 0x0B, 0x05, 0x00, 0x00, 0x00, 0x04,
4120 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
4121 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
4122 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x14,
4123 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
4124 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x4C, 0x65,
4125 0x6E, 0x67, 0x74, 0x68, 0x00, 0x00, 0x00, 0x00,
4126 0x42, 0x00, 0x0B, 0x02, 0x00, 0x00, 0x00, 0x04,
4127 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00
4128 };
4129
4130 struct kmip ctx = {0};
4131 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
4132
4133 uint8 value[16] = {
4134 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
4135 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
4136 };
4137 struct byte_string key = {0};
4138 key.value = value;
4139 key.size = ARRAY_LENGTH(value);
4140
4141 struct attribute attributes[2] = {0};
4142 for(size_t i = 0; i < 2; i++)
4143 {
4144 kmip_init_attribute(&attributes[i]);
4145 }
4146
4147 enum cryptographic_algorithm ca = KMIP_CRYPTOALG_AES;
4148 int length = 128;
4149 attributes[0].type = KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM;
4150 attributes[0].value = &ca;
4151 attributes[1].type = KMIP_ATTR_CRYPTOGRAPHIC_LENGTH;
4152 attributes[1].value = &length;
4153
4154 struct key_value expected = {0};
4155 expected.key_material = &key;
4156 expected.attributes = attributes;
4157 expected.attribute_count = ARRAY_LENGTH(attributes);
4158 struct key_value observed = {0};
4159
4160 int result = kmip_decode_key_value(&ctx, KMIP_KEYFORMAT_RAW, &observed);
4161 result = report_decoding_test_result(
4162 tracker,
4163 &ctx,
4164 kmip_compare_key_value(KMIP_KEYFORMAT_RAW, &expected, &observed),
4165 result,
4166 __func__);
4167 kmip_free_key_value(&ctx, KMIP_KEYFORMAT_RAW, &observed);
4168 kmip_destroy(&ctx);
4169 return(result);
4170 }
4171
4172 int
4173 test_encode_key_block_key_value_byte_string(TestTracker *tracker)
4174 {
4175 TRACK_TEST(tracker);
4176
4177 uint8 expected[192] = {
4178 0x42, 0x00, 0x40, 0x01, 0x00, 0x00, 0x00, 0xB8,
4179 0x42, 0x00, 0x42, 0x05, 0x00, 0x00, 0x00, 0x04,
4180 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
4181 0x42, 0x00, 0x45, 0x08, 0x00, 0x00, 0x00, 0x18,
4182 0x1F, 0xA6, 0x8B, 0x0A, 0x81, 0x12, 0xB4, 0x47,
4183 0xAE, 0xF3, 0x4B, 0xD8, 0xFB, 0x5A, 0x7B, 0x82,
4184 0x9D, 0x3E, 0x86, 0x23, 0x71, 0xD2, 0xCF, 0xE5,
4185 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
4186 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
4187 0x42, 0x00, 0x2A, 0x02, 0x00, 0x00, 0x00, 0x04,
4188 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
4189 0x42, 0x00, 0x46, 0x01, 0x00, 0x00, 0x00, 0x60,
4190 0x42, 0x00, 0x9E, 0x05, 0x00, 0x00, 0x00, 0x04,
4191 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
4192 0x42, 0x00, 0x36, 0x01, 0x00, 0x00, 0x00, 0x48,
4193 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
4194 0x31, 0x30, 0x30, 0x31, 0x38, 0x32, 0x64, 0x35,
4195 0x2D, 0x37, 0x32, 0x62, 0x38, 0x2D, 0x34, 0x37,
4196 0x61, 0x61, 0x2D, 0x38, 0x33, 0x38, 0x33, 0x2D,
4197 0x34, 0x64, 0x39, 0x37, 0x64, 0x35, 0x31, 0x32,
4198 0x65, 0x39, 0x38, 0x61, 0x00, 0x00, 0x00, 0x00,
4199 0x42, 0x00, 0x2B, 0x01, 0x00, 0x00, 0x00, 0x10,
4200 0x42, 0x00, 0x11, 0x05, 0x00, 0x00, 0x00, 0x04,
4201 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00
4202 };
4203
4204 uint8 observed[192] = {0};
4205 struct kmip ctx = {0};
4206 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
4207
4208 uint8 value[24] = {
4209 0x1F, 0xA6, 0x8B, 0x0A, 0x81, 0x12, 0xB4, 0x47,
4210 0xAE, 0xF3, 0x4B, 0xD8, 0xFB, 0x5A, 0x7B, 0x82,
4211 0x9D, 0x3E, 0x86, 0x23, 0x71, 0xD2, 0xCF, 0xE5
4212 };
4213 struct byte_string key = {0};
4214 key.value = value;
4215 key.size = ARRAY_LENGTH(value);
4216
4217 struct text_string uuid = {0};
4218 uuid.value = "100182d5-72b8-47aa-8383-4d97d512e98a";
4219 uuid.size = 36;
4220
4221 struct cryptographic_parameters cp = {0};
4222 cp.block_cipher_mode = KMIP_BLOCK_NIST_KEY_WRAP;
4223
4224 struct encryption_key_information eki = {0};
4225 eki.unique_identifier = &uuid;
4226 eki.cryptographic_parameters = &cp;
4227
4228 struct key_wrapping_data kwd = {0};
4229 kwd.wrapping_method = KMIP_WRAP_ENCRYPT;
4230 kwd.encryption_key_info = &eki;
4231
4232 struct key_block kb = {0};
4233 kb.key_format_type = KMIP_KEYFORMAT_RAW;
4234 kb.key_value = &key;
4235 kb.cryptographic_algorithm = KMIP_CRYPTOALG_AES;
4236 kb.cryptographic_length = 128;
4237 kb.key_wrapping_data = &kwd;
4238
4239 int result = kmip_encode_key_block(&ctx, &kb);
4240 result = report_encoding_test_result(
4241 tracker,
4242 &ctx,
4243 expected,
4244 observed,
4245 result,
4246 __func__);
4247 kmip_destroy(&ctx);
4248 return(result);
4249 }
4250
4251 int
4252 test_decode_key_block_key_value_byte_string(TestTracker *tracker)
4253 {
4254 TRACK_TEST(tracker);
4255
4256 uint8 encoding[192] = {
4257 0x42, 0x00, 0x40, 0x01, 0x00, 0x00, 0x00, 0xB8,
4258 0x42, 0x00, 0x42, 0x05, 0x00, 0x00, 0x00, 0x04,
4259 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
4260 0x42, 0x00, 0x45, 0x08, 0x00, 0x00, 0x00, 0x18,
4261 0x1F, 0xA6, 0x8B, 0x0A, 0x81, 0x12, 0xB4, 0x47,
4262 0xAE, 0xF3, 0x4B, 0xD8, 0xFB, 0x5A, 0x7B, 0x82,
4263 0x9D, 0x3E, 0x86, 0x23, 0x71, 0xD2, 0xCF, 0xE5,
4264 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
4265 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
4266 0x42, 0x00, 0x2A, 0x02, 0x00, 0x00, 0x00, 0x04,
4267 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
4268 0x42, 0x00, 0x46, 0x01, 0x00, 0x00, 0x00, 0x60,
4269 0x42, 0x00, 0x9E, 0x05, 0x00, 0x00, 0x00, 0x04,
4270 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
4271 0x42, 0x00, 0x36, 0x01, 0x00, 0x00, 0x00, 0x48,
4272 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
4273 0x31, 0x30, 0x30, 0x31, 0x38, 0x32, 0x64, 0x35,
4274 0x2D, 0x37, 0x32, 0x62, 0x38, 0x2D, 0x34, 0x37,
4275 0x61, 0x61, 0x2D, 0x38, 0x33, 0x38, 0x33, 0x2D,
4276 0x34, 0x64, 0x39, 0x37, 0x64, 0x35, 0x31, 0x32,
4277 0x65, 0x39, 0x38, 0x61, 0x00, 0x00, 0x00, 0x00,
4278 0x42, 0x00, 0x2B, 0x01, 0x00, 0x00, 0x00, 0x10,
4279 0x42, 0x00, 0x11, 0x05, 0x00, 0x00, 0x00, 0x04,
4280 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00
4281 };
4282
4283 struct kmip ctx = {0};
4284 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
4285
4286 uint8 value[24] = {
4287 0x1F, 0xA6, 0x8B, 0x0A, 0x81, 0x12, 0xB4, 0x47,
4288 0xAE, 0xF3, 0x4B, 0xD8, 0xFB, 0x5A, 0x7B, 0x82,
4289 0x9D, 0x3E, 0x86, 0x23, 0x71, 0xD2, 0xCF, 0xE5
4290 };
4291 struct byte_string key = {0};
4292 key.value = value;
4293 key.size = ARRAY_LENGTH(value);
4294
4295 struct text_string uuid = {0};
4296 uuid.value = "100182d5-72b8-47aa-8383-4d97d512e98a";
4297 uuid.size = 36;
4298
4299 struct cryptographic_parameters cp = {0};
4300 kmip_init_cryptographic_parameters(&cp);
4301
4302 cp.block_cipher_mode = KMIP_BLOCK_NIST_KEY_WRAP;
4303
4304 struct encryption_key_information eki = {0};
4305 eki.unique_identifier = &uuid;
4306 eki.cryptographic_parameters = &cp;
4307
4308 struct key_wrapping_data kwd = {0};
4309 kwd.wrapping_method = KMIP_WRAP_ENCRYPT;
4310 kwd.encryption_key_info = &eki;
4311
4312 struct key_block expected = {0};
4313 kmip_init_key_block(&expected);
4314
4315 expected.key_format_type = KMIP_KEYFORMAT_RAW;
4316 expected.key_value = &key;
4317 expected.key_value_type = KMIP_TYPE_BYTE_STRING;
4318 expected.cryptographic_algorithm = KMIP_CRYPTOALG_AES;
4319 expected.cryptographic_length = 128;
4320 expected.key_wrapping_data = &kwd;
4321
4322 struct key_block observed = {0};
4323 kmip_init_key_block(&observed);
4324
4325 int result = kmip_decode_key_block(&ctx, &observed);
4326 result = report_decoding_test_result(
4327 tracker,
4328 &ctx,
4329 kmip_compare_key_block(&expected, &observed),
4330 result,
4331 __func__);
4332 kmip_free_key_block(&ctx, &observed);
4333 kmip_destroy(&ctx);
4334 return(result);
4335 }
4336
4337 int
4338 test_encode_key_block_key_value_structure(TestTracker *tracker)
4339 {
4340 TRACK_TEST(tracker);
4341
4342 uint8 expected[88] = {
4343 0x42, 0x00, 0x40, 0x01, 0x00, 0x00, 0x00, 0x50,
4344 0x42, 0x00, 0x42, 0x05, 0x00, 0x00, 0x00, 0x04,
4345 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
4346 0x42, 0x00, 0x45, 0x01, 0x00, 0x00, 0x00, 0x18,
4347 0x42, 0x00, 0x43, 0x08, 0x00, 0x00, 0x00, 0x10,
4348 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
4349 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
4350 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
4351 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
4352 0x42, 0x00, 0x2A, 0x02, 0x00, 0x00, 0x00, 0x04,
4353 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00
4354 };
4355
4356 uint8 observed[88] = {0};
4357 struct kmip ctx = {0};
4358 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
4359
4360 uint8 value[16] = {
4361 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
4362 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
4363 };
4364 struct byte_string key = {0};
4365 key.value = value;
4366 key.size = ARRAY_LENGTH(value);
4367
4368 struct key_value kv = {0};
4369 kv.key_material = &key;
4370
4371 struct key_block kb = {0};
4372 kb.key_format_type = KMIP_KEYFORMAT_RAW;
4373 kb.key_value = &kv;
4374 kb.cryptographic_algorithm = KMIP_CRYPTOALG_AES;
4375 kb.cryptographic_length = 128;
4376
4377 int result = kmip_encode_key_block(&ctx, &kb);
4378 result = report_encoding_test_result(
4379 tracker,
4380 &ctx,
4381 expected,
4382 observed,
4383 result,
4384 __func__);
4385 kmip_destroy(&ctx);
4386 return(result);
4387 }
4388
4389 int
4390 test_decode_key_block_key_value_structure(TestTracker *tracker)
4391 {
4392 TRACK_TEST(tracker);
4393
4394 uint8 encoding[88] = {
4395 0x42, 0x00, 0x40, 0x01, 0x00, 0x00, 0x00, 0x50,
4396 0x42, 0x00, 0x42, 0x05, 0x00, 0x00, 0x00, 0x04,
4397 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
4398 0x42, 0x00, 0x45, 0x01, 0x00, 0x00, 0x00, 0x18,
4399 0x42, 0x00, 0x43, 0x08, 0x00, 0x00, 0x00, 0x10,
4400 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
4401 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
4402 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
4403 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
4404 0x42, 0x00, 0x2A, 0x02, 0x00, 0x00, 0x00, 0x04,
4405 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00
4406 };
4407
4408 struct kmip ctx = {0};
4409 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
4410
4411 uint8 value[16] = {
4412 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
4413 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
4414 };
4415 struct byte_string key = {0};
4416 key.value = value;
4417 key.size = ARRAY_LENGTH(value);
4418
4419 struct key_value kv = {0};
4420 kv.key_material = &key;
4421
4422 struct key_block expected = {0};
4423 kmip_init_key_block(&expected);
4424
4425 expected.key_format_type = KMIP_KEYFORMAT_RAW;
4426 expected.key_value = &kv;
4427 expected.key_value_type = KMIP_TYPE_STRUCTURE;
4428 expected.cryptographic_algorithm = KMIP_CRYPTOALG_AES;
4429 expected.cryptographic_length = 128;
4430
4431 struct key_block observed = {0};
4432 kmip_init_key_block(&observed);
4433
4434 int result = kmip_decode_key_block(&ctx, &observed);
4435 result = report_decoding_test_result(
4436 tracker,
4437 &ctx,
4438 kmip_compare_key_block(&expected, &observed),
4439 result,
4440 __func__);
4441 kmip_free_key_block(&ctx, &observed);
4442 kmip_destroy(&ctx);
4443 return(result);
4444 }
4445
4446 int
4447 test_encode_symmetric_key(TestTracker *tracker)
4448 {
4449 TRACK_TEST(tracker);
4450
4451 uint8 expected[96] = {
4452 0x42, 0x00, 0x8F, 0x01, 0x00, 0x00, 0x00, 0x58,
4453 0x42, 0x00, 0x40, 0x01, 0x00, 0x00, 0x00, 0x50,
4454 0x42, 0x00, 0x42, 0x05, 0x00, 0x00, 0x00, 0x04,
4455 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
4456 0x42, 0x00, 0x45, 0x01, 0x00, 0x00, 0x00, 0x18,
4457 0x42, 0x00, 0x43, 0x08, 0x00, 0x00, 0x00, 0x10,
4458 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
4459 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
4460 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
4461 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
4462 0x42, 0x00, 0x2A, 0x02, 0x00, 0x00, 0x00, 0x04,
4463 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00
4464 };
4465
4466 uint8 observed[96] = {0};
4467 struct kmip ctx = {0};
4468 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
4469
4470 uint8 value[16] = {
4471 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
4472 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
4473 };
4474 struct byte_string key = {0};
4475 key.value = value;
4476 key.size = ARRAY_LENGTH(value);
4477
4478 struct key_value kv = {0};
4479 kv.key_material = &key;
4480
4481 struct key_block kb = {0};
4482 kb.key_format_type = KMIP_KEYFORMAT_RAW;
4483 kb.key_value = &kv;
4484 kb.cryptographic_algorithm = KMIP_CRYPTOALG_AES;
4485 kb.cryptographic_length = 128;
4486
4487 struct symmetric_key sk = {0};
4488 sk.key_block = &kb;
4489
4490 int result = kmip_encode_symmetric_key(&ctx, &sk);
4491 result = report_encoding_test_result(
4492 tracker,
4493 &ctx,
4494 expected,
4495 observed,
4496 result,
4497 __func__);
4498 kmip_destroy(&ctx);
4499 return(result);
4500 }
4501
4502 int
4503 test_decode_symmetric_key(TestTracker *tracker)
4504 {
4505 TRACK_TEST(tracker);
4506
4507 uint8 encoding[96] = {
4508 0x42, 0x00, 0x8F, 0x01, 0x00, 0x00, 0x00, 0x58,
4509 0x42, 0x00, 0x40, 0x01, 0x00, 0x00, 0x00, 0x50,
4510 0x42, 0x00, 0x42, 0x05, 0x00, 0x00, 0x00, 0x04,
4511 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
4512 0x42, 0x00, 0x45, 0x01, 0x00, 0x00, 0x00, 0x18,
4513 0x42, 0x00, 0x43, 0x08, 0x00, 0x00, 0x00, 0x10,
4514 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
4515 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
4516 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
4517 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
4518 0x42, 0x00, 0x2A, 0x02, 0x00, 0x00, 0x00, 0x04,
4519 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00
4520 };
4521
4522 struct kmip ctx = {0};
4523 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
4524
4525 uint8 value[16] = {
4526 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
4527 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
4528 };
4529 struct byte_string key = {0};
4530 key.value = value;
4531 key.size = ARRAY_LENGTH(value);
4532
4533 struct key_value kv = {0};
4534 kv.key_material = &key;
4535
4536 struct key_block kb = {0};
4537 kb.key_format_type = KMIP_KEYFORMAT_RAW;
4538 kb.key_value = &kv;
4539 kb.key_value_type = KMIP_TYPE_STRUCTURE;
4540 kb.cryptographic_algorithm = KMIP_CRYPTOALG_AES;
4541 kb.cryptographic_length = 128;
4542
4543 struct symmetric_key expected = {0};
4544 expected.key_block = &kb;
4545
4546 struct symmetric_key observed = {0};
4547
4548 int result = kmip_decode_symmetric_key(&ctx, &observed);
4549 result = report_decoding_test_result(
4550 tracker,
4551 &ctx,
4552 kmip_compare_symmetric_key(&expected, &observed),
4553 result,
4554 __func__);
4555 kmip_free_symmetric_key(&ctx, &observed);
4556 kmip_destroy(&ctx);
4557 return(result);
4558 }
4559
4560 int
4561 test_encode_public_key(TestTracker *tracker)
4562 {
4563 TRACK_TEST(tracker);
4564
4565 uint8 expected[248] = {
4566 0x42, 0x00, 0x6D, 0x01, 0x00, 0x00, 0x00, 0xF0,
4567 0x42, 0x00, 0x40, 0x01, 0x00, 0x00, 0x00, 0xE8,
4568 0x42, 0x00, 0x42, 0x05, 0x00, 0x00, 0x00, 0x04,
4569 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00,
4570 0x42, 0x00, 0x45, 0x01, 0x00, 0x00, 0x00, 0xB0,
4571 0x42, 0x00, 0x43, 0x08, 0x00, 0x00, 0x00, 0xA2,
4572 0x30, 0x81, 0x9F, 0x30, 0x0D, 0x06, 0x09, 0x2A,
4573 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01,
4574 0x05, 0x00, 0x03, 0x81, 0x8D, 0x00, 0x30, 0x81,
4575 0x89, 0x02, 0x81, 0x81, 0x00, 0x93, 0x04, 0x51,
4576 0xC9, 0xEC, 0xD9, 0x4F, 0x5B, 0xB9, 0xDA, 0x17,
4577 0xDD, 0x09, 0x38, 0x1B, 0xD2, 0x3B, 0xE4, 0x3E,
4578 0xCA, 0x8C, 0x75, 0x39, 0xF3, 0x01, 0xFC, 0x8A,
4579 0x8C, 0xD5, 0xD5, 0x27, 0x4C, 0x3E, 0x76, 0x99,
4580 0xDB, 0xDC, 0x71, 0x1C, 0x97, 0xA7, 0xAA, 0x91,
4581 0xE2, 0xC5, 0x0A, 0x82, 0xBD, 0x0B, 0x10, 0x34,
4582 0xF0, 0xDF, 0x49, 0x3D, 0xEC, 0x16, 0x36, 0x24,
4583 0x27, 0xE5, 0x8A, 0xCC, 0xE7, 0xF6, 0xCE, 0x0F,
4584 0x9B, 0xCC, 0x61, 0x7B, 0xBD, 0x8C, 0x90, 0xD0,
4585 0x09, 0x4A, 0x27, 0x03, 0xBA, 0x0D, 0x09, 0xEB,
4586 0x19, 0xD1, 0x00, 0x5F, 0x2F, 0xB2, 0x65, 0x52,
4587 0x6A, 0xAC, 0x75, 0xAF, 0x32, 0xF8, 0xBC, 0x78,
4588 0x2C, 0xDE, 0xD2, 0xA5, 0x7F, 0x81, 0x1E, 0x03,
4589 0xEA, 0xF6, 0x7A, 0x94, 0x4D, 0xE5, 0xE7, 0x84,
4590 0x13, 0xDC, 0xA8, 0xF2, 0x32, 0xD0, 0x74, 0xE6,
4591 0xDC, 0xEA, 0x4C, 0xEC, 0x9F, 0x02, 0x03, 0x01,
4592 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4593 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
4594 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
4595 0x42, 0x00, 0x2A, 0x02, 0x00, 0x00, 0x00, 0x04,
4596 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00
4597 };
4598
4599 uint8 observed[248] = {0};
4600 struct kmip ctx = {0};
4601 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
4602
4603 uint8 value[162] = {
4604 0x30, 0x81, 0x9F, 0x30, 0x0D, 0x06, 0x09, 0x2A,
4605 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01,
4606 0x05, 0x00, 0x03, 0x81, 0x8D, 0x00, 0x30, 0x81,
4607 0x89, 0x02, 0x81, 0x81, 0x00, 0x93, 0x04, 0x51,
4608 0xC9, 0xEC, 0xD9, 0x4F, 0x5B, 0xB9, 0xDA, 0x17,
4609 0xDD, 0x09, 0x38, 0x1B, 0xD2, 0x3B, 0xE4, 0x3E,
4610 0xCA, 0x8C, 0x75, 0x39, 0xF3, 0x01, 0xFC, 0x8A,
4611 0x8C, 0xD5, 0xD5, 0x27, 0x4C, 0x3E, 0x76, 0x99,
4612 0xDB, 0xDC, 0x71, 0x1C, 0x97, 0xA7, 0xAA, 0x91,
4613 0xE2, 0xC5, 0x0A, 0x82, 0xBD, 0x0B, 0x10, 0x34,
4614 0xF0, 0xDF, 0x49, 0x3D, 0xEC, 0x16, 0x36, 0x24,
4615 0x27, 0xE5, 0x8A, 0xCC, 0xE7, 0xF6, 0xCE, 0x0F,
4616 0x9B, 0xCC, 0x61, 0x7B, 0xBD, 0x8C, 0x90, 0xD0,
4617 0x09, 0x4A, 0x27, 0x03, 0xBA, 0x0D, 0x09, 0xEB,
4618 0x19, 0xD1, 0x00, 0x5F, 0x2F, 0xB2, 0x65, 0x52,
4619 0x6A, 0xAC, 0x75, 0xAF, 0x32, 0xF8, 0xBC, 0x78,
4620 0x2C, 0xDE, 0xD2, 0xA5, 0x7F, 0x81, 0x1E, 0x03,
4621 0xEA, 0xF6, 0x7A, 0x94, 0x4D, 0xE5, 0xE7, 0x84,
4622 0x13, 0xDC, 0xA8, 0xF2, 0x32, 0xD0, 0x74, 0xE6,
4623 0xDC, 0xEA, 0x4C, 0xEC, 0x9F, 0x02, 0x03, 0x01,
4624 0x00, 0x01
4625 };
4626 struct byte_string key = {0};
4627 key.value = value;
4628 key.size = ARRAY_LENGTH(value);
4629
4630 struct key_value kv = {0};
4631 kv.key_material = &key;
4632
4633 struct key_block kb = {0};
4634 kb.key_format_type = KMIP_KEYFORMAT_X509;
4635 kb.key_value = &kv;
4636 kb.cryptographic_algorithm = KMIP_CRYPTOALG_RSA;
4637 kb.cryptographic_length = 1024;
4638
4639 struct public_key pk = {0};
4640 pk.key_block = &kb;
4641
4642 int result = kmip_encode_public_key(&ctx, &pk);
4643 result = report_encoding_test_result(
4644 tracker,
4645 &ctx,
4646 expected,
4647 observed,
4648 result,
4649 __func__);
4650 kmip_destroy(&ctx);
4651 return(result);
4652 }
4653
4654 int
4655 test_decode_public_key(TestTracker *tracker)
4656 {
4657 TRACK_TEST(tracker);
4658
4659 uint8 encoding[248] = {
4660 0x42, 0x00, 0x6D, 0x01, 0x00, 0x00, 0x00, 0xF0,
4661 0x42, 0x00, 0x40, 0x01, 0x00, 0x00, 0x00, 0xE8,
4662 0x42, 0x00, 0x42, 0x05, 0x00, 0x00, 0x00, 0x04,
4663 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00,
4664 0x42, 0x00, 0x45, 0x01, 0x00, 0x00, 0x00, 0xB0,
4665 0x42, 0x00, 0x43, 0x08, 0x00, 0x00, 0x00, 0xA2,
4666 0x30, 0x81, 0x9F, 0x30, 0x0D, 0x06, 0x09, 0x2A,
4667 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01,
4668 0x05, 0x00, 0x03, 0x81, 0x8D, 0x00, 0x30, 0x81,
4669 0x89, 0x02, 0x81, 0x81, 0x00, 0x93, 0x04, 0x51,
4670 0xC9, 0xEC, 0xD9, 0x4F, 0x5B, 0xB9, 0xDA, 0x17,
4671 0xDD, 0x09, 0x38, 0x1B, 0xD2, 0x3B, 0xE4, 0x3E,
4672 0xCA, 0x8C, 0x75, 0x39, 0xF3, 0x01, 0xFC, 0x8A,
4673 0x8C, 0xD5, 0xD5, 0x27, 0x4C, 0x3E, 0x76, 0x99,
4674 0xDB, 0xDC, 0x71, 0x1C, 0x97, 0xA7, 0xAA, 0x91,
4675 0xE2, 0xC5, 0x0A, 0x82, 0xBD, 0x0B, 0x10, 0x34,
4676 0xF0, 0xDF, 0x49, 0x3D, 0xEC, 0x16, 0x36, 0x24,
4677 0x27, 0xE5, 0x8A, 0xCC, 0xE7, 0xF6, 0xCE, 0x0F,
4678 0x9B, 0xCC, 0x61, 0x7B, 0xBD, 0x8C, 0x90, 0xD0,
4679 0x09, 0x4A, 0x27, 0x03, 0xBA, 0x0D, 0x09, 0xEB,
4680 0x19, 0xD1, 0x00, 0x5F, 0x2F, 0xB2, 0x65, 0x52,
4681 0x6A, 0xAC, 0x75, 0xAF, 0x32, 0xF8, 0xBC, 0x78,
4682 0x2C, 0xDE, 0xD2, 0xA5, 0x7F, 0x81, 0x1E, 0x03,
4683 0xEA, 0xF6, 0x7A, 0x94, 0x4D, 0xE5, 0xE7, 0x84,
4684 0x13, 0xDC, 0xA8, 0xF2, 0x32, 0xD0, 0x74, 0xE6,
4685 0xDC, 0xEA, 0x4C, 0xEC, 0x9F, 0x02, 0x03, 0x01,
4686 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4687 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
4688 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
4689 0x42, 0x00, 0x2A, 0x02, 0x00, 0x00, 0x00, 0x04,
4690 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00
4691 };
4692
4693 struct kmip ctx = {0};
4694 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
4695
4696 uint8 value[162] = {
4697 0x30, 0x81, 0x9F, 0x30, 0x0D, 0x06, 0x09, 0x2A,
4698 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01,
4699 0x05, 0x00, 0x03, 0x81, 0x8D, 0x00, 0x30, 0x81,
4700 0x89, 0x02, 0x81, 0x81, 0x00, 0x93, 0x04, 0x51,
4701 0xC9, 0xEC, 0xD9, 0x4F, 0x5B, 0xB9, 0xDA, 0x17,
4702 0xDD, 0x09, 0x38, 0x1B, 0xD2, 0x3B, 0xE4, 0x3E,
4703 0xCA, 0x8C, 0x75, 0x39, 0xF3, 0x01, 0xFC, 0x8A,
4704 0x8C, 0xD5, 0xD5, 0x27, 0x4C, 0x3E, 0x76, 0x99,
4705 0xDB, 0xDC, 0x71, 0x1C, 0x97, 0xA7, 0xAA, 0x91,
4706 0xE2, 0xC5, 0x0A, 0x82, 0xBD, 0x0B, 0x10, 0x34,
4707 0xF0, 0xDF, 0x49, 0x3D, 0xEC, 0x16, 0x36, 0x24,
4708 0x27, 0xE5, 0x8A, 0xCC, 0xE7, 0xF6, 0xCE, 0x0F,
4709 0x9B, 0xCC, 0x61, 0x7B, 0xBD, 0x8C, 0x90, 0xD0,
4710 0x09, 0x4A, 0x27, 0x03, 0xBA, 0x0D, 0x09, 0xEB,
4711 0x19, 0xD1, 0x00, 0x5F, 0x2F, 0xB2, 0x65, 0x52,
4712 0x6A, 0xAC, 0x75, 0xAF, 0x32, 0xF8, 0xBC, 0x78,
4713 0x2C, 0xDE, 0xD2, 0xA5, 0x7F, 0x81, 0x1E, 0x03,
4714 0xEA, 0xF6, 0x7A, 0x94, 0x4D, 0xE5, 0xE7, 0x84,
4715 0x13, 0xDC, 0xA8, 0xF2, 0x32, 0xD0, 0x74, 0xE6,
4716 0xDC, 0xEA, 0x4C, 0xEC, 0x9F, 0x02, 0x03, 0x01,
4717 0x00, 0x01
4718 };
4719 struct byte_string key = {0};
4720 key.value = value;
4721 key.size = ARRAY_LENGTH(value);
4722
4723 struct key_value kv = {0};
4724 kv.key_material = &key;
4725
4726 struct key_block kb = {0};
4727 kb.key_format_type = KMIP_KEYFORMAT_X509;
4728 kb.key_value = &kv;
4729 kb.key_value_type = KMIP_TYPE_STRUCTURE;
4730 kb.cryptographic_algorithm = KMIP_CRYPTOALG_RSA;
4731 kb.cryptographic_length = 1024;
4732
4733 struct public_key expected = {0};
4734 expected.key_block = &kb;
4735
4736 struct public_key observed = {0};
4737
4738 int result = kmip_decode_public_key(&ctx, &observed);
4739 result = report_decoding_test_result(
4740 tracker,
4741 &ctx,
4742 kmip_compare_public_key(&expected, &observed),
4743 result,
4744 __func__);
4745 kmip_free_public_key(&ctx, &observed);
4746 kmip_destroy(&ctx);
4747 return(result);
4748 }
4749
4750 int
4751 test_encode_private_key(TestTracker *tracker)
4752 {
4753 TRACK_TEST(tracker);
4754
4755 uint8 expected[1280] = {
4756 0x42, 0x00, 0x64, 0x01, 0x00, 0x00, 0x04, 0xF8,
4757 0x42, 0x00, 0x40, 0x01, 0x00, 0x00, 0x04, 0xF0,
4758 0x42, 0x00, 0x42, 0x05, 0x00, 0x00, 0x00, 0x04,
4759 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
4760 0x42, 0x00, 0x45, 0x01, 0x00, 0x00, 0x04, 0xB8,
4761 0x42, 0x00, 0x43, 0x08, 0x00, 0x00, 0x04, 0xA9,
4762 0x30, 0x82, 0x04, 0xA5, 0x02, 0x01, 0x00, 0x02,
4763 0x82, 0x01, 0x01, 0x00, 0xAB, 0x7F, 0x16, 0x1C,
4764 0x00, 0x42, 0x49, 0x6C, 0xCD, 0x6C, 0x6D, 0x4D,
4765 0xAD, 0xB9, 0x19, 0x97, 0x34, 0x35, 0x35, 0x77,
4766 0x76, 0x00, 0x3A, 0xCF, 0x54, 0xB7, 0xAF, 0x1E,
4767 0x44, 0x0A, 0xFB, 0x80, 0xB6, 0x4A, 0x87, 0x55,
4768 0xF8, 0x00, 0x2C, 0xFE, 0xBA, 0x6B, 0x18, 0x45,
4769 0x40, 0xA2, 0xD6, 0x60, 0x86, 0xD7, 0x46, 0x48,
4770 0x34, 0x6D, 0x75, 0xB8, 0xD7, 0x18, 0x12, 0xB2,
4771 0x05, 0x38, 0x7C, 0x0F, 0x65, 0x83, 0xBC, 0x4D,
4772 0x7D, 0xC7, 0xEC, 0x11, 0x4F, 0x3B, 0x17, 0x6B,
4773 0x79, 0x57, 0xC4, 0x22, 0xE7, 0xD0, 0x3F, 0xC6,
4774 0x26, 0x7F, 0xA2, 0xA6, 0xF8, 0x9B, 0x9B, 0xEE,
4775 0x9E, 0x60, 0xA1, 0xD7, 0xC2, 0xD8, 0x33, 0xE5,
4776 0xA5, 0xF4, 0xBB, 0x0B, 0x14, 0x34, 0xF4, 0xE7,
4777 0x95, 0xA4, 0x11, 0x00, 0xF8, 0xAA, 0x21, 0x49,
4778 0x00, 0xDF, 0x8B, 0x65, 0x08, 0x9F, 0x98, 0x13,
4779 0x5B, 0x1C, 0x67, 0xB7, 0x01, 0x67, 0x5A, 0xBD,
4780 0xBC, 0x7D, 0x57, 0x21, 0xAA, 0xC9, 0xD1, 0x4A,
4781 0x7F, 0x08, 0x1F, 0xCE, 0xC8, 0x0B, 0x64, 0xE8,
4782 0xA0, 0xEC, 0xC8, 0x29, 0x53, 0x53, 0xC7, 0x95,
4783 0x32, 0x8A, 0xBF, 0x70, 0xE1, 0xB4, 0x2E, 0x7B,
4784 0xB8, 0xB7, 0xF4, 0xE8, 0xAC, 0x8C, 0x81, 0x0C,
4785 0xDB, 0x66, 0xE3, 0xD2, 0x11, 0x26, 0xEB, 0xA8,
4786 0xDA, 0x7D, 0x0C, 0xA3, 0x41, 0x42, 0xCB, 0x76,
4787 0xF9, 0x1F, 0x01, 0x3D, 0xA8, 0x09, 0xE9, 0xC1,
4788 0xB7, 0xAE, 0x64, 0xC5, 0x41, 0x30, 0xFB, 0xC2,
4789 0x1D, 0x80, 0xE9, 0xC2, 0xCB, 0x06, 0xC5, 0xC8,
4790 0xD7, 0xCC, 0xE8, 0x94, 0x6A, 0x9A, 0xC9, 0x9B,
4791 0x1C, 0x28, 0x15, 0xC3, 0x61, 0x2A, 0x29, 0xA8,
4792 0x2D, 0x73, 0xA1, 0xF9, 0x93, 0x74, 0xFE, 0x30,
4793 0xE5, 0x49, 0x51, 0x66, 0x2A, 0x6E, 0xDA, 0x29,
4794 0xC6, 0xFC, 0x41, 0x13, 0x35, 0xD5, 0xDC, 0x74,
4795 0x26, 0xB0, 0xF6, 0x05, 0x02, 0x03, 0x01, 0x00,
4796 0x01, 0x02, 0x82, 0x01, 0x00, 0x3B, 0x12, 0x45,
4797 0x5D, 0x53, 0xC1, 0x81, 0x65, 0x16, 0xC5, 0x18,
4798 0x49, 0x3F, 0x63, 0x98, 0xAA, 0xFA, 0x72, 0xB1,
4799 0x7D, 0xFA, 0x89, 0x4D, 0xB8, 0x88, 0xA7, 0xD4,
4800 0x8C, 0x0A, 0x47, 0xF6, 0x25, 0x79, 0xA4, 0xE6,
4801 0x44, 0xF8, 0x6D, 0xA7, 0x11, 0xFE, 0xC8, 0x50,
4802 0xCD, 0xD9, 0xDB, 0xBD, 0x17, 0xF6, 0x9A, 0x44,
4803 0x3D, 0x2E, 0xC1, 0xDD, 0x60, 0xD3, 0xC6, 0x18,
4804 0xFA, 0x74, 0xCD, 0xE5, 0xFD, 0xAF, 0xAB, 0xD6,
4805 0xBA, 0xA2, 0x6E, 0xB0, 0xA3, 0xAD, 0xB4, 0xDE,
4806 0xF6, 0x48, 0x0F, 0xB1, 0x21, 0x8C, 0xD3, 0xB0,
4807 0x83, 0xE2, 0x52, 0xE8, 0x85, 0xB6, 0xF0, 0x72,
4808 0x9F, 0x98, 0xB2, 0x14, 0x4D, 0x2B, 0x72, 0x29,
4809 0x3E, 0x1B, 0x11, 0xD7, 0x33, 0x93, 0xBC, 0x41,
4810 0xF7, 0x5B, 0x15, 0xEE, 0x3D, 0x75, 0x69, 0xB4,
4811 0x99, 0x5E, 0xD1, 0xA1, 0x44, 0x25, 0xDA, 0x43,
4812 0x19, 0xB7, 0xB2, 0x6B, 0x0E, 0x8F, 0xEF, 0x17,
4813 0xC3, 0x75, 0x42, 0xAE, 0x5C, 0x6D, 0x58, 0x49,
4814 0xF8, 0x72, 0x09, 0x56, 0x7F, 0x39, 0x25, 0xA4,
4815 0x7B, 0x01, 0x6D, 0x56, 0x48, 0x59, 0x71, 0x7B,
4816 0xC5, 0x7F, 0xCB, 0x45, 0x22, 0xD0, 0xAA, 0x49,
4817 0xCE, 0x81, 0x6E, 0x5B, 0xE7, 0xB3, 0x08, 0x81,
4818 0x93, 0x23, 0x6E, 0xC9, 0xEF, 0xFF, 0x14, 0x08,
4819 0x58, 0x04, 0x5B, 0x73, 0xC5, 0xD7, 0x9B, 0xAF,
4820 0x38, 0xF7, 0xC6, 0x7F, 0x04, 0xC5, 0xDC, 0xF0,
4821 0xE3, 0x80, 0x6A, 0xD9, 0x82, 0xD1, 0x25, 0x90,
4822 0x58, 0xC3, 0x47, 0x3E, 0x84, 0x71, 0x79, 0xA8,
4823 0x78, 0xF2, 0xC6, 0xB3, 0xBD, 0x96, 0x8F, 0xB9,
4824 0x9E, 0xA4, 0x6E, 0x91, 0x85, 0x89, 0x2F, 0x36,
4825 0x76, 0xE7, 0x89, 0x65, 0xC2, 0xAE, 0xD4, 0x87,
4826 0x7B, 0xA3, 0x91, 0x7D, 0xF0, 0x7C, 0x5E, 0x92,
4827 0x74, 0x74, 0xF1, 0x9E, 0x76, 0x4B, 0xA6, 0x1D,
4828 0xC3, 0x8D, 0x63, 0xBF, 0x29, 0x02, 0x81, 0x81,
4829 0x00, 0xD5, 0xC6, 0x9C, 0x8C, 0x3C, 0xDC, 0x24,
4830 0x64, 0x74, 0x4A, 0x79, 0x37, 0x13, 0xDA, 0xFB,
4831 0x9F, 0x1D, 0xBC, 0x79, 0x9F, 0xF9, 0x64, 0x23,
4832 0xFE, 0xCD, 0x3C, 0xBA, 0x79, 0x42, 0x86, 0xBC,
4833 0xE9, 0x20, 0xF4, 0xB5, 0xC1, 0x83, 0xF9, 0x9E,
4834 0xE9, 0x02, 0x8D, 0xB6, 0x21, 0x2C, 0x62, 0x77,
4835 0xC4, 0xC8, 0x29, 0x7F, 0xCF, 0xBC, 0xE7, 0xF7,
4836 0xC2, 0x4C, 0xA4, 0xC5, 0x1F, 0xC7, 0x18, 0x2F,
4837 0xB8, 0xF4, 0x01, 0x9F, 0xB1, 0xD5, 0x65, 0x96,
4838 0x74, 0xC5, 0xCB, 0xE6, 0xD5, 0xFA, 0x99, 0x20,
4839 0x51, 0x34, 0x17, 0x60, 0xCD, 0x00, 0x73, 0x57,
4840 0x29, 0xA0, 0x70, 0xA9, 0xE5, 0x4D, 0x34, 0x2B,
4841 0xEB, 0xA8, 0xEF, 0x47, 0xEE, 0x82, 0xD3, 0xA0,
4842 0x1B, 0x04, 0xCE, 0xC4, 0xA0, 0x0D, 0x4D, 0xDB,
4843 0x41, 0xE3, 0x51, 0x16, 0xFC, 0x22, 0x1E, 0x85,
4844 0x4B, 0x43, 0xA6, 0x96, 0xC0, 0xE6, 0x41, 0x9B,
4845 0x1B, 0x02, 0x81, 0x81, 0x00, 0xCD, 0x5E, 0xA7,
4846 0x70, 0x27, 0x89, 0x06, 0x4B, 0x67, 0x35, 0x40,
4847 0xCB, 0xFF, 0x09, 0x35, 0x6A, 0xD8, 0x0B, 0xC3,
4848 0xD5, 0x92, 0x81, 0x2E, 0xBA, 0x47, 0x61, 0x0B,
4849 0x9F, 0xAC, 0x6A, 0xEC, 0xEF, 0xE2, 0x2A, 0xCA,
4850 0xE4, 0x38, 0x45, 0x9C, 0xDA, 0x74, 0xE5, 0x96,
4851 0x53, 0xD8, 0x8C, 0x04, 0x18, 0x9D, 0x34, 0x39,
4852 0x9B, 0xF5, 0xB1, 0x4B, 0x92, 0x0E, 0x34, 0xEF,
4853 0x38, 0xA7, 0xD0, 0x9F, 0xE6, 0x95, 0x93, 0x39,
4854 0x6E, 0x8F, 0xE7, 0x35, 0xE6, 0xF0, 0xA6, 0xAE,
4855 0x49, 0x90, 0x40, 0x10, 0x41, 0xD8, 0xA4, 0x06,
4856 0xB6, 0xFD, 0x86, 0xA1, 0x16, 0x1E, 0x45, 0xF9,
4857 0x5A, 0x3E, 0xAA, 0x5C, 0x10, 0x12, 0xE6, 0x66,
4858 0x2E, 0x44, 0xF1, 0x5F, 0x33, 0x5A, 0xC9, 0x71,
4859 0xE1, 0x76, 0x6B, 0x2B, 0xB9, 0xC9, 0x85, 0x10,
4860 0x99, 0x74, 0x14, 0x1B, 0x44, 0xD3, 0x7E, 0x1E,
4861 0x31, 0x98, 0x20, 0xA5, 0x5F, 0x02, 0x81, 0x81,
4862 0x00, 0xB2, 0x87, 0x12, 0x37, 0xBF, 0x9F, 0xAD,
4863 0x38, 0xC3, 0x31, 0x6A, 0xB7, 0x87, 0x7A, 0x6A,
4864 0x86, 0x80, 0x63, 0xE5, 0x42, 0xA7, 0x18, 0x6D,
4865 0x43, 0x1E, 0x8D, 0x27, 0xC1, 0x9A, 0xC0, 0x41,
4866 0x45, 0x84, 0x03, 0x39, 0x42, 0xE9, 0xFF, 0x6E,
4867 0x29, 0x73, 0xBB, 0x7B, 0x2D, 0x8B, 0x0E, 0x94,
4868 0xAD, 0x1E, 0xE8, 0x21, 0x58, 0x10, 0x8F, 0xBC,
4869 0x86, 0x64, 0x51, 0x7A, 0x5A, 0x46, 0x7F, 0xB9,
4870 0x63, 0x01, 0x4B, 0xD5, 0xDC, 0xC2, 0xB4, 0xFB,
4871 0x08, 0x7C, 0x23, 0x03, 0x9D, 0x11, 0x92, 0x0D,
4872 0xBE, 0x22, 0xFD, 0x9F, 0x16, 0xB4, 0xD8, 0x9E,
4873 0x23, 0x22, 0x5C, 0xD4, 0x55, 0xAD, 0xBA, 0xF3,
4874 0x2E, 0xF4, 0x3F, 0x18, 0x58, 0x64, 0xA3, 0x6D,
4875 0x63, 0x03, 0x09, 0xD6, 0x85, 0x3F, 0x77, 0x14,
4876 0xB3, 0x9A, 0xAE, 0x1E, 0xBE, 0xE3, 0x93, 0x8F,
4877 0x87, 0xC2, 0x70, 0x7E, 0x17, 0x8C, 0x73, 0x9F,
4878 0x9F, 0x02, 0x81, 0x81, 0x00, 0x96, 0x90, 0xBE,
4879 0xD1, 0x4B, 0x2A, 0xFA, 0xA2, 0x6D, 0x98, 0x6D,
4880 0x59, 0x22, 0x31, 0xEE, 0x27, 0xD7, 0x1D, 0x49,
4881 0x06, 0x5B, 0xD2, 0xBA, 0x1F, 0x78, 0x15, 0x7E,
4882 0x20, 0x22, 0x98, 0x81, 0xFD, 0x9D, 0x23, 0x22,
4883 0x7D, 0x0F, 0x84, 0x79, 0xEA, 0xEF, 0xA9, 0x22,
4884 0xFD, 0x75, 0xD5, 0xB1, 0x6B, 0x1A, 0x56, 0x1F,
4885 0xA6, 0x68, 0x0B, 0x04, 0x0C, 0xA0, 0xBD, 0xCE,
4886 0x65, 0x0B, 0x23, 0xB9, 0x17, 0xA4, 0xB1, 0xBB,
4887 0x79, 0x83, 0xA7, 0x4F, 0xAD, 0x70, 0xE1, 0xC3,
4888 0x05, 0xCB, 0xEC, 0x2B, 0xFF, 0x1A, 0x85, 0xA7,
4889 0x26, 0xA1, 0xD9, 0x02, 0x60, 0xE4, 0xF1, 0x08,
4890 0x4F, 0x51, 0x82, 0x34, 0xDC, 0xD3, 0xFE, 0x77,
4891 0x0B, 0x95, 0x20, 0x21, 0x5B, 0xD5, 0x43, 0xBB,
4892 0x6A, 0x41, 0x17, 0x71, 0x87, 0x54, 0x67, 0x6A,
4893 0x34, 0x17, 0x16, 0x66, 0xA7, 0x9F, 0x26, 0xE7,
4894 0x9C, 0x14, 0x9C, 0x5A, 0xA1, 0x02, 0x81, 0x81,
4895 0x00, 0xA0, 0xC9, 0x85, 0xA0, 0xA0, 0xA7, 0x91,
4896 0xA6, 0x59, 0xF9, 0x97, 0x31, 0x13, 0x4C, 0x44,
4897 0xF3, 0x7B, 0x2E, 0x52, 0x0A, 0x2C, 0xEA, 0x35,
4898 0x80, 0x0A, 0xD2, 0x72, 0x41, 0xED, 0x36, 0x0D,
4899 0xFD, 0xE6, 0xE8, 0xCA, 0x61, 0x4F, 0x12, 0x04,
4900 0x7F, 0xD0, 0x8B, 0x76, 0xAC, 0x4D, 0x13, 0xC0,
4901 0x56, 0xA0, 0x69, 0x9E, 0x2F, 0x98, 0xA1, 0xCA,
4902 0xC9, 0x10, 0x11, 0x29, 0x4D, 0x71, 0x20, 0x8F,
4903 0x4A, 0xBA, 0xB3, 0x3B, 0xA8, 0x7A, 0xA0, 0x51,
4904 0x7F, 0x41, 0x5B, 0xAC, 0xA8, 0x8D, 0x6B, 0xAC,
4905 0x00, 0x60, 0x88, 0xFA, 0x60, 0x1D, 0x34, 0x94,
4906 0x17, 0xE1, 0xF0, 0xC9, 0xB2, 0x3A, 0xFF, 0xA4,
4907 0xD4, 0x96, 0x61, 0x8D, 0xBC, 0x02, 0x49, 0x86,
4908 0xED, 0x69, 0x0B, 0xBB, 0x7B, 0x02, 0x57, 0x68,
4909 0xFF, 0x9D, 0xF8, 0xAC, 0x15, 0x41, 0x6F, 0x48,
4910 0x9F, 0x81, 0x29, 0xC3, 0x23, 0x41, 0xA8, 0xB4,
4911 0x4F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4912 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
4913 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
4914 0x42, 0x00, 0x2A, 0x02, 0x00, 0x00, 0x00, 0x04,
4915 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00
4916 };
4917
4918 uint8 observed[1280] = {0};
4919 struct kmip ctx = {0};
4920 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
4921
4922 uint8 value[1193] = {
4923 0x30, 0x82, 0x04, 0xA5, 0x02, 0x01, 0x00, 0x02,
4924 0x82, 0x01, 0x01, 0x00, 0xAB, 0x7F, 0x16, 0x1C,
4925 0x00, 0x42, 0x49, 0x6C, 0xCD, 0x6C, 0x6D, 0x4D,
4926 0xAD, 0xB9, 0x19, 0x97, 0x34, 0x35, 0x35, 0x77,
4927 0x76, 0x00, 0x3A, 0xCF, 0x54, 0xB7, 0xAF, 0x1E,
4928 0x44, 0x0A, 0xFB, 0x80, 0xB6, 0x4A, 0x87, 0x55,
4929 0xF8, 0x00, 0x2C, 0xFE, 0xBA, 0x6B, 0x18, 0x45,
4930 0x40, 0xA2, 0xD6, 0x60, 0x86, 0xD7, 0x46, 0x48,
4931 0x34, 0x6D, 0x75, 0xB8, 0xD7, 0x18, 0x12, 0xB2,
4932 0x05, 0x38, 0x7C, 0x0F, 0x65, 0x83, 0xBC, 0x4D,
4933 0x7D, 0xC7, 0xEC, 0x11, 0x4F, 0x3B, 0x17, 0x6B,
4934 0x79, 0x57, 0xC4, 0x22, 0xE7, 0xD0, 0x3F, 0xC6,
4935 0x26, 0x7F, 0xA2, 0xA6, 0xF8, 0x9B, 0x9B, 0xEE,
4936 0x9E, 0x60, 0xA1, 0xD7, 0xC2, 0xD8, 0x33, 0xE5,
4937 0xA5, 0xF4, 0xBB, 0x0B, 0x14, 0x34, 0xF4, 0xE7,
4938 0x95, 0xA4, 0x11, 0x00, 0xF8, 0xAA, 0x21, 0x49,
4939 0x00, 0xDF, 0x8B, 0x65, 0x08, 0x9F, 0x98, 0x13,
4940 0x5B, 0x1C, 0x67, 0xB7, 0x01, 0x67, 0x5A, 0xBD,
4941 0xBC, 0x7D, 0x57, 0x21, 0xAA, 0xC9, 0xD1, 0x4A,
4942 0x7F, 0x08, 0x1F, 0xCE, 0xC8, 0x0B, 0x64, 0xE8,
4943 0xA0, 0xEC, 0xC8, 0x29, 0x53, 0x53, 0xC7, 0x95,
4944 0x32, 0x8A, 0xBF, 0x70, 0xE1, 0xB4, 0x2E, 0x7B,
4945 0xB8, 0xB7, 0xF4, 0xE8, 0xAC, 0x8C, 0x81, 0x0C,
4946 0xDB, 0x66, 0xE3, 0xD2, 0x11, 0x26, 0xEB, 0xA8,
4947 0xDA, 0x7D, 0x0C, 0xA3, 0x41, 0x42, 0xCB, 0x76,
4948 0xF9, 0x1F, 0x01, 0x3D, 0xA8, 0x09, 0xE9, 0xC1,
4949 0xB7, 0xAE, 0x64, 0xC5, 0x41, 0x30, 0xFB, 0xC2,
4950 0x1D, 0x80, 0xE9, 0xC2, 0xCB, 0x06, 0xC5, 0xC8,
4951 0xD7, 0xCC, 0xE8, 0x94, 0x6A, 0x9A, 0xC9, 0x9B,
4952 0x1C, 0x28, 0x15, 0xC3, 0x61, 0x2A, 0x29, 0xA8,
4953 0x2D, 0x73, 0xA1, 0xF9, 0x93, 0x74, 0xFE, 0x30,
4954 0xE5, 0x49, 0x51, 0x66, 0x2A, 0x6E, 0xDA, 0x29,
4955 0xC6, 0xFC, 0x41, 0x13, 0x35, 0xD5, 0xDC, 0x74,
4956 0x26, 0xB0, 0xF6, 0x05, 0x02, 0x03, 0x01, 0x00,
4957 0x01, 0x02, 0x82, 0x01, 0x00, 0x3B, 0x12, 0x45,
4958 0x5D, 0x53, 0xC1, 0x81, 0x65, 0x16, 0xC5, 0x18,
4959 0x49, 0x3F, 0x63, 0x98, 0xAA, 0xFA, 0x72, 0xB1,
4960 0x7D, 0xFA, 0x89, 0x4D, 0xB8, 0x88, 0xA7, 0xD4,
4961 0x8C, 0x0A, 0x47, 0xF6, 0x25, 0x79, 0xA4, 0xE6,
4962 0x44, 0xF8, 0x6D, 0xA7, 0x11, 0xFE, 0xC8, 0x50,
4963 0xCD, 0xD9, 0xDB, 0xBD, 0x17, 0xF6, 0x9A, 0x44,
4964 0x3D, 0x2E, 0xC1, 0xDD, 0x60, 0xD3, 0xC6, 0x18,
4965 0xFA, 0x74, 0xCD, 0xE5, 0xFD, 0xAF, 0xAB, 0xD6,
4966 0xBA, 0xA2, 0x6E, 0xB0, 0xA3, 0xAD, 0xB4, 0xDE,
4967 0xF6, 0x48, 0x0F, 0xB1, 0x21, 0x8C, 0xD3, 0xB0,
4968 0x83, 0xE2, 0x52, 0xE8, 0x85, 0xB6, 0xF0, 0x72,
4969 0x9F, 0x98, 0xB2, 0x14, 0x4D, 0x2B, 0x72, 0x29,
4970 0x3E, 0x1B, 0x11, 0xD7, 0x33, 0x93, 0xBC, 0x41,
4971 0xF7, 0x5B, 0x15, 0xEE, 0x3D, 0x75, 0x69, 0xB4,
4972 0x99, 0x5E, 0xD1, 0xA1, 0x44, 0x25, 0xDA, 0x43,
4973 0x19, 0xB7, 0xB2, 0x6B, 0x0E, 0x8F, 0xEF, 0x17,
4974 0xC3, 0x75, 0x42, 0xAE, 0x5C, 0x6D, 0x58, 0x49,
4975 0xF8, 0x72, 0x09, 0x56, 0x7F, 0x39, 0x25, 0xA4,
4976 0x7B, 0x01, 0x6D, 0x56, 0x48, 0x59, 0x71, 0x7B,
4977 0xC5, 0x7F, 0xCB, 0x45, 0x22, 0xD0, 0xAA, 0x49,
4978 0xCE, 0x81, 0x6E, 0x5B, 0xE7, 0xB3, 0x08, 0x81,
4979 0x93, 0x23, 0x6E, 0xC9, 0xEF, 0xFF, 0x14, 0x08,
4980 0x58, 0x04, 0x5B, 0x73, 0xC5, 0xD7, 0x9B, 0xAF,
4981 0x38, 0xF7, 0xC6, 0x7F, 0x04, 0xC5, 0xDC, 0xF0,
4982 0xE3, 0x80, 0x6A, 0xD9, 0x82, 0xD1, 0x25, 0x90,
4983 0x58, 0xC3, 0x47, 0x3E, 0x84, 0x71, 0x79, 0xA8,
4984 0x78, 0xF2, 0xC6, 0xB3, 0xBD, 0x96, 0x8F, 0xB9,
4985 0x9E, 0xA4, 0x6E, 0x91, 0x85, 0x89, 0x2F, 0x36,
4986 0x76, 0xE7, 0x89, 0x65, 0xC2, 0xAE, 0xD4, 0x87,
4987 0x7B, 0xA3, 0x91, 0x7D, 0xF0, 0x7C, 0x5E, 0x92,
4988 0x74, 0x74, 0xF1, 0x9E, 0x76, 0x4B, 0xA6, 0x1D,
4989 0xC3, 0x8D, 0x63, 0xBF, 0x29, 0x02, 0x81, 0x81,
4990 0x00, 0xD5, 0xC6, 0x9C, 0x8C, 0x3C, 0xDC, 0x24,
4991 0x64, 0x74, 0x4A, 0x79, 0x37, 0x13, 0xDA, 0xFB,
4992 0x9F, 0x1D, 0xBC, 0x79, 0x9F, 0xF9, 0x64, 0x23,
4993 0xFE, 0xCD, 0x3C, 0xBA, 0x79, 0x42, 0x86, 0xBC,
4994 0xE9, 0x20, 0xF4, 0xB5, 0xC1, 0x83, 0xF9, 0x9E,
4995 0xE9, 0x02, 0x8D, 0xB6, 0x21, 0x2C, 0x62, 0x77,
4996 0xC4, 0xC8, 0x29, 0x7F, 0xCF, 0xBC, 0xE7, 0xF7,
4997 0xC2, 0x4C, 0xA4, 0xC5, 0x1F, 0xC7, 0x18, 0x2F,
4998 0xB8, 0xF4, 0x01, 0x9F, 0xB1, 0xD5, 0x65, 0x96,
4999 0x74, 0xC5, 0xCB, 0xE6, 0xD5, 0xFA, 0x99, 0x20,
5000 0x51, 0x34, 0x17, 0x60, 0xCD, 0x00, 0x73, 0x57,
5001 0x29, 0xA0, 0x70, 0xA9, 0xE5, 0x4D, 0x34, 0x2B,
5002 0xEB, 0xA8, 0xEF, 0x47, 0xEE, 0x82, 0xD3, 0xA0,
5003 0x1B, 0x04, 0xCE, 0xC4, 0xA0, 0x0D, 0x4D, 0xDB,
5004 0x41, 0xE3, 0x51, 0x16, 0xFC, 0x22, 0x1E, 0x85,
5005 0x4B, 0x43, 0xA6, 0x96, 0xC0, 0xE6, 0x41, 0x9B,
5006 0x1B, 0x02, 0x81, 0x81, 0x00, 0xCD, 0x5E, 0xA7,
5007 0x70, 0x27, 0x89, 0x06, 0x4B, 0x67, 0x35, 0x40,
5008 0xCB, 0xFF, 0x09, 0x35, 0x6A, 0xD8, 0x0B, 0xC3,
5009 0xD5, 0x92, 0x81, 0x2E, 0xBA, 0x47, 0x61, 0x0B,
5010 0x9F, 0xAC, 0x6A, 0xEC, 0xEF, 0xE2, 0x2A, 0xCA,
5011 0xE4, 0x38, 0x45, 0x9C, 0xDA, 0x74, 0xE5, 0x96,
5012 0x53, 0xD8, 0x8C, 0x04, 0x18, 0x9D, 0x34, 0x39,
5013 0x9B, 0xF5, 0xB1, 0x4B, 0x92, 0x0E, 0x34, 0xEF,
5014 0x38, 0xA7, 0xD0, 0x9F, 0xE6, 0x95, 0x93, 0x39,
5015 0x6E, 0x8F, 0xE7, 0x35, 0xE6, 0xF0, 0xA6, 0xAE,
5016 0x49, 0x90, 0x40, 0x10, 0x41, 0xD8, 0xA4, 0x06,
5017 0xB6, 0xFD, 0x86, 0xA1, 0x16, 0x1E, 0x45, 0xF9,
5018 0x5A, 0x3E, 0xAA, 0x5C, 0x10, 0x12, 0xE6, 0x66,
5019 0x2E, 0x44, 0xF1, 0x5F, 0x33, 0x5A, 0xC9, 0x71,
5020 0xE1, 0x76, 0x6B, 0x2B, 0xB9, 0xC9, 0x85, 0x10,
5021 0x99, 0x74, 0x14, 0x1B, 0x44, 0xD3, 0x7E, 0x1E,
5022 0x31, 0x98, 0x20, 0xA5, 0x5F, 0x02, 0x81, 0x81,
5023 0x00, 0xB2, 0x87, 0x12, 0x37, 0xBF, 0x9F, 0xAD,
5024 0x38, 0xC3, 0x31, 0x6A, 0xB7, 0x87, 0x7A, 0x6A,
5025 0x86, 0x80, 0x63, 0xE5, 0x42, 0xA7, 0x18, 0x6D,
5026 0x43, 0x1E, 0x8D, 0x27, 0xC1, 0x9A, 0xC0, 0x41,
5027 0x45, 0x84, 0x03, 0x39, 0x42, 0xE9, 0xFF, 0x6E,
5028 0x29, 0x73, 0xBB, 0x7B, 0x2D, 0x8B, 0x0E, 0x94,
5029 0xAD, 0x1E, 0xE8, 0x21, 0x58, 0x10, 0x8F, 0xBC,
5030 0x86, 0x64, 0x51, 0x7A, 0x5A, 0x46, 0x7F, 0xB9,
5031 0x63, 0x01, 0x4B, 0xD5, 0xDC, 0xC2, 0xB4, 0xFB,
5032 0x08, 0x7C, 0x23, 0x03, 0x9D, 0x11, 0x92, 0x0D,
5033 0xBE, 0x22, 0xFD, 0x9F, 0x16, 0xB4, 0xD8, 0x9E,
5034 0x23, 0x22, 0x5C, 0xD4, 0x55, 0xAD, 0xBA, 0xF3,
5035 0x2E, 0xF4, 0x3F, 0x18, 0x58, 0x64, 0xA3, 0x6D,
5036 0x63, 0x03, 0x09, 0xD6, 0x85, 0x3F, 0x77, 0x14,
5037 0xB3, 0x9A, 0xAE, 0x1E, 0xBE, 0xE3, 0x93, 0x8F,
5038 0x87, 0xC2, 0x70, 0x7E, 0x17, 0x8C, 0x73, 0x9F,
5039 0x9F, 0x02, 0x81, 0x81, 0x00, 0x96, 0x90, 0xBE,
5040 0xD1, 0x4B, 0x2A, 0xFA, 0xA2, 0x6D, 0x98, 0x6D,
5041 0x59, 0x22, 0x31, 0xEE, 0x27, 0xD7, 0x1D, 0x49,
5042 0x06, 0x5B, 0xD2, 0xBA, 0x1F, 0x78, 0x15, 0x7E,
5043 0x20, 0x22, 0x98, 0x81, 0xFD, 0x9D, 0x23, 0x22,
5044 0x7D, 0x0F, 0x84, 0x79, 0xEA, 0xEF, 0xA9, 0x22,
5045 0xFD, 0x75, 0xD5, 0xB1, 0x6B, 0x1A, 0x56, 0x1F,
5046 0xA6, 0x68, 0x0B, 0x04, 0x0C, 0xA0, 0xBD, 0xCE,
5047 0x65, 0x0B, 0x23, 0xB9, 0x17, 0xA4, 0xB1, 0xBB,
5048 0x79, 0x83, 0xA7, 0x4F, 0xAD, 0x70, 0xE1, 0xC3,
5049 0x05, 0xCB, 0xEC, 0x2B, 0xFF, 0x1A, 0x85, 0xA7,
5050 0x26, 0xA1, 0xD9, 0x02, 0x60, 0xE4, 0xF1, 0x08,
5051 0x4F, 0x51, 0x82, 0x34, 0xDC, 0xD3, 0xFE, 0x77,
5052 0x0B, 0x95, 0x20, 0x21, 0x5B, 0xD5, 0x43, 0xBB,
5053 0x6A, 0x41, 0x17, 0x71, 0x87, 0x54, 0x67, 0x6A,
5054 0x34, 0x17, 0x16, 0x66, 0xA7, 0x9F, 0x26, 0xE7,
5055 0x9C, 0x14, 0x9C, 0x5A, 0xA1, 0x02, 0x81, 0x81,
5056 0x00, 0xA0, 0xC9, 0x85, 0xA0, 0xA0, 0xA7, 0x91,
5057 0xA6, 0x59, 0xF9, 0x97, 0x31, 0x13, 0x4C, 0x44,
5058 0xF3, 0x7B, 0x2E, 0x52, 0x0A, 0x2C, 0xEA, 0x35,
5059 0x80, 0x0A, 0xD2, 0x72, 0x41, 0xED, 0x36, 0x0D,
5060 0xFD, 0xE6, 0xE8, 0xCA, 0x61, 0x4F, 0x12, 0x04,
5061 0x7F, 0xD0, 0x8B, 0x76, 0xAC, 0x4D, 0x13, 0xC0,
5062 0x56, 0xA0, 0x69, 0x9E, 0x2F, 0x98, 0xA1, 0xCA,
5063 0xC9, 0x10, 0x11, 0x29, 0x4D, 0x71, 0x20, 0x8F,
5064 0x4A, 0xBA, 0xB3, 0x3B, 0xA8, 0x7A, 0xA0, 0x51,
5065 0x7F, 0x41, 0x5B, 0xAC, 0xA8, 0x8D, 0x6B, 0xAC,
5066 0x00, 0x60, 0x88, 0xFA, 0x60, 0x1D, 0x34, 0x94,
5067 0x17, 0xE1, 0xF0, 0xC9, 0xB2, 0x3A, 0xFF, 0xA4,
5068 0xD4, 0x96, 0x61, 0x8D, 0xBC, 0x02, 0x49, 0x86,
5069 0xED, 0x69, 0x0B, 0xBB, 0x7B, 0x02, 0x57, 0x68,
5070 0xFF, 0x9D, 0xF8, 0xAC, 0x15, 0x41, 0x6F, 0x48,
5071 0x9F, 0x81, 0x29, 0xC3, 0x23, 0x41, 0xA8, 0xB4,
5072 0x4F
5073 };
5074 struct byte_string key = {0};
5075 key.value = value;
5076 key.size = ARRAY_LENGTH(value);
5077
5078 struct key_value kv = {0};
5079 kv.key_material = &key;
5080
5081 struct key_block kb = {0};
5082 kb.key_format_type = KMIP_KEYFORMAT_PKCS1;
5083 kb.key_value = &kv;
5084 kb.cryptographic_algorithm = KMIP_CRYPTOALG_RSA;
5085 kb.cryptographic_length = 2048;
5086
5087 struct private_key pk = {0};
5088 pk.key_block = &kb;
5089
5090 int result = kmip_encode_private_key(&ctx, &pk);
5091 result = report_encoding_test_result(
5092 tracker,
5093 &ctx,
5094 expected,
5095 observed,
5096 result,
5097 __func__);
5098 kmip_destroy(&ctx);
5099 return(result);
5100 }
5101
5102 int
5103 test_decode_private_key(TestTracker *tracker)
5104 {
5105 TRACK_TEST(tracker);
5106
5107 uint8 encoding[1280] = {
5108 0x42, 0x00, 0x64, 0x01, 0x00, 0x00, 0x04, 0xF8,
5109 0x42, 0x00, 0x40, 0x01, 0x00, 0x00, 0x04, 0xF0,
5110 0x42, 0x00, 0x42, 0x05, 0x00, 0x00, 0x00, 0x04,
5111 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
5112 0x42, 0x00, 0x45, 0x01, 0x00, 0x00, 0x04, 0xB8,
5113 0x42, 0x00, 0x43, 0x08, 0x00, 0x00, 0x04, 0xA9,
5114 0x30, 0x82, 0x04, 0xA5, 0x02, 0x01, 0x00, 0x02,
5115 0x82, 0x01, 0x01, 0x00, 0xAB, 0x7F, 0x16, 0x1C,
5116 0x00, 0x42, 0x49, 0x6C, 0xCD, 0x6C, 0x6D, 0x4D,
5117 0xAD, 0xB9, 0x19, 0x97, 0x34, 0x35, 0x35, 0x77,
5118 0x76, 0x00, 0x3A, 0xCF, 0x54, 0xB7, 0xAF, 0x1E,
5119 0x44, 0x0A, 0xFB, 0x80, 0xB6, 0x4A, 0x87, 0x55,
5120 0xF8, 0x00, 0x2C, 0xFE, 0xBA, 0x6B, 0x18, 0x45,
5121 0x40, 0xA2, 0xD6, 0x60, 0x86, 0xD7, 0x46, 0x48,
5122 0x34, 0x6D, 0x75, 0xB8, 0xD7, 0x18, 0x12, 0xB2,
5123 0x05, 0x38, 0x7C, 0x0F, 0x65, 0x83, 0xBC, 0x4D,
5124 0x7D, 0xC7, 0xEC, 0x11, 0x4F, 0x3B, 0x17, 0x6B,
5125 0x79, 0x57, 0xC4, 0x22, 0xE7, 0xD0, 0x3F, 0xC6,
5126 0x26, 0x7F, 0xA2, 0xA6, 0xF8, 0x9B, 0x9B, 0xEE,
5127 0x9E, 0x60, 0xA1, 0xD7, 0xC2, 0xD8, 0x33, 0xE5,
5128 0xA5, 0xF4, 0xBB, 0x0B, 0x14, 0x34, 0xF4, 0xE7,
5129 0x95, 0xA4, 0x11, 0x00, 0xF8, 0xAA, 0x21, 0x49,
5130 0x00, 0xDF, 0x8B, 0x65, 0x08, 0x9F, 0x98, 0x13,
5131 0x5B, 0x1C, 0x67, 0xB7, 0x01, 0x67, 0x5A, 0xBD,
5132 0xBC, 0x7D, 0x57, 0x21, 0xAA, 0xC9, 0xD1, 0x4A,
5133 0x7F, 0x08, 0x1F, 0xCE, 0xC8, 0x0B, 0x64, 0xE8,
5134 0xA0, 0xEC, 0xC8, 0x29, 0x53, 0x53, 0xC7, 0x95,
5135 0x32, 0x8A, 0xBF, 0x70, 0xE1, 0xB4, 0x2E, 0x7B,
5136 0xB8, 0xB7, 0xF4, 0xE8, 0xAC, 0x8C, 0x81, 0x0C,
5137 0xDB, 0x66, 0xE3, 0xD2, 0x11, 0x26, 0xEB, 0xA8,
5138 0xDA, 0x7D, 0x0C, 0xA3, 0x41, 0x42, 0xCB, 0x76,
5139 0xF9, 0x1F, 0x01, 0x3D, 0xA8, 0x09, 0xE9, 0xC1,
5140 0xB7, 0xAE, 0x64, 0xC5, 0x41, 0x30, 0xFB, 0xC2,
5141 0x1D, 0x80, 0xE9, 0xC2, 0xCB, 0x06, 0xC5, 0xC8,
5142 0xD7, 0xCC, 0xE8, 0x94, 0x6A, 0x9A, 0xC9, 0x9B,
5143 0x1C, 0x28, 0x15, 0xC3, 0x61, 0x2A, 0x29, 0xA8,
5144 0x2D, 0x73, 0xA1, 0xF9, 0x93, 0x74, 0xFE, 0x30,
5145 0xE5, 0x49, 0x51, 0x66, 0x2A, 0x6E, 0xDA, 0x29,
5146 0xC6, 0xFC, 0x41, 0x13, 0x35, 0xD5, 0xDC, 0x74,
5147 0x26, 0xB0, 0xF6, 0x05, 0x02, 0x03, 0x01, 0x00,
5148 0x01, 0x02, 0x82, 0x01, 0x00, 0x3B, 0x12, 0x45,
5149 0x5D, 0x53, 0xC1, 0x81, 0x65, 0x16, 0xC5, 0x18,
5150 0x49, 0x3F, 0x63, 0x98, 0xAA, 0xFA, 0x72, 0xB1,
5151 0x7D, 0xFA, 0x89, 0x4D, 0xB8, 0x88, 0xA7, 0xD4,
5152 0x8C, 0x0A, 0x47, 0xF6, 0x25, 0x79, 0xA4, 0xE6,
5153 0x44, 0xF8, 0x6D, 0xA7, 0x11, 0xFE, 0xC8, 0x50,
5154 0xCD, 0xD9, 0xDB, 0xBD, 0x17, 0xF6, 0x9A, 0x44,
5155 0x3D, 0x2E, 0xC1, 0xDD, 0x60, 0xD3, 0xC6, 0x18,
5156 0xFA, 0x74, 0xCD, 0xE5, 0xFD, 0xAF, 0xAB, 0xD6,
5157 0xBA, 0xA2, 0x6E, 0xB0, 0xA3, 0xAD, 0xB4, 0xDE,
5158 0xF6, 0x48, 0x0F, 0xB1, 0x21, 0x8C, 0xD3, 0xB0,
5159 0x83, 0xE2, 0x52, 0xE8, 0x85, 0xB6, 0xF0, 0x72,
5160 0x9F, 0x98, 0xB2, 0x14, 0x4D, 0x2B, 0x72, 0x29,
5161 0x3E, 0x1B, 0x11, 0xD7, 0x33, 0x93, 0xBC, 0x41,
5162 0xF7, 0x5B, 0x15, 0xEE, 0x3D, 0x75, 0x69, 0xB4,
5163 0x99, 0x5E, 0xD1, 0xA1, 0x44, 0x25, 0xDA, 0x43,
5164 0x19, 0xB7, 0xB2, 0x6B, 0x0E, 0x8F, 0xEF, 0x17,
5165 0xC3, 0x75, 0x42, 0xAE, 0x5C, 0x6D, 0x58, 0x49,
5166 0xF8, 0x72, 0x09, 0x56, 0x7F, 0x39, 0x25, 0xA4,
5167 0x7B, 0x01, 0x6D, 0x56, 0x48, 0x59, 0x71, 0x7B,
5168 0xC5, 0x7F, 0xCB, 0x45, 0x22, 0xD0, 0xAA, 0x49,
5169 0xCE, 0x81, 0x6E, 0x5B, 0xE7, 0xB3, 0x08, 0x81,
5170 0x93, 0x23, 0x6E, 0xC9, 0xEF, 0xFF, 0x14, 0x08,
5171 0x58, 0x04, 0x5B, 0x73, 0xC5, 0xD7, 0x9B, 0xAF,
5172 0x38, 0xF7, 0xC6, 0x7F, 0x04, 0xC5, 0xDC, 0xF0,
5173 0xE3, 0x80, 0x6A, 0xD9, 0x82, 0xD1, 0x25, 0x90,
5174 0x58, 0xC3, 0x47, 0x3E, 0x84, 0x71, 0x79, 0xA8,
5175 0x78, 0xF2, 0xC6, 0xB3, 0xBD, 0x96, 0x8F, 0xB9,
5176 0x9E, 0xA4, 0x6E, 0x91, 0x85, 0x89, 0x2F, 0x36,
5177 0x76, 0xE7, 0x89, 0x65, 0xC2, 0xAE, 0xD4, 0x87,
5178 0x7B, 0xA3, 0x91, 0x7D, 0xF0, 0x7C, 0x5E, 0x92,
5179 0x74, 0x74, 0xF1, 0x9E, 0x76, 0x4B, 0xA6, 0x1D,
5180 0xC3, 0x8D, 0x63, 0xBF, 0x29, 0x02, 0x81, 0x81,
5181 0x00, 0xD5, 0xC6, 0x9C, 0x8C, 0x3C, 0xDC, 0x24,
5182 0x64, 0x74, 0x4A, 0x79, 0x37, 0x13, 0xDA, 0xFB,
5183 0x9F, 0x1D, 0xBC, 0x79, 0x9F, 0xF9, 0x64, 0x23,
5184 0xFE, 0xCD, 0x3C, 0xBA, 0x79, 0x42, 0x86, 0xBC,
5185 0xE9, 0x20, 0xF4, 0xB5, 0xC1, 0x83, 0xF9, 0x9E,
5186 0xE9, 0x02, 0x8D, 0xB6, 0x21, 0x2C, 0x62, 0x77,
5187 0xC4, 0xC8, 0x29, 0x7F, 0xCF, 0xBC, 0xE7, 0xF7,
5188 0xC2, 0x4C, 0xA4, 0xC5, 0x1F, 0xC7, 0x18, 0x2F,
5189 0xB8, 0xF4, 0x01, 0x9F, 0xB1, 0xD5, 0x65, 0x96,
5190 0x74, 0xC5, 0xCB, 0xE6, 0xD5, 0xFA, 0x99, 0x20,
5191 0x51, 0x34, 0x17, 0x60, 0xCD, 0x00, 0x73, 0x57,
5192 0x29, 0xA0, 0x70, 0xA9, 0xE5, 0x4D, 0x34, 0x2B,
5193 0xEB, 0xA8, 0xEF, 0x47, 0xEE, 0x82, 0xD3, 0xA0,
5194 0x1B, 0x04, 0xCE, 0xC4, 0xA0, 0x0D, 0x4D, 0xDB,
5195 0x41, 0xE3, 0x51, 0x16, 0xFC, 0x22, 0x1E, 0x85,
5196 0x4B, 0x43, 0xA6, 0x96, 0xC0, 0xE6, 0x41, 0x9B,
5197 0x1B, 0x02, 0x81, 0x81, 0x00, 0xCD, 0x5E, 0xA7,
5198 0x70, 0x27, 0x89, 0x06, 0x4B, 0x67, 0x35, 0x40,
5199 0xCB, 0xFF, 0x09, 0x35, 0x6A, 0xD8, 0x0B, 0xC3,
5200 0xD5, 0x92, 0x81, 0x2E, 0xBA, 0x47, 0x61, 0x0B,
5201 0x9F, 0xAC, 0x6A, 0xEC, 0xEF, 0xE2, 0x2A, 0xCA,
5202 0xE4, 0x38, 0x45, 0x9C, 0xDA, 0x74, 0xE5, 0x96,
5203 0x53, 0xD8, 0x8C, 0x04, 0x18, 0x9D, 0x34, 0x39,
5204 0x9B, 0xF5, 0xB1, 0x4B, 0x92, 0x0E, 0x34, 0xEF,
5205 0x38, 0xA7, 0xD0, 0x9F, 0xE6, 0x95, 0x93, 0x39,
5206 0x6E, 0x8F, 0xE7, 0x35, 0xE6, 0xF0, 0xA6, 0xAE,
5207 0x49, 0x90, 0x40, 0x10, 0x41, 0xD8, 0xA4, 0x06,
5208 0xB6, 0xFD, 0x86, 0xA1, 0x16, 0x1E, 0x45, 0xF9,
5209 0x5A, 0x3E, 0xAA, 0x5C, 0x10, 0x12, 0xE6, 0x66,
5210 0x2E, 0x44, 0xF1, 0x5F, 0x33, 0x5A, 0xC9, 0x71,
5211 0xE1, 0x76, 0x6B, 0x2B, 0xB9, 0xC9, 0x85, 0x10,
5212 0x99, 0x74, 0x14, 0x1B, 0x44, 0xD3, 0x7E, 0x1E,
5213 0x31, 0x98, 0x20, 0xA5, 0x5F, 0x02, 0x81, 0x81,
5214 0x00, 0xB2, 0x87, 0x12, 0x37, 0xBF, 0x9F, 0xAD,
5215 0x38, 0xC3, 0x31, 0x6A, 0xB7, 0x87, 0x7A, 0x6A,
5216 0x86, 0x80, 0x63, 0xE5, 0x42, 0xA7, 0x18, 0x6D,
5217 0x43, 0x1E, 0x8D, 0x27, 0xC1, 0x9A, 0xC0, 0x41,
5218 0x45, 0x84, 0x03, 0x39, 0x42, 0xE9, 0xFF, 0x6E,
5219 0x29, 0x73, 0xBB, 0x7B, 0x2D, 0x8B, 0x0E, 0x94,
5220 0xAD, 0x1E, 0xE8, 0x21, 0x58, 0x10, 0x8F, 0xBC,
5221 0x86, 0x64, 0x51, 0x7A, 0x5A, 0x46, 0x7F, 0xB9,
5222 0x63, 0x01, 0x4B, 0xD5, 0xDC, 0xC2, 0xB4, 0xFB,
5223 0x08, 0x7C, 0x23, 0x03, 0x9D, 0x11, 0x92, 0x0D,
5224 0xBE, 0x22, 0xFD, 0x9F, 0x16, 0xB4, 0xD8, 0x9E,
5225 0x23, 0x22, 0x5C, 0xD4, 0x55, 0xAD, 0xBA, 0xF3,
5226 0x2E, 0xF4, 0x3F, 0x18, 0x58, 0x64, 0xA3, 0x6D,
5227 0x63, 0x03, 0x09, 0xD6, 0x85, 0x3F, 0x77, 0x14,
5228 0xB3, 0x9A, 0xAE, 0x1E, 0xBE, 0xE3, 0x93, 0x8F,
5229 0x87, 0xC2, 0x70, 0x7E, 0x17, 0x8C, 0x73, 0x9F,
5230 0x9F, 0x02, 0x81, 0x81, 0x00, 0x96, 0x90, 0xBE,
5231 0xD1, 0x4B, 0x2A, 0xFA, 0xA2, 0x6D, 0x98, 0x6D,
5232 0x59, 0x22, 0x31, 0xEE, 0x27, 0xD7, 0x1D, 0x49,
5233 0x06, 0x5B, 0xD2, 0xBA, 0x1F, 0x78, 0x15, 0x7E,
5234 0x20, 0x22, 0x98, 0x81, 0xFD, 0x9D, 0x23, 0x22,
5235 0x7D, 0x0F, 0x84, 0x79, 0xEA, 0xEF, 0xA9, 0x22,
5236 0xFD, 0x75, 0xD5, 0xB1, 0x6B, 0x1A, 0x56, 0x1F,
5237 0xA6, 0x68, 0x0B, 0x04, 0x0C, 0xA0, 0xBD, 0xCE,
5238 0x65, 0x0B, 0x23, 0xB9, 0x17, 0xA4, 0xB1, 0xBB,
5239 0x79, 0x83, 0xA7, 0x4F, 0xAD, 0x70, 0xE1, 0xC3,
5240 0x05, 0xCB, 0xEC, 0x2B, 0xFF, 0x1A, 0x85, 0xA7,
5241 0x26, 0xA1, 0xD9, 0x02, 0x60, 0xE4, 0xF1, 0x08,
5242 0x4F, 0x51, 0x82, 0x34, 0xDC, 0xD3, 0xFE, 0x77,
5243 0x0B, 0x95, 0x20, 0x21, 0x5B, 0xD5, 0x43, 0xBB,
5244 0x6A, 0x41, 0x17, 0x71, 0x87, 0x54, 0x67, 0x6A,
5245 0x34, 0x17, 0x16, 0x66, 0xA7, 0x9F, 0x26, 0xE7,
5246 0x9C, 0x14, 0x9C, 0x5A, 0xA1, 0x02, 0x81, 0x81,
5247 0x00, 0xA0, 0xC9, 0x85, 0xA0, 0xA0, 0xA7, 0x91,
5248 0xA6, 0x59, 0xF9, 0x97, 0x31, 0x13, 0x4C, 0x44,
5249 0xF3, 0x7B, 0x2E, 0x52, 0x0A, 0x2C, 0xEA, 0x35,
5250 0x80, 0x0A, 0xD2, 0x72, 0x41, 0xED, 0x36, 0x0D,
5251 0xFD, 0xE6, 0xE8, 0xCA, 0x61, 0x4F, 0x12, 0x04,
5252 0x7F, 0xD0, 0x8B, 0x76, 0xAC, 0x4D, 0x13, 0xC0,
5253 0x56, 0xA0, 0x69, 0x9E, 0x2F, 0x98, 0xA1, 0xCA,
5254 0xC9, 0x10, 0x11, 0x29, 0x4D, 0x71, 0x20, 0x8F,
5255 0x4A, 0xBA, 0xB3, 0x3B, 0xA8, 0x7A, 0xA0, 0x51,
5256 0x7F, 0x41, 0x5B, 0xAC, 0xA8, 0x8D, 0x6B, 0xAC,
5257 0x00, 0x60, 0x88, 0xFA, 0x60, 0x1D, 0x34, 0x94,
5258 0x17, 0xE1, 0xF0, 0xC9, 0xB2, 0x3A, 0xFF, 0xA4,
5259 0xD4, 0x96, 0x61, 0x8D, 0xBC, 0x02, 0x49, 0x86,
5260 0xED, 0x69, 0x0B, 0xBB, 0x7B, 0x02, 0x57, 0x68,
5261 0xFF, 0x9D, 0xF8, 0xAC, 0x15, 0x41, 0x6F, 0x48,
5262 0x9F, 0x81, 0x29, 0xC3, 0x23, 0x41, 0xA8, 0xB4,
5263 0x4F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5264 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
5265 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
5266 0x42, 0x00, 0x2A, 0x02, 0x00, 0x00, 0x00, 0x04,
5267 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00
5268 };
5269
5270 struct kmip ctx = {0};
5271 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
5272
5273 uint8 value[1193] = {
5274 0x30, 0x82, 0x04, 0xA5, 0x02, 0x01, 0x00, 0x02,
5275 0x82, 0x01, 0x01, 0x00, 0xAB, 0x7F, 0x16, 0x1C,
5276 0x00, 0x42, 0x49, 0x6C, 0xCD, 0x6C, 0x6D, 0x4D,
5277 0xAD, 0xB9, 0x19, 0x97, 0x34, 0x35, 0x35, 0x77,
5278 0x76, 0x00, 0x3A, 0xCF, 0x54, 0xB7, 0xAF, 0x1E,
5279 0x44, 0x0A, 0xFB, 0x80, 0xB6, 0x4A, 0x87, 0x55,
5280 0xF8, 0x00, 0x2C, 0xFE, 0xBA, 0x6B, 0x18, 0x45,
5281 0x40, 0xA2, 0xD6, 0x60, 0x86, 0xD7, 0x46, 0x48,
5282 0x34, 0x6D, 0x75, 0xB8, 0xD7, 0x18, 0x12, 0xB2,
5283 0x05, 0x38, 0x7C, 0x0F, 0x65, 0x83, 0xBC, 0x4D,
5284 0x7D, 0xC7, 0xEC, 0x11, 0x4F, 0x3B, 0x17, 0x6B,
5285 0x79, 0x57, 0xC4, 0x22, 0xE7, 0xD0, 0x3F, 0xC6,
5286 0x26, 0x7F, 0xA2, 0xA6, 0xF8, 0x9B, 0x9B, 0xEE,
5287 0x9E, 0x60, 0xA1, 0xD7, 0xC2, 0xD8, 0x33, 0xE5,
5288 0xA5, 0xF4, 0xBB, 0x0B, 0x14, 0x34, 0xF4, 0xE7,
5289 0x95, 0xA4, 0x11, 0x00, 0xF8, 0xAA, 0x21, 0x49,
5290 0x00, 0xDF, 0x8B, 0x65, 0x08, 0x9F, 0x98, 0x13,
5291 0x5B, 0x1C, 0x67, 0xB7, 0x01, 0x67, 0x5A, 0xBD,
5292 0xBC, 0x7D, 0x57, 0x21, 0xAA, 0xC9, 0xD1, 0x4A,
5293 0x7F, 0x08, 0x1F, 0xCE, 0xC8, 0x0B, 0x64, 0xE8,
5294 0xA0, 0xEC, 0xC8, 0x29, 0x53, 0x53, 0xC7, 0x95,
5295 0x32, 0x8A, 0xBF, 0x70, 0xE1, 0xB4, 0x2E, 0x7B,
5296 0xB8, 0xB7, 0xF4, 0xE8, 0xAC, 0x8C, 0x81, 0x0C,
5297 0xDB, 0x66, 0xE3, 0xD2, 0x11, 0x26, 0xEB, 0xA8,
5298 0xDA, 0x7D, 0x0C, 0xA3, 0x41, 0x42, 0xCB, 0x76,
5299 0xF9, 0x1F, 0x01, 0x3D, 0xA8, 0x09, 0xE9, 0xC1,
5300 0xB7, 0xAE, 0x64, 0xC5, 0x41, 0x30, 0xFB, 0xC2,
5301 0x1D, 0x80, 0xE9, 0xC2, 0xCB, 0x06, 0xC5, 0xC8,
5302 0xD7, 0xCC, 0xE8, 0x94, 0x6A, 0x9A, 0xC9, 0x9B,
5303 0x1C, 0x28, 0x15, 0xC3, 0x61, 0x2A, 0x29, 0xA8,
5304 0x2D, 0x73, 0xA1, 0xF9, 0x93, 0x74, 0xFE, 0x30,
5305 0xE5, 0x49, 0x51, 0x66, 0x2A, 0x6E, 0xDA, 0x29,
5306 0xC6, 0xFC, 0x41, 0x13, 0x35, 0xD5, 0xDC, 0x74,
5307 0x26, 0xB0, 0xF6, 0x05, 0x02, 0x03, 0x01, 0x00,
5308 0x01, 0x02, 0x82, 0x01, 0x00, 0x3B, 0x12, 0x45,
5309 0x5D, 0x53, 0xC1, 0x81, 0x65, 0x16, 0xC5, 0x18,
5310 0x49, 0x3F, 0x63, 0x98, 0xAA, 0xFA, 0x72, 0xB1,
5311 0x7D, 0xFA, 0x89, 0x4D, 0xB8, 0x88, 0xA7, 0xD4,
5312 0x8C, 0x0A, 0x47, 0xF6, 0x25, 0x79, 0xA4, 0xE6,
5313 0x44, 0xF8, 0x6D, 0xA7, 0x11, 0xFE, 0xC8, 0x50,
5314 0xCD, 0xD9, 0xDB, 0xBD, 0x17, 0xF6, 0x9A, 0x44,
5315 0x3D, 0x2E, 0xC1, 0xDD, 0x60, 0xD3, 0xC6, 0x18,
5316 0xFA, 0x74, 0xCD, 0xE5, 0xFD, 0xAF, 0xAB, 0xD6,
5317 0xBA, 0xA2, 0x6E, 0xB0, 0xA3, 0xAD, 0xB4, 0xDE,
5318 0xF6, 0x48, 0x0F, 0xB1, 0x21, 0x8C, 0xD3, 0xB0,
5319 0x83, 0xE2, 0x52, 0xE8, 0x85, 0xB6, 0xF0, 0x72,
5320 0x9F, 0x98, 0xB2, 0x14, 0x4D, 0x2B, 0x72, 0x29,
5321 0x3E, 0x1B, 0x11, 0xD7, 0x33, 0x93, 0xBC, 0x41,
5322 0xF7, 0x5B, 0x15, 0xEE, 0x3D, 0x75, 0x69, 0xB4,
5323 0x99, 0x5E, 0xD1, 0xA1, 0x44, 0x25, 0xDA, 0x43,
5324 0x19, 0xB7, 0xB2, 0x6B, 0x0E, 0x8F, 0xEF, 0x17,
5325 0xC3, 0x75, 0x42, 0xAE, 0x5C, 0x6D, 0x58, 0x49,
5326 0xF8, 0x72, 0x09, 0x56, 0x7F, 0x39, 0x25, 0xA4,
5327 0x7B, 0x01, 0x6D, 0x56, 0x48, 0x59, 0x71, 0x7B,
5328 0xC5, 0x7F, 0xCB, 0x45, 0x22, 0xD0, 0xAA, 0x49,
5329 0xCE, 0x81, 0x6E, 0x5B, 0xE7, 0xB3, 0x08, 0x81,
5330 0x93, 0x23, 0x6E, 0xC9, 0xEF, 0xFF, 0x14, 0x08,
5331 0x58, 0x04, 0x5B, 0x73, 0xC5, 0xD7, 0x9B, 0xAF,
5332 0x38, 0xF7, 0xC6, 0x7F, 0x04, 0xC5, 0xDC, 0xF0,
5333 0xE3, 0x80, 0x6A, 0xD9, 0x82, 0xD1, 0x25, 0x90,
5334 0x58, 0xC3, 0x47, 0x3E, 0x84, 0x71, 0x79, 0xA8,
5335 0x78, 0xF2, 0xC6, 0xB3, 0xBD, 0x96, 0x8F, 0xB9,
5336 0x9E, 0xA4, 0x6E, 0x91, 0x85, 0x89, 0x2F, 0x36,
5337 0x76, 0xE7, 0x89, 0x65, 0xC2, 0xAE, 0xD4, 0x87,
5338 0x7B, 0xA3, 0x91, 0x7D, 0xF0, 0x7C, 0x5E, 0x92,
5339 0x74, 0x74, 0xF1, 0x9E, 0x76, 0x4B, 0xA6, 0x1D,
5340 0xC3, 0x8D, 0x63, 0xBF, 0x29, 0x02, 0x81, 0x81,
5341 0x00, 0xD5, 0xC6, 0x9C, 0x8C, 0x3C, 0xDC, 0x24,
5342 0x64, 0x74, 0x4A, 0x79, 0x37, 0x13, 0xDA, 0xFB,
5343 0x9F, 0x1D, 0xBC, 0x79, 0x9F, 0xF9, 0x64, 0x23,
5344 0xFE, 0xCD, 0x3C, 0xBA, 0x79, 0x42, 0x86, 0xBC,
5345 0xE9, 0x20, 0xF4, 0xB5, 0xC1, 0x83, 0xF9, 0x9E,
5346 0xE9, 0x02, 0x8D, 0xB6, 0x21, 0x2C, 0x62, 0x77,
5347 0xC4, 0xC8, 0x29, 0x7F, 0xCF, 0xBC, 0xE7, 0xF7,
5348 0xC2, 0x4C, 0xA4, 0xC5, 0x1F, 0xC7, 0x18, 0x2F,
5349 0xB8, 0xF4, 0x01, 0x9F, 0xB1, 0xD5, 0x65, 0x96,
5350 0x74, 0xC5, 0xCB, 0xE6, 0xD5, 0xFA, 0x99, 0x20,
5351 0x51, 0x34, 0x17, 0x60, 0xCD, 0x00, 0x73, 0x57,
5352 0x29, 0xA0, 0x70, 0xA9, 0xE5, 0x4D, 0x34, 0x2B,
5353 0xEB, 0xA8, 0xEF, 0x47, 0xEE, 0x82, 0xD3, 0xA0,
5354 0x1B, 0x04, 0xCE, 0xC4, 0xA0, 0x0D, 0x4D, 0xDB,
5355 0x41, 0xE3, 0x51, 0x16, 0xFC, 0x22, 0x1E, 0x85,
5356 0x4B, 0x43, 0xA6, 0x96, 0xC0, 0xE6, 0x41, 0x9B,
5357 0x1B, 0x02, 0x81, 0x81, 0x00, 0xCD, 0x5E, 0xA7,
5358 0x70, 0x27, 0x89, 0x06, 0x4B, 0x67, 0x35, 0x40,
5359 0xCB, 0xFF, 0x09, 0x35, 0x6A, 0xD8, 0x0B, 0xC3,
5360 0xD5, 0x92, 0x81, 0x2E, 0xBA, 0x47, 0x61, 0x0B,
5361 0x9F, 0xAC, 0x6A, 0xEC, 0xEF, 0xE2, 0x2A, 0xCA,
5362 0xE4, 0x38, 0x45, 0x9C, 0xDA, 0x74, 0xE5, 0x96,
5363 0x53, 0xD8, 0x8C, 0x04, 0x18, 0x9D, 0x34, 0x39,
5364 0x9B, 0xF5, 0xB1, 0x4B, 0x92, 0x0E, 0x34, 0xEF,
5365 0x38, 0xA7, 0xD0, 0x9F, 0xE6, 0x95, 0x93, 0x39,
5366 0x6E, 0x8F, 0xE7, 0x35, 0xE6, 0xF0, 0xA6, 0xAE,
5367 0x49, 0x90, 0x40, 0x10, 0x41, 0xD8, 0xA4, 0x06,
5368 0xB6, 0xFD, 0x86, 0xA1, 0x16, 0x1E, 0x45, 0xF9,
5369 0x5A, 0x3E, 0xAA, 0x5C, 0x10, 0x12, 0xE6, 0x66,
5370 0x2E, 0x44, 0xF1, 0x5F, 0x33, 0x5A, 0xC9, 0x71,
5371 0xE1, 0x76, 0x6B, 0x2B, 0xB9, 0xC9, 0x85, 0x10,
5372 0x99, 0x74, 0x14, 0x1B, 0x44, 0xD3, 0x7E, 0x1E,
5373 0x31, 0x98, 0x20, 0xA5, 0x5F, 0x02, 0x81, 0x81,
5374 0x00, 0xB2, 0x87, 0x12, 0x37, 0xBF, 0x9F, 0xAD,
5375 0x38, 0xC3, 0x31, 0x6A, 0xB7, 0x87, 0x7A, 0x6A,
5376 0x86, 0x80, 0x63, 0xE5, 0x42, 0xA7, 0x18, 0x6D,
5377 0x43, 0x1E, 0x8D, 0x27, 0xC1, 0x9A, 0xC0, 0x41,
5378 0x45, 0x84, 0x03, 0x39, 0x42, 0xE9, 0xFF, 0x6E,
5379 0x29, 0x73, 0xBB, 0x7B, 0x2D, 0x8B, 0x0E, 0x94,
5380 0xAD, 0x1E, 0xE8, 0x21, 0x58, 0x10, 0x8F, 0xBC,
5381 0x86, 0x64, 0x51, 0x7A, 0x5A, 0x46, 0x7F, 0xB9,
5382 0x63, 0x01, 0x4B, 0xD5, 0xDC, 0xC2, 0xB4, 0xFB,
5383 0x08, 0x7C, 0x23, 0x03, 0x9D, 0x11, 0x92, 0x0D,
5384 0xBE, 0x22, 0xFD, 0x9F, 0x16, 0xB4, 0xD8, 0x9E,
5385 0x23, 0x22, 0x5C, 0xD4, 0x55, 0xAD, 0xBA, 0xF3,
5386 0x2E, 0xF4, 0x3F, 0x18, 0x58, 0x64, 0xA3, 0x6D,
5387 0x63, 0x03, 0x09, 0xD6, 0x85, 0x3F, 0x77, 0x14,
5388 0xB3, 0x9A, 0xAE, 0x1E, 0xBE, 0xE3, 0x93, 0x8F,
5389 0x87, 0xC2, 0x70, 0x7E, 0x17, 0x8C, 0x73, 0x9F,
5390 0x9F, 0x02, 0x81, 0x81, 0x00, 0x96, 0x90, 0xBE,
5391 0xD1, 0x4B, 0x2A, 0xFA, 0xA2, 0x6D, 0x98, 0x6D,
5392 0x59, 0x22, 0x31, 0xEE, 0x27, 0xD7, 0x1D, 0x49,
5393 0x06, 0x5B, 0xD2, 0xBA, 0x1F, 0x78, 0x15, 0x7E,
5394 0x20, 0x22, 0x98, 0x81, 0xFD, 0x9D, 0x23, 0x22,
5395 0x7D, 0x0F, 0x84, 0x79, 0xEA, 0xEF, 0xA9, 0x22,
5396 0xFD, 0x75, 0xD5, 0xB1, 0x6B, 0x1A, 0x56, 0x1F,
5397 0xA6, 0x68, 0x0B, 0x04, 0x0C, 0xA0, 0xBD, 0xCE,
5398 0x65, 0x0B, 0x23, 0xB9, 0x17, 0xA4, 0xB1, 0xBB,
5399 0x79, 0x83, 0xA7, 0x4F, 0xAD, 0x70, 0xE1, 0xC3,
5400 0x05, 0xCB, 0xEC, 0x2B, 0xFF, 0x1A, 0x85, 0xA7,
5401 0x26, 0xA1, 0xD9, 0x02, 0x60, 0xE4, 0xF1, 0x08,
5402 0x4F, 0x51, 0x82, 0x34, 0xDC, 0xD3, 0xFE, 0x77,
5403 0x0B, 0x95, 0x20, 0x21, 0x5B, 0xD5, 0x43, 0xBB,
5404 0x6A, 0x41, 0x17, 0x71, 0x87, 0x54, 0x67, 0x6A,
5405 0x34, 0x17, 0x16, 0x66, 0xA7, 0x9F, 0x26, 0xE7,
5406 0x9C, 0x14, 0x9C, 0x5A, 0xA1, 0x02, 0x81, 0x81,
5407 0x00, 0xA0, 0xC9, 0x85, 0xA0, 0xA0, 0xA7, 0x91,
5408 0xA6, 0x59, 0xF9, 0x97, 0x31, 0x13, 0x4C, 0x44,
5409 0xF3, 0x7B, 0x2E, 0x52, 0x0A, 0x2C, 0xEA, 0x35,
5410 0x80, 0x0A, 0xD2, 0x72, 0x41, 0xED, 0x36, 0x0D,
5411 0xFD, 0xE6, 0xE8, 0xCA, 0x61, 0x4F, 0x12, 0x04,
5412 0x7F, 0xD0, 0x8B, 0x76, 0xAC, 0x4D, 0x13, 0xC0,
5413 0x56, 0xA0, 0x69, 0x9E, 0x2F, 0x98, 0xA1, 0xCA,
5414 0xC9, 0x10, 0x11, 0x29, 0x4D, 0x71, 0x20, 0x8F,
5415 0x4A, 0xBA, 0xB3, 0x3B, 0xA8, 0x7A, 0xA0, 0x51,
5416 0x7F, 0x41, 0x5B, 0xAC, 0xA8, 0x8D, 0x6B, 0xAC,
5417 0x00, 0x60, 0x88, 0xFA, 0x60, 0x1D, 0x34, 0x94,
5418 0x17, 0xE1, 0xF0, 0xC9, 0xB2, 0x3A, 0xFF, 0xA4,
5419 0xD4, 0x96, 0x61, 0x8D, 0xBC, 0x02, 0x49, 0x86,
5420 0xED, 0x69, 0x0B, 0xBB, 0x7B, 0x02, 0x57, 0x68,
5421 0xFF, 0x9D, 0xF8, 0xAC, 0x15, 0x41, 0x6F, 0x48,
5422 0x9F, 0x81, 0x29, 0xC3, 0x23, 0x41, 0xA8, 0xB4,
5423 0x4F
5424 };
5425 struct byte_string key = {0};
5426 key.value = value;
5427 key.size = ARRAY_LENGTH(value);
5428
5429 struct key_value kv = {0};
5430 kv.key_material = &key;
5431
5432 struct key_block kb = {0};
5433 kb.key_format_type = KMIP_KEYFORMAT_PKCS1;
5434 kb.key_value = &kv;
5435 kb.key_value_type = KMIP_TYPE_STRUCTURE;
5436 kb.cryptographic_algorithm = KMIP_CRYPTOALG_RSA;
5437 kb.cryptographic_length = 2048;
5438
5439 struct private_key expected = {0};
5440 expected.key_block = &kb;
5441
5442 struct private_key observed = {0};
5443
5444 int result = kmip_decode_private_key(&ctx, &observed);
5445 result = report_decoding_test_result(
5446 tracker,
5447 &ctx,
5448 kmip_compare_private_key(&expected, &observed),
5449 result,
5450 __func__);
5451 kmip_free_private_key(&ctx, &observed);
5452 kmip_destroy(&ctx);
5453 return(result);
5454 }
5455
5456 int
5457 test_encode_key_wrapping_specification(TestTracker *tracker)
5458 {
5459 TRACK_TEST(tracker);
5460
5461 uint8 expected[136] = {
5462 0x42, 0x00, 0x47, 0x01, 0x00, 0x00, 0x00, 0x80,
5463 0x42, 0x00, 0x9E, 0x05, 0x00, 0x00, 0x00, 0x04,
5464 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
5465 0x42, 0x00, 0x36, 0x01, 0x00, 0x00, 0x00, 0x48,
5466 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
5467 0x66, 0x34, 0x62, 0x32, 0x62, 0x34, 0x63, 0x33,
5468 0x2D, 0x34, 0x63, 0x31, 0x39, 0x2D, 0x34, 0x65,
5469 0x63, 0x66, 0x2D, 0x38, 0x32, 0x37, 0x61, 0x2D,
5470 0x30, 0x31, 0x31, 0x63, 0x61, 0x36, 0x30, 0x35,
5471 0x37, 0x64, 0x33, 0x65, 0x00, 0x00, 0x00, 0x00,
5472 0x42, 0x00, 0x2B, 0x01, 0x00, 0x00, 0x00, 0x10,
5473 0x42, 0x00, 0x11, 0x05, 0x00, 0x00, 0x00, 0x04,
5474 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00,
5475 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x18,
5476 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
5477 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x55, 0x73,
5478 0x61, 0x67, 0x65, 0x20, 0x4D, 0x61, 0x73, 0x6B
5479 };
5480
5481 uint8 observed[136] = {0};
5482 struct kmip ctx = {0};
5483 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
5484
5485 struct text_string uuid = {0};
5486 uuid.value = "f4b2b4c3-4c19-4ecf-827a-011ca6057d3e";
5487 uuid.size = 36;
5488
5489 struct cryptographic_parameters cp = {0};
5490 cp.block_cipher_mode = KMIP_BLOCK_NIST_KEY_WRAP;
5491
5492 struct encryption_key_information eki = {0};
5493 eki.unique_identifier = &uuid;
5494 eki.cryptographic_parameters = &cp;
5495
5496 struct text_string attribute_name = {0};
5497 attribute_name.value = "Cryptographic Usage Mask";
5498 attribute_name.size = 24;
5499
5500 struct key_wrapping_specification kws = {0};
5501 kws.wrapping_method = KMIP_WRAP_ENCRYPT;
5502 kws.encryption_key_info = &eki;
5503 kws.attribute_names = &attribute_name;
5504 kws.attribute_name_count = 1;
5505
5506 int result = kmip_encode_key_wrapping_specification(&ctx, &kws);
5507 result = report_encoding_test_result(
5508 tracker,
5509 &ctx,
5510 expected,
5511 observed,
5512 result,
5513 __func__);
5514 kmip_destroy(&ctx);
5515 return(result);
5516 }
5517
5518 int
5519 test_decode_key_wrapping_specification(TestTracker *tracker)
5520 {
5521 TRACK_TEST(tracker);
5522
5523 uint8 encoding[136] = {
5524 0x42, 0x00, 0x47, 0x01, 0x00, 0x00, 0x00, 0x80,
5525 0x42, 0x00, 0x9E, 0x05, 0x00, 0x00, 0x00, 0x04,
5526 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
5527 0x42, 0x00, 0x36, 0x01, 0x00, 0x00, 0x00, 0x48,
5528 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
5529 0x66, 0x34, 0x62, 0x32, 0x62, 0x34, 0x63, 0x33,
5530 0x2D, 0x34, 0x63, 0x31, 0x39, 0x2D, 0x34, 0x65,
5531 0x63, 0x66, 0x2D, 0x38, 0x32, 0x37, 0x61, 0x2D,
5532 0x30, 0x31, 0x31, 0x63, 0x61, 0x36, 0x30, 0x35,
5533 0x37, 0x64, 0x33, 0x65, 0x00, 0x00, 0x00, 0x00,
5534 0x42, 0x00, 0x2B, 0x01, 0x00, 0x00, 0x00, 0x10,
5535 0x42, 0x00, 0x11, 0x05, 0x00, 0x00, 0x00, 0x04,
5536 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00,
5537 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x18,
5538 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
5539 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x55, 0x73,
5540 0x61, 0x67, 0x65, 0x20, 0x4D, 0x61, 0x73, 0x6B
5541 };
5542
5543 struct kmip ctx = {0};
5544 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
5545
5546 struct text_string uuid = {0};
5547 uuid.value = "f4b2b4c3-4c19-4ecf-827a-011ca6057d3e";
5548 uuid.size = 36;
5549
5550 struct cryptographic_parameters cp = {0};
5551 kmip_init_cryptographic_parameters(&cp);
5552
5553 cp.block_cipher_mode = KMIP_BLOCK_NIST_KEY_WRAP;
5554
5555 struct encryption_key_information eki = {0};
5556 eki.unique_identifier = &uuid;
5557 eki.cryptographic_parameters = &cp;
5558
5559 struct text_string attribute_name = {0};
5560 attribute_name.value = "Cryptographic Usage Mask";
5561 attribute_name.size = 24;
5562
5563 struct key_wrapping_specification expected = {0};
5564 expected.wrapping_method = KMIP_WRAP_ENCRYPT;
5565 expected.encryption_key_info = &eki;
5566 expected.attribute_names = &attribute_name;
5567 expected.attribute_name_count = 1;
5568
5569 struct key_wrapping_specification observed = {0};
5570
5571 int result = kmip_decode_key_wrapping_specification(&ctx, &observed);
5572 result = report_decoding_test_result(
5573 tracker,
5574 &ctx,
5575 kmip_compare_key_wrapping_specification(&expected, &observed),
5576 result,
5577 __func__);
5578 kmip_free_key_wrapping_specification(&ctx, &observed);
5579 kmip_destroy(&ctx);
5580 return(result);
5581 }
5582
5583 int
5584 test_encode_create_request_payload(TestTracker *tracker)
5585 {
5586 TRACK_TEST(tracker);
5587
5588 /* This encoding matches the following set of values:
5589 * Request Payload
5590 * Object Type - Symmetric Key
5591 * Template Attribute
5592 * Attribute
5593 * Attribute Name - Cryptographic Algorithm
5594 * Attribute Value - AES
5595 * Attribute
5596 * Attribute Name - Cryptographic Length
5597 * Attribute Value - 128
5598 * Attribute
5599 * Attribute Name - Cryptographic Usage Mask
5600 * Attribute Value - Encrypt | Decrypt
5601 */
5602 uint8 expected[200] = {
5603 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, 0xC0,
5604 0x42, 0x00, 0x57, 0x05, 0x00, 0x00, 0x00, 0x04,
5605 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
5606 0x42, 0x00, 0x91, 0x01, 0x00, 0x00, 0x00, 0xA8,
5607 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
5608 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x17,
5609 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
5610 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x41, 0x6C,
5611 0x67, 0x6F, 0x72, 0x69, 0x74, 0x68, 0x6D, 0x00,
5612 0x42, 0x00, 0x0B, 0x05, 0x00, 0x00, 0x00, 0x04,
5613 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
5614 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
5615 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x14,
5616 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
5617 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x4C, 0x65,
5618 0x6E, 0x67, 0x74, 0x68, 0x00, 0x00, 0x00, 0x00,
5619 0x42, 0x00, 0x0B, 0x02, 0x00, 0x00, 0x00, 0x04,
5620 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
5621 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
5622 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x18,
5623 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
5624 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x55, 0x73,
5625 0x61, 0x67, 0x65, 0x20, 0x4D, 0x61, 0x73, 0x6B,
5626 0x42, 0x00, 0x0B, 0x02, 0x00, 0x00, 0x00, 0x04,
5627 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00
5628 };
5629
5630 uint8 observed[200] = {0};
5631 struct kmip ctx = {0};
5632 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
5633
5634 struct attribute a[3] = {0};
5635 for(int i = 0; i < 3; i++)
5636 {
5637 kmip_init_attribute(&a[i]);
5638 }
5639
5640 enum cryptographic_algorithm algorithm = KMIP_CRYPTOALG_AES;
5641 a[0].type = KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM;
5642 a[0].value = &algorithm;
5643
5644 int32 length = 128;
5645 a[1].type = KMIP_ATTR_CRYPTOGRAPHIC_LENGTH;
5646 a[1].value = &length;
5647
5648 int32 mask = KMIP_CRYPTOMASK_ENCRYPT | KMIP_CRYPTOMASK_DECRYPT;
5649 a[2].type = KMIP_ATTR_CRYPTOGRAPHIC_USAGE_MASK;
5650 a[2].value = &mask;
5651
5652 struct template_attribute ta = {0};
5653 ta.attributes = a;
5654 ta.attribute_count = ARRAY_LENGTH(a);
5655
5656 struct create_request_payload crp = {0};
5657 crp.object_type = KMIP_OBJTYPE_SYMMETRIC_KEY;
5658 crp.template_attribute = &ta;
5659
5660 int result = kmip_encode_create_request_payload(&ctx, &crp);
5661 result = report_encoding_test_result(
5662 tracker,
5663 &ctx,
5664 expected,
5665 observed,
5666 result,
5667 __func__);
5668 kmip_destroy(&ctx);
5669 return(result);
5670 }
5671
5672 int
5673 test_encode_create_request_payload_kmip_2_0(TestTracker *tracker)
5674 {
5675 TRACK_TEST(tracker);
5676
5677 /* This encoding matches the following set of values:
5678 * Request Payload
5679 * Object Type - Symmetric Key
5680 * Attributes
5681 * Cryptographic Algorithm - AES
5682 * Cryptographic Length - 128
5683 * Cryptographic Usage Mask - Encrypt | Decrypt
5684 * Protection Storage Masks
5685 * Protection Storage Mask - Software | On System
5686 * Protection Storage Mask - Off System | Off Premises
5687 */
5688 uint8 expected[120] = {
5689 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, 0x70,
5690 0x42, 0x00, 0x57, 0x05, 0x00, 0x00, 0x00, 0x04,
5691 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
5692 0x42, 0x01, 0x25, 0x01, 0x00, 0x00, 0x00, 0x30,
5693 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
5694 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
5695 0x42, 0x00, 0x2A, 0x02, 0x00, 0x00, 0x00, 0x04,
5696 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
5697 0x42, 0x00, 0x2C, 0x02, 0x00, 0x00, 0x00, 0x04,
5698 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00,
5699 0x42, 0x01, 0x5F, 0x01, 0x00, 0x00, 0x00, 0x20,
5700 0x42, 0x01, 0x5E, 0x02, 0x00, 0x00, 0x00, 0x04,
5701 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00,
5702 0x42, 0x01, 0x5E, 0x02, 0x00, 0x00, 0x00, 0x04,
5703 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00
5704 };
5705
5706 uint8 observed[120] = {0};
5707 struct kmip ctx = {0};
5708 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_2_0);
5709
5710 Attribute a[3] = {0};
5711 for(int i = 0; i < 3; i++)
5712 {
5713 kmip_init_attribute(&a[i]);
5714 }
5715
5716 enum cryptographic_algorithm algorithm = KMIP_CRYPTOALG_AES;
5717 a[0].type = KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM;
5718 a[0].value = &algorithm;
5719
5720 int32 length = 128;
5721 a[1].type = KMIP_ATTR_CRYPTOGRAPHIC_LENGTH;
5722 a[1].value = &length;
5723
5724 int32 mask = KMIP_CRYPTOMASK_ENCRYPT | KMIP_CRYPTOMASK_DECRYPT;
5725 a[2].type = KMIP_ATTR_CRYPTOGRAPHIC_USAGE_MASK;
5726 a[2].value = &mask;
5727
5728 Attributes attributes = {0};
5729 LinkedList list = {0};
5730 LinkedListItem item_1, item_2, item_3 = {0};
5731 item_1.data = &a[0];
5732 item_2.data = &a[1];
5733 item_3.data = &a[2];
5734 kmip_linked_list_enqueue(&list, &item_1);
5735 kmip_linked_list_enqueue(&list, &item_2);
5736 kmip_linked_list_enqueue(&list, &item_3);
5737 attributes.attribute_list = &list;
5738
5739 ProtectionStorageMasks psm = {0};
5740 LinkedList masks = {0};
5741 LinkedListItem mask_1, mask_2 = {0};
5742 int32 m1 = KMIP_PROTECT_SOFTWARE | KMIP_PROTECT_ON_SYSTEM;
5743 int32 m2 = KMIP_PROTECT_OFF_SYSTEM | KMIP_PROTECT_OFF_PREMISES;
5744 mask_1.data = &m1;
5745 mask_2.data = &m2;
5746 kmip_linked_list_enqueue(&masks, &mask_1);
5747 kmip_linked_list_enqueue(&masks, &mask_2);
5748 psm.masks = &masks;
5749
5750 CreateRequestPayload payload = {0};
5751 payload.object_type = KMIP_OBJTYPE_SYMMETRIC_KEY;
5752 payload.attributes = &attributes;
5753 payload.protection_storage_masks = &psm;
5754
5755 int result = kmip_encode_create_request_payload(&ctx, &payload);
5756 result = report_encoding_test_result(
5757 tracker,
5758 &ctx,
5759 expected,
5760 observed,
5761 result,
5762 __func__);
5763 kmip_destroy(&ctx);
5764 return(result);
5765 }
5766
5767 int
5768 test_decode_create_request_payload(TestTracker *tracker)
5769 {
5770 TRACK_TEST(tracker);
5771
5772 uint8 encoding[200] = {
5773 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, 0xC0,
5774 0x42, 0x00, 0x57, 0x05, 0x00, 0x00, 0x00, 0x04,
5775 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
5776 0x42, 0x00, 0x91, 0x01, 0x00, 0x00, 0x00, 0xA8,
5777 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
5778 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x17,
5779 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
5780 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x41, 0x6C,
5781 0x67, 0x6F, 0x72, 0x69, 0x74, 0x68, 0x6D, 0x00,
5782 0x42, 0x00, 0x0B, 0x05, 0x00, 0x00, 0x00, 0x04,
5783 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
5784 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
5785 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x14,
5786 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
5787 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x4C, 0x65,
5788 0x6E, 0x67, 0x74, 0x68, 0x00, 0x00, 0x00, 0x00,
5789 0x42, 0x00, 0x0B, 0x02, 0x00, 0x00, 0x00, 0x04,
5790 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
5791 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
5792 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x18,
5793 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
5794 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x55, 0x73,
5795 0x61, 0x67, 0x65, 0x20, 0x4D, 0x61, 0x73, 0x6B,
5796 0x42, 0x00, 0x0B, 0x02, 0x00, 0x00, 0x00, 0x04,
5797 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00
5798 };
5799
5800 struct kmip ctx = {0};
5801 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
5802
5803 struct attribute a[3] = {0};
5804 for(int i = 0; i < 3; i++)
5805 {
5806 kmip_init_attribute(&a[i]);
5807 }
5808
5809 enum cryptographic_algorithm algorithm = KMIP_CRYPTOALG_AES;
5810 a[0].type = KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM;
5811 a[0].value = &algorithm;
5812
5813 int32 length = 128;
5814 a[1].type = KMIP_ATTR_CRYPTOGRAPHIC_LENGTH;
5815 a[1].value = &length;
5816
5817 int32 mask = KMIP_CRYPTOMASK_ENCRYPT | KMIP_CRYPTOMASK_DECRYPT;
5818 a[2].type = KMIP_ATTR_CRYPTOGRAPHIC_USAGE_MASK;
5819 a[2].value = &mask;
5820
5821 struct template_attribute ta = {0};
5822 ta.attributes = a;
5823 ta.attribute_count = ARRAY_LENGTH(a);
5824
5825 struct create_request_payload expected = {0};
5826 expected.object_type = KMIP_OBJTYPE_SYMMETRIC_KEY;
5827 expected.template_attribute = &ta;
5828
5829 struct create_request_payload observed = {0};
5830
5831 int result = kmip_decode_create_request_payload(&ctx, &observed);
5832 result = report_decoding_test_result(
5833 tracker,
5834 &ctx,
5835 kmip_compare_create_request_payload(&expected, &observed),
5836 result,
5837 __func__);
5838 kmip_free_create_request_payload(&ctx, &observed);
5839 kmip_destroy(&ctx);
5840 return(result);
5841 }
5842
5843 int
5844 test_decode_create_request_payload_kmip_2_0(TestTracker *tracker)
5845 {
5846 TRACK_TEST(tracker);
5847
5848 /* This encoding matches the following set of values:
5849 * Request Payload
5850 * Object Type - Symmetric Key
5851 * Attributes
5852 * Cryptographic Algorithm - AES
5853 * Cryptographic Length - 128
5854 * Cryptographic Usage Mask - Encrypt | Decrypt
5855 * Protection Storage Masks
5856 * Protection Storage Mask - Software | On System
5857 * Protection Storage Mask - Off System | Off Premises
5858 */
5859 uint8 encoding[120] = {
5860 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, 0x70,
5861 0x42, 0x00, 0x57, 0x05, 0x00, 0x00, 0x00, 0x04,
5862 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
5863 0x42, 0x01, 0x25, 0x01, 0x00, 0x00, 0x00, 0x30,
5864 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
5865 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
5866 0x42, 0x00, 0x2A, 0x02, 0x00, 0x00, 0x00, 0x04,
5867 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
5868 0x42, 0x00, 0x2C, 0x02, 0x00, 0x00, 0x00, 0x04,
5869 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00,
5870 0x42, 0x01, 0x5F, 0x01, 0x00, 0x00, 0x00, 0x20,
5871 0x42, 0x01, 0x5E, 0x02, 0x00, 0x00, 0x00, 0x04,
5872 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00,
5873 0x42, 0x01, 0x5E, 0x02, 0x00, 0x00, 0x00, 0x04,
5874 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00
5875 };
5876
5877 struct kmip ctx = {0};
5878 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_2_0);
5879
5880 Attribute a[3] = {0};
5881 for(int i = 0; i < 3; i++)
5882 {
5883 kmip_init_attribute(&a[i]);
5884 }
5885
5886 enum cryptographic_algorithm algorithm = KMIP_CRYPTOALG_AES;
5887 a[0].type = KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM;
5888 a[0].value = &algorithm;
5889
5890 int32 length = 128;
5891 a[1].type = KMIP_ATTR_CRYPTOGRAPHIC_LENGTH;
5892 a[1].value = &length;
5893
5894 int32 mask = KMIP_CRYPTOMASK_ENCRYPT | KMIP_CRYPTOMASK_DECRYPT;
5895 a[2].type = KMIP_ATTR_CRYPTOGRAPHIC_USAGE_MASK;
5896 a[2].value = &mask;
5897
5898 Attributes attributes = {0};
5899 LinkedList list = {0};
5900 LinkedListItem item_1, item_2, item_3 = {0};
5901 item_1.data = &a[0];
5902 item_2.data = &a[1];
5903 item_3.data = &a[2];
5904 kmip_linked_list_enqueue(&list, &item_1);
5905 kmip_linked_list_enqueue(&list, &item_2);
5906 kmip_linked_list_enqueue(&list, &item_3);
5907 attributes.attribute_list = &list;
5908
5909 ProtectionStorageMasks psm = {0};
5910 LinkedList masks = {0};
5911 LinkedListItem mask_1, mask_2 = {0};
5912 int32 m1 = KMIP_PROTECT_SOFTWARE | KMIP_PROTECT_ON_SYSTEM;
5913 int32 m2 = KMIP_PROTECT_OFF_SYSTEM | KMIP_PROTECT_OFF_PREMISES;
5914 mask_1.data = &m1;
5915 mask_2.data = &m2;
5916 kmip_linked_list_enqueue(&masks, &mask_1);
5917 kmip_linked_list_enqueue(&masks, &mask_2);
5918 psm.masks = &masks;
5919
5920 CreateRequestPayload expected = {0};
5921 expected.object_type = KMIP_OBJTYPE_SYMMETRIC_KEY;
5922 expected.attributes = &attributes;
5923 expected.protection_storage_masks = &psm;
5924
5925 CreateRequestPayload observed = {0};
5926
5927 int result = kmip_decode_create_request_payload(&ctx, &observed);
5928 result = report_decoding_test_result(
5929 tracker,
5930 &ctx,
5931 kmip_compare_create_request_payload(&expected, &observed),
5932 result,
5933 __func__);
5934 kmip_free_create_request_payload(&ctx, &observed);
5935 kmip_destroy(&ctx);
5936 return(result);
5937 }
5938
5939 int
5940 test_encode_create_response_payload(TestTracker *tracker)
5941 {
5942 TRACK_TEST(tracker);
5943
5944 uint8 expected[72] = {
5945 0x42, 0x00, 0x7C, 0x01, 0x00, 0x00, 0x00, 0x40,
5946 0x42, 0x00, 0x57, 0x05, 0x00, 0x00, 0x00, 0x04,
5947 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
5948 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
5949 0x66, 0x62, 0x34, 0x62, 0x35, 0x62, 0x39, 0x63,
5950 0x2D, 0x36, 0x31, 0x38, 0x38, 0x2D, 0x34, 0x63,
5951 0x36, 0x33, 0x2D, 0x38, 0x31, 0x34, 0x32, 0x2D,
5952 0x66, 0x65, 0x39, 0x63, 0x33, 0x32, 0x38, 0x31,
5953 0x32, 0x39, 0x66, 0x63, 0x00, 0x00, 0x00, 0x00
5954 };
5955
5956 uint8 observed[72] = {0};
5957 struct kmip ctx = {0};
5958 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
5959
5960 struct text_string uuid = {0};
5961 uuid.value = "fb4b5b9c-6188-4c63-8142-fe9c328129fc";
5962 uuid.size = 36;
5963
5964 struct create_response_payload crp = {0};
5965 crp.object_type = KMIP_OBJTYPE_SYMMETRIC_KEY;
5966 crp.unique_identifier = &uuid;
5967
5968 int result = kmip_encode_create_response_payload(&ctx, &crp);
5969 result = report_encoding_test_result(
5970 tracker,
5971 &ctx,
5972 expected,
5973 observed,
5974 result,
5975 __func__);
5976 kmip_destroy(&ctx);
5977 return(result);
5978 }
5979
5980 int
5981 test_decode_create_response_payload(TestTracker *tracker)
5982 {
5983 TRACK_TEST(tracker);
5984
5985 uint8 encoding[72] = {
5986 0x42, 0x00, 0x7C, 0x01, 0x00, 0x00, 0x00, 0x40,
5987 0x42, 0x00, 0x57, 0x05, 0x00, 0x00, 0x00, 0x04,
5988 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
5989 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
5990 0x66, 0x62, 0x34, 0x62, 0x35, 0x62, 0x39, 0x63,
5991 0x2D, 0x36, 0x31, 0x38, 0x38, 0x2D, 0x34, 0x63,
5992 0x36, 0x33, 0x2D, 0x38, 0x31, 0x34, 0x32, 0x2D,
5993 0x66, 0x65, 0x39, 0x63, 0x33, 0x32, 0x38, 0x31,
5994 0x32, 0x39, 0x66, 0x63, 0x00, 0x00, 0x00, 0x00
5995 };
5996
5997 struct kmip ctx = {0};
5998 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
5999
6000 struct text_string uuid = {0};
6001 uuid.value = "fb4b5b9c-6188-4c63-8142-fe9c328129fc";
6002 uuid.size = 36;
6003
6004 struct create_response_payload expected = {0};
6005 expected.object_type = KMIP_OBJTYPE_SYMMETRIC_KEY;
6006 expected.unique_identifier = &uuid;
6007
6008 struct create_response_payload observed = {0};
6009
6010 int result = kmip_decode_create_response_payload(&ctx, &observed);
6011 result = report_decoding_test_result(
6012 tracker,
6013 &ctx,
6014 kmip_compare_create_response_payload(&expected, &observed),
6015 result,
6016 __func__);
6017 kmip_free_create_response_payload(&ctx, &observed);
6018 kmip_destroy(&ctx);
6019 return(result);
6020 }
6021
6022 int
6023 test_encode_create_response_payload_with_template_attribute(TestTracker *tracker)
6024 {
6025 TRACK_TEST(tracker);
6026
6027 uint8 expected[136] = {
6028 0x42, 0x00, 0x7C, 0x01, 0x00, 0x00, 0x00, 0x80,
6029 0x42, 0x00, 0x57, 0x05, 0x00, 0x00, 0x00, 0x04,
6030 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
6031 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
6032 0x66, 0x62, 0x34, 0x62, 0x35, 0x62, 0x39, 0x63,
6033 0x2D, 0x36, 0x31, 0x38, 0x38, 0x2D, 0x34, 0x63,
6034 0x36, 0x33, 0x2D, 0x38, 0x31, 0x34, 0x32, 0x2D,
6035 0x66, 0x65, 0x39, 0x63, 0x33, 0x32, 0x38, 0x31,
6036 0x32, 0x39, 0x66, 0x63, 0x00, 0x00, 0x00, 0x00,
6037 0x42, 0x00, 0x91, 0x01, 0x00, 0x00, 0x00, 0x38,
6038 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
6039 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x17,
6040 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
6041 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x41, 0x6C,
6042 0x67, 0x6F, 0x72, 0x69, 0x74, 0x68, 0x6D, 0x00,
6043 0x42, 0x00, 0x0B, 0x05, 0x00, 0x00, 0x00, 0x04,
6044 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
6045 };
6046
6047 uint8 observed[136] = {0};
6048 struct kmip ctx = {0};
6049 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
6050
6051 struct text_string uuid = {0};
6052 uuid.value = "fb4b5b9c-6188-4c63-8142-fe9c328129fc";
6053 uuid.size = 36;
6054
6055 struct attribute a = {0};
6056 kmip_init_attribute(&a);
6057
6058 enum cryptographic_algorithm algorithm = KMIP_CRYPTOALG_AES;
6059 a.type = KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM;
6060 a.value = &algorithm;
6061
6062 struct template_attribute ta = {0};
6063 ta.attributes = &a;
6064 ta.attribute_count = 1;
6065
6066 struct create_response_payload crp = {0};
6067 crp.object_type = KMIP_OBJTYPE_SYMMETRIC_KEY;
6068 crp.unique_identifier = &uuid;
6069 crp.template_attribute = &ta;
6070
6071 int result = kmip_encode_create_response_payload(&ctx, &crp);
6072 result = report_encoding_test_result(
6073 tracker,
6074 &ctx,
6075 expected,
6076 observed,
6077 result,
6078 __func__);
6079 kmip_destroy(&ctx);
6080 return(result);
6081 }
6082
6083 int
6084 test_decode_create_response_payload_with_template_attribute(TestTracker *tracker)
6085 {
6086 TRACK_TEST(tracker);
6087
6088 uint8 encoding[136] = {
6089 0x42, 0x00, 0x7C, 0x01, 0x00, 0x00, 0x00, 0x80,
6090 0x42, 0x00, 0x57, 0x05, 0x00, 0x00, 0x00, 0x04,
6091 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
6092 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
6093 0x66, 0x62, 0x34, 0x62, 0x35, 0x62, 0x39, 0x63,
6094 0x2D, 0x36, 0x31, 0x38, 0x38, 0x2D, 0x34, 0x63,
6095 0x36, 0x33, 0x2D, 0x38, 0x31, 0x34, 0x32, 0x2D,
6096 0x66, 0x65, 0x39, 0x63, 0x33, 0x32, 0x38, 0x31,
6097 0x32, 0x39, 0x66, 0x63, 0x00, 0x00, 0x00, 0x00,
6098 0x42, 0x00, 0x91, 0x01, 0x00, 0x00, 0x00, 0x38,
6099 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
6100 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x17,
6101 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
6102 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x41, 0x6C,
6103 0x67, 0x6F, 0x72, 0x69, 0x74, 0x68, 0x6D, 0x00,
6104 0x42, 0x00, 0x0B, 0x05, 0x00, 0x00, 0x00, 0x04,
6105 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
6106 };
6107
6108 struct kmip ctx = {0};
6109 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
6110
6111 struct text_string uuid = {0};
6112 uuid.value = "fb4b5b9c-6188-4c63-8142-fe9c328129fc";
6113 uuid.size = 36;
6114
6115 struct attribute a = {0};
6116 kmip_init_attribute(&a);
6117
6118 enum cryptographic_algorithm algorithm = KMIP_CRYPTOALG_AES;
6119 a.type = KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM;
6120 a.value = &algorithm;
6121
6122 struct template_attribute ta = {0};
6123 ta.attributes = &a;
6124 ta.attribute_count = 1;
6125
6126 struct create_response_payload expected = {0};
6127 expected.object_type = KMIP_OBJTYPE_SYMMETRIC_KEY;
6128 expected.unique_identifier = &uuid;
6129 expected.template_attribute = &ta;
6130
6131 struct create_response_payload observed = {0};
6132
6133 int result = kmip_decode_create_response_payload(&ctx, &observed);
6134 result = report_decoding_test_result(
6135 tracker,
6136 &ctx,
6137 kmip_compare_create_response_payload(&expected, &observed),
6138 result,
6139 __func__);
6140 kmip_free_create_response_payload(&ctx, &observed);
6141 kmip_destroy(&ctx);
6142 return(result);
6143 }
6144
6145 int
6146 test_encode_get_request_payload(TestTracker *tracker)
6147 {
6148 TRACK_TEST(tracker);
6149
6150 uint8 expected[56] = {
6151 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, 0x30,
6152 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
6153 0x34, 0x39, 0x61, 0x31, 0x63, 0x61, 0x38, 0x38,
6154 0x2D, 0x36, 0x62, 0x65, 0x61, 0x2D, 0x34, 0x66,
6155 0x62, 0x32, 0x2D, 0x62, 0x34, 0x35, 0x30, 0x2D,
6156 0x37, 0x65, 0x35, 0x38, 0x38, 0x30, 0x32, 0x63,
6157 0x33, 0x30, 0x33, 0x38, 0x00, 0x00, 0x00, 0x00
6158 };
6159
6160 uint8 observed[56] = {0};
6161 struct kmip ctx = {0};
6162 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
6163
6164 struct text_string uuid = {0};
6165 uuid.value = "49a1ca88-6bea-4fb2-b450-7e58802c3038";
6166 uuid.size = 36;
6167
6168 struct get_request_payload grp = {0};
6169 grp.unique_identifier = &uuid;
6170
6171 int result = kmip_encode_get_request_payload(&ctx, &grp);
6172 result = report_encoding_test_result(
6173 tracker,
6174 &ctx,
6175 expected,
6176 observed,
6177 result,
6178 __func__);
6179 kmip_destroy(&ctx);
6180 return(result);
6181 }
6182
6183 int
6184 test_decode_get_request_payload(TestTracker *tracker)
6185 {
6186 TRACK_TEST(tracker);
6187
6188 uint8 encoding[56] = {
6189 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, 0x30,
6190 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
6191 0x34, 0x39, 0x61, 0x31, 0x63, 0x61, 0x38, 0x38,
6192 0x2D, 0x36, 0x62, 0x65, 0x61, 0x2D, 0x34, 0x66,
6193 0x62, 0x32, 0x2D, 0x62, 0x34, 0x35, 0x30, 0x2D,
6194 0x37, 0x65, 0x35, 0x38, 0x38, 0x30, 0x32, 0x63,
6195 0x33, 0x30, 0x33, 0x38, 0x00, 0x00, 0x00, 0x00
6196 };
6197
6198 struct kmip ctx = {0};
6199 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
6200
6201 struct text_string uuid = {0};
6202 uuid.value = "49a1ca88-6bea-4fb2-b450-7e58802c3038";
6203 uuid.size = 36;
6204
6205 struct get_request_payload expected = {0};
6206 expected.unique_identifier = &uuid;
6207
6208 struct get_request_payload observed = {0};
6209
6210 int result = kmip_decode_get_request_payload(&ctx, &observed);
6211 result = report_decoding_test_result(
6212 tracker,
6213 &ctx,
6214 kmip_compare_get_request_payload(&expected, &observed),
6215 result,
6216 __func__);
6217 kmip_free_get_request_payload(&ctx, &observed);
6218 kmip_destroy(&ctx);
6219 return(result);
6220 }
6221
6222 int
6223 test_encode_get_request_payload_with_format_compression(TestTracker *tracker)
6224 {
6225 TRACK_TEST(tracker);
6226
6227 uint8 expected[88] = {
6228 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, 0x50,
6229 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
6230 0x37, 0x63, 0x66, 0x35, 0x32, 0x30, 0x39, 0x62,
6231 0x2D, 0x36, 0x66, 0x66, 0x36, 0x2D, 0x34, 0x34,
6232 0x32, 0x36, 0x2D, 0x38, 0x39, 0x39, 0x65, 0x2D,
6233 0x32, 0x32, 0x62, 0x30, 0x36, 0x37, 0x38, 0x35,
6234 0x39, 0x33, 0x37, 0x32, 0x00, 0x00, 0x00, 0x00,
6235 0x42, 0x00, 0x42, 0x05, 0x00, 0x00, 0x00, 0x04,
6236 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
6237 0x42, 0x00, 0x41, 0x05, 0x00, 0x00, 0x00, 0x04,
6238 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
6239 };
6240
6241 uint8 observed[88] = {0};
6242 struct kmip ctx = {0};
6243 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
6244
6245 struct text_string uuid = {0};
6246 uuid.value = "7cf5209b-6ff6-4426-899e-22b067859372";
6247 uuid.size = 36;
6248
6249 struct get_request_payload grp = {0};
6250 grp.unique_identifier = &uuid;
6251 grp.key_format_type = KMIP_KEYFORMAT_PKCS1;
6252 grp.key_compression_type = KMIP_KEYCOMP_EC_PUB_UNCOMPRESSED;
6253
6254 int result = kmip_encode_get_request_payload(&ctx, &grp);
6255 result = report_encoding_test_result(
6256 tracker,
6257 &ctx,
6258 expected,
6259 observed,
6260 result,
6261 __func__);
6262 kmip_destroy(&ctx);
6263 return(result);
6264 }
6265
6266 int
6267 test_encode_get_request_payload_with_wrapping_spec(TestTracker *tracker)
6268 {
6269 TRACK_TEST(tracker);
6270
6271 uint8 expected[160] = {
6272 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, 0x98,
6273 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
6274 0x62, 0x66, 0x66, 0x37, 0x33, 0x34, 0x37, 0x62,
6275 0x2D, 0x33, 0x61, 0x33, 0x39, 0x2D, 0x34, 0x63,
6276 0x63, 0x62, 0x2D, 0x38, 0x32, 0x33, 0x34, 0x2D,
6277 0x62, 0x61, 0x32, 0x35, 0x36, 0x30, 0x63, 0x61,
6278 0x31, 0x35, 0x39, 0x38, 0x00, 0x00, 0x00, 0x00,
6279 0x42, 0x00, 0x47, 0x01, 0x00, 0x00, 0x00, 0x60,
6280 0x42, 0x00, 0x9E, 0x05, 0x00, 0x00, 0x00, 0x04,
6281 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
6282 0x42, 0x00, 0x36, 0x01, 0x00, 0x00, 0x00, 0x48,
6283 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
6284 0x31, 0x30, 0x30, 0x31, 0x38, 0x32, 0x64, 0x35,
6285 0x2D, 0x37, 0x32, 0x62, 0x38, 0x2D, 0x34, 0x37,
6286 0x61, 0x61, 0x2D, 0x38, 0x33, 0x38, 0x33, 0x2D,
6287 0x34, 0x64, 0x39, 0x37, 0x64, 0x35, 0x31, 0x32,
6288 0x65, 0x39, 0x38, 0x61, 0x00, 0x00, 0x00, 0x00,
6289 0x42, 0x00, 0x2B, 0x01, 0x00, 0x00, 0x00, 0x10,
6290 0x42, 0x00, 0x11, 0x05, 0x00, 0x00, 0x00, 0x04,
6291 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00
6292 };
6293
6294 uint8 observed[160] = {0};
6295 struct kmip ctx = {0};
6296 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
6297
6298 struct text_string wrapping_uuid = {0};
6299 wrapping_uuid.value = "100182d5-72b8-47aa-8383-4d97d512e98a";
6300 wrapping_uuid.size = 36;
6301 struct text_string uuid = {0};
6302 uuid.value = "bff7347b-3a39-4ccb-8234-ba2560ca1598";
6303 uuid.size = 36;
6304
6305 struct cryptographic_parameters cp = {0};
6306 cp.block_cipher_mode = KMIP_BLOCK_NIST_KEY_WRAP;
6307
6308 struct encryption_key_information eki = {0};
6309 eki.unique_identifier = &wrapping_uuid;
6310 eki.cryptographic_parameters = &cp;
6311
6312 struct key_wrapping_specification kws = {0};
6313 kws.wrapping_method = KMIP_WRAP_ENCRYPT;
6314 kws.encryption_key_info = &eki;
6315
6316 struct get_request_payload grp = {0};
6317 grp.unique_identifier = &uuid;
6318 grp.key_wrapping_spec = &kws;
6319
6320 int result = kmip_encode_get_request_payload(&ctx, &grp);
6321 result = report_encoding_test_result(
6322 tracker,
6323 &ctx,
6324 expected,
6325 observed,
6326 result,
6327 __func__);
6328 kmip_destroy(&ctx);
6329 return(result);
6330 }
6331
6332 int
6333 test_encode_get_response_payload(TestTracker *tracker)
6334 {
6335 TRACK_TEST(tracker);
6336
6337 uint8 expected[176] = {
6338 0x42, 0x00, 0x7C, 0x01, 0x00, 0x00, 0x00, 0xA8,
6339 0x42, 0x00, 0x57, 0x05, 0x00, 0x00, 0x00, 0x04,
6340 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
6341 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
6342 0x34, 0x39, 0x61, 0x31, 0x63, 0x61, 0x38, 0x38,
6343 0x2D, 0x36, 0x62, 0x65, 0x61, 0x2D, 0x34, 0x66,
6344 0x62, 0x32, 0x2D, 0x62, 0x34, 0x35, 0x30, 0x2D,
6345 0x37, 0x65, 0x35, 0x38, 0x38, 0x30, 0x32, 0x63,
6346 0x33, 0x30, 0x33, 0x38, 0x00, 0x00, 0x00, 0x00,
6347 0x42, 0x00, 0x8F, 0x01, 0x00, 0x00, 0x00, 0x60,
6348 0x42, 0x00, 0x40, 0x01, 0x00, 0x00, 0x00, 0x58,
6349 0x42, 0x00, 0x42, 0x05, 0x00, 0x00, 0x00, 0x04,
6350 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
6351 0x42, 0x00, 0x45, 0x01, 0x00, 0x00, 0x00, 0x20,
6352 0x42, 0x00, 0x43, 0x08, 0x00, 0x00, 0x00, 0x18,
6353 0x73, 0x67, 0x57, 0x80, 0x51, 0x01, 0x2A, 0x6D,
6354 0x13, 0x4A, 0x85, 0x5E, 0x25, 0xC8, 0xCD, 0x5E,
6355 0x4C, 0xA1, 0x31, 0x45, 0x57, 0x29, 0xD3, 0xC8,
6356 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
6357 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
6358 0x42, 0x00, 0x2A, 0x02, 0x00, 0x00, 0x00, 0x04,
6359 0x00, 0x00, 0x00, 0xA8, 0x00, 0x00, 0x00, 0x00
6360 };
6361
6362 uint8 observed[176] = {0};
6363 struct kmip ctx = {0};
6364 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
6365
6366 struct text_string uuid = {0};
6367 uuid.value = "49a1ca88-6bea-4fb2-b450-7e58802c3038";
6368 uuid.size = 36;
6369
6370 uint8 value[24] = {
6371 0x73, 0x67, 0x57, 0x80, 0x51, 0x01, 0x2A, 0x6D,
6372 0x13, 0x4A, 0x85, 0x5E, 0x25, 0xC8, 0xCD, 0x5E,
6373 0x4C, 0xA1, 0x31, 0x45, 0x57, 0x29, 0xD3, 0xC8
6374 };
6375 struct byte_string v = {0};
6376 v.value = value;
6377 v.size = ARRAY_LENGTH(value);
6378
6379 struct key_value kv = {0};
6380 kv.key_material = &v;
6381
6382 struct key_block kb = {0};
6383 kb.key_format_type = KMIP_KEYFORMAT_RAW;
6384 kb.key_value = &kv;
6385 kb.cryptographic_algorithm = KMIP_CRYPTOALG_TRIPLE_DES;
6386 kb.cryptographic_length = 168;
6387
6388 struct symmetric_key key = {0};
6389 key.key_block = &kb;
6390
6391 struct get_response_payload grp = {0};
6392 grp.object_type = KMIP_OBJTYPE_SYMMETRIC_KEY;
6393 grp.unique_identifier = &uuid;
6394 grp.object = &key;
6395
6396 int result = kmip_encode_get_response_payload(&ctx, &grp);
6397 result = report_encoding_test_result(
6398 tracker,
6399 &ctx,
6400 expected,
6401 observed,
6402 result,
6403 __func__);
6404 kmip_destroy(&ctx);
6405 return(result);
6406 }
6407
6408 int
6409 test_decode_get_response_payload(TestTracker *tracker)
6410 {
6411 TRACK_TEST(tracker);
6412
6413 uint8 encoding[176] = {
6414 0x42, 0x00, 0x7C, 0x01, 0x00, 0x00, 0x00, 0xA8,
6415 0x42, 0x00, 0x57, 0x05, 0x00, 0x00, 0x00, 0x04,
6416 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
6417 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
6418 0x34, 0x39, 0x61, 0x31, 0x63, 0x61, 0x38, 0x38,
6419 0x2D, 0x36, 0x62, 0x65, 0x61, 0x2D, 0x34, 0x66,
6420 0x62, 0x32, 0x2D, 0x62, 0x34, 0x35, 0x30, 0x2D,
6421 0x37, 0x65, 0x35, 0x38, 0x38, 0x30, 0x32, 0x63,
6422 0x33, 0x30, 0x33, 0x38, 0x00, 0x00, 0x00, 0x00,
6423 0x42, 0x00, 0x8F, 0x01, 0x00, 0x00, 0x00, 0x60,
6424 0x42, 0x00, 0x40, 0x01, 0x00, 0x00, 0x00, 0x58,
6425 0x42, 0x00, 0x42, 0x05, 0x00, 0x00, 0x00, 0x04,
6426 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
6427 0x42, 0x00, 0x45, 0x01, 0x00, 0x00, 0x00, 0x20,
6428 0x42, 0x00, 0x43, 0x08, 0x00, 0x00, 0x00, 0x18,
6429 0x73, 0x67, 0x57, 0x80, 0x51, 0x01, 0x2A, 0x6D,
6430 0x13, 0x4A, 0x85, 0x5E, 0x25, 0xC8, 0xCD, 0x5E,
6431 0x4C, 0xA1, 0x31, 0x45, 0x57, 0x29, 0xD3, 0xC8,
6432 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
6433 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
6434 0x42, 0x00, 0x2A, 0x02, 0x00, 0x00, 0x00, 0x04,
6435 0x00, 0x00, 0x00, 0xA8, 0x00, 0x00, 0x00, 0x00
6436 };
6437
6438 struct kmip ctx = {0};
6439 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
6440
6441 struct text_string uuid = {0};
6442 uuid.value = "49a1ca88-6bea-4fb2-b450-7e58802c3038";
6443 uuid.size = 36;
6444
6445 uint8 value[24] = {
6446 0x73, 0x67, 0x57, 0x80, 0x51, 0x01, 0x2A, 0x6D,
6447 0x13, 0x4A, 0x85, 0x5E, 0x25, 0xC8, 0xCD, 0x5E,
6448 0x4C, 0xA1, 0x31, 0x45, 0x57, 0x29, 0xD3, 0xC8
6449 };
6450 struct byte_string v = {0};
6451 v.value = value;
6452 v.size = ARRAY_LENGTH(value);
6453
6454 struct key_value kv = {0};
6455 kv.key_material = &v;
6456
6457 struct key_block kb = {0};
6458 kb.key_format_type = KMIP_KEYFORMAT_RAW;
6459 kb.key_value = &kv;
6460 kb.key_value_type = KMIP_TYPE_STRUCTURE;
6461 kb.cryptographic_algorithm = KMIP_CRYPTOALG_TRIPLE_DES;
6462 kb.cryptographic_length = 168;
6463
6464 struct symmetric_key key = {0};
6465 key.key_block = &kb;
6466
6467 struct get_response_payload expected = {0};
6468 expected.object_type = KMIP_OBJTYPE_SYMMETRIC_KEY;
6469 expected.unique_identifier = &uuid;
6470 expected.object = &key;
6471
6472 struct get_response_payload observed = {0};
6473
6474 int result = kmip_decode_get_response_payload(&ctx, &observed);
6475 result = report_decoding_test_result(
6476 tracker,
6477 &ctx,
6478 kmip_compare_get_response_payload(&expected, &observed),
6479 result,
6480 __func__);
6481 kmip_free_get_response_payload(&ctx, &observed);
6482 kmip_destroy(&ctx);
6483 return(result);
6484 }
6485
6486 int
6487 test_encode_destroy_request_payload(TestTracker *tracker)
6488 {
6489 TRACK_TEST(tracker);
6490
6491 uint8 expected[56] = {
6492 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, 0x30,
6493 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
6494 0x66, 0x62, 0x34, 0x62, 0x35, 0x62, 0x39, 0x63,
6495 0x2D, 0x36, 0x31, 0x38, 0x38, 0x2D, 0x34, 0x63,
6496 0x36, 0x33, 0x2D, 0x38, 0x31, 0x34, 0x32, 0x2D,
6497 0x66, 0x65, 0x39, 0x63, 0x33, 0x32, 0x38, 0x31,
6498 0x32, 0x39, 0x66, 0x63, 0x00, 0x00, 0x00, 0x00
6499 };
6500
6501 uint8 observed[56] = {0};
6502 struct kmip ctx = {0};
6503 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
6504
6505 struct text_string uuid = {0};
6506 uuid.value = "fb4b5b9c-6188-4c63-8142-fe9c328129fc";
6507 uuid.size = 36;
6508
6509 struct destroy_request_payload drp = {0};
6510 drp.unique_identifier = &uuid;
6511
6512 int result = kmip_encode_destroy_request_payload(&ctx, &drp);
6513 result = report_encoding_test_result(
6514 tracker,
6515 &ctx,
6516 expected,
6517 observed,
6518 result,
6519 __func__);
6520 kmip_destroy(&ctx);
6521 return(result);
6522 }
6523
6524 int
6525 test_decode_destroy_request_payload(TestTracker *tracker)
6526 {
6527 TRACK_TEST(tracker);
6528
6529 uint8 encoding[56] = {
6530 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, 0x30,
6531 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
6532 0x66, 0x62, 0x34, 0x62, 0x35, 0x62, 0x39, 0x63,
6533 0x2D, 0x36, 0x31, 0x38, 0x38, 0x2D, 0x34, 0x63,
6534 0x36, 0x33, 0x2D, 0x38, 0x31, 0x34, 0x32, 0x2D,
6535 0x66, 0x65, 0x39, 0x63, 0x33, 0x32, 0x38, 0x31,
6536 0x32, 0x39, 0x66, 0x63, 0x00, 0x00, 0x00, 0x00
6537 };
6538
6539 struct kmip ctx = {0};
6540 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
6541
6542 struct text_string uuid = {0};
6543 uuid.value = "fb4b5b9c-6188-4c63-8142-fe9c328129fc";
6544 uuid.size = 36;
6545
6546 struct destroy_request_payload expected = {0};
6547 expected.unique_identifier = &uuid;
6548
6549 struct destroy_request_payload observed = {0};
6550
6551 int result = kmip_decode_destroy_request_payload(&ctx, &observed);
6552 result = report_decoding_test_result(
6553 tracker,
6554 &ctx,
6555 kmip_compare_destroy_request_payload(&expected, &observed),
6556 result,
6557 __func__);
6558 kmip_free_destroy_request_payload(&ctx, &observed);
6559 kmip_destroy(&ctx);
6560 return(result);
6561 }
6562
6563 int
6564 test_encode_destroy_response_payload(TestTracker *tracker)
6565 {
6566 TRACK_TEST(tracker);
6567
6568 uint8 expected[56] = {
6569 0x42, 0x00, 0x7C, 0x01, 0x00, 0x00, 0x00, 0x30,
6570 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
6571 0x66, 0x62, 0x34, 0x62, 0x35, 0x62, 0x39, 0x63,
6572 0x2D, 0x36, 0x31, 0x38, 0x38, 0x2D, 0x34, 0x63,
6573 0x36, 0x33, 0x2D, 0x38, 0x31, 0x34, 0x32, 0x2D,
6574 0x66, 0x65, 0x39, 0x63, 0x33, 0x32, 0x38, 0x31,
6575 0x32, 0x39, 0x66, 0x63, 0x00, 0x00, 0x00, 0x00
6576 };
6577
6578 uint8 observed[56] = {0};
6579 struct kmip ctx = {0};
6580 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
6581
6582 struct text_string uuid = {0};
6583 uuid.value = "fb4b5b9c-6188-4c63-8142-fe9c328129fc";
6584 uuid.size = 36;
6585
6586 struct destroy_response_payload drp = {0};
6587 drp.unique_identifier = &uuid;
6588
6589 int result = kmip_encode_destroy_response_payload(&ctx, &drp);
6590 result = report_encoding_test_result(
6591 tracker,
6592 &ctx,
6593 expected,
6594 observed,
6595 result,
6596 __func__);
6597 kmip_destroy(&ctx);
6598 return(result);
6599 }
6600
6601 int
6602 test_decode_destroy_response_payload(TestTracker *tracker)
6603 {
6604 TRACK_TEST(tracker);
6605
6606 uint8 encoding[56] = {
6607 0x42, 0x00, 0x7C, 0x01, 0x00, 0x00, 0x00, 0x30,
6608 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
6609 0x66, 0x62, 0x34, 0x62, 0x35, 0x62, 0x39, 0x63,
6610 0x2D, 0x36, 0x31, 0x38, 0x38, 0x2D, 0x34, 0x63,
6611 0x36, 0x33, 0x2D, 0x38, 0x31, 0x34, 0x32, 0x2D,
6612 0x66, 0x65, 0x39, 0x63, 0x33, 0x32, 0x38, 0x31,
6613 0x32, 0x39, 0x66, 0x63, 0x00, 0x00, 0x00, 0x00
6614 };
6615
6616 struct kmip ctx = {0};
6617 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
6618
6619 struct text_string uuid = {0};
6620 uuid.value = "fb4b5b9c-6188-4c63-8142-fe9c328129fc";
6621 uuid.size = 36;
6622
6623 struct destroy_response_payload expected = {0};
6624 expected.unique_identifier = &uuid;
6625
6626 struct destroy_response_payload observed = {0};
6627
6628 int result = kmip_decode_destroy_response_payload(&ctx, &observed);
6629 result = report_decoding_test_result(
6630 tracker,
6631 &ctx,
6632 kmip_compare_destroy_response_payload(&expected, &observed),
6633 result,
6634 __func__);
6635 kmip_free_destroy_response_payload(&ctx, &observed);
6636 kmip_destroy(&ctx);
6637 return(result);
6638 }
6639
6640 int
6641 test_encode_username_password_credential(TestTracker *tracker)
6642 {
6643 TRACK_TEST(tracker);
6644
6645 uint8 expected[48] = {
6646 0x42, 0x00, 0x25, 0x01, 0x00, 0x00, 0x00, 0x28,
6647 0x42, 0x00, 0x99, 0x07, 0x00, 0x00, 0x00, 0x04,
6648 0x46, 0x72, 0x65, 0x64, 0x00, 0x00, 0x00, 0x00,
6649 0x42, 0x00, 0xA1, 0x07, 0x00, 0x00, 0x00, 0x09,
6650 0x70, 0x61, 0x73, 0x73, 0x77, 0x6F, 0x72, 0x64,
6651 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
6652 };
6653
6654 uint8 observed[48] = {0};
6655 struct kmip ctx = {0};
6656 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
6657
6658 struct text_string username = {0};
6659 username.value = "Fred";
6660 username.size = 4;
6661 struct text_string password = {0};
6662 password.value = "password1";
6663 password.size = 9;
6664
6665 struct username_password_credential upc = {0};
6666 upc.username = &username;
6667 upc.password = &password;
6668
6669 int result = kmip_encode_username_password_credential(&ctx, &upc);
6670 result = report_encoding_test_result(
6671 tracker,
6672 &ctx,
6673 expected,
6674 observed,
6675 result,
6676 __func__);
6677 kmip_destroy(&ctx);
6678 return(result);
6679 }
6680
6681 int
6682 test_decode_username_password_credential(TestTracker *tracker)
6683 {
6684 TRACK_TEST(tracker);
6685
6686 uint8 encoding[48] = {
6687 0x42, 0x00, 0x25, 0x01, 0x00, 0x00, 0x00, 0x28,
6688 0x42, 0x00, 0x99, 0x07, 0x00, 0x00, 0x00, 0x04,
6689 0x46, 0x72, 0x65, 0x64, 0x00, 0x00, 0x00, 0x00,
6690 0x42, 0x00, 0xA1, 0x07, 0x00, 0x00, 0x00, 0x09,
6691 0x70, 0x61, 0x73, 0x73, 0x77, 0x6F, 0x72, 0x64,
6692 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
6693 };
6694
6695 struct kmip ctx = {0};
6696 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
6697
6698 struct text_string username = {0};
6699 username.value = "Fred";
6700 username.size = 4;
6701 struct text_string password = {0};
6702 password.value = "password1";
6703 password.size = 9;
6704
6705 struct username_password_credential expected = {0};
6706 expected.username = &username;
6707 expected.password = &password;
6708
6709 struct username_password_credential observed = {0};
6710
6711 int result = kmip_decode_username_password_credential(&ctx, &observed);
6712 result = report_decoding_test_result(
6713 tracker,
6714 &ctx,
6715 kmip_compare_username_password_credential(&expected, &observed),
6716 result,
6717 __func__);
6718 kmip_free_username_password_credential(&ctx, &observed);
6719 kmip_destroy(&ctx);
6720 return(result);
6721 }
6722
6723 int
6724 test_encode_credential_username_password_credential(TestTracker *tracker)
6725 {
6726 TRACK_TEST(tracker);
6727
6728 uint8 expected[64] = {
6729 0x42, 0x00, 0x23, 0x01, 0x00, 0x00, 0x00, 0x38,
6730 0x42, 0x00, 0x24, 0x05, 0x00, 0x00, 0x00, 0x04,
6731 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
6732 0x42, 0x00, 0x25, 0x01, 0x00, 0x00, 0x00, 0x20,
6733 0x42, 0x00, 0x99, 0x07, 0x00, 0x00, 0x00, 0x06,
6734 0x42, 0x61, 0x72, 0x6E, 0x65, 0x79, 0x00, 0x00,
6735 0x42, 0x00, 0xA1, 0x07, 0x00, 0x00, 0x00, 0x07,
6736 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x32, 0x00
6737 };
6738
6739 uint8 observed[64] = {0};
6740 struct kmip ctx = {0};
6741 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
6742
6743 struct text_string username = {0};
6744 username.value = "Barney";
6745 username.size = 6;
6746 struct text_string password = {0};
6747 password.value = "secret2";
6748 password.size = 7;
6749
6750 struct username_password_credential upc = {0};
6751 upc.username = &username;
6752 upc.password = &password;
6753
6754 struct credential c = {0};
6755 c.credential_type = KMIP_CRED_USERNAME_AND_PASSWORD;
6756 c.credential_value = &upc;
6757
6758 int result = kmip_encode_credential(&ctx, &c);
6759 result = report_encoding_test_result(
6760 tracker,
6761 &ctx,
6762 expected,
6763 observed,
6764 result,
6765 __func__);
6766 kmip_destroy(&ctx);
6767 return(result);
6768 }
6769
6770 int
6771 test_decode_credential_username_password_credential(TestTracker *tracker)
6772 {
6773 TRACK_TEST(tracker);
6774
6775 uint8 encoding[64] = {
6776 0x42, 0x00, 0x23, 0x01, 0x00, 0x00, 0x00, 0x38,
6777 0x42, 0x00, 0x24, 0x05, 0x00, 0x00, 0x00, 0x04,
6778 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
6779 0x42, 0x00, 0x25, 0x01, 0x00, 0x00, 0x00, 0x20,
6780 0x42, 0x00, 0x99, 0x07, 0x00, 0x00, 0x00, 0x06,
6781 0x42, 0x61, 0x72, 0x6E, 0x65, 0x79, 0x00, 0x00,
6782 0x42, 0x00, 0xA1, 0x07, 0x00, 0x00, 0x00, 0x07,
6783 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x32, 0x00
6784 };
6785
6786 struct kmip ctx = {0};
6787 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
6788
6789 struct text_string username = {0};
6790 username.value = "Barney";
6791 username.size = 6;
6792 struct text_string password = {0};
6793 password.value = "secret2";
6794 password.size = 7;
6795
6796 struct username_password_credential upc = {0};
6797 upc.username = &username;
6798 upc.password = &password;
6799
6800 struct credential expected = {0};
6801 expected.credential_type = KMIP_CRED_USERNAME_AND_PASSWORD;
6802 expected.credential_value = &upc;
6803
6804 struct credential observed = {0};
6805
6806 int result = kmip_decode_credential(&ctx, &observed);
6807 result = report_decoding_test_result(
6808 tracker,
6809 &ctx,
6810 kmip_compare_credential(&expected, &observed),
6811 result,
6812 __func__);
6813 kmip_free_credential(&ctx, &observed);
6814 kmip_destroy(&ctx);
6815 return(result);
6816 }
6817
6818 int
6819 test_encode_authentication_username_password_credential(TestTracker *tracker)
6820 {
6821 TRACK_TEST(tracker);
6822
6823 uint8 expected[80] = {
6824 0x42, 0x00, 0x0C, 0x01, 0x00, 0x00, 0x00, 0x48,
6825 0x42, 0x00, 0x23, 0x01, 0x00, 0x00, 0x00, 0x40,
6826 0x42, 0x00, 0x24, 0x05, 0x00, 0x00, 0x00, 0x04,
6827 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
6828 0x42, 0x00, 0x25, 0x01, 0x00, 0x00, 0x00, 0x28,
6829 0x42, 0x00, 0x99, 0x07, 0x00, 0x00, 0x00, 0x04,
6830 0x46, 0x72, 0x65, 0x64, 0x00, 0x00, 0x00, 0x00,
6831 0x42, 0x00, 0xA1, 0x07, 0x00, 0x00, 0x00, 0x09,
6832 0x70, 0x61, 0x73, 0x73, 0x77, 0x6F, 0x72, 0x64,
6833 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
6834 };
6835
6836 uint8 observed[80] = {0};
6837 struct kmip ctx = {0};
6838 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
6839
6840 struct text_string username = {0};
6841 username.value = "Fred";
6842 username.size = 4;
6843 struct text_string password = {0};
6844 password.value = "password1";
6845 password.size = 9;
6846
6847 struct username_password_credential upc = {0};
6848 upc.username = &username;
6849 upc.password = &password;
6850
6851 struct credential c = {0};
6852 c.credential_type = KMIP_CRED_USERNAME_AND_PASSWORD;
6853 c.credential_value = &upc;
6854
6855 struct authentication a = {0};
6856 a.credential = &c;
6857
6858 int result = kmip_encode_authentication(&ctx, &a);
6859 result = report_encoding_test_result(
6860 tracker,
6861 &ctx,
6862 expected,
6863 observed,
6864 result,
6865 __func__);
6866 kmip_destroy(&ctx);
6867 return(result);
6868 }
6869
6870 int
6871 test_decode_authentication_username_password_credential(TestTracker *tracker)
6872 {
6873 TRACK_TEST(tracker);
6874
6875 uint8 encoding[80] = {
6876 0x42, 0x00, 0x0C, 0x01, 0x00, 0x00, 0x00, 0x48,
6877 0x42, 0x00, 0x23, 0x01, 0x00, 0x00, 0x00, 0x40,
6878 0x42, 0x00, 0x24, 0x05, 0x00, 0x00, 0x00, 0x04,
6879 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
6880 0x42, 0x00, 0x25, 0x01, 0x00, 0x00, 0x00, 0x28,
6881 0x42, 0x00, 0x99, 0x07, 0x00, 0x00, 0x00, 0x04,
6882 0x46, 0x72, 0x65, 0x64, 0x00, 0x00, 0x00, 0x00,
6883 0x42, 0x00, 0xA1, 0x07, 0x00, 0x00, 0x00, 0x09,
6884 0x70, 0x61, 0x73, 0x73, 0x77, 0x6F, 0x72, 0x64,
6885 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
6886 };
6887
6888 struct kmip ctx = {0};
6889 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
6890
6891 struct text_string username = {0};
6892 username.value = "Fred";
6893 username.size = 4;
6894 struct text_string password = {0};
6895 password.value = "password1";
6896 password.size = 9;
6897
6898 struct username_password_credential upc = {0};
6899 upc.username = &username;
6900 upc.password = &password;
6901
6902 struct credential c = {0};
6903 c.credential_type = KMIP_CRED_USERNAME_AND_PASSWORD;
6904 c.credential_value = &upc;
6905
6906 struct authentication expected = {0};
6907 expected.credential = &c;
6908
6909 struct authentication observed = {0};
6910
6911 int result = kmip_decode_authentication(&ctx, &observed);
6912 result = report_decoding_test_result(
6913 tracker,
6914 &ctx,
6915 kmip_compare_authentication(&expected, &observed),
6916 result,
6917 __func__);
6918 kmip_free_authentication(&ctx, &observed);
6919 kmip_destroy(&ctx);
6920 return(result);
6921 }
6922
6923 int
6924 test_encode_request_header(TestTracker *tracker)
6925 {
6926 TRACK_TEST(tracker);
6927
6928 uint8 expected[168] = {
6929 0x42, 0x00, 0x77, 0x01, 0x00, 0x00, 0x00, 0xA0,
6930 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20,
6931 0x42, 0x00, 0x6A, 0x02, 0x00, 0x00, 0x00, 0x04,
6932 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
6933 0x42, 0x00, 0x6B, 0x02, 0x00, 0x00, 0x00, 0x04,
6934 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6935 0x42, 0x00, 0x0C, 0x01, 0x00, 0x00, 0x00, 0x40,
6936 0x42, 0x00, 0x23, 0x01, 0x00, 0x00, 0x00, 0x38,
6937 0x42, 0x00, 0x24, 0x05, 0x00, 0x00, 0x00, 0x04,
6938 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
6939 0x42, 0x00, 0x25, 0x01, 0x00, 0x00, 0x00, 0x20,
6940 0x42, 0x00, 0x99, 0x07, 0x00, 0x00, 0x00, 0x06,
6941 0x42, 0x61, 0x72, 0x6E, 0x65, 0x79, 0x00, 0x00,
6942 0x42, 0x00, 0xA1, 0x07, 0x00, 0x00, 0x00, 0x07,
6943 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x32, 0x00,
6944 0x42, 0x00, 0x0E, 0x05, 0x00, 0x00, 0x00, 0x04,
6945 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
6946 0x42, 0x00, 0x10, 0x06, 0x00, 0x00, 0x00, 0x08,
6947 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
6948 0x42, 0x00, 0x0D, 0x02, 0x00, 0x00, 0x00, 0x04,
6949 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00
6950 };
6951
6952 uint8 observed[168] = {0};
6953 struct kmip ctx = {0};
6954 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
6955
6956 struct protocol_version pv = {0};
6957 pv.major = 1;
6958 pv.minor = 0;
6959
6960 struct text_string username = {0};
6961 username.value = "Barney";
6962 username.size = 6;
6963 struct text_string password = {0};
6964 password.value = "secret2";
6965 password.size = 7;
6966
6967 struct username_password_credential upc = {0};
6968 upc.username = &username;
6969 upc.password = &password;
6970
6971 struct credential c = {0};
6972 c.credential_type = KMIP_CRED_USERNAME_AND_PASSWORD;
6973 c.credential_value = &upc;
6974
6975 struct authentication a = {0};
6976 a.credential = &c;
6977
6978 struct request_header rh = {0};
6979 kmip_init_request_header(&rh);
6980
6981 rh.protocol_version = &pv;
6982 rh.authentication = &a;
6983 rh.batch_error_continuation_option = KMIP_BATCH_CONTINUE;
6984 rh.batch_order_option = KMIP_TRUE;
6985 rh.batch_count = 2;
6986
6987 int result = kmip_encode_request_header(&ctx, &rh);
6988 result = report_encoding_test_result(
6989 tracker,
6990 &ctx,
6991 expected,
6992 observed,
6993 result,
6994 __func__);
6995 kmip_destroy(&ctx);
6996 return(result);
6997 }
6998
6999 int
7000 test_decode_request_header(TestTracker *tracker)
7001 {
7002 TRACK_TEST(tracker);
7003
7004 uint8 encoding[168] = {
7005 0x42, 0x00, 0x77, 0x01, 0x00, 0x00, 0x00, 0xA0,
7006 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20,
7007 0x42, 0x00, 0x6A, 0x02, 0x00, 0x00, 0x00, 0x04,
7008 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
7009 0x42, 0x00, 0x6B, 0x02, 0x00, 0x00, 0x00, 0x04,
7010 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7011 0x42, 0x00, 0x0C, 0x01, 0x00, 0x00, 0x00, 0x40,
7012 0x42, 0x00, 0x23, 0x01, 0x00, 0x00, 0x00, 0x38,
7013 0x42, 0x00, 0x24, 0x05, 0x00, 0x00, 0x00, 0x04,
7014 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
7015 0x42, 0x00, 0x25, 0x01, 0x00, 0x00, 0x00, 0x20,
7016 0x42, 0x00, 0x99, 0x07, 0x00, 0x00, 0x00, 0x06,
7017 0x42, 0x61, 0x72, 0x6E, 0x65, 0x79, 0x00, 0x00,
7018 0x42, 0x00, 0xA1, 0x07, 0x00, 0x00, 0x00, 0x07,
7019 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x32, 0x00,
7020 0x42, 0x00, 0x0E, 0x05, 0x00, 0x00, 0x00, 0x04,
7021 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
7022 0x42, 0x00, 0x10, 0x06, 0x00, 0x00, 0x00, 0x08,
7023 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
7024 0x42, 0x00, 0x0D, 0x02, 0x00, 0x00, 0x00, 0x04,
7025 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00
7026 };
7027
7028 struct kmip ctx = {0};
7029 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
7030
7031 struct protocol_version pv = {0};
7032 pv.major = 1;
7033 pv.minor = 0;
7034
7035 struct text_string username = {0};
7036 username.value = "Barney";
7037 username.size = 6;
7038 struct text_string password = {0};
7039 password.value = "secret2";
7040 password.size = 7;
7041
7042 struct username_password_credential upc = {0};
7043 upc.username = &username;
7044 upc.password = &password;
7045
7046 struct credential c = {0};
7047 c.credential_type = KMIP_CRED_USERNAME_AND_PASSWORD;
7048 c.credential_value = &upc;
7049
7050 struct authentication a = {0};
7051 a.credential = &c;
7052
7053 struct request_header expected = {0};
7054 kmip_init_request_header(&expected);
7055
7056 expected.protocol_version = &pv;
7057 expected.authentication = &a;
7058 expected.batch_error_continuation_option = KMIP_BATCH_CONTINUE;
7059 expected.batch_order_option = KMIP_TRUE;
7060 expected.batch_count = 2;
7061
7062 struct request_header observed = {0};
7063 kmip_init_request_header(&observed);
7064
7065 int result = kmip_decode_request_header(&ctx, &observed);
7066 result = report_decoding_test_result(
7067 tracker,
7068 &ctx,
7069 kmip_compare_request_header(&expected, &observed),
7070 result,
7071 __func__);
7072 kmip_free_request_header(&ctx, &observed);
7073 kmip_destroy(&ctx);
7074 return(result);
7075 }
7076
7077 int
7078 test_encode_response_header(TestTracker *tracker)
7079 {
7080 TRACK_TEST(tracker);
7081
7082 uint8 expected[80] = {
7083 0x42, 0x00, 0x7A, 0x01, 0x00, 0x00, 0x00, 0x48,
7084 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20,
7085 0x42, 0x00, 0x6A, 0x02, 0x00, 0x00, 0x00, 0x04,
7086 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
7087 0x42, 0x00, 0x6B, 0x02, 0x00, 0x00, 0x00, 0x04,
7088 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7089 0x42, 0x00, 0x92, 0x09, 0x00, 0x00, 0x00, 0x08,
7090 0x00, 0x00, 0x00, 0x00, 0x4F, 0x9A, 0x54, 0xE5,
7091 0x42, 0x00, 0x0D, 0x02, 0x00, 0x00, 0x00, 0x04,
7092 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
7093 };
7094
7095 uint8 observed[80] = {0};
7096 struct kmip ctx = {0};
7097 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
7098
7099 struct protocol_version pv = {0};
7100 pv.major = 1;
7101 pv.minor = 0;
7102
7103 struct response_header rh = {0};
7104 kmip_init_response_header(&rh);
7105
7106 rh.protocol_version = &pv;
7107 rh.time_stamp = 1335514341;
7108 rh.batch_count = 1;
7109
7110 int result = kmip_encode_response_header(&ctx, &rh);
7111 result = report_encoding_test_result(
7112 tracker,
7113 &ctx,
7114 expected,
7115 observed,
7116 result,
7117 __func__);
7118 kmip_destroy(&ctx);
7119 return(result);
7120 }
7121
7122 int
7123 test_decode_response_header(TestTracker *tracker)
7124 {
7125 TRACK_TEST(tracker);
7126
7127 uint8 encoding[80] = {
7128 0x42, 0x00, 0x7A, 0x01, 0x00, 0x00, 0x00, 0x48,
7129 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20,
7130 0x42, 0x00, 0x6A, 0x02, 0x00, 0x00, 0x00, 0x04,
7131 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
7132 0x42, 0x00, 0x6B, 0x02, 0x00, 0x00, 0x00, 0x04,
7133 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7134 0x42, 0x00, 0x92, 0x09, 0x00, 0x00, 0x00, 0x08,
7135 0x00, 0x00, 0x00, 0x00, 0x4F, 0x9A, 0x54, 0xE5,
7136 0x42, 0x00, 0x0D, 0x02, 0x00, 0x00, 0x00, 0x04,
7137 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
7138 };
7139
7140 struct kmip ctx = {0};
7141 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
7142
7143 struct protocol_version pv = {0};
7144 pv.major = 1;
7145 pv.minor = 0;
7146
7147 struct response_header expected = {0};
7148 kmip_init_response_header(&expected);
7149
7150 expected.protocol_version = &pv;
7151 expected.time_stamp = 1335514341;
7152 expected.batch_count = 1;
7153
7154 struct response_header observed = {0};
7155 kmip_init_response_header(&observed);
7156
7157 int result = kmip_decode_response_header(&ctx, &observed);
7158 result = report_decoding_test_result(
7159 tracker,
7160 &ctx,
7161 kmip_compare_response_header(&expected, &observed),
7162 result,
7163 __func__);
7164 kmip_free_response_header(&ctx, &observed);
7165 kmip_destroy(&ctx);
7166 return(result);
7167 }
7168
7169 int
7170 test_encode_request_batch_item_get_payload(TestTracker *tracker)
7171 {
7172 TRACK_TEST(tracker);
7173
7174 uint8 expected[80] = {
7175 0x42, 0x00, 0x0F, 0x01, 0x00, 0x00, 0x00, 0x48,
7176 0x42, 0x00, 0x5C, 0x05, 0x00, 0x00, 0x00, 0x04,
7177 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00,
7178 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, 0x30,
7179 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
7180 0x34, 0x39, 0x61, 0x31, 0x63, 0x61, 0x38, 0x38,
7181 0x2D, 0x36, 0x62, 0x65, 0x61, 0x2D, 0x34, 0x66,
7182 0x62, 0x32, 0x2D, 0x62, 0x34, 0x35, 0x30, 0x2D,
7183 0x37, 0x65, 0x35, 0x38, 0x38, 0x30, 0x32, 0x63,
7184 0x33, 0x30, 0x33, 0x38, 0x00, 0x00, 0x00, 0x00
7185 };
7186
7187 uint8 observed[80] = {0};
7188 struct kmip ctx = {0};
7189 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
7190
7191 struct text_string uuid = {0};
7192 uuid.value = "49a1ca88-6bea-4fb2-b450-7e58802c3038";
7193 uuid.size = 36;
7194
7195 struct get_request_payload grp = {0};
7196 grp.unique_identifier = &uuid;
7197
7198 struct request_batch_item rbi = {0};
7199 kmip_init_request_batch_item(&rbi);
7200 rbi.operation = KMIP_OP_GET;
7201 rbi.request_payload = &grp;
7202
7203 int result = kmip_encode_request_batch_item(&ctx, &rbi);
7204 result = report_encoding_test_result(
7205 tracker,
7206 &ctx,
7207 expected,
7208 observed,
7209 result,
7210 __func__);
7211 kmip_destroy(&ctx);
7212 return(result);
7213 }
7214
7215 int
7216 test_encode_request_batch_item_get_payload_kmip_2_0(TestTracker *tracker)
7217 {
7218 TRACK_TEST(tracker);
7219
7220 /* This encoding matches the following set of values:
7221 * Batch Item
7222 * Operation - Get
7223 * Ephemeral - False
7224 * Request Payload
7225 * Unique Identifier - 49a1ca88-6bea-4fb2-b450-7e58802c3038
7226 */
7227 uint8 expected[96] = {
7228 0x42, 0x00, 0x0F, 0x01, 0x00, 0x00, 0x00, 0x58,
7229 0x42, 0x00, 0x5C, 0x05, 0x00, 0x00, 0x00, 0x04,
7230 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00,
7231 0x42, 0x01, 0x54, 0x06, 0x00, 0x00, 0x00, 0x08,
7232 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7233 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, 0x30,
7234 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
7235 0x34, 0x39, 0x61, 0x31, 0x63, 0x61, 0x38, 0x38,
7236 0x2D, 0x36, 0x62, 0x65, 0x61, 0x2D, 0x34, 0x66,
7237 0x62, 0x32, 0x2D, 0x62, 0x34, 0x35, 0x30, 0x2D,
7238 0x37, 0x65, 0x35, 0x38, 0x38, 0x30, 0x32, 0x63,
7239 0x33, 0x30, 0x33, 0x38, 0x00, 0x00, 0x00, 0x00
7240 };
7241
7242 uint8 observed[96] = {0};
7243 KMIP ctx = {0};
7244 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_2_0);
7245
7246 TextString uuid = {0};
7247 uuid.value = "49a1ca88-6bea-4fb2-b450-7e58802c3038";
7248 uuid.size = 36;
7249
7250 GetRequestPayload grp = {0};
7251 grp.unique_identifier = &uuid;
7252
7253 RequestBatchItem rbi = {0};
7254 kmip_init_request_batch_item(&rbi);
7255 rbi.operation = KMIP_OP_GET;
7256 rbi.ephemeral = KMIP_FALSE;
7257 rbi.request_payload = &grp;
7258
7259 int result = kmip_encode_request_batch_item(&ctx, &rbi);
7260 result = report_encoding_test_result(tracker, &ctx, expected, observed, result, __func__);
7261 kmip_destroy(&ctx);
7262 return(result);
7263 }
7264
7265 int
7266 test_decode_request_batch_item_get_payload(TestTracker *tracker)
7267 {
7268 TRACK_TEST(tracker);
7269
7270 uint8 encoding[80] = {
7271 0x42, 0x00, 0x0F, 0x01, 0x00, 0x00, 0x00, 0x48,
7272 0x42, 0x00, 0x5C, 0x05, 0x00, 0x00, 0x00, 0x04,
7273 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00,
7274 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, 0x30,
7275 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
7276 0x34, 0x39, 0x61, 0x31, 0x63, 0x61, 0x38, 0x38,
7277 0x2D, 0x36, 0x62, 0x65, 0x61, 0x2D, 0x34, 0x66,
7278 0x62, 0x32, 0x2D, 0x62, 0x34, 0x35, 0x30, 0x2D,
7279 0x37, 0x65, 0x35, 0x38, 0x38, 0x30, 0x32, 0x63,
7280 0x33, 0x30, 0x33, 0x38, 0x00, 0x00, 0x00, 0x00
7281 };
7282
7283 struct kmip ctx = {0};
7284 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
7285
7286 struct text_string uuid = {0};
7287 uuid.value = "49a1ca88-6bea-4fb2-b450-7e58802c3038";
7288 uuid.size = 36;
7289
7290 struct get_request_payload grp = {0};
7291 grp.unique_identifier = &uuid;
7292
7293 struct request_batch_item expected = {0};
7294 kmip_init_request_batch_item(&expected);
7295 expected.operation = KMIP_OP_GET;
7296 expected.request_payload = &grp;
7297
7298 struct request_batch_item observed = {0};
7299 kmip_init_request_batch_item(&observed);
7300
7301 int result = kmip_decode_request_batch_item(&ctx, &observed);
7302 result = report_decoding_test_result(
7303 tracker,
7304 &ctx,
7305 kmip_compare_request_batch_item(&expected, &observed),
7306 result,
7307 __func__);
7308 kmip_free_request_batch_item(&ctx, &observed);
7309 kmip_destroy(&ctx);
7310 return(result);
7311 }
7312
7313 int
7314 test_decode_request_batch_item_get_payload_kmip_2_0(TestTracker *tracker)
7315 {
7316 TRACK_TEST(tracker);
7317
7318 /* This encoding matches the following set of values:
7319 * Batch Item
7320 * Operation - Get
7321 * Ephemeral - False
7322 * Request Payload
7323 * Unique Identifier - 49a1ca88-6bea-4fb2-b450-7e58802c3038
7324 */
7325 uint8 encoding[96] = {
7326 0x42, 0x00, 0x0F, 0x01, 0x00, 0x00, 0x00, 0x58,
7327 0x42, 0x00, 0x5C, 0x05, 0x00, 0x00, 0x00, 0x04,
7328 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00,
7329 0x42, 0x01, 0x54, 0x06, 0x00, 0x00, 0x00, 0x08,
7330 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7331 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, 0x30,
7332 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
7333 0x34, 0x39, 0x61, 0x31, 0x63, 0x61, 0x38, 0x38,
7334 0x2D, 0x36, 0x62, 0x65, 0x61, 0x2D, 0x34, 0x66,
7335 0x62, 0x32, 0x2D, 0x62, 0x34, 0x35, 0x30, 0x2D,
7336 0x37, 0x65, 0x35, 0x38, 0x38, 0x30, 0x32, 0x63,
7337 0x33, 0x30, 0x33, 0x38, 0x00, 0x00, 0x00, 0x00
7338 };
7339
7340 KMIP ctx = {0};
7341 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_2_0);
7342
7343 TextString uuid = {0};
7344 uuid.value = "49a1ca88-6bea-4fb2-b450-7e58802c3038";
7345 uuid.size = 36;
7346
7347 GetRequestPayload grp = {0};
7348 grp.unique_identifier = &uuid;
7349
7350 RequestBatchItem expected = {0};
7351 kmip_init_request_batch_item(&expected);
7352 expected.operation = KMIP_OP_GET;
7353 expected.ephemeral = KMIP_FALSE;
7354 expected.request_payload = &grp;
7355
7356 RequestBatchItem observed = {0};
7357 kmip_init_request_batch_item(&observed);
7358
7359 int result = kmip_decode_request_batch_item(&ctx, &observed);
7360 int comparison = kmip_compare_request_batch_item(&expected, &observed);
7361 if(!comparison)
7362 {
7363 kmip_print_request_batch_item(1, &expected);
7364 kmip_print_request_batch_item(1, &observed);
7365 }
7366 result = report_decoding_test_result(tracker, &ctx, comparison, result, __func__);
7367
7368 kmip_free_request_batch_item(&ctx, &observed);
7369 kmip_destroy(&ctx);
7370 return(result);
7371 }
7372
7373 int
7374 test_encode_response_batch_item_get_payload(TestTracker *tracker)
7375 {
7376 TRACK_TEST(tracker);
7377
7378 uint8 expected[216] = {
7379 0x42, 0x00, 0x0F, 0x01, 0x00, 0x00, 0x00, 0xD0,
7380 0x42, 0x00, 0x5C, 0x05, 0x00, 0x00, 0x00, 0x04,
7381 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00,
7382 0x42, 0x00, 0x7F, 0x05, 0x00, 0x00, 0x00, 0x04,
7383 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7384 0x42, 0x00, 0x7C, 0x01, 0x00, 0x00, 0x00, 0xA8,
7385 0x42, 0x00, 0x57, 0x05, 0x00, 0x00, 0x00, 0x04,
7386 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
7387 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
7388 0x34, 0x39, 0x61, 0x31, 0x63, 0x61, 0x38, 0x38,
7389 0x2D, 0x36, 0x62, 0x65, 0x61, 0x2D, 0x34, 0x66,
7390 0x62, 0x32, 0x2D, 0x62, 0x34, 0x35, 0x30, 0x2D,
7391 0x37, 0x65, 0x35, 0x38, 0x38, 0x30, 0x32, 0x63,
7392 0x33, 0x30, 0x33, 0x38, 0x00, 0x00, 0x00, 0x00,
7393 0x42, 0x00, 0x8F, 0x01, 0x00, 0x00, 0x00, 0x60,
7394 0x42, 0x00, 0x40, 0x01, 0x00, 0x00, 0x00, 0x58,
7395 0x42, 0x00, 0x42, 0x05, 0x00, 0x00, 0x00, 0x04,
7396 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
7397 0x42, 0x00, 0x45, 0x01, 0x00, 0x00, 0x00, 0x20,
7398 0x42, 0x00, 0x43, 0x08, 0x00, 0x00, 0x00, 0x18,
7399 0x73, 0x67, 0x57, 0x80, 0x51, 0x01, 0x2A, 0x6D,
7400 0x13, 0x4A, 0x85, 0x5E, 0x25, 0xC8, 0xCD, 0x5E,
7401 0x4C, 0xA1, 0x31, 0x45, 0x57, 0x29, 0xD3, 0xC8,
7402 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
7403 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
7404 0x42, 0x00, 0x2A, 0x02, 0x00, 0x00, 0x00, 0x04,
7405 0x00, 0x00, 0x00, 0xA8, 0x00, 0x00, 0x00, 0x00
7406 };
7407
7408 uint8 observed[216] = {0};
7409 struct kmip ctx = {0};
7410 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
7411
7412 struct text_string uuid = {0};
7413 uuid.value = "49a1ca88-6bea-4fb2-b450-7e58802c3038";
7414 uuid.size = 36;
7415
7416 uint8 value[24] = {
7417 0x73, 0x67, 0x57, 0x80, 0x51, 0x01, 0x2A, 0x6D,
7418 0x13, 0x4A, 0x85, 0x5E, 0x25, 0xC8, 0xCD, 0x5E,
7419 0x4C, 0xA1, 0x31, 0x45, 0x57, 0x29, 0xD3, 0xC8
7420 };
7421
7422 struct byte_string v = {0};
7423 v.value = value;
7424 v.size = ARRAY_LENGTH(value);
7425
7426 struct key_value kv = {0};
7427 kv.key_material = &v;
7428
7429 struct key_block kb = {0};
7430 kb.key_format_type = KMIP_KEYFORMAT_RAW;
7431 kb.key_value = &kv;
7432 kb.cryptographic_algorithm = KMIP_CRYPTOALG_TRIPLE_DES;
7433 kb.cryptographic_length = 168;
7434
7435 struct symmetric_key key = {0};
7436 key.key_block = &kb;
7437
7438 struct get_response_payload grp = {0};
7439 grp.object_type = KMIP_OBJTYPE_SYMMETRIC_KEY;
7440 grp.unique_identifier = &uuid;
7441 grp.object = &key;
7442
7443 struct response_batch_item rbi = {0};
7444 rbi.operation = KMIP_OP_GET;
7445 rbi.result_status = KMIP_STATUS_SUCCESS;
7446 rbi.response_payload = &grp;
7447
7448 int result = kmip_encode_response_batch_item(&ctx, &rbi);
7449 result = report_encoding_test_result(
7450 tracker,
7451 &ctx,
7452 expected,
7453 observed,
7454 result,
7455 __func__);
7456 kmip_destroy(&ctx);
7457 return(result);
7458 }
7459
7460 int
7461 test_decode_response_batch_item_get_payload(TestTracker *tracker)
7462 {
7463 TRACK_TEST(tracker);
7464
7465 uint8 encoding[216] = {
7466 0x42, 0x00, 0x0F, 0x01, 0x00, 0x00, 0x00, 0xD0,
7467 0x42, 0x00, 0x5C, 0x05, 0x00, 0x00, 0x00, 0x04,
7468 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00,
7469 0x42, 0x00, 0x7F, 0x05, 0x00, 0x00, 0x00, 0x04,
7470 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7471 0x42, 0x00, 0x7C, 0x01, 0x00, 0x00, 0x00, 0xA8,
7472 0x42, 0x00, 0x57, 0x05, 0x00, 0x00, 0x00, 0x04,
7473 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
7474 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
7475 0x34, 0x39, 0x61, 0x31, 0x63, 0x61, 0x38, 0x38,
7476 0x2D, 0x36, 0x62, 0x65, 0x61, 0x2D, 0x34, 0x66,
7477 0x62, 0x32, 0x2D, 0x62, 0x34, 0x35, 0x30, 0x2D,
7478 0x37, 0x65, 0x35, 0x38, 0x38, 0x30, 0x32, 0x63,
7479 0x33, 0x30, 0x33, 0x38, 0x00, 0x00, 0x00, 0x00,
7480 0x42, 0x00, 0x8F, 0x01, 0x00, 0x00, 0x00, 0x60,
7481 0x42, 0x00, 0x40, 0x01, 0x00, 0x00, 0x00, 0x58,
7482 0x42, 0x00, 0x42, 0x05, 0x00, 0x00, 0x00, 0x04,
7483 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
7484 0x42, 0x00, 0x45, 0x01, 0x00, 0x00, 0x00, 0x20,
7485 0x42, 0x00, 0x43, 0x08, 0x00, 0x00, 0x00, 0x18,
7486 0x73, 0x67, 0x57, 0x80, 0x51, 0x01, 0x2A, 0x6D,
7487 0x13, 0x4A, 0x85, 0x5E, 0x25, 0xC8, 0xCD, 0x5E,
7488 0x4C, 0xA1, 0x31, 0x45, 0x57, 0x29, 0xD3, 0xC8,
7489 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
7490 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
7491 0x42, 0x00, 0x2A, 0x02, 0x00, 0x00, 0x00, 0x04,
7492 0x00, 0x00, 0x00, 0xA8, 0x00, 0x00, 0x00, 0x00
7493 };
7494
7495 struct kmip ctx = {0};
7496 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
7497
7498 struct text_string uuid = {0};
7499 uuid.value = "49a1ca88-6bea-4fb2-b450-7e58802c3038";
7500 uuid.size = 36;
7501
7502 uint8 value[24] = {
7503 0x73, 0x67, 0x57, 0x80, 0x51, 0x01, 0x2A, 0x6D,
7504 0x13, 0x4A, 0x85, 0x5E, 0x25, 0xC8, 0xCD, 0x5E,
7505 0x4C, 0xA1, 0x31, 0x45, 0x57, 0x29, 0xD3, 0xC8
7506 };
7507
7508 struct byte_string v = {0};
7509 v.value = value;
7510 v.size = ARRAY_LENGTH(value);
7511
7512 struct key_value kv = {0};
7513 kv.key_material = &v;
7514
7515 struct key_block kb = {0};
7516 kb.key_format_type = KMIP_KEYFORMAT_RAW;
7517 kb.key_value = &kv;
7518 kb.key_value_type = KMIP_TYPE_STRUCTURE;
7519 kb.cryptographic_algorithm = KMIP_CRYPTOALG_TRIPLE_DES;
7520 kb.cryptographic_length = 168;
7521
7522 struct symmetric_key key = {0};
7523 key.key_block = &kb;
7524
7525 struct get_response_payload grp = {0};
7526 grp.object_type = KMIP_OBJTYPE_SYMMETRIC_KEY;
7527 grp.unique_identifier = &uuid;
7528 grp.object = &key;
7529
7530 struct response_batch_item expected = {0};
7531 expected.operation = KMIP_OP_GET;
7532 expected.result_status = KMIP_STATUS_SUCCESS;
7533 expected.response_payload = &grp;
7534
7535 struct response_batch_item observed = {0};
7536
7537 int result = kmip_decode_response_batch_item(&ctx, &observed);
7538 result = report_decoding_test_result(
7539 tracker,
7540 &ctx,
7541 kmip_compare_response_batch_item(&expected, &observed),
7542 result,
7543 __func__);
7544 kmip_free_response_batch_item(&ctx, &observed);
7545 kmip_destroy(&ctx);
7546 return(result);
7547 }
7548
7549 int
7550 test_encode_request_message_get(TestTracker *tracker)
7551 {
7552 TRACK_TEST(tracker);
7553
7554 uint8 expected[152] = {
7555 0x42, 0x00, 0x78, 0x01, 0x00, 0x00, 0x00, 0x90,
7556 0x42, 0x00, 0x77, 0x01, 0x00, 0x00, 0x00, 0x38,
7557 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20,
7558 0x42, 0x00, 0x6A, 0x02, 0x00, 0x00, 0x00, 0x04,
7559 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
7560 0x42, 0x00, 0x6B, 0x02, 0x00, 0x00, 0x00, 0x04,
7561 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7562 0x42, 0x00, 0x0D, 0x02, 0x00, 0x00, 0x00, 0x04,
7563 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
7564 0x42, 0x00, 0x0F, 0x01, 0x00, 0x00, 0x00, 0x48,
7565 0x42, 0x00, 0x5C, 0x05, 0x00, 0x00, 0x00, 0x04,
7566 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00,
7567 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, 0x30,
7568 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
7569 0x34, 0x39, 0x61, 0x31, 0x63, 0x61, 0x38, 0x38,
7570 0x2D, 0x36, 0x62, 0x65, 0x61, 0x2D, 0x34, 0x66,
7571 0x62, 0x32, 0x2D, 0x62, 0x34, 0x35, 0x30, 0x2D,
7572 0x37, 0x65, 0x35, 0x38, 0x38, 0x30, 0x32, 0x63,
7573 0x33, 0x30, 0x33, 0x38, 0x00, 0x00, 0x00, 0x00
7574 };
7575
7576 uint8 observed[152] = {0};
7577 struct kmip ctx = {0};
7578 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
7579
7580 struct protocol_version pv = {0};
7581 pv.major = 1;
7582 pv.minor = 0;
7583
7584 struct request_header rh = {0};
7585 kmip_init_request_header(&rh);
7586
7587 rh.protocol_version = &pv;
7588 rh.batch_count = 1;
7589
7590 struct text_string uuid = {0};
7591 uuid.value = "49a1ca88-6bea-4fb2-b450-7e58802c3038";
7592 uuid.size = 36;
7593
7594 struct get_request_payload grp = {0};
7595 grp.unique_identifier = &uuid;
7596
7597 struct request_batch_item rbi = {0};
7598 kmip_init_request_batch_item(&rbi);
7599 rbi.operation = KMIP_OP_GET;
7600 rbi.request_payload = &grp;
7601
7602 struct request_message rm = {0};
7603 rm.request_header = &rh;
7604 rm.batch_items = &rbi;
7605 rm.batch_count = 1;
7606
7607 int result = kmip_encode_request_message(&ctx, &rm);
7608 result = report_encoding_test_result(
7609 tracker,
7610 &ctx,
7611 expected,
7612 observed,
7613 result,
7614 __func__);
7615 kmip_destroy(&ctx);
7616 return(result);
7617 }
7618
7619 int
7620 test_decode_request_message_get(TestTracker *tracker)
7621 {
7622 TRACK_TEST(tracker);
7623
7624 uint8 encoding[152] = {
7625 0x42, 0x00, 0x78, 0x01, 0x00, 0x00, 0x00, 0x90,
7626 0x42, 0x00, 0x77, 0x01, 0x00, 0x00, 0x00, 0x38,
7627 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20,
7628 0x42, 0x00, 0x6A, 0x02, 0x00, 0x00, 0x00, 0x04,
7629 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
7630 0x42, 0x00, 0x6B, 0x02, 0x00, 0x00, 0x00, 0x04,
7631 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7632 0x42, 0x00, 0x0D, 0x02, 0x00, 0x00, 0x00, 0x04,
7633 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
7634 0x42, 0x00, 0x0F, 0x01, 0x00, 0x00, 0x00, 0x48,
7635 0x42, 0x00, 0x5C, 0x05, 0x00, 0x00, 0x00, 0x04,
7636 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00,
7637 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, 0x30,
7638 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
7639 0x34, 0x39, 0x61, 0x31, 0x63, 0x61, 0x38, 0x38,
7640 0x2D, 0x36, 0x62, 0x65, 0x61, 0x2D, 0x34, 0x66,
7641 0x62, 0x32, 0x2D, 0x62, 0x34, 0x35, 0x30, 0x2D,
7642 0x37, 0x65, 0x35, 0x38, 0x38, 0x30, 0x32, 0x63,
7643 0x33, 0x30, 0x33, 0x38, 0x00, 0x00, 0x00, 0x00
7644 };
7645
7646 struct kmip ctx = {0};
7647 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
7648
7649 struct protocol_version pv = {0};
7650 pv.major = 1;
7651 pv.minor = 0;
7652
7653 struct request_header rh = {0};
7654 kmip_init_request_header(&rh);
7655
7656 rh.protocol_version = &pv;
7657 rh.batch_count = 1;
7658
7659 struct text_string uuid = {0};
7660 uuid.value = "49a1ca88-6bea-4fb2-b450-7e58802c3038";
7661 uuid.size = 36;
7662
7663 struct get_request_payload grp = {0};
7664 grp.unique_identifier = &uuid;
7665
7666 struct request_batch_item rbi = {0};
7667 kmip_init_request_batch_item(&rbi);
7668 rbi.operation = KMIP_OP_GET;
7669 rbi.request_payload = &grp;
7670
7671 struct request_message expected = {0};
7672 expected.request_header = &rh;
7673 expected.batch_items = &rbi;
7674 expected.batch_count = 1;
7675
7676 struct request_message observed = {0};
7677
7678 int result = kmip_decode_request_message(&ctx, &observed);
7679 int comparison = kmip_compare_request_message(&expected, &observed);
7680 if(!comparison)
7681 {
7682 kmip_print_request_message(&expected);
7683 kmip_print_request_message(&observed);
7684 }
7685 result = report_decoding_test_result(tracker, &ctx, comparison, result, __func__);
7686
7687 kmip_free_request_message(&ctx, &observed);
7688 kmip_destroy(&ctx);
7689 return(result);
7690 }
7691
7692 int
7693 test_encode_response_message_get(TestTracker *tracker)
7694 {
7695 TRACK_TEST(tracker);
7696
7697 uint8 expected[304] = {
7698 0x42, 0x00, 0x7B, 0x01, 0x00, 0x00, 0x01, 0x28,
7699 0x42, 0x00, 0x7A, 0x01, 0x00, 0x00, 0x00, 0x48,
7700 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20,
7701 0x42, 0x00, 0x6A, 0x02, 0x00, 0x00, 0x00, 0x04,
7702 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
7703 0x42, 0x00, 0x6B, 0x02, 0x00, 0x00, 0x00, 0x04,
7704 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7705 0x42, 0x00, 0x92, 0x09, 0x00, 0x00, 0x00, 0x08,
7706 0x00, 0x00, 0x00, 0x00, 0x4F, 0x9A, 0x54, 0xE7,
7707 0x42, 0x00, 0x0D, 0x02, 0x00, 0x00, 0x00, 0x04,
7708 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
7709 0x42, 0x00, 0x0F, 0x01, 0x00, 0x00, 0x00, 0xD0,
7710 0x42, 0x00, 0x5C, 0x05, 0x00, 0x00, 0x00, 0x04,
7711 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00,
7712 0x42, 0x00, 0x7F, 0x05, 0x00, 0x00, 0x00, 0x04,
7713 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7714 0x42, 0x00, 0x7C, 0x01, 0x00, 0x00, 0x00, 0xA8,
7715 0x42, 0x00, 0x57, 0x05, 0x00, 0x00, 0x00, 0x04,
7716 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
7717 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
7718 0x34, 0x39, 0x61, 0x31, 0x63, 0x61, 0x38, 0x38,
7719 0x2D, 0x36, 0x62, 0x65, 0x61, 0x2D, 0x34, 0x66,
7720 0x62, 0x32, 0x2D, 0x62, 0x34, 0x35, 0x30, 0x2D,
7721 0x37, 0x65, 0x35, 0x38, 0x38, 0x30, 0x32, 0x63,
7722 0x33, 0x30, 0x33, 0x38, 0x00, 0x00, 0x00, 0x00,
7723 0x42, 0x00, 0x8F, 0x01, 0x00, 0x00, 0x00, 0x60,
7724 0x42, 0x00, 0x40, 0x01, 0x00, 0x00, 0x00, 0x58,
7725 0x42, 0x00, 0x42, 0x05, 0x00, 0x00, 0x00, 0x04,
7726 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
7727 0x42, 0x00, 0x45, 0x01, 0x00, 0x00, 0x00, 0x20,
7728 0x42, 0x00, 0x43, 0x08, 0x00, 0x00, 0x00, 0x18,
7729 0x73, 0x67, 0x57, 0x80, 0x51, 0x01, 0x2A, 0x6D,
7730 0x13, 0x4A, 0x85, 0x5E, 0x25, 0xC8, 0xCD, 0x5E,
7731 0x4C, 0xA1, 0x31, 0x45, 0x57, 0x29, 0xD3, 0xC8,
7732 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
7733 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
7734 0x42, 0x00, 0x2A, 0x02, 0x00, 0x00, 0x00, 0x04,
7735 0x00, 0x00, 0x00, 0xA8, 0x00, 0x00, 0x00, 0x00
7736 };
7737
7738 uint8 observed[304] = {0};
7739 struct kmip ctx = {0};
7740 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
7741
7742 struct protocol_version pv = {0};
7743 pv.major = 1;
7744 pv.minor = 0;
7745
7746 struct response_header rh = {0};
7747 kmip_init_response_header(&rh);
7748
7749 rh.protocol_version = &pv;
7750 rh.time_stamp = 1335514343;
7751 rh.batch_count = 1;
7752
7753 struct text_string uuid = {0};
7754 uuid.value = "49a1ca88-6bea-4fb2-b450-7e58802c3038";
7755 uuid.size = 36;
7756
7757 uint8 value[24] = {
7758 0x73, 0x67, 0x57, 0x80, 0x51, 0x01, 0x2A, 0x6D,
7759 0x13, 0x4A, 0x85, 0x5E, 0x25, 0xC8, 0xCD, 0x5E,
7760 0x4C, 0xA1, 0x31, 0x45, 0x57, 0x29, 0xD3, 0xC8
7761 };
7762
7763 struct byte_string v = {0};
7764 v.value = value;
7765 v.size = ARRAY_LENGTH(value);
7766
7767 struct key_value kv = {0};
7768 kv.key_material = &v;
7769
7770 struct key_block kb = {0};
7771 kb.key_format_type = KMIP_KEYFORMAT_RAW;
7772 kb.key_value = &kv;
7773 kb.cryptographic_algorithm = KMIP_CRYPTOALG_TRIPLE_DES;
7774 kb.cryptographic_length = 168;
7775
7776 struct symmetric_key key = {0};
7777 key.key_block = &kb;
7778
7779 struct get_response_payload grp = {0};
7780 grp.object_type = KMIP_OBJTYPE_SYMMETRIC_KEY;
7781 grp.unique_identifier = &uuid;
7782 grp.object = &key;
7783
7784 struct response_batch_item rbi = {0};
7785 rbi.operation = KMIP_OP_GET;
7786 rbi.result_status = KMIP_STATUS_SUCCESS;
7787 rbi.response_payload = &grp;
7788
7789 struct response_message rm = {0};
7790 rm.response_header = &rh;
7791 rm.batch_items = &rbi;
7792 rm.batch_count = 1;
7793
7794 int result = kmip_encode_response_message(&ctx, &rm);
7795 result = report_encoding_test_result(
7796 tracker,
7797 &ctx,
7798 expected,
7799 observed,
7800 result,
7801 __func__);
7802 kmip_destroy(&ctx);
7803 return(result);
7804 }
7805
7806 int
7807 test_decode_response_message_get(TestTracker *tracker)
7808 {
7809 TRACK_TEST(tracker);
7810
7811 uint8 encoding[304] = {
7812 0x42, 0x00, 0x7B, 0x01, 0x00, 0x00, 0x01, 0x28,
7813 0x42, 0x00, 0x7A, 0x01, 0x00, 0x00, 0x00, 0x48,
7814 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20,
7815 0x42, 0x00, 0x6A, 0x02, 0x00, 0x00, 0x00, 0x04,
7816 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
7817 0x42, 0x00, 0x6B, 0x02, 0x00, 0x00, 0x00, 0x04,
7818 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7819 0x42, 0x00, 0x92, 0x09, 0x00, 0x00, 0x00, 0x08,
7820 0x00, 0x00, 0x00, 0x00, 0x4F, 0x9A, 0x54, 0xE7,
7821 0x42, 0x00, 0x0D, 0x02, 0x00, 0x00, 0x00, 0x04,
7822 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
7823 0x42, 0x00, 0x0F, 0x01, 0x00, 0x00, 0x00, 0xD0,
7824 0x42, 0x00, 0x5C, 0x05, 0x00, 0x00, 0x00, 0x04,
7825 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00,
7826 0x42, 0x00, 0x7F, 0x05, 0x00, 0x00, 0x00, 0x04,
7827 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7828 0x42, 0x00, 0x7C, 0x01, 0x00, 0x00, 0x00, 0xA8,
7829 0x42, 0x00, 0x57, 0x05, 0x00, 0x00, 0x00, 0x04,
7830 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
7831 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
7832 0x34, 0x39, 0x61, 0x31, 0x63, 0x61, 0x38, 0x38,
7833 0x2D, 0x36, 0x62, 0x65, 0x61, 0x2D, 0x34, 0x66,
7834 0x62, 0x32, 0x2D, 0x62, 0x34, 0x35, 0x30, 0x2D,
7835 0x37, 0x65, 0x35, 0x38, 0x38, 0x30, 0x32, 0x63,
7836 0x33, 0x30, 0x33, 0x38, 0x00, 0x00, 0x00, 0x00,
7837 0x42, 0x00, 0x8F, 0x01, 0x00, 0x00, 0x00, 0x60,
7838 0x42, 0x00, 0x40, 0x01, 0x00, 0x00, 0x00, 0x58,
7839 0x42, 0x00, 0x42, 0x05, 0x00, 0x00, 0x00, 0x04,
7840 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
7841 0x42, 0x00, 0x45, 0x01, 0x00, 0x00, 0x00, 0x20,
7842 0x42, 0x00, 0x43, 0x08, 0x00, 0x00, 0x00, 0x18,
7843 0x73, 0x67, 0x57, 0x80, 0x51, 0x01, 0x2A, 0x6D,
7844 0x13, 0x4A, 0x85, 0x5E, 0x25, 0xC8, 0xCD, 0x5E,
7845 0x4C, 0xA1, 0x31, 0x45, 0x57, 0x29, 0xD3, 0xC8,
7846 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
7847 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
7848 0x42, 0x00, 0x2A, 0x02, 0x00, 0x00, 0x00, 0x04,
7849 0x00, 0x00, 0x00, 0xA8, 0x00, 0x00, 0x00, 0x00
7850 };
7851
7852 struct kmip ctx = {0};
7853 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
7854
7855 struct protocol_version pv = {0};
7856 pv.major = 1;
7857 pv.minor = 0;
7858
7859 struct response_header rh = {0};
7860 kmip_init_response_header(&rh);
7861
7862 rh.protocol_version = &pv;
7863 rh.time_stamp = 1335514343;
7864 rh.batch_count = 1;
7865
7866 struct text_string uuid = {0};
7867 uuid.value = "49a1ca88-6bea-4fb2-b450-7e58802c3038";
7868 uuid.size = 36;
7869
7870 uint8 value[24] = {
7871 0x73, 0x67, 0x57, 0x80, 0x51, 0x01, 0x2A, 0x6D,
7872 0x13, 0x4A, 0x85, 0x5E, 0x25, 0xC8, 0xCD, 0x5E,
7873 0x4C, 0xA1, 0x31, 0x45, 0x57, 0x29, 0xD3, 0xC8
7874 };
7875
7876 struct byte_string v = {0};
7877 v.value = value;
7878 v.size = ARRAY_LENGTH(value);
7879
7880 struct key_value kv = {0};
7881 kv.key_material = &v;
7882
7883 struct key_block kb = {0};
7884 kb.key_format_type = KMIP_KEYFORMAT_RAW;
7885 kb.key_value = &kv;
7886 kb.key_value_type = KMIP_TYPE_STRUCTURE;
7887 kb.cryptographic_algorithm = KMIP_CRYPTOALG_TRIPLE_DES;
7888 kb.cryptographic_length = 168;
7889
7890 struct symmetric_key key = {0};
7891 key.key_block = &kb;
7892
7893 struct get_response_payload grp = {0};
7894 grp.object_type = KMIP_OBJTYPE_SYMMETRIC_KEY;
7895 grp.unique_identifier = &uuid;
7896 grp.object = &key;
7897
7898 struct response_batch_item rbi = {0};
7899 rbi.operation = KMIP_OP_GET;
7900 rbi.result_status = KMIP_STATUS_SUCCESS;
7901 rbi.response_payload = &grp;
7902
7903 struct response_message expected = {0};
7904 expected.response_header = &rh;
7905 expected.batch_items = &rbi;
7906 expected.batch_count = 1;
7907
7908 struct response_message observed = {0};
7909
7910 int result = kmip_decode_response_message(&ctx, &observed);
7911 result = report_decoding_test_result(
7912 tracker,
7913 &ctx,
7914 kmip_compare_response_message(&expected, &observed),
7915 result,
7916 __func__);
7917 kmip_free_response_message(&ctx, &observed);
7918 kmip_destroy(&ctx);
7919 return(result);
7920 }
7921
7922 int
7923 test_encode_attributes(TestTracker *tracker)
7924 {
7925 TRACK_TEST(tracker);
7926
7927 /* This encoding matches the following set of values:
7928 * Attributes
7929 * Cryptographic Algorithm - AES
7930 * Cryptographic Length - 128
7931 */
7932 uint8 expected[40] = {
7933 0x42, 0x01, 0x25, 0x01, 0x00, 0x00, 0x00, 0x20,
7934 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
7935 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
7936 0x42, 0x00, 0x2A, 0x02, 0x00, 0x00, 0x00, 0x04,
7937 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00
7938 };
7939
7940 uint8 observed[40] = {0};
7941 struct kmip ctx = {0};
7942 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_2_0);
7943
7944 LinkedList attribute_list = {0};
7945
7946 LinkedListItem item_1 = {0};
7947 Attribute attr_1 = {0};
7948 kmip_init_attribute(&attr_1);
7949 enum cryptographic_algorithm algorithm = KMIP_CRYPTOALG_AES;
7950 attr_1.type = KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM;
7951 attr_1.value = &algorithm;
7952 item_1.data = &attr_1;
7953
7954 LinkedListItem item_2 = {0};
7955 Attribute attr_2 = {0};
7956 kmip_init_attribute(&attr_2);
7957 int32 length = 128;
7958 attr_2.type = KMIP_ATTR_CRYPTOGRAPHIC_LENGTH;
7959 attr_2.value = &length;
7960 item_2.data = &attr_2;
7961
7962 kmip_linked_list_enqueue(&attribute_list, &item_1);
7963 kmip_linked_list_enqueue(&attribute_list, &item_2);
7964
7965 Attributes attributes = {0};
7966 attributes.attribute_list = &attribute_list;
7967
7968 int result = kmip_encode_attributes(&ctx, &attributes);
7969 result = report_encoding_test_result(tracker, &ctx, expected, observed, result, __func__);
7970
7971 kmip_destroy(&ctx);
7972
7973 return(result);
7974 }
7975
7976 int
7977 test_encode_attributes_with_invalid_kmip_version(TestTracker *tracker)
7978 {
7979 TRACK_TEST(tracker);
7980
7981 uint8 observed[40] = {0};
7982 struct kmip ctx = {0};
7983 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_4);
7984
7985 Attributes attributes = {0};
7986
7987 int result = kmip_encode_attributes(&ctx, &attributes);
7988 kmip_destroy(&ctx);
7989
7990 result = report_result(tracker, result, KMIP_INVALID_FOR_VERSION, __func__);
7991 return(result);
7992 }
7993
7994 int
7995 test_encode_attribute_v2_unique_identifier(TestTracker *tracker)
7996 {
7997 TRACK_TEST(tracker);
7998
7999 /* This encoding matches the following value:
8000 * Unique Identifier - fb4b5b9c-6188-4c63-8142-fe9c328129fc
8001 */
8002 uint8 expected[48] = {
8003 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
8004 0x66, 0x62, 0x34, 0x62, 0x35, 0x62, 0x39, 0x63,
8005 0x2D, 0x36, 0x31, 0x38, 0x38, 0x2D, 0x34, 0x63,
8006 0x36, 0x33, 0x2D, 0x38, 0x31, 0x34, 0x32, 0x2D,
8007 0x66, 0x65, 0x39, 0x63, 0x33, 0x32, 0x38, 0x31,
8008 0x32, 0x39, 0x66, 0x63, 0x00, 0x00, 0x00, 0x00
8009 };
8010
8011 uint8 observed[48] = {0};
8012 KMIP ctx = {0};
8013 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_2_0);
8014
8015 Attribute attribute = {0};
8016 kmip_init_attribute(&attribute);
8017 TextString unique_identifier = {0};
8018 unique_identifier.value = "fb4b5b9c-6188-4c63-8142-fe9c328129fc";
8019 unique_identifier.size = 36;
8020 attribute.type = KMIP_ATTR_UNIQUE_IDENTIFIER;
8021 attribute.value = &unique_identifier;
8022
8023 int result = kmip_encode_attribute_v2(&ctx, &attribute);
8024 result = report_encoding_test_result(tracker, &ctx, expected, observed, result, __func__);
8025
8026 kmip_destroy(&ctx);
8027
8028 return(result);
8029 }
8030
8031 int
8032 test_encode_attribute_v2_name(TestTracker *tracker)
8033 {
8034 TRACK_TEST(tracker);
8035
8036 /* This encoding matches the following value:
8037 * Name
8038 * Value - Template1
8039 * Type - Uninterpreted Text String
8040 */
8041 uint8 expected[48] = {
8042 0x42, 0x00, 0x53, 0x01, 0x00, 0x00, 0x00, 0x28,
8043 0x42, 0x00, 0x55, 0x07, 0x00, 0x00, 0x00, 0x09,
8044 0x54, 0x65, 0x6D, 0x70, 0x6C, 0x61, 0x74, 0x65,
8045 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8046 0x42, 0x00, 0x54, 0x05, 0x00, 0x00, 0x00, 0x04,
8047 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
8048 };
8049
8050 uint8 observed[48] = {0};
8051 KMIP ctx = {0};
8052 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_2_0);
8053
8054 Attribute attribute = {0};
8055 kmip_init_attribute(&attribute);
8056 TextString name_value = {0};
8057 name_value.value = "Template1";
8058 name_value.size = 9;
8059 Name name = {0};
8060 name.value = &name_value;
8061 name.type = KMIP_NAME_UNINTERPRETED_TEXT_STRING;
8062
8063 attribute.type = KMIP_ATTR_NAME;
8064 attribute.value = &name;
8065
8066 int result = kmip_encode_attribute_v2(&ctx, &attribute);
8067 result = report_encoding_test_result(tracker, &ctx, expected, observed, result, __func__);
8068
8069 kmip_destroy(&ctx);
8070
8071 return(result);
8072 }
8073
8074 int
8075 test_encode_attribute_v2_object_type(TestTracker *tracker)
8076 {
8077 TRACK_TEST(tracker);
8078
8079 /* This encoding matches the following value:
8080 * Object Type - Symmetric Key
8081 */
8082 uint8 expected[16] = {
8083 0x42, 0x00, 0x57, 0x05, 0x00, 0x00, 0x00, 0x04,
8084 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00
8085 };
8086
8087 uint8 observed[16] = {0};
8088 KMIP ctx = {0};
8089 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_2_0);
8090
8091 Attribute attribute = {0};
8092 kmip_init_attribute(&attribute);
8093 enum object_type object_type = KMIP_OBJTYPE_SYMMETRIC_KEY;
8094 attribute.type = KMIP_ATTR_OBJECT_TYPE;
8095 attribute.value = &object_type;
8096
8097 int result = kmip_encode_attribute_v2(&ctx, &attribute);
8098 result = report_encoding_test_result(tracker, &ctx, expected, observed, result, __func__);
8099
8100 kmip_destroy(&ctx);
8101
8102 return(result);
8103 }
8104
8105 int
8106 test_encode_attribute_v2_cryptographic_algorithm(TestTracker *tracker)
8107 {
8108 TRACK_TEST(tracker);
8109
8110 /* This encoding matches the following value:
8111 * Cryptographic Algorithm - AES
8112 */
8113 uint8 expected[16] = {
8114 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
8115 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00
8116 };
8117
8118 uint8 observed[16] = {0};
8119 KMIP ctx = {0};
8120 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_2_0);
8121
8122 Attribute attribute = {0};
8123 kmip_init_attribute(&attribute);
8124 enum cryptographic_algorithm algorithm = KMIP_CRYPTOALG_AES;
8125 attribute.type = KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM;
8126 attribute.value = &algorithm;
8127
8128 int result = kmip_encode_attribute_v2(&ctx, &attribute);
8129 result = report_encoding_test_result(tracker, &ctx, expected, observed, result, __func__);
8130
8131 kmip_destroy(&ctx);
8132
8133 return(result);
8134 }
8135
8136 int
8137 test_encode_attribute_v2_cryptographic_length(TestTracker *tracker)
8138 {
8139 TRACK_TEST(tracker);
8140
8141 /* This encoding matches the following value:
8142 * Cryptographic Length - 128
8143 */
8144 uint8 expected[16] = {
8145 0x42, 0x00, 0x2A, 0x02, 0x00, 0x00, 0x00, 0x04,
8146 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00
8147 };
8148
8149 uint8 observed[16] = {0};
8150 KMIP ctx = {0};
8151 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_2_0);
8152
8153 Attribute attribute = {0};
8154 kmip_init_attribute(&attribute);
8155 int32 length = 128;
8156 attribute.type = KMIP_ATTR_CRYPTOGRAPHIC_LENGTH;
8157 attribute.value = &length;
8158
8159 int result = kmip_encode_attribute_v2(&ctx, &attribute);
8160 result = report_encoding_test_result(tracker, &ctx, expected, observed, result, __func__);
8161
8162 kmip_destroy(&ctx);
8163
8164 return(result);
8165 }
8166
8167 int
8168 test_encode_attribute_v2_cryptographic_usage_mask(TestTracker *tracker)
8169 {
8170 TRACK_TEST(tracker);
8171
8172 /* This encoding matches the following value:
8173 * Cryptographic Usage Mask - Encrypt | Decrypt
8174 */
8175 uint8 expected[16] = {
8176 0x42, 0x00, 0x2C, 0x02, 0x00, 0x00, 0x00, 0x04,
8177 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00
8178 };
8179
8180 uint8 observed[16] = {0};
8181 KMIP ctx = {0};
8182 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_2_0);
8183
8184 Attribute attribute = {0};
8185 kmip_init_attribute(&attribute);
8186 int32 mask = KMIP_CRYPTOMASK_ENCRYPT | KMIP_CRYPTOMASK_DECRYPT;
8187 attribute.type = KMIP_ATTR_CRYPTOGRAPHIC_USAGE_MASK;
8188 attribute.value = &mask;
8189
8190 int result = kmip_encode_attribute_v2(&ctx, &attribute);
8191 result = report_encoding_test_result(tracker, &ctx, expected, observed, result, __func__);
8192
8193 kmip_destroy(&ctx);
8194
8195 return(result);
8196 }
8197
8198 int
8199 test_encode_attribute_v2_state(TestTracker *tracker)
8200 {
8201 TRACK_TEST(tracker);
8202
8203 /* This encoding matches the following value:
8204 * State - Active
8205 */
8206 uint8 expected[16] = {
8207 0x42, 0x00, 0x8D, 0x05, 0x00, 0x00, 0x00, 0x04,
8208 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00
8209 };
8210
8211 uint8 observed[16] = {0};
8212 KMIP ctx = {0};
8213 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_2_0);
8214
8215 Attribute attribute = {0};
8216 kmip_init_attribute(&attribute);
8217 enum state state = KMIP_STATE_ACTIVE;
8218 attribute.type = KMIP_ATTR_STATE;
8219 attribute.value = &state;
8220
8221 int result = kmip_encode_attribute_v2(&ctx, &attribute);
8222 result = report_encoding_test_result(tracker, &ctx, expected, observed, result, __func__);
8223
8224 kmip_destroy(&ctx);
8225
8226 return(result);
8227 }
8228
8229 int
8230 test_encode_attribute_v2_unsupported_attribute(TestTracker *tracker)
8231 {
8232 TRACK_TEST(tracker);
8233
8234 uint8 encoding[16] = {0};
8235
8236 KMIP ctx = {0};
8237 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_2_0);
8238
8239 Attribute attribute = {0};
8240 attribute.type = -1;
8241 int result = kmip_encode_attribute_v2(&ctx, &attribute);
8242 if(result != KMIP_ERROR_ATTR_UNSUPPORTED)
8243 {
8244 TEST_FAILED(tracker, __func__, __LINE__);
8245 }
8246
8247 kmip_destroy(&ctx);
8248
8249 TEST_PASSED(tracker, __func__);
8250 }
8251
8252 int
8253 test_decode_attributes(TestTracker *tracker)
8254 {
8255 TRACK_TEST(tracker);
8256
8257 /* This encoding matches the following set of values:
8258 * Attributes
8259 * Cryptographic Algorithm - AES
8260 * Cryptographic Length - 128
8261 */
8262 uint8 encoding[40] = {
8263 0x42, 0x01, 0x25, 0x01, 0x00, 0x00, 0x00, 0x20,
8264 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
8265 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
8266 0x42, 0x00, 0x2A, 0x02, 0x00, 0x00, 0x00, 0x04,
8267 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00
8268 };
8269
8270 KMIP ctx = {0};
8271 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_2_0);
8272
8273 LinkedList attribute_list = {0};
8274
8275 LinkedListItem item_1 = {0};
8276 Attribute attr_1 = {0};
8277 kmip_init_attribute(&attr_1);
8278 enum cryptographic_algorithm algorithm = KMIP_CRYPTOALG_AES;
8279 attr_1.type = KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM;
8280 attr_1.value = &algorithm;
8281 item_1.data = &attr_1;
8282
8283 LinkedListItem item_2 = {0};
8284 Attribute attr_2 = {0};
8285 kmip_init_attribute(&attr_2);
8286 int32 length = 128;
8287 attr_2.type = KMIP_ATTR_CRYPTOGRAPHIC_LENGTH;
8288 attr_2.value = &length;
8289 item_2.data = &attr_2;
8290
8291 kmip_linked_list_enqueue(&attribute_list, &item_1);
8292 kmip_linked_list_enqueue(&attribute_list, &item_2);
8293
8294 Attributes expected = {0};
8295 expected.attribute_list = &attribute_list;
8296
8297 Attributes observed = {0};
8298 int result = kmip_decode_attributes(&ctx, &observed);
8299 int comparison = kmip_compare_attributes(&expected, &observed);
8300 if(!comparison)
8301 {
8302 kmip_print_attributes(1, &expected);
8303 kmip_print_attributes(1, &observed);
8304 }
8305 result = report_decoding_test_result(tracker, &ctx, comparison, result, __func__);
8306
8307 kmip_free_attributes(&ctx, &observed);
8308 kmip_destroy(&ctx);
8309
8310 return(result);
8311 }
8312
8313 int
8314 test_decode_attributes_with_invalid_kmip_version(TestTracker *tracker)
8315 {
8316 TRACK_TEST(tracker);
8317
8318 uint8 encoding[] = {0};
8319
8320 KMIP ctx = {0};
8321 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_4);
8322
8323 Attributes observed = {0};
8324 int result = kmip_decode_attributes(&ctx, &observed);
8325
8326 kmip_free_attributes(&ctx, &observed);
8327 kmip_destroy(&ctx);
8328
8329 result = report_result(tracker, result, KMIP_INVALID_FOR_VERSION, __func__);
8330 return(result);
8331 }
8332
8333 int
8334 test_decode_attribute_v2_unique_identifier(TestTracker *tracker)
8335 {
8336 TRACK_TEST(tracker);
8337
8338 /* This encoding matches the following value:
8339 * Unique Identifier - fb4b5b9c-6188-4c63-8142-fe9c328129fc
8340 */
8341 uint8 encoding[48] = {
8342 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
8343 0x66, 0x62, 0x34, 0x62, 0x35, 0x62, 0x39, 0x63,
8344 0x2D, 0x36, 0x31, 0x38, 0x38, 0x2D, 0x34, 0x63,
8345 0x36, 0x33, 0x2D, 0x38, 0x31, 0x34, 0x32, 0x2D,
8346 0x66, 0x65, 0x39, 0x63, 0x33, 0x32, 0x38, 0x31,
8347 0x32, 0x39, 0x66, 0x63, 0x00, 0x00, 0x00, 0x00
8348 };
8349
8350 KMIP ctx = {0};
8351 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_2_0);
8352
8353 Attribute expected = {0};
8354 kmip_init_attribute(&expected);
8355 TextString unique_identifier = {0};
8356 unique_identifier.value = "fb4b5b9c-6188-4c63-8142-fe9c328129fc";
8357 unique_identifier.size = 36;
8358 expected.type = KMIP_ATTR_UNIQUE_IDENTIFIER;
8359 expected.value = &unique_identifier;
8360
8361 Attribute observed = {0};
8362 int result = kmip_decode_attribute_v2(&ctx, &observed);
8363 int comparison = kmip_compare_attribute(&expected, &observed);
8364 if(!comparison)
8365 {
8366 kmip_print_attribute(1, &expected);
8367 kmip_print_attribute(1, &observed);
8368 }
8369 result = report_decoding_test_result(tracker, &ctx, comparison, result, __func__);
8370
8371 kmip_free_attribute(&ctx, &observed);
8372 kmip_destroy(&ctx);
8373
8374 return(result);
8375 }
8376
8377 int
8378 test_decode_attribute_v2_name(TestTracker *tracker)
8379 {
8380 TRACK_TEST(tracker);
8381
8382 /* This encoding matches the following value:
8383 * Name
8384 * Value - Template1
8385 * Type - Uninterpreted Text String
8386 */
8387 uint8 encoding[48] = {
8388 0x42, 0x00, 0x53, 0x01, 0x00, 0x00, 0x00, 0x28,
8389 0x42, 0x00, 0x55, 0x07, 0x00, 0x00, 0x00, 0x09,
8390 0x54, 0x65, 0x6D, 0x70, 0x6C, 0x61, 0x74, 0x65,
8391 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8392 0x42, 0x00, 0x54, 0x05, 0x00, 0x00, 0x00, 0x04,
8393 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
8394 };
8395
8396 KMIP ctx = {0};
8397 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_2_0);
8398
8399 Attribute expected = {0};
8400 kmip_init_attribute(&expected);
8401 TextString name_value = {0};
8402 name_value.value = "Template1";
8403 name_value.size = 9;
8404 Name name = {0};
8405 name.value = &name_value;
8406 name.type = KMIP_NAME_UNINTERPRETED_TEXT_STRING;
8407
8408 expected.type = KMIP_ATTR_NAME;
8409 expected.value = &name;
8410
8411 Attribute observed = {0};
8412 int result = kmip_decode_attribute_v2(&ctx, &observed);
8413 int comparison = kmip_compare_attribute(&expected, &observed);
8414 if(!comparison)
8415 {
8416 kmip_print_attribute(1, &expected);
8417 kmip_print_attribute(1, &observed);
8418 }
8419 result = report_decoding_test_result(tracker, &ctx, comparison, result, __func__);
8420
8421 kmip_free_attribute(&ctx, &observed);
8422 kmip_destroy(&ctx);
8423
8424 return(result);
8425 }
8426
8427 int
8428 test_decode_attribute_v2_object_type(TestTracker *tracker)
8429 {
8430 TRACK_TEST(tracker);
8431
8432 /* This encoding matches the following value:
8433 * Object Type - Symmetric Key
8434 */
8435 uint8 encoding[16] = {
8436 0x42, 0x00, 0x57, 0x05, 0x00, 0x00, 0x00, 0x04,
8437 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00
8438 };
8439
8440 KMIP ctx = {0};
8441 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_2_0);
8442
8443 Attribute expected = {0};
8444 kmip_init_attribute(&expected);
8445 enum object_type object_type = KMIP_OBJTYPE_SYMMETRIC_KEY;
8446 expected.type = KMIP_ATTR_OBJECT_TYPE;
8447 expected.value = &object_type;
8448
8449 Attribute observed = {0};
8450 int result = kmip_decode_attribute_v2(&ctx, &observed);
8451 int comparison = kmip_compare_attribute(&expected, &observed);
8452 if(!comparison)
8453 {
8454 kmip_print_attribute(1, &expected);
8455 kmip_print_attribute(1, &observed);
8456 }
8457 result = report_decoding_test_result(tracker, &ctx, comparison, result, __func__);
8458
8459 kmip_free_attribute(&ctx, &observed);
8460 kmip_destroy(&ctx);
8461
8462 return(result);
8463 }
8464
8465 int
8466 test_decode_attribute_v2_cryptographic_algorithm(TestTracker *tracker)
8467 {
8468 TRACK_TEST(tracker);
8469
8470 /* This encoding matches the following value:
8471 * Cryptographic Algorithm - AES
8472 */
8473 uint8 encoding[16] = {
8474 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
8475 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00
8476 };
8477
8478 KMIP ctx = {0};
8479 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_2_0);
8480
8481 Attribute expected = {0};
8482 kmip_init_attribute(&expected);
8483 enum cryptographic_algorithm algorithm = KMIP_CRYPTOALG_AES;
8484 expected.type = KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM;
8485 expected.value = &algorithm;
8486
8487 Attribute observed = {0};
8488 int result = kmip_decode_attribute_v2(&ctx, &observed);
8489 int comparison = kmip_compare_attribute(&expected, &observed);
8490 if(!comparison)
8491 {
8492 kmip_print_attribute(1, &expected);
8493 kmip_print_attribute(1, &observed);
8494 }
8495 result = report_decoding_test_result(tracker, &ctx, comparison, result, __func__);
8496
8497 kmip_free_attribute(&ctx, &observed);
8498 kmip_destroy(&ctx);
8499
8500 return(result);
8501 }
8502
8503 int
8504 test_decode_attribute_v2_cryptographic_length(TestTracker *tracker)
8505 {
8506 TRACK_TEST(tracker);
8507
8508 /* This encoding matches the following value:
8509 * Cryptographic Length - 128
8510 */
8511 uint8 encoding[16] = {
8512 0x42, 0x00, 0x2A, 0x02, 0x00, 0x00, 0x00, 0x04,
8513 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00
8514 };
8515
8516 KMIP ctx = {0};
8517 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_2_0);
8518
8519 Attribute expected = {0};
8520 kmip_init_attribute(&expected);
8521 int32 length = 128;
8522 expected.type = KMIP_ATTR_CRYPTOGRAPHIC_LENGTH;
8523 expected.value = &length;
8524
8525 Attribute observed = {0};
8526 int result = kmip_decode_attribute_v2(&ctx, &observed);
8527 int comparison = kmip_compare_attribute(&expected, &observed);
8528 if(!comparison)
8529 {
8530 kmip_print_attribute(1, &expected);
8531 kmip_print_attribute(1, &observed);
8532 }
8533 result = report_decoding_test_result(tracker, &ctx, comparison, result, __func__);
8534
8535 kmip_free_attribute(&ctx, &observed);
8536 kmip_destroy(&ctx);
8537
8538 return(result);
8539 }
8540
8541 int
8542 test_decode_attribute_v2_cryptographic_usage_mask(TestTracker *tracker)
8543 {
8544 TRACK_TEST(tracker);
8545
8546 /* This encoding matches the following value:
8547 * Cryptographic Usage Mask - Encrypt | Decrypt
8548 */
8549 uint8 encoding[16] = {
8550 0x42, 0x00, 0x2C, 0x02, 0x00, 0x00, 0x00, 0x04,
8551 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00
8552 };
8553
8554 KMIP ctx = {0};
8555 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_2_0);
8556
8557 Attribute expected = {0};
8558 kmip_init_attribute(&expected);
8559 int32 mask = KMIP_CRYPTOMASK_ENCRYPT | KMIP_CRYPTOMASK_DECRYPT;
8560 expected.type = KMIP_ATTR_CRYPTOGRAPHIC_USAGE_MASK;
8561 expected.value = &mask;
8562
8563 Attribute observed = {0};
8564 int result = kmip_decode_attribute_v2(&ctx, &observed);
8565 int comparison = kmip_compare_attribute(&expected, &observed);
8566 if(!comparison)
8567 {
8568 kmip_print_attribute(1, &expected);
8569 kmip_print_attribute(1, &observed);
8570 }
8571 result = report_decoding_test_result(tracker, &ctx, comparison, result, __func__);
8572
8573 kmip_free_attribute(&ctx, &observed);
8574 kmip_destroy(&ctx);
8575
8576 return(result);
8577 }
8578
8579 int
8580 test_decode_attribute_v2_state(TestTracker *tracker)
8581 {
8582 TRACK_TEST(tracker);
8583
8584 /* This encoding matches the following value:
8585 * State - Active
8586 */
8587 uint8 encoding[16] = {
8588 0x42, 0x00, 0x8D, 0x05, 0x00, 0x00, 0x00, 0x04,
8589 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00
8590 };
8591
8592 KMIP ctx = {0};
8593 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_2_0);
8594
8595 Attribute expected = {0};
8596 kmip_init_attribute(&expected);
8597 enum state state = KMIP_STATE_ACTIVE;
8598 expected.type = KMIP_ATTR_STATE;
8599 expected.value = &state;
8600
8601 Attribute observed = {0};
8602 int result = kmip_decode_attribute_v2(&ctx, &observed);
8603 int comparison = kmip_compare_attribute(&expected, &observed);
8604 if(!comparison)
8605 {
8606 kmip_print_attribute(1, &expected);
8607 kmip_print_attribute(1, &observed);
8608 }
8609 result = report_decoding_test_result(tracker, &ctx, comparison, result, __func__);
8610
8611 kmip_free_attribute(&ctx, &observed);
8612 kmip_destroy(&ctx);
8613
8614 return(result);
8615 }
8616
8617 int
8618 test_decode_attribute_v2_unsupported_attribute(TestTracker *tracker)
8619 {
8620 TRACK_TEST(tracker);
8621
8622 uint8 encoding[3] = {0x42, 0x00, 0x00};
8623
8624 KMIP ctx = {0};
8625 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_2_0);
8626
8627 Attribute observed = {0};
8628 int result = kmip_decode_attribute_v2(&ctx, &observed);
8629 if(result != KMIP_ERROR_ATTR_UNSUPPORTED)
8630 {
8631 TEST_FAILED(tracker, __func__, __LINE__);
8632 }
8633
8634 kmip_free_attribute(&ctx, &observed);
8635 kmip_destroy(&ctx);
8636
8637 TEST_PASSED(tracker, __func__);
8638 }
8639
8640 int
8641 test_encode_template_attribute(TestTracker *tracker)
8642 {
8643 TRACK_TEST(tracker);
8644
8645 uint8 expected[288] = {
8646 0x42, 0x00, 0x91, 0x01, 0x00, 0x00, 0x01, 0x18,
8647 0x42, 0x00, 0x53, 0x01, 0x00, 0x00, 0x00, 0x28,
8648 0x42, 0x00, 0x55, 0x07, 0x00, 0x00, 0x00, 0x09,
8649 0x54, 0x65, 0x6D, 0x70, 0x6C, 0x61, 0x74, 0x65,
8650 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8651 0x42, 0x00, 0x54, 0x05, 0x00, 0x00, 0x00, 0x04,
8652 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
8653 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
8654 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x17,
8655 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
8656 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x41, 0x6C,
8657 0x67, 0x6F, 0x72, 0x69, 0x74, 0x68, 0x6D, 0x00,
8658 0x42, 0x00, 0x0B, 0x05, 0x00, 0x00, 0x00, 0x04,
8659 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
8660 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
8661 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x14,
8662 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
8663 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x4C, 0x65,
8664 0x6E, 0x67, 0x74, 0x68, 0x00, 0x00, 0x00, 0x00,
8665 0x42, 0x00, 0x0B, 0x02, 0x00, 0x00, 0x00, 0x04,
8666 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
8667 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
8668 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x18,
8669 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
8670 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x55, 0x73,
8671 0x61, 0x67, 0x65, 0x20, 0x4D, 0x61, 0x73, 0x6B,
8672 0x42, 0x00, 0x0B, 0x02, 0x00, 0x00, 0x00, 0x04,
8673 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00,
8674 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x38,
8675 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x04,
8676 0x4E, 0x61, 0x6D, 0x65, 0x00, 0x00, 0x00, 0x00,
8677 0x42, 0x00, 0x0B, 0x01, 0x00, 0x00, 0x00, 0x20,
8678 0x42, 0x00, 0x55, 0x07, 0x00, 0x00, 0x00, 0x04,
8679 0x4B, 0x65, 0x79, 0x31, 0x00, 0x00, 0x00, 0x00,
8680 0x42, 0x00, 0x54, 0x05, 0x00, 0x00, 0x00, 0x04,
8681 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
8682 };
8683
8684 uint8 observed[288] = {0};
8685 struct kmip ctx = {0};
8686 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
8687
8688 struct text_string v = {0};
8689 v.value = "Template1";
8690 v.size = 9;
8691
8692 struct name n = {0};
8693 n.value = &v;
8694 n.type = KMIP_NAME_UNINTERPRETED_TEXT_STRING;
8695
8696 struct attribute a[4] = {0};
8697 for(int i = 0; i < 4; i++)
8698 {
8699 kmip_init_attribute(&a[i]);
8700 }
8701
8702 enum cryptographic_algorithm algorithm = KMIP_CRYPTOALG_AES;
8703 a[0].type = KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM;
8704 a[0].value = &algorithm;
8705
8706 int32 length = 128;
8707 a[1].type = KMIP_ATTR_CRYPTOGRAPHIC_LENGTH;
8708 a[1].value = &length;
8709
8710 int32 mask = KMIP_CRYPTOMASK_ENCRYPT | KMIP_CRYPTOMASK_DECRYPT;
8711 a[2].type = KMIP_ATTR_CRYPTOGRAPHIC_USAGE_MASK;
8712 a[2].value = &mask;
8713
8714 struct text_string value = {0};
8715 value.value = "Key1";
8716 value.size = 4;
8717
8718 struct name name = {0};
8719 name.value = &value;
8720 name.type = KMIP_NAME_UNINTERPRETED_TEXT_STRING;
8721 a[3].type = KMIP_ATTR_NAME;
8722 a[3].value = &name;
8723
8724 struct template_attribute ta = {0};
8725 ta.names = &n;
8726 ta.name_count = 1;
8727 ta.attributes = a;
8728 ta.attribute_count = ARRAY_LENGTH(a);
8729
8730 int result = kmip_encode_template_attribute(&ctx, &ta);
8731 result = report_encoding_test_result(
8732 tracker,
8733 &ctx,
8734 expected,
8735 observed,
8736 result,
8737 __func__);
8738 kmip_destroy(&ctx);
8739 return(result);
8740 }
8741
8742 int
8743 test_decode_template_attribute(TestTracker *tracker)
8744 {
8745 TRACK_TEST(tracker);
8746
8747 uint8 encoding[288] = {
8748 0x42, 0x00, 0x91, 0x01, 0x00, 0x00, 0x01, 0x18,
8749 0x42, 0x00, 0x53, 0x01, 0x00, 0x00, 0x00, 0x28,
8750 0x42, 0x00, 0x55, 0x07, 0x00, 0x00, 0x00, 0x09,
8751 0x54, 0x65, 0x6D, 0x70, 0x6C, 0x61, 0x74, 0x65,
8752 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8753 0x42, 0x00, 0x54, 0x05, 0x00, 0x00, 0x00, 0x04,
8754 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
8755 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
8756 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x17,
8757 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
8758 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x41, 0x6C,
8759 0x67, 0x6F, 0x72, 0x69, 0x74, 0x68, 0x6D, 0x00,
8760 0x42, 0x00, 0x0B, 0x05, 0x00, 0x00, 0x00, 0x04,
8761 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
8762 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
8763 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x14,
8764 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
8765 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x4C, 0x65,
8766 0x6E, 0x67, 0x74, 0x68, 0x00, 0x00, 0x00, 0x00,
8767 0x42, 0x00, 0x0B, 0x02, 0x00, 0x00, 0x00, 0x04,
8768 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
8769 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
8770 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x18,
8771 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
8772 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x55, 0x73,
8773 0x61, 0x67, 0x65, 0x20, 0x4D, 0x61, 0x73, 0x6B,
8774 0x42, 0x00, 0x0B, 0x02, 0x00, 0x00, 0x00, 0x04,
8775 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00,
8776 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x38,
8777 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x04,
8778 0x4E, 0x61, 0x6D, 0x65, 0x00, 0x00, 0x00, 0x00,
8779 0x42, 0x00, 0x0B, 0x01, 0x00, 0x00, 0x00, 0x20,
8780 0x42, 0x00, 0x55, 0x07, 0x00, 0x00, 0x00, 0x04,
8781 0x4B, 0x65, 0x79, 0x31, 0x00, 0x00, 0x00, 0x00,
8782 0x42, 0x00, 0x54, 0x05, 0x00, 0x00, 0x00, 0x04,
8783 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
8784 };
8785
8786 struct kmip ctx = {0};
8787 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_0);
8788
8789 struct text_string v = {0};
8790 v.value = "Template1";
8791 v.size = 9;
8792
8793 struct name n = {0};
8794 n.value = &v;
8795 n.type = KMIP_NAME_UNINTERPRETED_TEXT_STRING;
8796
8797 struct attribute a[4] = {0};
8798 for(int i = 0; i < 4; i++)
8799 {
8800 kmip_init_attribute(&a[i]);
8801 }
8802
8803 enum cryptographic_algorithm algorithm = KMIP_CRYPTOALG_AES;
8804 a[0].type = KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM;
8805 a[0].value = &algorithm;
8806
8807 int32 length = 128;
8808 a[1].type = KMIP_ATTR_CRYPTOGRAPHIC_LENGTH;
8809 a[1].value = &length;
8810
8811 int32 mask = KMIP_CRYPTOMASK_ENCRYPT | KMIP_CRYPTOMASK_DECRYPT;
8812 a[2].type = KMIP_ATTR_CRYPTOGRAPHIC_USAGE_MASK;
8813 a[2].value = &mask;
8814
8815 struct text_string value = {0};
8816 value.value = "Key1";
8817 value.size = 4;
8818
8819 struct name name = {0};
8820 name.value = &value;
8821 name.type = KMIP_NAME_UNINTERPRETED_TEXT_STRING;
8822 a[3].type = KMIP_ATTR_NAME;
8823 a[3].value = &name;
8824
8825 struct template_attribute expected = {0};
8826 expected.names = &n;
8827 expected.name_count = 1;
8828 expected.attributes = a;
8829 expected.attribute_count = ARRAY_LENGTH(a);
8830 struct template_attribute observed = {0};
8831
8832 int result = kmip_decode_template_attribute(&ctx, &observed);
8833 result = report_decoding_test_result(
8834 tracker,
8835 &ctx,
8836 kmip_compare_template_attribute(&expected, &observed),
8837 result,
8838 __func__);
8839 kmip_free_template_attribute(&ctx, &observed);
8840 kmip_destroy(&ctx);
8841 return(result);
8842 }
8843
8844 /*
8845 The following tests cover features added in KMIP 1.1.
8846 */
8847
8848 int
8849 test_encode_device_credential(TestTracker *tracker)
8850 {
8851 TRACK_TEST(tracker);
8852
8853 uint8 expected[144] = {
8854 0x42, 0x00, 0x25, 0x01, 0x00, 0x00, 0x00, 0x88,
8855 0x42, 0x00, 0xB0, 0x07, 0x00, 0x00, 0x00, 0x0C,
8856 0x73, 0x65, 0x72, 0x4E, 0x75, 0x6D, 0x31, 0x32,
8857 0x33, 0x34, 0x35, 0x36, 0x00, 0x00, 0x00, 0x00,
8858 0x42, 0x00, 0xA1, 0x07, 0x00, 0x00, 0x00, 0x06,
8859 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x00, 0x00,
8860 0x42, 0x00, 0xA2, 0x07, 0x00, 0x00, 0x00, 0x09,
8861 0x64, 0x65, 0x76, 0x49, 0x44, 0x32, 0x32, 0x33,
8862 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8863 0x42, 0x00, 0xAB, 0x07, 0x00, 0x00, 0x00, 0x09,
8864 0x6E, 0x65, 0x74, 0x49, 0x44, 0x39, 0x30, 0x30,
8865 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8866 0x42, 0x00, 0xA9, 0x07, 0x00, 0x00, 0x00, 0x0A,
8867 0x6D, 0x61, 0x63, 0x68, 0x69, 0x6E, 0x65, 0x49,
8868 0x44, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8869 0x42, 0x00, 0xAA, 0x07, 0x00, 0x00, 0x00, 0x0A,
8870 0x6D, 0x65, 0x64, 0x69, 0x61, 0x49, 0x44, 0x33,
8871 0x31, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
8872 };
8873
8874 uint8 observed[144] = {0};
8875 struct kmip ctx = {0};
8876 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_1);
8877
8878 struct text_string dsn = {0};
8879 dsn.value = "serNum123456";
8880 dsn.size = 12;
8881
8882 struct text_string p = {0};
8883 p.value = "secret";
8884 p.size = 6;
8885
8886 struct text_string di = {0};
8887 di.value = "devID2233";
8888 di.size = 9;
8889
8890 struct text_string ni = {0};
8891 ni.value = "netID9000";
8892 ni.size = 9;
8893
8894 struct text_string mac = {0};
8895 mac.value = "machineID1";
8896 mac.size = 10;
8897
8898 struct text_string med = {0};
8899 med.value = "mediaID313";
8900 med.size = 10;
8901
8902 struct device_credential dc = {0};
8903 dc.device_serial_number = &dsn;
8904 dc.password = &p;
8905 dc.device_identifier = &di;
8906 dc.network_identifier = &ni;
8907 dc.machine_identifier = &mac;
8908 dc.media_identifier = &med;
8909
8910 int result = kmip_encode_device_credential(&ctx, &dc);
8911 result = report_encoding_test_result(
8912 tracker,
8913 &ctx,
8914 expected,
8915 observed,
8916 result,
8917 __func__);
8918 kmip_destroy(&ctx);
8919 return(result);
8920 }
8921
8922 int
8923 test_decode_device_credential(TestTracker *tracker)
8924 {
8925 TRACK_TEST(tracker);
8926
8927 uint8 encoding[144] = {
8928 0x42, 0x00, 0x25, 0x01, 0x00, 0x00, 0x00, 0x88,
8929 0x42, 0x00, 0xB0, 0x07, 0x00, 0x00, 0x00, 0x0C,
8930 0x73, 0x65, 0x72, 0x4E, 0x75, 0x6D, 0x31, 0x32,
8931 0x33, 0x34, 0x35, 0x36, 0x00, 0x00, 0x00, 0x00,
8932 0x42, 0x00, 0xA1, 0x07, 0x00, 0x00, 0x00, 0x06,
8933 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x00, 0x00,
8934 0x42, 0x00, 0xA2, 0x07, 0x00, 0x00, 0x00, 0x09,
8935 0x64, 0x65, 0x76, 0x49, 0x44, 0x32, 0x32, 0x33,
8936 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8937 0x42, 0x00, 0xAB, 0x07, 0x00, 0x00, 0x00, 0x09,
8938 0x6E, 0x65, 0x74, 0x49, 0x44, 0x39, 0x30, 0x30,
8939 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8940 0x42, 0x00, 0xA9, 0x07, 0x00, 0x00, 0x00, 0x0A,
8941 0x6D, 0x61, 0x63, 0x68, 0x69, 0x6E, 0x65, 0x49,
8942 0x44, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8943 0x42, 0x00, 0xAA, 0x07, 0x00, 0x00, 0x00, 0x0A,
8944 0x6D, 0x65, 0x64, 0x69, 0x61, 0x49, 0x44, 0x33,
8945 0x31, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
8946 };
8947
8948 struct kmip ctx = {0};
8949 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_1);
8950
8951 struct text_string dsn = {0};
8952 dsn.value = "serNum123456";
8953 dsn.size = 12;
8954
8955 struct text_string p = {0};
8956 p.value = "secret";
8957 p.size = 6;
8958
8959 struct text_string di = {0};
8960 di.value = "devID2233";
8961 di.size = 9;
8962
8963 struct text_string ni = {0};
8964 ni.value = "netID9000";
8965 ni.size = 9;
8966
8967 struct text_string mac = {0};
8968 mac.value = "machineID1";
8969 mac.size = 10;
8970
8971 struct text_string med = {0};
8972 med.value = "mediaID313";
8973 med.size = 10;
8974
8975 struct device_credential expected = {0};
8976 expected.device_serial_number = &dsn;
8977 expected.password = &p;
8978 expected.device_identifier = &di;
8979 expected.network_identifier = &ni;
8980 expected.machine_identifier = &mac;
8981 expected.media_identifier = &med;
8982
8983 struct device_credential observed = {0};
8984
8985 int result = kmip_decode_device_credential(&ctx, &observed);
8986 result = report_decoding_test_result(
8987 tracker,
8988 &ctx,
8989 kmip_compare_device_credential(&expected, &observed),
8990 result,
8991 __func__);
8992 kmip_free_device_credential(&ctx, &observed);
8993 kmip_destroy(&ctx);
8994 return(result);
8995 }
8996
8997 int
8998 test_encode_key_wrapping_data_with_encoding_option(TestTracker *tracker)
8999 {
9000 TRACK_TEST(tracker);
9001
9002 uint8 expected[120] = {
9003 0x42, 0x00, 0x46, 0x01, 0x00, 0x00, 0x00, 0x70,
9004 0x42, 0x00, 0x9E, 0x05, 0x00, 0x00, 0x00, 0x04,
9005 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
9006 0x42, 0x00, 0x36, 0x01, 0x00, 0x00, 0x00, 0x48,
9007 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
9008 0x31, 0x30, 0x30, 0x31, 0x38, 0x32, 0x64, 0x35,
9009 0x2D, 0x37, 0x32, 0x62, 0x38, 0x2D, 0x34, 0x37,
9010 0x61, 0x61, 0x2D, 0x38, 0x33, 0x38, 0x33, 0x2D,
9011 0x34, 0x64, 0x39, 0x37, 0x64, 0x35, 0x31, 0x32,
9012 0x65, 0x39, 0x38, 0x61, 0x00, 0x00, 0x00, 0x00,
9013 0x42, 0x00, 0x2B, 0x01, 0x00, 0x00, 0x00, 0x10,
9014 0x42, 0x00, 0x11, 0x05, 0x00, 0x00, 0x00, 0x04,
9015 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00,
9016 0x42, 0x00, 0xA3, 0x05, 0x00, 0x00, 0x00, 0x04,
9017 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
9018 };
9019
9020 uint8 observed[120] = {0};
9021 struct kmip ctx = {0};
9022 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_1);
9023
9024 struct text_string uuid = {0};
9025 uuid.value = "100182d5-72b8-47aa-8383-4d97d512e98a";
9026 uuid.size = 36;
9027
9028 struct cryptographic_parameters cp = {0};
9029 cp.block_cipher_mode = KMIP_BLOCK_NIST_KEY_WRAP;
9030
9031 struct encryption_key_information eki = {0};
9032 eki.unique_identifier = &uuid;
9033 eki.cryptographic_parameters = &cp;
9034
9035 struct key_wrapping_data kwd = {0};
9036 kwd.wrapping_method = KMIP_WRAP_ENCRYPT;
9037 kwd.encryption_key_info = &eki;
9038 kwd.encoding_option = KMIP_ENCODE_NO_ENCODING;
9039
9040 int result = kmip_encode_key_wrapping_data(&ctx, &kwd);
9041 result = report_encoding_test_result(
9042 tracker,
9043 &ctx,
9044 expected,
9045 observed,
9046 result,
9047 __func__);
9048 kmip_destroy(&ctx);
9049 return(result);
9050 }
9051
9052 int
9053 test_decode_key_wrapping_data_with_encoding_option(TestTracker *tracker)
9054 {
9055 TRACK_TEST(tracker);
9056
9057 uint8 encoding[120] = {
9058 0x42, 0x00, 0x46, 0x01, 0x00, 0x00, 0x00, 0x70,
9059 0x42, 0x00, 0x9E, 0x05, 0x00, 0x00, 0x00, 0x04,
9060 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
9061 0x42, 0x00, 0x36, 0x01, 0x00, 0x00, 0x00, 0x48,
9062 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
9063 0x31, 0x30, 0x30, 0x31, 0x38, 0x32, 0x64, 0x35,
9064 0x2D, 0x37, 0x32, 0x62, 0x38, 0x2D, 0x34, 0x37,
9065 0x61, 0x61, 0x2D, 0x38, 0x33, 0x38, 0x33, 0x2D,
9066 0x34, 0x64, 0x39, 0x37, 0x64, 0x35, 0x31, 0x32,
9067 0x65, 0x39, 0x38, 0x61, 0x00, 0x00, 0x00, 0x00,
9068 0x42, 0x00, 0x2B, 0x01, 0x00, 0x00, 0x00, 0x10,
9069 0x42, 0x00, 0x11, 0x05, 0x00, 0x00, 0x00, 0x04,
9070 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00,
9071 0x42, 0x00, 0xA3, 0x05, 0x00, 0x00, 0x00, 0x04,
9072 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
9073 };
9074
9075 struct kmip ctx = {0};
9076 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_1);
9077
9078 struct text_string uuid = {0};
9079 uuid.value = "100182d5-72b8-47aa-8383-4d97d512e98a";
9080 uuid.size = 36;
9081
9082 struct cryptographic_parameters cp = {0};
9083 kmip_init_cryptographic_parameters(&cp);
9084 cp.block_cipher_mode = KMIP_BLOCK_NIST_KEY_WRAP;
9085
9086 struct encryption_key_information eki = {0};
9087 eki.unique_identifier = &uuid;
9088 eki.cryptographic_parameters = &cp;
9089
9090 struct key_wrapping_data expected = {0};
9091 expected.wrapping_method = KMIP_WRAP_ENCRYPT;
9092 expected.encryption_key_info = &eki;
9093 expected.encoding_option = KMIP_ENCODE_NO_ENCODING;
9094
9095 struct key_wrapping_data observed = {0};
9096
9097 int result = kmip_decode_key_wrapping_data(&ctx, &observed);
9098 result = report_decoding_test_result(
9099 tracker,
9100 &ctx,
9101 kmip_compare_key_wrapping_data(&expected, &observed),
9102 result,
9103 __func__);
9104 kmip_free_key_wrapping_data(&ctx, &observed);
9105 kmip_destroy(&ctx);
9106 return(result);
9107 }
9108
9109 int
9110 test_encode_key_wrapping_specification_with_encoding_option(TestTracker *tracker)
9111 {
9112 TRACK_TEST(tracker);
9113
9114 uint8 expected[120] = {
9115 0x42, 0x00, 0x47, 0x01, 0x00, 0x00, 0x00, 0x70,
9116 0x42, 0x00, 0x9E, 0x05, 0x00, 0x00, 0x00, 0x04,
9117 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
9118 0x42, 0x00, 0x36, 0x01, 0x00, 0x00, 0x00, 0x48,
9119 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
9120 0x31, 0x30, 0x30, 0x31, 0x38, 0x32, 0x64, 0x35,
9121 0x2D, 0x37, 0x32, 0x62, 0x38, 0x2D, 0x34, 0x37,
9122 0x61, 0x61, 0x2D, 0x38, 0x33, 0x38, 0x33, 0x2D,
9123 0x34, 0x64, 0x39, 0x37, 0x64, 0x35, 0x31, 0x32,
9124 0x65, 0x39, 0x38, 0x61, 0x00, 0x00, 0x00, 0x00,
9125 0x42, 0x00, 0x2B, 0x01, 0x00, 0x00, 0x00, 0x10,
9126 0x42, 0x00, 0x11, 0x05, 0x00, 0x00, 0x00, 0x04,
9127 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00,
9128 0x42, 0x00, 0xA3, 0x05, 0x00, 0x00, 0x00, 0x04,
9129 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
9130 };
9131
9132 uint8 observed[120] = {0};
9133 struct kmip ctx = {0};
9134 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_1);
9135
9136 struct text_string uuid = {0};
9137 uuid.value = "100182d5-72b8-47aa-8383-4d97d512e98a";
9138 uuid.size = 36;
9139
9140 struct cryptographic_parameters cp = {0};
9141 cp.block_cipher_mode = KMIP_BLOCK_NIST_KEY_WRAP;
9142
9143 struct encryption_key_information eki = {0};
9144 eki.unique_identifier = &uuid;
9145 eki.cryptographic_parameters = &cp;
9146
9147 struct key_wrapping_specification kws = {0};
9148 kws.wrapping_method = KMIP_WRAP_ENCRYPT;
9149 kws.encryption_key_info = &eki;
9150 kws.encoding_option = KMIP_ENCODE_NO_ENCODING;
9151
9152 int result = kmip_encode_key_wrapping_specification(&ctx, &kws);
9153 result = report_encoding_test_result(
9154 tracker,
9155 &ctx,
9156 expected,
9157 observed,
9158 result,
9159 __func__);
9160 kmip_destroy(&ctx);
9161 return(result);
9162 }
9163
9164 /*
9165 The following tests cover features added in KMIP 1.2.
9166 */
9167
9168 int
9169 test_encode_nonce(TestTracker *tracker)
9170 {
9171 TRACK_TEST(tracker);
9172
9173 uint8 expected[40] = {
9174 0x42, 0x00, 0xC8, 0x01, 0x00, 0x00, 0x00, 0x20,
9175 0x42, 0x00, 0xC9, 0x08, 0x00, 0x00, 0x00, 0x04,
9176 0x01, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00,
9177 0x42, 0x00, 0xCA, 0x08, 0x00, 0x00, 0x00, 0x06,
9178 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00
9179 };
9180
9181 uint8 observed[40] = {0};
9182 struct kmip ctx = {0};
9183 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_2);
9184
9185 uint8 id[4] = {0x01, 0x02, 0x03, 0x04};
9186 struct byte_string ni = {0};
9187 ni.value = id;
9188 ni.size = ARRAY_LENGTH(id);
9189
9190 uint8 value[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
9191 struct byte_string nv = {0};
9192 nv.value = value;
9193 nv.size = ARRAY_LENGTH(value);
9194
9195 struct nonce n = {0};
9196 n.nonce_id = &ni;
9197 n.nonce_value = &nv;
9198
9199 int result = kmip_encode_nonce(&ctx, &n);
9200 result = report_encoding_test_result(
9201 tracker,
9202 &ctx,
9203 expected,
9204 observed,
9205 result,
9206 __func__);
9207 kmip_destroy(&ctx);
9208 return(result);
9209 }
9210
9211 int
9212 test_decode_nonce(TestTracker *tracker)
9213 {
9214 TRACK_TEST(tracker);
9215
9216 uint8 encoding[40] = {
9217 0x42, 0x00, 0xC8, 0x01, 0x00, 0x00, 0x00, 0x20,
9218 0x42, 0x00, 0xC9, 0x08, 0x00, 0x00, 0x00, 0x04,
9219 0x01, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00,
9220 0x42, 0x00, 0xCA, 0x08, 0x00, 0x00, 0x00, 0x06,
9221 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00
9222 };
9223
9224 struct kmip ctx = {0};
9225 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_2);
9226
9227 uint8 id[4] = {0x01, 0x02, 0x03, 0x04};
9228 struct byte_string ni = {0};
9229 ni.value = id;
9230 ni.size = ARRAY_LENGTH(id);
9231
9232 uint8 value[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
9233 struct byte_string nv = {0};
9234 nv.value = value;
9235 nv.size = ARRAY_LENGTH(value);
9236
9237 struct nonce expected = {0};
9238 expected.nonce_id = &ni;
9239 expected.nonce_value = &nv;
9240
9241 struct nonce observed = {0};
9242
9243 int result = kmip_decode_nonce(&ctx, &observed);
9244 result = report_decoding_test_result(
9245 tracker,
9246 &ctx,
9247 kmip_compare_nonce(&expected, &observed),
9248 result,
9249 __func__);
9250 kmip_free_nonce(&ctx, &observed);
9251 kmip_destroy(&ctx);
9252 return(result);
9253 }
9254
9255 int
9256 test_encode_attestation_credential(TestTracker *tracker)
9257 {
9258 TRACK_TEST(tracker);
9259
9260 uint8 expected[128] = {
9261 0x42, 0x00, 0x25, 0x01, 0x00, 0x00, 0x00, 0x70,
9262 0x42, 0x00, 0xC8, 0x01, 0x00, 0x00, 0x00, 0x20,
9263 0x42, 0x00, 0xC9, 0x08, 0x00, 0x00, 0x00, 0x04,
9264 0x01, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00,
9265 0x42, 0x00, 0xCA, 0x08, 0x00, 0x00, 0x00, 0x06,
9266 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00,
9267 0x42, 0x00, 0xC7, 0x05, 0x00, 0x00, 0x00, 0x04,
9268 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
9269 0x42, 0x00, 0xCB, 0x08, 0x00, 0x00, 0x00, 0x10,
9270 0x22, 0x22, 0x22, 0x22, 0x44, 0x44, 0x44, 0x44,
9271 0x66, 0x66, 0x66, 0x66, 0x88, 0x88, 0x88, 0x88,
9272 0x42, 0x00, 0xCC, 0x08, 0x00, 0x00, 0x00, 0x14,
9273 0x11, 0x11, 0x11, 0x11, 0x33, 0x33, 0x33, 0x33,
9274 0x55, 0x55, 0x55, 0x55, 0x77, 0x77, 0x77, 0x77,
9275 0x99, 0x99, 0x99, 0x99, 0x00, 0x00, 0x00, 0x00
9276 };
9277
9278 uint8 observed[128] = {0};
9279 struct kmip ctx = {0};
9280 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_2);
9281
9282 uint8 nonce_id[4] = {0x01, 0x02, 0x03, 0x04};
9283 struct byte_string ni = {0};
9284 ni.value = nonce_id;
9285 ni.size = ARRAY_LENGTH(nonce_id);
9286
9287 uint8 nonce_value[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
9288 struct byte_string nv = {0};
9289 nv.value = nonce_value;
9290 nv.size = ARRAY_LENGTH(nonce_value);
9291
9292 struct nonce n = {0};
9293 n.nonce_id = &ni;
9294 n.nonce_value = &nv;
9295
9296 uint8 measurement[16] = {
9297 0x22, 0x22, 0x22, 0x22, 0x44, 0x44, 0x44, 0x44,
9298 0x66, 0x66, 0x66, 0x66, 0x88, 0x88, 0x88, 0x88
9299 };
9300 struct byte_string am = {0};
9301 am.value = measurement;
9302 am.size = ARRAY_LENGTH(measurement);
9303
9304 uint8 assertion[20] = {
9305 0x11, 0x11, 0x11, 0x11, 0x33, 0x33, 0x33, 0x33,
9306 0x55, 0x55, 0x55, 0x55, 0x77, 0x77, 0x77, 0x77,
9307 0x99, 0x99, 0x99, 0x99
9308 };
9309 struct byte_string aa = {0};
9310 aa.value = assertion;
9311 aa.size = ARRAY_LENGTH(assertion);
9312
9313 struct attestation_credential ac = {0};
9314 ac.nonce = &n;
9315 ac.attestation_type = KMIP_ATTEST_TPM_QUOTE;
9316 ac.attestation_measurement = &am;
9317 ac.attestation_assertion = &aa;
9318
9319 int result = kmip_encode_attestation_credential(&ctx, &ac);
9320 result = report_encoding_test_result(
9321 tracker,
9322 &ctx,
9323 expected,
9324 observed,
9325 result,
9326 __func__);
9327 kmip_destroy(&ctx);
9328 return(result);
9329 }
9330
9331 int
9332 test_decode_attestation_credential(TestTracker *tracker)
9333 {
9334 TRACK_TEST(tracker);
9335
9336 uint8 encoding[128] = {
9337 0x42, 0x00, 0x25, 0x01, 0x00, 0x00, 0x00, 0x70,
9338 0x42, 0x00, 0xC8, 0x01, 0x00, 0x00, 0x00, 0x20,
9339 0x42, 0x00, 0xC9, 0x08, 0x00, 0x00, 0x00, 0x04,
9340 0x01, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00,
9341 0x42, 0x00, 0xCA, 0x08, 0x00, 0x00, 0x00, 0x06,
9342 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00,
9343 0x42, 0x00, 0xC7, 0x05, 0x00, 0x00, 0x00, 0x04,
9344 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
9345 0x42, 0x00, 0xCB, 0x08, 0x00, 0x00, 0x00, 0x10,
9346 0x22, 0x22, 0x22, 0x22, 0x44, 0x44, 0x44, 0x44,
9347 0x66, 0x66, 0x66, 0x66, 0x88, 0x88, 0x88, 0x88,
9348 0x42, 0x00, 0xCC, 0x08, 0x00, 0x00, 0x00, 0x14,
9349 0x11, 0x11, 0x11, 0x11, 0x33, 0x33, 0x33, 0x33,
9350 0x55, 0x55, 0x55, 0x55, 0x77, 0x77, 0x77, 0x77,
9351 0x99, 0x99, 0x99, 0x99, 0x00, 0x00, 0x00, 0x00
9352 };
9353
9354 struct kmip ctx = {0};
9355 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_2);
9356
9357 uint8 nonce_id[4] = {0x01, 0x02, 0x03, 0x04};
9358 struct byte_string ni = {0};
9359 ni.value = nonce_id;
9360 ni.size = ARRAY_LENGTH(nonce_id);
9361
9362 uint8 nonce_value[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
9363 struct byte_string nv = {0};
9364 nv.value = nonce_value;
9365 nv.size = ARRAY_LENGTH(nonce_value);
9366
9367 struct nonce n = {0};
9368 n.nonce_id = &ni;
9369 n.nonce_value = &nv;
9370
9371 uint8 measurement[16] = {
9372 0x22, 0x22, 0x22, 0x22, 0x44, 0x44, 0x44, 0x44,
9373 0x66, 0x66, 0x66, 0x66, 0x88, 0x88, 0x88, 0x88
9374 };
9375 struct byte_string am = {0};
9376 am.value = measurement;
9377 am.size = ARRAY_LENGTH(measurement);
9378
9379 uint8 assertion[20] = {
9380 0x11, 0x11, 0x11, 0x11, 0x33, 0x33, 0x33, 0x33,
9381 0x55, 0x55, 0x55, 0x55, 0x77, 0x77, 0x77, 0x77,
9382 0x99, 0x99, 0x99, 0x99
9383 };
9384 struct byte_string aa = {0};
9385 aa.value = assertion;
9386 aa.size = ARRAY_LENGTH(assertion);
9387
9388 struct attestation_credential expected = {0};
9389 expected.nonce = &n;
9390 expected.attestation_type = KMIP_ATTEST_TPM_QUOTE;
9391 expected.attestation_measurement = &am;
9392 expected.attestation_assertion = &aa;
9393
9394 struct attestation_credential observed = {0};
9395
9396 int result = kmip_decode_attestation_credential(&ctx, &observed);
9397 result = report_decoding_test_result(
9398 tracker,
9399 &ctx,
9400 kmip_compare_attestation_credential(&expected, &observed),
9401 result,
9402 __func__);
9403 kmip_free_attestation_credential(&ctx, &observed);
9404 kmip_destroy(&ctx);
9405 return(result);
9406 }
9407
9408 int
9409 test_encode_request_header_with_attestation_details(TestTracker *tracker)
9410 {
9411 TRACK_TEST(tracker);
9412
9413 uint8 expected[216] = {
9414 0x42, 0x00, 0x77, 0x01, 0x00, 0x00, 0x00, 0xD0,
9415 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20,
9416 0x42, 0x00, 0x6A, 0x02, 0x00, 0x00, 0x00, 0x04,
9417 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
9418 0x42, 0x00, 0x6B, 0x02, 0x00, 0x00, 0x00, 0x04,
9419 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9420 0x42, 0x00, 0xD3, 0x06, 0x00, 0x00, 0x00, 0x08,
9421 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
9422 0x42, 0x00, 0xC7, 0x05, 0x00, 0x00, 0x00, 0x04,
9423 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
9424 0x42, 0x00, 0xC7, 0x05, 0x00, 0x00, 0x00, 0x04,
9425 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
9426 0x42, 0x00, 0x0C, 0x01, 0x00, 0x00, 0x00, 0x40,
9427 0x42, 0x00, 0x23, 0x01, 0x00, 0x00, 0x00, 0x38,
9428 0x42, 0x00, 0x24, 0x05, 0x00, 0x00, 0x00, 0x04,
9429 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
9430 0x42, 0x00, 0x25, 0x01, 0x00, 0x00, 0x00, 0x20,
9431 0x42, 0x00, 0x99, 0x07, 0x00, 0x00, 0x00, 0x06,
9432 0x42, 0x61, 0x72, 0x6E, 0x65, 0x79, 0x00, 0x00,
9433 0x42, 0x00, 0xA1, 0x07, 0x00, 0x00, 0x00, 0x07,
9434 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x32, 0x00,
9435 0x42, 0x00, 0x0E, 0x05, 0x00, 0x00, 0x00, 0x04,
9436 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
9437 0x42, 0x00, 0x10, 0x06, 0x00, 0x00, 0x00, 0x08,
9438 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
9439 0x42, 0x00, 0x0D, 0x02, 0x00, 0x00, 0x00, 0x04,
9440 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00
9441 };
9442
9443 uint8 observed[216] = {0};
9444 struct kmip ctx = {0};
9445 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_2);
9446
9447 struct protocol_version pv = {0};
9448 pv.major = 1;
9449 pv.minor = 0;
9450
9451 struct text_string username = {0};
9452 username.value = "Barney";
9453 username.size = 6;
9454 struct text_string password = {0};
9455 password.value = "secret2";
9456 password.size = 7;
9457
9458 struct username_password_credential upc = {0};
9459 upc.username = &username;
9460 upc.password = &password;
9461
9462 struct credential c = {0};
9463 c.credential_type = KMIP_CRED_USERNAME_AND_PASSWORD;
9464 c.credential_value = &upc;
9465
9466 struct authentication a = {0};
9467 a.credential = &c;
9468
9469 enum attestation_type types[2] = {
9470 KMIP_ATTEST_TPM_QUOTE,
9471 KMIP_ATTEST_SAML_ASSERTION
9472 };
9473
9474 struct request_header rh = {0};
9475 kmip_init_request_header(&rh);
9476
9477 rh.protocol_version = &pv;
9478 rh.attestation_capable_indicator = KMIP_TRUE;
9479 rh.attestation_types = types;
9480 rh.attestation_type_count = ARRAY_LENGTH(types);
9481 rh.authentication = &a;
9482 rh.batch_error_continuation_option = KMIP_BATCH_CONTINUE;
9483 rh.batch_order_option = KMIP_TRUE;
9484 rh.batch_count = 2;
9485
9486 int result = kmip_encode_request_header(&ctx, &rh);
9487 result = report_encoding_test_result(
9488 tracker,
9489 &ctx,
9490 expected,
9491 observed,
9492 result,
9493 __func__);
9494 kmip_destroy(&ctx);
9495 return(result);
9496 }
9497
9498 int
9499 test_encode_response_header_with_attestation_details(TestTracker *tracker)
9500 {
9501 TRACK_TEST(tracker);
9502
9503 uint8 expected[152] = {
9504 0x42, 0x00, 0x7A, 0x01, 0x00, 0x00, 0x00, 0x90,
9505 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20,
9506 0x42, 0x00, 0x6A, 0x02, 0x00, 0x00, 0x00, 0x04,
9507 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
9508 0x42, 0x00, 0x6B, 0x02, 0x00, 0x00, 0x00, 0x04,
9509 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9510 0x42, 0x00, 0x92, 0x09, 0x00, 0x00, 0x00, 0x08,
9511 0x00, 0x00, 0x00, 0x00, 0x4F, 0x9A, 0x54, 0xE5,
9512 0x42, 0x00, 0xC8, 0x01, 0x00, 0x00, 0x00, 0x20,
9513 0x42, 0x00, 0xC9, 0x08, 0x00, 0x00, 0x00, 0x04,
9514 0x01, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00,
9515 0x42, 0x00, 0xCA, 0x08, 0x00, 0x00, 0x00, 0x06,
9516 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00,
9517 0x42, 0x00, 0xC7, 0x05, 0x00, 0x00, 0x00, 0x04,
9518 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
9519 0x42, 0x00, 0xC7, 0x05, 0x00, 0x00, 0x00, 0x04,
9520 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
9521 0x42, 0x00, 0x0D, 0x02, 0x00, 0x00, 0x00, 0x04,
9522 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
9523 };
9524
9525 uint8 observed[152] = {0};
9526 struct kmip ctx = {0};
9527 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_2);
9528
9529 struct protocol_version pv = {0};
9530 pv.major = 1;
9531 pv.minor = 0;
9532
9533 uint8 id[4] = {0x01, 0x02, 0x03, 0x04};
9534 struct byte_string ni = {0};
9535 ni.value = id;
9536 ni.size = ARRAY_LENGTH(id);
9537
9538 uint8 value[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
9539 struct byte_string nv = {0};
9540 nv.value = value;
9541 nv.size = ARRAY_LENGTH(value);
9542
9543 struct nonce n = {0};
9544 n.nonce_id = &ni;
9545 n.nonce_value = &nv;
9546
9547 enum attestation_type types[2] = {
9548 KMIP_ATTEST_TPM_QUOTE,
9549 KMIP_ATTEST_SAML_ASSERTION
9550 };
9551
9552 struct response_header rh = {0};
9553 kmip_init_response_header(&rh);
9554
9555 rh.protocol_version = &pv;
9556 rh.time_stamp = 1335514341;
9557 rh.nonce = &n;
9558 rh.attestation_types = types;
9559 rh.attestation_type_count = ARRAY_LENGTH(types);
9560 rh.batch_count = 1;
9561
9562 int result = kmip_encode_response_header(&ctx, &rh);
9563 result = report_encoding_test_result(
9564 tracker,
9565 &ctx,
9566 expected,
9567 observed,
9568 result,
9569 __func__);
9570 kmip_destroy(&ctx);
9571 return(result);
9572 }
9573
9574 int
9575 test_decode_response_header_with_attestation_details(TestTracker *tracker)
9576 {
9577 TRACK_TEST(tracker);
9578
9579 uint8 encoding[152] = {
9580 0x42, 0x00, 0x7A, 0x01, 0x00, 0x00, 0x00, 0x90,
9581 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20,
9582 0x42, 0x00, 0x6A, 0x02, 0x00, 0x00, 0x00, 0x04,
9583 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
9584 0x42, 0x00, 0x6B, 0x02, 0x00, 0x00, 0x00, 0x04,
9585 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9586 0x42, 0x00, 0x92, 0x09, 0x00, 0x00, 0x00, 0x08,
9587 0x00, 0x00, 0x00, 0x00, 0x4F, 0x9A, 0x54, 0xE5,
9588 0x42, 0x00, 0xC8, 0x01, 0x00, 0x00, 0x00, 0x20,
9589 0x42, 0x00, 0xC9, 0x08, 0x00, 0x00, 0x00, 0x04,
9590 0x01, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00,
9591 0x42, 0x00, 0xCA, 0x08, 0x00, 0x00, 0x00, 0x06,
9592 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00,
9593 0x42, 0x00, 0xC7, 0x05, 0x00, 0x00, 0x00, 0x04,
9594 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
9595 0x42, 0x00, 0xC7, 0x05, 0x00, 0x00, 0x00, 0x04,
9596 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
9597 0x42, 0x00, 0x0D, 0x02, 0x00, 0x00, 0x00, 0x04,
9598 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
9599 };
9600
9601 struct kmip ctx = {0};
9602 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_2);
9603
9604 struct protocol_version pv = {0};
9605 pv.major = 1;
9606 pv.minor = 0;
9607
9608 uint8 id[4] = {0x01, 0x02, 0x03, 0x04};
9609 struct byte_string ni = {0};
9610 ni.value = id;
9611 ni.size = ARRAY_LENGTH(id);
9612
9613 uint8 value[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
9614 struct byte_string nv = {0};
9615 nv.value = value;
9616 nv.size = ARRAY_LENGTH(value);
9617
9618 struct nonce n = {0};
9619 n.nonce_id = &ni;
9620 n.nonce_value = &nv;
9621
9622 enum attestation_type types[2] = {
9623 KMIP_ATTEST_TPM_QUOTE,
9624 KMIP_ATTEST_SAML_ASSERTION
9625 };
9626
9627 struct response_header expected = {0};
9628 kmip_init_response_header(&expected);
9629
9630 expected.protocol_version = &pv;
9631 expected.time_stamp = 1335514341;
9632 expected.nonce = &n;
9633 expected.attestation_types = types;
9634 expected.attestation_type_count = ARRAY_LENGTH(types);
9635 expected.batch_count = 1;
9636
9637 struct response_header observed = {0};
9638 kmip_init_response_header(&observed);
9639
9640 int result = kmip_decode_response_header(&ctx, &observed);
9641 result = report_decoding_test_result(
9642 tracker,
9643 &ctx,
9644 kmip_compare_response_header(&expected, &observed),
9645 result,
9646 __func__);
9647 kmip_free_response_header(&ctx, &observed);
9648 kmip_destroy(&ctx);
9649 return(result);
9650 }
9651
9652 int
9653 test_encode_cryptographic_parameters_with_digital_signature_fields(TestTracker *tracker)
9654 {
9655 TRACK_TEST(tracker);
9656
9657 uint8 expected[216] = {
9658 0x42, 0x00, 0x2B, 0x01, 0x00, 0x00, 0x00, 0xD0,
9659 0x42, 0x00, 0x11, 0x05, 0x00, 0x00, 0x00, 0x04,
9660 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
9661 0x42, 0x00, 0x5F, 0x05, 0x00, 0x00, 0x00, 0x04,
9662 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
9663 0x42, 0x00, 0x38, 0x05, 0x00, 0x00, 0x00, 0x04,
9664 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
9665 0x42, 0x00, 0x83, 0x05, 0x00, 0x00, 0x00, 0x04,
9666 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x00,
9667 0x42, 0x00, 0xAE, 0x05, 0x00, 0x00, 0x00, 0x04,
9668 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00,
9669 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
9670 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
9671 0x42, 0x00, 0xC5, 0x06, 0x00, 0x00, 0x00, 0x08,
9672 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
9673 0x42, 0x00, 0xCD, 0x02, 0x00, 0x00, 0x00, 0x04,
9674 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
9675 0x42, 0x00, 0xCE, 0x02, 0x00, 0x00, 0x00, 0x04,
9676 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
9677 0x42, 0x00, 0xCF, 0x02, 0x00, 0x00, 0x00, 0x04,
9678 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
9679 0x42, 0x00, 0xD2, 0x02, 0x00, 0x00, 0x00, 0x04,
9680 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
9681 0x42, 0x00, 0xD0, 0x02, 0x00, 0x00, 0x00, 0x04,
9682 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
9683 0x42, 0x00, 0xD1, 0x02, 0x00, 0x00, 0x00, 0x04,
9684 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
9685 };
9686
9687 uint8 observed[216] = {0};
9688 struct kmip ctx = {0};
9689 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_2);
9690
9691 struct cryptographic_parameters cp = {0};
9692 cp.block_cipher_mode = KMIP_BLOCK_CBC;
9693 cp.padding_method = KMIP_PAD_PKCS5;
9694 cp.hashing_algorithm = KMIP_HASH_SHA1;
9695 cp.key_role_type = KMIP_ROLE_KEK;
9696
9697 cp.digital_signature_algorithm = KMIP_DIGITAL_SHA256_WITH_RSA;
9698 cp.cryptographic_algorithm = KMIP_CRYPTOALG_RSA;
9699 cp.random_iv = KMIP_TRUE;
9700 cp.iv_length = 128;
9701 cp.tag_length = 64;
9702 cp.fixed_field_length = 64;
9703 cp.invocation_field_length = 64;
9704 cp.counter_length = 256;
9705 cp.initial_counter_value = 0;
9706
9707 int result = kmip_encode_cryptographic_parameters(&ctx, &cp);
9708 result = report_encoding_test_result(
9709 tracker,
9710 &ctx,
9711 expected,
9712 observed,
9713 result,
9714 __func__);
9715 kmip_destroy(&ctx);
9716 return(result);
9717 }
9718
9719 int
9720 test_decode_cryptographic_parameters_with_digital_signature_fields(TestTracker *tracker)
9721 {
9722 TRACK_TEST(tracker);
9723
9724 uint8 encoding[216] = {
9725 0x42, 0x00, 0x2B, 0x01, 0x00, 0x00, 0x00, 0xD0,
9726 0x42, 0x00, 0x11, 0x05, 0x00, 0x00, 0x00, 0x04,
9727 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
9728 0x42, 0x00, 0x5F, 0x05, 0x00, 0x00, 0x00, 0x04,
9729 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
9730 0x42, 0x00, 0x38, 0x05, 0x00, 0x00, 0x00, 0x04,
9731 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
9732 0x42, 0x00, 0x83, 0x05, 0x00, 0x00, 0x00, 0x04,
9733 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x00,
9734 0x42, 0x00, 0xAE, 0x05, 0x00, 0x00, 0x00, 0x04,
9735 0x00, 0x00 ,0x00, 0x05, 0x00, 0x00, 0x00, 0x00,
9736 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
9737 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
9738 0x42, 0x00, 0xC5, 0x06, 0x00, 0x00, 0x00, 0x08,
9739 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
9740 0x42, 0x00, 0xCD, 0x02, 0x00, 0x00, 0x00, 0x04,
9741 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
9742 0x42, 0x00, 0xCE, 0x02, 0x00, 0x00, 0x00, 0x04,
9743 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
9744 0x42, 0x00, 0xCF, 0x02, 0x00, 0x00, 0x00, 0x04,
9745 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
9746 0x42, 0x00, 0xD2, 0x02, 0x00, 0x00, 0x00, 0x04,
9747 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
9748 0x42, 0x00, 0xD0, 0x02, 0x00, 0x00, 0x00, 0x04,
9749 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
9750 0x42, 0x00, 0xD1, 0x02, 0x00, 0x00, 0x00, 0x04,
9751 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
9752 };
9753
9754 struct kmip ctx = {0};
9755 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_2);
9756
9757 struct cryptographic_parameters expected = {0};
9758 kmip_init_cryptographic_parameters(&expected);
9759 expected.block_cipher_mode = KMIP_BLOCK_CBC;
9760 expected.padding_method = KMIP_PAD_PKCS5;
9761 expected.hashing_algorithm = KMIP_HASH_SHA1;
9762 expected.key_role_type = KMIP_ROLE_KEK;
9763
9764 expected.digital_signature_algorithm = KMIP_DIGITAL_SHA256_WITH_RSA;
9765 expected.cryptographic_algorithm = KMIP_CRYPTOALG_RSA;
9766 expected.random_iv = KMIP_TRUE;
9767 expected.iv_length = 128;
9768 expected.tag_length = 64;
9769 expected.fixed_field_length = 64;
9770 expected.invocation_field_length = 64;
9771 expected.counter_length = 256;
9772 expected.initial_counter_value = 0;
9773
9774 struct cryptographic_parameters observed = {0};
9775 kmip_init_cryptographic_parameters(&observed);
9776
9777 int result = kmip_decode_cryptographic_parameters(&ctx, &observed);
9778 result = report_decoding_test_result(
9779 tracker,
9780 &ctx,
9781 kmip_compare_cryptographic_parameters(&expected, &observed),
9782 result,
9783 __func__);
9784 kmip_free_cryptographic_parameters(&ctx, &observed);
9785 kmip_destroy(&ctx);
9786 return(result);
9787 }
9788
9789 /*
9790 The following tests cover features added in KMIP 1.4.
9791 */
9792
9793 int
9794 test_encode_cryptographic_parameters_with_mask_fields(TestTracker *tracker)
9795 {
9796 TRACK_TEST(tracker);
9797
9798 uint8 expected[312] = {
9799 0x42, 0x00, 0x2B, 0x01, 0x00, 0x00, 0x01, 0x30,
9800 0x42, 0x00, 0x11, 0x05, 0x00, 0x00, 0x00, 0x04,
9801 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
9802 0x42, 0x00, 0x5F, 0x05, 0x00, 0x00, 0x00, 0x04,
9803 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
9804 0x42, 0x00, 0x38, 0x05, 0x00, 0x00, 0x00, 0x04,
9805 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
9806 0x42, 0x00, 0x83, 0x05, 0x00, 0x00, 0x00, 0x04,
9807 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x00,
9808 0x42, 0x00, 0xAE, 0x05, 0x00, 0x00, 0x00, 0x04,
9809 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00,
9810 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
9811 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
9812 0x42, 0x00, 0xC5, 0x06, 0x00, 0x00, 0x00, 0x08,
9813 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
9814 0x42, 0x00, 0xCD, 0x02, 0x00, 0x00, 0x00, 0x04,
9815 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
9816 0x42, 0x00, 0xCE, 0x02, 0x00, 0x00, 0x00, 0x04,
9817 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
9818 0x42, 0x00, 0xCF, 0x02, 0x00, 0x00, 0x00, 0x04,
9819 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
9820 0x42, 0x00, 0xD2, 0x02, 0x00, 0x00, 0x00, 0x04,
9821 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
9822 0x42, 0x00, 0xD0, 0x02, 0x00, 0x00, 0x00, 0x04,
9823 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
9824 0x42, 0x00, 0xD1, 0x02, 0x00, 0x00, 0x00, 0x04,
9825 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9826 0x42, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04,
9827 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00,
9828 0x42, 0x01, 0x01, 0x05, 0x00, 0x00, 0x00, 0x04,
9829 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
9830 0x42, 0x01, 0x02, 0x05, 0x00, 0x00, 0x00, 0x04,
9831 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
9832 0x42, 0x01, 0x03, 0x08, 0x00, 0x00, 0x00, 0x18,
9833 0x73, 0x67, 0x57, 0x80, 0x51, 0x01, 0x2A, 0x6D,
9834 0x13, 0x4A, 0x85, 0x5E, 0x25, 0xC8, 0xCD, 0x5E,
9835 0x4C, 0xA1, 0x31, 0x45, 0x57, 0x29, 0xD3, 0xC8,
9836 0x42, 0x01, 0x04, 0x02, 0x00, 0x00, 0x00, 0x04,
9837 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
9838 };
9839
9840 uint8 observed[312] = {0};
9841 struct kmip ctx = {0};
9842 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_4);
9843
9844 uint8 value[24] = {
9845 0x73, 0x67, 0x57, 0x80, 0x51, 0x01, 0x2A, 0x6D,
9846 0x13, 0x4A, 0x85, 0x5E, 0x25, 0xC8, 0xCD, 0x5E,
9847 0x4C, 0xA1, 0x31, 0x45, 0x57, 0x29, 0xD3, 0xC8
9848 };
9849 struct byte_string ps = {0};
9850 ps.value = value;
9851 ps.size = ARRAY_LENGTH(value);
9852
9853 struct cryptographic_parameters cp = {0};
9854 cp.block_cipher_mode = KMIP_BLOCK_CBC;
9855 cp.padding_method = KMIP_PAD_PKCS5;
9856 cp.hashing_algorithm = KMIP_HASH_SHA1;
9857 cp.key_role_type = KMIP_ROLE_KEK;
9858
9859 cp.digital_signature_algorithm = KMIP_DIGITAL_SHA256_WITH_RSA;
9860 cp.cryptographic_algorithm = KMIP_CRYPTOALG_RSA;
9861 cp.random_iv = KMIP_TRUE;
9862 cp.iv_length = 128;
9863 cp.tag_length = 64;
9864 cp.fixed_field_length = 64;
9865 cp.invocation_field_length = 64;
9866 cp.counter_length = 256;
9867 cp.initial_counter_value = 0;
9868
9869 cp.salt_length = 32;
9870 cp.mask_generator = KMIP_MASKGEN_MGF1;
9871 cp.mask_generator_hashing_algorithm = KMIP_HASH_SHA256;
9872 cp.p_source = &ps;
9873 cp.trailer_field = 1;
9874
9875 int result = kmip_encode_cryptographic_parameters(&ctx, &cp);
9876 result = report_encoding_test_result(
9877 tracker,
9878 &ctx,
9879 expected,
9880 observed,
9881 result,
9882 __func__);
9883 kmip_destroy(&ctx);
9884 return(result);
9885 }
9886
9887 int
9888 test_decode_cryptographic_parameters_with_mask_fields(TestTracker *tracker)
9889 {
9890 TRACK_TEST(tracker);
9891
9892 uint8 encoding[312] = {
9893 0x42, 0x00, 0x2B, 0x01, 0x00, 0x00, 0x01, 0x30,
9894 0x42, 0x00, 0x11, 0x05, 0x00, 0x00, 0x00, 0x04,
9895 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
9896 0x42, 0x00, 0x5F, 0x05, 0x00, 0x00, 0x00, 0x04,
9897 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
9898 0x42, 0x00, 0x38, 0x05, 0x00, 0x00, 0x00, 0x04,
9899 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
9900 0x42, 0x00, 0x83, 0x05, 0x00, 0x00, 0x00, 0x04,
9901 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x00,
9902 0x42, 0x00, 0xAE, 0x05, 0x00, 0x00, 0x00, 0x04,
9903 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00,
9904 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
9905 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
9906 0x42, 0x00, 0xC5, 0x06, 0x00, 0x00, 0x00, 0x08,
9907 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
9908 0x42, 0x00, 0xCD, 0x02, 0x00, 0x00, 0x00, 0x04,
9909 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
9910 0x42, 0x00, 0xCE, 0x02, 0x00, 0x00, 0x00, 0x04,
9911 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
9912 0x42, 0x00, 0xCF, 0x02, 0x00, 0x00, 0x00, 0x04,
9913 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
9914 0x42, 0x00, 0xD2, 0x02, 0x00, 0x00, 0x00, 0x04,
9915 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
9916 0x42, 0x00, 0xD0, 0x02, 0x00, 0x00, 0x00, 0x04,
9917 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
9918 0x42, 0x00, 0xD1, 0x02, 0x00, 0x00, 0x00, 0x04,
9919 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9920 0x42, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04,
9921 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00,
9922 0x42, 0x01, 0x01, 0x05, 0x00, 0x00, 0x00, 0x04,
9923 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
9924 0x42, 0x01, 0x02, 0x05, 0x00, 0x00, 0x00, 0x04,
9925 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
9926 0x42, 0x01, 0x03, 0x08, 0x00, 0x00, 0x00, 0x18,
9927 0x73, 0x67, 0x57, 0x80, 0x51, 0x01, 0x2A, 0x6D,
9928 0x13, 0x4A, 0x85, 0x5E, 0x25, 0xC8, 0xCD, 0x5E,
9929 0x4C, 0xA1, 0x31, 0x45, 0x57, 0x29, 0xD3, 0xC8,
9930 0x42, 0x01, 0x04, 0x02, 0x00, 0x00, 0x00, 0x04,
9931 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
9932 };
9933
9934 struct kmip ctx = {0};
9935 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_4);
9936
9937 uint8 value[24] = {
9938 0x73, 0x67, 0x57, 0x80, 0x51, 0x01, 0x2A, 0x6D,
9939 0x13, 0x4A, 0x85, 0x5E, 0x25, 0xC8, 0xCD, 0x5E,
9940 0x4C, 0xA1, 0x31, 0x45, 0x57, 0x29, 0xD3, 0xC8
9941 };
9942 struct byte_string ps = {0};
9943 ps.value = value;
9944 ps.size = ARRAY_LENGTH(value);
9945
9946 struct cryptographic_parameters expected = {0};
9947 kmip_init_cryptographic_parameters(&expected);
9948
9949 expected.block_cipher_mode = KMIP_BLOCK_CBC;
9950 expected.padding_method = KMIP_PAD_PKCS5;
9951 expected.hashing_algorithm = KMIP_HASH_SHA1;
9952 expected.key_role_type = KMIP_ROLE_KEK;
9953
9954 expected.digital_signature_algorithm = KMIP_DIGITAL_SHA256_WITH_RSA;
9955 expected.cryptographic_algorithm = KMIP_CRYPTOALG_RSA;
9956 expected.random_iv = KMIP_TRUE;
9957 expected.iv_length = 128;
9958 expected.tag_length = 64;
9959 expected.fixed_field_length = 64;
9960 expected.invocation_field_length = 64;
9961 expected.counter_length = 256;
9962 expected.initial_counter_value = 0;
9963
9964 expected.salt_length = 32;
9965 expected.mask_generator = KMIP_MASKGEN_MGF1;
9966 expected.mask_generator_hashing_algorithm = KMIP_HASH_SHA256;
9967 expected.p_source = &ps;
9968 expected.trailer_field = 1;
9969
9970 struct cryptographic_parameters observed = {0};
9971 kmip_init_cryptographic_parameters(&observed);
9972
9973 int result = kmip_decode_cryptographic_parameters(&ctx, &observed);
9974 result = report_decoding_test_result(
9975 tracker,
9976 &ctx,
9977 kmip_compare_cryptographic_parameters(&expected, &observed),
9978 result,
9979 __func__);
9980 kmip_free_cryptographic_parameters(&ctx, &observed);
9981 kmip_destroy(&ctx);
9982 return(result);
9983 }
9984
9985 int
9986 test_encode_get_request_payload_with_wrap_type(TestTracker *tracker)
9987 {
9988 TRACK_TEST(tracker);
9989
9990 uint8 expected[104] = {
9991 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, 0x60,
9992 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
9993 0x37, 0x63, 0x66, 0x35, 0x32, 0x30, 0x39, 0x62,
9994 0x2D, 0x36, 0x66, 0x66, 0x36, 0x2D, 0x34, 0x34,
9995 0x32, 0x36, 0x2D, 0x38, 0x39, 0x39, 0x65, 0x2D,
9996 0x32, 0x32, 0x62, 0x30, 0x36, 0x37, 0x38, 0x35,
9997 0x39, 0x33, 0x37, 0x32, 0x00, 0x00, 0x00, 0x00,
9998 0x42, 0x00, 0x42, 0x05, 0x00, 0x00, 0x00, 0x04,
9999 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
10000 0x42, 0x00, 0xF8, 0x05, 0x00, 0x00, 0x00, 0x04,
10001 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10002 0x42, 0x00, 0x41, 0x05, 0x00, 0x00, 0x00, 0x04,
10003 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
10004 };
10005
10006 uint8 observed[104] = {0};
10007 struct kmip ctx = {0};
10008 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_4);
10009
10010 struct text_string uuid = {0};
10011 uuid.value = "7cf5209b-6ff6-4426-899e-22b067859372";
10012 uuid.size = 36;
10013
10014 struct get_request_payload grp = {0};
10015 grp.unique_identifier = &uuid;
10016 grp.key_format_type = KMIP_KEYFORMAT_PKCS1;
10017 grp.key_compression_type = KMIP_KEYCOMP_EC_PUB_UNCOMPRESSED;
10018
10019 grp.key_wrap_type = KMIP_WRAPTYPE_NOT_WRAPPED;
10020
10021 int result = kmip_encode_get_request_payload(&ctx, &grp);
10022 result = report_encoding_test_result(
10023 tracker,
10024 &ctx,
10025 expected,
10026 observed,
10027 result,
10028 __func__);
10029 kmip_destroy(&ctx);
10030 return(result);
10031 }
10032
10033 int
10034 test_encode_request_header_with_correlation_values(TestTracker *tracker)
10035 {
10036 TRACK_TEST(tracker);
10037
10038 uint8 expected[280] = {
10039 0x42, 0x00, 0x77, 0x01, 0x00, 0x00, 0x01, 0x10,
10040 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20,
10041 0x42, 0x00, 0x6A, 0x02, 0x00, 0x00, 0x00, 0x04,
10042 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10043 0x42, 0x00, 0x6B, 0x02, 0x00, 0x00, 0x00, 0x04,
10044 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
10045 0x42, 0x00, 0x50, 0x02, 0x00, 0x00, 0x00, 0x04,
10046 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
10047 0x42, 0x01, 0x05, 0x07, 0x00, 0x00, 0x00, 0x08,
10048 0x63, 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x20, 0x31,
10049 0x42, 0x01, 0x06, 0x07, 0x00, 0x00, 0x00, 0x08,
10050 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x31,
10051 0x42, 0x00, 0x07, 0x06, 0x00, 0x00, 0x00, 0x08,
10052 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
10053 0x42, 0x00, 0xD3, 0x06, 0x00, 0x00, 0x00, 0x08,
10054 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
10055 0x42, 0x00, 0xC7, 0x05, 0x00, 0x00, 0x00, 0x04,
10056 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10057 0x42, 0x00, 0xC7, 0x05, 0x00, 0x00, 0x00, 0x04,
10058 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
10059 0x42, 0x00, 0x0C, 0x01, 0x00, 0x00, 0x00, 0x40,
10060 0x42, 0x00, 0x23, 0x01, 0x00, 0x00, 0x00, 0x38,
10061 0x42, 0x00, 0x24, 0x05, 0x00, 0x00, 0x00, 0x04,
10062 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10063 0x42, 0x00, 0x25, 0x01, 0x00, 0x00, 0x00, 0x20,
10064 0x42, 0x00, 0x99, 0x07, 0x00, 0x00, 0x00, 0x06,
10065 0x42, 0x61, 0x72, 0x6E, 0x65, 0x79, 0x00, 0x00,
10066 0x42, 0x00, 0xA1, 0x07, 0x00, 0x00, 0x00, 0x07,
10067 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x32, 0x00,
10068 0x42, 0x00, 0x0E, 0x05, 0x00, 0x00, 0x00, 0x04,
10069 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10070 0x42, 0x00, 0x10, 0x06, 0x00, 0x00, 0x00, 0x08,
10071 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
10072 0x42, 0x00, 0x0D, 0x02, 0x00, 0x00, 0x00, 0x04,
10073 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00
10074 };
10075
10076 uint8 observed[280] = {0};
10077 struct kmip ctx = {0};
10078 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_4);
10079
10080 struct protocol_version pv = {0};
10081 pv.major = 1;
10082 pv.minor = 0;
10083
10084 struct text_string username = {0};
10085 username.value = "Barney";
10086 username.size = 6;
10087 struct text_string password = {0};
10088 password.value = "secret2";
10089 password.size = 7;
10090
10091 struct username_password_credential upc = {0};
10092 upc.username = &username;
10093 upc.password = &password;
10094
10095 struct credential c = {0};
10096 c.credential_type = KMIP_CRED_USERNAME_AND_PASSWORD;
10097 c.credential_value = &upc;
10098
10099 struct authentication a = {0};
10100 a.credential = &c;
10101
10102 enum attestation_type types[2] = {
10103 KMIP_ATTEST_TPM_QUOTE,
10104 KMIP_ATTEST_SAML_ASSERTION
10105 };
10106
10107 struct text_string ccv = {0};
10108 ccv.value = "client 1";
10109 ccv.size = 8;
10110
10111 struct text_string scv = {0};
10112 scv.value = "server 1";
10113 scv.size = 8;
10114
10115 struct request_header rh = {0};
10116 kmip_init_request_header(&rh);
10117
10118 rh.protocol_version = &pv;
10119 rh.maximum_response_size = 4096;
10120 rh.asynchronous_indicator = KMIP_TRUE;
10121 rh.attestation_capable_indicator = KMIP_TRUE;
10122 rh.attestation_types = types;
10123 rh.attestation_type_count = ARRAY_LENGTH(types);
10124 rh.authentication = &a;
10125 rh.batch_error_continuation_option = KMIP_BATCH_CONTINUE;
10126 rh.batch_order_option = KMIP_TRUE;
10127 rh.batch_count = 2;
10128
10129 rh.client_correlation_value = &ccv;
10130 rh.server_correlation_value = &scv;
10131
10132 int result = kmip_encode_request_header(&ctx, &rh);
10133 result = report_encoding_test_result(
10134 tracker,
10135 &ctx,
10136 expected,
10137 observed,
10138 result,
10139 __func__);
10140 kmip_destroy(&ctx);
10141 return(result);
10142 }
10143
10144 int
10145 test_encode_response_header_with_correlation_values(TestTracker *tracker)
10146 {
10147 TRACK_TEST(tracker);
10148
10149 uint8 expected[184] = {
10150 0x42, 0x00, 0x7A, 0x01, 0x00, 0x00, 0x00, 0xB0,
10151 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20,
10152 0x42, 0x00, 0x6A, 0x02, 0x00, 0x00, 0x00, 0x04,
10153 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10154 0x42, 0x00, 0x6B, 0x02, 0x00, 0x00, 0x00, 0x04,
10155 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
10156 0x42, 0x00, 0x92, 0x09, 0x00, 0x00, 0x00, 0x08,
10157 0x00, 0x00, 0x00, 0x00, 0x4F, 0x9A, 0x54, 0xE5,
10158 0x42, 0x00, 0xC8, 0x01, 0x00, 0x00, 0x00, 0x20,
10159 0x42, 0x00, 0xC9, 0x08, 0x00, 0x00, 0x00, 0x04,
10160 0x01, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00,
10161 0x42, 0x00, 0xCA, 0x08, 0x00, 0x00, 0x00, 0x06,
10162 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00,
10163 0x42, 0x00, 0xC7, 0x05, 0x00, 0x00, 0x00, 0x04,
10164 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10165 0x42, 0x00, 0xC7, 0x05, 0x00, 0x00, 0x00, 0x04,
10166 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
10167 0x42, 0x01, 0x05, 0x07, 0x00, 0x00, 0x00, 0x08,
10168 0x63, 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x20, 0x31,
10169 0x42, 0x01, 0x06, 0x07, 0x00, 0x00, 0x00, 0x08,
10170 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x31,
10171 0x42, 0x00, 0x0D, 0x02, 0x00, 0x00, 0x00, 0x04,
10172 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
10173 };
10174
10175 uint8 observed[184] = {0};
10176 struct kmip ctx = {0};
10177 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_4);
10178
10179 struct protocol_version pv = {0};
10180 pv.major = 1;
10181 pv.minor = 0;
10182
10183 uint8 id[4] = {0x01, 0x02, 0x03, 0x04};
10184 struct byte_string ni = {0};
10185 ni.value = id;
10186 ni.size = ARRAY_LENGTH(id);
10187
10188 uint8 value[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
10189 struct byte_string nv = {0};
10190 nv.value = value;
10191 nv.size = ARRAY_LENGTH(value);
10192
10193 struct nonce n = {0};
10194 n.nonce_id = &ni;
10195 n.nonce_value = &nv;
10196
10197 enum attestation_type types[2] = {
10198 KMIP_ATTEST_TPM_QUOTE,
10199 KMIP_ATTEST_SAML_ASSERTION
10200 };
10201
10202 struct text_string ccv = {0};
10203 ccv.value = "client 1";
10204 ccv.size = 8;
10205
10206 struct text_string scv = {0};
10207 scv.value = "server 1";
10208 scv.size = 8;
10209
10210 struct response_header rh = {0};
10211 kmip_init_response_header(&rh);
10212
10213 rh.protocol_version = &pv;
10214 rh.time_stamp = 1335514341;
10215 rh.nonce = &n;
10216 rh.attestation_types = types;
10217 rh.attestation_type_count = ARRAY_LENGTH(types);
10218 rh.batch_count = 1;
10219
10220 rh.client_correlation_value = &ccv;
10221 rh.server_correlation_value = &scv;
10222
10223 int result = kmip_encode_response_header(&ctx, &rh);
10224 result = report_encoding_test_result(
10225 tracker,
10226 &ctx,
10227 expected,
10228 observed,
10229 result,
10230 __func__);
10231 kmip_destroy(&ctx);
10232 return(result);
10233 }
10234
10235 int
10236 test_decode_response_header_with_correlation_values(TestTracker *tracker)
10237 {
10238 TRACK_TEST(tracker);
10239
10240 uint8 encoding[184] = {
10241 0x42, 0x00, 0x7A, 0x01, 0x00, 0x00, 0x00, 0xB0,
10242 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20,
10243 0x42, 0x00, 0x6A, 0x02, 0x00, 0x00, 0x00, 0x04,
10244 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10245 0x42, 0x00, 0x6B, 0x02, 0x00, 0x00, 0x00, 0x04,
10246 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
10247 0x42, 0x00, 0x92, 0x09, 0x00, 0x00, 0x00, 0x08,
10248 0x00, 0x00, 0x00, 0x00, 0x4F, 0x9A, 0x54, 0xE5,
10249 0x42, 0x00, 0xC8, 0x01, 0x00, 0x00, 0x00, 0x20,
10250 0x42, 0x00, 0xC9, 0x08, 0x00, 0x00, 0x00, 0x04,
10251 0x01, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00,
10252 0x42, 0x00, 0xCA, 0x08, 0x00, 0x00, 0x00, 0x06,
10253 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00,
10254 0x42, 0x00, 0xC7, 0x05, 0x00, 0x00, 0x00, 0x04,
10255 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10256 0x42, 0x00, 0xC7, 0x05, 0x00, 0x00, 0x00, 0x04,
10257 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
10258 0x42, 0x01, 0x05, 0x07, 0x00, 0x00, 0x00, 0x08,
10259 0x63, 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x20, 0x31,
10260 0x42, 0x01, 0x06, 0x07, 0x00, 0x00, 0x00, 0x08,
10261 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x31,
10262 0x42, 0x00, 0x0D, 0x02, 0x00, 0x00, 0x00, 0x04,
10263 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
10264 };
10265
10266 struct kmip ctx = {0};
10267 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_1_4);
10268
10269 struct protocol_version pv = {0};
10270 pv.major = 1;
10271 pv.minor = 0;
10272
10273 uint8 id[4] = {0x01, 0x02, 0x03, 0x04};
10274 struct byte_string ni = {0};
10275 ni.value = id;
10276 ni.size = ARRAY_LENGTH(id);
10277
10278 uint8 value[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
10279 struct byte_string nv = {0};
10280 nv.value = value;
10281 nv.size = ARRAY_LENGTH(value);
10282
10283 struct nonce n = {0};
10284 n.nonce_id = &ni;
10285 n.nonce_value = &nv;
10286
10287 enum attestation_type types[2] = {
10288 KMIP_ATTEST_TPM_QUOTE,
10289 KMIP_ATTEST_SAML_ASSERTION
10290 };
10291
10292 struct text_string ccv = {0};
10293 ccv.value = "client 1";
10294 ccv.size = 8;
10295
10296 struct text_string scv = {0};
10297 scv.value = "server 1";
10298 scv.size = 8;
10299
10300 struct response_header expected = {0};
10301 kmip_init_response_header(&expected);
10302
10303 expected.protocol_version = &pv;
10304 expected.time_stamp = 1335514341;
10305 expected.nonce = &n;
10306 expected.attestation_types = types;
10307 expected.attestation_type_count = ARRAY_LENGTH(types);
10308 expected.batch_count = 1;
10309
10310 expected.client_correlation_value = &ccv;
10311 expected.server_correlation_value = &scv;
10312
10313 struct response_header observed = {0};
10314 kmip_init_response_header(&observed);
10315
10316 int result = kmip_decode_response_header(&ctx, &observed);
10317 result = report_decoding_test_result(
10318 tracker,
10319 &ctx,
10320 kmip_compare_response_header(&expected, &observed),
10321 result,
10322 __func__);
10323 kmip_free_response_header(&ctx, &observed);
10324 kmip_destroy(&ctx);
10325 return(result);
10326 }
10327
10328 int
10329 test_encode_response_header_kmip_2_0(TestTracker *tracker)
10330 {
10331 TRACK_TEST(tracker);
10332
10333 /* This encoding matches the following set of values:
10334 * Response Header
10335 * Protocol Version
10336 * Protocol Version Major - 2
10337 * Protocol Version Minor - 0
10338 * Time Stamp - 1335514341
10339 * Nonce
10340 * Nonce ID - 0x01020304
10341 * Nonce Value - 0xFFFFFFFFFFFF
10342 * Server Hashed Password - 301EC144E9C6C4F64C29C01C3E11839C97D6E7D2BC0C5DBC68377B679AE51D4D
10343 * Attestation Type - TPM Quote
10344 * Attestation Type - SAML Assertion
10345 * Client Correlation Value - client 1
10346 * Server Correlation Value - server 1
10347 * Batch Count - 1
10348 */
10349 uint8 expected[224] = {
10350 0x42, 0x00, 0x7A, 0x01, 0x00, 0x00, 0x00, 0xD8,
10351 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20,
10352 0x42, 0x00, 0x6A, 0x02, 0x00, 0x00, 0x00, 0x04,
10353 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
10354 0x42, 0x00, 0x6B, 0x02, 0x00, 0x00, 0x00, 0x04,
10355 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
10356 0x42, 0x00, 0x92, 0x09, 0x00, 0x00, 0x00, 0x08,
10357 0x00, 0x00, 0x00, 0x00, 0x4F, 0x9A, 0x54, 0xE5,
10358 0x42, 0x00, 0xC8, 0x01, 0x00, 0x00, 0x00, 0x20,
10359 0x42, 0x00, 0xC9, 0x08, 0x00, 0x00, 0x00, 0x04,
10360 0x01, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00,
10361 0x42, 0x00, 0xCA, 0x08, 0x00, 0x00, 0x00, 0x06,
10362 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00,
10363 0x42, 0x01, 0x55, 0x08, 0x00, 0x00, 0x00, 0x20,
10364 0x30, 0x1E, 0xC1, 0x44, 0xE9, 0xC6, 0xC4, 0xF6,
10365 0x4C, 0x29, 0xC0, 0x1C, 0x3E, 0x11, 0x83, 0x9C,
10366 0x97, 0xD6, 0xE7, 0xD2, 0xBC, 0x0C, 0x5D, 0xBC,
10367 0x68, 0x37, 0x7B, 0x67, 0x9A, 0xE5, 0x1D, 0x4D,
10368 0x42, 0x00, 0xC7, 0x05, 0x00, 0x00, 0x00, 0x04,
10369 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10370 0x42, 0x00, 0xC7, 0x05, 0x00, 0x00, 0x00, 0x04,
10371 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
10372 0x42, 0x01, 0x05, 0x07, 0x00, 0x00, 0x00, 0x08,
10373 0x63, 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x20, 0x31,
10374 0x42, 0x01, 0x06, 0x07, 0x00, 0x00, 0x00, 0x08,
10375 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x31,
10376 0x42, 0x00, 0x0D, 0x02, 0x00, 0x00, 0x00, 0x04,
10377 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
10378 };
10379
10380 uint8 observed[224] = {0};
10381 KMIP ctx = {0};
10382 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_2_0);
10383
10384 ProtocolVersion pv = {0};
10385 pv.major = 2;
10386 pv.minor = 0;
10387
10388 uint8 id[4] = {0x01, 0x02, 0x03, 0x04};
10389 ByteString ni = {0};
10390 ni.value = id;
10391 ni.size = ARRAY_LENGTH(id);
10392
10393 uint8 value[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
10394 ByteString nv = {0};
10395 nv.value = value;
10396 nv.size = ARRAY_LENGTH(value);
10397
10398 Nonce n = {0};
10399 n.nonce_id = &ni;
10400 n.nonce_value = &nv;
10401
10402 uint8 hash[32] = {
10403 0x30, 0x1E, 0xC1, 0x44, 0xE9, 0xC6, 0xC4, 0xF6,
10404 0x4C, 0x29, 0xC0, 0x1C, 0x3E, 0x11, 0x83, 0x9C,
10405 0x97, 0xD6, 0xE7, 0xD2, 0xBC, 0x0C, 0x5D, 0xBC,
10406 0x68, 0x37, 0x7B, 0x67, 0x9A, 0xE5, 0x1D, 0x4D
10407 };
10408 ByteString shp = {0};
10409 shp.value = hash;
10410 shp.size = ARRAY_LENGTH(hash);
10411
10412 enum attestation_type types[2] = {
10413 KMIP_ATTEST_TPM_QUOTE,
10414 KMIP_ATTEST_SAML_ASSERTION
10415 };
10416
10417 TextString ccv = {0};
10418 ccv.value = "client 1";
10419 ccv.size = 8;
10420
10421 TextString scv = {0};
10422 scv.value = "server 1";
10423 scv.size = 8;
10424
10425 ResponseHeader rh = {0};
10426 kmip_init_response_header(&rh);
10427
10428 rh.protocol_version = &pv;
10429 rh.time_stamp = 1335514341;
10430 rh.nonce = &n;
10431 rh.server_hashed_password = &shp;
10432 rh.attestation_types = types;
10433 rh.attestation_type_count = ARRAY_LENGTH(types);
10434 rh.batch_count = 1;
10435
10436 rh.client_correlation_value = &ccv;
10437 rh.server_correlation_value = &scv;
10438
10439 int result = kmip_encode_response_header(&ctx, &rh);
10440 result = report_encoding_test_result(tracker, &ctx, expected, observed, result, __func__);
10441
10442 kmip_destroy(&ctx);
10443 return(result);
10444 }
10445
10446 int
10447 test_decode_response_header_kmip_2_0(TestTracker *tracker)
10448 {
10449 TRACK_TEST(tracker);
10450
10451 /* This encoding matches the following set of values:
10452 * Response Header
10453 * Protocol Version
10454 * Protocol Version Major - 2
10455 * Protocol Version Minor - 0
10456 * Time Stamp - 1335514341
10457 * Nonce
10458 * Nonce ID - 0x01020304
10459 * Nonce Value - 0xFFFFFFFFFFFF
10460 * Server Hashed Password - 301EC144E9C6C4F64C29C01C3E11839C97D6E7D2BC0C5DBC68377B679AE51D4D
10461 * Attestation Type - TPM Quote
10462 * Attestation Type - SAML Assertion
10463 * Client Correlation Value - client 1
10464 * Server Correlation Value - server 1
10465 * Batch Count - 1
10466 */
10467 uint8 encoding[224] = {
10468 0x42, 0x00, 0x7A, 0x01, 0x00, 0x00, 0x00, 0xD8,
10469 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20,
10470 0x42, 0x00, 0x6A, 0x02, 0x00, 0x00, 0x00, 0x04,
10471 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
10472 0x42, 0x00, 0x6B, 0x02, 0x00, 0x00, 0x00, 0x04,
10473 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
10474 0x42, 0x00, 0x92, 0x09, 0x00, 0x00, 0x00, 0x08,
10475 0x00, 0x00, 0x00, 0x00, 0x4F, 0x9A, 0x54, 0xE5,
10476 0x42, 0x00, 0xC8, 0x01, 0x00, 0x00, 0x00, 0x20,
10477 0x42, 0x00, 0xC9, 0x08, 0x00, 0x00, 0x00, 0x04,
10478 0x01, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00,
10479 0x42, 0x00, 0xCA, 0x08, 0x00, 0x00, 0x00, 0x06,
10480 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00,
10481 0x42, 0x01, 0x55, 0x08, 0x00, 0x00, 0x00, 0x20,
10482 0x30, 0x1E, 0xC1, 0x44, 0xE9, 0xC6, 0xC4, 0xF6,
10483 0x4C, 0x29, 0xC0, 0x1C, 0x3E, 0x11, 0x83, 0x9C,
10484 0x97, 0xD6, 0xE7, 0xD2, 0xBC, 0x0C, 0x5D, 0xBC,
10485 0x68, 0x37, 0x7B, 0x67, 0x9A, 0xE5, 0x1D, 0x4D,
10486 0x42, 0x00, 0xC7, 0x05, 0x00, 0x00, 0x00, 0x04,
10487 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10488 0x42, 0x00, 0xC7, 0x05, 0x00, 0x00, 0x00, 0x04,
10489 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
10490 0x42, 0x01, 0x05, 0x07, 0x00, 0x00, 0x00, 0x08,
10491 0x63, 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x20, 0x31,
10492 0x42, 0x01, 0x06, 0x07, 0x00, 0x00, 0x00, 0x08,
10493 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x31,
10494 0x42, 0x00, 0x0D, 0x02, 0x00, 0x00, 0x00, 0x04,
10495 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
10496 };
10497
10498 KMIP ctx = {0};
10499 kmip_init(&ctx, encoding, ARRAY_LENGTH(encoding), KMIP_2_0);
10500
10501 ProtocolVersion pv = {0};
10502 pv.major = 2;
10503 pv.minor = 0;
10504
10505 uint8 id[4] = {0x01, 0x02, 0x03, 0x04};
10506 ByteString ni = {0};
10507 ni.value = id;
10508 ni.size = ARRAY_LENGTH(id);
10509
10510 uint8 value[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
10511 ByteString nv = {0};
10512 nv.value = value;
10513 nv.size = ARRAY_LENGTH(value);
10514
10515 Nonce n = {0};
10516 n.nonce_id = &ni;
10517 n.nonce_value = &nv;
10518
10519 uint8 hash[32] = {
10520 0x30, 0x1E, 0xC1, 0x44, 0xE9, 0xC6, 0xC4, 0xF6,
10521 0x4C, 0x29, 0xC0, 0x1C, 0x3E, 0x11, 0x83, 0x9C,
10522 0x97, 0xD6, 0xE7, 0xD2, 0xBC, 0x0C, 0x5D, 0xBC,
10523 0x68, 0x37, 0x7B, 0x67, 0x9A, 0xE5, 0x1D, 0x4D
10524 };
10525 ByteString shp = {0};
10526 shp.value = hash;
10527 shp.size = ARRAY_LENGTH(hash);
10528
10529 enum attestation_type types[2] = {
10530 KMIP_ATTEST_TPM_QUOTE,
10531 KMIP_ATTEST_SAML_ASSERTION
10532 };
10533
10534 TextString ccv = {0};
10535 ccv.value = "client 1";
10536 ccv.size = 8;
10537
10538 TextString scv = {0};
10539 scv.value = "server 1";
10540 scv.size = 8;
10541
10542 ResponseHeader expected = {0};
10543 kmip_init_response_header(&expected);
10544
10545 expected.protocol_version = &pv;
10546 expected.time_stamp = 1335514341;
10547 expected.nonce = &n;
10548 expected.server_hashed_password = &shp;
10549 expected.attestation_types = types;
10550 expected.attestation_type_count = ARRAY_LENGTH(types);
10551 expected.batch_count = 1;
10552
10553 expected.client_correlation_value = &ccv;
10554 expected.server_correlation_value = &scv;
10555
10556 ResponseHeader observed = {0};
10557 kmip_init_response_header(&observed);
10558
10559 int result = kmip_decode_response_header(&ctx, &observed);
10560 int comparison = kmip_compare_response_header(&expected, &observed);
10561 if(!comparison)
10562 {
10563 /* TODO (ph) Reorder these with printing result so that objects are
10564 below function name.
10565 */
10566 kmip_print_response_header(1, &expected);
10567 kmip_print_response_header(1, &observed);
10568 }
10569 result = report_decoding_test_result(tracker, &ctx, comparison, result, __func__);
10570
10571 kmip_free_response_header(&ctx, &observed);
10572 kmip_destroy(&ctx);
10573 return(result);
10574 }
10575
10576 /*
10577 The following tests are taken verbatim from the KMIP 1.1 Test Cases
10578 documentation, available here:
10579
10580 http://docs.oasis-open.org/kmip/testcases/v1.1/kmip-testcases-v1.1.html
10581 */
10582
10583 int
10584 test_kmip_1_1_test_suite_3_1_1_0_a(TestTracker *tracker)
10585 {
10586 TRACK_TEST(tracker);
10587
10588 /* KMIP 1.1 Test Suite - Test 3.1.1.0a */
10589 uint8 expected[296] = {
10590 0x42, 0x00, 0x78, 0x01, 0x00, 0x00, 0x01, 0x20,
10591 0x42, 0x00, 0x77, 0x01, 0x00, 0x00, 0x00, 0x38,
10592 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20,
10593 0x42, 0x00, 0x6A, 0x02, 0x00, 0x00, 0x00, 0x04,
10594 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10595 0x42, 0x00, 0x6B, 0x02, 0x00, 0x00, 0x00, 0x04,
10596 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10597 0x42, 0x00, 0x0D, 0x02, 0x00, 0x00, 0x00, 0x04,
10598 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10599 0x42, 0x00, 0x0F, 0x01, 0x00, 0x00, 0x00, 0xD8,
10600 0x42, 0x00, 0x5C, 0x05, 0x00, 0x00, 0x00, 0x04,
10601 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10602 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, 0xC0,
10603 0x42, 0x00, 0x57, 0x05, 0x00, 0x00, 0x00, 0x04,
10604 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
10605 0x42, 0x00, 0x91, 0x01, 0x00, 0x00, 0x00, 0xA8,
10606 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
10607 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x17,
10608 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
10609 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x41, 0x6C,
10610 0x67, 0x6F, 0x72, 0x69, 0x74, 0x68, 0x6D, 0x00,
10611 0x42, 0x00, 0x0B, 0x05, 0x00, 0x00, 0x00, 0x04,
10612 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
10613 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
10614 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x14,
10615 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
10616 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x4C, 0x65,
10617 0x6E, 0x67, 0x74, 0x68, 0x00, 0x00, 0x00, 0x00,
10618 0x42, 0x00, 0x0B, 0x02, 0x00, 0x00, 0x00, 0x04,
10619 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
10620 0x42, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x30,
10621 0x42, 0x00, 0x0A, 0x07, 0x00, 0x00, 0x00, 0x18,
10622 0x43, 0x72, 0x79, 0x70, 0x74, 0x6F, 0x67, 0x72,
10623 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x55, 0x73,
10624 0x61, 0x67, 0x65, 0x20, 0x4D, 0x61, 0x73, 0x6B,
10625 0x42, 0x00, 0x0B, 0x02, 0x00, 0x00, 0x00, 0x04,
10626 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00
10627 };
10628
10629 uint8 observed[296] = {0};
10630 struct kmip ctx = {0};
10631 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_1);
10632
10633 /* TODO (ph) If protocol version omitted, pull from context? */
10634 struct protocol_version pv = {0};
10635 pv.major = 1;
10636 pv.minor = 1;
10637
10638 struct request_header rh = {0};
10639 kmip_init_request_header(&rh);
10640
10641 rh.protocol_version = &pv;
10642 rh.batch_count = 1;
10643
10644 struct attribute a[3] = {0};
10645 for(int i = 0; i < 3; i++)
10646 {
10647 kmip_init_attribute(&a[i]);
10648 }
10649
10650 enum cryptographic_algorithm algorithm = KMIP_CRYPTOALG_AES;
10651 a[0].type = KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM;
10652 a[0].value = &algorithm;
10653
10654 int32 length = 128;
10655 a[1].type = KMIP_ATTR_CRYPTOGRAPHIC_LENGTH;
10656 a[1].value = &length;
10657
10658 int32 mask = KMIP_CRYPTOMASK_ENCRYPT | KMIP_CRYPTOMASK_DECRYPT;
10659 a[2].type = KMIP_ATTR_CRYPTOGRAPHIC_USAGE_MASK;
10660 a[2].value = &mask;
10661
10662 struct template_attribute ta = {0};
10663 ta.attributes = a;
10664 ta.attribute_count = ARRAY_LENGTH(a);
10665
10666 struct create_request_payload crp = {0};
10667 crp.object_type = KMIP_OBJTYPE_SYMMETRIC_KEY;
10668 crp.template_attribute = &ta;
10669
10670 struct request_batch_item rbi = {0};
10671 kmip_init_request_batch_item(&rbi);
10672 rbi.operation = KMIP_OP_CREATE;
10673 rbi.request_payload = &crp;
10674
10675 struct request_message rm = {0};
10676 rm.request_header = &rh;
10677 rm.batch_items = &rbi;
10678 rm.batch_count = 1;
10679
10680 int result = kmip_encode_request_message(&ctx, &rm);
10681 result = report_encoding_test_result(
10682 tracker,
10683 &ctx,
10684 expected,
10685 observed,
10686 result,
10687 __func__);
10688 kmip_destroy(&ctx);
10689 return(result);
10690 }
10691
10692 int
10693 test_kmip_1_1_test_suite_3_1_1_0_b(TestTracker *tracker)
10694 {
10695 TRACK_TEST(tracker);
10696
10697 /* KMIP 1.1 Test Suite - Test 3.1.1.0b */
10698 uint8 expected[200] = {
10699 0x42, 0x00, 0x7B, 0x01, 0x00, 0x00, 0x00, 0xC0,
10700 0x42, 0x00, 0x7A, 0x01, 0x00, 0x00, 0x00, 0x48,
10701 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20,
10702 0x42, 0x00, 0x6A, 0x02, 0x00, 0x00, 0x00, 0x04,
10703 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10704 0x42, 0x00, 0x6B, 0x02, 0x00, 0x00, 0x00, 0x04,
10705 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10706 0x42, 0x00, 0x92, 0x09, 0x00, 0x00, 0x00, 0x08,
10707 0x00, 0x00, 0x00, 0x00, 0x4F, 0x9A, 0x54, 0xE5,
10708 0x42, 0x00, 0x0D, 0x02, 0x00, 0x00, 0x00, 0x04,
10709 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10710 0x42, 0x00, 0x0F, 0x01, 0x00, 0x00, 0x00, 0x68,
10711 0x42, 0x00, 0x5C, 0x05, 0x00, 0x00, 0x00, 0x04,
10712 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10713 0x42, 0x00, 0x7F, 0x05, 0x00, 0x00, 0x00, 0x04,
10714 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
10715 0x42, 0x00, 0x7C, 0x01, 0x00, 0x00, 0x00, 0x40,
10716 0x42, 0x00, 0x57, 0x05, 0x00, 0x00, 0x00, 0x04,
10717 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
10718 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
10719 0x66, 0x62, 0x34, 0x62, 0x35, 0x62, 0x39, 0x63,
10720 0x2D, 0x36, 0x31, 0x38, 0x38, 0x2D, 0x34, 0x63,
10721 0x36, 0x33, 0x2D, 0x38, 0x31, 0x34, 0x32, 0x2D,
10722 0x66, 0x65, 0x39, 0x63, 0x33, 0x32, 0x38, 0x31,
10723 0x32, 0x39, 0x66, 0x63, 0x00, 0x00, 0x00, 0x00
10724 };
10725
10726 uint8 observed[200] = {0};
10727 struct kmip ctx = {0};
10728 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_0);
10729
10730 struct protocol_version pv = {0};
10731 pv.major = 1;
10732 pv.minor = 1;
10733
10734 struct response_header rh = {0};
10735 kmip_init_response_header(&rh);
10736
10737 rh.protocol_version = &pv;
10738 rh.time_stamp = 1335514341;
10739 rh.batch_count = 1;
10740
10741 struct text_string uuid = {0};
10742 uuid.value = "fb4b5b9c-6188-4c63-8142-fe9c328129fc";
10743 uuid.size = 36;
10744
10745 struct create_response_payload crp = {0};
10746 crp.object_type = KMIP_OBJTYPE_SYMMETRIC_KEY;
10747 crp.unique_identifier = &uuid;
10748
10749 struct response_batch_item rbi = {0};
10750 rbi.operation = KMIP_OP_CREATE;
10751 rbi.result_status = KMIP_STATUS_SUCCESS;
10752 rbi.response_payload = &crp;
10753
10754 struct response_message rm = {0};
10755 rm.response_header = &rh;
10756 rm.batch_items = &rbi;
10757 rm.batch_count = 1;
10758
10759 int result = kmip_encode_response_message(&ctx, &rm);
10760 result = report_encoding_test_result(
10761 tracker,
10762 &ctx,
10763 expected,
10764 observed,
10765 result,
10766 __func__);
10767 kmip_destroy(&ctx);
10768 return(result);
10769 }
10770
10771 int
10772 test_kmip_1_1_test_suite_3_1_1_1_a(TestTracker *tracker)
10773 {
10774 TRACK_TEST(tracker);
10775
10776 /* KMIP 1.1 Test Suite - Test 3.1.1.1a */
10777 uint8 expected[152] = {
10778 0x42, 0x00, 0x78, 0x01, 0x00, 0x00, 0x00, 0x90,
10779 0x42, 0x00, 0x77, 0x01, 0x00, 0x00, 0x00, 0x38,
10780 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20,
10781 0x42, 0x00, 0x6A, 0x02, 0x00, 0x00, 0x00, 0x04,
10782 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10783 0x42, 0x00, 0x6B, 0x02, 0x00, 0x00, 0x00, 0x04,
10784 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10785 0x42, 0x00, 0x0D, 0x02, 0x00, 0x00, 0x00, 0x04,
10786 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10787 0x42, 0x00, 0x0F, 0x01, 0x00, 0x00, 0x00, 0x48,
10788 0x42, 0x00, 0x5C, 0x05, 0x00, 0x00, 0x00, 0x04,
10789 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00,
10790 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, 0x30,
10791 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
10792 0x66, 0x62, 0x34, 0x62, 0x35, 0x62, 0x39, 0x63,
10793 0x2D, 0x36, 0x31, 0x38, 0x38, 0x2D, 0x34, 0x63,
10794 0x36, 0x33, 0x2D, 0x38, 0x31, 0x34, 0x32, 0x2D,
10795 0x66, 0x65, 0x39, 0x63, 0x33, 0x32, 0x38, 0x31,
10796 0x32, 0x39, 0x66, 0x63, 0x00, 0x00, 0x00, 0x00
10797 };
10798
10799 uint8 observed[152] = {0};
10800 struct kmip ctx = {0};
10801 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_1);
10802
10803 struct protocol_version pv = {0};
10804 pv.major = 1;
10805 pv.minor = 1;
10806
10807 struct request_header rh = {0};
10808 kmip_init_request_header(&rh);
10809
10810 rh.protocol_version = &pv;
10811 rh.batch_count = 1;
10812
10813 struct text_string uuid = {0};
10814 uuid.value = "fb4b5b9c-6188-4c63-8142-fe9c328129fc";
10815 uuid.size = 36;
10816
10817 struct destroy_request_payload drp = {0};
10818 drp.unique_identifier = &uuid;
10819
10820 struct request_batch_item rbi = {0};
10821 kmip_init_request_batch_item(&rbi);
10822 rbi.operation = KMIP_OP_DESTROY;
10823 rbi.request_payload = &drp;
10824
10825 struct request_message rm = {0};
10826 rm.request_header = &rh;
10827 rm.batch_items = &rbi;
10828 rm.batch_count = 1;
10829
10830 int result = kmip_encode_request_message(&ctx, &rm);
10831 result = report_encoding_test_result(
10832 tracker,
10833 &ctx,
10834 expected,
10835 observed,
10836 result,
10837 __func__);
10838 kmip_destroy(&ctx);
10839 return(result);
10840 }
10841
10842 int
10843 test_kmip_1_1_test_suite_3_1_1_1_b(TestTracker *tracker)
10844 {
10845 TRACK_TEST(tracker);
10846
10847 /* KMIP 1.1 Test Suite - Test 3.1.1.1b */
10848 uint8 expected[184] = {
10849 0x42, 0x00, 0x7B, 0x01, 0x00, 0x00, 0x00, 0xB0,
10850 0x42, 0x00, 0x7A, 0x01, 0x00, 0x00, 0x00, 0x48,
10851 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20,
10852 0x42, 0x00, 0x6A, 0x02, 0x00, 0x00, 0x00, 0x04,
10853 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10854 0x42, 0x00, 0x6B, 0x02, 0x00, 0x00, 0x00, 0x04,
10855 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10856 0x42, 0x00, 0x92, 0x09, 0x00, 0x00, 0x00, 0x08,
10857 0x00, 0x00, 0x00, 0x00, 0x4F, 0x9A, 0x54, 0xE5,
10858 0x42, 0x00, 0x0D, 0x02, 0x00, 0x00, 0x00, 0x04,
10859 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10860 0x42, 0x00, 0x0F, 0x01, 0x00, 0x00, 0x00, 0x58,
10861 0x42, 0x00, 0x5C, 0x05, 0x00, 0x00, 0x00, 0x04,
10862 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00,
10863 0x42, 0x00, 0x7F, 0x05, 0x00, 0x00, 0x00, 0x04,
10864 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
10865 0x42, 0x00, 0x7C, 0x01, 0x00, 0x00, 0x00, 0x30,
10866 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
10867 0x66, 0x62, 0x34, 0x62, 0x35, 0x62, 0x39, 0x63,
10868 0x2D, 0x36, 0x31, 0x38, 0x38, 0x2D, 0x34, 0x63,
10869 0x36, 0x33, 0x2D, 0x38, 0x31, 0x34, 0x32, 0x2D,
10870 0x66, 0x65, 0x39, 0x63, 0x33, 0x32, 0x38, 0x31,
10871 0x32, 0x39, 0x66, 0x63, 0x00, 0x00, 0x00, 0x00
10872 };
10873
10874 uint8 observed[184] = {0};
10875 struct kmip ctx = {0};
10876 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_1);
10877
10878 struct protocol_version pv = {0};
10879 pv.major = 1;
10880 pv.minor = 1;
10881
10882 struct response_header rh = {0};
10883 kmip_init_response_header(&rh);
10884
10885 rh.protocol_version = &pv;
10886 rh.time_stamp = 1335514341;
10887 rh.batch_count = 1;
10888
10889 struct text_string uuid = {0};
10890 uuid.value = "fb4b5b9c-6188-4c63-8142-fe9c328129fc";
10891 uuid.size = 36;
10892
10893 struct destroy_response_payload drp = {0};
10894 drp.unique_identifier = &uuid;
10895
10896 struct response_batch_item rbi = {0};
10897 rbi.operation = KMIP_OP_DESTROY;
10898 rbi.result_status = KMIP_STATUS_SUCCESS;
10899 rbi.response_payload = &drp;
10900
10901 struct response_message rm = {0};
10902 rm.response_header = &rh;
10903 rm.batch_items = &rbi;
10904 rm.batch_count = 1;
10905
10906 int result = kmip_encode_response_message(&ctx, &rm);
10907 result = report_encoding_test_result(
10908 tracker,
10909 &ctx,
10910 expected,
10911 observed,
10912 result,
10913 __func__);
10914 kmip_destroy(&ctx);
10915 return(result);
10916 }
10917
10918 int
10919 test_kmip_1_1_test_suite_3_1_3_2_a(TestTracker *tracker)
10920 {
10921 TRACK_TEST(tracker);
10922
10923 /* KMIP 1.1 Test Suite - Test 3.1.3.2a */
10924 uint8 expected[152] = {
10925 0x42, 0x00, 0x78, 0x01, 0x00, 0x00, 0x00, 0x90,
10926 0x42, 0x00, 0x77, 0x01, 0x00, 0x00, 0x00, 0x38,
10927 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20,
10928 0x42, 0x00, 0x6A, 0x02, 0x00, 0x00, 0x00, 0x04,
10929 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10930 0x42, 0x00, 0x6B, 0x02, 0x00, 0x00, 0x00, 0x04,
10931 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10932 0x42, 0x00, 0x0D, 0x02, 0x00, 0x00, 0x00, 0x04,
10933 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
10934 0x42, 0x00, 0x0F, 0x01, 0x00, 0x00, 0x00, 0x48,
10935 0x42, 0x00, 0x5C, 0x05, 0x00, 0x00, 0x00, 0x04,
10936 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00,
10937 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, 0x30,
10938 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
10939 0x34, 0x39, 0x61, 0x31, 0x63, 0x61, 0x38, 0x38,
10940 0x2D, 0x36, 0x62, 0x65, 0x61, 0x2D, 0x34, 0x66,
10941 0x62, 0x32, 0x2D, 0x62, 0x34, 0x35, 0x30, 0x2D,
10942 0x37, 0x65, 0x35, 0x38, 0x38, 0x30, 0x32, 0x63,
10943 0x33, 0x30, 0x33, 0x38, 0x00, 0x00, 0x00, 0x00
10944 };
10945
10946 uint8 observed[152] = {0};
10947 struct kmip ctx = {0};
10948 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_1);
10949
10950 struct protocol_version pv = {0};
10951 pv.major = 1;
10952 pv.minor = 1;
10953
10954 struct request_header rh = {0};
10955 kmip_init_request_header(&rh);
10956
10957 rh.protocol_version = &pv;
10958 rh.batch_count = 1;
10959
10960 struct text_string uuid = {0};
10961 uuid.value = "49a1ca88-6bea-4fb2-b450-7e58802c3038";
10962 uuid.size = 36;
10963
10964 struct get_request_payload grp = {0};
10965 grp.unique_identifier = &uuid;
10966
10967 struct request_batch_item rbi = {0};
10968 kmip_init_request_batch_item(&rbi);
10969 rbi.operation = KMIP_OP_GET;
10970 rbi.request_payload = &grp;
10971
10972 struct request_message rm = {0};
10973 rm.request_header = &rh;
10974 rm.batch_items = &rbi;
10975 rm.batch_count = 1;
10976
10977 int result = kmip_encode_request_message(&ctx, &rm);
10978 result = report_encoding_test_result(
10979 tracker,
10980 &ctx,
10981 expected,
10982 observed,
10983 result,
10984 __func__);
10985 kmip_destroy(&ctx);
10986 return(result);
10987 }
10988
10989 int
10990 test_kmip_1_1_test_suite_3_1_3_2_b(TestTracker *tracker)
10991 {
10992 TRACK_TEST(tracker);
10993
10994 uint8 expected[304] = {
10995 0x42, 0x00, 0x7B, 0x01, 0x00, 0x00, 0x01, 0x28,
10996 0x42, 0x00, 0x7A, 0x01, 0x00, 0x00, 0x00, 0x48,
10997 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20,
10998 0x42, 0x00, 0x6A, 0x02, 0x00, 0x00, 0x00, 0x04,
10999 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
11000 0x42, 0x00, 0x6B, 0x02, 0x00, 0x00, 0x00, 0x04,
11001 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
11002 0x42, 0x00, 0x92, 0x09, 0x00, 0x00, 0x00, 0x08,
11003 0x00, 0x00, 0x00, 0x00, 0x4F, 0x9A, 0x54, 0xE7,
11004 0x42, 0x00, 0x0D, 0x02, 0x00, 0x00, 0x00, 0x04,
11005 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
11006 0x42, 0x00, 0x0F, 0x01, 0x00, 0x00, 0x00, 0xD0,
11007 0x42, 0x00, 0x5C, 0x05, 0x00, 0x00, 0x00, 0x04,
11008 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00,
11009 0x42, 0x00, 0x7F, 0x05, 0x00, 0x00, 0x00, 0x04,
11010 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
11011 0x42, 0x00, 0x7C, 0x01, 0x00, 0x00, 0x00, 0xA8,
11012 0x42, 0x00, 0x57, 0x05, 0x00, 0x00, 0x00, 0x04,
11013 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
11014 0x42, 0x00, 0x94, 0x07, 0x00, 0x00, 0x00, 0x24,
11015 0x34, 0x39, 0x61, 0x31, 0x63, 0x61, 0x38, 0x38,
11016 0x2D, 0x36, 0x62, 0x65, 0x61, 0x2D, 0x34, 0x66,
11017 0x62, 0x32, 0x2D, 0x62, 0x34, 0x35, 0x30, 0x2D,
11018 0x37, 0x65, 0x35, 0x38, 0x38, 0x30, 0x32, 0x63,
11019 0x33, 0x30, 0x33, 0x38, 0x00, 0x00, 0x00, 0x00,
11020 0x42, 0x00, 0x8F, 0x01, 0x00, 0x00, 0x00, 0x60,
11021 0x42, 0x00, 0x40, 0x01, 0x00, 0x00, 0x00, 0x58,
11022 0x42, 0x00, 0x42, 0x05, 0x00, 0x00, 0x00, 0x04,
11023 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
11024 0x42, 0x00, 0x45, 0x01, 0x00, 0x00, 0x00, 0x20,
11025 0x42, 0x00, 0x43, 0x08, 0x00, 0x00, 0x00, 0x18,
11026 0x73, 0x67, 0x57, 0x80, 0x51, 0x01, 0x2A, 0x6D,
11027 0x13, 0x4A, 0x85, 0x5E, 0x25, 0xC8, 0xCD, 0x5E,
11028 0x4C, 0xA1, 0x31, 0x45, 0x57, 0x29, 0xD3, 0xC8,
11029 0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
11030 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
11031 0x42, 0x00, 0x2A, 0x02, 0x00, 0x00, 0x00, 0x04,
11032 0x00, 0x00, 0x00, 0xA8, 0x00, 0x00, 0x00, 0x00
11033 };
11034
11035 uint8 observed[304] = {0};
11036 struct kmip ctx = {0};
11037 kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_1_1);
11038
11039 struct protocol_version pv = {0};
11040 pv.major = 1;
11041 pv.minor = 1;
11042
11043 struct response_header rh = {0};
11044 kmip_init_response_header(&rh);
11045
11046 rh.protocol_version = &pv;
11047 rh.time_stamp = 1335514343;
11048 rh.batch_count = 1;
11049
11050 struct text_string uuid = {0};
11051 uuid.value = "49a1ca88-6bea-4fb2-b450-7e58802c3038";
11052 uuid.size = 36;
11053
11054 uint8 value[24] = {
11055 0x73, 0x67, 0x57, 0x80, 0x51, 0x01, 0x2A, 0x6D,
11056 0x13, 0x4A, 0x85, 0x5E, 0x25, 0xC8, 0xCD, 0x5E,
11057 0x4C, 0xA1, 0x31, 0x45, 0x57, 0x29, 0xD3, 0xC8
11058 };
11059
11060 struct byte_string v = {0};
11061 v.value = value;
11062 v.size = ARRAY_LENGTH(value);
11063
11064 struct key_value kv = {0};
11065 kv.key_material = &v;
11066
11067 struct key_block kb = {0};
11068 kb.key_format_type = KMIP_KEYFORMAT_RAW;
11069 kb.key_value = &kv;
11070 kb.cryptographic_algorithm = KMIP_CRYPTOALG_TRIPLE_DES;
11071 kb.cryptographic_length = 168;
11072
11073 struct symmetric_key key = {0};
11074 key.key_block = &kb;
11075
11076 struct get_response_payload grp = {0};
11077 grp.object_type = KMIP_OBJTYPE_SYMMETRIC_KEY;
11078 grp.unique_identifier = &uuid;
11079 grp.object = &key;
11080
11081 struct response_batch_item rbi = {0};
11082 rbi.operation = KMIP_OP_GET;
11083 rbi.result_status = KMIP_STATUS_SUCCESS;
11084 rbi.response_payload = &grp;
11085
11086 struct response_message rm = {0};
11087 rm.response_header = &rh;
11088 rm.batch_items = &rbi;
11089 rm.batch_count = 1;
11090
11091 int result = kmip_encode_response_message(&ctx, &rm);
11092 result = report_encoding_test_result(
11093 tracker,
11094 &ctx,
11095 expected,
11096 observed,
11097 result,
11098 __func__);
11099 kmip_destroy(&ctx);
11100 return(result);
11101 }
11102
11103 /* Test Harness */
11104
11105 int
11106 run_tests(void)
11107 {
11108 TestTracker tracker = {0};
11109
11110 printf("Tests\n");
11111 printf("=====\n");
11112
11113 printf("\nUtility Tests\n");
11114 printf("-------------\n");
11115 test_linked_list_pop(&tracker);
11116 test_linked_list_push(&tracker);
11117 test_linked_list_enqueue(&tracker);
11118 test_buffer_bytes_left(&tracker);
11119 test_peek_tag(&tracker);
11120 test_is_attribute_tag(&tracker);
11121 test_get_enum_string_index(&tracker);
11122 test_check_enum_value_protection_storage_masks(&tracker);
11123 test_init_protocol_version(&tracker);
11124 test_init_request_batch_item(&tracker);
11125 test_deep_copy_int32(&tracker);
11126 test_deep_copy_text_string(&tracker);
11127 test_deep_copy_name(&tracker);
11128 test_deep_copy_attribute(&tracker);
11129
11130 printf("\nKMIP 1.0 Feature Tests\n");
11131 printf("----------------------\n");
11132 test_buffer_full_and_resize(&tracker);
11133 test_is_tag_next(&tracker);
11134 test_get_num_items_next(&tracker);
11135 test_get_num_items_next_with_partial_item(&tracker);
11136 test_get_num_items_next_with_mismatch_item(&tracker);
11137 test_get_num_items_next_with_no_matches(&tracker);
11138 test_get_num_items_next_with_non_structures(&tracker);
11139
11140 printf("\n");
11141 test_decode_int8_be(&tracker);
11142 test_decode_int32_be(&tracker);
11143 test_decode_int64_be(&tracker);
11144 test_decode_integer(&tracker);
11145 test_decode_long(&tracker);
11146 test_decode_enum(&tracker);
11147 test_decode_bool(&tracker);
11148 test_decode_text_string(&tracker);
11149 test_decode_byte_string(&tracker);
11150 test_decode_date_time(&tracker);
11151 test_decode_interval(&tracker);
11152 test_decode_name(&tracker);
11153 test_decode_attribute_unique_identifier(&tracker);
11154 test_decode_attribute_name(&tracker);
11155 test_decode_attribute_object_type(&tracker);
11156 test_decode_attribute_cryptographic_algorithm(&tracker);
11157 test_decode_attribute_cryptographic_length(&tracker);
11158 test_decode_attribute_operation_policy_name(&tracker);
11159 test_decode_attribute_cryptographic_usage_mask(&tracker);
11160 test_decode_attribute_state(&tracker);
11161 test_decode_template_attribute(&tracker);
11162 test_decode_protocol_version(&tracker);
11163 test_decode_key_material_byte_string(&tracker);
11164 test_decode_key_material_transparent_symmetric_key(&tracker);
11165 test_decode_key_value(&tracker);
11166 test_decode_key_value_with_attributes(&tracker);
11167 test_decode_cryptographic_parameters(&tracker);
11168 test_decode_encryption_key_information(&tracker);
11169 test_decode_mac_signature_key_information(&tracker);
11170 test_decode_key_wrapping_data(&tracker);
11171 test_decode_key_block_key_value_byte_string(&tracker);
11172 test_decode_key_block_key_value_structure(&tracker);
11173 test_decode_symmetric_key(&tracker);
11174 test_decode_public_key(&tracker);
11175 test_decode_private_key(&tracker);
11176 test_decode_key_wrapping_specification(&tracker);
11177 test_decode_create_request_payload(&tracker);
11178 test_decode_create_response_payload(&tracker);
11179 test_decode_create_response_payload_with_template_attribute(&tracker);
11180 test_decode_get_request_payload(&tracker);
11181 test_decode_get_response_payload(&tracker);
11182 test_decode_destroy_request_payload(&tracker);
11183 test_decode_destroy_response_payload(&tracker);
11184 test_decode_response_batch_item_get_payload(&tracker);
11185 test_decode_username_password_credential(&tracker);
11186 test_decode_credential_username_password_credential(&tracker);
11187 test_decode_authentication_username_password_credential(&tracker);
11188 test_decode_request_header(&tracker);
11189 test_decode_response_header(&tracker);
11190 test_decode_request_batch_item_get_payload(&tracker);
11191 test_decode_request_message_get(&tracker);
11192 test_decode_response_message_get(&tracker);
11193
11194 printf("\n");
11195 test_encode_integer(&tracker);
11196 test_encode_long(&tracker);
11197 test_encode_enum(&tracker);
11198 test_encode_bool(&tracker);
11199 test_encode_text_string(&tracker);
11200 test_encode_byte_string(&tracker);
11201 test_encode_date_time(&tracker);
11202 test_encode_interval(&tracker);
11203 test_encode_name(&tracker);
11204 test_encode_attribute_unique_identifier(&tracker);
11205 test_encode_attribute_name(&tracker);
11206 test_encode_attribute_object_type(&tracker);
11207 test_encode_attribute_cryptographic_algorithm(&tracker);
11208 test_encode_attribute_cryptographic_length(&tracker);
11209 test_encode_attribute_operation_policy_name(&tracker);
11210 test_encode_attribute_cryptographic_usage_mask(&tracker);
11211 test_encode_attribute_state(&tracker);
11212 test_encode_protocol_version(&tracker);
11213 test_encode_cryptographic_parameters(&tracker);
11214 test_encode_encryption_key_information(&tracker);
11215 test_encode_mac_signature_key_information(&tracker);
11216 test_encode_key_wrapping_data(&tracker);
11217 test_encode_key_material_byte_string(&tracker);
11218 test_encode_key_material_transparent_symmetric_key(&tracker);
11219 test_encode_key_value(&tracker);
11220 test_encode_key_value_with_attributes(&tracker);
11221 test_encode_key_block_key_value_byte_string(&tracker);
11222 test_encode_key_block_key_value_structure(&tracker);
11223 test_encode_symmetric_key(&tracker);
11224 test_encode_public_key(&tracker);
11225 test_encode_private_key(&tracker);
11226 test_encode_key_wrapping_specification(&tracker);
11227 test_encode_create_request_payload(&tracker);
11228 test_encode_create_response_payload(&tracker);
11229 test_encode_create_response_payload_with_template_attribute(&tracker);
11230 test_encode_get_request_payload(&tracker);
11231 test_encode_get_request_payload_with_format_compression(&tracker);
11232 test_encode_get_request_payload_with_wrapping_spec(&tracker);
11233 test_encode_get_response_payload(&tracker);
11234 test_encode_destroy_request_payload(&tracker);
11235 test_encode_destroy_response_payload(&tracker);
11236 test_encode_username_password_credential(&tracker);
11237 test_encode_credential_username_password_credential(&tracker);
11238 test_encode_authentication_username_password_credential(&tracker);
11239 test_encode_request_header(&tracker);
11240 test_encode_response_header(&tracker);
11241 test_encode_request_batch_item_get_payload(&tracker);
11242 test_encode_response_batch_item_get_payload(&tracker);
11243 test_encode_request_message_get(&tracker);
11244 test_encode_response_message_get(&tracker);
11245 test_encode_template_attribute(&tracker);
11246
11247 printf("\nKMIP 1.1 Feature Tests\n");
11248 printf("----------------------\n");
11249 test_decode_device_credential(&tracker);
11250 test_decode_key_wrapping_data_with_encoding_option(&tracker);
11251
11252 printf("\n");
11253 test_encode_device_credential(&tracker);
11254 test_encode_key_wrapping_data_with_encoding_option(&tracker);
11255 test_encode_key_wrapping_specification_with_encoding_option(&tracker);
11256
11257 printf("\nKMIP 1.1 Test Suite Test Cases\n");
11258 printf("------------------------------\n");
11259 test_kmip_1_1_test_suite_3_1_1_0_a(&tracker);
11260 test_kmip_1_1_test_suite_3_1_1_0_b(&tracker);
11261 test_kmip_1_1_test_suite_3_1_1_1_a(&tracker);
11262 test_kmip_1_1_test_suite_3_1_1_1_b(&tracker);
11263 test_kmip_1_1_test_suite_3_1_3_2_a(&tracker);
11264 test_kmip_1_1_test_suite_3_1_3_2_b(&tracker);
11265
11266 printf("\nKMIP 1.2 Feature Tests\n");
11267 printf("----------------------\n");
11268 test_decode_nonce(&tracker);
11269 test_decode_attestation_credential(&tracker);
11270 test_decode_response_header_with_attestation_details(&tracker);
11271 test_decode_cryptographic_parameters_with_digital_signature_fields(&tracker);
11272
11273 printf("\n");
11274 test_encode_nonce(&tracker);
11275 test_encode_attestation_credential(&tracker);
11276 test_encode_request_header_with_attestation_details(&tracker);
11277 test_encode_response_header_with_attestation_details(&tracker);
11278 test_encode_cryptographic_parameters_with_digital_signature_fields(&tracker);
11279
11280 printf("\nKMIP 1.4 Feature Tests\n");
11281 printf("----------------------\n");
11282 test_decode_cryptographic_parameters_with_mask_fields(&tracker);
11283 test_decode_response_header_with_correlation_values(&tracker);
11284
11285 printf("\n");
11286 test_encode_cryptographic_parameters_with_mask_fields(&tracker);
11287 test_encode_get_request_payload_with_wrap_type(&tracker);
11288 test_encode_request_header_with_correlation_values(&tracker);
11289 test_encode_response_header_with_correlation_values(&tracker);
11290
11291 printf("\nKMIP 2.0 Feature Tests\n");
11292 printf("----------------------\n");
11293 test_decode_protection_storage_masks(&tracker);
11294 test_decode_attributes(&tracker);
11295 test_decode_attributes_with_invalid_kmip_version(&tracker);
11296 test_decode_attribute_v2_unique_identifier(&tracker);
11297 test_decode_attribute_v2_name(&tracker);
11298 test_decode_attribute_v2_object_type(&tracker);
11299 test_decode_attribute_v2_cryptographic_algorithm(&tracker);
11300 test_decode_attribute_v2_cryptographic_length(&tracker);
11301 test_decode_attribute_v2_cryptographic_usage_mask(&tracker);
11302 test_decode_attribute_v2_state(&tracker);
11303 test_decode_attribute_v2_unsupported_attribute(&tracker);
11304 test_decode_create_request_payload_kmip_2_0(&tracker);
11305 test_decode_request_batch_item_get_payload_kmip_2_0(&tracker);
11306 test_decode_response_header_kmip_2_0(&tracker);
11307
11308 printf("\n");
11309 test_encode_protection_storage_masks(&tracker);
11310 test_encode_attributes(&tracker);
11311 test_encode_attributes_with_invalid_kmip_version(&tracker);
11312 test_encode_attribute_v2_unique_identifier(&tracker);
11313 test_encode_attribute_v2_name(&tracker);
11314 test_encode_attribute_v2_object_type(&tracker);
11315 test_encode_attribute_v2_cryptographic_algorithm(&tracker);
11316 test_encode_attribute_v2_cryptographic_length(&tracker);
11317 test_encode_attribute_v2_cryptographic_usage_mask(&tracker);
11318 test_encode_attribute_v2_state(&tracker);
11319 test_encode_attribute_v2_unsupported_attribute(&tracker);
11320 test_encode_create_request_payload_kmip_2_0(&tracker);
11321 test_encode_request_batch_item_get_payload_kmip_2_0(&tracker);
11322 test_encode_response_header_kmip_2_0(&tracker);
11323
11324 printf("\nSummary\n");
11325 printf("================\n");
11326 printf("Total tests: %u\n", tracker.test_count);
11327 printf(" PASS: %u\n", tracker.tests_passed);
11328 printf(" FAILURE: %u\n", tracker.tests_failed);
11329
11330 return(tracker.tests_failed);
11331 }
11332
11333 void
11334 print_help(const char *app)
11335 {
11336 printf("Usage: %s [flag] ...\n\n", app);
11337 printf("Flags:\n");
11338 printf("-h : print this help info\n");
11339 printf("-i : run the test suite forever\n");
11340 }
11341
11342 int
11343 parse_arguments(int argc,
11344 char **argv,
11345 int *print_usage,
11346 int *run_forever)
11347 {
11348 for(int i = 1; i < argc; i++)
11349 {
11350 if(strncmp(argv[i], "-h", 2) == 0)
11351 {
11352 *print_usage = 1;
11353 }
11354 else if(strncmp(argv[i], "-i", 2) == 0)
11355 {
11356 *run_forever = 1;
11357 }
11358 else
11359 {
11360 printf("Invalid option: '%s'\n", argv[i]);
11361 print_help(argv[0]);
11362 return(-1);
11363 }
11364 }
11365
11366 return(0);
11367 }
11368
11369 int
11370 main(int argc, char **argv)
11371 {
11372 int print_usage = 0;
11373 int run_forever = 0;
11374
11375 int error = parse_arguments(argc, argv, &print_usage, &run_forever);
11376 if(error)
11377 {
11378 return(error);
11379 }
11380 if(print_usage)
11381 {
11382 print_help(argv[0]);
11383 return(0);
11384 }
11385
11386 int results = 0;
11387 if(run_forever)
11388 {
11389 while(1)
11390 {
11391 run_tests();
11392 }
11393 }
11394 else
11395 {
11396 results = run_tests();
11397 }
11398
11399 return(results);
11400 }