2 * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
14 #include "internal/nelem.h"
16 #include <openssl/pkcs12.h>
17 #include <openssl/x509.h>
18 #include <openssl/x509v3.h>
19 #include <openssl/pem.h>
21 #include "../testutil.h"
24 /* -------------------------------------------------------------------------
25 * PKCS#12 Test structures
28 /* Holds a set of Attributes */
29 typedef struct pkcs12_attr {
35 /* Holds encryption parameters */
36 typedef struct pkcs12_enc {
42 /* Set of variables required for constructing the PKCS#12 structure */
43 typedef struct pkcs12_builder {
47 STACK_OF(PKCS7) *safes;
49 STACK_OF(PKCS12_SAFEBAG) *bags;
54 /* -------------------------------------------------------------------------
55 * PKCS#12 Test function declarations
59 void PKCS12_helper_set_write_files(int enable);
60 void PKCS12_helper_set_legacy(int enable);
61 void PKCS12_helper_set_libctx(OSSL_LIB_CTX *libctx);
62 void PKCS12_helper_set_propq(const char *propq);
64 /* Allocate and initialise a PKCS#12 builder object */
65 PKCS12_BUILDER *new_pkcs12_builder(const char *filename);
67 /* Finalise and free the PKCS#12 builder object, returning the success/fail flag */
68 int end_pkcs12_builder(PKCS12_BUILDER *pb);
70 /* Encode/build functions */
71 void start_pkcs12(PKCS12_BUILDER *pb);
72 void end_pkcs12(PKCS12_BUILDER *pb);
73 void end_pkcs12_with_mac(PKCS12_BUILDER *pb, const PKCS12_ENC *mac);
75 void start_contentinfo(PKCS12_BUILDER *pb);
76 void end_contentinfo(PKCS12_BUILDER *pb);
77 void end_contentinfo_encrypted(PKCS12_BUILDER *pb, const PKCS12_ENC *enc);
79 void add_certbag(PKCS12_BUILDER *pb, const unsigned char *bytes, int len,
80 const PKCS12_ATTR *attrs);
81 void add_keybag(PKCS12_BUILDER *pb, const unsigned char *bytes, int len,
82 const PKCS12_ATTR *attrs, const PKCS12_ENC *enc);
83 void add_secretbag(PKCS12_BUILDER *pb, int secret_nid, const char *secret,
84 const PKCS12_ATTR *attrs);
86 /* Decode/check functions */
87 void start_check_pkcs12(PKCS12_BUILDER *pb);
88 void start_check_pkcs12_with_mac(PKCS12_BUILDER *pb, const PKCS12_ENC *mac);
89 void start_check_pkcs12_file(PKCS12_BUILDER *pb);
90 void start_check_pkcs12_file_with_mac(PKCS12_BUILDER *pb, const PKCS12_ENC *mac);
91 void end_check_pkcs12(PKCS12_BUILDER *pb);
93 void start_check_contentinfo(PKCS12_BUILDER *pb);
94 void start_check_contentinfo_encrypted(PKCS12_BUILDER *pb, const PKCS12_ENC *enc);
95 void end_check_contentinfo(PKCS12_BUILDER *pb);
97 void check_certbag(PKCS12_BUILDER *pb, const unsigned char *bytes, int len,
98 const PKCS12_ATTR *attrs);
99 void check_keybag(PKCS12_BUILDER *pb, const unsigned char *bytes, int len,
100 const PKCS12_ATTR *attrs, const PKCS12_ENC *enc);
101 void check_secretbag(PKCS12_BUILDER *pb, int secret_nid, const char *secret,
102 const PKCS12_ATTR *attrs);