[331] | 1 | /*
|
---|
| 2 | * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
|
---|
| 3 | *
|
---|
| 4 | * Licensed under the OpenSSL license (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 | #ifndef HEADER_PKCS12_H
|
---|
| 11 | # define HEADER_PKCS12_H
|
---|
| 12 |
|
---|
| 13 | # include <openssl/bio.h>
|
---|
| 14 | # include <openssl/x509.h>
|
---|
| 15 |
|
---|
| 16 | #ifdef __cplusplus
|
---|
| 17 | extern "C" {
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
| 20 | # define PKCS12_KEY_ID 1
|
---|
| 21 | # define PKCS12_IV_ID 2
|
---|
| 22 | # define PKCS12_MAC_ID 3
|
---|
| 23 |
|
---|
| 24 | /* Default iteration count */
|
---|
| 25 | # ifndef PKCS12_DEFAULT_ITER
|
---|
| 26 | # define PKCS12_DEFAULT_ITER PKCS5_DEFAULT_ITER
|
---|
| 27 | # endif
|
---|
| 28 |
|
---|
| 29 | # define PKCS12_MAC_KEY_LENGTH 20
|
---|
| 30 |
|
---|
| 31 | # define PKCS12_SALT_LEN 8
|
---|
| 32 |
|
---|
| 33 | /* It's not clear if these are actually needed... */
|
---|
| 34 | # define PKCS12_key_gen PKCS12_key_gen_utf8
|
---|
| 35 | # define PKCS12_add_friendlyname PKCS12_add_friendlyname_utf8
|
---|
| 36 |
|
---|
| 37 | /* MS key usage constants */
|
---|
| 38 |
|
---|
| 39 | # define KEY_EX 0x10
|
---|
| 40 | # define KEY_SIG 0x80
|
---|
| 41 |
|
---|
| 42 | typedef struct PKCS12_MAC_DATA_st PKCS12_MAC_DATA;
|
---|
| 43 |
|
---|
| 44 | typedef struct PKCS12_st PKCS12;
|
---|
| 45 |
|
---|
| 46 | typedef struct PKCS12_SAFEBAG_st PKCS12_SAFEBAG;
|
---|
| 47 |
|
---|
| 48 | DEFINE_STACK_OF(PKCS12_SAFEBAG)
|
---|
| 49 |
|
---|
| 50 | typedef struct pkcs12_bag_st PKCS12_BAGS;
|
---|
| 51 |
|
---|
| 52 | # define PKCS12_ERROR 0
|
---|
| 53 | # define PKCS12_OK 1
|
---|
| 54 |
|
---|
| 55 | /* Compatibility macros */
|
---|
| 56 |
|
---|
| 57 | #if OPENSSL_API_COMPAT < 0x10100000L
|
---|
| 58 |
|
---|
| 59 | # define M_PKCS12_bag_type PKCS12_bag_type
|
---|
| 60 | # define M_PKCS12_cert_bag_type PKCS12_cert_bag_type
|
---|
| 61 | # define M_PKCS12_crl_bag_type PKCS12_cert_bag_type
|
---|
| 62 |
|
---|
| 63 | # define PKCS12_certbag2x509 PKCS12_SAFEBAG_get1_cert
|
---|
| 64 | # define PKCS12_certbag2scrl PKCS12_SAFEBAG_get1_crl
|
---|
| 65 | # define PKCS12_bag_type PKCS12_SAFEBAG_get_nid
|
---|
| 66 | # define PKCS12_cert_bag_type PKCS12_SAFEBAG_get_bag_nid
|
---|
| 67 | # define PKCS12_x5092certbag PKCS12_SAFEBAG_create_cert
|
---|
| 68 | # define PKCS12_x509crl2certbag PKCS12_SAFEBAG_create_crl
|
---|
| 69 | # define PKCS12_MAKE_KEYBAG PKCS12_SAFEBAG_create0_p8inf
|
---|
| 70 | # define PKCS12_MAKE_SHKEYBAG PKCS12_SAFEBAG_create_pkcs8_encrypt
|
---|
| 71 |
|
---|
| 72 | #endif
|
---|
| 73 |
|
---|
| 74 | DEPRECATEDIN_1_1_0(ASN1_TYPE *PKCS12_get_attr(const PKCS12_SAFEBAG *bag, int attr_nid))
|
---|
| 75 |
|
---|
| 76 | ASN1_TYPE *PKCS8_get_attr(PKCS8_PRIV_KEY_INFO *p8, int attr_nid);
|
---|
| 77 | int PKCS12_mac_present(const PKCS12 *p12);
|
---|
| 78 | void PKCS12_get0_mac(const ASN1_OCTET_STRING **pmac,
|
---|
| 79 | const X509_ALGOR **pmacalg,
|
---|
| 80 | const ASN1_OCTET_STRING **psalt,
|
---|
| 81 | const ASN1_INTEGER **piter,
|
---|
| 82 | const PKCS12 *p12);
|
---|
| 83 |
|
---|
| 84 | const ASN1_TYPE *PKCS12_SAFEBAG_get0_attr(const PKCS12_SAFEBAG *bag,
|
---|
| 85 | int attr_nid);
|
---|
| 86 | const ASN1_OBJECT *PKCS12_SAFEBAG_get0_type(const PKCS12_SAFEBAG *bag);
|
---|
| 87 | int PKCS12_SAFEBAG_get_nid(const PKCS12_SAFEBAG *bag);
|
---|
| 88 | int PKCS12_SAFEBAG_get_bag_nid(const PKCS12_SAFEBAG *bag);
|
---|
| 89 |
|
---|
| 90 | X509 *PKCS12_SAFEBAG_get1_cert(const PKCS12_SAFEBAG *bag);
|
---|
| 91 | X509_CRL *PKCS12_SAFEBAG_get1_crl(const PKCS12_SAFEBAG *bag);
|
---|
| 92 | const STACK_OF(PKCS12_SAFEBAG) *
|
---|
| 93 | PKCS12_SAFEBAG_get0_safes(const PKCS12_SAFEBAG *bag);
|
---|
| 94 | const PKCS8_PRIV_KEY_INFO *PKCS12_SAFEBAG_get0_p8inf(const PKCS12_SAFEBAG *bag);
|
---|
| 95 | const X509_SIG *PKCS12_SAFEBAG_get0_pkcs8(const PKCS12_SAFEBAG *bag);
|
---|
| 96 |
|
---|
| 97 | PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_cert(X509 *x509);
|
---|
| 98 | PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_crl(X509_CRL *crl);
|
---|
| 99 | PKCS12_SAFEBAG *PKCS12_SAFEBAG_create0_p8inf(PKCS8_PRIV_KEY_INFO *p8);
|
---|
| 100 | PKCS12_SAFEBAG *PKCS12_SAFEBAG_create0_pkcs8(X509_SIG *p8);
|
---|
| 101 | PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_pkcs8_encrypt(int pbe_nid,
|
---|
| 102 | const char *pass,
|
---|
| 103 | int passlen,
|
---|
| 104 | unsigned char *salt,
|
---|
| 105 | int saltlen, int iter,
|
---|
| 106 | PKCS8_PRIV_KEY_INFO *p8inf);
|
---|
| 107 |
|
---|
| 108 | PKCS12_SAFEBAG *PKCS12_item_pack_safebag(void *obj, const ASN1_ITEM *it,
|
---|
| 109 | int nid1, int nid2);
|
---|
| 110 | PKCS8_PRIV_KEY_INFO *PKCS8_decrypt(const X509_SIG *p8, const char *pass,
|
---|
| 111 | int passlen);
|
---|
| 112 | PKCS8_PRIV_KEY_INFO *PKCS12_decrypt_skey(const PKCS12_SAFEBAG *bag,
|
---|
| 113 | const char *pass, int passlen);
|
---|
| 114 | X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher,
|
---|
| 115 | const char *pass, int passlen, unsigned char *salt,
|
---|
| 116 | int saltlen, int iter, PKCS8_PRIV_KEY_INFO *p8);
|
---|
| 117 | X509_SIG *PKCS8_set0_pbe(const char *pass, int passlen,
|
---|
| 118 | PKCS8_PRIV_KEY_INFO *p8inf, X509_ALGOR *pbe);
|
---|
| 119 | PKCS7 *PKCS12_pack_p7data(STACK_OF(PKCS12_SAFEBAG) *sk);
|
---|
| 120 | STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7data(PKCS7 *p7);
|
---|
| 121 | PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen,
|
---|
| 122 | unsigned char *salt, int saltlen, int iter,
|
---|
| 123 | STACK_OF(PKCS12_SAFEBAG) *bags);
|
---|
| 124 | STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7encdata(PKCS7 *p7, const char *pass,
|
---|
| 125 | int passlen);
|
---|
| 126 |
|
---|
| 127 | int PKCS12_pack_authsafes(PKCS12 *p12, STACK_OF(PKCS7) *safes);
|
---|
| 128 | STACK_OF(PKCS7) *PKCS12_unpack_authsafes(const PKCS12 *p12);
|
---|
| 129 |
|
---|
| 130 | int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name,
|
---|
| 131 | int namelen);
|
---|
| 132 | int PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name,
|
---|
| 133 | int namelen);
|
---|
| 134 | int PKCS12_add_friendlyname_utf8(PKCS12_SAFEBAG *bag, const char *name,
|
---|
| 135 | int namelen);
|
---|
| 136 | int PKCS12_add_CSPName_asc(PKCS12_SAFEBAG *bag, const char *name,
|
---|
| 137 | int namelen);
|
---|
| 138 | int PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag,
|
---|
| 139 | const unsigned char *name, int namelen);
|
---|
| 140 | int PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage);
|
---|
| 141 | ASN1_TYPE *PKCS12_get_attr_gen(const STACK_OF(X509_ATTRIBUTE) *attrs,
|
---|
| 142 | int attr_nid);
|
---|
| 143 | char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag);
|
---|
| 144 | const STACK_OF(X509_ATTRIBUTE) *
|
---|
| 145 | PKCS12_SAFEBAG_get0_attrs(const PKCS12_SAFEBAG *bag);
|
---|
| 146 | unsigned char *PKCS12_pbe_crypt(const X509_ALGOR *algor,
|
---|
| 147 | const char *pass, int passlen,
|
---|
| 148 | const unsigned char *in, int inlen,
|
---|
| 149 | unsigned char **data, int *datalen,
|
---|
| 150 | int en_de);
|
---|
| 151 | void *PKCS12_item_decrypt_d2i(const X509_ALGOR *algor, const ASN1_ITEM *it,
|
---|
| 152 | const char *pass, int passlen,
|
---|
| 153 | const ASN1_OCTET_STRING *oct, int zbuf);
|
---|
| 154 | ASN1_OCTET_STRING *PKCS12_item_i2d_encrypt(X509_ALGOR *algor,
|
---|
| 155 | const ASN1_ITEM *it,
|
---|
| 156 | const char *pass, int passlen,
|
---|
| 157 | void *obj, int zbuf);
|
---|
| 158 | PKCS12 *PKCS12_init(int mode);
|
---|
| 159 | int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt,
|
---|
| 160 | int saltlen, int id, int iter, int n,
|
---|
| 161 | unsigned char *out, const EVP_MD *md_type);
|
---|
| 162 | int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt,
|
---|
| 163 | int saltlen, int id, int iter, int n,
|
---|
| 164 | unsigned char *out, const EVP_MD *md_type);
|
---|
| 165 | int PKCS12_key_gen_utf8(const char *pass, int passlen, unsigned char *salt,
|
---|
| 166 | int saltlen, int id, int iter, int n,
|
---|
| 167 | unsigned char *out, const EVP_MD *md_type);
|
---|
| 168 | int PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
|
---|
| 169 | ASN1_TYPE *param, const EVP_CIPHER *cipher,
|
---|
| 170 | const EVP_MD *md_type, int en_de);
|
---|
| 171 | int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen,
|
---|
| 172 | unsigned char *mac, unsigned int *maclen);
|
---|
| 173 | int PKCS12_verify_mac(PKCS12 *p12, const char *pass, int passlen);
|
---|
| 174 | int PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen,
|
---|
| 175 | unsigned char *salt, int saltlen, int iter,
|
---|
| 176 | const EVP_MD *md_type);
|
---|
| 177 | int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt,
|
---|
| 178 | int saltlen, const EVP_MD *md_type);
|
---|
| 179 | unsigned char *OPENSSL_asc2uni(const char *asc, int asclen,
|
---|
| 180 | unsigned char **uni, int *unilen);
|
---|
| 181 | char *OPENSSL_uni2asc(const unsigned char *uni, int unilen);
|
---|
| 182 | unsigned char *OPENSSL_utf82uni(const char *asc, int asclen,
|
---|
| 183 | unsigned char **uni, int *unilen);
|
---|
| 184 | char *OPENSSL_uni2utf8(const unsigned char *uni, int unilen);
|
---|
| 185 |
|
---|
| 186 | DECLARE_ASN1_FUNCTIONS(PKCS12)
|
---|
| 187 | DECLARE_ASN1_FUNCTIONS(PKCS12_MAC_DATA)
|
---|
| 188 | DECLARE_ASN1_FUNCTIONS(PKCS12_SAFEBAG)
|
---|
| 189 | DECLARE_ASN1_FUNCTIONS(PKCS12_BAGS)
|
---|
| 190 |
|
---|
| 191 | DECLARE_ASN1_ITEM(PKCS12_SAFEBAGS)
|
---|
| 192 | DECLARE_ASN1_ITEM(PKCS12_AUTHSAFES)
|
---|
| 193 |
|
---|
| 194 | void PKCS12_PBE_add(void);
|
---|
| 195 | int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert,
|
---|
| 196 | STACK_OF(X509) **ca);
|
---|
| 197 | PKCS12 *PKCS12_create(const char *pass, const char *name, EVP_PKEY *pkey,
|
---|
| 198 | X509 *cert, STACK_OF(X509) *ca, int nid_key, int nid_cert,
|
---|
| 199 | int iter, int mac_iter, int keytype);
|
---|
| 200 |
|
---|
| 201 | PKCS12_SAFEBAG *PKCS12_add_cert(STACK_OF(PKCS12_SAFEBAG) **pbags, X509 *cert);
|
---|
| 202 | PKCS12_SAFEBAG *PKCS12_add_key(STACK_OF(PKCS12_SAFEBAG) **pbags,
|
---|
| 203 | EVP_PKEY *key, int key_usage, int iter,
|
---|
| 204 | int key_nid, const char *pass);
|
---|
| 205 | int PKCS12_add_safe(STACK_OF(PKCS7) **psafes, STACK_OF(PKCS12_SAFEBAG) *bags,
|
---|
| 206 | int safe_nid, int iter, const char *pass);
|
---|
| 207 | PKCS12 *PKCS12_add_safes(STACK_OF(PKCS7) *safes, int p7_nid);
|
---|
| 208 |
|
---|
| 209 | int i2d_PKCS12_bio(BIO *bp, PKCS12 *p12);
|
---|
| 210 | # ifndef OPENSSL_NO_STDIO
|
---|
| 211 | int i2d_PKCS12_fp(FILE *fp, PKCS12 *p12);
|
---|
| 212 | # endif
|
---|
| 213 | PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12);
|
---|
| 214 | # ifndef OPENSSL_NO_STDIO
|
---|
| 215 | PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12);
|
---|
| 216 | # endif
|
---|
| 217 | int PKCS12_newpass(PKCS12 *p12, const char *oldpass, const char *newpass);
|
---|
| 218 |
|
---|
| 219 | /* BEGIN ERROR CODES */
|
---|
| 220 | /*
|
---|
| 221 | * The following lines are auto generated by the script mkerr.pl. Any changes
|
---|
| 222 | * made after this point may be overwritten when the script is next run.
|
---|
| 223 | */
|
---|
| 224 |
|
---|
| 225 | int ERR_load_PKCS12_strings(void);
|
---|
| 226 |
|
---|
| 227 | /* Error codes for the PKCS12 functions. */
|
---|
| 228 |
|
---|
| 229 | /* Function codes. */
|
---|
| 230 | # define PKCS12_F_PKCS12_CREATE 105
|
---|
| 231 | # define PKCS12_F_PKCS12_GEN_MAC 107
|
---|
| 232 | # define PKCS12_F_PKCS12_INIT 109
|
---|
| 233 | # define PKCS12_F_PKCS12_ITEM_DECRYPT_D2I 106
|
---|
| 234 | # define PKCS12_F_PKCS12_ITEM_I2D_ENCRYPT 108
|
---|
| 235 | # define PKCS12_F_PKCS12_ITEM_PACK_SAFEBAG 117
|
---|
| 236 | # define PKCS12_F_PKCS12_KEY_GEN_ASC 110
|
---|
| 237 | # define PKCS12_F_PKCS12_KEY_GEN_UNI 111
|
---|
| 238 | # define PKCS12_F_PKCS12_KEY_GEN_UTF8 116
|
---|
| 239 | # define PKCS12_F_PKCS12_NEWPASS 128
|
---|
| 240 | # define PKCS12_F_PKCS12_PACK_P7DATA 114
|
---|
| 241 | # define PKCS12_F_PKCS12_PACK_P7ENCDATA 115
|
---|
| 242 | # define PKCS12_F_PKCS12_PARSE 118
|
---|
| 243 | # define PKCS12_F_PKCS12_PBE_CRYPT 119
|
---|
| 244 | # define PKCS12_F_PKCS12_PBE_KEYIVGEN 120
|
---|
| 245 | # define PKCS12_F_PKCS12_SAFEBAG_CREATE0_P8INF 112
|
---|
| 246 | # define PKCS12_F_PKCS12_SAFEBAG_CREATE0_PKCS8 113
|
---|
| 247 | # define PKCS12_F_PKCS12_SAFEBAG_CREATE_PKCS8_ENCRYPT 133
|
---|
| 248 | # define PKCS12_F_PKCS12_SETUP_MAC 122
|
---|
| 249 | # define PKCS12_F_PKCS12_SET_MAC 123
|
---|
| 250 | # define PKCS12_F_PKCS12_UNPACK_AUTHSAFES 130
|
---|
| 251 | # define PKCS12_F_PKCS12_UNPACK_P7DATA 131
|
---|
| 252 | # define PKCS12_F_PKCS12_VERIFY_MAC 126
|
---|
| 253 | # define PKCS12_F_PKCS8_ENCRYPT 125
|
---|
| 254 | # define PKCS12_F_PKCS8_SET0_PBE 132
|
---|
| 255 |
|
---|
| 256 | /* Reason codes. */
|
---|
| 257 | # define PKCS12_R_CANT_PACK_STRUCTURE 100
|
---|
| 258 | # define PKCS12_R_CONTENT_TYPE_NOT_DATA 121
|
---|
| 259 | # define PKCS12_R_DECODE_ERROR 101
|
---|
| 260 | # define PKCS12_R_ENCODE_ERROR 102
|
---|
| 261 | # define PKCS12_R_ENCRYPT_ERROR 103
|
---|
| 262 | # define PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE 120
|
---|
| 263 | # define PKCS12_R_INVALID_NULL_ARGUMENT 104
|
---|
| 264 | # define PKCS12_R_INVALID_NULL_PKCS12_POINTER 105
|
---|
| 265 | # define PKCS12_R_IV_GEN_ERROR 106
|
---|
| 266 | # define PKCS12_R_KEY_GEN_ERROR 107
|
---|
| 267 | # define PKCS12_R_MAC_ABSENT 108
|
---|
| 268 | # define PKCS12_R_MAC_GENERATION_ERROR 109
|
---|
| 269 | # define PKCS12_R_MAC_SETUP_ERROR 110
|
---|
| 270 | # define PKCS12_R_MAC_STRING_SET_ERROR 111
|
---|
| 271 | # define PKCS12_R_MAC_VERIFY_FAILURE 113
|
---|
| 272 | # define PKCS12_R_PARSE_ERROR 114
|
---|
| 273 | # define PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR 115
|
---|
| 274 | # define PKCS12_R_PKCS12_CIPHERFINAL_ERROR 116
|
---|
| 275 | # define PKCS12_R_PKCS12_PBE_CRYPT_ERROR 117
|
---|
| 276 | # define PKCS12_R_UNKNOWN_DIGEST_ALGORITHM 118
|
---|
| 277 | # define PKCS12_R_UNSUPPORTED_PKCS12_MODE 119
|
---|
| 278 |
|
---|
| 279 | # ifdef __cplusplus
|
---|
| 280 | }
|
---|
| 281 | # endif
|
---|
| 282 | #endif
|
---|