From 1387a2ecb8f4eecb407952f56eafcce10ab68cb0 Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Sun, 27 Sep 2015 00:33:59 +0100 Subject: [PATCH] pkcs12 accessors Reviewed-by: Rich Salz --- crypto/pkcs12/p12_attr.c | 5 +++++ crypto/pkcs12/p12_utl.c | 37 +++++++++++++++++++++++++++++++++++++ include/openssl/pkcs12.h | 6 ++++++ 3 files changed, 48 insertions(+) diff --git a/crypto/pkcs12/p12_attr.c b/crypto/pkcs12/p12_attr.c index 5746a7b502..454db9e46e 100644 --- a/crypto/pkcs12/p12_attr.c +++ b/crypto/pkcs12/p12_attr.c @@ -137,3 +137,8 @@ char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag) return OPENSSL_uni2asc(atype->value.bmpstring->data, atype->value.bmpstring->length); } + +STACK_OF(X509_ATTRIBUTE) *PKCS12_SAFEBAG_get0_attrs(PKCS12_SAFEBAG *bag) +{ + return bag->attrib; +} diff --git a/crypto/pkcs12/p12_utl.c b/crypto/pkcs12/p12_utl.c index db4c139101..eabfb8e703 100644 --- a/crypto/pkcs12/p12_utl.c +++ b/crypto/pkcs12/p12_utl.c @@ -177,6 +177,31 @@ int PKCS12_mac_present(PKCS12 *p12) return p12->mac ? 1 : 0; } +void PKCS12_get0_mac(ASN1_OCTET_STRING **pmac, X509_ALGOR **pmacalg, + ASN1_OCTET_STRING **psalt, ASN1_INTEGER **piter, + PKCS12 *p12) +{ + if (p12->mac) { + if (pmac) + *pmac = p12->mac->dinfo->digest; + if (pmacalg) + *pmacalg = p12->mac->dinfo->algor; + if (psalt) + *psalt = p12->mac->salt; + if (piter) + *piter = p12->mac->iter; + } else { + if (pmac) + *pmac = NULL; + if (pmacalg) + *pmacalg = NULL; + if (psalt) + *psalt = NULL; + if (piter) + *piter = NULL; + } +} + int PKCS12_bag_type(PKCS12_SAFEBAG *bag) { return OBJ_obj2nid(bag->type); @@ -196,9 +221,21 @@ PKCS8_PRIV_KEY_INFO *PKCS12_SAFEBAG_get0_p8inf(PKCS12_SAFEBAG *bag) return bag->value.keybag; } +X509_SIG *PKCS12_SAFEBAG_get0_pkcs8(PKCS12_SAFEBAG *bag) +{ + if (OBJ_obj2nid(bag->type) != NID_pkcs8ShroudedKeyBag) + return NULL; + return bag->value.shkeybag; +} + STACK_OF(PKCS12_SAFEBAG) *PKCS12_SAFEBAG_get0_safes(PKCS12_SAFEBAG *bag) { if (OBJ_obj2nid(bag->type) != NID_safeContentsBag) return NULL; return bag->value.safes; } + +ASN1_OBJECT *PKCS12_SAFEBAG_get0_type(PKCS12_SAFEBAG *bag) +{ + return bag->type; +} diff --git a/include/openssl/pkcs12.h b/include/openssl/pkcs12.h index db355fc82e..079ac1af07 100644 --- a/include/openssl/pkcs12.h +++ b/include/openssl/pkcs12.h @@ -134,10 +134,15 @@ typedef struct pkcs12_bag_st PKCS12_BAGS; ASN1_TYPE *PKCS12_get_attr(PKCS12_SAFEBAG *bag, int attr_nid); ASN1_TYPE *PKCS8_get_attr(PKCS8_PRIV_KEY_INFO *p8, int attr_nid); int PKCS12_mac_present(PKCS12 *p12); +void PKCS12_get0_mac(ASN1_OCTET_STRING **pmac, X509_ALGOR **pmacalg, + ASN1_OCTET_STRING **psalt, ASN1_INTEGER **piter, + PKCS12 *p12); int PKCS12_bag_type(PKCS12_SAFEBAG *bag); int PKCS12_cert_bag_type(PKCS12_SAFEBAG *bag); PKCS8_PRIV_KEY_INFO *PKCS12_SAFEBAG_get0_p8inf(PKCS12_SAFEBAG *bag); +X509_SIG *PKCS12_SAFEBAG_get0_pkcs8(PKCS12_SAFEBAG *bag); STACK_OF(PKCS12_SAFEBAG) *PKCS12_SAFEBAG_get0_safes(PKCS12_SAFEBAG *bag); +ASN1_OBJECT *PKCS12_SAFEBAG_get0_type(PKCS12_SAFEBAG *bag); PKCS12_SAFEBAG *PKCS12_x5092certbag(X509 *x509); PKCS12_SAFEBAG *PKCS12_x509crl2certbag(X509_CRL *crl); @@ -182,6 +187,7 @@ int PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag, int PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage); ASN1_TYPE *PKCS12_get_attr_gen(STACK_OF(X509_ATTRIBUTE) *attrs, int attr_nid); char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag); +STACK_OF(X509_ATTRIBUTE) *PKCS12_SAFEBAG_get0_attrs(PKCS12_SAFEBAG *bag); unsigned char *PKCS12_pbe_crypt(X509_ALGOR *algor, const char *pass, int passlen, unsigned char *in, int inlen, unsigned char **data, int *datalen, -- GitLab