diff options
Diffstat (limited to 'src/lib/libcrypto/pkcs12/p12_sbag.c')
-rw-r--r-- | src/lib/libcrypto/pkcs12/p12_sbag.c | 235 |
1 files changed, 0 insertions, 235 deletions
diff --git a/src/lib/libcrypto/pkcs12/p12_sbag.c b/src/lib/libcrypto/pkcs12/p12_sbag.c deleted file mode 100644 index 1664e9409d..0000000000 --- a/src/lib/libcrypto/pkcs12/p12_sbag.c +++ /dev/null | |||
@@ -1,235 +0,0 @@ | |||
1 | /* $OpenBSD: p12_sbag.c,v 1.9 2024/03/24 06:48:03 tb Exp $ */ | ||
2 | /* | ||
3 | * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project | ||
4 | * 1999-2018. | ||
5 | */ | ||
6 | /* ==================================================================== | ||
7 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
8 | * | ||
9 | * Redistribution and use in source and binary forms, with or without | ||
10 | * modification, are permitted provided that the following conditions | ||
11 | * are met: | ||
12 | * | ||
13 | * 1. Redistributions of source code must retain the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer. | ||
15 | * | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in | ||
18 | * the documentation and/or other materials provided with the | ||
19 | * distribution. | ||
20 | * | ||
21 | * 3. All advertising materials mentioning features or use of this | ||
22 | * software must display the following acknowledgment: | ||
23 | * "This product includes software developed by the OpenSSL Project | ||
24 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
25 | * | ||
26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
27 | * endorse or promote products derived from this software without | ||
28 | * prior written permission. For written permission, please contact | ||
29 | * licensing@OpenSSL.org. | ||
30 | * | ||
31 | * 5. Products derived from this software may not be called "OpenSSL" | ||
32 | * nor may "OpenSSL" appear in their names without prior written | ||
33 | * permission of the OpenSSL Project. | ||
34 | * | ||
35 | * 6. Redistributions of any form whatsoever must retain the following | ||
36 | * acknowledgment: | ||
37 | * "This product includes software developed by the OpenSSL Project | ||
38 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
39 | * | ||
40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
51 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
52 | * ==================================================================== | ||
53 | * | ||
54 | * This product includes cryptographic software written by Eric Young | ||
55 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
56 | * Hudson (tjh@cryptsoft.com). | ||
57 | * | ||
58 | */ | ||
59 | |||
60 | #include <stdio.h> | ||
61 | |||
62 | #include <openssl/err.h> | ||
63 | #include <openssl/pkcs12.h> | ||
64 | |||
65 | #include "pkcs12_local.h" | ||
66 | #include "x509_local.h" | ||
67 | |||
68 | const ASN1_TYPE * | ||
69 | PKCS12_SAFEBAG_get0_attr(const PKCS12_SAFEBAG *bag, int attr_nid) | ||
70 | { | ||
71 | return PKCS12_get_attr_gen(bag->attrib, attr_nid); | ||
72 | } | ||
73 | LCRYPTO_ALIAS(PKCS12_SAFEBAG_get0_attr); | ||
74 | |||
75 | ASN1_TYPE * | ||
76 | PKCS8_get_attr(PKCS8_PRIV_KEY_INFO *p8, int attr_nid) | ||
77 | { | ||
78 | return PKCS12_get_attr_gen(p8->attributes, attr_nid); | ||
79 | } | ||
80 | LCRYPTO_ALIAS(PKCS8_get_attr); | ||
81 | |||
82 | const PKCS8_PRIV_KEY_INFO * | ||
83 | PKCS12_SAFEBAG_get0_p8inf(const PKCS12_SAFEBAG *bag) | ||
84 | { | ||
85 | if (PKCS12_SAFEBAG_get_nid(bag) != NID_keyBag) | ||
86 | return NULL; | ||
87 | |||
88 | return bag->value.keybag; | ||
89 | } | ||
90 | LCRYPTO_ALIAS(PKCS12_SAFEBAG_get0_p8inf); | ||
91 | |||
92 | const X509_SIG * | ||
93 | PKCS12_SAFEBAG_get0_pkcs8(const PKCS12_SAFEBAG *bag) | ||
94 | { | ||
95 | if (PKCS12_SAFEBAG_get_nid(bag) != NID_pkcs8ShroudedKeyBag) | ||
96 | return NULL; | ||
97 | |||
98 | return bag->value.shkeybag; | ||
99 | } | ||
100 | LCRYPTO_ALIAS(PKCS12_SAFEBAG_get0_pkcs8); | ||
101 | |||
102 | const STACK_OF(PKCS12_SAFEBAG) * | ||
103 | PKCS12_SAFEBAG_get0_safes(const PKCS12_SAFEBAG *bag) | ||
104 | { | ||
105 | if (PKCS12_SAFEBAG_get_nid(bag) != NID_safeContentsBag) | ||
106 | return NULL; | ||
107 | |||
108 | return bag->value.safes; | ||
109 | } | ||
110 | LCRYPTO_ALIAS(PKCS12_SAFEBAG_get0_safes); | ||
111 | |||
112 | const ASN1_OBJECT * | ||
113 | PKCS12_SAFEBAG_get0_type(const PKCS12_SAFEBAG *bag) | ||
114 | { | ||
115 | return bag->type; | ||
116 | } | ||
117 | LCRYPTO_ALIAS(PKCS12_SAFEBAG_get0_type); | ||
118 | |||
119 | int | ||
120 | PKCS12_SAFEBAG_get_nid(const PKCS12_SAFEBAG *bag) | ||
121 | { | ||
122 | return OBJ_obj2nid(bag->type); | ||
123 | } | ||
124 | LCRYPTO_ALIAS(PKCS12_SAFEBAG_get_nid); | ||
125 | |||
126 | int | ||
127 | PKCS12_SAFEBAG_get_bag_nid(const PKCS12_SAFEBAG *bag) | ||
128 | { | ||
129 | int bag_type; | ||
130 | |||
131 | bag_type = PKCS12_SAFEBAG_get_nid(bag); | ||
132 | |||
133 | if (bag_type == NID_certBag || bag_type == NID_crlBag || | ||
134 | bag_type == NID_secretBag) | ||
135 | return OBJ_obj2nid(bag->value.bag->type); | ||
136 | |||
137 | return -1; | ||
138 | } | ||
139 | LCRYPTO_ALIAS(PKCS12_SAFEBAG_get_bag_nid); | ||
140 | |||
141 | X509 * | ||
142 | PKCS12_SAFEBAG_get1_cert(const PKCS12_SAFEBAG *bag) | ||
143 | { | ||
144 | if (OBJ_obj2nid(bag->type) != NID_certBag) | ||
145 | return NULL; | ||
146 | if (OBJ_obj2nid(bag->value.bag->type) != NID_x509Certificate) | ||
147 | return NULL; | ||
148 | return ASN1_item_unpack(bag->value.bag->value.octet, &X509_it); | ||
149 | } | ||
150 | LCRYPTO_ALIAS(PKCS12_SAFEBAG_get1_cert); | ||
151 | |||
152 | X509_CRL * | ||
153 | PKCS12_SAFEBAG_get1_crl(const PKCS12_SAFEBAG *bag) | ||
154 | { | ||
155 | if (OBJ_obj2nid(bag->type) != NID_crlBag) | ||
156 | return NULL; | ||
157 | if (OBJ_obj2nid(bag->value.bag->type) != NID_x509Crl) | ||
158 | return NULL; | ||
159 | return ASN1_item_unpack(bag->value.bag->value.octet, &X509_CRL_it); | ||
160 | } | ||
161 | LCRYPTO_ALIAS(PKCS12_SAFEBAG_get1_crl); | ||
162 | |||
163 | PKCS12_SAFEBAG * | ||
164 | PKCS12_SAFEBAG_create_cert(X509 *x509) | ||
165 | { | ||
166 | return PKCS12_item_pack_safebag(x509, &X509_it, | ||
167 | NID_x509Certificate, NID_certBag); | ||
168 | } | ||
169 | |||
170 | PKCS12_SAFEBAG * | ||
171 | PKCS12_SAFEBAG_create_crl(X509_CRL *crl) | ||
172 | { | ||
173 | return PKCS12_item_pack_safebag(crl, &X509_CRL_it, | ||
174 | NID_x509Crl, NID_crlBag); | ||
175 | } | ||
176 | |||
177 | /* Turn PKCS8 object into a keybag */ | ||
178 | |||
179 | PKCS12_SAFEBAG * | ||
180 | PKCS12_SAFEBAG_create0_p8inf(PKCS8_PRIV_KEY_INFO *p8) | ||
181 | { | ||
182 | PKCS12_SAFEBAG *bag; | ||
183 | |||
184 | if ((bag = PKCS12_SAFEBAG_new()) == NULL) { | ||
185 | PKCS12error(ERR_R_MALLOC_FAILURE); | ||
186 | return NULL; | ||
187 | } | ||
188 | |||
189 | bag->type = OBJ_nid2obj(NID_keyBag); | ||
190 | bag->value.keybag = p8; | ||
191 | |||
192 | return bag; | ||
193 | } | ||
194 | |||
195 | /* Turn PKCS8 object into a shrouded keybag */ | ||
196 | |||
197 | PKCS12_SAFEBAG * | ||
198 | PKCS12_SAFEBAG_create0_pkcs8(X509_SIG *p8) | ||
199 | { | ||
200 | PKCS12_SAFEBAG *bag; | ||
201 | |||
202 | /* Set up the safe bag */ | ||
203 | if ((bag = PKCS12_SAFEBAG_new()) == NULL) { | ||
204 | PKCS12error(ERR_R_MALLOC_FAILURE); | ||
205 | return NULL; | ||
206 | } | ||
207 | |||
208 | bag->type = OBJ_nid2obj(NID_pkcs8ShroudedKeyBag); | ||
209 | bag->value.shkeybag = p8; | ||
210 | |||
211 | return bag; | ||
212 | } | ||
213 | |||
214 | PKCS12_SAFEBAG * | ||
215 | PKCS12_SAFEBAG_create_pkcs8_encrypt(int pbe_nid, const char *pass, int passlen, | ||
216 | unsigned char *salt, int saltlen, int iter, PKCS8_PRIV_KEY_INFO *p8info) | ||
217 | { | ||
218 | const EVP_CIPHER *pbe_ciph; | ||
219 | X509_SIG *p8; | ||
220 | PKCS12_SAFEBAG *bag; | ||
221 | |||
222 | if ((pbe_ciph = EVP_get_cipherbynid(pbe_nid)) != NULL) | ||
223 | pbe_nid = -1; | ||
224 | |||
225 | if ((p8 = PKCS8_encrypt(pbe_nid, pbe_ciph, pass, passlen, salt, saltlen, | ||
226 | iter, p8info)) == NULL) | ||
227 | return NULL; | ||
228 | |||
229 | if ((bag = PKCS12_SAFEBAG_create0_pkcs8(p8)) == NULL) { | ||
230 | X509_SIG_free(p8); | ||
231 | return NULL; | ||
232 | } | ||
233 | |||
234 | return bag; | ||
235 | } | ||