]> git.ipfire.org Git - thirdparty/openssl.git/blame - test/pkcs12_helper.h
Fix safestack issues in conf.h
[thirdparty/openssl.git] / test / pkcs12_helper.h
CommitLineData
c5ec6dcf
JS
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 */
24extern int write_files;
25
26/* -------------------------------------------------------------------------
27 * PKCS#12 Test structures
28 */
29
30/* Holds a set of Attributes */
31typedef struct pkcs12_attr {
32 char *oid;
33 char *value;
34} PKCS12_ATTR;
35
36
37/* Holds encryption parameters */
38typedef 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 */
45typedef 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 */
61PKCS12_BUILDER *new_pkcs12_builder(const char *filename);
62
63/* Finalise and free the PKCS#12 builder object, returning the success/fail flag */
64int end_pkcs12_builder(PKCS12_BUILDER *pb);
65
66/* Encode/build functions */
67void start_pkcs12(PKCS12_BUILDER *pb);
68void end_pkcs12(PKCS12_BUILDER *pb);
69void end_pkcs12_with_mac(PKCS12_BUILDER *pb, const PKCS12_ENC *mac);
70
71void start_contentinfo(PKCS12_BUILDER *pb);
72void end_contentinfo(PKCS12_BUILDER *pb);
73void end_contentinfo_encrypted(PKCS12_BUILDER *pb, const PKCS12_ENC *enc);
74
75void add_certbag(PKCS12_BUILDER *pb, const unsigned char *bytes, int len,
76 const PKCS12_ATTR *attrs);
77void add_keybag(PKCS12_BUILDER *pb, const unsigned char *bytes, int len,
78 const PKCS12_ATTR *attrs, const PKCS12_ENC *enc);
79void add_secretbag(PKCS12_BUILDER *pb, int secret_nid, const char *secret,
80 const PKCS12_ATTR *attrs);
81
82/* Decode/check functions */
83void start_check_pkcs12(PKCS12_BUILDER *pb);
84void start_check_pkcs12_with_mac(PKCS12_BUILDER *pb, const PKCS12_ENC *mac);
85void start_check_pkcs12_file(PKCS12_BUILDER *pb);
86void start_check_pkcs12_file_with_mac(PKCS12_BUILDER *pb, const PKCS12_ENC *mac);
87void end_check_pkcs12(PKCS12_BUILDER *pb);
88
89void start_check_contentinfo(PKCS12_BUILDER *pb);
90void start_check_contentinfo_encrypted(PKCS12_BUILDER *pb, const PKCS12_ENC *enc);
91void end_check_contentinfo(PKCS12_BUILDER *pb);
92
93void check_certbag(PKCS12_BUILDER *pb, const unsigned char *bytes, int len,
94 const PKCS12_ATTR *attrs);
95void check_keybag(PKCS12_BUILDER *pb, const unsigned char *bytes, int len,
96 const PKCS12_ATTR *attrs, const PKCS12_ENC *enc);
97void check_secretbag(PKCS12_BUILDER *pb, int secret_nid, const char *secret,
98 const PKCS12_ATTR *attrs);
99