10SN/A/*
216709Spsandoz * Copyright 2020-2023 The OpenSSL Project Authors. All Rights Reserved.
30SN/A *
40SN/A * Licensed under the Apache License 2.0 (the "License").  You may not use
50SN/A * this file except in compliance with the License.  You can obtain a copy
60SN/A * in the file LICENSE in the source distribution or at
72362SN/A * https://www.openssl.org/source/license.html
80SN/A */
92362SN/A
100SN/A#include <stdio.h>
110SN/A#include <string.h>
120SN/A#include <stdlib.h>
130SN/A
140SN/A#include "internal/nelem.h"
150SN/A
160SN/A#include <openssl/pkcs12.h>
170SN/A#include <openssl/x509.h>
180SN/A#include <openssl/x509v3.h>
190SN/A#include <openssl/pem.h>
200SN/A
212362SN/A#include "testutil.h"
222362SN/A#include "helpers/pkcs12.h"
232362SN/A
240SN/Astatic int default_libctx = 1;
250SN/A
260SN/Astatic OSSL_LIB_CTX *testctx = NULL;
270SN/Astatic OSSL_PROVIDER *nullprov = NULL;
280SN/Astatic OSSL_PROVIDER *deflprov = NULL;
290SN/Astatic OSSL_PROVIDER *lgcyprov = NULL;
3011480Schegar
3111480Schegar/* --------------------------------------------------------------------------
3211480Schegar * PKCS12 component test data
330SN/A */
3413510Smsheppar
3513510Smshepparstatic const unsigned char CERT1[] =
3613510Smsheppar{
3713510Smsheppar    0x30, 0x82, 0x01, 0xed, 0x30, 0x82, 0x01, 0x56, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00,
3811480Schegar    0x8b, 0x4b, 0x5e, 0x6c, 0x03, 0x28, 0x4e, 0xe6, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
3913551Sredestad    0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x19, 0x31, 0x17, 0x30, 0x15, 0x06, 0x03, 0x55,
4011480Schegar    0x04, 0x03, 0x0c, 0x0e, 0x50, 0x31, 0x32, 0x54, 0x65, 0x73, 0x74, 0x2d, 0x52, 0x6f, 0x6f, 0x74,
4111480Schegar    0x2d, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x39, 0x30, 0x39, 0x33, 0x30, 0x30, 0x30, 0x34, 0x36,
4211480Schegar    0x35, 0x36, 0x5a, 0x17, 0x0d, 0x32, 0x39, 0x30, 0x39, 0x32, 0x37, 0x30, 0x30, 0x34, 0x36, 0x35,
4311480Schegar    0x36, 0x5a, 0x30, 0x1b, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x10, 0x50,
4416709Spsandoz    0x31, 0x32, 0x54, 0x65, 0x73, 0x74, 0x2d, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2d, 0x31, 0x30,
4516709Spsandoz    0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05,
460SN/A    0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xbc, 0xdc, 0x6f, 0x8c,
4714265Sredestad    0x7a, 0x2a, 0x4b, 0xea, 0x66, 0x66, 0x04, 0xa9, 0x05, 0x92, 0x53, 0xd7, 0x13, 0x3c, 0x49, 0xe1,
480SN/A    0xc8, 0xbb, 0xdf, 0x3d, 0xcb, 0x88, 0x31, 0x07, 0x20, 0x59, 0x93, 0x24, 0x7f, 0x7d, 0xc6, 0x84,
490SN/A    0x81, 0x16, 0x64, 0x4a, 0x52, 0xa6, 0x30, 0x44, 0xdc, 0x1a, 0x30, 0xde, 0xae, 0x29, 0x18, 0xcf,
507755SN/A    0xc7, 0xf3, 0xcf, 0x0c, 0xb7, 0x8e, 0x2b, 0x1e, 0x21, 0x01, 0x0b, 0xfb, 0xe5, 0xe6, 0xcf, 0x2b,
510SN/A    0x84, 0xe1, 0x33, 0xf8, 0xba, 0x02, 0xfc, 0x30, 0xfa, 0xc4, 0x33, 0xc7, 0x37, 0xc6, 0x7f, 0x72,
520SN/A    0x31, 0x92, 0x1d, 0x8f, 0xa0, 0xfb, 0xe5, 0x4a, 0x08, 0x31, 0x78, 0x80, 0x9c, 0x23, 0xb4, 0xe9,
530SN/A    0x19, 0x56, 0x04, 0xfa, 0x0d, 0x07, 0x04, 0xb7, 0x43, 0xac, 0x4c, 0x49, 0x7c, 0xc2, 0xa1, 0x44,
540SN/A    0xc1, 0x48, 0x7d, 0x28, 0xe5, 0x23, 0x66, 0x07, 0x22, 0xd5, 0xf0, 0xf1, 0x02, 0x03, 0x01, 0x00,
550SN/A    0x01, 0xa3, 0x3b, 0x30, 0x39, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16,
566438SN/A    0x80, 0x14, 0xdb, 0xbb, 0xb8, 0x92, 0x4e, 0x24, 0x0b, 0x1b, 0xbb, 0x78, 0x33, 0xf9, 0x01, 0x02,
576438SN/A    0x23, 0x0d, 0x96, 0x18, 0x30, 0x47, 0x30, 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30,
586438SN/A    0x00, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x04, 0x04, 0x03, 0x02, 0x04, 0xf0, 0x30, 0x0d,
590SN/A    0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x81, 0x81,
606438SN/A    0x00, 0x1c, 0x13, 0xdc, 0x02, 0xf1, 0x44, 0x36, 0x65, 0xa9, 0xbe, 0x30, 0x1c, 0x66, 0x14, 0x20,
616438SN/A    0x86, 0x5a, 0xa8, 0x69, 0x25, 0xf8, 0x1a, 0xb6, 0x9e, 0x5e, 0xe9, 0x89, 0xb8, 0x67, 0x70, 0x19,
626438SN/A    0x87, 0x60, 0xeb, 0x4b, 0x11, 0x71, 0x85, 0xf8, 0xe9, 0xa7, 0x3e, 0x20, 0x42, 0xec, 0x43, 0x25,
636438SN/A    0x01, 0x03, 0xe5, 0x4d, 0x83, 0x22, 0xf5, 0x8e, 0x3a, 0x1a, 0x1b, 0xd4, 0x1c, 0xda, 0x6b, 0x9d,
646438SN/A    0x10, 0x1b, 0xee, 0x67, 0x4e, 0x1f, 0x69, 0xab, 0xbc, 0xaa, 0x62, 0x8e, 0x9e, 0xc6, 0xee, 0xd6,
656438SN/A    0x09, 0xc0, 0xca, 0xe0, 0xaa, 0x9f, 0x07, 0xb2, 0xc2, 0xbb, 0x31, 0x96, 0xa2, 0x04, 0x62, 0xd3,
666438SN/A    0x13, 0x32, 0x29, 0x67, 0x6e, 0xad, 0x2e, 0x0b, 0xea, 0x04, 0x7c, 0x8c, 0x5a, 0x5d, 0xac, 0x14,
677755SN/A    0xaa, 0x61, 0x7f, 0x28, 0x6c, 0x2d, 0x64, 0x2d, 0xc3, 0xaf, 0x77, 0x52, 0x90, 0xb4, 0x37, 0xc0,
680SN/A    0x30,
697755SN/A};
707755SN/A
710SN/Astatic const unsigned char CERT2[] =
720SN/A{
730SN/A    0x30, 0x82, 0x01, 0xed, 0x30, 0x82, 0x01, 0x56, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00,
740SN/A    0x8b, 0x4b, 0x5e, 0x6c, 0x03, 0x28, 0x4e, 0xe7, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
750SN/A    0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x19, 0x31, 0x17, 0x30, 0x15, 0x06, 0x03, 0x55,
760SN/A    0x04, 0x03, 0x0c, 0x0e, 0x50, 0x31, 0x32, 0x54, 0x65, 0x73, 0x74, 0x2d, 0x52, 0x6f, 0x6f, 0x74,
770SN/A    0x2d, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x39, 0x30, 0x39, 0x33, 0x30, 0x30, 0x30, 0x34, 0x36,
780SN/A    0x35, 0x36, 0x5a, 0x17, 0x0d, 0x32, 0x39, 0x30, 0x39, 0x32, 0x37, 0x30, 0x30, 0x34, 0x36, 0x35,
790SN/A    0x36, 0x5a, 0x30, 0x1b, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x10, 0x50,
807755SN/A    0x31, 0x32, 0x54, 0x65, 0x73, 0x74, 0x2d, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2d, 0x31, 0x30,
810SN/A    0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05,
820SN/A    0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xa8, 0x6e, 0x40, 0x86,
836438SN/A    0x9f, 0x98, 0x59, 0xfb, 0x57, 0xbf, 0xc1, 0x55, 0x12, 0x38, 0xeb, 0xb3, 0x46, 0x34, 0xc9, 0x35,
840SN/A    0x4d, 0xfd, 0x03, 0xe9, 0x3a, 0x88, 0x9e, 0x97, 0x8f, 0xf4, 0xec, 0x36, 0x7b, 0x3f, 0xba, 0xb8,
850SN/A    0xa5, 0x96, 0x30, 0x03, 0xc5, 0xc6, 0xd9, 0xa8, 0x4e, 0xbc, 0x23, 0x51, 0xa1, 0x96, 0xd2, 0x03,
867755SN/A    0x98, 0x73, 0xb6, 0x17, 0x9c, 0x77, 0xd4, 0x95, 0x1e, 0x1b, 0xb3, 0x1b, 0xc8, 0x71, 0xd1, 0x2e,
87374SN/A    0x31, 0xc7, 0x6a, 0x75, 0x57, 0x08, 0x7f, 0xba, 0x70, 0x76, 0xf7, 0x67, 0xf4, 0x4e, 0xbe, 0xfc,
880SN/A    0x70, 0x61, 0x41, 0x07, 0x2b, 0x7c, 0x3c, 0x3b, 0xb3, 0xbc, 0xd5, 0xa8, 0xbd, 0x28, 0xd8, 0x49,
890SN/A    0xd3, 0xe1, 0x78, 0xc8, 0xc1, 0x42, 0x5e, 0x18, 0x36, 0xa8, 0x41, 0xf7, 0xc8, 0xaa, 0x35, 0xfe,
900SN/A    0x2d, 0xd1, 0xb4, 0xcc, 0x00, 0x67, 0xae, 0x79, 0xd3, 0x28, 0xd5, 0x5b, 0x02, 0x03, 0x01, 0x00,
910SN/A    0x01, 0xa3, 0x3b, 0x30, 0x39, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16,
920SN/A    0x80, 0x14, 0xdb, 0xbb, 0xb8, 0x92, 0x4e, 0x24, 0x0b, 0x1b, 0xbb, 0x78, 0x33, 0xf9, 0x01, 0x02,
930SN/A    0x23, 0x0d, 0x96, 0x18, 0x30, 0x47, 0x30, 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30,
940SN/A    0x00, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x04, 0x04, 0x03, 0x02, 0x04, 0xf0, 0x30, 0x0d,
950SN/A    0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x81, 0x81,
960SN/A    0x00, 0x3b, 0xa6, 0x73, 0xbe, 0xe0, 0x28, 0xed, 0x1f, 0x29, 0x78, 0x4c, 0xc0, 0x1f, 0xe9, 0x85,
970SN/A    0xc6, 0x8f, 0xe3, 0x87, 0x7c, 0xd9, 0xe7, 0x0a, 0x37, 0xe8, 0xaa, 0xb5, 0xd2, 0x7f, 0xf8, 0x90,
980SN/A    0x20, 0x80, 0x35, 0xa7, 0x79, 0x2b, 0x04, 0xa7, 0xbf, 0xe6, 0x7b, 0x58, 0xcb, 0xec, 0x0e, 0x58,
990SN/A    0xef, 0x2a, 0x70, 0x8a, 0x56, 0x8a, 0xcf, 0x6b, 0x7a, 0x74, 0x0c, 0xf4, 0x15, 0x37, 0x93, 0xcd,
1000SN/A    0xe6, 0xb2, 0xa1, 0x83, 0x09, 0xdb, 0x9e, 0x4f, 0xff, 0x6a, 0x17, 0x4f, 0x33, 0xc9, 0xcc, 0x90,
1010SN/A    0x2a, 0x67, 0xff, 0x16, 0x78, 0xa8, 0x2c, 0x10, 0xe0, 0x52, 0x8c, 0xe6, 0xe9, 0x90, 0x8d, 0xe0,
1020SN/A    0x62, 0x04, 0x9a, 0x0f, 0x44, 0x01, 0x82, 0x14, 0x92, 0x44, 0x25, 0x69, 0x22, 0xb7, 0xb8, 0xc5,
1030SN/A    0x94, 0x4c, 0x4b, 0x1c, 0x9b, 0x92, 0x60, 0x66, 0x90, 0x4e, 0xb9, 0xa8, 0x4c, 0x89, 0xbb, 0x0f,
1047755SN/A    0x0b,
1050SN/A};
1060SN/A
1070SN/Astatic const unsigned char KEY1[] =
1080SN/A{
1090SN/A    0x30, 0x82, 0x02, 0x5d, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xbc, 0xdc, 0x6f, 0x8c, 0x7a,
1100SN/A    0x2a, 0x4b, 0xea, 0x66, 0x66, 0x04, 0xa9, 0x05, 0x92, 0x53, 0xd7, 0x13, 0x3c, 0x49, 0xe1, 0xc8,
1110SN/A    0xbb, 0xdf, 0x3d, 0xcb, 0x88, 0x31, 0x07, 0x20, 0x59, 0x93, 0x24, 0x7f, 0x7d, 0xc6, 0x84, 0x81,
1120SN/A    0x16, 0x64, 0x4a, 0x52, 0xa6, 0x30, 0x44, 0xdc, 0x1a, 0x30, 0xde, 0xae, 0x29, 0x18, 0xcf, 0xc7,
1130SN/A    0xf3, 0xcf, 0x0c, 0xb7, 0x8e, 0x2b, 0x1e, 0x21, 0x01, 0x0b, 0xfb, 0xe5, 0xe6, 0xcf, 0x2b, 0x84,
1140SN/A    0xe1, 0x33, 0xf8, 0xba, 0x02, 0xfc, 0x30, 0xfa, 0xc4, 0x33, 0xc7, 0x37, 0xc6, 0x7f, 0x72, 0x31,
1150SN/A    0x92, 0x1d, 0x8f, 0xa0, 0xfb, 0xe5, 0x4a, 0x08, 0x31, 0x78, 0x80, 0x9c, 0x23, 0xb4, 0xe9, 0x19,
1160SN/A    0x56, 0x04, 0xfa, 0x0d, 0x07, 0x04, 0xb7, 0x43, 0xac, 0x4c, 0x49, 0x7c, 0xc2, 0xa1, 0x44, 0xc1,
1170SN/A    0x48, 0x7d, 0x28, 0xe5, 0x23, 0x66, 0x07, 0x22, 0xd5, 0xf0, 0xf1, 0x02, 0x03, 0x01, 0x00, 0x01,
1180SN/A    0x02, 0x81, 0x81, 0x00, 0xa5, 0x6d, 0xf9, 0x8f, 0xf5, 0x5a, 0xa3, 0x50, 0xd9, 0x0d, 0x37, 0xbb,
1190SN/A    0xce, 0x13, 0x94, 0xb8, 0xea, 0x32, 0x7f, 0x0c, 0xf5, 0x46, 0x0b, 0x90, 0x17, 0x7e, 0x5e, 0x63,
1200SN/A    0xbd, 0xa4, 0x78, 0xcd, 0x19, 0x97, 0xd4, 0x92, 0x30, 0x78, 0xaa, 0xb4, 0xa7, 0x9c, 0xc6, 0xdf,
1210SN/A    0x2a, 0x65, 0x0e, 0xb5, 0x9f, 0x9c, 0x84, 0x0d, 0x4d, 0x3a, 0x74, 0xfc, 0xd0, 0xb4, 0x09, 0x74,
1220SN/A    0xc4, 0xb8, 0x24, 0x03, 0xa8, 0xf0, 0xf8, 0x0d, 0x5c, 0x8e, 0xdf, 0x4b, 0xe1, 0x0a, 0x8f, 0x4f,
1230SN/A    0xd5, 0xc7, 0x9b, 0x54, 0x55, 0x8f, 0x00, 0x5c, 0xea, 0x4c, 0x73, 0xf9, 0x1b, 0xbf, 0xb8, 0x93,
1240SN/A    0x33, 0x20, 0xce, 0x45, 0xd9, 0x03, 0x02, 0xb2, 0x36, 0xc5, 0x0a, 0x30, 0x50, 0x78, 0x80, 0x66,
1250SN/A    0x00, 0x22, 0x38, 0x86, 0xcf, 0x63, 0x4a, 0x5c, 0xbf, 0x2b, 0xd9, 0x6e, 0xe6, 0xf0, 0x39, 0xad,
1260SN/A    0x12, 0x25, 0x41, 0xb9, 0x02, 0x41, 0x00, 0xf3, 0x7c, 0x07, 0x99, 0x64, 0x3a, 0x28, 0x8c, 0x8d,
1270SN/A    0x05, 0xfe, 0x32, 0xb5, 0x4c, 0x8c, 0x6d, 0xde, 0x3d, 0x16, 0x08, 0xa0, 0x01, 0x61, 0x4f, 0x8e,
1280SN/A    0xa0, 0xf7, 0x26, 0x26, 0xb5, 0x8e, 0xc0, 0x7a, 0xce, 0x86, 0x34, 0xde, 0xb8, 0xef, 0x86, 0x01,
1290SN/A    0xbe, 0x24, 0xaa, 0x9b, 0x36, 0x93, 0x72, 0x9b, 0xf9, 0xc6, 0xcb, 0x76, 0x84, 0x67, 0x06, 0x06,
1300SN/A    0x30, 0x50, 0xdf, 0x42, 0x17, 0xe0, 0xa7, 0x02, 0x41, 0x00, 0xc6, 0x91, 0xa0, 0x41, 0x34, 0x11,
1310SN/A    0x67, 0x4b, 0x08, 0x0f, 0xda, 0xa7, 0x99, 0xec, 0x58, 0x11, 0xa5, 0x82, 0xdb, 0x50, 0xfe, 0x77,
1320SN/A    0xe2, 0xd1, 0x53, 0x9c, 0x7d, 0xe8, 0xbf, 0xe7, 0x7c, 0xa9, 0x01, 0xb1, 0x87, 0xc3, 0x52, 0x79,
1330SN/A    0x9e, 0x2c, 0xa7, 0x6f, 0x02, 0x37, 0x32, 0xef, 0x24, 0x31, 0x21, 0x0b, 0x86, 0x05, 0x32, 0x4a,
1340SN/A    0x2e, 0x0b, 0x65, 0x05, 0xd3, 0xd6, 0x30, 0xb2, 0xfc, 0xa7, 0x02, 0x41, 0x00, 0xc2, 0xed, 0x31,
1350SN/A    0xdc, 0x40, 0x9c, 0x3a, 0xe8, 0x42, 0xe2, 0x60, 0x5e, 0x52, 0x3c, 0xc5, 0x54, 0x14, 0x0e, 0x8d,
1360SN/A    0x7c, 0x3c, 0x34, 0xbe, 0xa6, 0x05, 0x86, 0xa2, 0x36, 0x5d, 0xd9, 0x0e, 0x3e, 0xd4, 0x52, 0x50,
1370SN/A    0xa9, 0x35, 0x01, 0x93, 0x68, 0x92, 0x2e, 0x9a, 0x86, 0x27, 0x1a, 0xab, 0x32, 0x9e, 0xe2, 0x79,
1380SN/A    0x9f, 0x5b, 0xf3, 0xa5, 0xd2, 0xf1, 0xd3, 0x6e, 0x7b, 0x3e, 0x1b, 0x85, 0x93, 0x02, 0x40, 0x68,
1390SN/A    0xb8, 0xb6, 0x7e, 0x8c, 0xba, 0x3c, 0xf2, 0x8a, 0x2e, 0xea, 0x4f, 0x07, 0xd3, 0x68, 0x62, 0xee,
1400SN/A    0x1a, 0x04, 0x16, 0x44, 0x0d, 0xef, 0xf6, 0x1b, 0x95, 0x65, 0xa5, 0xd1, 0x47, 0x81, 0x2c, 0x14,
1410SN/A    0xb3, 0x8e, 0xf9, 0x08, 0xcf, 0x11, 0x07, 0x55, 0xca, 0x2a, 0xad, 0xf7, 0xd3, 0xbd, 0x0f, 0x97,
1420SN/A    0xf0, 0xde, 0xde, 0x70, 0xb6, 0x44, 0x70, 0x47, 0xf7, 0xf9, 0xcf, 0x75, 0x61, 0x7f, 0xf3, 0x02,
1430SN/A    0x40, 0x38, 0x4a, 0x67, 0xaf, 0xae, 0xb6, 0xb2, 0x6a, 0x00, 0x25, 0x5a, 0xa4, 0x65, 0x20, 0xb1,
1440SN/A    0x13, 0xbd, 0x83, 0xff, 0xb4, 0xbc, 0xf4, 0xdd, 0xa1, 0xbb, 0x1c, 0x96, 0x37, 0x35, 0xf4, 0xbf,
1450SN/A    0xed, 0x4c, 0xed, 0x92, 0xe8, 0xac, 0xc9, 0xc1, 0xa5, 0xa3, 0x23, 0x66, 0x40, 0x8a, 0xa1, 0xe6,
1460SN/A    0xe3, 0x95, 0xfe, 0xc4, 0x53, 0xf5, 0x7d, 0x6e, 0xca, 0x45, 0x42, 0xe4, 0xc2, 0x9f, 0xe5, 0x1e,
1470SN/A    0xb5,
1480SN/A};
14910071SN/A
1500SN/A
1510SN/Astatic const unsigned char KEY2[] =
1520SN/A{
15313510Smsheppar    0x30, 0x82, 0x02, 0x5c, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xa8, 0x6e, 0x40, 0x86, 0x9f,
1540SN/A    0x98, 0x59, 0xfb, 0x57, 0xbf, 0xc1, 0x55, 0x12, 0x38, 0xeb, 0xb3, 0x46, 0x34, 0xc9, 0x35, 0x4d,
1550SN/A    0xfd, 0x03, 0xe9, 0x3a, 0x88, 0x9e, 0x97, 0x8f, 0xf4, 0xec, 0x36, 0x7b, 0x3f, 0xba, 0xb8, 0xa5,
1560SN/A    0x96, 0x30, 0x03, 0xc5, 0xc6, 0xd9, 0xa8, 0x4e, 0xbc, 0x23, 0x51, 0xa1, 0x96, 0xd2, 0x03, 0x98,
1570SN/A    0x73, 0xb6, 0x17, 0x9c, 0x77, 0xd4, 0x95, 0x1e, 0x1b, 0xb3, 0x1b, 0xc8, 0x71, 0xd1, 0x2e, 0x31,
1580SN/A    0xc7, 0x6a, 0x75, 0x57, 0x08, 0x7f, 0xba, 0x70, 0x76, 0xf7, 0x67, 0xf4, 0x4e, 0xbe, 0xfc, 0x70,
1590SN/A    0x61, 0x41, 0x07, 0x2b, 0x7c, 0x3c, 0x3b, 0xb3, 0xbc, 0xd5, 0xa8, 0xbd, 0x28, 0xd8, 0x49, 0xd3,
1600SN/A    0xe1, 0x78, 0xc8, 0xc1, 0x42, 0x5e, 0x18, 0x36, 0xa8, 0x41, 0xf7, 0xc8, 0xaa, 0x35, 0xfe, 0x2d,
1610SN/A    0xd1, 0xb4, 0xcc, 0x00, 0x67, 0xae, 0x79, 0xd3, 0x28, 0xd5, 0x5b, 0x02, 0x03, 0x01, 0x00, 0x01,
1620SN/A    0x02, 0x81, 0x81, 0x00, 0xa6, 0x00, 0x83, 0xf8, 0x2b, 0x33, 0xac, 0xfb, 0xdb, 0xf0, 0x52, 0x4b,
1630SN/A    0xd6, 0x39, 0xe3, 0x94, 0x3d, 0x8d, 0xa9, 0x01, 0xb0, 0x6b, 0xbe, 0x7f, 0x10, 0x01, 0xb6, 0xcd,
1640SN/A    0x0a, 0x45, 0x0a, 0xca, 0x67, 0x8e, 0xd8, 0x29, 0x44, 0x8a, 0x51, 0xa8, 0x66, 0x35, 0x26, 0x30,
1650SN/A    0x8b, 0xe9, 0x41, 0xa6, 0x22, 0xec, 0xd2, 0xf0, 0x58, 0x41, 0x33, 0x26, 0xf2, 0x3f, 0xe8, 0x75,
1660SN/A    0x4f, 0xc7, 0x5d, 0x2e, 0x5a, 0xa8, 0x7a, 0xd2, 0xbf, 0x59, 0xa0, 0x86, 0x79, 0x0b, 0x92, 0x6c,
1670SN/A    0x95, 0x5d, 0x87, 0x63, 0x5c, 0xd6, 0x1a, 0xc0, 0xf6, 0x7a, 0x15, 0x8d, 0xc7, 0x3c, 0xb6, 0x9e,
1680SN/A    0xa6, 0x58, 0x46, 0x9b, 0xbf, 0x3e, 0x28, 0x8c, 0xdf, 0x1a, 0x87, 0xaa, 0x7e, 0xf5, 0xf2, 0xcb,
1690SN/A    0x5e, 0x84, 0x2d, 0xf6, 0x82, 0x7e, 0x89, 0x4e, 0xf5, 0xe6, 0x3c, 0x92, 0x80, 0x1e, 0x98, 0x1c,
1700SN/A    0x6a, 0x7b, 0x57, 0x01, 0x02, 0x41, 0x00, 0xdd, 0x60, 0x95, 0xd7, 0xa1, 0x9d, 0x0c, 0xa1, 0x84,
1710SN/A    0xc5, 0x39, 0xca, 0x67, 0x4c, 0x1c, 0x06, 0x71, 0x5b, 0x5c, 0x2d, 0x8d, 0xce, 0xcd, 0xe2, 0x79,
1720SN/A    0xc8, 0x33, 0xbe, 0x50, 0x37, 0x60, 0x9f, 0x3b, 0xb9, 0x59, 0x55, 0x22, 0x1f, 0xa5, 0x4b, 0x1d,
1730SN/A    0xca, 0x38, 0xa0, 0xab, 0x87, 0x9c, 0x86, 0x0e, 0xdb, 0x1c, 0x4f, 0x4f, 0x07, 0xed, 0x18, 0x3f,
1740SN/A    0x05, 0x3c, 0xec, 0x78, 0x11, 0xf6, 0x99, 0x02, 0x41, 0x00, 0xc2, 0xc5, 0xcf, 0xbe, 0x95, 0x91,
1750SN/A    0xeb, 0xcf, 0x47, 0xf3, 0x33, 0x32, 0xc7, 0x7e, 0x93, 0x56, 0xf7, 0xd8, 0xf9, 0xd4, 0xb6, 0xd6,
1760SN/A    0x20, 0xac, 0xba, 0x8a, 0x20, 0x19, 0x14, 0xab, 0xc5, 0x5d, 0xb2, 0x08, 0xcc, 0x77, 0x7c, 0x65,
1770SN/A    0xa8, 0xdb, 0x66, 0x97, 0x36, 0x44, 0x2c, 0x63, 0xc0, 0x6a, 0x7e, 0xb0, 0x0b, 0x5c, 0x90, 0x12,
1780SN/A    0x50, 0xb4, 0x36, 0x60, 0xc3, 0x1f, 0x22, 0x0c, 0xc8, 0x13, 0x02, 0x40, 0x33, 0xc8, 0x7e, 0x04,
1790SN/A    0x7c, 0x97, 0x61, 0xf6, 0xfe, 0x39, 0xac, 0x34, 0xfe, 0x48, 0xbd, 0x5d, 0x7c, 0x72, 0xa4, 0x73,
1800SN/A    0x3b, 0x72, 0x9e, 0x92, 0x55, 0x6e, 0x51, 0x3c, 0x39, 0x43, 0x5a, 0xe4, 0xa4, 0x71, 0xcc, 0xc5,
1810SN/A    0xaf, 0x3f, 0xbb, 0xc8, 0x80, 0x65, 0x67, 0x2d, 0x9e, 0x32, 0x10, 0x99, 0x03, 0x2c, 0x99, 0xc8,
1820SN/A    0xab, 0x71, 0xed, 0x31, 0xf8, 0xbb, 0xde, 0xee, 0x69, 0x7f, 0xba, 0x31, 0x02, 0x40, 0x7e, 0xbc,
1830SN/A    0x60, 0x55, 0x4e, 0xd5, 0xc8, 0x6e, 0xf4, 0x0e, 0x57, 0xbe, 0x2e, 0xf9, 0x39, 0xbe, 0x59, 0x3f,
1840SN/A    0xa2, 0x30, 0xbb, 0x57, 0xd1, 0xa3, 0x13, 0x2e, 0x55, 0x7c, 0x7c, 0x6a, 0xd8, 0xde, 0x02, 0xbe,
1850SN/A    0x9e, 0xed, 0x10, 0xd0, 0xc5, 0x73, 0x1d, 0xea, 0x3e, 0xb1, 0x55, 0x81, 0x02, 0xef, 0x48, 0xc8,
1860SN/A    0x1c, 0x5c, 0x7a, 0x92, 0xb0, 0x58, 0xd3, 0x19, 0x5b, 0x5d, 0xa2, 0xb6, 0x56, 0x69, 0x02, 0x40,
1870SN/A    0x1e, 0x00, 0x6a, 0x9f, 0xba, 0xee, 0x46, 0x5a, 0xc5, 0xb5, 0x9f, 0x91, 0x33, 0xdd, 0xc9, 0x96,
1880SN/A    0x75, 0xb7, 0x87, 0xcf, 0x18, 0x1c, 0xb7, 0xb9, 0x3f, 0x04, 0x10, 0xb8, 0x75, 0xa9, 0xb8, 0xa0,
1897755SN/A    0x31, 0x35, 0x03, 0x30, 0x89, 0xc8, 0x37, 0x68, 0x20, 0x30, 0x99, 0x39, 0x96, 0xd6, 0x2b, 0x3d,
1907755SN/A    0x5e, 0x45, 0x84, 0xf7, 0xd2, 0x61, 0x50, 0xc9, 0x50, 0xba, 0x8d, 0x08, 0xaa, 0xd0, 0x08, 0x1e,
1910SN/A};
1920SN/A
1930SN/A
1940SN/Astatic const PKCS12_ATTR ATTRS1[] = {
1950SN/A    { "friendlyName", "george" },
1960SN/A    { "localKeyID", "1234567890" },
1970SN/A    { "1.2.3.4.5", "MyCustomAttribute" },
1980SN/A    { NULL, NULL }
1990SN/A};
2000SN/A
2010SN/Astatic const PKCS12_ATTR ATTRS2[] = {
2020SN/A    { "friendlyName", "janet" },
2030SN/A    { "localKeyID", "987654321" },
2040SN/A    { "1.2.3.5.8.13", "AnotherCustomAttribute" },
2050SN/A    { NULL, NULL }
2060SN/A};
2070SN/A
2080SN/Astatic const PKCS12_ENC enc_default = {
2090SN/A#ifndef OPENSSL_NO_DES
2100SN/A    NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
2110SN/A#else
2120SN/A    NID_aes_128_cbc,
2130SN/A#endif
2140SN/A    "Password1",
2150SN/A    1000
2160SN/A};
2170SN/A
2180SN/Astatic const PKCS12_ENC mac_default = {
2190SN/A    NID_sha1,
2200SN/A    "Password1",
2210SN/A    1000
2220SN/A};
2230SN/A
2240SN/Astatic const int enc_nids_all[] = {
2250SN/A    /* NOTE: To use PBES2 we pass the desired cipher NID instead of NID_pbes2 */
2260SN/A    NID_aes_128_cbc,
2270SN/A    NID_aes_256_cbc,
2280SN/A#ifndef OPENSSL_NO_DES
2290SN/A    NID_des_ede3_cbc,
2300SN/A    NID_des_cbc,
2310SN/A#endif
2320SN/A#ifndef OPENSSL_NO_RC5
2330SN/A    NID_rc5_cbc,
2340SN/A#endif
2350SN/A#ifndef OPENSSL_NO_RC4
2360SN/A    NID_rc4,
2370SN/A#endif
23813510Smsheppar#ifndef OPENSSL_NO_RC2
23913510Smsheppar    NID_rc2_cbc,
2400SN/A#endif
2417755SN/A
2427755SN/A#ifndef OPENSSL_NO_MD2
2437755SN/A# ifndef OPENSSL_NO_DES
2440SN/A    NID_pbeWithMD2AndDES_CBC,
2457755SN/A# endif
2460SN/A# ifndef OPENSSL_NO_RC2
2477755SN/A    NID_pbeWithMD2AndRC2_CBC,
2480SN/A# endif
2490SN/A#endif
2500SN/A
2510SN/A#ifndef OPENSSL_NO_MD5
2520SN/A# ifndef OPENSSL_NO_DES
2530SN/A    NID_pbeWithMD5AndDES_CBC,
2547755SN/A# endif
2550SN/A# ifndef OPENSSL_NO_RC2
2560SN/A    NID_pbeWithMD5AndRC2_CBC,
2570SN/A# endif
2580SN/A#endif
2590SN/A#ifndef OPENSSL_NO_DES
2607755SN/A    NID_pbeWithSHA1AndDES_CBC,
2610SN/A#endif
2620SN/A#ifndef OPENSSL_NO_RC2
2637755SN/A    NID_pbe_WithSHA1And128BitRC2_CBC,
2647755SN/A    NID_pbe_WithSHA1And40BitRC2_CBC,
2650SN/A    NID_pbeWithSHA1AndRC2_CBC,
2660SN/A#endif
2677755SN/A#ifndef OPENSSL_NO_RC4
2687755SN/A    NID_pbe_WithSHA1And128BitRC4,
26911480Schegar    NID_pbe_WithSHA1And40BitRC4,
27011480Schegar#endif
27111480Schegar#ifndef OPENSSL_NO_DES
27211480Schegar    NID_pbe_WithSHA1And2_Key_TripleDES_CBC,
27311480Schegar    NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
27411480Schegar#endif
27511480Schegar};
27611480Schegar
27711480Schegarstatic const int enc_nids_no_legacy[] = {
27811480Schegar    /* NOTE: To use PBES2 we pass the desired cipher NID instead of NID_pbes2 */
27911480Schegar    NID_aes_128_cbc,
28011480Schegar    NID_aes_256_cbc,
28111480Schegar#ifndef OPENSSL_NO_DES
28211796Schegar    NID_des_ede3_cbc,
28311796Schegar    NID_pbe_WithSHA1And2_Key_TripleDES_CBC,
28411796Schegar    NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
28511796Schegar#endif
28611796Schegar};
28711796Schegar
28811796Schegarstatic const int mac_nids[] = {
28911796Schegar    NID_sha1,
29011796Schegar    NID_md5,
29111796Schegar    NID_sha256,
29211796Schegar    NID_sha512,
29311796Schegar    NID_sha3_256,
29411796Schegar    NID_sha3_512
29511796Schegar};
29611796Schegar
29711796Schegarstatic const int iters[] = {
29811796Schegar    1,
2990SN/A    1000
3009892SN/A};
3010SN/A
3027755SN/Astatic const char *passwords[] = {
3037755SN/A    "Password1",
3040SN/A    "",
3050SN/A};
3060SN/A
3070SN/A/* --------------------------------------------------------------------------
3080SN/A * Local functions
3095991SN/A */
3100SN/A
31111480Schegarstatic int get_custom_oid(void)
31211480Schegar{
31311480Schegar    static int sec_nid = -1;
31411480Schegar
31511480Schegar    if (sec_nid != -1)
31611480Schegar        return sec_nid;
3170SN/A    if (!TEST_true(OBJ_create("1.3.5.7.9", "CustomSecretOID", "My custom secret OID")))
3180SN/A        return -1;
3190SN/A    return sec_nid = OBJ_txt2nid("CustomSecretOID");
3200SN/A}
3210SN/A
3220SN/A
3230SN/A/* --------------------------------------------------------------------------
32413346Ssebastian * PKCS12 format tests
32513346Ssebastian */
3260SN/A
3270SN/Astatic int test_single_cert_no_attrs(void)
3280SN/A{
3290SN/A    PKCS12_BUILDER *pb = new_pkcs12_builder("1cert.p12");
3300SN/A
3310SN/A    /* Generate/encode */
3320SN/A    start_pkcs12(pb);
3330SN/A
3340SN/A        start_contentinfo(pb);
3350SN/A
3360SN/A            add_certbag(pb, CERT1, sizeof(CERT1), NULL);
3370SN/A
3380SN/A        end_contentinfo(pb);
3390SN/A
3407755SN/A    end_pkcs12(pb);
3417755SN/A
3420SN/A    /* Read/decode */
3430SN/A    start_check_pkcs12(pb);
34413346Ssebastian
34513346Ssebastian        start_check_contentinfo(pb);
34613346Ssebastian
3470SN/A            check_certbag(pb, CERT1, sizeof(CERT1), NULL);
3480SN/A
3490SN/A        end_check_contentinfo(pb);
3500SN/A
3510SN/A    end_check_pkcs12(pb);
3520SN/A
3530SN/A    return end_pkcs12_builder(pb);
3540SN/A}
3550SN/A
3560SN/Astatic int test_single_key(PKCS12_ENC *enc)
3570SN/A{
3580SN/A    char fname[80];
3590SN/A    PKCS12_BUILDER *pb;
3600SN/A
3610SN/A    sprintf(fname, "1key_ciph-%s_iter-%d.p12", OBJ_nid2sn(enc->nid), enc->iter);
3620SN/A
3637755SN/A    pb = new_pkcs12_builder(fname);
3647755SN/A
3657755SN/A    /* Generate/encode */
3667755SN/A    start_pkcs12(pb);
3670SN/A
3687755SN/A        start_contentinfo(pb);
3690SN/A
3700SN/A            add_keybag(pb, KEY1, sizeof(KEY1), NULL, enc);
3710SN/A
3720SN/A        end_contentinfo(pb);
3730SN/A
3740SN/A    end_pkcs12(pb);
3757755SN/A
3760SN/A    /* Read/decode */
3777755SN/A    start_check_pkcs12(pb);
3780SN/A
3790SN/A        start_check_contentinfo(pb);
3800SN/A
3810SN/A            check_keybag(pb, KEY1, sizeof(KEY1), NULL, enc);
3820SN/A
3830SN/A        end_check_contentinfo(pb);
3840SN/A
3850SN/A    end_check_pkcs12(pb);
3860SN/A
38713346Ssebastian    return end_pkcs12_builder(pb);
38813346Ssebastian}
3890SN/A
3900SN/Astatic int test_single_key_enc_alg(int z)
3917755SN/A{
3920SN/A    PKCS12_ENC enc;
3930SN/A
3940SN/A    if (lgcyprov == NULL)
3950SN/A        enc.nid = enc_nids_no_legacy[z];
3960SN/A    else
3970SN/A        enc.nid = enc_nids_all[z];
3980SN/A    enc.pass = enc_default.pass;
3990SN/A    enc.iter = enc_default.iter;
4000SN/A
4010SN/A    return test_single_key(&enc);
4020SN/A}
4030SN/A
4040SN/Astatic int test_single_key_enc_pass(int z)
4050SN/A{
4060SN/A    PKCS12_ENC enc;
4070SN/A
4080SN/A    enc.nid = enc_default.nid;
4090SN/A    enc.pass = passwords[z];
4100SN/A    enc.iter = enc_default.iter;
4110SN/A
41213551Sredestad    return test_single_key(&enc);
4130SN/A}
4140SN/A
4150SN/Astatic int test_single_key_enc_iter(int z)
4160SN/A{
4170SN/A    PKCS12_ENC enc;
4180SN/A
4190SN/A    enc.nid = enc_default.nid;
4200SN/A    enc.pass = enc_default.pass;
4210SN/A    enc.iter = iters[z];
4220SN/A
4230SN/A    return test_single_key(&enc);
4240SN/A}
4250SN/A
4260SN/Astatic int test_single_key_with_attrs(void)
4270SN/A{
4280SN/A    PKCS12_BUILDER *pb = new_pkcs12_builder("1keyattrs.p12");
4290SN/A
4300SN/A    /* Generate/encode */
4310SN/A    start_pkcs12(pb);
4320SN/A
43314852Sredestad        start_contentinfo(pb);
43414852Sredestad
43514852Sredestad            add_keybag(pb, KEY1, sizeof(KEY1), ATTRS1, &enc_default);
43614852Sredestad
43714852Sredestad        end_contentinfo(pb);
43814852Sredestad
43914852Sredestad    end_pkcs12(pb);
4400SN/A
4410SN/A    /* Read/decode */
44214852Sredestad    start_check_pkcs12(pb);
4430SN/A
4440SN/A        start_check_contentinfo(pb);
4450SN/A
4460SN/A            check_keybag(pb, KEY1, sizeof(KEY1), ATTRS1, &enc_default);
4470SN/A
4480SN/A        end_check_contentinfo(pb);
4490SN/A
4500SN/A    end_check_pkcs12(pb);
4510SN/A
4520SN/A    return end_pkcs12_builder(pb);
4530SN/A}
4540SN/A
4550SN/Astatic int test_single_cert_mac(PKCS12_ENC *mac)
4567755SN/A{
4570SN/A    char fname[80];
4580SN/A    PKCS12_BUILDER *pb;
4590SN/A
4607755SN/A    sprintf(fname, "1cert_mac-%s_iter-%d.p12", OBJ_nid2sn(mac->nid), mac->iter);
4610SN/A
4627755SN/A    pb = new_pkcs12_builder(fname);
4630SN/A
46413346Ssebastian    /* Generate/encode */
46513346Ssebastian    start_pkcs12(pb);
46613346Ssebastian
4670SN/A        start_contentinfo(pb);
4680SN/A
4690SN/A            add_certbag(pb, CERT1, sizeof(CERT1), NULL);
4700SN/A
4710SN/A        end_contentinfo(pb);
4720SN/A
4730SN/A    end_pkcs12_with_mac(pb, mac);
4740SN/A
4750SN/A    /* Read/decode */
4760SN/A    start_check_pkcs12_with_mac(pb, mac);
4770SN/A
4780SN/A        start_check_contentinfo(pb);
4790SN/A
4800SN/A            check_certbag(pb, CERT1, sizeof(CERT1), NULL);
4810SN/A
4820SN/A        end_check_contentinfo(pb);
4830SN/A
4840SN/A    end_check_pkcs12(pb);
4850SN/A
4860SN/A    return end_pkcs12_builder(pb);
4870SN/A}
4880SN/A
4890SN/Astatic int test_single_cert_mac_alg(int z)
4900SN/A{
4910SN/A    PKCS12_ENC mac;
4920SN/A
4930SN/A    mac.nid = mac_nids[z];
4940SN/A    mac.pass = mac_default.pass;
4950SN/A    mac.iter = mac_default.iter;
4960SN/A
4970SN/A    return test_single_cert_mac(&mac);
4980SN/A}
4990SN/A
5000SN/Astatic int test_single_cert_mac_pass(int z)
5010SN/A{
5020SN/A    PKCS12_ENC mac;
5030SN/A
5040SN/A    mac.nid = mac_default.nid;
5050SN/A    mac.pass = passwords[z];
5068565SN/A    mac.iter = mac_default.iter;
5070SN/A
5080SN/A    return test_single_cert_mac(&mac);
5090SN/A}
5100SN/A
5117755SN/Astatic int test_single_cert_mac_iter(int z)
5120SN/A{
51313346Ssebastian    PKCS12_ENC mac;
51413346Ssebastian
51513346Ssebastian    mac.nid = mac_default.nid;
5160SN/A    mac.pass = mac_default.pass;
5170SN/A    mac.iter = iters[z];
5180SN/A
5190SN/A    return test_single_cert_mac(&mac);
5200SN/A}
5210SN/A
5220SN/Astatic int test_cert_key_with_attrs_and_mac(void)
5230SN/A{
5240SN/A    PKCS12_BUILDER *pb = new_pkcs12_builder("1cert1key.p12");
5250SN/A
5260SN/A    /* Generate/encode */
5270SN/A    start_pkcs12(pb);
5280SN/A
5290SN/A        start_contentinfo(pb);
5300SN/A
5310SN/A            add_certbag(pb, CERT1, sizeof(CERT1), ATTRS1);
5327755SN/A            add_keybag(pb, KEY1, sizeof(KEY1), ATTRS1, &enc_default);
5330SN/A
5340SN/A        end_contentinfo(pb);
53513346Ssebastian
53613346Ssebastian    end_pkcs12_with_mac(pb, &mac_default);
53713346Ssebastian
5380SN/A    /* Read/decode */
5390SN/A    start_check_pkcs12_with_mac(pb, &mac_default);
5407755SN/A
5410SN/A        start_check_contentinfo(pb);
5420SN/A
5430SN/A            check_certbag(pb, CERT1, sizeof(CERT1), ATTRS1);
5440SN/A            check_keybag(pb, KEY1, sizeof(KEY1), ATTRS1, &enc_default);
5450SN/A
5460SN/A        end_check_contentinfo(pb);
5470SN/A
5480SN/A    end_check_pkcs12(pb);
5490SN/A
5500SN/A    return end_pkcs12_builder(pb);
5510SN/A}
5520SN/A
5530SN/Astatic int test_cert_key_encrypted_content(void)
5540SN/A{
5550SN/A    PKCS12_BUILDER *pb = new_pkcs12_builder("1cert1key_enc.p12");
5560SN/A
5570SN/A    /* Generate/encode */
5580SN/A    start_pkcs12(pb);
5590SN/A
5600SN/A        start_contentinfo(pb);
5610SN/A
5620SN/A            add_certbag(pb, CERT1, sizeof(CERT1), ATTRS1);
5630SN/A            add_keybag(pb, KEY1, sizeof(KEY1), ATTRS1, &enc_default);
5640SN/A
5650SN/A        end_contentinfo_encrypted(pb, &enc_default);
5660SN/A
5670SN/A    end_pkcs12_with_mac(pb, &mac_default);
5680SN/A
5690SN/A    /* Read/decode */
5700SN/A    start_check_pkcs12_with_mac(pb, &mac_default);
5710SN/A
5720SN/A        start_check_contentinfo_encrypted(pb, &enc_default);
5730SN/A
5740SN/A            check_certbag(pb, CERT1, sizeof(CERT1), ATTRS1);
5750SN/A            check_keybag(pb, KEY1, sizeof(KEY1), ATTRS1, &enc_default);
5760SN/A
5770SN/A        end_check_contentinfo(pb);
5780SN/A
5790SN/A    end_check_pkcs12(pb);
5800SN/A
5810SN/A    return end_pkcs12_builder(pb);
5820SN/A}
5830SN/A
5840SN/Astatic int test_single_secret_encrypted_content(void)
5850SN/A{
5860SN/A    PKCS12_BUILDER *pb = new_pkcs12_builder("1secret.p12");
5870SN/A    int custom_nid = get_custom_oid();
58813551Sredestad
5890SN/A    /* Generate/encode */
5900SN/A    start_pkcs12(pb);
5910SN/A
5920SN/A        start_contentinfo(pb);
5930SN/A
5940SN/A            add_secretbag(pb, custom_nid, "VerySecretMessage", ATTRS1);
5950SN/A
5960SN/A        end_contentinfo_encrypted(pb, &enc_default);
5970SN/A
5980SN/A    end_pkcs12_with_mac(pb, &mac_default);
5990SN/A
6000SN/A    /* Read/decode */
6010SN/A    start_check_pkcs12_with_mac(pb, &mac_default);
6020SN/A
6030SN/A        start_check_contentinfo_encrypted(pb, &enc_default);
6040SN/A
6050SN/A            check_secretbag(pb, custom_nid, "VerySecretMessage", ATTRS1);
6060SN/A
6070SN/A        end_check_contentinfo(pb);
6080SN/A
6090SN/A    end_check_pkcs12(pb);
6100SN/A
6110SN/A    return end_pkcs12_builder(pb);
6120SN/A}
6130SN/A
6140SN/Astatic int test_single_secret(PKCS12_ENC *enc)
6150SN/A{
6160SN/A    int custom_nid;
6170SN/A    char fname[80];
6180SN/A    PKCS12_BUILDER *pb;
6190SN/A
6200SN/A    sprintf(fname, "1secret_ciph-%s_iter-%d.p12", OBJ_nid2sn(enc->nid), enc->iter);
6210SN/A    pb = new_pkcs12_builder(fname);
6220SN/A    custom_nid = get_custom_oid();
6230SN/A
6240SN/A    /* Generate/encode */
6250SN/A    start_pkcs12(pb);
6260SN/A
6270SN/A        start_contentinfo(pb);
6280SN/A
6290SN/A            add_secretbag(pb, custom_nid, "VerySecretMessage", ATTRS1);
6300SN/A
6310SN/A        end_contentinfo_encrypted(pb, enc);
6320SN/A
6330SN/A    end_pkcs12_with_mac(pb, &mac_default);
6340SN/A
6350SN/A    /* Read/decode */
6360SN/A    start_check_pkcs12_with_mac(pb, &mac_default);
6370SN/A
6380SN/A        start_check_contentinfo_encrypted(pb, enc);
6390SN/A
6400SN/A            check_secretbag(pb, custom_nid, "VerySecretMessage", ATTRS1);
6410SN/A
6420SN/A        end_check_contentinfo(pb);
6430SN/A
6440SN/A    end_check_pkcs12(pb);
6450SN/A
6460SN/A    return end_pkcs12_builder(pb);
6470SN/A}
6480SN/A
6490SN/Astatic int test_single_secret_enc_alg(int z)
6500SN/A{
6510SN/A    PKCS12_ENC enc;
6520SN/A
6530SN/A    if (lgcyprov == NULL)
6540SN/A        enc.nid = enc_nids_no_legacy[z];
6550SN/A    else
6560SN/A        enc.nid = enc_nids_all[z];
6570SN/A    enc.pass = enc_default.pass;
6580SN/A    enc.iter = enc_default.iter;
6590SN/A
6600SN/A    return test_single_secret(&enc);
6610SN/A}
6620SN/A
6630SN/Astatic int test_multiple_contents(void)
6640SN/A{
6650SN/A    PKCS12_BUILDER *pb = new_pkcs12_builder("multi_contents.p12");
6660SN/A    int custom_nid = get_custom_oid();
66713563Sredestad
66813563Sredestad    /* Generate/encode */
66913563Sredestad    start_pkcs12(pb);
67013563Sredestad
67113563Sredestad        start_contentinfo(pb);
67213563Sredestad
67313563Sredestad            add_certbag(pb, CERT1, sizeof(CERT1), ATTRS1);
67413563Sredestad            add_certbag(pb, CERT2, sizeof(CERT2), ATTRS2);
67513563Sredestad            add_keybag(pb, KEY1, sizeof(KEY1), ATTRS1, &enc_default);
67613563Sredestad            add_keybag(pb, KEY2, sizeof(KEY2), ATTRS2, &enc_default);
67713569Sredestad
67813569Sredestad        end_contentinfo(pb);
67913569Sredestad
68013569Sredestad        start_contentinfo(pb);
68113569Sredestad
68213569Sredestad            add_secretbag(pb, custom_nid, "VeryVerySecretMessage", ATTRS1);
68313569Sredestad
68413569Sredestad        end_contentinfo_encrypted(pb, &enc_default);
68513569Sredestad
68613563Sredestad    end_pkcs12_with_mac(pb, &mac_default);
68713563Sredestad
68813563Sredestad    /* Read/decode */
68913563Sredestad    start_check_pkcs12_with_mac(pb, &mac_default);
69013563Sredestad
69113563Sredestad        start_check_contentinfo(pb);
69213563Sredestad
69313563Sredestad            check_certbag(pb, CERT1, sizeof(CERT1), ATTRS1);
69413563Sredestad            check_certbag(pb, CERT2, sizeof(CERT2), ATTRS2);
69513563Sredestad            check_keybag(pb, KEY1, sizeof(KEY1), ATTRS1, &enc_default);
69613563Sredestad            check_keybag(pb, KEY2, sizeof(KEY2), ATTRS2, &enc_default);
69713563Sredestad
69813563Sredestad        end_check_contentinfo(pb);
69913569Sredestad
70013563Sredestad        start_check_contentinfo_encrypted(pb, &enc_default);
70113563Sredestad
70213563Sredestad            check_secretbag(pb, custom_nid, "VeryVerySecretMessage", ATTRS1);
70313563Sredestad
70413563Sredestad        end_check_contentinfo(pb);
7050SN/A
7060SN/A    end_check_pkcs12(pb);
7070SN/A
7080SN/A    return end_pkcs12_builder(pb);
7090SN/A}
7100SN/A
7110SN/A#ifndef OPENSSL_NO_DES
7120SN/Astatic int pkcs12_create_test(void)
7130SN/A{
7140SN/A    int ret = 0;
7150SN/A    EVP_PKEY *pkey = NULL;
7160SN/A    PKCS12 *p12 = NULL;
7170SN/A    const unsigned char *p;
7180SN/A
7190SN/A    static const unsigned char rsa_key[] = {
7200SN/A        0x30, 0x82, 0x02, 0x5d, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xbb,
7210SN/A        0x24, 0x7a, 0x09, 0x7e, 0x0e, 0xb2, 0x37, 0x32, 0xcc, 0x39, 0x67, 0xad,
7220SN/A        0xf1, 0x9e, 0x3d, 0x6b, 0x82, 0x83, 0xd1, 0xd0, 0xac, 0xa4, 0xc0, 0x18,
7230SN/A        0xbe, 0x8d, 0x98, 0x00, 0xc0, 0x7b, 0xff, 0x07, 0x44, 0xc9, 0xca, 0x1c,
7240SN/A        0xba, 0x36, 0xe1, 0x27, 0x69, 0xff, 0xb1, 0xe3, 0x8d, 0x8b, 0xee, 0x57,
7250SN/A        0xa9, 0x3a, 0xaa, 0x16, 0x43, 0x39, 0x54, 0x19, 0x7c, 0xae, 0x69, 0x24,
7260SN/A        0x14, 0xf6, 0x64, 0xff, 0xbc, 0x74, 0xc6, 0x67, 0x6c, 0x4c, 0xf1, 0x02,
7270SN/A        0x49, 0x69, 0xc7, 0x2b, 0xe1, 0xe1, 0xa1, 0xa3, 0x43, 0x14, 0xf4, 0x77,
7280SN/A        0x8f, 0xc8, 0xd0, 0x85, 0x5a, 0x35, 0x95, 0xac, 0x62, 0xa9, 0xc1, 0x21,
7290SN/A        0x00, 0x77, 0xa0, 0x8b, 0x97, 0x30, 0xb4, 0x5a, 0x2c, 0xb8, 0x90, 0x2f,
7300SN/A        0x48, 0xa0, 0x05, 0x28, 0x4b, 0xf2, 0x0f, 0x8d, 0xec, 0x8b, 0x4d, 0x03,
7310SN/A        0x42, 0x75, 0xd6, 0xad, 0x81, 0xc0, 0x11, 0x02, 0x03, 0x01, 0x00, 0x01,
7320SN/A        0x02, 0x81, 0x80, 0x00, 0xfc, 0xb9, 0x4a, 0x26, 0x07, 0x89, 0x51, 0x2b,
7330SN/A        0x53, 0x72, 0x91, 0xe0, 0x18, 0x3e, 0xa6, 0x5e, 0x31, 0xef, 0x9c, 0x0c,
7340SN/A        0x16, 0x24, 0x42, 0xd0, 0x28, 0x33, 0xf9, 0xfa, 0xd0, 0x3c, 0x54, 0x04,
7350SN/A        0x06, 0xc0, 0x15, 0xf5, 0x1b, 0x9a, 0xb3, 0x24, 0x31, 0xab, 0x3c, 0x6b,
7360SN/A        0x47, 0x43, 0xb0, 0xd2, 0xa9, 0xdc, 0x05, 0xe1, 0x81, 0x59, 0xb6, 0x04,
7370SN/A        0xe9, 0x66, 0x61, 0xaa, 0xd7, 0x0b, 0x00, 0x8f, 0x3d, 0xe5, 0xbf, 0xa2,
7380SN/A        0xf8, 0x5e, 0x25, 0x6c, 0x1e, 0x22, 0x0f, 0xb4, 0xfd, 0x41, 0xe2, 0x03,
7390SN/A        0x31, 0x5f, 0xda, 0x20, 0xc5, 0xc0, 0xf3, 0x55, 0x0e, 0xe1, 0xc9, 0xec,
7400SN/A        0xd7, 0x3e, 0x2a, 0x0c, 0x01, 0xca, 0x7b, 0x22, 0xcb, 0xac, 0xf4, 0x2b,
7410SN/A        0x27, 0xf0, 0x78, 0x5f, 0xb5, 0xc2, 0xf9, 0xe8, 0x14, 0x5a, 0x6e, 0x7e,
7420SN/A        0x86, 0xbd, 0x6a, 0x9b, 0x20, 0x0c, 0xba, 0xcc, 0x97, 0x20, 0x11, 0x02,
7436693SN/A        0x41, 0x00, 0xc9, 0x59, 0x9f, 0x29, 0x8a, 0x5b, 0x9f, 0xe3, 0x2a, 0xd8,
7446693SN/A        0x7e, 0xc2, 0x40, 0x9f, 0xa8, 0x45, 0xe5, 0x3e, 0x11, 0x8d, 0x3c, 0xed,
7450SN/A        0x6e, 0xab, 0xce, 0xd0, 0x65, 0x46, 0xd8, 0xc7, 0x07, 0x63, 0xb5, 0x23,
7460SN/A        0x34, 0xf4, 0x9f, 0x7e, 0x1c, 0xc7, 0xc7, 0xf9, 0x65, 0xd1, 0xf4, 0x04,
7470SN/A        0x42, 0x38, 0xbe, 0x3a, 0x0c, 0x9d, 0x08, 0x25, 0xfc, 0xa3, 0x71, 0xd9,
7480SN/A        0xae, 0x0c, 0x39, 0x61, 0xf4, 0x89, 0x02, 0x41, 0x00, 0xed, 0xef, 0xab,
7490SN/A        0xa9, 0xd5, 0x39, 0x9c, 0xee, 0x59, 0x1b, 0xff, 0xcf, 0x48, 0x44, 0x1b,
7500SN/A        0xb6, 0x32, 0xe7, 0x46, 0x24, 0xf3, 0x04, 0x7f, 0xde, 0x95, 0x08, 0x6d,
7510SN/A        0x75, 0x9e, 0x67, 0x17, 0xba, 0x5c, 0xa4, 0xd4, 0xe2, 0xe2, 0x4d, 0x77,
7520SN/A        0xce, 0xeb, 0x66, 0x29, 0xc5, 0x96, 0xe0, 0x62, 0xbb, 0xe5, 0xac, 0xdc,
7530SN/A        0x44, 0x62, 0x54, 0x86, 0xed, 0x64, 0x0c, 0xce, 0xd0, 0x60, 0x03, 0x9d,
7540SN/A        0x49, 0x02, 0x40, 0x54, 0xd9, 0x18, 0x72, 0x27, 0xe4, 0xbe, 0x76, 0xbb,
7550SN/A        0x1a, 0x6a, 0x28, 0x2f, 0x95, 0x58, 0x12, 0xc4, 0x2c, 0xa8, 0xb6, 0xcc,
7560SN/A        0xe2, 0xfd, 0x0d, 0x17, 0x64, 0xc8, 0x18, 0xd7, 0xc6, 0xdf, 0x3d, 0x4c,
7570SN/A        0x1a, 0x9e, 0xf9, 0x2a, 0xb0, 0xb9, 0x2e, 0x12, 0xfd, 0xec, 0xc3, 0x51,
7580SN/A        0xc1, 0xed, 0xa9, 0xfd, 0xb7, 0x76, 0x93, 0x41, 0xd8, 0xc8, 0x22, 0x94,
7590SN/A        0x1a, 0x77, 0xf6, 0x9c, 0xc3, 0xc3, 0x89, 0x02, 0x41, 0x00, 0x8e, 0xf9,
7600SN/A        0xa7, 0x08, 0xad, 0xb5, 0x2a, 0x04, 0xdb, 0x8d, 0x04, 0xa1, 0xb5, 0x06,
7610SN/A        0x20, 0x34, 0xd2, 0xcf, 0xc0, 0x89, 0xb1, 0x72, 0x31, 0xb8, 0x39, 0x8b,
7620SN/A        0xcf, 0xe2, 0x8e, 0xa5, 0xda, 0x4f, 0x45, 0x1e, 0x53, 0x42, 0x66, 0xc4,
7630SN/A        0x30, 0x4b, 0x29, 0x8e, 0xc1, 0x69, 0x17, 0x29, 0x8c, 0x8a, 0xe6, 0x0f,
7640SN/A        0x82, 0x68, 0xa1, 0x41, 0xb3, 0xb6, 0x70, 0x99, 0x75, 0xa9, 0x27, 0x18,
7650SN/A        0xe4, 0xe9, 0x02, 0x41, 0x00, 0x89, 0xea, 0x6e, 0x6d, 0x70, 0xdf, 0x25,
7660SN/A        0x5f, 0x18, 0x3f, 0x48, 0xda, 0x63, 0x10, 0x8b, 0xfe, 0xa8, 0x0c, 0x94,
7670SN/A        0x0f, 0xde, 0x97, 0x56, 0x53, 0x89, 0x94, 0xe2, 0x1e, 0x2c, 0x74, 0x3c,
7680SN/A        0x91, 0x81, 0x34, 0x0b, 0xa6, 0x40, 0xf8, 0xcb, 0x2a, 0x60, 0x8c, 0xe0,
7690SN/A        0x02, 0xb7, 0x89, 0x93, 0xcf, 0x18, 0x9f, 0x49, 0x54, 0xfd, 0x7d, 0x3f,
7700SN/A        0x9a, 0xef, 0xd4, 0xa4, 0x4f, 0xc1, 0x45, 0x99, 0x91,
7710SN/A    };
7720SN/A
7730SN/A    p = rsa_key;
7740SN/A    if (!TEST_ptr(pkey = d2i_PrivateKey_ex(EVP_PKEY_RSA, NULL, &p,
7750SN/A                                           sizeof(rsa_key), NULL, NULL)))
7760SN/A        goto err;
7770SN/A    if (!TEST_int_eq(ERR_peek_error(), 0))
7780SN/A        goto err;
7790SN/A    p12 = PKCS12_create(NULL, NULL, pkey, NULL, NULL,
7806693SN/A                        NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
7816693SN/A                        NID_pbe_WithSHA1And3_Key_TripleDES_CBC, 2, 1, 0);
7826693SN/A    if (!TEST_ptr(p12))
7830SN/A        goto err;
7840SN/A
7850SN/A    if (!TEST_int_eq(ERR_peek_error(), 0))
7860SN/A        goto err;
7870SN/A    ret = 1;
7880SN/Aerr:
7890SN/A    PKCS12_free(p12);
7900SN/A    EVP_PKEY_free(pkey);
7910SN/A    return ret;
7920SN/A}
7930SN/A#endif
7940SN/A
7950SN/Astatic int pkcs12_recreate_test(void)
7960SN/A{
7970SN/A    int ret = 0;
7980SN/A    X509 *cert = NULL;
7990SN/A    X509 *cert_parsed = NULL;
8000SN/A    EVP_PKEY *pkey = NULL;
8017755SN/A    EVP_PKEY *pkey_parsed = NULL;
8020SN/A    PKCS12 *p12 = NULL;
8037755SN/A    PKCS12 *p12_parsed = NULL;
8040SN/A    PKCS12 *p12_recreated = NULL;
8050SN/A    const unsigned char *cert_bytes = CERT1;
8060SN/A    const unsigned char *key_bytes = KEY1;
8070SN/A    BIO *bio = NULL;
8080SN/A
8090SN/A    cert = d2i_X509(NULL, &cert_bytes, sizeof(CERT1));
8100SN/A    if (!TEST_ptr(cert))
8110SN/A        goto err;
8127755SN/A    pkey = d2i_AutoPrivateKey(NULL, &key_bytes, sizeof(KEY1));
8130SN/A    if (!TEST_ptr(pkey))
8147755SN/A        goto err;
8150SN/A    p12 = PKCS12_create("pass", NULL, pkey, cert, NULL, NID_aes_256_cbc,
8160SN/A                        NID_aes_256_cbc, 2, 1, 0);
8170SN/A    if (!TEST_ptr(p12))
8180SN/A        goto err;
8190SN/A    if (!TEST_int_eq(ERR_peek_error(), 0))
8200SN/A        goto err;
8210SN/A
8220SN/A    bio = BIO_new(BIO_s_mem());
8237755SN/A    if (!TEST_ptr(bio))
8240SN/A        goto err;
8257755SN/A    if (!TEST_int_eq(i2d_PKCS12_bio(bio, p12), 1))
8260SN/A        goto err;
8270SN/A    p12_parsed = PKCS12_init_ex(NID_pkcs7_data, testctx, NULL);
8280SN/A    if (!TEST_ptr(p12_parsed))
8290SN/A        goto err;
8300SN/A    p12_parsed = d2i_PKCS12_bio(bio, &p12_parsed);
8310SN/A    if (!TEST_ptr(p12_parsed))
8320SN/A        goto err;
8330SN/A    if (!TEST_int_eq(PKCS12_parse(p12_parsed, "pass", &pkey_parsed,
8347755SN/A                                  &cert_parsed, NULL), 1))
8350SN/A        goto err;
8367755SN/A
8370SN/A    /* cert_parsed also contains auxiliary data */
8380SN/A    p12_recreated = PKCS12_create("new_pass", NULL, pkey_parsed, cert_parsed,
8390SN/A                                  NULL, NID_aes_256_cbc, NID_aes_256_cbc,
8400SN/A                                  2, 1, 0);
8410SN/A    if (!TEST_ptr(p12_recreated))
8420SN/A        goto err;
8430SN/A    if (!TEST_int_eq(ERR_peek_error(), 0))
8447755SN/A        goto err;
8450SN/A
8460SN/A    ret = 1;
8470SN/Aerr:
8480SN/A    BIO_free(bio);
8490SN/A    PKCS12_free(p12);
8500SN/A    PKCS12_free(p12_parsed);
8510SN/A    PKCS12_free(p12_recreated);
8520SN/A    EVP_PKEY_free(pkey);
8530SN/A    EVP_PKEY_free(pkey_parsed);
8547755SN/A    X509_free(cert);
8550SN/A    X509_free(cert_parsed);
8560SN/A    return ret;
8570SN/A}
8580SN/A
8590SN/Atypedef enum OPTION_choice {
8600SN/A    OPT_ERR = -1,
8610SN/A    OPT_EOF = 0,
8620SN/A    OPT_WRITE,
8630SN/A    OPT_LEGACY,
8640SN/A    OPT_CONTEXT,
8650SN/A    OPT_TEST_ENUM
8667755SN/A} OPTION_CHOICE;
8670SN/A
8687755SN/Aconst OPTIONS *test_get_options(void)
8690SN/A{
8700SN/A    static const OPTIONS options[] = {
8710SN/A        OPT_TEST_OPTIONS_DEFAULT_USAGE,
8720SN/A        { "write",   OPT_WRITE,   '-', "Write PKCS12 objects to file" },
8730SN/A        { "legacy",  OPT_LEGACY,  '-', "Test the legacy APIs" },
8740SN/A        { "context", OPT_CONTEXT, '-', "Explicitly use a non-default library context" },
8757755SN/A        { NULL }
8760SN/A    };
8770SN/A    return options;
8787755SN/A}
8790SN/A
8807755SN/Aint setup_tests(void)
8810SN/A{
8820SN/A    OPTION_CHOICE o;
8830SN/A
8840SN/A    while ((o = opt_next()) != OPT_EOF) {
8850SN/A        switch (o) {
8860SN/A        case OPT_WRITE:
8877755SN/A            PKCS12_helper_set_write_files(1);
8880SN/A            break;
8890SN/A        case OPT_LEGACY:
8900SN/A            PKCS12_helper_set_legacy(1);
8910SN/A            break;
8920SN/A        case OPT_CONTEXT:
8930SN/A            default_libctx = 0;
8947755SN/A            break;
8950SN/A        case OPT_TEST_CASES:
8960SN/A            break;
8970SN/A        default:
8980SN/A            return 0;
8990SN/A        }
9000SN/A    }
9010SN/A
9020SN/A    if (!default_libctx) {
9037755SN/A        testctx = OSSL_LIB_CTX_new();
9040SN/A        if (!TEST_ptr(testctx))
9050SN/A            return 0;
9067755SN/A        nullprov = OSSL_PROVIDER_load(NULL, "null");
9070SN/A        if (!TEST_ptr(nullprov))
9080SN/A            return 0;
9090SN/A    }
9100SN/A
9110SN/A    deflprov = OSSL_PROVIDER_load(testctx, "default");
9120SN/A    if (!TEST_ptr(deflprov))
9130SN/A        return 0;
9140SN/A    lgcyprov = OSSL_PROVIDER_load(testctx, "legacy");
9150SN/A
9167755SN/A    PKCS12_helper_set_libctx(testctx);
9170SN/A
9180SN/A    /*
9190SN/A     * Verify that the default and fips providers in the default libctx are not
9200SN/A     * available if we are using a standalone context
9210SN/A     */
9220SN/A    if (!default_libctx) {
9230SN/A        if (!TEST_false(OSSL_PROVIDER_available(NULL, "default"))
9240SN/A                || !TEST_false(OSSL_PROVIDER_available(NULL, "fips")))
9250SN/A            return 0;
9260SN/A    }
9270SN/A
9280SN/A    ADD_TEST(test_single_cert_no_attrs);
9290SN/A    if (lgcyprov == NULL) {
9307755SN/A        ADD_ALL_TESTS(test_single_key_enc_alg, OSSL_NELEM(enc_nids_no_legacy));
9310SN/A        ADD_ALL_TESTS(test_single_secret_enc_alg, OSSL_NELEM(enc_nids_no_legacy));
9320SN/A    } else {
9330SN/A        ADD_ALL_TESTS(test_single_key_enc_alg, OSSL_NELEM(enc_nids_all));
9347755SN/A        ADD_ALL_TESTS(test_single_secret_enc_alg, OSSL_NELEM(enc_nids_all));
9357755SN/A    }
9360SN/A#ifndef OPENSSL_NO_DES
9370SN/A    if (default_libctx)
9380SN/A        ADD_TEST(pkcs12_create_test);
9390SN/A#endif
9400SN/A    if (default_libctx)
9410SN/A        ADD_TEST(pkcs12_recreate_test);
9420SN/A    ADD_ALL_TESTS(test_single_key_enc_pass, OSSL_NELEM(passwords));
9430SN/A    ADD_ALL_TESTS(test_single_key_enc_iter, OSSL_NELEM(iters));
9440SN/A    ADD_TEST(test_single_key_with_attrs);
9450SN/A    ADD_ALL_TESTS(test_single_cert_mac_alg, OSSL_NELEM(mac_nids));
9460SN/A    ADD_ALL_TESTS(test_single_cert_mac_pass, OSSL_NELEM(passwords));
9470SN/A    ADD_ALL_TESTS(test_single_cert_mac_iter, OSSL_NELEM(iters));
9480SN/A    ADD_TEST(test_cert_key_with_attrs_and_mac);
9499683SN/A    ADD_TEST(test_cert_key_encrypted_content);
9500SN/A    ADD_TEST(test_single_secret_encrypted_content);
9517755SN/A    ADD_TEST(test_multiple_contents);
9520SN/A    return 1;
9530SN/A}
9540SN/A
9550SN/Avoid cleanup_tests(void)
9560SN/A{
9570SN/A    OSSL_PROVIDER_unload(nullprov);
9580SN/A    OSSL_PROVIDER_unload(deflprov);
9590SN/A    OSSL_PROVIDER_unload(lgcyprov);
9600SN/A    OSSL_LIB_CTX_free(testctx);
9610SN/A}
9620SN/A