提交 b0e69a05 编写于 作者: D Dr. Stephen Henson

Add feature to PKCS12_create() if the encryption NID corresponds to a

supported encryption algorithm instead of a PBE NID then use that
algorithm with PBES2.
上级 856640b5
...@@ -106,6 +106,7 @@ PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, const char *pass, ...@@ -106,6 +106,7 @@ PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, const char *pass,
PKCS8_PRIV_KEY_INFO *p8) PKCS8_PRIV_KEY_INFO *p8)
{ {
PKCS12_SAFEBAG *bag; PKCS12_SAFEBAG *bag;
const EVP_CIPHER *pbe_ciph;
/* Set up the safe bag */ /* Set up the safe bag */
if (!(bag = PKCS12_SAFEBAG_new())) { if (!(bag = PKCS12_SAFEBAG_new())) {
...@@ -114,8 +115,14 @@ PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, const char *pass, ...@@ -114,8 +115,14 @@ PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, const char *pass,
} }
bag->type = OBJ_nid2obj(NID_pkcs8ShroudedKeyBag); bag->type = OBJ_nid2obj(NID_pkcs8ShroudedKeyBag);
pbe_ciph = EVP_get_cipherbynid(pbe_nid);
if (pbe_ciph)
pbe_nid = -1;
if (!(bag->value.shkeybag = if (!(bag->value.shkeybag =
PKCS8_encrypt(pbe_nid, NULL, pass, passlen, salt, saltlen, iter, PKCS8_encrypt(pbe_nid, pbe_ciph, pass, passlen, salt, saltlen, iter,
p8))) { p8))) {
PKCS12err(PKCS12_F_PKCS12_MAKE_SHKEYBAG, ERR_R_MALLOC_FAILURE); PKCS12err(PKCS12_F_PKCS12_MAKE_SHKEYBAG, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
...@@ -164,6 +171,7 @@ PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen, ...@@ -164,6 +171,7 @@ PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen,
{ {
PKCS7 *p7; PKCS7 *p7;
X509_ALGOR *pbe; X509_ALGOR *pbe;
const EVP_CIPHER *pbe_ciph;
if (!(p7 = PKCS7_new())) { if (!(p7 = PKCS7_new())) {
PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE); PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
...@@ -173,7 +181,15 @@ PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen, ...@@ -173,7 +181,15 @@ PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen,
PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE); PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE);
return NULL; return NULL;
} }
if (!(pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen))) {
pbe_ciph = EVP_get_cipherbynid(pbe_nid);
if (pbe_ciph)
pbe = PKCS5_pbe2_set(pbe_ciph, iter, salt, saltlen);
else
pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen);
if (!pbe) {
PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE); PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册