diff options
Diffstat (limited to 'src/lib/libcrypto/pkcs12/p12_add.c')
-rw-r--r-- | src/lib/libcrypto/pkcs12/p12_add.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/lib/libcrypto/pkcs12/p12_add.c b/src/lib/libcrypto/pkcs12/p12_add.c index ae3d9de3b4..d045cbba8d 100644 --- a/src/lib/libcrypto/pkcs12/p12_add.c +++ b/src/lib/libcrypto/pkcs12/p12_add.c | |||
@@ -133,7 +133,7 @@ PKCS7 *PKCS12_pack_p7data (STACK *sk) | |||
133 | return NULL; | 133 | return NULL; |
134 | } | 134 | } |
135 | p7->type = OBJ_nid2obj(NID_pkcs7_data); | 135 | p7->type = OBJ_nid2obj(NID_pkcs7_data); |
136 | if (!(p7->d.data = ASN1_OCTET_STRING_new())) { | 136 | if (!(p7->d.data = M_ASN1_OCTET_STRING_new())) { |
137 | PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, ERR_R_MALLOC_FAILURE); | 137 | PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, ERR_R_MALLOC_FAILURE); |
138 | return NULL; | 138 | return NULL; |
139 | } | 139 | } |
@@ -157,20 +157,18 @@ PKCS7 *PKCS12_pack_p7encdata (int pbe_nid, const char *pass, int passlen, | |||
157 | PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE); | 157 | PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE); |
158 | return NULL; | 158 | return NULL; |
159 | } | 159 | } |
160 | p7->type = OBJ_nid2obj(NID_pkcs7_encrypted); | 160 | if(!PKCS7_set_type(p7, NID_pkcs7_encrypted)) { |
161 | if (!(p7->d.encrypted = PKCS7_ENCRYPT_new ())) { | 161 | PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, |
162 | PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE); | 162 | PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE); |
163 | return NULL; | 163 | return NULL; |
164 | } | 164 | } |
165 | ASN1_INTEGER_set (p7->d.encrypted->version, 0); | ||
166 | p7->d.encrypted->enc_data->content_type = OBJ_nid2obj(NID_pkcs7_data); | ||
167 | if (!(pbe = PKCS5_pbe_set (pbe_nid, iter, salt, saltlen))) { | 165 | if (!(pbe = PKCS5_pbe_set (pbe_nid, iter, salt, saltlen))) { |
168 | PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE); | 166 | PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE); |
169 | return NULL; | 167 | return NULL; |
170 | } | 168 | } |
171 | X509_ALGOR_free(p7->d.encrypted->enc_data->algorithm); | 169 | X509_ALGOR_free(p7->d.encrypted->enc_data->algorithm); |
172 | p7->d.encrypted->enc_data->algorithm = pbe; | 170 | p7->d.encrypted->enc_data->algorithm = pbe; |
173 | ASN1_OCTET_STRING_free(p7->d.encrypted->enc_data->enc_data); | 171 | M_ASN1_OCTET_STRING_free(p7->d.encrypted->enc_data->enc_data); |
174 | if (!(p7->d.encrypted->enc_data->enc_data = | 172 | if (!(p7->d.encrypted->enc_data->enc_data = |
175 | PKCS12_i2d_encrypt (pbe, i2d_PKCS12_SAFEBAG, pass, passlen, | 173 | PKCS12_i2d_encrypt (pbe, i2d_PKCS12_SAFEBAG, pass, passlen, |
176 | (char *)bags, 1))) { | 174 | (char *)bags, 1))) { |
@@ -191,24 +189,28 @@ X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher, | |||
191 | 189 | ||
192 | if (!(p8 = X509_SIG_new())) { | 190 | if (!(p8 = X509_SIG_new())) { |
193 | PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_MALLOC_FAILURE); | 191 | PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_MALLOC_FAILURE); |
194 | return NULL; | 192 | goto err; |
195 | } | 193 | } |
196 | 194 | ||
197 | if(pbe_nid == -1) pbe = PKCS5_pbe2_set(cipher, iter, salt, saltlen); | 195 | if(pbe_nid == -1) pbe = PKCS5_pbe2_set(cipher, iter, salt, saltlen); |
198 | else pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen); | 196 | else pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen); |
199 | if(!pbe) { | 197 | if(!pbe) { |
200 | PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_MALLOC_FAILURE); | 198 | PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_ASN1_LIB); |
201 | return NULL; | 199 | goto err; |
202 | } | 200 | } |
203 | X509_ALGOR_free(p8->algor); | 201 | X509_ALGOR_free(p8->algor); |
204 | p8->algor = pbe; | 202 | p8->algor = pbe; |
205 | ASN1_OCTET_STRING_free(p8->digest); | 203 | M_ASN1_OCTET_STRING_free(p8->digest); |
206 | if (!(p8->digest = | 204 | if (!(p8->digest = |
207 | PKCS12_i2d_encrypt (pbe, i2d_PKCS8_PRIV_KEY_INFO, pass, passlen, | 205 | PKCS12_i2d_encrypt (pbe, i2d_PKCS8_PRIV_KEY_INFO, pass, passlen, |
208 | (char *)p8inf, 0))) { | 206 | (char *)p8inf, 0))) { |
209 | PKCS12err(PKCS12_F_PKCS8_ENCRYPT, PKCS12_R_ENCRYPT_ERROR); | 207 | PKCS12err(PKCS12_F_PKCS8_ENCRYPT, PKCS12_R_ENCRYPT_ERROR); |
210 | return NULL; | 208 | goto err; |
211 | } | 209 | } |
212 | 210 | ||
213 | return p8; | 211 | return p8; |
212 | |||
213 | err: | ||
214 | X509_SIG_free(p8); | ||
215 | return NULL; | ||
214 | } | 216 | } |