VirtualBox

source: vbox/trunk/src/libs/openssl-3.3.2/test/pkcs12_format_test.c@ 108358

最後變更 在這個檔案從108358是 108206,由 vboxsync 提交於 5 週 前

openssl-3.3.2: Exported all files to OSE and removed .scm-settings ​bugref:10757

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 37.5 KB
 
1/*
2 * Copyright 2020-2023 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10#include <stdio.h>
11#include <string.h>
12#include <stdlib.h>
13
14#include <openssl/pkcs12.h>
15#include <openssl/x509.h>
16#include <openssl/x509v3.h>
17#include <openssl/pem.h>
18
19#include "testutil.h"
20#include "helpers/pkcs12.h"
21
22static int default_libctx = 1;
23
24static OSSL_LIB_CTX *testctx = NULL;
25static OSSL_PROVIDER *nullprov = NULL;
26static OSSL_PROVIDER *deflprov = NULL;
27static OSSL_PROVIDER *lgcyprov = NULL;
28
29/* --------------------------------------------------------------------------
30 * PKCS12 component test data
31 */
32
33static const unsigned char CERT1[] =
34{
35 0x30, 0x82, 0x01, 0xed, 0x30, 0x82, 0x01, 0x56, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00,
36 0x8b, 0x4b, 0x5e, 0x6c, 0x03, 0x28, 0x4e, 0xe6, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
37 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x19, 0x31, 0x17, 0x30, 0x15, 0x06, 0x03, 0x55,
38 0x04, 0x03, 0x0c, 0x0e, 0x50, 0x31, 0x32, 0x54, 0x65, 0x73, 0x74, 0x2d, 0x52, 0x6f, 0x6f, 0x74,
39 0x2d, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x39, 0x30, 0x39, 0x33, 0x30, 0x30, 0x30, 0x34, 0x36,
40 0x35, 0x36, 0x5a, 0x17, 0x0d, 0x32, 0x39, 0x30, 0x39, 0x32, 0x37, 0x30, 0x30, 0x34, 0x36, 0x35,
41 0x36, 0x5a, 0x30, 0x1b, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x10, 0x50,
42 0x31, 0x32, 0x54, 0x65, 0x73, 0x74, 0x2d, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2d, 0x31, 0x30,
43 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05,
44 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xbc, 0xdc, 0x6f, 0x8c,
45 0x7a, 0x2a, 0x4b, 0xea, 0x66, 0x66, 0x04, 0xa9, 0x05, 0x92, 0x53, 0xd7, 0x13, 0x3c, 0x49, 0xe1,
46 0xc8, 0xbb, 0xdf, 0x3d, 0xcb, 0x88, 0x31, 0x07, 0x20, 0x59, 0x93, 0x24, 0x7f, 0x7d, 0xc6, 0x84,
47 0x81, 0x16, 0x64, 0x4a, 0x52, 0xa6, 0x30, 0x44, 0xdc, 0x1a, 0x30, 0xde, 0xae, 0x29, 0x18, 0xcf,
48 0xc7, 0xf3, 0xcf, 0x0c, 0xb7, 0x8e, 0x2b, 0x1e, 0x21, 0x01, 0x0b, 0xfb, 0xe5, 0xe6, 0xcf, 0x2b,
49 0x84, 0xe1, 0x33, 0xf8, 0xba, 0x02, 0xfc, 0x30, 0xfa, 0xc4, 0x33, 0xc7, 0x37, 0xc6, 0x7f, 0x72,
50 0x31, 0x92, 0x1d, 0x8f, 0xa0, 0xfb, 0xe5, 0x4a, 0x08, 0x31, 0x78, 0x80, 0x9c, 0x23, 0xb4, 0xe9,
51 0x19, 0x56, 0x04, 0xfa, 0x0d, 0x07, 0x04, 0xb7, 0x43, 0xac, 0x4c, 0x49, 0x7c, 0xc2, 0xa1, 0x44,
52 0xc1, 0x48, 0x7d, 0x28, 0xe5, 0x23, 0x66, 0x07, 0x22, 0xd5, 0xf0, 0xf1, 0x02, 0x03, 0x01, 0x00,
53 0x01, 0xa3, 0x3b, 0x30, 0x39, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16,
54 0x80, 0x14, 0xdb, 0xbb, 0xb8, 0x92, 0x4e, 0x24, 0x0b, 0x1b, 0xbb, 0x78, 0x33, 0xf9, 0x01, 0x02,
55 0x23, 0x0d, 0x96, 0x18, 0x30, 0x47, 0x30, 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30,
56 0x00, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x04, 0x04, 0x03, 0x02, 0x04, 0xf0, 0x30, 0x0d,
57 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x81, 0x81,
58 0x00, 0x1c, 0x13, 0xdc, 0x02, 0xf1, 0x44, 0x36, 0x65, 0xa9, 0xbe, 0x30, 0x1c, 0x66, 0x14, 0x20,
59 0x86, 0x5a, 0xa8, 0x69, 0x25, 0xf8, 0x1a, 0xb6, 0x9e, 0x5e, 0xe9, 0x89, 0xb8, 0x67, 0x70, 0x19,
60 0x87, 0x60, 0xeb, 0x4b, 0x11, 0x71, 0x85, 0xf8, 0xe9, 0xa7, 0x3e, 0x20, 0x42, 0xec, 0x43, 0x25,
61 0x01, 0x03, 0xe5, 0x4d, 0x83, 0x22, 0xf5, 0x8e, 0x3a, 0x1a, 0x1b, 0xd4, 0x1c, 0xda, 0x6b, 0x9d,
62 0x10, 0x1b, 0xee, 0x67, 0x4e, 0x1f, 0x69, 0xab, 0xbc, 0xaa, 0x62, 0x8e, 0x9e, 0xc6, 0xee, 0xd6,
63 0x09, 0xc0, 0xca, 0xe0, 0xaa, 0x9f, 0x07, 0xb2, 0xc2, 0xbb, 0x31, 0x96, 0xa2, 0x04, 0x62, 0xd3,
64 0x13, 0x32, 0x29, 0x67, 0x6e, 0xad, 0x2e, 0x0b, 0xea, 0x04, 0x7c, 0x8c, 0x5a, 0x5d, 0xac, 0x14,
65 0xaa, 0x61, 0x7f, 0x28, 0x6c, 0x2d, 0x64, 0x2d, 0xc3, 0xaf, 0x77, 0x52, 0x90, 0xb4, 0x37, 0xc0,
66 0x30,
67};
68
69static const unsigned char CERT2[] =
70{
71 0x30, 0x82, 0x01, 0xed, 0x30, 0x82, 0x01, 0x56, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00,
72 0x8b, 0x4b, 0x5e, 0x6c, 0x03, 0x28, 0x4e, 0xe7, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
73 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x19, 0x31, 0x17, 0x30, 0x15, 0x06, 0x03, 0x55,
74 0x04, 0x03, 0x0c, 0x0e, 0x50, 0x31, 0x32, 0x54, 0x65, 0x73, 0x74, 0x2d, 0x52, 0x6f, 0x6f, 0x74,
75 0x2d, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x39, 0x30, 0x39, 0x33, 0x30, 0x30, 0x30, 0x34, 0x36,
76 0x35, 0x36, 0x5a, 0x17, 0x0d, 0x32, 0x39, 0x30, 0x39, 0x32, 0x37, 0x30, 0x30, 0x34, 0x36, 0x35,
77 0x36, 0x5a, 0x30, 0x1b, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x10, 0x50,
78 0x31, 0x32, 0x54, 0x65, 0x73, 0x74, 0x2d, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2d, 0x31, 0x30,
79 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05,
80 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xa8, 0x6e, 0x40, 0x86,
81 0x9f, 0x98, 0x59, 0xfb, 0x57, 0xbf, 0xc1, 0x55, 0x12, 0x38, 0xeb, 0xb3, 0x46, 0x34, 0xc9, 0x35,
82 0x4d, 0xfd, 0x03, 0xe9, 0x3a, 0x88, 0x9e, 0x97, 0x8f, 0xf4, 0xec, 0x36, 0x7b, 0x3f, 0xba, 0xb8,
83 0xa5, 0x96, 0x30, 0x03, 0xc5, 0xc6, 0xd9, 0xa8, 0x4e, 0xbc, 0x23, 0x51, 0xa1, 0x96, 0xd2, 0x03,
84 0x98, 0x73, 0xb6, 0x17, 0x9c, 0x77, 0xd4, 0x95, 0x1e, 0x1b, 0xb3, 0x1b, 0xc8, 0x71, 0xd1, 0x2e,
85 0x31, 0xc7, 0x6a, 0x75, 0x57, 0x08, 0x7f, 0xba, 0x70, 0x76, 0xf7, 0x67, 0xf4, 0x4e, 0xbe, 0xfc,
86 0x70, 0x61, 0x41, 0x07, 0x2b, 0x7c, 0x3c, 0x3b, 0xb3, 0xbc, 0xd5, 0xa8, 0xbd, 0x28, 0xd8, 0x49,
87 0xd3, 0xe1, 0x78, 0xc8, 0xc1, 0x42, 0x5e, 0x18, 0x36, 0xa8, 0x41, 0xf7, 0xc8, 0xaa, 0x35, 0xfe,
88 0x2d, 0xd1, 0xb4, 0xcc, 0x00, 0x67, 0xae, 0x79, 0xd3, 0x28, 0xd5, 0x5b, 0x02, 0x03, 0x01, 0x00,
89 0x01, 0xa3, 0x3b, 0x30, 0x39, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16,
90 0x80, 0x14, 0xdb, 0xbb, 0xb8, 0x92, 0x4e, 0x24, 0x0b, 0x1b, 0xbb, 0x78, 0x33, 0xf9, 0x01, 0x02,
91 0x23, 0x0d, 0x96, 0x18, 0x30, 0x47, 0x30, 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30,
92 0x00, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x04, 0x04, 0x03, 0x02, 0x04, 0xf0, 0x30, 0x0d,
93 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x81, 0x81,
94 0x00, 0x3b, 0xa6, 0x73, 0xbe, 0xe0, 0x28, 0xed, 0x1f, 0x29, 0x78, 0x4c, 0xc0, 0x1f, 0xe9, 0x85,
95 0xc6, 0x8f, 0xe3, 0x87, 0x7c, 0xd9, 0xe7, 0x0a, 0x37, 0xe8, 0xaa, 0xb5, 0xd2, 0x7f, 0xf8, 0x90,
96 0x20, 0x80, 0x35, 0xa7, 0x79, 0x2b, 0x04, 0xa7, 0xbf, 0xe6, 0x7b, 0x58, 0xcb, 0xec, 0x0e, 0x58,
97 0xef, 0x2a, 0x70, 0x8a, 0x56, 0x8a, 0xcf, 0x6b, 0x7a, 0x74, 0x0c, 0xf4, 0x15, 0x37, 0x93, 0xcd,
98 0xe6, 0xb2, 0xa1, 0x83, 0x09, 0xdb, 0x9e, 0x4f, 0xff, 0x6a, 0x17, 0x4f, 0x33, 0xc9, 0xcc, 0x90,
99 0x2a, 0x67, 0xff, 0x16, 0x78, 0xa8, 0x2c, 0x10, 0xe0, 0x52, 0x8c, 0xe6, 0xe9, 0x90, 0x8d, 0xe0,
100 0x62, 0x04, 0x9a, 0x0f, 0x44, 0x01, 0x82, 0x14, 0x92, 0x44, 0x25, 0x69, 0x22, 0xb7, 0xb8, 0xc5,
101 0x94, 0x4c, 0x4b, 0x1c, 0x9b, 0x92, 0x60, 0x66, 0x90, 0x4e, 0xb9, 0xa8, 0x4c, 0x89, 0xbb, 0x0f,
102 0x0b,
103};
104
105static const unsigned char KEY1[] =
106{
107 0x30, 0x82, 0x02, 0x5d, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xbc, 0xdc, 0x6f, 0x8c, 0x7a,
108 0x2a, 0x4b, 0xea, 0x66, 0x66, 0x04, 0xa9, 0x05, 0x92, 0x53, 0xd7, 0x13, 0x3c, 0x49, 0xe1, 0xc8,
109 0xbb, 0xdf, 0x3d, 0xcb, 0x88, 0x31, 0x07, 0x20, 0x59, 0x93, 0x24, 0x7f, 0x7d, 0xc6, 0x84, 0x81,
110 0x16, 0x64, 0x4a, 0x52, 0xa6, 0x30, 0x44, 0xdc, 0x1a, 0x30, 0xde, 0xae, 0x29, 0x18, 0xcf, 0xc7,
111 0xf3, 0xcf, 0x0c, 0xb7, 0x8e, 0x2b, 0x1e, 0x21, 0x01, 0x0b, 0xfb, 0xe5, 0xe6, 0xcf, 0x2b, 0x84,
112 0xe1, 0x33, 0xf8, 0xba, 0x02, 0xfc, 0x30, 0xfa, 0xc4, 0x33, 0xc7, 0x37, 0xc6, 0x7f, 0x72, 0x31,
113 0x92, 0x1d, 0x8f, 0xa0, 0xfb, 0xe5, 0x4a, 0x08, 0x31, 0x78, 0x80, 0x9c, 0x23, 0xb4, 0xe9, 0x19,
114 0x56, 0x04, 0xfa, 0x0d, 0x07, 0x04, 0xb7, 0x43, 0xac, 0x4c, 0x49, 0x7c, 0xc2, 0xa1, 0x44, 0xc1,
115 0x48, 0x7d, 0x28, 0xe5, 0x23, 0x66, 0x07, 0x22, 0xd5, 0xf0, 0xf1, 0x02, 0x03, 0x01, 0x00, 0x01,
116 0x02, 0x81, 0x81, 0x00, 0xa5, 0x6d, 0xf9, 0x8f, 0xf5, 0x5a, 0xa3, 0x50, 0xd9, 0x0d, 0x37, 0xbb,
117 0xce, 0x13, 0x94, 0xb8, 0xea, 0x32, 0x7f, 0x0c, 0xf5, 0x46, 0x0b, 0x90, 0x17, 0x7e, 0x5e, 0x63,
118 0xbd, 0xa4, 0x78, 0xcd, 0x19, 0x97, 0xd4, 0x92, 0x30, 0x78, 0xaa, 0xb4, 0xa7, 0x9c, 0xc6, 0xdf,
119 0x2a, 0x65, 0x0e, 0xb5, 0x9f, 0x9c, 0x84, 0x0d, 0x4d, 0x3a, 0x74, 0xfc, 0xd0, 0xb4, 0x09, 0x74,
120 0xc4, 0xb8, 0x24, 0x03, 0xa8, 0xf0, 0xf8, 0x0d, 0x5c, 0x8e, 0xdf, 0x4b, 0xe1, 0x0a, 0x8f, 0x4f,
121 0xd5, 0xc7, 0x9b, 0x54, 0x55, 0x8f, 0x00, 0x5c, 0xea, 0x4c, 0x73, 0xf9, 0x1b, 0xbf, 0xb8, 0x93,
122 0x33, 0x20, 0xce, 0x45, 0xd9, 0x03, 0x02, 0xb2, 0x36, 0xc5, 0x0a, 0x30, 0x50, 0x78, 0x80, 0x66,
123 0x00, 0x22, 0x38, 0x86, 0xcf, 0x63, 0x4a, 0x5c, 0xbf, 0x2b, 0xd9, 0x6e, 0xe6, 0xf0, 0x39, 0xad,
124 0x12, 0x25, 0x41, 0xb9, 0x02, 0x41, 0x00, 0xf3, 0x7c, 0x07, 0x99, 0x64, 0x3a, 0x28, 0x8c, 0x8d,
125 0x05, 0xfe, 0x32, 0xb5, 0x4c, 0x8c, 0x6d, 0xde, 0x3d, 0x16, 0x08, 0xa0, 0x01, 0x61, 0x4f, 0x8e,
126 0xa0, 0xf7, 0x26, 0x26, 0xb5, 0x8e, 0xc0, 0x7a, 0xce, 0x86, 0x34, 0xde, 0xb8, 0xef, 0x86, 0x01,
127 0xbe, 0x24, 0xaa, 0x9b, 0x36, 0x93, 0x72, 0x9b, 0xf9, 0xc6, 0xcb, 0x76, 0x84, 0x67, 0x06, 0x06,
128 0x30, 0x50, 0xdf, 0x42, 0x17, 0xe0, 0xa7, 0x02, 0x41, 0x00, 0xc6, 0x91, 0xa0, 0x41, 0x34, 0x11,
129 0x67, 0x4b, 0x08, 0x0f, 0xda, 0xa7, 0x99, 0xec, 0x58, 0x11, 0xa5, 0x82, 0xdb, 0x50, 0xfe, 0x77,
130 0xe2, 0xd1, 0x53, 0x9c, 0x7d, 0xe8, 0xbf, 0xe7, 0x7c, 0xa9, 0x01, 0xb1, 0x87, 0xc3, 0x52, 0x79,
131 0x9e, 0x2c, 0xa7, 0x6f, 0x02, 0x37, 0x32, 0xef, 0x24, 0x31, 0x21, 0x0b, 0x86, 0x05, 0x32, 0x4a,
132 0x2e, 0x0b, 0x65, 0x05, 0xd3, 0xd6, 0x30, 0xb2, 0xfc, 0xa7, 0x02, 0x41, 0x00, 0xc2, 0xed, 0x31,
133 0xdc, 0x40, 0x9c, 0x3a, 0xe8, 0x42, 0xe2, 0x60, 0x5e, 0x52, 0x3c, 0xc5, 0x54, 0x14, 0x0e, 0x8d,
134 0x7c, 0x3c, 0x34, 0xbe, 0xa6, 0x05, 0x86, 0xa2, 0x36, 0x5d, 0xd9, 0x0e, 0x3e, 0xd4, 0x52, 0x50,
135 0xa9, 0x35, 0x01, 0x93, 0x68, 0x92, 0x2e, 0x9a, 0x86, 0x27, 0x1a, 0xab, 0x32, 0x9e, 0xe2, 0x79,
136 0x9f, 0x5b, 0xf3, 0xa5, 0xd2, 0xf1, 0xd3, 0x6e, 0x7b, 0x3e, 0x1b, 0x85, 0x93, 0x02, 0x40, 0x68,
137 0xb8, 0xb6, 0x7e, 0x8c, 0xba, 0x3c, 0xf2, 0x8a, 0x2e, 0xea, 0x4f, 0x07, 0xd3, 0x68, 0x62, 0xee,
138 0x1a, 0x04, 0x16, 0x44, 0x0d, 0xef, 0xf6, 0x1b, 0x95, 0x65, 0xa5, 0xd1, 0x47, 0x81, 0x2c, 0x14,
139 0xb3, 0x8e, 0xf9, 0x08, 0xcf, 0x11, 0x07, 0x55, 0xca, 0x2a, 0xad, 0xf7, 0xd3, 0xbd, 0x0f, 0x97,
140 0xf0, 0xde, 0xde, 0x70, 0xb6, 0x44, 0x70, 0x47, 0xf7, 0xf9, 0xcf, 0x75, 0x61, 0x7f, 0xf3, 0x02,
141 0x40, 0x38, 0x4a, 0x67, 0xaf, 0xae, 0xb6, 0xb2, 0x6a, 0x00, 0x25, 0x5a, 0xa4, 0x65, 0x20, 0xb1,
142 0x13, 0xbd, 0x83, 0xff, 0xb4, 0xbc, 0xf4, 0xdd, 0xa1, 0xbb, 0x1c, 0x96, 0x37, 0x35, 0xf4, 0xbf,
143 0xed, 0x4c, 0xed, 0x92, 0xe8, 0xac, 0xc9, 0xc1, 0xa5, 0xa3, 0x23, 0x66, 0x40, 0x8a, 0xa1, 0xe6,
144 0xe3, 0x95, 0xfe, 0xc4, 0x53, 0xf5, 0x7d, 0x6e, 0xca, 0x45, 0x42, 0xe4, 0xc2, 0x9f, 0xe5, 0x1e,
145 0xb5,
146};
147
148
149static const unsigned char KEY2[] =
150{
151 0x30, 0x82, 0x02, 0x5c, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xa8, 0x6e, 0x40, 0x86, 0x9f,
152 0x98, 0x59, 0xfb, 0x57, 0xbf, 0xc1, 0x55, 0x12, 0x38, 0xeb, 0xb3, 0x46, 0x34, 0xc9, 0x35, 0x4d,
153 0xfd, 0x03, 0xe9, 0x3a, 0x88, 0x9e, 0x97, 0x8f, 0xf4, 0xec, 0x36, 0x7b, 0x3f, 0xba, 0xb8, 0xa5,
154 0x96, 0x30, 0x03, 0xc5, 0xc6, 0xd9, 0xa8, 0x4e, 0xbc, 0x23, 0x51, 0xa1, 0x96, 0xd2, 0x03, 0x98,
155 0x73, 0xb6, 0x17, 0x9c, 0x77, 0xd4, 0x95, 0x1e, 0x1b, 0xb3, 0x1b, 0xc8, 0x71, 0xd1, 0x2e, 0x31,
156 0xc7, 0x6a, 0x75, 0x57, 0x08, 0x7f, 0xba, 0x70, 0x76, 0xf7, 0x67, 0xf4, 0x4e, 0xbe, 0xfc, 0x70,
157 0x61, 0x41, 0x07, 0x2b, 0x7c, 0x3c, 0x3b, 0xb3, 0xbc, 0xd5, 0xa8, 0xbd, 0x28, 0xd8, 0x49, 0xd3,
158 0xe1, 0x78, 0xc8, 0xc1, 0x42, 0x5e, 0x18, 0x36, 0xa8, 0x41, 0xf7, 0xc8, 0xaa, 0x35, 0xfe, 0x2d,
159 0xd1, 0xb4, 0xcc, 0x00, 0x67, 0xae, 0x79, 0xd3, 0x28, 0xd5, 0x5b, 0x02, 0x03, 0x01, 0x00, 0x01,
160 0x02, 0x81, 0x81, 0x00, 0xa6, 0x00, 0x83, 0xf8, 0x2b, 0x33, 0xac, 0xfb, 0xdb, 0xf0, 0x52, 0x4b,
161 0xd6, 0x39, 0xe3, 0x94, 0x3d, 0x8d, 0xa9, 0x01, 0xb0, 0x6b, 0xbe, 0x7f, 0x10, 0x01, 0xb6, 0xcd,
162 0x0a, 0x45, 0x0a, 0xca, 0x67, 0x8e, 0xd8, 0x29, 0x44, 0x8a, 0x51, 0xa8, 0x66, 0x35, 0x26, 0x30,
163 0x8b, 0xe9, 0x41, 0xa6, 0x22, 0xec, 0xd2, 0xf0, 0x58, 0x41, 0x33, 0x26, 0xf2, 0x3f, 0xe8, 0x75,
164 0x4f, 0xc7, 0x5d, 0x2e, 0x5a, 0xa8, 0x7a, 0xd2, 0xbf, 0x59, 0xa0, 0x86, 0x79, 0x0b, 0x92, 0x6c,
165 0x95, 0x5d, 0x87, 0x63, 0x5c, 0xd6, 0x1a, 0xc0, 0xf6, 0x7a, 0x15, 0x8d, 0xc7, 0x3c, 0xb6, 0x9e,
166 0xa6, 0x58, 0x46, 0x9b, 0xbf, 0x3e, 0x28, 0x8c, 0xdf, 0x1a, 0x87, 0xaa, 0x7e, 0xf5, 0xf2, 0xcb,
167 0x5e, 0x84, 0x2d, 0xf6, 0x82, 0x7e, 0x89, 0x4e, 0xf5, 0xe6, 0x3c, 0x92, 0x80, 0x1e, 0x98, 0x1c,
168 0x6a, 0x7b, 0x57, 0x01, 0x02, 0x41, 0x00, 0xdd, 0x60, 0x95, 0xd7, 0xa1, 0x9d, 0x0c, 0xa1, 0x84,
169 0xc5, 0x39, 0xca, 0x67, 0x4c, 0x1c, 0x06, 0x71, 0x5b, 0x5c, 0x2d, 0x8d, 0xce, 0xcd, 0xe2, 0x79,
170 0xc8, 0x33, 0xbe, 0x50, 0x37, 0x60, 0x9f, 0x3b, 0xb9, 0x59, 0x55, 0x22, 0x1f, 0xa5, 0x4b, 0x1d,
171 0xca, 0x38, 0xa0, 0xab, 0x87, 0x9c, 0x86, 0x0e, 0xdb, 0x1c, 0x4f, 0x4f, 0x07, 0xed, 0x18, 0x3f,
172 0x05, 0x3c, 0xec, 0x78, 0x11, 0xf6, 0x99, 0x02, 0x41, 0x00, 0xc2, 0xc5, 0xcf, 0xbe, 0x95, 0x91,
173 0xeb, 0xcf, 0x47, 0xf3, 0x33, 0x32, 0xc7, 0x7e, 0x93, 0x56, 0xf7, 0xd8, 0xf9, 0xd4, 0xb6, 0xd6,
174 0x20, 0xac, 0xba, 0x8a, 0x20, 0x19, 0x14, 0xab, 0xc5, 0x5d, 0xb2, 0x08, 0xcc, 0x77, 0x7c, 0x65,
175 0xa8, 0xdb, 0x66, 0x97, 0x36, 0x44, 0x2c, 0x63, 0xc0, 0x6a, 0x7e, 0xb0, 0x0b, 0x5c, 0x90, 0x12,
176 0x50, 0xb4, 0x36, 0x60, 0xc3, 0x1f, 0x22, 0x0c, 0xc8, 0x13, 0x02, 0x40, 0x33, 0xc8, 0x7e, 0x04,
177 0x7c, 0x97, 0x61, 0xf6, 0xfe, 0x39, 0xac, 0x34, 0xfe, 0x48, 0xbd, 0x5d, 0x7c, 0x72, 0xa4, 0x73,
178 0x3b, 0x72, 0x9e, 0x92, 0x55, 0x6e, 0x51, 0x3c, 0x39, 0x43, 0x5a, 0xe4, 0xa4, 0x71, 0xcc, 0xc5,
179 0xaf, 0x3f, 0xbb, 0xc8, 0x80, 0x65, 0x67, 0x2d, 0x9e, 0x32, 0x10, 0x99, 0x03, 0x2c, 0x99, 0xc8,
180 0xab, 0x71, 0xed, 0x31, 0xf8, 0xbb, 0xde, 0xee, 0x69, 0x7f, 0xba, 0x31, 0x02, 0x40, 0x7e, 0xbc,
181 0x60, 0x55, 0x4e, 0xd5, 0xc8, 0x6e, 0xf4, 0x0e, 0x57, 0xbe, 0x2e, 0xf9, 0x39, 0xbe, 0x59, 0x3f,
182 0xa2, 0x30, 0xbb, 0x57, 0xd1, 0xa3, 0x13, 0x2e, 0x55, 0x7c, 0x7c, 0x6a, 0xd8, 0xde, 0x02, 0xbe,
183 0x9e, 0xed, 0x10, 0xd0, 0xc5, 0x73, 0x1d, 0xea, 0x3e, 0xb1, 0x55, 0x81, 0x02, 0xef, 0x48, 0xc8,
184 0x1c, 0x5c, 0x7a, 0x92, 0xb0, 0x58, 0xd3, 0x19, 0x5b, 0x5d, 0xa2, 0xb6, 0x56, 0x69, 0x02, 0x40,
185 0x1e, 0x00, 0x6a, 0x9f, 0xba, 0xee, 0x46, 0x5a, 0xc5, 0xb5, 0x9f, 0x91, 0x33, 0xdd, 0xc9, 0x96,
186 0x75, 0xb7, 0x87, 0xcf, 0x18, 0x1c, 0xb7, 0xb9, 0x3f, 0x04, 0x10, 0xb8, 0x75, 0xa9, 0xb8, 0xa0,
187 0x31, 0x35, 0x03, 0x30, 0x89, 0xc8, 0x37, 0x68, 0x20, 0x30, 0x99, 0x39, 0x96, 0xd6, 0x2b, 0x3d,
188 0x5e, 0x45, 0x84, 0xf7, 0xd2, 0x61, 0x50, 0xc9, 0x50, 0xba, 0x8d, 0x08, 0xaa, 0xd0, 0x08, 0x1e,
189};
190
191
192static const PKCS12_ATTR ATTRS1[] = {
193 { "friendlyName", "george" },
194 { "localKeyID", "1234567890" },
195 { "1.2.3.4.5", "MyCustomAttribute" },
196 { NULL, NULL }
197};
198
199static const PKCS12_ATTR ATTRS2[] = {
200 { "friendlyName", "janet" },
201 { "localKeyID", "987654321" },
202 { "1.2.3.5.8.13", "AnotherCustomAttribute" },
203 { NULL, NULL }
204};
205
206static const PKCS12_ATTR ATTRS3[] = {
207 { "friendlyName", "wildduk" },
208 { "localKeyID", "1122334455" },
209 { "oracle-jdk-trustedkeyusage", "anyExtendedKeyUsage" },
210 { NULL, NULL }
211};
212
213static const PKCS12_ATTR ATTRS4[] = {
214 { "friendlyName", "wildduk" },
215 { "localKeyID", "1122334455" },
216 { NULL, NULL }
217};
218
219static const PKCS12_ENC enc_default = {
220#ifndef OPENSSL_NO_DES
221 NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
222#else
223 NID_aes_128_cbc,
224#endif
225 "Password1",
226 1000
227};
228
229static const PKCS12_ENC mac_default = {
230 NID_sha1,
231 "Password1",
232 1000
233};
234
235static const int enc_nids_all[] = {
236 /* NOTE: To use PBES2 we pass the desired cipher NID instead of NID_pbes2 */
237 NID_aes_128_cbc,
238 NID_aes_256_cbc,
239#ifndef OPENSSL_NO_DES
240 NID_des_ede3_cbc,
241 NID_des_cbc,
242#endif
243#ifndef OPENSSL_NO_RC5
244 NID_rc5_cbc,
245#endif
246#ifndef OPENSSL_NO_RC4
247 NID_rc4,
248#endif
249#ifndef OPENSSL_NO_RC2
250 NID_rc2_cbc,
251#endif
252
253#ifndef OPENSSL_NO_MD2
254# ifndef OPENSSL_NO_DES
255 NID_pbeWithMD2AndDES_CBC,
256# endif
257# ifndef OPENSSL_NO_RC2
258 NID_pbeWithMD2AndRC2_CBC,
259# endif
260#endif
261
262#ifndef OPENSSL_NO_MD5
263# ifndef OPENSSL_NO_DES
264 NID_pbeWithMD5AndDES_CBC,
265# endif
266# ifndef OPENSSL_NO_RC2
267 NID_pbeWithMD5AndRC2_CBC,
268# endif
269#endif
270#ifndef OPENSSL_NO_DES
271 NID_pbeWithSHA1AndDES_CBC,
272#endif
273#ifndef OPENSSL_NO_RC2
274 NID_pbe_WithSHA1And128BitRC2_CBC,
275 NID_pbe_WithSHA1And40BitRC2_CBC,
276 NID_pbeWithSHA1AndRC2_CBC,
277#endif
278#ifndef OPENSSL_NO_RC4
279 NID_pbe_WithSHA1And128BitRC4,
280 NID_pbe_WithSHA1And40BitRC4,
281#endif
282#ifndef OPENSSL_NO_DES
283 NID_pbe_WithSHA1And2_Key_TripleDES_CBC,
284 NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
285#endif
286};
287
288static const int enc_nids_no_legacy[] = {
289 /* NOTE: To use PBES2 we pass the desired cipher NID instead of NID_pbes2 */
290 NID_aes_128_cbc,
291 NID_aes_256_cbc,
292#ifndef OPENSSL_NO_DES
293 NID_des_ede3_cbc,
294 NID_pbe_WithSHA1And2_Key_TripleDES_CBC,
295 NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
296#endif
297};
298
299static const int mac_nids[] = {
300 NID_sha1,
301 NID_md5,
302 NID_sha256,
303 NID_sha512,
304 NID_sha3_256,
305 NID_sha3_512
306};
307
308static const int iters[] = {
309 1,
310 1000
311};
312
313static const char *passwords[] = {
314 "Password1",
315 "",
316};
317
318/* --------------------------------------------------------------------------
319 * Local functions
320 */
321
322static int get_custom_oid(void)
323{
324 static int sec_nid = -1;
325
326 if (sec_nid != -1)
327 return sec_nid;
328 if (!TEST_true(OBJ_create("1.3.5.7.9", "CustomSecretOID", "My custom secret OID")))
329 return -1;
330 return sec_nid = OBJ_txt2nid("CustomSecretOID");
331}
332
333
334/* --------------------------------------------------------------------------
335 * PKCS12 format tests
336 */
337
338static int test_single_cert_no_attrs(void)
339{
340 PKCS12_BUILDER *pb = new_pkcs12_builder("1cert.p12");
341
342 /* Generate/encode */
343 start_pkcs12(pb);
344
345 start_contentinfo(pb);
346
347 add_certbag(pb, CERT1, sizeof(CERT1), NULL);
348
349 end_contentinfo(pb);
350
351 end_pkcs12(pb);
352
353 /* Read/decode */
354 start_check_pkcs12(pb);
355
356 start_check_contentinfo(pb);
357
358 check_certbag(pb, CERT1, sizeof(CERT1), NULL);
359
360 end_check_contentinfo(pb);
361
362 end_check_pkcs12(pb);
363
364 return end_pkcs12_builder(pb);
365}
366
367static int test_single_key(PKCS12_ENC *enc)
368{
369 char fname[80];
370 PKCS12_BUILDER *pb;
371
372 sprintf(fname, "1key_ciph-%s_iter-%d.p12", OBJ_nid2sn(enc->nid), enc->iter);
373
374 pb = new_pkcs12_builder(fname);
375
376 /* Generate/encode */
377 start_pkcs12(pb);
378
379 start_contentinfo(pb);
380
381 add_keybag(pb, KEY1, sizeof(KEY1), NULL, enc);
382
383 end_contentinfo(pb);
384
385 end_pkcs12(pb);
386
387 /* Read/decode */
388 start_check_pkcs12(pb);
389
390 start_check_contentinfo(pb);
391
392 check_keybag(pb, KEY1, sizeof(KEY1), NULL, enc);
393
394 end_check_contentinfo(pb);
395
396 end_check_pkcs12(pb);
397
398 return end_pkcs12_builder(pb);
399}
400
401static int test_single_key_enc_alg(int z)
402{
403 PKCS12_ENC enc;
404
405 if (lgcyprov == NULL)
406 enc.nid = enc_nids_no_legacy[z];
407 else
408 enc.nid = enc_nids_all[z];
409 enc.pass = enc_default.pass;
410 enc.iter = enc_default.iter;
411
412 return test_single_key(&enc);
413}
414
415static int test_single_key_enc_pass(int z)
416{
417 PKCS12_ENC enc;
418
419 enc.nid = enc_default.nid;
420 enc.pass = passwords[z];
421 enc.iter = enc_default.iter;
422
423 return test_single_key(&enc);
424}
425
426static int test_single_key_enc_iter(int z)
427{
428 PKCS12_ENC enc;
429
430 enc.nid = enc_default.nid;
431 enc.pass = enc_default.pass;
432 enc.iter = iters[z];
433
434 return test_single_key(&enc);
435}
436
437static int test_single_key_with_attrs(void)
438{
439 PKCS12_BUILDER *pb = new_pkcs12_builder("1keyattrs.p12");
440
441 /* Generate/encode */
442 start_pkcs12(pb);
443
444 start_contentinfo(pb);
445
446 add_keybag(pb, KEY1, sizeof(KEY1), ATTRS1, &enc_default);
447
448 end_contentinfo(pb);
449
450 end_pkcs12(pb);
451
452 /* Read/decode */
453 start_check_pkcs12(pb);
454
455 start_check_contentinfo(pb);
456
457 check_keybag(pb, KEY1, sizeof(KEY1), ATTRS1, &enc_default);
458
459 end_check_contentinfo(pb);
460
461 end_check_pkcs12(pb);
462
463 return end_pkcs12_builder(pb);
464}
465
466static int test_single_cert_mac(PKCS12_ENC *mac)
467{
468 char fname[80];
469 PKCS12_BUILDER *pb;
470
471 sprintf(fname, "1cert_mac-%s_iter-%d.p12", OBJ_nid2sn(mac->nid), mac->iter);
472
473 pb = new_pkcs12_builder(fname);
474
475 /* Generate/encode */
476 start_pkcs12(pb);
477
478 start_contentinfo(pb);
479
480 add_certbag(pb, CERT1, sizeof(CERT1), NULL);
481
482 end_contentinfo(pb);
483
484 end_pkcs12_with_mac(pb, mac);
485
486 /* Read/decode */
487 start_check_pkcs12_with_mac(pb, mac);
488
489 start_check_contentinfo(pb);
490
491 check_certbag(pb, CERT1, sizeof(CERT1), NULL);
492
493 end_check_contentinfo(pb);
494
495 end_check_pkcs12(pb);
496
497 return end_pkcs12_builder(pb);
498}
499
500static int test_single_cert_mac_alg(int z)
501{
502 PKCS12_ENC mac;
503
504 mac.nid = mac_nids[z];
505 mac.pass = mac_default.pass;
506 mac.iter = mac_default.iter;
507
508 return test_single_cert_mac(&mac);
509}
510
511static int test_single_cert_mac_pass(int z)
512{
513 PKCS12_ENC mac;
514
515 mac.nid = mac_default.nid;
516 mac.pass = passwords[z];
517 mac.iter = mac_default.iter;
518
519 return test_single_cert_mac(&mac);
520}
521
522static int test_single_cert_mac_iter(int z)
523{
524 PKCS12_ENC mac;
525
526 mac.nid = mac_default.nid;
527 mac.pass = mac_default.pass;
528 mac.iter = iters[z];
529
530 return test_single_cert_mac(&mac);
531}
532
533static int test_cert_key_with_attrs_and_mac(void)
534{
535 PKCS12_BUILDER *pb = new_pkcs12_builder("1cert1key.p12");
536
537 /* Generate/encode */
538 start_pkcs12(pb);
539
540 start_contentinfo(pb);
541
542 add_certbag(pb, CERT1, sizeof(CERT1), ATTRS1);
543 add_keybag(pb, KEY1, sizeof(KEY1), ATTRS1, &enc_default);
544
545 end_contentinfo(pb);
546
547 end_pkcs12_with_mac(pb, &mac_default);
548
549 /* Read/decode */
550 start_check_pkcs12_with_mac(pb, &mac_default);
551
552 start_check_contentinfo(pb);
553
554 check_certbag(pb, CERT1, sizeof(CERT1), ATTRS1);
555 check_keybag(pb, KEY1, sizeof(KEY1), ATTRS1, &enc_default);
556
557 end_check_contentinfo(pb);
558
559 end_check_pkcs12(pb);
560
561 return end_pkcs12_builder(pb);
562}
563
564static int test_cert_key_encrypted_content(void)
565{
566 PKCS12_BUILDER *pb = new_pkcs12_builder("1cert1key_enc.p12");
567
568 /* Generate/encode */
569 start_pkcs12(pb);
570
571 start_contentinfo(pb);
572
573 add_certbag(pb, CERT1, sizeof(CERT1), ATTRS1);
574 add_keybag(pb, KEY1, sizeof(KEY1), ATTRS1, &enc_default);
575
576 end_contentinfo_encrypted(pb, &enc_default);
577
578 end_pkcs12_with_mac(pb, &mac_default);
579
580 /* Read/decode */
581 start_check_pkcs12_with_mac(pb, &mac_default);
582
583 start_check_contentinfo_encrypted(pb, &enc_default);
584
585 check_certbag(pb, CERT1, sizeof(CERT1), ATTRS1);
586 check_keybag(pb, KEY1, sizeof(KEY1), ATTRS1, &enc_default);
587
588 end_check_contentinfo(pb);
589
590 end_check_pkcs12(pb);
591
592 return end_pkcs12_builder(pb);
593}
594
595static int test_single_secret_encrypted_content(void)
596{
597 PKCS12_BUILDER *pb = new_pkcs12_builder("1secret.p12");
598 int custom_nid = get_custom_oid();
599
600 /* Generate/encode */
601 start_pkcs12(pb);
602
603 start_contentinfo(pb);
604
605 add_secretbag(pb, custom_nid, "VerySecretMessage", ATTRS1);
606
607 end_contentinfo_encrypted(pb, &enc_default);
608
609 end_pkcs12_with_mac(pb, &mac_default);
610
611 /* Read/decode */
612 start_check_pkcs12_with_mac(pb, &mac_default);
613
614 start_check_contentinfo_encrypted(pb, &enc_default);
615
616 check_secretbag(pb, custom_nid, "VerySecretMessage", ATTRS1);
617
618 end_check_contentinfo(pb);
619
620 end_check_pkcs12(pb);
621
622 return end_pkcs12_builder(pb);
623}
624
625static int test_single_secret(PKCS12_ENC *enc)
626{
627 int custom_nid;
628 char fname[80];
629 PKCS12_BUILDER *pb;
630
631 sprintf(fname, "1secret_ciph-%s_iter-%d.p12", OBJ_nid2sn(enc->nid), enc->iter);
632 pb = new_pkcs12_builder(fname);
633 custom_nid = get_custom_oid();
634
635 /* Generate/encode */
636 start_pkcs12(pb);
637
638 start_contentinfo(pb);
639
640 add_secretbag(pb, custom_nid, "VerySecretMessage", ATTRS1);
641
642 end_contentinfo_encrypted(pb, enc);
643
644 end_pkcs12_with_mac(pb, &mac_default);
645
646 /* Read/decode */
647 start_check_pkcs12_with_mac(pb, &mac_default);
648
649 start_check_contentinfo_encrypted(pb, enc);
650
651 check_secretbag(pb, custom_nid, "VerySecretMessage", ATTRS1);
652
653 end_check_contentinfo(pb);
654
655 end_check_pkcs12(pb);
656
657 return end_pkcs12_builder(pb);
658}
659
660static int test_single_secret_enc_alg(int z)
661{
662 PKCS12_ENC enc;
663
664 if (lgcyprov == NULL)
665 enc.nid = enc_nids_no_legacy[z];
666 else
667 enc.nid = enc_nids_all[z];
668 enc.pass = enc_default.pass;
669 enc.iter = enc_default.iter;
670
671 return test_single_secret(&enc);
672}
673
674static int test_multiple_contents(void)
675{
676 PKCS12_BUILDER *pb = new_pkcs12_builder("multi_contents.p12");
677 int custom_nid = get_custom_oid();
678
679 /* Generate/encode */
680 start_pkcs12(pb);
681
682 start_contentinfo(pb);
683
684 add_certbag(pb, CERT1, sizeof(CERT1), ATTRS1);
685 add_certbag(pb, CERT2, sizeof(CERT2), ATTRS2);
686 add_keybag(pb, KEY1, sizeof(KEY1), ATTRS1, &enc_default);
687 add_keybag(pb, KEY2, sizeof(KEY2), ATTRS2, &enc_default);
688
689 end_contentinfo(pb);
690
691 start_contentinfo(pb);
692
693 add_secretbag(pb, custom_nid, "VeryVerySecretMessage", ATTRS1);
694
695 end_contentinfo_encrypted(pb, &enc_default);
696
697 end_pkcs12_with_mac(pb, &mac_default);
698
699 /* Read/decode */
700 start_check_pkcs12_with_mac(pb, &mac_default);
701
702 start_check_contentinfo(pb);
703
704 check_certbag(pb, CERT1, sizeof(CERT1), ATTRS1);
705 check_certbag(pb, CERT2, sizeof(CERT2), ATTRS2);
706 check_keybag(pb, KEY1, sizeof(KEY1), ATTRS1, &enc_default);
707 check_keybag(pb, KEY2, sizeof(KEY2), ATTRS2, &enc_default);
708
709 end_check_contentinfo(pb);
710
711 start_check_contentinfo_encrypted(pb, &enc_default);
712
713 check_secretbag(pb, custom_nid, "VeryVerySecretMessage", ATTRS1);
714
715 end_check_contentinfo(pb);
716
717 end_check_pkcs12(pb);
718
719 return end_pkcs12_builder(pb);
720}
721
722static int test_jdk_trusted_attr(void)
723{
724 PKCS12_BUILDER *pb = new_pkcs12_builder("jdk_trusted.p12");
725
726 /* Generate/encode */
727 start_pkcs12(pb);
728
729 start_contentinfo(pb);
730
731 add_certbag(pb, CERT1, sizeof(CERT1), ATTRS3);
732
733 end_contentinfo(pb);
734
735 end_pkcs12_with_mac(pb, &mac_default);
736
737 /* Read/decode */
738 start_check_pkcs12_with_mac(pb, &mac_default);
739
740 start_check_contentinfo(pb);
741
742 check_certbag(pb, CERT1, sizeof(CERT1), ATTRS3);
743
744 end_check_contentinfo(pb);
745
746 end_check_pkcs12(pb);
747
748 return end_pkcs12_builder(pb);
749}
750
751static int test_set0_attrs(void)
752{
753 PKCS12_BUILDER *pb = new_pkcs12_builder("attrs.p12");
754 PKCS12_SAFEBAG *bag = NULL;
755 STACK_OF(X509_ATTRIBUTE) *attrs = NULL;
756 X509_ATTRIBUTE *attr = NULL;
757
758 start_pkcs12(pb);
759
760 start_contentinfo(pb);
761
762 /* Add cert and attrs (name/locakkey only) */
763 add_certbag(pb, CERT1, sizeof(CERT1), ATTRS4);
764
765 bag = sk_PKCS12_SAFEBAG_value(pb->bags, 0);
766 attrs = (STACK_OF(X509_ATTRIBUTE)*)PKCS12_SAFEBAG_get0_attrs(bag);
767
768 /* Create new attr, add to list and confirm return attrs is not NULL */
769 attr = X509_ATTRIBUTE_create(NID_oracle_jdk_trustedkeyusage, V_ASN1_OBJECT, OBJ_txt2obj("anyExtendedKeyUsage", 0));
770 X509at_add1_attr(&attrs, attr);
771 PKCS12_SAFEBAG_set0_attrs(bag, attrs);
772 attrs = (STACK_OF(X509_ATTRIBUTE)*)PKCS12_SAFEBAG_get0_attrs(bag);
773 X509_ATTRIBUTE_free(attr);
774 if(!TEST_ptr(attrs)) {
775 goto err;
776 }
777
778 end_contentinfo(pb);
779
780 end_pkcs12(pb);
781
782 /* Read/decode */
783 start_check_pkcs12(pb);
784
785 start_check_contentinfo(pb);
786
787 /* Use existing check functionality to confirm cert bag attrs identical to ATTRS3 */
788 check_certbag(pb, CERT1, sizeof(CERT1), ATTRS3);
789
790 end_check_contentinfo(pb);
791
792 end_check_pkcs12(pb);
793
794 return end_pkcs12_builder(pb);
795
796err:
797 (void)end_pkcs12_builder(pb);
798 return 0;
799}
800
801#ifndef OPENSSL_NO_DES
802static int pkcs12_create_test(void)
803{
804 int ret = 0;
805 EVP_PKEY *pkey = NULL;
806 PKCS12 *p12 = NULL;
807 const unsigned char *p;
808
809 static const unsigned char rsa_key[] = {
810 0x30, 0x82, 0x02, 0x5d, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xbb,
811 0x24, 0x7a, 0x09, 0x7e, 0x0e, 0xb2, 0x37, 0x32, 0xcc, 0x39, 0x67, 0xad,
812 0xf1, 0x9e, 0x3d, 0x6b, 0x82, 0x83, 0xd1, 0xd0, 0xac, 0xa4, 0xc0, 0x18,
813 0xbe, 0x8d, 0x98, 0x00, 0xc0, 0x7b, 0xff, 0x07, 0x44, 0xc9, 0xca, 0x1c,
814 0xba, 0x36, 0xe1, 0x27, 0x69, 0xff, 0xb1, 0xe3, 0x8d, 0x8b, 0xee, 0x57,
815 0xa9, 0x3a, 0xaa, 0x16, 0x43, 0x39, 0x54, 0x19, 0x7c, 0xae, 0x69, 0x24,
816 0x14, 0xf6, 0x64, 0xff, 0xbc, 0x74, 0xc6, 0x67, 0x6c, 0x4c, 0xf1, 0x02,
817 0x49, 0x69, 0xc7, 0x2b, 0xe1, 0xe1, 0xa1, 0xa3, 0x43, 0x14, 0xf4, 0x77,
818 0x8f, 0xc8, 0xd0, 0x85, 0x5a, 0x35, 0x95, 0xac, 0x62, 0xa9, 0xc1, 0x21,
819 0x00, 0x77, 0xa0, 0x8b, 0x97, 0x30, 0xb4, 0x5a, 0x2c, 0xb8, 0x90, 0x2f,
820 0x48, 0xa0, 0x05, 0x28, 0x4b, 0xf2, 0x0f, 0x8d, 0xec, 0x8b, 0x4d, 0x03,
821 0x42, 0x75, 0xd6, 0xad, 0x81, 0xc0, 0x11, 0x02, 0x03, 0x01, 0x00, 0x01,
822 0x02, 0x81, 0x80, 0x00, 0xfc, 0xb9, 0x4a, 0x26, 0x07, 0x89, 0x51, 0x2b,
823 0x53, 0x72, 0x91, 0xe0, 0x18, 0x3e, 0xa6, 0x5e, 0x31, 0xef, 0x9c, 0x0c,
824 0x16, 0x24, 0x42, 0xd0, 0x28, 0x33, 0xf9, 0xfa, 0xd0, 0x3c, 0x54, 0x04,
825 0x06, 0xc0, 0x15, 0xf5, 0x1b, 0x9a, 0xb3, 0x24, 0x31, 0xab, 0x3c, 0x6b,
826 0x47, 0x43, 0xb0, 0xd2, 0xa9, 0xdc, 0x05, 0xe1, 0x81, 0x59, 0xb6, 0x04,
827 0xe9, 0x66, 0x61, 0xaa, 0xd7, 0x0b, 0x00, 0x8f, 0x3d, 0xe5, 0xbf, 0xa2,
828 0xf8, 0x5e, 0x25, 0x6c, 0x1e, 0x22, 0x0f, 0xb4, 0xfd, 0x41, 0xe2, 0x03,
829 0x31, 0x5f, 0xda, 0x20, 0xc5, 0xc0, 0xf3, 0x55, 0x0e, 0xe1, 0xc9, 0xec,
830 0xd7, 0x3e, 0x2a, 0x0c, 0x01, 0xca, 0x7b, 0x22, 0xcb, 0xac, 0xf4, 0x2b,
831 0x27, 0xf0, 0x78, 0x5f, 0xb5, 0xc2, 0xf9, 0xe8, 0x14, 0x5a, 0x6e, 0x7e,
832 0x86, 0xbd, 0x6a, 0x9b, 0x20, 0x0c, 0xba, 0xcc, 0x97, 0x20, 0x11, 0x02,
833 0x41, 0x00, 0xc9, 0x59, 0x9f, 0x29, 0x8a, 0x5b, 0x9f, 0xe3, 0x2a, 0xd8,
834 0x7e, 0xc2, 0x40, 0x9f, 0xa8, 0x45, 0xe5, 0x3e, 0x11, 0x8d, 0x3c, 0xed,
835 0x6e, 0xab, 0xce, 0xd0, 0x65, 0x46, 0xd8, 0xc7, 0x07, 0x63, 0xb5, 0x23,
836 0x34, 0xf4, 0x9f, 0x7e, 0x1c, 0xc7, 0xc7, 0xf9, 0x65, 0xd1, 0xf4, 0x04,
837 0x42, 0x38, 0xbe, 0x3a, 0x0c, 0x9d, 0x08, 0x25, 0xfc, 0xa3, 0x71, 0xd9,
838 0xae, 0x0c, 0x39, 0x61, 0xf4, 0x89, 0x02, 0x41, 0x00, 0xed, 0xef, 0xab,
839 0xa9, 0xd5, 0x39, 0x9c, 0xee, 0x59, 0x1b, 0xff, 0xcf, 0x48, 0x44, 0x1b,
840 0xb6, 0x32, 0xe7, 0x46, 0x24, 0xf3, 0x04, 0x7f, 0xde, 0x95, 0x08, 0x6d,
841 0x75, 0x9e, 0x67, 0x17, 0xba, 0x5c, 0xa4, 0xd4, 0xe2, 0xe2, 0x4d, 0x77,
842 0xce, 0xeb, 0x66, 0x29, 0xc5, 0x96, 0xe0, 0x62, 0xbb, 0xe5, 0xac, 0xdc,
843 0x44, 0x62, 0x54, 0x86, 0xed, 0x64, 0x0c, 0xce, 0xd0, 0x60, 0x03, 0x9d,
844 0x49, 0x02, 0x40, 0x54, 0xd9, 0x18, 0x72, 0x27, 0xe4, 0xbe, 0x76, 0xbb,
845 0x1a, 0x6a, 0x28, 0x2f, 0x95, 0x58, 0x12, 0xc4, 0x2c, 0xa8, 0xb6, 0xcc,
846 0xe2, 0xfd, 0x0d, 0x17, 0x64, 0xc8, 0x18, 0xd7, 0xc6, 0xdf, 0x3d, 0x4c,
847 0x1a, 0x9e, 0xf9, 0x2a, 0xb0, 0xb9, 0x2e, 0x12, 0xfd, 0xec, 0xc3, 0x51,
848 0xc1, 0xed, 0xa9, 0xfd, 0xb7, 0x76, 0x93, 0x41, 0xd8, 0xc8, 0x22, 0x94,
849 0x1a, 0x77, 0xf6, 0x9c, 0xc3, 0xc3, 0x89, 0x02, 0x41, 0x00, 0x8e, 0xf9,
850 0xa7, 0x08, 0xad, 0xb5, 0x2a, 0x04, 0xdb, 0x8d, 0x04, 0xa1, 0xb5, 0x06,
851 0x20, 0x34, 0xd2, 0xcf, 0xc0, 0x89, 0xb1, 0x72, 0x31, 0xb8, 0x39, 0x8b,
852 0xcf, 0xe2, 0x8e, 0xa5, 0xda, 0x4f, 0x45, 0x1e, 0x53, 0x42, 0x66, 0xc4,
853 0x30, 0x4b, 0x29, 0x8e, 0xc1, 0x69, 0x17, 0x29, 0x8c, 0x8a, 0xe6, 0x0f,
854 0x82, 0x68, 0xa1, 0x41, 0xb3, 0xb6, 0x70, 0x99, 0x75, 0xa9, 0x27, 0x18,
855 0xe4, 0xe9, 0x02, 0x41, 0x00, 0x89, 0xea, 0x6e, 0x6d, 0x70, 0xdf, 0x25,
856 0x5f, 0x18, 0x3f, 0x48, 0xda, 0x63, 0x10, 0x8b, 0xfe, 0xa8, 0x0c, 0x94,
857 0x0f, 0xde, 0x97, 0x56, 0x53, 0x89, 0x94, 0xe2, 0x1e, 0x2c, 0x74, 0x3c,
858 0x91, 0x81, 0x34, 0x0b, 0xa6, 0x40, 0xf8, 0xcb, 0x2a, 0x60, 0x8c, 0xe0,
859 0x02, 0xb7, 0x89, 0x93, 0xcf, 0x18, 0x9f, 0x49, 0x54, 0xfd, 0x7d, 0x3f,
860 0x9a, 0xef, 0xd4, 0xa4, 0x4f, 0xc1, 0x45, 0x99, 0x91,
861 };
862
863 p = rsa_key;
864 if (!TEST_ptr(pkey = d2i_PrivateKey_ex(EVP_PKEY_RSA, NULL, &p,
865 sizeof(rsa_key), NULL, NULL)))
866 goto err;
867 if (!TEST_int_eq(ERR_peek_error(), 0))
868 goto err;
869 p12 = PKCS12_create(NULL, NULL, pkey, NULL, NULL,
870 NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
871 NID_pbe_WithSHA1And3_Key_TripleDES_CBC, 2, 1, 0);
872 if (!TEST_ptr(p12))
873 goto err;
874
875 if (!TEST_int_eq(ERR_peek_error(), 0))
876 goto err;
877 ret = 1;
878err:
879 PKCS12_free(p12);
880 EVP_PKEY_free(pkey);
881 return ret;
882}
883#endif
884
885static int pkcs12_recreate_test(void)
886{
887 int ret = 0;
888 X509 *cert = NULL;
889 X509 *cert_parsed = NULL;
890 EVP_PKEY *pkey = NULL;
891 EVP_PKEY *pkey_parsed = NULL;
892 PKCS12 *p12 = NULL;
893 PKCS12 *p12_parsed = NULL;
894 PKCS12 *p12_recreated = NULL;
895 const unsigned char *cert_bytes = CERT1;
896 const unsigned char *key_bytes = KEY1;
897 BIO *bio = NULL;
898
899 cert = d2i_X509(NULL, &cert_bytes, sizeof(CERT1));
900 if (!TEST_ptr(cert))
901 goto err;
902 pkey = d2i_AutoPrivateKey(NULL, &key_bytes, sizeof(KEY1));
903 if (!TEST_ptr(pkey))
904 goto err;
905 p12 = PKCS12_create("pass", NULL, pkey, cert, NULL, NID_aes_256_cbc,
906 NID_aes_256_cbc, 2, 1, 0);
907 if (!TEST_ptr(p12))
908 goto err;
909 if (!TEST_int_eq(ERR_peek_error(), 0))
910 goto err;
911
912 bio = BIO_new(BIO_s_mem());
913 if (!TEST_ptr(bio))
914 goto err;
915 if (!TEST_int_eq(i2d_PKCS12_bio(bio, p12), 1))
916 goto err;
917 p12_parsed = PKCS12_init_ex(NID_pkcs7_data, testctx, NULL);
918 if (!TEST_ptr(p12_parsed))
919 goto err;
920 p12_parsed = d2i_PKCS12_bio(bio, &p12_parsed);
921 if (!TEST_ptr(p12_parsed))
922 goto err;
923 if (!TEST_int_eq(PKCS12_parse(p12_parsed, "pass", &pkey_parsed,
924 &cert_parsed, NULL), 1))
925 goto err;
926
927 /* cert_parsed also contains auxiliary data */
928 p12_recreated = PKCS12_create("new_pass", NULL, pkey_parsed, cert_parsed,
929 NULL, NID_aes_256_cbc, NID_aes_256_cbc,
930 2, 1, 0);
931 if (!TEST_ptr(p12_recreated))
932 goto err;
933 if (!TEST_int_eq(ERR_peek_error(), 0))
934 goto err;
935
936 ret = 1;
937err:
938 BIO_free(bio);
939 PKCS12_free(p12);
940 PKCS12_free(p12_parsed);
941 PKCS12_free(p12_recreated);
942 EVP_PKEY_free(pkey);
943 EVP_PKEY_free(pkey_parsed);
944 X509_free(cert);
945 X509_free(cert_parsed);
946 return ret;
947}
948
949typedef enum OPTION_choice {
950 OPT_ERR = -1,
951 OPT_EOF = 0,
952 OPT_WRITE,
953 OPT_LEGACY,
954 OPT_CONTEXT,
955 OPT_TEST_ENUM
956} OPTION_CHOICE;
957
958const OPTIONS *test_get_options(void)
959{
960 static const OPTIONS options[] = {
961 OPT_TEST_OPTIONS_DEFAULT_USAGE,
962 { "write", OPT_WRITE, '-', "Write PKCS12 objects to file" },
963 { "legacy", OPT_LEGACY, '-', "Test the legacy APIs" },
964 { "context", OPT_CONTEXT, '-', "Explicitly use a non-default library context" },
965 { NULL }
966 };
967 return options;
968}
969
970int setup_tests(void)
971{
972 OPTION_CHOICE o;
973
974 while ((o = opt_next()) != OPT_EOF) {
975 switch (o) {
976 case OPT_WRITE:
977 PKCS12_helper_set_write_files(1);
978 break;
979 case OPT_LEGACY:
980 PKCS12_helper_set_legacy(1);
981 break;
982 case OPT_CONTEXT:
983 default_libctx = 0;
984 break;
985 case OPT_TEST_CASES:
986 break;
987 default:
988 return 0;
989 }
990 }
991
992 if (!default_libctx) {
993 testctx = OSSL_LIB_CTX_new();
994 if (!TEST_ptr(testctx))
995 return 0;
996 nullprov = OSSL_PROVIDER_load(NULL, "null");
997 if (!TEST_ptr(nullprov))
998 return 0;
999 }
1000
1001 deflprov = OSSL_PROVIDER_load(testctx, "default");
1002 if (!TEST_ptr(deflprov))
1003 return 0;
1004 lgcyprov = OSSL_PROVIDER_load(testctx, "legacy");
1005
1006 PKCS12_helper_set_libctx(testctx);
1007
1008 /*
1009 * Verify that the default and fips providers in the default libctx are not
1010 * available if we are using a standalone context
1011 */
1012 if (!default_libctx) {
1013 if (!TEST_false(OSSL_PROVIDER_available(NULL, "default"))
1014 || !TEST_false(OSSL_PROVIDER_available(NULL, "fips")))
1015 return 0;
1016 }
1017
1018 ADD_TEST(test_single_cert_no_attrs);
1019 if (lgcyprov == NULL) {
1020 ADD_ALL_TESTS(test_single_key_enc_alg, OSSL_NELEM(enc_nids_no_legacy));
1021 ADD_ALL_TESTS(test_single_secret_enc_alg, OSSL_NELEM(enc_nids_no_legacy));
1022 } else {
1023 ADD_ALL_TESTS(test_single_key_enc_alg, OSSL_NELEM(enc_nids_all));
1024 ADD_ALL_TESTS(test_single_secret_enc_alg, OSSL_NELEM(enc_nids_all));
1025 }
1026#ifndef OPENSSL_NO_DES
1027 if (default_libctx)
1028 ADD_TEST(pkcs12_create_test);
1029#endif
1030 if (default_libctx)
1031 ADD_TEST(pkcs12_recreate_test);
1032 ADD_ALL_TESTS(test_single_key_enc_pass, OSSL_NELEM(passwords));
1033 ADD_ALL_TESTS(test_single_key_enc_iter, OSSL_NELEM(iters));
1034 ADD_TEST(test_single_key_with_attrs);
1035 ADD_ALL_TESTS(test_single_cert_mac_alg, OSSL_NELEM(mac_nids));
1036 ADD_ALL_TESTS(test_single_cert_mac_pass, OSSL_NELEM(passwords));
1037 ADD_ALL_TESTS(test_single_cert_mac_iter, OSSL_NELEM(iters));
1038 ADD_TEST(test_cert_key_with_attrs_and_mac);
1039 ADD_TEST(test_cert_key_encrypted_content);
1040 ADD_TEST(test_single_secret_encrypted_content);
1041 ADD_TEST(test_multiple_contents);
1042 ADD_TEST(test_jdk_trusted_attr);
1043 ADD_TEST(test_set0_attrs);
1044 return 1;
1045}
1046
1047void cleanup_tests(void)
1048{
1049 OSSL_PROVIDER_unload(nullprov);
1050 OSSL_PROVIDER_unload(deflprov);
1051 OSSL_PROVIDER_unload(lgcyprov);
1052 OSSL_LIB_CTX_free(testctx);
1053}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette