]> git.ipfire.org Git - thirdparty/openssl.git/blame - include/openssl/pkcs12.h
In OpenSSL builds, declare STACK for datatypes ...
[thirdparty/openssl.git] / include / openssl / pkcs12.h
CommitLineData
0f113f3e 1/*
21dcbebc 2 * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
8d8c7266 3 *
48f4ad77 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
21dcbebc
RS
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
8d8c7266
DSH
8 */
9
ae4186b0
DMSP
10#ifndef OPENSSL_PKCS12_H
11# define OPENSSL_PKCS12_H
d86167ec
DMSP
12# pragma once
13
14# include <openssl/macros.h>
936c2b9e 15# ifndef OPENSSL_NO_DEPRECATED_3_0
d86167ec
DMSP
16# define HEADER_PKCS12_H
17# endif
8d8c7266 18
0f113f3e
MC
19# include <openssl/bio.h>
20# include <openssl/x509.h>
52df25cf 21# include <openssl/pkcs12err.h>
82271cee 22
8d8c7266
DSH
23#ifdef __cplusplus
24extern "C" {
25#endif
26
0f113f3e
MC
27# define PKCS12_KEY_ID 1
28# define PKCS12_IV_ID 2
29# define PKCS12_MAC_ID 3
8d8c7266 30
e84240d4 31/* Default iteration count */
0f113f3e
MC
32# ifndef PKCS12_DEFAULT_ITER
33# define PKCS12_DEFAULT_ITER PKCS5_DEFAULT_ITER
34# endif
e84240d4 35
0f113f3e 36# define PKCS12_MAC_KEY_LENGTH 20
8d8c7266 37
0f113f3e 38# define PKCS12_SALT_LEN 8
8d8c7266 39
1194ea8d
AP
40/* It's not clear if these are actually needed... */
41# define PKCS12_key_gen PKCS12_key_gen_utf8
42# define PKCS12_add_friendlyname PKCS12_add_friendlyname_utf8
8d8c7266
DSH
43
44/* MS key usage constants */
45
0f113f3e
MC
46# define KEY_EX 0x10
47# define KEY_SIG 0x80
8d8c7266 48
852c2ed2
RS
49DEFINE_OR_DECLARE_STACK_OF(PKCS12_SAFEBAG)
50
54c38b7f
DSH
51typedef struct PKCS12_MAC_DATA_st PKCS12_MAC_DATA;
52
53typedef struct PKCS12_st PKCS12;
54
55typedef struct PKCS12_SAFEBAG_st PKCS12_SAFEBAG;
8d8c7266 56
54c38b7f 57typedef struct pkcs12_bag_st PKCS12_BAGS;
8d8c7266 58
0f113f3e
MC
59# define PKCS12_ERROR 0
60# define PKCS12_OK 1
8d8c7266 61
ecbe0781 62/* Compatibility macros */
8d8c7266 63
00db8c60 64#ifndef OPENSSL_NO_DEPRECATED_1_1_0
116503cd 65
a40d5949
DSH
66# define M_PKCS12_bag_type PKCS12_bag_type
67# define M_PKCS12_cert_bag_type PKCS12_cert_bag_type
68# define M_PKCS12_crl_bag_type PKCS12_cert_bag_type
69
e8503762
DSH
70# define PKCS12_certbag2x509 PKCS12_SAFEBAG_get1_cert
71# define PKCS12_certbag2scrl PKCS12_SAFEBAG_get1_crl
e8503762
DSH
72# define PKCS12_bag_type PKCS12_SAFEBAG_get_nid
73# define PKCS12_cert_bag_type PKCS12_SAFEBAG_get_bag_nid
293042c9 74# define PKCS12_x5092certbag PKCS12_SAFEBAG_create_cert
425f3300
DSH
75# define PKCS12_x509crl2certbag PKCS12_SAFEBAG_create_crl
76# define PKCS12_MAKE_KEYBAG PKCS12_SAFEBAG_create0_p8inf
77# define PKCS12_MAKE_SHKEYBAG PKCS12_SAFEBAG_create_pkcs8_encrypt
e8503762 78
116503cd
DSH
79#endif
80
28da1455
MC
81DEPRECATEDIN_1_1_0(ASN1_TYPE *PKCS12_get_attr(const PKCS12_SAFEBAG *bag, int attr_nid))
82
a40d5949 83ASN1_TYPE *PKCS8_get_attr(PKCS8_PRIV_KEY_INFO *p8, int attr_nid);
28da1455 84int PKCS12_mac_present(const PKCS12 *p12);
59b4da05
DSH
85void PKCS12_get0_mac(const ASN1_OCTET_STRING **pmac,
86 const X509_ALGOR **pmacalg,
87 const ASN1_OCTET_STRING **psalt,
88 const ASN1_INTEGER **piter,
89 const PKCS12 *p12);
1e1b48d1 90
28da1455
MC
91const ASN1_TYPE *PKCS12_SAFEBAG_get0_attr(const PKCS12_SAFEBAG *bag,
92 int attr_nid);
93const ASN1_OBJECT *PKCS12_SAFEBAG_get0_type(const PKCS12_SAFEBAG *bag);
94int PKCS12_SAFEBAG_get_nid(const PKCS12_SAFEBAG *bag);
95int PKCS12_SAFEBAG_get_bag_nid(const PKCS12_SAFEBAG *bag);
1e1b48d1 96
28da1455
MC
97X509 *PKCS12_SAFEBAG_get1_cert(const PKCS12_SAFEBAG *bag);
98X509_CRL *PKCS12_SAFEBAG_get1_crl(const PKCS12_SAFEBAG *bag);
99const STACK_OF(PKCS12_SAFEBAG) *
100PKCS12_SAFEBAG_get0_safes(const PKCS12_SAFEBAG *bag);
101const PKCS8_PRIV_KEY_INFO *PKCS12_SAFEBAG_get0_p8inf(const PKCS12_SAFEBAG *bag);
102const X509_SIG *PKCS12_SAFEBAG_get0_pkcs8(const PKCS12_SAFEBAG *bag);
8d8c7266 103
293042c9
DSH
104PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_cert(X509 *x509);
105PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_crl(X509_CRL *crl);
425f3300
DSH
106PKCS12_SAFEBAG *PKCS12_SAFEBAG_create0_p8inf(PKCS8_PRIV_KEY_INFO *p8);
107PKCS12_SAFEBAG *PKCS12_SAFEBAG_create0_pkcs8(X509_SIG *p8);
108PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_pkcs8_encrypt(int pbe_nid,
109 const char *pass,
110 int passlen,
111 unsigned char *salt,
112 int saltlen, int iter,
113 PKCS8_PRIV_KEY_INFO *p8inf);
ecbe0781 114
0f113f3e
MC
115PKCS12_SAFEBAG *PKCS12_item_pack_safebag(void *obj, const ASN1_ITEM *it,
116 int nid1, int nid2);
59b4da05 117PKCS8_PRIV_KEY_INFO *PKCS8_decrypt(const X509_SIG *p8, const char *pass,
0f113f3e 118 int passlen);
28da1455 119PKCS8_PRIV_KEY_INFO *PKCS12_decrypt_skey(const PKCS12_SAFEBAG *bag,
0f113f3e
MC
120 const char *pass, int passlen);
121X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher,
122 const char *pass, int passlen, unsigned char *salt,
123 int saltlen, int iter, PKCS8_PRIV_KEY_INFO *p8);
6355d315
DSH
124X509_SIG *PKCS8_set0_pbe(const char *pass, int passlen,
125 PKCS8_PRIV_KEY_INFO *p8inf, X509_ALGOR *pbe);
f2716dad 126PKCS7 *PKCS12_pack_p7data(STACK_OF(PKCS12_SAFEBAG) *sk);
ecbe0781 127STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7data(PKCS7 *p7);
61f5b6f3 128PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen,
0f113f3e
MC
129 unsigned char *salt, int saltlen, int iter,
130 STACK_OF(PKCS12_SAFEBAG) *bags);
131STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7encdata(PKCS7 *p7, const char *pass,
132 int passlen);
ecbe0781
DSH
133
134int PKCS12_pack_authsafes(PKCS12 *p12, STACK_OF(PKCS7) *safes);
28da1455 135STACK_OF(PKCS7) *PKCS12_unpack_authsafes(const PKCS12 *p12);
ecbe0781 136
0f113f3e
MC
137int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name,
138 int namelen);
61f5b6f3 139int PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name,
0f113f3e 140 int namelen);
b799aef8
AP
141int PKCS12_add_friendlyname_utf8(PKCS12_SAFEBAG *bag, const char *name,
142 int namelen);
f2a253e0 143int PKCS12_add_CSPName_asc(PKCS12_SAFEBAG *bag, const char *name,
0f113f3e
MC
144 int namelen);
145int PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag,
146 const unsigned char *name, int namelen);
8d8c7266 147int PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage);
b2e57e09
MC
148ASN1_TYPE *PKCS12_get_attr_gen(const STACK_OF(X509_ATTRIBUTE) *attrs,
149 int attr_nid);
8d8c7266 150char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag);
28da1455
MC
151const STACK_OF(X509_ATTRIBUTE) *
152PKCS12_SAFEBAG_get0_attrs(const PKCS12_SAFEBAG *bag);
59b4da05
DSH
153unsigned char *PKCS12_pbe_crypt(const X509_ALGOR *algor,
154 const char *pass, int passlen,
155 const unsigned char *in, int inlen,
0f113f3e
MC
156 unsigned char **data, int *datalen,
157 int en_de);
59b4da05 158void *PKCS12_item_decrypt_d2i(const X509_ALGOR *algor, const ASN1_ITEM *it,
0f113f3e 159 const char *pass, int passlen,
59b4da05 160 const ASN1_OCTET_STRING *oct, int zbuf);
0f113f3e
MC
161ASN1_OCTET_STRING *PKCS12_item_i2d_encrypt(X509_ALGOR *algor,
162 const ASN1_ITEM *it,
163 const char *pass, int passlen,
164 void *obj, int zbuf);
8d8c7266 165PKCS12 *PKCS12_init(int mode);
61f5b6f3 166int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt,
0f113f3e
MC
167 int saltlen, int id, int iter, int n,
168 unsigned char *out, const EVP_MD *md_type);
169int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt,
170 int saltlen, int id, int iter, int n,
171 unsigned char *out, const EVP_MD *md_type);
9e6b2f54
AP
172int PKCS12_key_gen_utf8(const char *pass, int passlen, unsigned char *salt,
173 int saltlen, int id, int iter, int n,
174 unsigned char *out, const EVP_MD *md_type);
2bd83ca1 175int PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
0f113f3e
MC
176 ASN1_TYPE *param, const EVP_CIPHER *cipher,
177 const EVP_MD *md_type, int en_de);
69cbf468 178int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen,
0f113f3e 179 unsigned char *mac, unsigned int *maclen);
61f5b6f3
BL
180int PKCS12_verify_mac(PKCS12 *p12, const char *pass, int passlen);
181int PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen,
0f113f3e
MC
182 unsigned char *salt, int saltlen, int iter,
183 const EVP_MD *md_type);
69cbf468 184int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt,
0f113f3e
MC
185 int saltlen, const EVP_MD *md_type);
186unsigned char *OPENSSL_asc2uni(const char *asc, int asclen,
187 unsigned char **uni, int *unilen);
9e6b2f54
AP
188char *OPENSSL_uni2asc(const unsigned char *uni, int unilen);
189unsigned char *OPENSSL_utf82uni(const char *asc, int asclen,
190 unsigned char **uni, int *unilen);
191char *OPENSSL_uni2utf8(const unsigned char *uni, int unilen);
9d6b1ce6
DSH
192
193DECLARE_ASN1_FUNCTIONS(PKCS12)
194DECLARE_ASN1_FUNCTIONS(PKCS12_MAC_DATA)
195DECLARE_ASN1_FUNCTIONS(PKCS12_SAFEBAG)
196DECLARE_ASN1_FUNCTIONS(PKCS12_BAGS)
197
ecbe0781
DSH
198DECLARE_ASN1_ITEM(PKCS12_SAFEBAGS)
199DECLARE_ASN1_ITEM(PKCS12_AUTHSAFES)
200
8d8c7266 201void PKCS12_PBE_add(void);
61f5b6f3 202int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert,
0f113f3e 203 STACK_OF(X509) **ca);
02e112a8
F
204PKCS12 *PKCS12_create(const char *pass, const char *name, EVP_PKEY *pkey,
205 X509 *cert, STACK_OF(X509) *ca, int nid_key, int nid_cert,
82af00fb 206 int iter, int mac_iter, int keytype);
9a48b07e
DSH
207
208PKCS12_SAFEBAG *PKCS12_add_cert(STACK_OF(PKCS12_SAFEBAG) **pbags, X509 *cert);
0f113f3e
MC
209PKCS12_SAFEBAG *PKCS12_add_key(STACK_OF(PKCS12_SAFEBAG) **pbags,
210 EVP_PKEY *key, int key_usage, int iter,
82af00fb 211 int key_nid, const char *pass);
9a48b07e 212int PKCS12_add_safe(STACK_OF(PKCS7) **psafes, STACK_OF(PKCS12_SAFEBAG) *bags,
82af00fb 213 int safe_nid, int iter, const char *pass);
9a48b07e
DSH
214PKCS12 *PKCS12_add_safes(STACK_OF(PKCS7) *safes, int p7_nid);
215
9fdcc21f 216int i2d_PKCS12_bio(BIO *bp, const PKCS12 *p12);
739fe504 217# ifndef OPENSSL_NO_STDIO
9fdcc21f 218int i2d_PKCS12_fp(FILE *fp, const PKCS12 *p12);
739fe504 219# endif
8d8c7266 220PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12);
739fe504 221# ifndef OPENSSL_NO_STDIO
8d8c7266 222PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12);
739fe504 223# endif
049f5bbc 224int PKCS12_newpass(PKCS12 *p12, const char *oldpass, const char *newpass);
8d8c7266 225
0cd0a820 226# ifdef __cplusplus
8d8c7266 227}
0cd0a820 228# endif
8d8c7266 229#endif