]> git.ipfire.org Git - thirdparty/openssl.git/blob - test/helpers/pkcs12.h
threads_pthread.c: change inline to ossl_inline
[thirdparty/openssl.git] / test / helpers / pkcs12.h
1 /*
2 * Copyright 2020-2021 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
24 /* -------------------------------------------------------------------------
25 * PKCS#12 Test structures
26 */
27
28 /* Holds a set of Attributes */
29 typedef struct pkcs12_attr {
30 char *oid;
31 char *value;
32 } PKCS12_ATTR;
33
34
35 /* Holds encryption parameters */
36 typedef struct pkcs12_enc {
37 int nid;
38 const char *pass;
39 int iter;
40 } PKCS12_ENC;
41
42 /* Set of variables required for constructing the PKCS#12 structure */
43 typedef struct pkcs12_builder {
44 const char *filename;
45 int success;
46 BIO *p12bio;
47 STACK_OF(PKCS7) *safes;
48 int safe_idx;
49 STACK_OF(PKCS12_SAFEBAG) *bags;
50 int bag_idx;
51 } PKCS12_BUILDER;
52
53
54 /* -------------------------------------------------------------------------
55 * PKCS#12 Test function declarations
56 */
57
58 /* Global settings */
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);
63
64 /* Allocate and initialise a PKCS#12 builder object */
65 PKCS12_BUILDER *new_pkcs12_builder(const char *filename);
66
67 /* Finalise and free the PKCS#12 builder object, returning the success/fail flag */
68 int end_pkcs12_builder(PKCS12_BUILDER *pb);
69
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);
74
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);
78
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);
85 void add_extra_attr(PKCS12_BUILDER *pb);
86
87 /* Decode/check functions */
88 void start_check_pkcs12(PKCS12_BUILDER *pb);
89 void start_check_pkcs12_with_mac(PKCS12_BUILDER *pb, const PKCS12_ENC *mac);
90 void start_check_pkcs12_file(PKCS12_BUILDER *pb);
91 void start_check_pkcs12_file_with_mac(PKCS12_BUILDER *pb, const PKCS12_ENC *mac);
92 void end_check_pkcs12(PKCS12_BUILDER *pb);
93
94 void start_check_contentinfo(PKCS12_BUILDER *pb);
95 void start_check_contentinfo_encrypted(PKCS12_BUILDER *pb, const PKCS12_ENC *enc);
96 void end_check_contentinfo(PKCS12_BUILDER *pb);
97
98 void check_certbag(PKCS12_BUILDER *pb, const unsigned char *bytes, int len,
99 const PKCS12_ATTR *attrs);
100 void check_keybag(PKCS12_BUILDER *pb, const unsigned char *bytes, int len,
101 const PKCS12_ATTR *attrs, const PKCS12_ENC *enc);
102 void check_secretbag(PKCS12_BUILDER *pb, int secret_nid, const char *secret,
103 const PKCS12_ATTR *attrs);
104