diff options
| author | cvs2svn <admin@example.com> | 2015-08-02 21:54:22 +0000 |
|---|---|---|
| committer | cvs2svn <admin@example.com> | 2015-08-02 21:54:22 +0000 |
| commit | 92262c9818409ff436c41f1e51c2cea5b227f152 (patch) | |
| tree | 5609c82060f75c53af0a7641d9b33a88574876cd /src/lib/libcrypto/pkcs12 | |
| parent | ed40f444ba01bcae1d8540f9c26d79537ab5baf2 (diff) | |
| download | openbsd-OPENBSD_5_8_BASE.tar.gz openbsd-OPENBSD_5_8_BASE.tar.bz2 openbsd-OPENBSD_5_8_BASE.zip | |
This commit was manufactured by cvs2git to create tag 'OPENBSD_5_8_BASE'.OPENBSD_5_8_BASE
Diffstat (limited to 'src/lib/libcrypto/pkcs12')
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_add.c | 266 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_asn.c | 476 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_attr.c | 155 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_crpt.c | 117 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_crt.c | 350 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_decr.c | 189 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_init.c | 97 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_key.c | 199 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_kiss.c | 299 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_mutl.c | 210 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_npas.c | 244 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_p8d.c | 68 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_p8e.c | 100 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_utl.c | 168 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/pk12err.c | 144 | ||||
| -rw-r--r-- | src/lib/libcrypto/pkcs12/pkcs12.h | 331 |
16 files changed, 0 insertions, 3413 deletions
diff --git a/src/lib/libcrypto/pkcs12/p12_add.c b/src/lib/libcrypto/pkcs12/p12_add.c deleted file mode 100644 index b141851514..0000000000 --- a/src/lib/libcrypto/pkcs12/p12_add.c +++ /dev/null | |||
| @@ -1,266 +0,0 @@ | |||
| 1 | /* $OpenBSD: p12_add.c,v 1.12 2015/02/14 12:43:07 miod Exp $ */ | ||
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | |||
| 61 | #include <openssl/err.h> | ||
| 62 | #include <openssl/pkcs12.h> | ||
| 63 | |||
| 64 | /* Pack an object into an OCTET STRING and turn into a safebag */ | ||
| 65 | |||
| 66 | PKCS12_SAFEBAG * | ||
| 67 | PKCS12_item_pack_safebag(void *obj, const ASN1_ITEM *it, int nid1, int nid2) | ||
| 68 | { | ||
| 69 | PKCS12_BAGS *bag; | ||
| 70 | PKCS12_SAFEBAG *safebag; | ||
| 71 | |||
| 72 | if (!(bag = PKCS12_BAGS_new())) { | ||
| 73 | PKCS12err(PKCS12_F_PKCS12_ITEM_PACK_SAFEBAG, | ||
| 74 | ERR_R_MALLOC_FAILURE); | ||
| 75 | return NULL; | ||
| 76 | } | ||
| 77 | bag->type = OBJ_nid2obj(nid1); | ||
| 78 | if (!ASN1_item_pack(obj, it, &bag->value.octet)) { | ||
| 79 | PKCS12err(PKCS12_F_PKCS12_ITEM_PACK_SAFEBAG, | ||
| 80 | ERR_R_MALLOC_FAILURE); | ||
| 81 | PKCS12_BAGS_free(bag); | ||
| 82 | return NULL; | ||
| 83 | } | ||
| 84 | if (!(safebag = PKCS12_SAFEBAG_new())) { | ||
| 85 | PKCS12err(PKCS12_F_PKCS12_ITEM_PACK_SAFEBAG, | ||
| 86 | ERR_R_MALLOC_FAILURE); | ||
| 87 | PKCS12_BAGS_free(bag); | ||
| 88 | return NULL; | ||
| 89 | } | ||
| 90 | safebag->value.bag = bag; | ||
| 91 | safebag->type = OBJ_nid2obj(nid2); | ||
| 92 | return safebag; | ||
| 93 | } | ||
| 94 | |||
| 95 | /* Turn PKCS8 object into a keybag */ | ||
| 96 | |||
| 97 | PKCS12_SAFEBAG * | ||
| 98 | PKCS12_MAKE_KEYBAG(PKCS8_PRIV_KEY_INFO *p8) | ||
| 99 | { | ||
| 100 | PKCS12_SAFEBAG *bag; | ||
| 101 | |||
| 102 | if (!(bag = PKCS12_SAFEBAG_new())) { | ||
| 103 | PKCS12err(PKCS12_F_PKCS12_MAKE_KEYBAG, ERR_R_MALLOC_FAILURE); | ||
| 104 | return NULL; | ||
| 105 | } | ||
| 106 | bag->type = OBJ_nid2obj(NID_keyBag); | ||
| 107 | bag->value.keybag = p8; | ||
| 108 | return bag; | ||
| 109 | } | ||
| 110 | |||
| 111 | /* Turn PKCS8 object into a shrouded keybag */ | ||
| 112 | |||
| 113 | PKCS12_SAFEBAG * | ||
| 114 | PKCS12_MAKE_SHKEYBAG(int pbe_nid, const char *pass, int passlen, | ||
| 115 | unsigned char *salt, int saltlen, int iter, PKCS8_PRIV_KEY_INFO *p8) | ||
| 116 | { | ||
| 117 | PKCS12_SAFEBAG *bag; | ||
| 118 | const EVP_CIPHER *pbe_ciph; | ||
| 119 | |||
| 120 | /* Set up the safe bag */ | ||
| 121 | if (!(bag = PKCS12_SAFEBAG_new())) { | ||
| 122 | PKCS12err(PKCS12_F_PKCS12_MAKE_SHKEYBAG, ERR_R_MALLOC_FAILURE); | ||
| 123 | return NULL; | ||
| 124 | } | ||
| 125 | |||
| 126 | bag->type = OBJ_nid2obj(NID_pkcs8ShroudedKeyBag); | ||
| 127 | |||
| 128 | pbe_ciph = EVP_get_cipherbynid(pbe_nid); | ||
| 129 | |||
| 130 | if (pbe_ciph) | ||
| 131 | pbe_nid = -1; | ||
| 132 | |||
| 133 | if (!(bag->value.shkeybag = PKCS8_encrypt(pbe_nid, pbe_ciph, pass, | ||
| 134 | passlen, salt, saltlen, iter, p8))) { | ||
| 135 | PKCS12err(PKCS12_F_PKCS12_MAKE_SHKEYBAG, ERR_R_MALLOC_FAILURE); | ||
| 136 | PKCS12_SAFEBAG_free(bag); | ||
| 137 | return NULL; | ||
| 138 | } | ||
| 139 | |||
| 140 | return bag; | ||
| 141 | } | ||
| 142 | |||
| 143 | /* Turn a stack of SAFEBAGS into a PKCS#7 data Contentinfo */ | ||
| 144 | PKCS7 * | ||
| 145 | PKCS12_pack_p7data(STACK_OF(PKCS12_SAFEBAG) *sk) | ||
| 146 | { | ||
| 147 | PKCS7 *p7; | ||
| 148 | |||
| 149 | if (!(p7 = PKCS7_new())) { | ||
| 150 | PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, ERR_R_MALLOC_FAILURE); | ||
| 151 | return NULL; | ||
| 152 | } | ||
| 153 | p7->type = OBJ_nid2obj(NID_pkcs7_data); | ||
| 154 | if (!(p7->d.data = M_ASN1_OCTET_STRING_new())) { | ||
| 155 | PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, ERR_R_MALLOC_FAILURE); | ||
| 156 | goto err; | ||
| 157 | } | ||
| 158 | |||
| 159 | if (!ASN1_item_pack(sk, ASN1_ITEM_rptr(PKCS12_SAFEBAGS), &p7->d.data)) { | ||
| 160 | PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, | ||
| 161 | PKCS12_R_CANT_PACK_STRUCTURE); | ||
| 162 | goto err; | ||
| 163 | } | ||
| 164 | return p7; | ||
| 165 | |||
| 166 | err: | ||
| 167 | PKCS7_free(p7); | ||
| 168 | return NULL; | ||
| 169 | } | ||
| 170 | |||
| 171 | /* Unpack SAFEBAGS from PKCS#7 data ContentInfo */ | ||
| 172 | STACK_OF(PKCS12_SAFEBAG) * | ||
| 173 | PKCS12_unpack_p7data(PKCS7 *p7) | ||
| 174 | { | ||
| 175 | if (!PKCS7_type_is_data(p7)) { | ||
| 176 | PKCS12err(PKCS12_F_PKCS12_UNPACK_P7DATA, | ||
| 177 | PKCS12_R_CONTENT_TYPE_NOT_DATA); | ||
| 178 | return NULL; | ||
| 179 | } | ||
| 180 | return ASN1_item_unpack(p7->d.data, ASN1_ITEM_rptr(PKCS12_SAFEBAGS)); | ||
| 181 | } | ||
| 182 | |||
| 183 | /* Turn a stack of SAFEBAGS into a PKCS#7 encrypted data ContentInfo */ | ||
| 184 | |||
| 185 | PKCS7 * | ||
| 186 | PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen, | ||
| 187 | unsigned char *salt, int saltlen, int iter, STACK_OF(PKCS12_SAFEBAG) *bags) | ||
| 188 | { | ||
| 189 | PKCS7 *p7; | ||
| 190 | X509_ALGOR *pbe; | ||
| 191 | const EVP_CIPHER *pbe_ciph; | ||
| 192 | |||
| 193 | if (!(p7 = PKCS7_new())) { | ||
| 194 | PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE); | ||
| 195 | return NULL; | ||
| 196 | } | ||
| 197 | if (!PKCS7_set_type(p7, NID_pkcs7_encrypted)) { | ||
| 198 | PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, | ||
| 199 | PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE); | ||
| 200 | goto err; | ||
| 201 | } | ||
| 202 | |||
| 203 | pbe_ciph = EVP_get_cipherbynid(pbe_nid); | ||
| 204 | |||
| 205 | if (pbe_ciph) | ||
| 206 | pbe = PKCS5_pbe2_set(pbe_ciph, iter, salt, saltlen); | ||
| 207 | else | ||
| 208 | pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen); | ||
| 209 | |||
| 210 | if (!pbe) { | ||
| 211 | PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE); | ||
| 212 | goto err; | ||
| 213 | } | ||
| 214 | X509_ALGOR_free(p7->d.encrypted->enc_data->algorithm); | ||
| 215 | p7->d.encrypted->enc_data->algorithm = pbe; | ||
| 216 | M_ASN1_OCTET_STRING_free(p7->d.encrypted->enc_data->enc_data); | ||
| 217 | if (!(p7->d.encrypted->enc_data->enc_data = PKCS12_item_i2d_encrypt( | ||
| 218 | pbe, ASN1_ITEM_rptr(PKCS12_SAFEBAGS), pass, passlen, bags, 1))) { | ||
| 219 | PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, | ||
| 220 | PKCS12_R_ENCRYPT_ERROR); | ||
| 221 | goto err; | ||
| 222 | } | ||
| 223 | |||
| 224 | return p7; | ||
| 225 | |||
| 226 | err: | ||
| 227 | PKCS7_free(p7); | ||
| 228 | return NULL; | ||
| 229 | } | ||
| 230 | |||
| 231 | STACK_OF(PKCS12_SAFEBAG) * | ||
| 232 | PKCS12_unpack_p7encdata(PKCS7 *p7, const char *pass, int passlen) | ||
| 233 | { | ||
| 234 | if (!PKCS7_type_is_encrypted(p7)) | ||
| 235 | return NULL; | ||
| 236 | return PKCS12_item_decrypt_d2i(p7->d.encrypted->enc_data->algorithm, | ||
| 237 | ASN1_ITEM_rptr(PKCS12_SAFEBAGS), pass, passlen, | ||
| 238 | p7->d.encrypted->enc_data->enc_data, 1); | ||
| 239 | } | ||
| 240 | |||
| 241 | PKCS8_PRIV_KEY_INFO * | ||
| 242 | PKCS12_decrypt_skey(PKCS12_SAFEBAG *bag, const char *pass, int passlen) | ||
| 243 | { | ||
| 244 | return PKCS8_decrypt(bag->value.shkeybag, pass, passlen); | ||
| 245 | } | ||
| 246 | |||
| 247 | int | ||
| 248 | PKCS12_pack_authsafes(PKCS12 *p12, STACK_OF(PKCS7) *safes) | ||
| 249 | { | ||
| 250 | if (ASN1_item_pack(safes, ASN1_ITEM_rptr(PKCS12_AUTHSAFES), | ||
| 251 | &p12->authsafes->d.data)) | ||
| 252 | return 1; | ||
| 253 | return 0; | ||
| 254 | } | ||
| 255 | |||
| 256 | STACK_OF(PKCS7) * | ||
| 257 | PKCS12_unpack_authsafes(PKCS12 *p12) | ||
| 258 | { | ||
| 259 | if (!PKCS7_type_is_data(p12->authsafes)) { | ||
| 260 | PKCS12err(PKCS12_F_PKCS12_UNPACK_AUTHSAFES, | ||
| 261 | PKCS12_R_CONTENT_TYPE_NOT_DATA); | ||
| 262 | return NULL; | ||
| 263 | } | ||
| 264 | return ASN1_item_unpack(p12->authsafes->d.data, | ||
| 265 | ASN1_ITEM_rptr(PKCS12_AUTHSAFES)); | ||
| 266 | } | ||
diff --git a/src/lib/libcrypto/pkcs12/p12_asn.c b/src/lib/libcrypto/pkcs12/p12_asn.c deleted file mode 100644 index 3baf8f43d5..0000000000 --- a/src/lib/libcrypto/pkcs12/p12_asn.c +++ /dev/null | |||
| @@ -1,476 +0,0 @@ | |||
| 1 | /* $OpenBSD: p12_asn.c,v 1.9 2015/07/25 17:08:40 jsing Exp $ */ | ||
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | |||
| 61 | #include <openssl/asn1t.h> | ||
| 62 | #include <openssl/pkcs12.h> | ||
| 63 | |||
| 64 | /* PKCS#12 ASN1 module */ | ||
| 65 | |||
| 66 | static const ASN1_TEMPLATE PKCS12_seq_tt[] = { | ||
| 67 | { | ||
| 68 | .flags = 0, | ||
| 69 | .tag = 0, | ||
| 70 | .offset = offsetof(PKCS12, version), | ||
| 71 | .field_name = "version", | ||
| 72 | .item = &ASN1_INTEGER_it, | ||
| 73 | }, | ||
| 74 | { | ||
| 75 | .flags = 0, | ||
| 76 | .tag = 0, | ||
| 77 | .offset = offsetof(PKCS12, authsafes), | ||
| 78 | .field_name = "authsafes", | ||
| 79 | .item = &PKCS7_it, | ||
| 80 | }, | ||
| 81 | { | ||
| 82 | .flags = ASN1_TFLG_OPTIONAL, | ||
| 83 | .tag = 0, | ||
| 84 | .offset = offsetof(PKCS12, mac), | ||
| 85 | .field_name = "mac", | ||
| 86 | .item = &PKCS12_MAC_DATA_it, | ||
| 87 | }, | ||
| 88 | }; | ||
| 89 | |||
| 90 | const ASN1_ITEM PKCS12_it = { | ||
| 91 | .itype = ASN1_ITYPE_SEQUENCE, | ||
| 92 | .utype = V_ASN1_SEQUENCE, | ||
| 93 | .templates = PKCS12_seq_tt, | ||
| 94 | .tcount = sizeof(PKCS12_seq_tt) / sizeof(ASN1_TEMPLATE), | ||
| 95 | .funcs = NULL, | ||
| 96 | .size = sizeof(PKCS12), | ||
| 97 | .sname = "PKCS12", | ||
| 98 | }; | ||
| 99 | |||
| 100 | |||
| 101 | PKCS12 * | ||
| 102 | d2i_PKCS12(PKCS12 **a, const unsigned char **in, long len) | ||
| 103 | { | ||
| 104 | return (PKCS12 *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, | ||
| 105 | &PKCS12_it); | ||
| 106 | } | ||
| 107 | |||
| 108 | int | ||
| 109 | i2d_PKCS12(PKCS12 *a, unsigned char **out) | ||
| 110 | { | ||
| 111 | return ASN1_item_i2d((ASN1_VALUE *)a, out, &PKCS12_it); | ||
| 112 | } | ||
| 113 | |||
| 114 | PKCS12 * | ||
| 115 | PKCS12_new(void) | ||
| 116 | { | ||
| 117 | return (PKCS12 *)ASN1_item_new(&PKCS12_it); | ||
| 118 | } | ||
| 119 | |||
| 120 | void | ||
| 121 | PKCS12_free(PKCS12 *a) | ||
| 122 | { | ||
| 123 | ASN1_item_free((ASN1_VALUE *)a, &PKCS12_it); | ||
| 124 | } | ||
| 125 | |||
| 126 | static const ASN1_TEMPLATE PKCS12_MAC_DATA_seq_tt[] = { | ||
| 127 | { | ||
| 128 | .flags = 0, | ||
| 129 | .tag = 0, | ||
| 130 | .offset = offsetof(PKCS12_MAC_DATA, dinfo), | ||
| 131 | .field_name = "dinfo", | ||
| 132 | .item = &X509_SIG_it, | ||
| 133 | }, | ||
| 134 | { | ||
| 135 | .flags = 0, | ||
| 136 | .tag = 0, | ||
| 137 | .offset = offsetof(PKCS12_MAC_DATA, salt), | ||
| 138 | .field_name = "salt", | ||
| 139 | .item = &ASN1_OCTET_STRING_it, | ||
| 140 | }, | ||
| 141 | { | ||
| 142 | .flags = ASN1_TFLG_OPTIONAL, | ||
| 143 | .tag = 0, | ||
| 144 | .offset = offsetof(PKCS12_MAC_DATA, iter), | ||
| 145 | .field_name = "iter", | ||
| 146 | .item = &ASN1_INTEGER_it, | ||
| 147 | }, | ||
| 148 | }; | ||
| 149 | |||
| 150 | const ASN1_ITEM PKCS12_MAC_DATA_it = { | ||
| 151 | .itype = ASN1_ITYPE_SEQUENCE, | ||
| 152 | .utype = V_ASN1_SEQUENCE, | ||
| 153 | .templates = PKCS12_MAC_DATA_seq_tt, | ||
| 154 | .tcount = sizeof(PKCS12_MAC_DATA_seq_tt) / sizeof(ASN1_TEMPLATE), | ||
| 155 | .funcs = NULL, | ||
| 156 | .size = sizeof(PKCS12_MAC_DATA), | ||
| 157 | .sname = "PKCS12_MAC_DATA", | ||
| 158 | }; | ||
| 159 | |||
| 160 | |||
| 161 | PKCS12_MAC_DATA * | ||
| 162 | d2i_PKCS12_MAC_DATA(PKCS12_MAC_DATA **a, const unsigned char **in, long len) | ||
| 163 | { | ||
| 164 | return (PKCS12_MAC_DATA *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, | ||
| 165 | &PKCS12_MAC_DATA_it); | ||
| 166 | } | ||
| 167 | |||
| 168 | int | ||
| 169 | i2d_PKCS12_MAC_DATA(PKCS12_MAC_DATA *a, unsigned char **out) | ||
| 170 | { | ||
| 171 | return ASN1_item_i2d((ASN1_VALUE *)a, out, &PKCS12_MAC_DATA_it); | ||
| 172 | } | ||
| 173 | |||
| 174 | PKCS12_MAC_DATA * | ||
| 175 | PKCS12_MAC_DATA_new(void) | ||
| 176 | { | ||
| 177 | return (PKCS12_MAC_DATA *)ASN1_item_new(&PKCS12_MAC_DATA_it); | ||
| 178 | } | ||
| 179 | |||
| 180 | void | ||
| 181 | PKCS12_MAC_DATA_free(PKCS12_MAC_DATA *a) | ||
| 182 | { | ||
| 183 | ASN1_item_free((ASN1_VALUE *)a, &PKCS12_MAC_DATA_it); | ||
| 184 | } | ||
| 185 | |||
| 186 | static const ASN1_TEMPLATE bag_default_tt = { | ||
| 187 | .flags = ASN1_TFLG_EXPLICIT, | ||
| 188 | .tag = 0, | ||
| 189 | .offset = offsetof(PKCS12_BAGS, value.other), | ||
| 190 | .field_name = "value.other", | ||
| 191 | .item = &ASN1_ANY_it, | ||
| 192 | }; | ||
| 193 | |||
| 194 | static const ASN1_ADB_TABLE PKCS12_BAGS_adbtbl[] = { | ||
| 195 | { | ||
| 196 | .value = NID_x509Certificate, | ||
| 197 | .tt = { | ||
| 198 | .flags = ASN1_TFLG_EXPLICIT, | ||
| 199 | .tag = 0, | ||
| 200 | .offset = offsetof(PKCS12_BAGS, value.x509cert), | ||
| 201 | .field_name = "value.x509cert", | ||
| 202 | .item = &ASN1_OCTET_STRING_it, | ||
| 203 | }, | ||
| 204 | |||
| 205 | }, | ||
| 206 | { | ||
| 207 | .value = NID_x509Crl, | ||
| 208 | .tt = { | ||
| 209 | .flags = ASN1_TFLG_EXPLICIT, | ||
| 210 | .tag = 0, | ||
| 211 | .offset = offsetof(PKCS12_BAGS, value.x509crl), | ||
| 212 | .field_name = "value.x509crl", | ||
| 213 | .item = &ASN1_OCTET_STRING_it, | ||
| 214 | }, | ||
| 215 | |||
| 216 | }, | ||
| 217 | { | ||
| 218 | .value = NID_sdsiCertificate, | ||
| 219 | .tt = { | ||
| 220 | .flags = ASN1_TFLG_EXPLICIT, | ||
| 221 | .tag = 0, | ||
| 222 | .offset = offsetof(PKCS12_BAGS, value.sdsicert), | ||
| 223 | .field_name = "value.sdsicert", | ||
| 224 | .item = &ASN1_IA5STRING_it, | ||
| 225 | }, | ||
| 226 | |||
| 227 | }, | ||
| 228 | }; | ||
| 229 | |||
| 230 | static const ASN1_ADB PKCS12_BAGS_adb = { | ||
| 231 | .flags = 0, | ||
| 232 | .offset = offsetof(PKCS12_BAGS, type), | ||
| 233 | .app_items = 0, | ||
| 234 | .tbl = PKCS12_BAGS_adbtbl, | ||
| 235 | .tblcount = sizeof(PKCS12_BAGS_adbtbl) / sizeof(ASN1_ADB_TABLE), | ||
| 236 | .default_tt = &bag_default_tt, | ||
| 237 | .null_tt = NULL, | ||
| 238 | }; | ||
| 239 | |||
| 240 | static const ASN1_TEMPLATE PKCS12_BAGS_seq_tt[] = { | ||
| 241 | { | ||
| 242 | .flags = 0, | ||
| 243 | .tag = 0, | ||
| 244 | .offset = offsetof(PKCS12_BAGS, type), | ||
| 245 | .field_name = "type", | ||
| 246 | .item = &ASN1_OBJECT_it, | ||
| 247 | }, | ||
| 248 | { | ||
| 249 | .flags = ASN1_TFLG_ADB_OID, | ||
| 250 | .tag = -1, | ||
| 251 | .offset = 0, | ||
| 252 | .field_name = "PKCS12_BAGS", | ||
| 253 | .item = (const ASN1_ITEM *)&PKCS12_BAGS_adb, | ||
| 254 | }, | ||
| 255 | }; | ||
| 256 | |||
| 257 | const ASN1_ITEM PKCS12_BAGS_it = { | ||
| 258 | .itype = ASN1_ITYPE_SEQUENCE, | ||
| 259 | .utype = V_ASN1_SEQUENCE, | ||
| 260 | .templates = PKCS12_BAGS_seq_tt, | ||
| 261 | .tcount = sizeof(PKCS12_BAGS_seq_tt) / sizeof(ASN1_TEMPLATE), | ||
| 262 | .funcs = NULL, | ||
| 263 | .size = sizeof(PKCS12_BAGS), | ||
| 264 | .sname = "PKCS12_BAGS", | ||
| 265 | }; | ||
| 266 | |||
| 267 | |||
| 268 | PKCS12_BAGS * | ||
| 269 | d2i_PKCS12_BAGS(PKCS12_BAGS **a, const unsigned char **in, long len) | ||
| 270 | { | ||
| 271 | return (PKCS12_BAGS *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, | ||
| 272 | &PKCS12_BAGS_it); | ||
| 273 | } | ||
| 274 | |||
| 275 | int | ||
| 276 | i2d_PKCS12_BAGS(PKCS12_BAGS *a, unsigned char **out) | ||
| 277 | { | ||
| 278 | return ASN1_item_i2d((ASN1_VALUE *)a, out, &PKCS12_BAGS_it); | ||
| 279 | } | ||
| 280 | |||
| 281 | PKCS12_BAGS * | ||
| 282 | PKCS12_BAGS_new(void) | ||
| 283 | { | ||
| 284 | return (PKCS12_BAGS *)ASN1_item_new(&PKCS12_BAGS_it); | ||
| 285 | } | ||
| 286 | |||
| 287 | void | ||
| 288 | PKCS12_BAGS_free(PKCS12_BAGS *a) | ||
| 289 | { | ||
| 290 | ASN1_item_free((ASN1_VALUE *)a, &PKCS12_BAGS_it); | ||
| 291 | } | ||
| 292 | |||
| 293 | static const ASN1_TEMPLATE safebag_default_tt = { | ||
| 294 | .flags = ASN1_TFLG_EXPLICIT, | ||
| 295 | .tag = 0, | ||
| 296 | .offset = offsetof(PKCS12_SAFEBAG, value.other), | ||
| 297 | .field_name = "value.other", | ||
| 298 | .item = &ASN1_ANY_it, | ||
| 299 | }; | ||
| 300 | |||
| 301 | static const ASN1_ADB_TABLE PKCS12_SAFEBAG_adbtbl[] = { | ||
| 302 | { | ||
| 303 | .value = NID_keyBag, | ||
| 304 | .tt = { | ||
| 305 | .flags = ASN1_TFLG_EXPLICIT, | ||
| 306 | .tag = 0, | ||
| 307 | .offset = offsetof(PKCS12_SAFEBAG, value.keybag), | ||
| 308 | .field_name = "value.keybag", | ||
| 309 | .item = &PKCS8_PRIV_KEY_INFO_it, | ||
| 310 | }, | ||
| 311 | |||
| 312 | }, | ||
| 313 | { | ||
| 314 | .value = NID_pkcs8ShroudedKeyBag, | ||
| 315 | .tt = { | ||
| 316 | .flags = ASN1_TFLG_EXPLICIT, | ||
| 317 | .tag = 0, | ||
| 318 | .offset = offsetof(PKCS12_SAFEBAG, value.shkeybag), | ||
| 319 | .field_name = "value.shkeybag", | ||
| 320 | .item = &X509_SIG_it, | ||
| 321 | }, | ||
| 322 | |||
| 323 | }, | ||
| 324 | { | ||
| 325 | .value = NID_safeContentsBag, | ||
| 326 | .tt = { | ||
| 327 | .flags = ASN1_TFLG_EXPLICIT | ASN1_TFLG_SET_OF, | ||
| 328 | .tag = 0, | ||
| 329 | .offset = offsetof(PKCS12_SAFEBAG, value.safes), | ||
| 330 | .field_name = "value.safes", | ||
| 331 | .item = &PKCS12_SAFEBAG_it, | ||
| 332 | }, | ||
| 333 | }, | ||
| 334 | { | ||
| 335 | .value = NID_certBag, | ||
| 336 | .tt = { | ||
| 337 | .flags = ASN1_TFLG_EXPLICIT, | ||
| 338 | .tag = 0, | ||
| 339 | .offset = offsetof(PKCS12_SAFEBAG, value.bag), | ||
| 340 | .field_name = "value.bag", | ||
| 341 | .item = &PKCS12_BAGS_it, | ||
| 342 | }, | ||
| 343 | |||
| 344 | }, | ||
| 345 | { | ||
| 346 | .value = NID_crlBag, | ||
| 347 | .tt = { | ||
| 348 | .flags = ASN1_TFLG_EXPLICIT, | ||
| 349 | .tag = 0, | ||
| 350 | .offset = offsetof(PKCS12_SAFEBAG, value.bag), | ||
| 351 | .field_name = "value.bag", | ||
| 352 | .item = &PKCS12_BAGS_it, | ||
| 353 | }, | ||
| 354 | |||
| 355 | }, | ||
| 356 | { | ||
| 357 | .value = NID_secretBag, | ||
| 358 | .tt = { | ||
| 359 | .flags = ASN1_TFLG_EXPLICIT, | ||
| 360 | .tag = 0, | ||
| 361 | .offset = offsetof(PKCS12_SAFEBAG, value.bag), | ||
| 362 | .field_name = "value.bag", | ||
| 363 | .item = &PKCS12_BAGS_it, | ||
| 364 | }, | ||
| 365 | |||
| 366 | }, | ||
| 367 | }; | ||
| 368 | |||
| 369 | static const ASN1_ADB PKCS12_SAFEBAG_adb = { | ||
| 370 | .flags = 0, | ||
| 371 | .offset = offsetof(PKCS12_SAFEBAG, type), | ||
| 372 | .app_items = 0, | ||
| 373 | .tbl = PKCS12_SAFEBAG_adbtbl, | ||
| 374 | .tblcount = sizeof(PKCS12_SAFEBAG_adbtbl) / sizeof(ASN1_ADB_TABLE), | ||
| 375 | .default_tt = &safebag_default_tt, | ||
| 376 | .null_tt = NULL, | ||
| 377 | }; | ||
| 378 | |||
| 379 | static const ASN1_TEMPLATE PKCS12_SAFEBAG_seq_tt[] = { | ||
| 380 | { | ||
| 381 | .flags = 0, | ||
| 382 | .tag = 0, | ||
| 383 | .offset = offsetof(PKCS12_SAFEBAG, type), | ||
| 384 | .field_name = "type", | ||
| 385 | .item = &ASN1_OBJECT_it, | ||
| 386 | }, | ||
| 387 | { | ||
| 388 | .flags = ASN1_TFLG_ADB_OID, | ||
| 389 | .tag = -1, | ||
| 390 | .offset = 0, | ||
| 391 | .field_name = "PKCS12_SAFEBAG", | ||
| 392 | .item = (const ASN1_ITEM *)&PKCS12_SAFEBAG_adb, | ||
| 393 | }, | ||
| 394 | { | ||
| 395 | .flags = ASN1_TFLG_SET_OF | ASN1_TFLG_OPTIONAL, | ||
| 396 | .tag = 0, | ||
| 397 | .offset = offsetof(PKCS12_SAFEBAG, attrib), | ||
| 398 | .field_name = "attrib", | ||
| 399 | .item = &X509_ATTRIBUTE_it, | ||
| 400 | }, | ||
| 401 | }; | ||
| 402 | |||
| 403 | const ASN1_ITEM PKCS12_SAFEBAG_it = { | ||
| 404 | .itype = ASN1_ITYPE_SEQUENCE, | ||
| 405 | .utype = V_ASN1_SEQUENCE, | ||
| 406 | .templates = PKCS12_SAFEBAG_seq_tt, | ||
| 407 | .tcount = sizeof(PKCS12_SAFEBAG_seq_tt) / sizeof(ASN1_TEMPLATE), | ||
| 408 | .funcs = NULL, | ||
| 409 | .size = sizeof(PKCS12_SAFEBAG), | ||
| 410 | .sname = "PKCS12_SAFEBAG", | ||
| 411 | }; | ||
| 412 | |||
| 413 | |||
| 414 | PKCS12_SAFEBAG * | ||
| 415 | d2i_PKCS12_SAFEBAG(PKCS12_SAFEBAG **a, const unsigned char **in, long len) | ||
| 416 | { | ||
| 417 | return (PKCS12_SAFEBAG *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, | ||
| 418 | &PKCS12_SAFEBAG_it); | ||
| 419 | } | ||
| 420 | |||
| 421 | int | ||
| 422 | i2d_PKCS12_SAFEBAG(PKCS12_SAFEBAG *a, unsigned char **out) | ||
| 423 | { | ||
| 424 | return ASN1_item_i2d((ASN1_VALUE *)a, out, &PKCS12_SAFEBAG_it); | ||
| 425 | } | ||
| 426 | |||
| 427 | PKCS12_SAFEBAG * | ||
| 428 | PKCS12_SAFEBAG_new(void) | ||
| 429 | { | ||
| 430 | return (PKCS12_SAFEBAG *)ASN1_item_new(&PKCS12_SAFEBAG_it); | ||
| 431 | } | ||
| 432 | |||
| 433 | void | ||
| 434 | PKCS12_SAFEBAG_free(PKCS12_SAFEBAG *a) | ||
| 435 | { | ||
| 436 | ASN1_item_free((ASN1_VALUE *)a, &PKCS12_SAFEBAG_it); | ||
| 437 | } | ||
| 438 | |||
| 439 | /* SEQUENCE OF SafeBag */ | ||
| 440 | static const ASN1_TEMPLATE PKCS12_SAFEBAGS_item_tt = { | ||
| 441 | .flags = ASN1_TFLG_SEQUENCE_OF, | ||
| 442 | .tag = 0, | ||
| 443 | .offset = 0, | ||
| 444 | .field_name = "PKCS12_SAFEBAGS", | ||
| 445 | .item = &PKCS12_SAFEBAG_it, | ||
| 446 | }; | ||
| 447 | |||
| 448 | const ASN1_ITEM PKCS12_SAFEBAGS_it = { | ||
| 449 | .itype = ASN1_ITYPE_PRIMITIVE, | ||
| 450 | .utype = -1, | ||
| 451 | .templates = &PKCS12_SAFEBAGS_item_tt, | ||
| 452 | .tcount = 0, | ||
| 453 | .funcs = NULL, | ||
| 454 | .size = 0, | ||
| 455 | .sname = "PKCS12_SAFEBAGS", | ||
| 456 | }; | ||
| 457 | |||
| 458 | /* Authsafes: SEQUENCE OF PKCS7 */ | ||
| 459 | static const ASN1_TEMPLATE PKCS12_AUTHSAFES_item_tt = { | ||
| 460 | .flags = ASN1_TFLG_SEQUENCE_OF, | ||
| 461 | .tag = 0, | ||
| 462 | .offset = 0, | ||
| 463 | .field_name = "PKCS12_AUTHSAFES", | ||
| 464 | .item = &PKCS7_it, | ||
| 465 | }; | ||
| 466 | |||
| 467 | const ASN1_ITEM PKCS12_AUTHSAFES_it = { | ||
| 468 | .itype = ASN1_ITYPE_PRIMITIVE, | ||
| 469 | .utype = -1, | ||
| 470 | .templates = &PKCS12_AUTHSAFES_item_tt, | ||
| 471 | .tcount = 0, | ||
| 472 | .funcs = NULL, | ||
| 473 | .size = 0, | ||
| 474 | .sname = "PKCS12_AUTHSAFES", | ||
| 475 | }; | ||
| 476 | |||
diff --git a/src/lib/libcrypto/pkcs12/p12_attr.c b/src/lib/libcrypto/pkcs12/p12_attr.c deleted file mode 100644 index 7552cf0a60..0000000000 --- a/src/lib/libcrypto/pkcs12/p12_attr.c +++ /dev/null | |||
| @@ -1,155 +0,0 @@ | |||
| 1 | /* $OpenBSD: p12_attr.c,v 1.10 2014/07/11 08:44:49 jsing Exp $ */ | ||
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | |||
| 61 | #include <openssl/pkcs12.h> | ||
| 62 | |||
| 63 | /* Add a local keyid to a safebag */ | ||
| 64 | |||
| 65 | int | ||
| 66 | PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen) | ||
| 67 | { | ||
| 68 | if (X509at_add1_attr_by_NID(&bag->attrib, NID_localKeyID, | ||
| 69 | V_ASN1_OCTET_STRING, name, namelen)) | ||
| 70 | return 1; | ||
| 71 | else | ||
| 72 | return 0; | ||
| 73 | } | ||
| 74 | |||
| 75 | /* Add key usage to PKCS#8 structure */ | ||
| 76 | |||
| 77 | int | ||
| 78 | PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage) | ||
| 79 | { | ||
| 80 | unsigned char us_val; | ||
| 81 | |||
| 82 | us_val = (unsigned char) usage; | ||
| 83 | if (X509at_add1_attr_by_NID(&p8->attributes, NID_key_usage, | ||
| 84 | V_ASN1_BIT_STRING, &us_val, 1)) | ||
| 85 | return 1; | ||
| 86 | else | ||
| 87 | return 0; | ||
| 88 | } | ||
| 89 | |||
| 90 | /* Add a friendlyname to a safebag */ | ||
| 91 | |||
| 92 | int | ||
| 93 | PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name, int namelen) | ||
| 94 | { | ||
| 95 | if (X509at_add1_attr_by_NID(&bag->attrib, NID_friendlyName, | ||
| 96 | MBSTRING_ASC, (unsigned char *)name, namelen)) | ||
| 97 | return 1; | ||
| 98 | else | ||
| 99 | return 0; | ||
| 100 | } | ||
| 101 | |||
| 102 | |||
| 103 | int | ||
| 104 | PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag, const unsigned char *name, | ||
| 105 | int namelen) | ||
| 106 | { | ||
| 107 | if (X509at_add1_attr_by_NID(&bag->attrib, NID_friendlyName, | ||
| 108 | MBSTRING_BMP, name, namelen)) | ||
| 109 | return 1; | ||
| 110 | else | ||
| 111 | return 0; | ||
| 112 | } | ||
| 113 | |||
| 114 | int | ||
| 115 | PKCS12_add_CSPName_asc(PKCS12_SAFEBAG *bag, const char *name, int namelen) | ||
| 116 | { | ||
| 117 | if (X509at_add1_attr_by_NID(&bag->attrib, NID_ms_csp_name, | ||
| 118 | MBSTRING_ASC, (unsigned char *)name, namelen)) | ||
| 119 | return 1; | ||
| 120 | else | ||
| 121 | return 0; | ||
| 122 | } | ||
| 123 | |||
| 124 | ASN1_TYPE * | ||
| 125 | PKCS12_get_attr_gen(STACK_OF(X509_ATTRIBUTE) *attrs, int attr_nid) | ||
| 126 | { | ||
| 127 | X509_ATTRIBUTE *attrib; | ||
| 128 | int i; | ||
| 129 | |||
| 130 | if (!attrs) | ||
| 131 | return NULL; | ||
| 132 | for (i = 0; i < sk_X509_ATTRIBUTE_num (attrs); i++) { | ||
| 133 | attrib = sk_X509_ATTRIBUTE_value (attrs, i); | ||
| 134 | if (OBJ_obj2nid (attrib->object) == attr_nid) { | ||
| 135 | if (sk_ASN1_TYPE_num (attrib->value.set)) | ||
| 136 | return sk_ASN1_TYPE_value(attrib->value.set, 0); | ||
| 137 | else | ||
| 138 | return NULL; | ||
| 139 | } | ||
| 140 | } | ||
| 141 | return NULL; | ||
| 142 | } | ||
| 143 | |||
| 144 | char * | ||
| 145 | PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag) | ||
| 146 | { | ||
| 147 | ASN1_TYPE *atype; | ||
| 148 | |||
| 149 | if (!(atype = PKCS12_get_attr(bag, NID_friendlyName))) | ||
| 150 | return NULL; | ||
| 151 | if (atype->type != V_ASN1_BMPSTRING) | ||
| 152 | return NULL; | ||
| 153 | return OPENSSL_uni2asc(atype->value.bmpstring->data, | ||
| 154 | atype->value.bmpstring->length); | ||
| 155 | } | ||
diff --git a/src/lib/libcrypto/pkcs12/p12_crpt.c b/src/lib/libcrypto/pkcs12/p12_crpt.c deleted file mode 100644 index 288c93c49f..0000000000 --- a/src/lib/libcrypto/pkcs12/p12_crpt.c +++ /dev/null | |||
| @@ -1,117 +0,0 @@ | |||
| 1 | /* $OpenBSD: p12_crpt.c,v 1.11 2014/07/11 08:44:49 jsing Exp $ */ | ||
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | |||
| 61 | #include <openssl/err.h> | ||
| 62 | #include <openssl/pkcs12.h> | ||
| 63 | |||
| 64 | /* PKCS#12 PBE algorithms now in static table */ | ||
| 65 | |||
| 66 | void | ||
| 67 | PKCS12_PBE_add(void) | ||
| 68 | { | ||
| 69 | } | ||
| 70 | |||
| 71 | int | ||
| 72 | PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, | ||
| 73 | ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md, int en_de) | ||
| 74 | { | ||
| 75 | PBEPARAM *pbe; | ||
| 76 | int saltlen, iter, ret; | ||
| 77 | unsigned char *salt; | ||
| 78 | const unsigned char *pbuf; | ||
| 79 | unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH]; | ||
| 80 | |||
| 81 | /* Extract useful info from parameter */ | ||
| 82 | if (param == NULL || param->type != V_ASN1_SEQUENCE || | ||
| 83 | param->value.sequence == NULL) { | ||
| 84 | PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN, PKCS12_R_DECODE_ERROR); | ||
| 85 | return 0; | ||
| 86 | } | ||
| 87 | |||
| 88 | pbuf = param->value.sequence->data; | ||
| 89 | if (!(pbe = d2i_PBEPARAM(NULL, &pbuf, param->value.sequence->length))) { | ||
| 90 | PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN, PKCS12_R_DECODE_ERROR); | ||
| 91 | return 0; | ||
| 92 | } | ||
| 93 | |||
| 94 | if (!pbe->iter) | ||
| 95 | iter = 1; | ||
| 96 | else | ||
| 97 | iter = ASN1_INTEGER_get (pbe->iter); | ||
| 98 | salt = pbe->salt->data; | ||
| 99 | saltlen = pbe->salt->length; | ||
| 100 | if (!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_KEY_ID, | ||
| 101 | iter, EVP_CIPHER_key_length(cipher), key, md)) { | ||
| 102 | PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN, PKCS12_R_KEY_GEN_ERROR); | ||
| 103 | PBEPARAM_free(pbe); | ||
| 104 | return 0; | ||
| 105 | } | ||
| 106 | if (!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_IV_ID, | ||
| 107 | iter, EVP_CIPHER_iv_length(cipher), iv, md)) { | ||
| 108 | PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN, PKCS12_R_IV_GEN_ERROR); | ||
| 109 | PBEPARAM_free(pbe); | ||
| 110 | return 0; | ||
| 111 | } | ||
| 112 | PBEPARAM_free(pbe); | ||
| 113 | ret = EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, en_de); | ||
| 114 | OPENSSL_cleanse(key, EVP_MAX_KEY_LENGTH); | ||
| 115 | OPENSSL_cleanse(iv, EVP_MAX_IV_LENGTH); | ||
| 116 | return ret; | ||
| 117 | } | ||
diff --git a/src/lib/libcrypto/pkcs12/p12_crt.c b/src/lib/libcrypto/pkcs12/p12_crt.c deleted file mode 100644 index bef4d54cd9..0000000000 --- a/src/lib/libcrypto/pkcs12/p12_crt.c +++ /dev/null | |||
| @@ -1,350 +0,0 @@ | |||
| 1 | /* $OpenBSD: p12_crt.c,v 1.16 2015/02/14 12:43:07 miod Exp $ */ | ||
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | * project. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | |||
| 61 | #include <openssl/err.h> | ||
| 62 | #include <openssl/pkcs12.h> | ||
| 63 | |||
| 64 | static int pkcs12_add_bag(STACK_OF(PKCS12_SAFEBAG) **pbags, | ||
| 65 | PKCS12_SAFEBAG *bag); | ||
| 66 | |||
| 67 | static int | ||
| 68 | copy_bag_attr(PKCS12_SAFEBAG *bag, EVP_PKEY *pkey, int nid) | ||
| 69 | { | ||
| 70 | int idx; | ||
| 71 | X509_ATTRIBUTE *attr; | ||
| 72 | |||
| 73 | idx = EVP_PKEY_get_attr_by_NID(pkey, nid, -1); | ||
| 74 | if (idx < 0) | ||
| 75 | return 1; | ||
| 76 | attr = EVP_PKEY_get_attr(pkey, idx); | ||
| 77 | if (!X509at_add1_attr(&bag->attrib, attr)) | ||
| 78 | return 0; | ||
| 79 | return 1; | ||
| 80 | } | ||
| 81 | |||
| 82 | PKCS12 * | ||
| 83 | PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert, | ||
| 84 | STACK_OF(X509) *ca, int nid_key, int nid_cert, int iter, int mac_iter, | ||
| 85 | int keytype) | ||
| 86 | { | ||
| 87 | PKCS12 *p12 = NULL; | ||
| 88 | STACK_OF(PKCS7) *safes = NULL; | ||
| 89 | STACK_OF(PKCS12_SAFEBAG) *bags = NULL; | ||
| 90 | PKCS12_SAFEBAG *bag = NULL; | ||
| 91 | int i; | ||
| 92 | unsigned char keyid[EVP_MAX_MD_SIZE]; | ||
| 93 | unsigned int keyidlen = 0; | ||
| 94 | |||
| 95 | /* Set defaults */ | ||
| 96 | if (!nid_cert) { | ||
| 97 | nid_cert = NID_pbe_WithSHA1And40BitRC2_CBC; | ||
| 98 | } | ||
| 99 | if (!nid_key) | ||
| 100 | nid_key = NID_pbe_WithSHA1And3_Key_TripleDES_CBC; | ||
| 101 | if (!iter) | ||
| 102 | iter = PKCS12_DEFAULT_ITER; | ||
| 103 | if (!mac_iter) | ||
| 104 | mac_iter = 1; | ||
| 105 | |||
| 106 | if (!pkey && !cert && !ca) { | ||
| 107 | PKCS12err(PKCS12_F_PKCS12_CREATE, | ||
| 108 | PKCS12_R_INVALID_NULL_ARGUMENT); | ||
| 109 | return NULL; | ||
| 110 | } | ||
| 111 | |||
| 112 | if (pkey && cert) { | ||
| 113 | if (!X509_check_private_key(cert, pkey)) | ||
| 114 | return NULL; | ||
| 115 | X509_digest(cert, EVP_sha1(), keyid, &keyidlen); | ||
| 116 | } | ||
| 117 | |||
| 118 | if (cert) { | ||
| 119 | bag = PKCS12_add_cert(&bags, cert); | ||
| 120 | if (name && !PKCS12_add_friendlyname(bag, name, -1)) | ||
| 121 | goto err; | ||
| 122 | if (keyidlen && !PKCS12_add_localkeyid(bag, keyid, keyidlen)) | ||
| 123 | goto err; | ||
| 124 | } | ||
| 125 | |||
| 126 | /* Add all other certificates */ | ||
| 127 | for (i = 0; i < sk_X509_num(ca); i++) { | ||
| 128 | if (!PKCS12_add_cert(&bags, sk_X509_value(ca, i))) | ||
| 129 | goto err; | ||
| 130 | } | ||
| 131 | |||
| 132 | if (bags && !PKCS12_add_safe(&safes, bags, nid_cert, iter, pass)) | ||
| 133 | goto err; | ||
| 134 | |||
| 135 | sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free); | ||
| 136 | bags = NULL; | ||
| 137 | |||
| 138 | if (pkey) { | ||
| 139 | bag = PKCS12_add_key(&bags, pkey, keytype, iter, nid_key, pass); | ||
| 140 | |||
| 141 | if (!bag) | ||
| 142 | goto err; | ||
| 143 | |||
| 144 | if (!copy_bag_attr(bag, pkey, NID_ms_csp_name)) | ||
| 145 | goto err; | ||
| 146 | if (!copy_bag_attr(bag, pkey, NID_LocalKeySet)) | ||
| 147 | goto err; | ||
| 148 | |||
| 149 | if (name && !PKCS12_add_friendlyname(bag, name, -1)) | ||
| 150 | goto err; | ||
| 151 | if (keyidlen && !PKCS12_add_localkeyid(bag, keyid, keyidlen)) | ||
| 152 | goto err; | ||
| 153 | } | ||
| 154 | |||
| 155 | if (bags && !PKCS12_add_safe(&safes, bags, -1, 0, NULL)) | ||
| 156 | goto err; | ||
| 157 | |||
| 158 | sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free); | ||
| 159 | bags = NULL; | ||
| 160 | |||
| 161 | p12 = PKCS12_add_safes(safes, 0); | ||
| 162 | |||
| 163 | if (!p12) | ||
| 164 | goto err; | ||
| 165 | |||
| 166 | sk_PKCS7_pop_free(safes, PKCS7_free); | ||
| 167 | |||
| 168 | safes = NULL; | ||
| 169 | |||
| 170 | if ((mac_iter != -1) && | ||
| 171 | !PKCS12_set_mac(p12, pass, -1, NULL, 0, mac_iter, NULL)) | ||
| 172 | goto err; | ||
| 173 | |||
| 174 | return p12; | ||
| 175 | |||
| 176 | err: | ||
| 177 | if (p12) | ||
| 178 | PKCS12_free(p12); | ||
| 179 | if (safes) | ||
| 180 | sk_PKCS7_pop_free(safes, PKCS7_free); | ||
| 181 | if (bags) | ||
| 182 | sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free); | ||
| 183 | return NULL; | ||
| 184 | } | ||
| 185 | |||
| 186 | PKCS12_SAFEBAG * | ||
| 187 | PKCS12_add_cert(STACK_OF(PKCS12_SAFEBAG) **pbags, X509 *cert) | ||
| 188 | { | ||
| 189 | PKCS12_SAFEBAG *bag = NULL; | ||
| 190 | char *name; | ||
| 191 | int namelen = -1; | ||
| 192 | unsigned char *keyid; | ||
| 193 | int keyidlen = -1; | ||
| 194 | |||
| 195 | /* Add user certificate */ | ||
| 196 | if (!(bag = PKCS12_x5092certbag(cert))) | ||
| 197 | goto err; | ||
| 198 | |||
| 199 | /* Use friendlyName and localKeyID in certificate. | ||
| 200 | * (if present) | ||
| 201 | */ | ||
| 202 | name = (char *)X509_alias_get0(cert, &namelen); | ||
| 203 | if (name && !PKCS12_add_friendlyname(bag, name, namelen)) | ||
| 204 | goto err; | ||
| 205 | |||
| 206 | keyid = X509_keyid_get0(cert, &keyidlen); | ||
| 207 | |||
| 208 | if (keyid && !PKCS12_add_localkeyid(bag, keyid, keyidlen)) | ||
| 209 | goto err; | ||
| 210 | |||
| 211 | if (!pkcs12_add_bag(pbags, bag)) | ||
| 212 | goto err; | ||
| 213 | |||
| 214 | return bag; | ||
| 215 | |||
| 216 | err: | ||
| 217 | if (bag) | ||
| 218 | PKCS12_SAFEBAG_free(bag); | ||
| 219 | |||
| 220 | return NULL; | ||
| 221 | } | ||
| 222 | |||
| 223 | PKCS12_SAFEBAG * | ||
| 224 | PKCS12_add_key(STACK_OF(PKCS12_SAFEBAG) **pbags, EVP_PKEY *key, int key_usage, | ||
| 225 | int iter, int nid_key, char *pass) | ||
| 226 | { | ||
| 227 | PKCS12_SAFEBAG *bag = NULL; | ||
| 228 | PKCS8_PRIV_KEY_INFO *p8 = NULL; | ||
| 229 | |||
| 230 | /* Make a PKCS#8 structure */ | ||
| 231 | if (!(p8 = EVP_PKEY2PKCS8(key))) | ||
| 232 | goto err; | ||
| 233 | if (key_usage && !PKCS8_add_keyusage(p8, key_usage)) | ||
| 234 | goto err; | ||
| 235 | if (nid_key != -1) { | ||
| 236 | bag = PKCS12_MAKE_SHKEYBAG(nid_key, pass, -1, NULL, 0, | ||
| 237 | iter, p8); | ||
| 238 | PKCS8_PRIV_KEY_INFO_free(p8); | ||
| 239 | p8 = NULL; | ||
| 240 | } else { | ||
| 241 | bag = PKCS12_MAKE_KEYBAG(p8); | ||
| 242 | if (bag != NULL) | ||
| 243 | p8 = NULL; | ||
| 244 | } | ||
| 245 | |||
| 246 | if (!bag) | ||
| 247 | goto err; | ||
| 248 | |||
| 249 | if (!pkcs12_add_bag(pbags, bag)) | ||
| 250 | goto err; | ||
| 251 | |||
| 252 | return bag; | ||
| 253 | |||
| 254 | err: | ||
| 255 | if (bag) | ||
| 256 | PKCS12_SAFEBAG_free(bag); | ||
| 257 | if (p8) | ||
| 258 | PKCS8_PRIV_KEY_INFO_free(p8); | ||
| 259 | |||
| 260 | return NULL; | ||
| 261 | } | ||
| 262 | |||
| 263 | int | ||
| 264 | PKCS12_add_safe(STACK_OF(PKCS7) **psafes, STACK_OF(PKCS12_SAFEBAG) *bags, | ||
| 265 | int nid_safe, int iter, char *pass) | ||
| 266 | { | ||
| 267 | PKCS7 *p7 = NULL; | ||
| 268 | int free_safes = 0; | ||
| 269 | |||
| 270 | if (!*psafes) { | ||
| 271 | *psafes = sk_PKCS7_new_null(); | ||
| 272 | if (!*psafes) | ||
| 273 | return 0; | ||
| 274 | free_safes = 1; | ||
| 275 | } else | ||
| 276 | free_safes = 0; | ||
| 277 | |||
| 278 | if (nid_safe == 0) | ||
| 279 | nid_safe = NID_pbe_WithSHA1And40BitRC2_CBC; | ||
| 280 | |||
| 281 | if (nid_safe == -1) | ||
| 282 | p7 = PKCS12_pack_p7data(bags); | ||
| 283 | else | ||
| 284 | p7 = PKCS12_pack_p7encdata(nid_safe, pass, -1, NULL, 0, | ||
| 285 | iter, bags); | ||
| 286 | if (!p7) | ||
| 287 | goto err; | ||
| 288 | |||
| 289 | if (!sk_PKCS7_push(*psafes, p7)) | ||
| 290 | goto err; | ||
| 291 | |||
| 292 | return 1; | ||
| 293 | |||
| 294 | err: | ||
| 295 | if (free_safes) { | ||
| 296 | sk_PKCS7_free(*psafes); | ||
| 297 | *psafes = NULL; | ||
| 298 | } | ||
| 299 | |||
| 300 | if (p7) | ||
| 301 | PKCS7_free(p7); | ||
| 302 | |||
| 303 | return 0; | ||
| 304 | } | ||
| 305 | |||
| 306 | static int | ||
| 307 | pkcs12_add_bag(STACK_OF(PKCS12_SAFEBAG) **pbags, PKCS12_SAFEBAG *bag) | ||
| 308 | { | ||
| 309 | int free_bags; | ||
| 310 | |||
| 311 | if (!pbags) | ||
| 312 | return 1; | ||
| 313 | if (!*pbags) { | ||
| 314 | *pbags = sk_PKCS12_SAFEBAG_new_null(); | ||
| 315 | if (!*pbags) | ||
| 316 | return 0; | ||
| 317 | free_bags = 1; | ||
| 318 | } else | ||
| 319 | free_bags = 0; | ||
| 320 | |||
| 321 | if (!sk_PKCS12_SAFEBAG_push(*pbags, bag)) { | ||
| 322 | if (free_bags) { | ||
| 323 | sk_PKCS12_SAFEBAG_free(*pbags); | ||
| 324 | *pbags = NULL; | ||
| 325 | } | ||
| 326 | return 0; | ||
| 327 | } | ||
| 328 | |||
| 329 | return 1; | ||
| 330 | } | ||
| 331 | |||
| 332 | PKCS12 * | ||
| 333 | PKCS12_add_safes(STACK_OF(PKCS7) *safes, int nid_p7) | ||
| 334 | { | ||
| 335 | PKCS12 *p12; | ||
| 336 | |||
| 337 | if (nid_p7 <= 0) | ||
| 338 | nid_p7 = NID_pkcs7_data; | ||
| 339 | p12 = PKCS12_init(nid_p7); | ||
| 340 | |||
| 341 | if (!p12) | ||
| 342 | return NULL; | ||
| 343 | |||
| 344 | if (!PKCS12_pack_authsafes(p12, safes)) { | ||
| 345 | PKCS12_free(p12); | ||
| 346 | return NULL; | ||
| 347 | } | ||
| 348 | |||
| 349 | return p12; | ||
| 350 | } | ||
diff --git a/src/lib/libcrypto/pkcs12/p12_decr.c b/src/lib/libcrypto/pkcs12/p12_decr.c deleted file mode 100644 index 4cccf43d3f..0000000000 --- a/src/lib/libcrypto/pkcs12/p12_decr.c +++ /dev/null | |||
| @@ -1,189 +0,0 @@ | |||
| 1 | /* $OpenBSD: p12_decr.c,v 1.15 2015/05/15 11:00:14 jsg Exp $ */ | ||
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | |||
| 61 | #include <openssl/err.h> | ||
| 62 | #include <openssl/pkcs12.h> | ||
| 63 | |||
| 64 | /* Encrypt/Decrypt a buffer based on password and algor, result in a | ||
| 65 | * malloc'ed buffer | ||
| 66 | */ | ||
| 67 | |||
| 68 | unsigned char * | ||
| 69 | PKCS12_pbe_crypt(X509_ALGOR *algor, const char *pass, int passlen, | ||
| 70 | unsigned char *in, int inlen, unsigned char **data, int *datalen, int en_de) | ||
| 71 | { | ||
| 72 | unsigned char *out; | ||
| 73 | int outlen, i; | ||
| 74 | EVP_CIPHER_CTX ctx; | ||
| 75 | |||
| 76 | EVP_CIPHER_CTX_init(&ctx); | ||
| 77 | /* Decrypt data */ | ||
| 78 | if (!EVP_PBE_CipherInit(algor->algorithm, pass, passlen, | ||
| 79 | algor->parameter, &ctx, en_de)) { | ||
| 80 | out = NULL; | ||
| 81 | PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT, | ||
| 82 | PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR); | ||
| 83 | goto err; | ||
| 84 | } | ||
| 85 | |||
| 86 | if (!(out = malloc(inlen + EVP_CIPHER_CTX_block_size(&ctx)))) { | ||
| 87 | PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT, ERR_R_MALLOC_FAILURE); | ||
| 88 | goto err; | ||
| 89 | } | ||
| 90 | |||
| 91 | if (!EVP_CipherUpdate(&ctx, out, &i, in, inlen)) { | ||
| 92 | free(out); | ||
| 93 | out = NULL; | ||
| 94 | PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT, ERR_R_EVP_LIB); | ||
| 95 | goto err; | ||
| 96 | } | ||
| 97 | |||
| 98 | outlen = i; | ||
| 99 | if (!EVP_CipherFinal_ex(&ctx, out + i, &i)) { | ||
| 100 | free(out); | ||
| 101 | out = NULL; | ||
| 102 | PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT, | ||
| 103 | PKCS12_R_PKCS12_CIPHERFINAL_ERROR); | ||
| 104 | goto err; | ||
| 105 | } | ||
| 106 | outlen += i; | ||
| 107 | if (datalen) | ||
| 108 | *datalen = outlen; | ||
| 109 | if (data) | ||
| 110 | *data = out; | ||
| 111 | |||
| 112 | err: | ||
| 113 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
| 114 | return out; | ||
| 115 | |||
| 116 | } | ||
| 117 | |||
| 118 | /* Decrypt an OCTET STRING and decode ASN1 structure | ||
| 119 | * if zbuf set zero buffer after use. | ||
| 120 | */ | ||
| 121 | |||
| 122 | void * | ||
| 123 | PKCS12_item_decrypt_d2i(X509_ALGOR *algor, const ASN1_ITEM *it, | ||
| 124 | const char *pass, int passlen, ASN1_OCTET_STRING *oct, int zbuf) | ||
| 125 | { | ||
| 126 | unsigned char *out; | ||
| 127 | const unsigned char *p; | ||
| 128 | void *ret; | ||
| 129 | int outlen; | ||
| 130 | |||
| 131 | if (!PKCS12_pbe_crypt(algor, pass, passlen, oct->data, oct->length, | ||
| 132 | &out, &outlen, 0)) { | ||
| 133 | PKCS12err(PKCS12_F_PKCS12_ITEM_DECRYPT_D2I, | ||
| 134 | PKCS12_R_PKCS12_PBE_CRYPT_ERROR); | ||
| 135 | return NULL; | ||
| 136 | } | ||
| 137 | p = out; | ||
| 138 | ret = ASN1_item_d2i(NULL, &p, outlen, it); | ||
| 139 | if (zbuf) | ||
| 140 | OPENSSL_cleanse(out, outlen); | ||
| 141 | if (!ret) | ||
| 142 | PKCS12err(PKCS12_F_PKCS12_ITEM_DECRYPT_D2I, | ||
| 143 | PKCS12_R_DECODE_ERROR); | ||
| 144 | free(out); | ||
| 145 | return ret; | ||
| 146 | } | ||
| 147 | |||
| 148 | /* Encode ASN1 structure and encrypt, return OCTET STRING | ||
| 149 | * if zbuf set zero encoding. | ||
| 150 | */ | ||
| 151 | |||
| 152 | ASN1_OCTET_STRING * | ||
| 153 | PKCS12_item_i2d_encrypt(X509_ALGOR *algor, const ASN1_ITEM *it, | ||
| 154 | const char *pass, int passlen, | ||
| 155 | void *obj, int zbuf) | ||
| 156 | { | ||
| 157 | ASN1_OCTET_STRING *oct; | ||
| 158 | unsigned char *in = NULL; | ||
| 159 | int inlen; | ||
| 160 | |||
| 161 | if (!(oct = M_ASN1_OCTET_STRING_new ())) { | ||
| 162 | PKCS12err(PKCS12_F_PKCS12_ITEM_I2D_ENCRYPT, | ||
| 163 | ERR_R_MALLOC_FAILURE); | ||
| 164 | return NULL; | ||
| 165 | } | ||
| 166 | inlen = ASN1_item_i2d(obj, &in, it); | ||
| 167 | if (!in) { | ||
| 168 | PKCS12err(PKCS12_F_PKCS12_ITEM_I2D_ENCRYPT, | ||
| 169 | PKCS12_R_ENCODE_ERROR); | ||
| 170 | goto err; | ||
| 171 | } | ||
| 172 | if (!PKCS12_pbe_crypt(algor, pass, passlen, in, inlen, &oct->data, | ||
| 173 | &oct->length, 1)) { | ||
| 174 | PKCS12err(PKCS12_F_PKCS12_ITEM_I2D_ENCRYPT, | ||
| 175 | PKCS12_R_ENCRYPT_ERROR); | ||
| 176 | goto err; | ||
| 177 | } | ||
| 178 | if (zbuf) | ||
| 179 | OPENSSL_cleanse(in, inlen); | ||
| 180 | free(in); | ||
| 181 | return oct; | ||
| 182 | |||
| 183 | err: | ||
| 184 | free(in); | ||
| 185 | M_ASN1_OCTET_STRING_free(oct); | ||
| 186 | return NULL; | ||
| 187 | } | ||
| 188 | |||
| 189 | IMPLEMENT_PKCS12_STACK_OF(PKCS7) | ||
diff --git a/src/lib/libcrypto/pkcs12/p12_init.c b/src/lib/libcrypto/pkcs12/p12_init.c deleted file mode 100644 index 2db73d34c2..0000000000 --- a/src/lib/libcrypto/pkcs12/p12_init.c +++ /dev/null | |||
| @@ -1,97 +0,0 @@ | |||
| 1 | /* $OpenBSD: p12_init.c,v 1.9 2014/07/11 08:44:49 jsing Exp $ */ | ||
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | |||
| 61 | #include <openssl/err.h> | ||
| 62 | #include <openssl/pkcs12.h> | ||
| 63 | |||
| 64 | /* Initialise a PKCS12 structure to take data */ | ||
| 65 | |||
| 66 | PKCS12 * | ||
| 67 | PKCS12_init(int mode) | ||
| 68 | { | ||
| 69 | PKCS12 *pkcs12; | ||
| 70 | |||
| 71 | if (!(pkcs12 = PKCS12_new())) { | ||
| 72 | PKCS12err(PKCS12_F_PKCS12_INIT, ERR_R_MALLOC_FAILURE); | ||
| 73 | return NULL; | ||
| 74 | } | ||
| 75 | ASN1_INTEGER_set(pkcs12->version, 3); | ||
| 76 | pkcs12->authsafes->type = OBJ_nid2obj(mode); | ||
| 77 | switch (mode) { | ||
| 78 | case NID_pkcs7_data: | ||
| 79 | if (!(pkcs12->authsafes->d.data = | ||
| 80 | M_ASN1_OCTET_STRING_new())) { | ||
| 81 | PKCS12err(PKCS12_F_PKCS12_INIT, ERR_R_MALLOC_FAILURE); | ||
| 82 | goto err; | ||
| 83 | } | ||
| 84 | break; | ||
| 85 | default: | ||
| 86 | PKCS12err(PKCS12_F_PKCS12_INIT, | ||
| 87 | PKCS12_R_UNSUPPORTED_PKCS12_MODE); | ||
| 88 | goto err; | ||
| 89 | } | ||
| 90 | |||
| 91 | return pkcs12; | ||
| 92 | |||
| 93 | err: | ||
| 94 | if (pkcs12 != NULL) | ||
| 95 | PKCS12_free(pkcs12); | ||
| 96 | return NULL; | ||
| 97 | } | ||
diff --git a/src/lib/libcrypto/pkcs12/p12_key.c b/src/lib/libcrypto/pkcs12/p12_key.c deleted file mode 100644 index 0b3547a6fb..0000000000 --- a/src/lib/libcrypto/pkcs12/p12_key.c +++ /dev/null | |||
| @@ -1,199 +0,0 @@ | |||
| 1 | /* $OpenBSD: p12_key.c,v 1.22 2015/02/07 13:19:15 doug Exp $ */ | ||
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <string.h> | ||
| 61 | |||
| 62 | #include <openssl/bn.h> | ||
| 63 | #include <openssl/err.h> | ||
| 64 | #include <openssl/pkcs12.h> | ||
| 65 | |||
| 66 | /* PKCS12 compatible key/IV generation */ | ||
| 67 | #ifndef min | ||
| 68 | #define min(a,b) ((a) < (b) ? (a) : (b)) | ||
| 69 | #endif | ||
| 70 | |||
| 71 | int | ||
| 72 | PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt, | ||
| 73 | int saltlen, int id, int iter, int n, unsigned char *out, | ||
| 74 | const EVP_MD *md_type) | ||
| 75 | { | ||
| 76 | int ret; | ||
| 77 | unsigned char *unipass; | ||
| 78 | int uniplen; | ||
| 79 | |||
| 80 | if (!pass) { | ||
| 81 | unipass = NULL; | ||
| 82 | uniplen = 0; | ||
| 83 | } else if (!OPENSSL_asc2uni(pass, passlen, &unipass, &uniplen)) { | ||
| 84 | PKCS12err(PKCS12_F_PKCS12_KEY_GEN_ASC, ERR_R_MALLOC_FAILURE); | ||
| 85 | return 0; | ||
| 86 | } | ||
| 87 | ret = PKCS12_key_gen_uni(unipass, uniplen, salt, saltlen, | ||
| 88 | id, iter, n, out, md_type); | ||
| 89 | if (ret <= 0) | ||
| 90 | return 0; | ||
| 91 | if (unipass) { | ||
| 92 | OPENSSL_cleanse(unipass, uniplen); | ||
| 93 | free(unipass); | ||
| 94 | } | ||
| 95 | return ret; | ||
| 96 | } | ||
| 97 | |||
| 98 | int | ||
| 99 | PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt, | ||
| 100 | int saltlen, int id, int iter, int n, unsigned char *out, | ||
| 101 | const EVP_MD *md_type) | ||
| 102 | { | ||
| 103 | unsigned char *B, *D, *I, *p, *Ai; | ||
| 104 | int Slen, Plen, Ilen, Ijlen; | ||
| 105 | int i, j, u, v; | ||
| 106 | int ret = 0; | ||
| 107 | BIGNUM *Ij, *Bpl1; /* These hold Ij and B + 1 */ | ||
| 108 | EVP_MD_CTX ctx; | ||
| 109 | |||
| 110 | EVP_MD_CTX_init(&ctx); | ||
| 111 | v = EVP_MD_block_size(md_type); | ||
| 112 | u = EVP_MD_size(md_type); | ||
| 113 | if (u < 0) | ||
| 114 | return 0; | ||
| 115 | D = malloc(v); | ||
| 116 | Ai = malloc(u); | ||
| 117 | B = malloc(v + 1); | ||
| 118 | Slen = v * ((saltlen + v - 1) / v); | ||
| 119 | if (passlen) | ||
| 120 | Plen = v * ((passlen + v - 1)/v); | ||
| 121 | else | ||
| 122 | Plen = 0; | ||
| 123 | Ilen = Slen + Plen; | ||
| 124 | I = malloc(Ilen); | ||
| 125 | Ij = BN_new(); | ||
| 126 | Bpl1 = BN_new(); | ||
| 127 | if (!D || !Ai || !B || !I || !Ij || !Bpl1) | ||
| 128 | goto err; | ||
| 129 | for (i = 0; i < v; i++) | ||
| 130 | D[i] = id; | ||
| 131 | p = I; | ||
| 132 | for (i = 0; i < Slen; i++) | ||
| 133 | *p++ = salt[i % saltlen]; | ||
| 134 | for (i = 0; i < Plen; i++) | ||
| 135 | *p++ = pass[i % passlen]; | ||
| 136 | for (;;) { | ||
| 137 | if (!EVP_DigestInit_ex(&ctx, md_type, NULL) || | ||
| 138 | !EVP_DigestUpdate(&ctx, D, v) || | ||
| 139 | !EVP_DigestUpdate(&ctx, I, Ilen) || | ||
| 140 | !EVP_DigestFinal_ex(&ctx, Ai, NULL)) | ||
| 141 | goto err; | ||
| 142 | for (j = 1; j < iter; j++) { | ||
| 143 | if (!EVP_DigestInit_ex(&ctx, md_type, NULL) || | ||
| 144 | !EVP_DigestUpdate(&ctx, Ai, u) || | ||
| 145 | !EVP_DigestFinal_ex(&ctx, Ai, NULL)) | ||
| 146 | goto err; | ||
| 147 | } | ||
| 148 | memcpy (out, Ai, min (n, u)); | ||
| 149 | if (u >= n) { | ||
| 150 | ret = 1; | ||
| 151 | goto end; | ||
| 152 | } | ||
| 153 | n -= u; | ||
| 154 | out += u; | ||
| 155 | for (j = 0; j < v; j++) | ||
| 156 | B[j] = Ai[j % u]; | ||
| 157 | /* Work out B + 1 first then can use B as tmp space */ | ||
| 158 | if (!BN_bin2bn (B, v, Bpl1)) | ||
| 159 | goto err; | ||
| 160 | if (!BN_add_word (Bpl1, 1)) | ||
| 161 | goto err; | ||
| 162 | for (j = 0; j < Ilen; j += v) { | ||
| 163 | if (!BN_bin2bn(I + j, v, Ij)) | ||
| 164 | goto err; | ||
| 165 | if (!BN_add(Ij, Ij, Bpl1)) | ||
| 166 | goto err; | ||
| 167 | if (!BN_bn2bin(Ij, B)) | ||
| 168 | goto err; | ||
| 169 | Ijlen = BN_num_bytes (Ij); | ||
| 170 | /* If more than 2^(v*8) - 1 cut off MSB */ | ||
| 171 | if (Ijlen > v) { | ||
| 172 | if (!BN_bn2bin (Ij, B)) | ||
| 173 | goto err; | ||
| 174 | memcpy (I + j, B + 1, v); | ||
| 175 | #ifndef PKCS12_BROKEN_KEYGEN | ||
| 176 | /* If less than v bytes pad with zeroes */ | ||
| 177 | } else if (Ijlen < v) { | ||
| 178 | memset(I + j, 0, v - Ijlen); | ||
| 179 | if (!BN_bn2bin(Ij, I + j + v - Ijlen)) | ||
| 180 | goto err; | ||
| 181 | #endif | ||
| 182 | } else if (!BN_bn2bin (Ij, I + j)) | ||
| 183 | goto err; | ||
| 184 | } | ||
| 185 | } | ||
| 186 | |||
| 187 | err: | ||
| 188 | PKCS12err(PKCS12_F_PKCS12_KEY_GEN_UNI, ERR_R_MALLOC_FAILURE); | ||
| 189 | |||
| 190 | end: | ||
| 191 | free(Ai); | ||
| 192 | free(B); | ||
| 193 | free(D); | ||
| 194 | free(I); | ||
| 195 | BN_free(Ij); | ||
| 196 | BN_free(Bpl1); | ||
| 197 | EVP_MD_CTX_cleanup(&ctx); | ||
| 198 | return ret; | ||
| 199 | } | ||
diff --git a/src/lib/libcrypto/pkcs12/p12_kiss.c b/src/lib/libcrypto/pkcs12/p12_kiss.c deleted file mode 100644 index eaaa2bc911..0000000000 --- a/src/lib/libcrypto/pkcs12/p12_kiss.c +++ /dev/null | |||
| @@ -1,299 +0,0 @@ | |||
| 1 | /* $OpenBSD: p12_kiss.c,v 1.16 2014/07/11 08:44:49 jsing Exp $ */ | ||
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | |||
| 61 | #include <openssl/err.h> | ||
| 62 | #include <openssl/pkcs12.h> | ||
| 63 | |||
| 64 | /* Simplified PKCS#12 routines */ | ||
| 65 | |||
| 66 | static int parse_pk12( PKCS12 *p12, const char *pass, int passlen, | ||
| 67 | EVP_PKEY **pkey, STACK_OF(X509) *ocerts); | ||
| 68 | |||
| 69 | static int parse_bags( STACK_OF(PKCS12_SAFEBAG) *bags, const char *pass, | ||
| 70 | int passlen, EVP_PKEY **pkey, STACK_OF(X509) *ocerts); | ||
| 71 | |||
| 72 | static int parse_bag( PKCS12_SAFEBAG *bag, const char *pass, int passlen, | ||
| 73 | EVP_PKEY **pkey, STACK_OF(X509) *ocerts); | ||
| 74 | |||
| 75 | /* Parse and decrypt a PKCS#12 structure returning user key, user cert | ||
| 76 | * and other (CA) certs. Note either ca should be NULL, *ca should be NULL, | ||
| 77 | * or it should point to a valid STACK structure. pkey and cert can be | ||
| 78 | * passed unitialised. | ||
| 79 | */ | ||
| 80 | |||
| 81 | int | ||
| 82 | PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert, | ||
| 83 | STACK_OF(X509) **ca) | ||
| 84 | { | ||
| 85 | STACK_OF(X509) *ocerts = NULL; | ||
| 86 | X509 *x = NULL; | ||
| 87 | /* Check for NULL PKCS12 structure */ | ||
| 88 | |||
| 89 | if (!p12) { | ||
| 90 | PKCS12err(PKCS12_F_PKCS12_PARSE, | ||
| 91 | PKCS12_R_INVALID_NULL_PKCS12_POINTER); | ||
| 92 | return 0; | ||
| 93 | } | ||
| 94 | |||
| 95 | if (pkey) | ||
| 96 | *pkey = NULL; | ||
| 97 | if (cert) | ||
| 98 | *cert = NULL; | ||
| 99 | |||
| 100 | /* Check the mac */ | ||
| 101 | |||
| 102 | /* If password is zero length or NULL then try verifying both cases | ||
| 103 | * to determine which password is correct. The reason for this is that | ||
| 104 | * under PKCS#12 password based encryption no password and a zero length | ||
| 105 | * password are two different things... | ||
| 106 | */ | ||
| 107 | |||
| 108 | if (!pass || !*pass) { | ||
| 109 | if (PKCS12_verify_mac(p12, NULL, 0)) | ||
| 110 | pass = NULL; | ||
| 111 | else if (PKCS12_verify_mac(p12, "", 0)) | ||
| 112 | pass = ""; | ||
| 113 | else { | ||
| 114 | PKCS12err(PKCS12_F_PKCS12_PARSE, | ||
| 115 | PKCS12_R_MAC_VERIFY_FAILURE); | ||
| 116 | goto err; | ||
| 117 | } | ||
| 118 | } else if (!PKCS12_verify_mac(p12, pass, -1)) { | ||
| 119 | PKCS12err(PKCS12_F_PKCS12_PARSE, PKCS12_R_MAC_VERIFY_FAILURE); | ||
| 120 | goto err; | ||
| 121 | } | ||
| 122 | |||
| 123 | /* Allocate stack for other certificates */ | ||
| 124 | ocerts = sk_X509_new_null(); | ||
| 125 | if (!ocerts) { | ||
| 126 | PKCS12err(PKCS12_F_PKCS12_PARSE, ERR_R_MALLOC_FAILURE); | ||
| 127 | return 0; | ||
| 128 | } | ||
| 129 | |||
| 130 | if (!parse_pk12 (p12, pass, -1, pkey, ocerts)) { | ||
| 131 | PKCS12err(PKCS12_F_PKCS12_PARSE, PKCS12_R_PARSE_ERROR); | ||
| 132 | goto err; | ||
| 133 | } | ||
| 134 | |||
| 135 | while ((x = sk_X509_pop(ocerts))) { | ||
| 136 | if (pkey && *pkey && cert && !*cert) { | ||
| 137 | if (X509_check_private_key(x, *pkey)) { | ||
| 138 | *cert = x; | ||
| 139 | x = NULL; | ||
| 140 | } | ||
| 141 | } | ||
| 142 | |||
| 143 | if (ca && x) { | ||
| 144 | if (!*ca) | ||
| 145 | *ca = sk_X509_new_null(); | ||
| 146 | if (!*ca) | ||
| 147 | goto err; | ||
| 148 | if (!sk_X509_push(*ca, x)) | ||
| 149 | goto err; | ||
| 150 | x = NULL; | ||
| 151 | } | ||
| 152 | if (x) | ||
| 153 | X509_free(x); | ||
| 154 | } | ||
| 155 | |||
| 156 | if (ocerts) | ||
| 157 | sk_X509_pop_free(ocerts, X509_free); | ||
| 158 | |||
| 159 | return 1; | ||
| 160 | |||
| 161 | err: | ||
| 162 | if (pkey && *pkey) | ||
| 163 | EVP_PKEY_free(*pkey); | ||
| 164 | if (cert && *cert) | ||
| 165 | X509_free(*cert); | ||
| 166 | if (x) | ||
| 167 | X509_free(x); | ||
| 168 | if (ocerts) | ||
| 169 | sk_X509_pop_free(ocerts, X509_free); | ||
| 170 | return 0; | ||
| 171 | } | ||
| 172 | |||
| 173 | /* Parse the outer PKCS#12 structure */ | ||
| 174 | |||
| 175 | static int | ||
| 176 | parse_pk12(PKCS12 *p12, const char *pass, int passlen, EVP_PKEY **pkey, | ||
| 177 | STACK_OF(X509) *ocerts) | ||
| 178 | { | ||
| 179 | STACK_OF(PKCS7) *asafes; | ||
| 180 | STACK_OF(PKCS12_SAFEBAG) *bags; | ||
| 181 | int i, bagnid; | ||
| 182 | PKCS7 *p7; | ||
| 183 | |||
| 184 | if (!(asafes = PKCS12_unpack_authsafes (p12))) | ||
| 185 | return 0; | ||
| 186 | for (i = 0; i < sk_PKCS7_num (asafes); i++) { | ||
| 187 | p7 = sk_PKCS7_value (asafes, i); | ||
| 188 | bagnid = OBJ_obj2nid (p7->type); | ||
| 189 | if (bagnid == NID_pkcs7_data) { | ||
| 190 | bags = PKCS12_unpack_p7data(p7); | ||
| 191 | } else if (bagnid == NID_pkcs7_encrypted) { | ||
| 192 | bags = PKCS12_unpack_p7encdata(p7, pass, passlen); | ||
| 193 | } else | ||
| 194 | continue; | ||
| 195 | if (!bags) { | ||
| 196 | sk_PKCS7_pop_free(asafes, PKCS7_free); | ||
| 197 | return 0; | ||
| 198 | } | ||
| 199 | if (!parse_bags(bags, pass, passlen, pkey, ocerts)) { | ||
| 200 | sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free); | ||
| 201 | sk_PKCS7_pop_free(asafes, PKCS7_free); | ||
| 202 | return 0; | ||
| 203 | } | ||
| 204 | sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free); | ||
| 205 | } | ||
| 206 | sk_PKCS7_pop_free(asafes, PKCS7_free); | ||
| 207 | return 1; | ||
| 208 | } | ||
| 209 | |||
| 210 | static int | ||
| 211 | parse_bags(STACK_OF(PKCS12_SAFEBAG) *bags, const char *pass, int passlen, | ||
| 212 | EVP_PKEY **pkey, STACK_OF(X509) *ocerts) | ||
| 213 | { | ||
| 214 | int i; | ||
| 215 | |||
| 216 | for (i = 0; i < sk_PKCS12_SAFEBAG_num(bags); i++) { | ||
| 217 | if (!parse_bag(sk_PKCS12_SAFEBAG_value(bags, i), pass, passlen, | ||
| 218 | pkey, ocerts)) | ||
| 219 | return 0; | ||
| 220 | } | ||
| 221 | return 1; | ||
| 222 | } | ||
| 223 | |||
| 224 | static int | ||
| 225 | parse_bag(PKCS12_SAFEBAG *bag, const char *pass, int passlen, EVP_PKEY **pkey, | ||
| 226 | STACK_OF(X509) *ocerts) | ||
| 227 | { | ||
| 228 | PKCS8_PRIV_KEY_INFO *p8; | ||
| 229 | X509 *x509; | ||
| 230 | ASN1_TYPE *attrib; | ||
| 231 | ASN1_BMPSTRING *fname = NULL; | ||
| 232 | ASN1_OCTET_STRING *lkid = NULL; | ||
| 233 | |||
| 234 | if ((attrib = PKCS12_get_attr (bag, NID_friendlyName))) | ||
| 235 | fname = attrib->value.bmpstring; | ||
| 236 | |||
| 237 | if ((attrib = PKCS12_get_attr (bag, NID_localKeyID))) | ||
| 238 | lkid = attrib->value.octet_string; | ||
| 239 | |||
| 240 | switch (M_PKCS12_bag_type(bag)) { | ||
| 241 | case NID_keyBag: | ||
| 242 | if (!pkey || *pkey) | ||
| 243 | return 1; | ||
| 244 | if (!(*pkey = EVP_PKCS82PKEY(bag->value.keybag))) | ||
| 245 | return 0; | ||
| 246 | break; | ||
| 247 | |||
| 248 | case NID_pkcs8ShroudedKeyBag: | ||
| 249 | if (!pkey || *pkey) | ||
| 250 | return 1; | ||
| 251 | if (!(p8 = PKCS12_decrypt_skey(bag, pass, passlen))) | ||
| 252 | return 0; | ||
| 253 | *pkey = EVP_PKCS82PKEY(p8); | ||
| 254 | PKCS8_PRIV_KEY_INFO_free(p8); | ||
| 255 | if (!(*pkey)) | ||
| 256 | return 0; | ||
| 257 | break; | ||
| 258 | |||
| 259 | case NID_certBag: | ||
| 260 | if (M_PKCS12_cert_bag_type(bag) != NID_x509Certificate ) | ||
| 261 | return 1; | ||
| 262 | if (!(x509 = PKCS12_certbag2x509(bag))) | ||
| 263 | return 0; | ||
| 264 | if (lkid && !X509_keyid_set1(x509, lkid->data, lkid->length)) { | ||
| 265 | X509_free(x509); | ||
| 266 | return 0; | ||
| 267 | } | ||
| 268 | if (fname) { | ||
| 269 | int len, r; | ||
| 270 | unsigned char *data; | ||
| 271 | len = ASN1_STRING_to_UTF8(&data, fname); | ||
| 272 | if (len >= 0) { | ||
| 273 | r = X509_alias_set1(x509, data, len); | ||
| 274 | free(data); | ||
| 275 | if (!r) { | ||
| 276 | X509_free(x509); | ||
| 277 | return 0; | ||
| 278 | } | ||
| 279 | } | ||
| 280 | } | ||
| 281 | |||
| 282 | if (!sk_X509_push(ocerts, x509)) { | ||
| 283 | X509_free(x509); | ||
| 284 | return 0; | ||
| 285 | } | ||
| 286 | |||
| 287 | break; | ||
| 288 | |||
| 289 | case NID_safeContentsBag: | ||
| 290 | return parse_bags(bag->value.safes, pass, passlen, | ||
| 291 | pkey, ocerts); | ||
| 292 | break; | ||
| 293 | |||
| 294 | default: | ||
| 295 | return 1; | ||
| 296 | break; | ||
| 297 | } | ||
| 298 | return 1; | ||
| 299 | } | ||
diff --git a/src/lib/libcrypto/pkcs12/p12_mutl.c b/src/lib/libcrypto/pkcs12/p12_mutl.c deleted file mode 100644 index 00acf1f210..0000000000 --- a/src/lib/libcrypto/pkcs12/p12_mutl.c +++ /dev/null | |||
| @@ -1,210 +0,0 @@ | |||
| 1 | /* $OpenBSD: p12_mutl.c,v 1.20 2015/07/29 14:58:34 jsing Exp $ */ | ||
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <stdlib.h> | ||
| 61 | #include <string.h> | ||
| 62 | |||
| 63 | #include <openssl/opensslconf.h> | ||
| 64 | |||
| 65 | #ifndef OPENSSL_NO_HMAC | ||
| 66 | |||
| 67 | #include <openssl/err.h> | ||
| 68 | #include <openssl/hmac.h> | ||
| 69 | #include <openssl/pkcs12.h> | ||
| 70 | |||
| 71 | /* Generate a MAC */ | ||
| 72 | int | ||
| 73 | PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen, | ||
| 74 | unsigned char *mac, unsigned int *maclen) | ||
| 75 | { | ||
| 76 | const EVP_MD *md_type; | ||
| 77 | HMAC_CTX hmac; | ||
| 78 | unsigned char key[EVP_MAX_MD_SIZE], *salt; | ||
| 79 | int saltlen, iter; | ||
| 80 | int md_size; | ||
| 81 | |||
| 82 | if (!PKCS7_type_is_data(p12->authsafes)) { | ||
| 83 | PKCS12err(PKCS12_F_PKCS12_GEN_MAC, | ||
| 84 | PKCS12_R_CONTENT_TYPE_NOT_DATA); | ||
| 85 | return 0; | ||
| 86 | } | ||
| 87 | |||
| 88 | salt = p12->mac->salt->data; | ||
| 89 | saltlen = p12->mac->salt->length; | ||
| 90 | if (!p12->mac->iter) | ||
| 91 | iter = 1; | ||
| 92 | else | ||
| 93 | iter = ASN1_INTEGER_get(p12->mac->iter); | ||
| 94 | if (!(md_type = EVP_get_digestbyobj( | ||
| 95 | p12->mac->dinfo->algor->algorithm))) { | ||
| 96 | PKCS12err(PKCS12_F_PKCS12_GEN_MAC, | ||
| 97 | PKCS12_R_UNKNOWN_DIGEST_ALGORITHM); | ||
| 98 | return 0; | ||
| 99 | } | ||
| 100 | md_size = EVP_MD_size(md_type); | ||
| 101 | if (md_size < 0) | ||
| 102 | return 0; | ||
| 103 | if (!PKCS12_key_gen(pass, passlen, salt, saltlen, PKCS12_MAC_ID, iter, | ||
| 104 | md_size, key, md_type)) { | ||
| 105 | PKCS12err(PKCS12_F_PKCS12_GEN_MAC, PKCS12_R_KEY_GEN_ERROR); | ||
| 106 | return 0; | ||
| 107 | } | ||
| 108 | HMAC_CTX_init(&hmac); | ||
| 109 | if (!HMAC_Init_ex(&hmac, key, md_size, md_type, NULL) || | ||
| 110 | !HMAC_Update(&hmac, p12->authsafes->d.data->data, | ||
| 111 | p12->authsafes->d.data->length) || | ||
| 112 | !HMAC_Final(&hmac, mac, maclen)) { | ||
| 113 | HMAC_CTX_cleanup(&hmac); | ||
| 114 | return 0; | ||
| 115 | } | ||
| 116 | HMAC_CTX_cleanup(&hmac); | ||
| 117 | return 1; | ||
| 118 | } | ||
| 119 | |||
| 120 | /* Verify the mac */ | ||
| 121 | int | ||
| 122 | PKCS12_verify_mac(PKCS12 *p12, const char *pass, int passlen) | ||
| 123 | { | ||
| 124 | unsigned char mac[EVP_MAX_MD_SIZE]; | ||
| 125 | unsigned int maclen; | ||
| 126 | |||
| 127 | if (p12->mac == NULL) { | ||
| 128 | PKCS12err(PKCS12_F_PKCS12_VERIFY_MAC, PKCS12_R_MAC_ABSENT); | ||
| 129 | return 0; | ||
| 130 | } | ||
| 131 | if (!PKCS12_gen_mac(p12, pass, passlen, mac, &maclen)) { | ||
| 132 | PKCS12err(PKCS12_F_PKCS12_VERIFY_MAC, | ||
| 133 | PKCS12_R_MAC_GENERATION_ERROR); | ||
| 134 | return 0; | ||
| 135 | } | ||
| 136 | if ((maclen != (unsigned int)p12->mac->dinfo->digest->length) || | ||
| 137 | memcmp(mac, p12->mac->dinfo->digest->data, maclen)) | ||
| 138 | return 0; | ||
| 139 | return 1; | ||
| 140 | } | ||
| 141 | |||
| 142 | /* Set a mac */ | ||
| 143 | |||
| 144 | int | ||
| 145 | PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen, unsigned char *salt, | ||
| 146 | int saltlen, int iter, const EVP_MD *md_type) | ||
| 147 | { | ||
| 148 | unsigned char mac[EVP_MAX_MD_SIZE]; | ||
| 149 | unsigned int maclen; | ||
| 150 | |||
| 151 | if (!md_type) | ||
| 152 | md_type = EVP_sha1(); | ||
| 153 | if (PKCS12_setup_mac(p12, iter, salt, saltlen, md_type) == | ||
| 154 | PKCS12_ERROR) { | ||
| 155 | PKCS12err(PKCS12_F_PKCS12_SET_MAC, PKCS12_R_MAC_SETUP_ERROR); | ||
| 156 | return 0; | ||
| 157 | } | ||
| 158 | if (!PKCS12_gen_mac(p12, pass, passlen, mac, &maclen)) { | ||
| 159 | PKCS12err(PKCS12_F_PKCS12_SET_MAC, | ||
| 160 | PKCS12_R_MAC_GENERATION_ERROR); | ||
| 161 | return 0; | ||
| 162 | } | ||
| 163 | if (!(ASN1_STRING_set(p12->mac->dinfo->digest, mac, maclen))) { | ||
| 164 | PKCS12err(PKCS12_F_PKCS12_SET_MAC, | ||
| 165 | PKCS12_R_MAC_STRING_SET_ERROR); | ||
| 166 | return 0; | ||
| 167 | } | ||
| 168 | return 1; | ||
| 169 | } | ||
| 170 | |||
| 171 | /* Set up a mac structure */ | ||
| 172 | int | ||
| 173 | PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt, int saltlen, | ||
| 174 | const EVP_MD *md_type) | ||
| 175 | { | ||
| 176 | if (!(p12->mac = PKCS12_MAC_DATA_new())) | ||
| 177 | return PKCS12_ERROR; | ||
| 178 | if (iter > 1) { | ||
| 179 | if (!(p12->mac->iter = M_ASN1_INTEGER_new())) { | ||
| 180 | PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, | ||
| 181 | ERR_R_MALLOC_FAILURE); | ||
| 182 | return 0; | ||
| 183 | } | ||
| 184 | if (!ASN1_INTEGER_set(p12->mac->iter, iter)) { | ||
| 185 | PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, | ||
| 186 | ERR_R_MALLOC_FAILURE); | ||
| 187 | return 0; | ||
| 188 | } | ||
| 189 | } | ||
| 190 | if (!saltlen) | ||
| 191 | saltlen = PKCS12_SALT_LEN; | ||
| 192 | if (!(p12->mac->salt->data = malloc(saltlen))) { | ||
| 193 | PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE); | ||
| 194 | return 0; | ||
| 195 | } | ||
| 196 | p12->mac->salt->length = saltlen; | ||
| 197 | if (!salt) | ||
| 198 | arc4random_buf(p12->mac->salt->data, saltlen); | ||
| 199 | else | ||
| 200 | memcpy (p12->mac->salt->data, salt, saltlen); | ||
| 201 | p12->mac->dinfo->algor->algorithm = OBJ_nid2obj(EVP_MD_type(md_type)); | ||
| 202 | if (!(p12->mac->dinfo->algor->parameter = ASN1_TYPE_new())) { | ||
| 203 | PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE); | ||
| 204 | return 0; | ||
| 205 | } | ||
| 206 | p12->mac->dinfo->algor->parameter->type = V_ASN1_NULL; | ||
| 207 | |||
| 208 | return 1; | ||
| 209 | } | ||
| 210 | #endif | ||
diff --git a/src/lib/libcrypto/pkcs12/p12_npas.c b/src/lib/libcrypto/pkcs12/p12_npas.c deleted file mode 100644 index b9dea51b85..0000000000 --- a/src/lib/libcrypto/pkcs12/p12_npas.c +++ /dev/null | |||
| @@ -1,244 +0,0 @@ | |||
| 1 | /* $OpenBSD: p12_npas.c,v 1.10 2015/02/14 14:18:58 miod Exp $ */ | ||
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <stdlib.h> | ||
| 61 | #include <string.h> | ||
| 62 | #include <openssl/pem.h> | ||
| 63 | #include <openssl/err.h> | ||
| 64 | #include <openssl/pkcs12.h> | ||
| 65 | |||
| 66 | /* PKCS#12 password change routine */ | ||
| 67 | |||
| 68 | static int newpass_p12(PKCS12 *p12, char *oldpass, char *newpass); | ||
| 69 | static int newpass_bags(STACK_OF(PKCS12_SAFEBAG) *bags, char *oldpass, | ||
| 70 | char *newpass); | ||
| 71 | static int newpass_bag(PKCS12_SAFEBAG *bag, char *oldpass, char *newpass); | ||
| 72 | static int alg_get(X509_ALGOR *alg, int *pnid, int *piter, int *psaltlen); | ||
| 73 | |||
| 74 | /* | ||
| 75 | * Change the password on a PKCS#12 structure. | ||
| 76 | */ | ||
| 77 | |||
| 78 | int | ||
| 79 | PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass) | ||
| 80 | { | ||
| 81 | /* Check for NULL PKCS12 structure */ | ||
| 82 | |||
| 83 | if (!p12) { | ||
| 84 | PKCS12err(PKCS12_F_PKCS12_NEWPASS, | ||
| 85 | PKCS12_R_INVALID_NULL_PKCS12_POINTER); | ||
| 86 | return 0; | ||
| 87 | } | ||
| 88 | |||
| 89 | /* Check the mac */ | ||
| 90 | |||
| 91 | if (!PKCS12_verify_mac(p12, oldpass, -1)) { | ||
| 92 | PKCS12err(PKCS12_F_PKCS12_NEWPASS, PKCS12_R_MAC_VERIFY_FAILURE); | ||
| 93 | return 0; | ||
| 94 | } | ||
| 95 | |||
| 96 | if (!newpass_p12(p12, oldpass, newpass)) { | ||
| 97 | PKCS12err(PKCS12_F_PKCS12_NEWPASS, PKCS12_R_PARSE_ERROR); | ||
| 98 | return 0; | ||
| 99 | } | ||
| 100 | |||
| 101 | return 1; | ||
| 102 | } | ||
| 103 | |||
| 104 | /* Parse the outer PKCS#12 structure */ | ||
| 105 | |||
| 106 | static int | ||
| 107 | newpass_p12(PKCS12 *p12, char *oldpass, char *newpass) | ||
| 108 | { | ||
| 109 | STACK_OF(PKCS7) *asafes, *newsafes; | ||
| 110 | STACK_OF(PKCS12_SAFEBAG) *bags; | ||
| 111 | int i, bagnid, pbe_nid = 0, pbe_iter = 0, pbe_saltlen = 0; | ||
| 112 | PKCS7 *p7, *p7new; | ||
| 113 | ASN1_OCTET_STRING *p12_data_tmp = NULL, *macnew = NULL; | ||
| 114 | unsigned char mac[EVP_MAX_MD_SIZE]; | ||
| 115 | unsigned int maclen; | ||
| 116 | |||
| 117 | if (!(asafes = PKCS12_unpack_authsafes(p12))) | ||
| 118 | return 0; | ||
| 119 | if (!(newsafes = sk_PKCS7_new_null())) | ||
| 120 | return 0; | ||
| 121 | for (i = 0; i < sk_PKCS7_num(asafes); i++) { | ||
| 122 | p7 = sk_PKCS7_value(asafes, i); | ||
| 123 | bagnid = OBJ_obj2nid(p7->type); | ||
| 124 | if (bagnid == NID_pkcs7_data) { | ||
| 125 | bags = PKCS12_unpack_p7data(p7); | ||
| 126 | } else if (bagnid == NID_pkcs7_encrypted) { | ||
| 127 | bags = PKCS12_unpack_p7encdata(p7, oldpass, -1); | ||
| 128 | if (!alg_get(p7->d.encrypted->enc_data->algorithm, | ||
| 129 | &pbe_nid, &pbe_iter, &pbe_saltlen)) { | ||
| 130 | sk_PKCS12_SAFEBAG_pop_free(bags, | ||
| 131 | PKCS12_SAFEBAG_free); | ||
| 132 | bags = NULL; | ||
| 133 | } | ||
| 134 | } else | ||
| 135 | continue; | ||
| 136 | if (bags == NULL) | ||
| 137 | goto err; | ||
| 138 | if (!newpass_bags(bags, oldpass, newpass)) { | ||
| 139 | sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free); | ||
| 140 | goto err; | ||
| 141 | } | ||
| 142 | /* Repack bag in same form with new password */ | ||
| 143 | if (bagnid == NID_pkcs7_data) | ||
| 144 | p7new = PKCS12_pack_p7data(bags); | ||
| 145 | else | ||
| 146 | p7new = PKCS12_pack_p7encdata(pbe_nid, newpass, -1, | ||
| 147 | NULL, pbe_saltlen, pbe_iter, bags); | ||
| 148 | sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free); | ||
| 149 | if (p7new == NULL) | ||
| 150 | goto err; | ||
| 151 | if (sk_PKCS7_push(newsafes, p7new) == 0) | ||
| 152 | goto err; | ||
| 153 | } | ||
| 154 | sk_PKCS7_pop_free(asafes, PKCS7_free); | ||
| 155 | |||
| 156 | /* Repack safe: save old safe in case of error */ | ||
| 157 | |||
| 158 | p12_data_tmp = p12->authsafes->d.data; | ||
| 159 | if (!(p12->authsafes->d.data = ASN1_OCTET_STRING_new())) { | ||
| 160 | p12->authsafes->d.data = p12_data_tmp; | ||
| 161 | goto err; | ||
| 162 | } | ||
| 163 | if (!PKCS12_pack_authsafes(p12, newsafes)) | ||
| 164 | goto saferr; | ||
| 165 | |||
| 166 | if (!PKCS12_gen_mac(p12, newpass, -1, mac, &maclen)) | ||
| 167 | goto saferr; | ||
| 168 | if (!(macnew = ASN1_OCTET_STRING_new())) | ||
| 169 | goto saferr; | ||
| 170 | if (!ASN1_OCTET_STRING_set(macnew, mac, maclen)) | ||
| 171 | goto saferr; | ||
| 172 | ASN1_OCTET_STRING_free(p12->mac->dinfo->digest); | ||
| 173 | p12->mac->dinfo->digest = macnew; | ||
| 174 | ASN1_OCTET_STRING_free(p12_data_tmp); | ||
| 175 | |||
| 176 | return 1; | ||
| 177 | |||
| 178 | saferr: | ||
| 179 | /* Restore old safe */ | ||
| 180 | ASN1_OCTET_STRING_free(p12->authsafes->d.data); | ||
| 181 | ASN1_OCTET_STRING_free(macnew); | ||
| 182 | p12->authsafes->d.data = p12_data_tmp; | ||
| 183 | return 0; | ||
| 184 | |||
| 185 | err: | ||
| 186 | sk_PKCS7_pop_free(asafes, PKCS7_free); | ||
| 187 | sk_PKCS7_pop_free(newsafes, PKCS7_free); | ||
| 188 | return 0; | ||
| 189 | } | ||
| 190 | |||
| 191 | |||
| 192 | static int | ||
| 193 | newpass_bags(STACK_OF(PKCS12_SAFEBAG) *bags, char *oldpass, char *newpass) | ||
| 194 | { | ||
| 195 | int i; | ||
| 196 | |||
| 197 | for (i = 0; i < sk_PKCS12_SAFEBAG_num(bags); i++) { | ||
| 198 | if (!newpass_bag(sk_PKCS12_SAFEBAG_value(bags, i), | ||
| 199 | oldpass, newpass)) | ||
| 200 | return 0; | ||
| 201 | } | ||
| 202 | return 1; | ||
| 203 | } | ||
| 204 | |||
| 205 | /* Change password of safebag: only needs handle shrouded keybags */ | ||
| 206 | |||
| 207 | static int | ||
| 208 | newpass_bag(PKCS12_SAFEBAG *bag, char *oldpass, char *newpass) | ||
| 209 | { | ||
| 210 | PKCS8_PRIV_KEY_INFO *p8; | ||
| 211 | X509_SIG *p8new; | ||
| 212 | int p8_nid, p8_saltlen, p8_iter; | ||
| 213 | |||
| 214 | if (M_PKCS12_bag_type(bag) != NID_pkcs8ShroudedKeyBag) | ||
| 215 | return 1; | ||
| 216 | |||
| 217 | if (!(p8 = PKCS8_decrypt(bag->value.shkeybag, oldpass, -1))) | ||
| 218 | return 0; | ||
| 219 | if (!alg_get(bag->value.shkeybag->algor, &p8_nid, &p8_iter, | ||
| 220 | &p8_saltlen)) | ||
| 221 | return 0; | ||
| 222 | if (!(p8new = PKCS8_encrypt(p8_nid, NULL, newpass, -1, NULL, p8_saltlen, | ||
| 223 | p8_iter, p8))) return 0; | ||
| 224 | X509_SIG_free(bag->value.shkeybag); | ||
| 225 | bag->value.shkeybag = p8new; | ||
| 226 | return 1; | ||
| 227 | } | ||
| 228 | |||
| 229 | static int | ||
| 230 | alg_get(X509_ALGOR *alg, int *pnid, int *piter, int *psaltlen) | ||
| 231 | { | ||
| 232 | PBEPARAM *pbe; | ||
| 233 | const unsigned char *p; | ||
| 234 | |||
| 235 | p = alg->parameter->value.sequence->data; | ||
| 236 | pbe = d2i_PBEPARAM(NULL, &p, alg->parameter->value.sequence->length); | ||
| 237 | if (!pbe) | ||
| 238 | return 0; | ||
| 239 | *pnid = OBJ_obj2nid(alg->algorithm); | ||
| 240 | *piter = ASN1_INTEGER_get(pbe->iter); | ||
| 241 | *psaltlen = pbe->salt->length; | ||
| 242 | PBEPARAM_free(pbe); | ||
| 243 | return 1; | ||
| 244 | } | ||
diff --git a/src/lib/libcrypto/pkcs12/p12_p8d.c b/src/lib/libcrypto/pkcs12/p12_p8d.c deleted file mode 100644 index 5d3339e2f2..0000000000 --- a/src/lib/libcrypto/pkcs12/p12_p8d.c +++ /dev/null | |||
| @@ -1,68 +0,0 @@ | |||
| 1 | /* $OpenBSD: p12_p8d.c,v 1.5 2014/07/11 08:44:49 jsing Exp $ */ | ||
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | * project 2001. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2001 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | |||
| 61 | #include <openssl/pkcs12.h> | ||
| 62 | |||
| 63 | PKCS8_PRIV_KEY_INFO * | ||
| 64 | PKCS8_decrypt(X509_SIG *p8, const char *pass, int passlen) | ||
| 65 | { | ||
| 66 | return PKCS12_item_decrypt_d2i(p8->algor, | ||
| 67 | ASN1_ITEM_rptr(PKCS8_PRIV_KEY_INFO), pass, passlen, p8->digest, 1); | ||
| 68 | } | ||
diff --git a/src/lib/libcrypto/pkcs12/p12_p8e.c b/src/lib/libcrypto/pkcs12/p12_p8e.c deleted file mode 100644 index 24ed7f69ed..0000000000 --- a/src/lib/libcrypto/pkcs12/p12_p8e.c +++ /dev/null | |||
| @@ -1,100 +0,0 @@ | |||
| 1 | /* $OpenBSD: p12_p8e.c,v 1.5 2014/07/11 08:44:49 jsing Exp $ */ | ||
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | * project 2001. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2001 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | |||
| 61 | #include <openssl/err.h> | ||
| 62 | #include <openssl/pkcs12.h> | ||
| 63 | |||
| 64 | X509_SIG * | ||
| 65 | PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher, const char *pass, | ||
| 66 | int passlen, unsigned char *salt, int saltlen, int iter, | ||
| 67 | PKCS8_PRIV_KEY_INFO *p8inf) | ||
| 68 | { | ||
| 69 | X509_SIG *p8 = NULL; | ||
| 70 | X509_ALGOR *pbe; | ||
| 71 | |||
| 72 | if (!(p8 = X509_SIG_new())) { | ||
| 73 | PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_MALLOC_FAILURE); | ||
| 74 | goto err; | ||
| 75 | } | ||
| 76 | |||
| 77 | if (pbe_nid == -1) | ||
| 78 | pbe = PKCS5_pbe2_set(cipher, iter, salt, saltlen); | ||
| 79 | else | ||
| 80 | pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen); | ||
| 81 | if (!pbe) { | ||
| 82 | PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_ASN1_LIB); | ||
| 83 | goto err; | ||
| 84 | } | ||
| 85 | X509_ALGOR_free(p8->algor); | ||
| 86 | p8->algor = pbe; | ||
| 87 | M_ASN1_OCTET_STRING_free(p8->digest); | ||
| 88 | p8->digest = PKCS12_item_i2d_encrypt(pbe, | ||
| 89 | ASN1_ITEM_rptr(PKCS8_PRIV_KEY_INFO), pass, passlen, p8inf, 1); | ||
| 90 | if (!p8->digest) { | ||
| 91 | PKCS12err(PKCS12_F_PKCS8_ENCRYPT, PKCS12_R_ENCRYPT_ERROR); | ||
| 92 | goto err; | ||
| 93 | } | ||
| 94 | |||
| 95 | return p8; | ||
| 96 | |||
| 97 | err: | ||
| 98 | X509_SIG_free(p8); | ||
| 99 | return NULL; | ||
| 100 | } | ||
diff --git a/src/lib/libcrypto/pkcs12/p12_utl.c b/src/lib/libcrypto/pkcs12/p12_utl.c deleted file mode 100644 index b60d4d020c..0000000000 --- a/src/lib/libcrypto/pkcs12/p12_utl.c +++ /dev/null | |||
| @@ -1,168 +0,0 @@ | |||
| 1 | /* $OpenBSD: p12_utl.c,v 1.12 2014/07/11 08:44:49 jsing Exp $ */ | ||
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <string.h> | ||
| 61 | |||
| 62 | #include <openssl/pkcs12.h> | ||
| 63 | |||
| 64 | /* Cheap and nasty Unicode stuff */ | ||
| 65 | |||
| 66 | unsigned char * | ||
| 67 | OPENSSL_asc2uni(const char *asc, int asclen, unsigned char **uni, int *unilen) | ||
| 68 | { | ||
| 69 | int ulen, i; | ||
| 70 | unsigned char *unitmp; | ||
| 71 | |||
| 72 | if (asclen == -1) | ||
| 73 | asclen = strlen(asc); | ||
| 74 | ulen = asclen * 2 + 2; | ||
| 75 | if (!(unitmp = malloc(ulen))) | ||
| 76 | return NULL; | ||
| 77 | for (i = 0; i < ulen - 2; i += 2) { | ||
| 78 | unitmp[i] = 0; | ||
| 79 | unitmp[i + 1] = asc[i >> 1]; | ||
| 80 | } | ||
| 81 | /* Make result double null terminated */ | ||
| 82 | unitmp[ulen - 2] = 0; | ||
| 83 | unitmp[ulen - 1] = 0; | ||
| 84 | if (unilen) | ||
| 85 | *unilen = ulen; | ||
| 86 | if (uni) | ||
| 87 | *uni = unitmp; | ||
| 88 | return unitmp; | ||
| 89 | } | ||
| 90 | |||
| 91 | char * | ||
| 92 | OPENSSL_uni2asc(unsigned char *uni, int unilen) | ||
| 93 | { | ||
| 94 | int asclen, i; | ||
| 95 | char *asctmp; | ||
| 96 | |||
| 97 | asclen = unilen / 2; | ||
| 98 | /* If no terminating zero allow for one */ | ||
| 99 | if (!unilen || uni[unilen - 1]) | ||
| 100 | asclen++; | ||
| 101 | uni++; | ||
| 102 | if (!(asctmp = malloc(asclen))) | ||
| 103 | return NULL; | ||
| 104 | for (i = 0; i < unilen; i += 2) | ||
| 105 | asctmp[i >> 1] = uni[i]; | ||
| 106 | asctmp[asclen - 1] = 0; | ||
| 107 | return asctmp; | ||
| 108 | } | ||
| 109 | |||
| 110 | int | ||
| 111 | i2d_PKCS12_bio(BIO *bp, PKCS12 *p12) | ||
| 112 | { | ||
| 113 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(PKCS12), bp, p12); | ||
| 114 | } | ||
| 115 | |||
| 116 | int | ||
| 117 | i2d_PKCS12_fp(FILE *fp, PKCS12 *p12) | ||
| 118 | { | ||
| 119 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(PKCS12), fp, p12); | ||
| 120 | } | ||
| 121 | |||
| 122 | PKCS12 * | ||
| 123 | d2i_PKCS12_bio(BIO *bp, PKCS12 **p12) | ||
| 124 | { | ||
| 125 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(PKCS12), bp, p12); | ||
| 126 | } | ||
| 127 | |||
| 128 | PKCS12 * | ||
| 129 | d2i_PKCS12_fp(FILE *fp, PKCS12 **p12) | ||
| 130 | { | ||
| 131 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(PKCS12), fp, p12); | ||
| 132 | } | ||
| 133 | |||
| 134 | PKCS12_SAFEBAG * | ||
| 135 | PKCS12_x5092certbag(X509 *x509) | ||
| 136 | { | ||
| 137 | return PKCS12_item_pack_safebag(x509, ASN1_ITEM_rptr(X509), | ||
| 138 | NID_x509Certificate, NID_certBag); | ||
| 139 | } | ||
| 140 | |||
| 141 | PKCS12_SAFEBAG * | ||
| 142 | PKCS12_x509crl2certbag(X509_CRL *crl) | ||
| 143 | { | ||
| 144 | return PKCS12_item_pack_safebag(crl, ASN1_ITEM_rptr(X509_CRL), | ||
| 145 | NID_x509Crl, NID_crlBag); | ||
| 146 | } | ||
| 147 | |||
| 148 | X509 * | ||
| 149 | PKCS12_certbag2x509(PKCS12_SAFEBAG *bag) | ||
| 150 | { | ||
| 151 | if (M_PKCS12_bag_type(bag) != NID_certBag) | ||
| 152 | return NULL; | ||
| 153 | if (M_PKCS12_cert_bag_type(bag) != NID_x509Certificate) | ||
| 154 | return NULL; | ||
| 155 | return ASN1_item_unpack(bag->value.bag->value.octet, | ||
| 156 | ASN1_ITEM_rptr(X509)); | ||
| 157 | } | ||
| 158 | |||
| 159 | X509_CRL * | ||
| 160 | PKCS12_certbag2x509crl(PKCS12_SAFEBAG *bag) | ||
| 161 | { | ||
| 162 | if (M_PKCS12_bag_type(bag) != NID_crlBag) | ||
| 163 | return NULL; | ||
| 164 | if (M_PKCS12_cert_bag_type(bag) != NID_x509Crl) | ||
| 165 | return NULL; | ||
| 166 | return ASN1_item_unpack(bag->value.bag->value.octet, | ||
| 167 | ASN1_ITEM_rptr(X509_CRL)); | ||
| 168 | } | ||
diff --git a/src/lib/libcrypto/pkcs12/pk12err.c b/src/lib/libcrypto/pkcs12/pk12err.c deleted file mode 100644 index 0464a8303c..0000000000 --- a/src/lib/libcrypto/pkcs12/pk12err.c +++ /dev/null | |||
| @@ -1,144 +0,0 @@ | |||
| 1 | /* $OpenBSD: pk12err.c,v 1.10 2014/07/10 22:45:57 jsing Exp $ */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1999-2006 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * openssl-core@OpenSSL.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | * This product includes cryptographic software written by Eric Young | ||
| 51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 52 | * Hudson (tjh@cryptsoft.com). | ||
| 53 | * | ||
| 54 | */ | ||
| 55 | |||
| 56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
| 57 | * made to it will be overwritten when the script next updates this file, | ||
| 58 | * only reason strings will be preserved. | ||
| 59 | */ | ||
| 60 | |||
| 61 | #include <stdio.h> | ||
| 62 | |||
| 63 | #include <openssl/opensslconf.h> | ||
| 64 | |||
| 65 | #include <openssl/err.h> | ||
| 66 | #include <openssl/pkcs12.h> | ||
| 67 | |||
| 68 | /* BEGIN ERROR CODES */ | ||
| 69 | #ifndef OPENSSL_NO_ERR | ||
| 70 | |||
| 71 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_PKCS12,func,0) | ||
| 72 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_PKCS12,0,reason) | ||
| 73 | |||
| 74 | static ERR_STRING_DATA PKCS12_str_functs[]= { | ||
| 75 | {ERR_FUNC(PKCS12_F_PARSE_BAG), "PARSE_BAG"}, | ||
| 76 | {ERR_FUNC(PKCS12_F_PARSE_BAGS), "PARSE_BAGS"}, | ||
| 77 | {ERR_FUNC(PKCS12_F_PKCS12_ADD_FRIENDLYNAME), "PKCS12_ADD_FRIENDLYNAME"}, | ||
| 78 | {ERR_FUNC(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_ASC), "PKCS12_add_friendlyname_asc"}, | ||
| 79 | {ERR_FUNC(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI), "PKCS12_add_friendlyname_uni"}, | ||
| 80 | {ERR_FUNC(PKCS12_F_PKCS12_ADD_LOCALKEYID), "PKCS12_add_localkeyid"}, | ||
| 81 | {ERR_FUNC(PKCS12_F_PKCS12_CREATE), "PKCS12_create"}, | ||
| 82 | {ERR_FUNC(PKCS12_F_PKCS12_GEN_MAC), "PKCS12_gen_mac"}, | ||
| 83 | {ERR_FUNC(PKCS12_F_PKCS12_INIT), "PKCS12_init"}, | ||
| 84 | {ERR_FUNC(PKCS12_F_PKCS12_ITEM_DECRYPT_D2I), "PKCS12_item_decrypt_d2i"}, | ||
| 85 | {ERR_FUNC(PKCS12_F_PKCS12_ITEM_I2D_ENCRYPT), "PKCS12_item_i2d_encrypt"}, | ||
| 86 | {ERR_FUNC(PKCS12_F_PKCS12_ITEM_PACK_SAFEBAG), "PKCS12_item_pack_safebag"}, | ||
| 87 | {ERR_FUNC(PKCS12_F_PKCS12_KEY_GEN_ASC), "PKCS12_key_gen_asc"}, | ||
| 88 | {ERR_FUNC(PKCS12_F_PKCS12_KEY_GEN_UNI), "PKCS12_key_gen_uni"}, | ||
| 89 | {ERR_FUNC(PKCS12_F_PKCS12_MAKE_KEYBAG), "PKCS12_MAKE_KEYBAG"}, | ||
| 90 | {ERR_FUNC(PKCS12_F_PKCS12_MAKE_SHKEYBAG), "PKCS12_MAKE_SHKEYBAG"}, | ||
| 91 | {ERR_FUNC(PKCS12_F_PKCS12_NEWPASS), "PKCS12_newpass"}, | ||
| 92 | {ERR_FUNC(PKCS12_F_PKCS12_PACK_P7DATA), "PKCS12_pack_p7data"}, | ||
| 93 | {ERR_FUNC(PKCS12_F_PKCS12_PACK_P7ENCDATA), "PKCS12_pack_p7encdata"}, | ||
| 94 | {ERR_FUNC(PKCS12_F_PKCS12_PARSE), "PKCS12_parse"}, | ||
| 95 | {ERR_FUNC(PKCS12_F_PKCS12_PBE_CRYPT), "PKCS12_pbe_crypt"}, | ||
| 96 | {ERR_FUNC(PKCS12_F_PKCS12_PBE_KEYIVGEN), "PKCS12_PBE_keyivgen"}, | ||
| 97 | {ERR_FUNC(PKCS12_F_PKCS12_SETUP_MAC), "PKCS12_setup_mac"}, | ||
| 98 | {ERR_FUNC(PKCS12_F_PKCS12_SET_MAC), "PKCS12_set_mac"}, | ||
| 99 | {ERR_FUNC(PKCS12_F_PKCS12_UNPACK_AUTHSAFES), "PKCS12_unpack_authsafes"}, | ||
| 100 | {ERR_FUNC(PKCS12_F_PKCS12_UNPACK_P7DATA), "PKCS12_unpack_p7data"}, | ||
| 101 | {ERR_FUNC(PKCS12_F_PKCS12_VERIFY_MAC), "PKCS12_verify_mac"}, | ||
| 102 | {ERR_FUNC(PKCS12_F_PKCS8_ADD_KEYUSAGE), "PKCS8_add_keyusage"}, | ||
| 103 | {ERR_FUNC(PKCS12_F_PKCS8_ENCRYPT), "PKCS8_encrypt"}, | ||
| 104 | {0, NULL} | ||
| 105 | }; | ||
| 106 | |||
| 107 | static ERR_STRING_DATA PKCS12_str_reasons[]= { | ||
| 108 | {ERR_REASON(PKCS12_R_CANT_PACK_STRUCTURE), "cant pack structure"}, | ||
| 109 | {ERR_REASON(PKCS12_R_CONTENT_TYPE_NOT_DATA), "content type not data"}, | ||
| 110 | {ERR_REASON(PKCS12_R_DECODE_ERROR) , "decode error"}, | ||
| 111 | {ERR_REASON(PKCS12_R_ENCODE_ERROR) , "encode error"}, | ||
| 112 | {ERR_REASON(PKCS12_R_ENCRYPT_ERROR) , "encrypt error"}, | ||
| 113 | {ERR_REASON(PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE), "error setting encrypted data type"}, | ||
| 114 | {ERR_REASON(PKCS12_R_INVALID_NULL_ARGUMENT), "invalid null argument"}, | ||
| 115 | {ERR_REASON(PKCS12_R_INVALID_NULL_PKCS12_POINTER), "invalid null pkcs12 pointer"}, | ||
| 116 | {ERR_REASON(PKCS12_R_IV_GEN_ERROR) , "iv gen error"}, | ||
| 117 | {ERR_REASON(PKCS12_R_KEY_GEN_ERROR) , "key gen error"}, | ||
| 118 | {ERR_REASON(PKCS12_R_MAC_ABSENT) , "mac absent"}, | ||
| 119 | {ERR_REASON(PKCS12_R_MAC_GENERATION_ERROR), "mac generation error"}, | ||
| 120 | {ERR_REASON(PKCS12_R_MAC_SETUP_ERROR) , "mac setup error"}, | ||
| 121 | {ERR_REASON(PKCS12_R_MAC_STRING_SET_ERROR), "mac string set error"}, | ||
| 122 | {ERR_REASON(PKCS12_R_MAC_VERIFY_ERROR) , "mac verify error"}, | ||
| 123 | {ERR_REASON(PKCS12_R_MAC_VERIFY_FAILURE) , "mac verify failure"}, | ||
| 124 | {ERR_REASON(PKCS12_R_PARSE_ERROR) , "parse error"}, | ||
| 125 | {ERR_REASON(PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR), "pkcs12 algor cipherinit error"}, | ||
| 126 | {ERR_REASON(PKCS12_R_PKCS12_CIPHERFINAL_ERROR), "pkcs12 cipherfinal error"}, | ||
| 127 | {ERR_REASON(PKCS12_R_PKCS12_PBE_CRYPT_ERROR), "pkcs12 pbe crypt error"}, | ||
| 128 | {ERR_REASON(PKCS12_R_UNKNOWN_DIGEST_ALGORITHM), "unknown digest algorithm"}, | ||
| 129 | {ERR_REASON(PKCS12_R_UNSUPPORTED_PKCS12_MODE), "unsupported pkcs12 mode"}, | ||
| 130 | {0, NULL} | ||
| 131 | }; | ||
| 132 | |||
| 133 | #endif | ||
| 134 | |||
| 135 | void | ||
| 136 | ERR_load_PKCS12_strings(void) | ||
| 137 | { | ||
| 138 | #ifndef OPENSSL_NO_ERR | ||
| 139 | if (ERR_func_error_string(PKCS12_str_functs[0].error) == NULL) { | ||
| 140 | ERR_load_strings(0, PKCS12_str_functs); | ||
| 141 | ERR_load_strings(0, PKCS12_str_reasons); | ||
| 142 | } | ||
| 143 | #endif | ||
| 144 | } | ||
diff --git a/src/lib/libcrypto/pkcs12/pkcs12.h b/src/lib/libcrypto/pkcs12/pkcs12.h deleted file mode 100644 index ead29fd717..0000000000 --- a/src/lib/libcrypto/pkcs12/pkcs12.h +++ /dev/null | |||
| @@ -1,331 +0,0 @@ | |||
| 1 | /* $OpenBSD: pkcs12.h,v 1.13 2014/07/08 09:27:21 jsing Exp $ */ | ||
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #ifndef HEADER_PKCS12_H | ||
| 60 | #define HEADER_PKCS12_H | ||
| 61 | |||
| 62 | #include <openssl/bio.h> | ||
| 63 | #include <openssl/x509.h> | ||
| 64 | |||
| 65 | #ifdef __cplusplus | ||
| 66 | extern "C" { | ||
| 67 | #endif | ||
| 68 | |||
| 69 | #define PKCS12_KEY_ID 1 | ||
| 70 | #define PKCS12_IV_ID 2 | ||
| 71 | #define PKCS12_MAC_ID 3 | ||
| 72 | |||
| 73 | /* Default iteration count */ | ||
| 74 | #ifndef PKCS12_DEFAULT_ITER | ||
| 75 | #define PKCS12_DEFAULT_ITER PKCS5_DEFAULT_ITER | ||
| 76 | #endif | ||
| 77 | |||
| 78 | #define PKCS12_MAC_KEY_LENGTH 20 | ||
| 79 | |||
| 80 | #define PKCS12_SALT_LEN 8 | ||
| 81 | |||
| 82 | /* Uncomment out next line for unicode password and names, otherwise ASCII */ | ||
| 83 | |||
| 84 | /*#define PBE_UNICODE*/ | ||
| 85 | |||
| 86 | #ifdef PBE_UNICODE | ||
| 87 | #define PKCS12_key_gen PKCS12_key_gen_uni | ||
| 88 | #define PKCS12_add_friendlyname PKCS12_add_friendlyname_uni | ||
| 89 | #else | ||
| 90 | #define PKCS12_key_gen PKCS12_key_gen_asc | ||
| 91 | #define PKCS12_add_friendlyname PKCS12_add_friendlyname_asc | ||
| 92 | #endif | ||
| 93 | |||
| 94 | /* MS key usage constants */ | ||
| 95 | |||
| 96 | #define KEY_EX 0x10 | ||
| 97 | #define KEY_SIG 0x80 | ||
| 98 | |||
| 99 | typedef struct { | ||
| 100 | X509_SIG *dinfo; | ||
| 101 | ASN1_OCTET_STRING *salt; | ||
| 102 | ASN1_INTEGER *iter; /* defaults to 1 */ | ||
| 103 | } PKCS12_MAC_DATA; | ||
| 104 | |||
| 105 | typedef struct { | ||
| 106 | ASN1_INTEGER *version; | ||
| 107 | PKCS12_MAC_DATA *mac; | ||
| 108 | PKCS7 *authsafes; | ||
| 109 | } PKCS12; | ||
| 110 | |||
| 111 | typedef struct { | ||
| 112 | ASN1_OBJECT *type; | ||
| 113 | union { | ||
| 114 | struct pkcs12_bag_st *bag; /* secret, crl and certbag */ | ||
| 115 | struct pkcs8_priv_key_info_st *keybag; /* keybag */ | ||
| 116 | X509_SIG *shkeybag; /* shrouded key bag */ | ||
| 117 | STACK_OF(PKCS12_SAFEBAG) *safes; | ||
| 118 | ASN1_TYPE *other; | ||
| 119 | } value; | ||
| 120 | STACK_OF(X509_ATTRIBUTE) *attrib; | ||
| 121 | } PKCS12_SAFEBAG; | ||
| 122 | |||
| 123 | DECLARE_STACK_OF(PKCS12_SAFEBAG) | ||
| 124 | DECLARE_ASN1_SET_OF(PKCS12_SAFEBAG) | ||
| 125 | DECLARE_PKCS12_STACK_OF(PKCS12_SAFEBAG) | ||
| 126 | |||
| 127 | typedef struct pkcs12_bag_st { | ||
| 128 | ASN1_OBJECT *type; | ||
| 129 | union { | ||
| 130 | ASN1_OCTET_STRING *x509cert; | ||
| 131 | ASN1_OCTET_STRING *x509crl; | ||
| 132 | ASN1_OCTET_STRING *octet; | ||
| 133 | ASN1_IA5STRING *sdsicert; | ||
| 134 | ASN1_TYPE *other; /* Secret or other bag */ | ||
| 135 | } value; | ||
| 136 | } PKCS12_BAGS; | ||
| 137 | |||
| 138 | #define PKCS12_ERROR 0 | ||
| 139 | #define PKCS12_OK 1 | ||
| 140 | |||
| 141 | /* Compatibility macros */ | ||
| 142 | |||
| 143 | #define M_PKCS12_x5092certbag PKCS12_x5092certbag | ||
| 144 | #define M_PKCS12_x509crl2certbag PKCS12_x509crl2certbag | ||
| 145 | |||
| 146 | #define M_PKCS12_certbag2x509 PKCS12_certbag2x509 | ||
| 147 | #define M_PKCS12_certbag2x509crl PKCS12_certbag2x509crl | ||
| 148 | |||
| 149 | #define M_PKCS12_unpack_p7data PKCS12_unpack_p7data | ||
| 150 | #define M_PKCS12_pack_authsafes PKCS12_pack_authsafes | ||
| 151 | #define M_PKCS12_unpack_authsafes PKCS12_unpack_authsafes | ||
| 152 | #define M_PKCS12_unpack_p7encdata PKCS12_unpack_p7encdata | ||
| 153 | |||
| 154 | #define M_PKCS12_decrypt_skey PKCS12_decrypt_skey | ||
| 155 | #define M_PKCS8_decrypt PKCS8_decrypt | ||
| 156 | |||
| 157 | #define M_PKCS12_bag_type(bg) OBJ_obj2nid((bg)->type) | ||
| 158 | #define M_PKCS12_cert_bag_type(bg) OBJ_obj2nid((bg)->value.bag->type) | ||
| 159 | #define M_PKCS12_crl_bag_type M_PKCS12_cert_bag_type | ||
| 160 | |||
| 161 | #define PKCS12_get_attr(bag, attr_nid) \ | ||
| 162 | PKCS12_get_attr_gen(bag->attrib, attr_nid) | ||
| 163 | |||
| 164 | #define PKCS8_get_attr(p8, attr_nid) \ | ||
| 165 | PKCS12_get_attr_gen(p8->attributes, attr_nid) | ||
| 166 | |||
| 167 | #define PKCS12_mac_present(p12) ((p12)->mac ? 1 : 0) | ||
| 168 | |||
| 169 | |||
| 170 | PKCS12_SAFEBAG *PKCS12_x5092certbag(X509 *x509); | ||
| 171 | PKCS12_SAFEBAG *PKCS12_x509crl2certbag(X509_CRL *crl); | ||
| 172 | X509 *PKCS12_certbag2x509(PKCS12_SAFEBAG *bag); | ||
| 173 | X509_CRL *PKCS12_certbag2x509crl(PKCS12_SAFEBAG *bag); | ||
| 174 | |||
| 175 | PKCS12_SAFEBAG *PKCS12_item_pack_safebag(void *obj, const ASN1_ITEM *it, | ||
| 176 | int nid1, int nid2); | ||
| 177 | PKCS12_SAFEBAG *PKCS12_MAKE_KEYBAG(PKCS8_PRIV_KEY_INFO *p8); | ||
| 178 | PKCS8_PRIV_KEY_INFO *PKCS8_decrypt(X509_SIG *p8, const char *pass, int passlen); | ||
| 179 | PKCS8_PRIV_KEY_INFO *PKCS12_decrypt_skey(PKCS12_SAFEBAG *bag, const char *pass, | ||
| 180 | int passlen); | ||
| 181 | X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher, | ||
| 182 | const char *pass, int passlen, unsigned char *salt, int saltlen, int iter, | ||
| 183 | PKCS8_PRIV_KEY_INFO *p8); | ||
| 184 | PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, const char *pass, | ||
| 185 | int passlen, unsigned char *salt, int saltlen, int iter, | ||
| 186 | PKCS8_PRIV_KEY_INFO *p8); | ||
| 187 | PKCS7 *PKCS12_pack_p7data(STACK_OF(PKCS12_SAFEBAG) *sk); | ||
| 188 | STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7data(PKCS7 *p7); | ||
| 189 | PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen, | ||
| 190 | unsigned char *salt, int saltlen, int iter, STACK_OF(PKCS12_SAFEBAG) *bags); | ||
| 191 | STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7encdata(PKCS7 *p7, const char *pass, | ||
| 192 | int passlen); | ||
| 193 | |||
| 194 | int PKCS12_pack_authsafes(PKCS12 *p12, STACK_OF(PKCS7) *safes); | ||
| 195 | STACK_OF(PKCS7) *PKCS12_unpack_authsafes(PKCS12 *p12); | ||
| 196 | |||
| 197 | int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, | ||
| 198 | int namelen); | ||
| 199 | int PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name, | ||
| 200 | int namelen); | ||
| 201 | int PKCS12_add_CSPName_asc(PKCS12_SAFEBAG *bag, const char *name, | ||
| 202 | int namelen); | ||
| 203 | int PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag, const unsigned char *name, | ||
| 204 | int namelen); | ||
| 205 | int PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage); | ||
| 206 | ASN1_TYPE *PKCS12_get_attr_gen(STACK_OF(X509_ATTRIBUTE) *attrs, int attr_nid); | ||
| 207 | char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag); | ||
| 208 | unsigned char *PKCS12_pbe_crypt(X509_ALGOR *algor, const char *pass, | ||
| 209 | int passlen, unsigned char *in, int inlen, unsigned char **data, | ||
| 210 | int *datalen, int en_de); | ||
| 211 | void * PKCS12_item_decrypt_d2i(X509_ALGOR *algor, const ASN1_ITEM *it, | ||
| 212 | const char *pass, int passlen, ASN1_OCTET_STRING *oct, int zbuf); | ||
| 213 | ASN1_OCTET_STRING *PKCS12_item_i2d_encrypt(X509_ALGOR *algor, | ||
| 214 | const ASN1_ITEM *it, const char *pass, int passlen, void *obj, int zbuf); | ||
| 215 | PKCS12 *PKCS12_init(int mode); | ||
| 216 | int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt, | ||
| 217 | int saltlen, int id, int iter, int n, unsigned char *out, | ||
| 218 | const EVP_MD *md_type); | ||
| 219 | int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt, | ||
| 220 | int saltlen, int id, int iter, int n, unsigned char *out, | ||
| 221 | const EVP_MD *md_type); | ||
| 222 | int PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, | ||
| 223 | ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md_type, | ||
| 224 | int en_de); | ||
| 225 | int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen, | ||
| 226 | unsigned char *mac, unsigned int *maclen); | ||
| 227 | int PKCS12_verify_mac(PKCS12 *p12, const char *pass, int passlen); | ||
| 228 | int PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen, | ||
| 229 | unsigned char *salt, int saltlen, int iter, | ||
| 230 | const EVP_MD *md_type); | ||
| 231 | int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt, | ||
| 232 | int saltlen, const EVP_MD *md_type); | ||
| 233 | unsigned char *OPENSSL_asc2uni(const char *asc, int asclen, | ||
| 234 | unsigned char **uni, int *unilen); | ||
| 235 | char *OPENSSL_uni2asc(unsigned char *uni, int unilen); | ||
| 236 | |||
| 237 | DECLARE_ASN1_FUNCTIONS(PKCS12) | ||
| 238 | DECLARE_ASN1_FUNCTIONS(PKCS12_MAC_DATA) | ||
| 239 | DECLARE_ASN1_FUNCTIONS(PKCS12_SAFEBAG) | ||
| 240 | DECLARE_ASN1_FUNCTIONS(PKCS12_BAGS) | ||
| 241 | |||
| 242 | DECLARE_ASN1_ITEM(PKCS12_SAFEBAGS) | ||
| 243 | DECLARE_ASN1_ITEM(PKCS12_AUTHSAFES) | ||
| 244 | |||
| 245 | void PKCS12_PBE_add(void); | ||
| 246 | int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert, | ||
| 247 | STACK_OF(X509) **ca); | ||
| 248 | PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert, | ||
| 249 | STACK_OF(X509) *ca, int nid_key, int nid_cert, int iter, | ||
| 250 | int mac_iter, int keytype); | ||
| 251 | |||
| 252 | PKCS12_SAFEBAG *PKCS12_add_cert(STACK_OF(PKCS12_SAFEBAG) **pbags, X509 *cert); | ||
| 253 | PKCS12_SAFEBAG *PKCS12_add_key(STACK_OF(PKCS12_SAFEBAG) **pbags, EVP_PKEY *key, | ||
| 254 | int key_usage, int iter, int key_nid, char *pass); | ||
| 255 | int PKCS12_add_safe(STACK_OF(PKCS7) **psafes, STACK_OF(PKCS12_SAFEBAG) *bags, | ||
| 256 | int safe_nid, int iter, char *pass); | ||
| 257 | PKCS12 *PKCS12_add_safes(STACK_OF(PKCS7) *safes, int p7_nid); | ||
| 258 | |||
| 259 | int i2d_PKCS12_bio(BIO *bp, PKCS12 *p12); | ||
| 260 | int i2d_PKCS12_fp(FILE *fp, PKCS12 *p12); | ||
| 261 | PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12); | ||
| 262 | PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12); | ||
| 263 | int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass); | ||
| 264 | |||
| 265 | /* BEGIN ERROR CODES */ | ||
| 266 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
| 267 | * made after this point may be overwritten when the script is next run. | ||
| 268 | */ | ||
| 269 | void ERR_load_PKCS12_strings(void); | ||
| 270 | |||
| 271 | /* Error codes for the PKCS12 functions. */ | ||
| 272 | |||
| 273 | /* Function codes. */ | ||
| 274 | #define PKCS12_F_PARSE_BAG 129 | ||
| 275 | #define PKCS12_F_PARSE_BAGS 103 | ||
| 276 | #define PKCS12_F_PKCS12_ADD_FRIENDLYNAME 100 | ||
| 277 | #define PKCS12_F_PKCS12_ADD_FRIENDLYNAME_ASC 127 | ||
| 278 | #define PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI 102 | ||
| 279 | #define PKCS12_F_PKCS12_ADD_LOCALKEYID 104 | ||
| 280 | #define PKCS12_F_PKCS12_CREATE 105 | ||
| 281 | #define PKCS12_F_PKCS12_GEN_MAC 107 | ||
| 282 | #define PKCS12_F_PKCS12_INIT 109 | ||
| 283 | #define PKCS12_F_PKCS12_ITEM_DECRYPT_D2I 106 | ||
| 284 | #define PKCS12_F_PKCS12_ITEM_I2D_ENCRYPT 108 | ||
| 285 | #define PKCS12_F_PKCS12_ITEM_PACK_SAFEBAG 117 | ||
| 286 | #define PKCS12_F_PKCS12_KEY_GEN_ASC 110 | ||
| 287 | #define PKCS12_F_PKCS12_KEY_GEN_UNI 111 | ||
| 288 | #define PKCS12_F_PKCS12_MAKE_KEYBAG 112 | ||
| 289 | #define PKCS12_F_PKCS12_MAKE_SHKEYBAG 113 | ||
| 290 | #define PKCS12_F_PKCS12_NEWPASS 128 | ||
| 291 | #define PKCS12_F_PKCS12_PACK_P7DATA 114 | ||
| 292 | #define PKCS12_F_PKCS12_PACK_P7ENCDATA 115 | ||
| 293 | #define PKCS12_F_PKCS12_PARSE 118 | ||
| 294 | #define PKCS12_F_PKCS12_PBE_CRYPT 119 | ||
| 295 | #define PKCS12_F_PKCS12_PBE_KEYIVGEN 120 | ||
| 296 | #define PKCS12_F_PKCS12_SETUP_MAC 122 | ||
| 297 | #define PKCS12_F_PKCS12_SET_MAC 123 | ||
| 298 | #define PKCS12_F_PKCS12_UNPACK_AUTHSAFES 130 | ||
| 299 | #define PKCS12_F_PKCS12_UNPACK_P7DATA 131 | ||
| 300 | #define PKCS12_F_PKCS12_VERIFY_MAC 126 | ||
| 301 | #define PKCS12_F_PKCS8_ADD_KEYUSAGE 124 | ||
| 302 | #define PKCS12_F_PKCS8_ENCRYPT 125 | ||
| 303 | |||
| 304 | /* Reason codes. */ | ||
| 305 | #define PKCS12_R_CANT_PACK_STRUCTURE 100 | ||
| 306 | #define PKCS12_R_CONTENT_TYPE_NOT_DATA 121 | ||
| 307 | #define PKCS12_R_DECODE_ERROR 101 | ||
| 308 | #define PKCS12_R_ENCODE_ERROR 102 | ||
| 309 | #define PKCS12_R_ENCRYPT_ERROR 103 | ||
| 310 | #define PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE 120 | ||
| 311 | #define PKCS12_R_INVALID_NULL_ARGUMENT 104 | ||
| 312 | #define PKCS12_R_INVALID_NULL_PKCS12_POINTER 105 | ||
| 313 | #define PKCS12_R_IV_GEN_ERROR 106 | ||
| 314 | #define PKCS12_R_KEY_GEN_ERROR 107 | ||
| 315 | #define PKCS12_R_MAC_ABSENT 108 | ||
| 316 | #define PKCS12_R_MAC_GENERATION_ERROR 109 | ||
| 317 | #define PKCS12_R_MAC_SETUP_ERROR 110 | ||
| 318 | #define PKCS12_R_MAC_STRING_SET_ERROR 111 | ||
| 319 | #define PKCS12_R_MAC_VERIFY_ERROR 112 | ||
| 320 | #define PKCS12_R_MAC_VERIFY_FAILURE 113 | ||
| 321 | #define PKCS12_R_PARSE_ERROR 114 | ||
| 322 | #define PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR 115 | ||
| 323 | #define PKCS12_R_PKCS12_CIPHERFINAL_ERROR 116 | ||
| 324 | #define PKCS12_R_PKCS12_PBE_CRYPT_ERROR 117 | ||
| 325 | #define PKCS12_R_UNKNOWN_DIGEST_ALGORITHM 118 | ||
| 326 | #define PKCS12_R_UNSUPPORTED_PKCS12_MODE 119 | ||
| 327 | |||
| 328 | #ifdef __cplusplus | ||
| 329 | } | ||
| 330 | #endif | ||
| 331 | #endif | ||
