]> git.ipfire.org Git - thirdparty/openssl.git/blob - test/helpers/pkcs12.h
remove obsolete test/drbg_cavs_data.h
[thirdparty/openssl.git] / test / helpers / pkcs12.h
1 /*
2 * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10 #include <stdio.h>
11 #include <string.h>
12 #include <stdlib.h>
13
14 #include "internal/nelem.h"
15
16 #include <openssl/pkcs12.h>
17 #include <openssl/x509.h>
18 #include <openssl/x509v3.h>
19 #include <openssl/pem.h>
20
21 #include "../testutil.h"
22
23 /* Set this to > 0 write test data to file */
24 extern int write_files;
25
26 /* -------------------------------------------------------------------------
27 * PKCS#12 Test structures
28 */
29
30 /* Holds a set of Attributes */
31 typedef struct pkcs12_attr {
32 char *oid;
33 char *value;
34 } PKCS12_ATTR;
35
36
37 /* Holds encryption parameters */
38 typedef struct pkcs12_enc {
39 int nid;
40 char *pass;
41 int iter;
42 } PKCS12_ENC;
43
44 /* Set of variables required for constructing the PKCS#12 structure */
45 typedef struct pkcs12_builder {
46 const char *filename;
47 int success;
48 BIO *p12bio;
49 STACK_OF(PKCS7) *safes;
50 int safe_idx;
51 STACK_OF(PKCS12_SAFEBAG) *bags;
52 int bag_idx;
53 } PKCS12_BUILDER;
54
55
56 /* -------------------------------------------------------------------------
57 * PKCS#12 Test function declarations
58 */
59
60 /* Allocate and initialise a PKCS#12 builder object */
61 PKCS12_BUILDER *new_pkcs12_builder(const char *filename);
62
63 /* Finalise and free the PKCS#12 builder object, returning the success/fail flag */
64 int end_pkcs12_builder(PKCS12_BUILDER *pb);
65
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);
70
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);
74
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);
81
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);
88
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);
92
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);
99