2 * Copyright 2020 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>
23 /* Set this to > 0 write test data to file */
24 extern int write_files;
26 /* -------------------------------------------------------------------------
27 * PKCS#12 Test structures
30 /* Holds a set of Attributes */
31 typedef struct pkcs12_attr {
37 /* Holds encryption parameters */
38 typedef struct pkcs12_enc {
44 /* Set of variables required for constructing the PKCS#12 structure */
45 typedef struct pkcs12_builder {
49 STACK_OF(PKCS7) *safes;
51 STACK_OF(PKCS12_SAFEBAG) *bags;
56 /* -------------------------------------------------------------------------
57 * PKCS#12 Test function declarations
60 /* Allocate and initialise a PKCS#12 builder object */
61 PKCS12_BUILDER *new_pkcs12_builder(const char *filename);
63 /* Finalise and free the PKCS#12 builder object, returning the success/fail flag */
64 int end_pkcs12_builder(PKCS12_BUILDER *pb);
66 /* Encode/build functions */
67 void start_pkcs12(PKCS12_BUILDER *pb);
68 void end_pkcs12(PKCS12_BUILDER *pb);
69 void end_pkcs12_with_mac(PKCS12_BUILDER *pb, const PKCS12_ENC *mac);
71 void start_contentinfo(PKCS12_BUILDER *pb);
72 void end_contentinfo(PKCS12_BUILDER *pb);
73 void end_contentinfo_encrypted(PKCS12_BUILDER *pb, const PKCS12_ENC *enc);
75 void add_certbag(PKCS12_BUILDER *pb, const unsigned char *bytes, int len,
76 const PKCS12_ATTR *attrs);
77 void add_keybag(PKCS12_BUILDER *pb, const unsigned char *bytes, int len,
78 const PKCS12_ATTR *attrs, const PKCS12_ENC *enc);
79 void add_secretbag(PKCS12_BUILDER *pb, int secret_nid, const char *secret,
80 const PKCS12_ATTR *attrs);
82 /* Decode/check functions */
83 void start_check_pkcs12(PKCS12_BUILDER *pb);
84 void start_check_pkcs12_with_mac(PKCS12_BUILDER *pb, const PKCS12_ENC *mac);
85 void start_check_pkcs12_file(PKCS12_BUILDER *pb);
86 void start_check_pkcs12_file_with_mac(PKCS12_BUILDER *pb, const PKCS12_ENC *mac);
87 void end_check_pkcs12(PKCS12_BUILDER *pb);
89 void start_check_contentinfo(PKCS12_BUILDER *pb);
90 void start_check_contentinfo_encrypted(PKCS12_BUILDER *pb, const PKCS12_ENC *enc);
91 void end_check_contentinfo(PKCS12_BUILDER *pb);
93 void check_certbag(PKCS12_BUILDER *pb, const unsigned char *bytes, int len,
94 const PKCS12_ATTR *attrs);
95 void check_keybag(PKCS12_BUILDER *pb, const unsigned char *bytes, int len,
96 const PKCS12_ATTR *attrs, const PKCS12_ENC *enc);
97 void check_secretbag(PKCS12_BUILDER *pb, int secret_nid, const char *secret,
98 const PKCS12_ATTR *attrs);