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