Constify X509_SIG_get0() and order arguments to mactch new standard.
Add X509_SIG_get0_mutable() to support modification or initialisation
of an X509_SIG structure.
Reviewed-by: Matt Caswell <matt@openssl.org>
int print_attribs(BIO *out, const STACK_OF(X509_ATTRIBUTE) *attrlst,
const char *name);
void hex_prin(BIO *out, unsigned char *buf, int len);
-static int alg_print(X509_ALGOR *alg);
+static int alg_print(const X509_ALGOR *alg);
int cert_load(BIO *in, STACK_OF(X509) *sk);
static int set_pbe(int *ppbe, const char *str);
OPENSSL_strlcpy(macpass, pass, sizeof macpass);
if ((options & INFO) && PKCS12_mac_present(p12)) {
- ASN1_INTEGER *tmaciter;
- X509_ALGOR *macalgid;
+ const ASN1_INTEGER *tmaciter;
+ const X509_ALGOR *macalgid;
const ASN1_OBJECT *macobj;
PKCS12_get0_mac(NULL, &macalgid, NULL, &tmaciter, p12);
X509_ALGOR_get0(&macobj, NULL, NULL, macalgid);
case NID_pkcs8ShroudedKeyBag:
if (options & INFO) {
- X509_SIG *tp8;
- X509_ALGOR *tp8alg;
+ const X509_SIG *tp8;
+ const X509_ALGOR *tp8alg;
BIO_printf(bio_err, "Shrouded Keybag: ");
tp8 = PKCS12_SAFEBAG_get0_pkcs8(bag);
- X509_SIG_get0(&tp8alg, NULL, tp8);
+ X509_SIG_get0(tp8, &tp8alg, NULL);
alg_print(tp8alg);
}
if (options & NOKEYS)
return i;
}
-static int alg_print(X509_ALGOR *alg)
+static int alg_print(const X509_ALGOR *alg)
{
int pbenid, aparamtype;
const ASN1_OBJECT *aoid;
IMPLEMENT_ASN1_FUNCTIONS(X509_SIG)
-void X509_SIG_get0(X509_ALGOR **palg, ASN1_OCTET_STRING **pdigest,
- X509_SIG *sig)
+void X509_SIG_get0(const X509_SIG *sig, const X509_ALGOR **palg,
+ const ASN1_OCTET_STRING **pdigest)
+{
+ if (palg)
+ *palg = sig->algor;
+ if (pdigest)
+ *pdigest = sig->digest;
+}
+
+void X509_SIG_get0_mutable(X509_SIG *sig, X509_ALGOR **palg,
+ ASN1_OCTET_STRING **pdigest)
{
if (palg)
*palg = sig->algor;
* Encrypt/Decrypt a buffer based on password and algor, result in a
* OPENSSL_malloc'ed buffer
*/
-
-unsigned char *PKCS12_pbe_crypt(X509_ALGOR *algor, const char *pass,
- int passlen, unsigned char *in, int inlen,
+unsigned char *PKCS12_pbe_crypt(const X509_ALGOR *algor,
+ const char *pass, int passlen,
+ const unsigned char *in, int inlen,
unsigned char **data, int *datalen, int en_de)
{
unsigned char *out = NULL;
* after use.
*/
-void *PKCS12_item_decrypt_d2i(X509_ALGOR *algor, const ASN1_ITEM *it,
+void *PKCS12_item_decrypt_d2i(const X509_ALGOR *algor, const ASN1_ITEM *it,
const char *pass, int passlen,
- ASN1_OCTET_STRING *oct, int zbuf)
+ const ASN1_OCTET_STRING *oct, int zbuf)
{
unsigned char *out;
const unsigned char *p;
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)
+void PKCS12_get0_mac(const ASN1_OCTET_STRING **pmac,
+ const X509_ALGOR **pmacalg,
+ const ASN1_OCTET_STRING **psalt,
+ const ASN1_INTEGER **piter,
+ const PKCS12 *p12)
{
if (p12->mac) {
- X509_SIG_get0(pmacalg, pmac, p12->mac->dinfo);
+ X509_SIG_get0(p12->mac->dinfo, pmacalg, pmac);
if (psalt)
*psalt = p12->mac->salt;
if (piter)
int saltlen, iter;
int md_size = 0;
int md_type_nid;
- X509_ALGOR *macalg;
+ const X509_ALGOR *macalg;
const ASN1_OBJECT *macoid;
if (!PKCS7_type_is_data(p12->authsafes)) {
iter = 1;
else
iter = ASN1_INTEGER_get(p12->mac->iter);
- X509_SIG_get0(&macalg, NULL, p12->mac->dinfo);
+ X509_SIG_get0(p12->mac->dinfo, &macalg, NULL);
X509_ALGOR_get0(&macoid, NULL, NULL, macalg);
if ((md_type = EVP_get_digestbyobj(macoid)) == NULL) {
PKCS12err(PKCS12_F_PKCS12_GEN_MAC, PKCS12_R_UNKNOWN_DIGEST_ALGORITHM);
{
unsigned char mac[EVP_MAX_MD_SIZE];
unsigned int maclen;
- ASN1_OCTET_STRING *macoct;
+ const ASN1_OCTET_STRING *macoct;
if (p12->mac == NULL) {
PKCS12err(PKCS12_F_PKCS12_VERIFY_MAC, PKCS12_R_MAC_ABSENT);
PKCS12err(PKCS12_F_PKCS12_VERIFY_MAC, PKCS12_R_MAC_GENERATION_ERROR);
return 0;
}
- X509_SIG_get0(NULL, &macoct, p12->mac->dinfo);
+ X509_SIG_get0(p12->mac->dinfo, NULL, &macoct);
if ((maclen != (unsigned int)ASN1_STRING_length(macoct))
|| CRYPTO_memcmp(mac, ASN1_STRING_get0_data(macoct), maclen))
return 0;
PKCS12err(PKCS12_F_PKCS12_SET_MAC, PKCS12_R_MAC_GENERATION_ERROR);
return 0;
}
- X509_SIG_get0(NULL, &macoct, p12->mac->dinfo);
+ X509_SIG_get0_mutable(p12->mac->dinfo, NULL, &macoct);
if (!ASN1_OCTET_STRING_set(macoct, mac, maclen)) {
PKCS12err(PKCS12_F_PKCS12_SET_MAC, PKCS12_R_MAC_STRING_SET_ERROR);
return 0;
return 0;
} else
memcpy(p12->mac->salt->data, salt, saltlen);
- X509_SIG_get0(&macalg, NULL, p12->mac->dinfo);
+ X509_SIG_get0_mutable(p12->mac->dinfo, &macalg, NULL);
if (!X509_ALGOR_set0(macalg, OBJ_nid2obj(EVP_MD_type(md_type)),
V_ASN1_NULL, NULL)) {
PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE);
const char *newpass);
static int newpass_bag(PKCS12_SAFEBAG *bag, const char *oldpass,
const char *newpass);
-static int alg_get(X509_ALGOR *alg, int *pnid, int *piter, int *psaltlen);
+static int alg_get(const X509_ALGOR *alg, int *pnid, int *piter,
+ int *psaltlen);
/*
* Change the password on a PKCS#12 structure.
if (!PKCS12_gen_mac(p12, newpass, -1, mac, &maclen))
goto err;
- X509_SIG_get0(NULL, &macoct, p12->mac->dinfo);
+ X509_SIG_get0_mutable(p12->mac->dinfo, NULL, &macoct);
if (!ASN1_OCTET_STRING_set(macoct, mac, maclen))
goto err;
PKCS8_PRIV_KEY_INFO *p8;
X509_SIG *p8new;
int p8_nid, p8_saltlen, p8_iter;
- X509_ALGOR *shalg;
+ const X509_ALGOR *shalg;
if (PKCS12_SAFEBAG_get_nid(bag) != NID_pkcs8ShroudedKeyBag)
return 1;
if ((p8 = PKCS8_decrypt(bag->value.shkeybag, oldpass, -1)) == NULL)
return 0;
- X509_SIG_get0(&shalg, NULL, bag->value.shkeybag);
+ X509_SIG_get0(bag->value.shkeybag, &shalg, NULL);
if (!alg_get(shalg, &p8_nid, &p8_iter, &p8_saltlen))
return 0;
p8new = PKCS8_encrypt(p8_nid, NULL, newpass, -1, NULL, p8_saltlen,
return 1;
}
-static int alg_get(X509_ALGOR *alg, int *pnid, int *piter, int *psaltlen)
+static int alg_get(const X509_ALGOR *alg, int *pnid, int *piter,
+ int *psaltlen)
{
PBEPARAM *pbe;
pbe = ASN1_TYPE_unpack_sequence(ASN1_ITEM_rptr(PBEPARAM), alg->parameter);
#include "internal/cryptlib.h"
#include <openssl/pkcs12.h>
-PKCS8_PRIV_KEY_INFO *PKCS8_decrypt(X509_SIG *p8, const char *pass,
+PKCS8_PRIV_KEY_INFO *PKCS8_decrypt(const X509_SIG *p8, const char *pass,
int passlen)
{
- X509_ALGOR *dalg;
- ASN1_OCTET_STRING *doct;
- X509_SIG_get0(&dalg, &doct, p8);
+ const X509_ALGOR *dalg;
+ const ASN1_OCTET_STRING *doct;
+ X509_SIG_get0(p8, &dalg, &doct);
return PKCS12_item_decrypt_d2i(dalg,
ASN1_ITEM_rptr(PKCS8_PRIV_KEY_INFO), pass,
passlen, doct, 1);
=head1 NAME
-X509_SIG_get0 - Get DigestInfo functions
+X509_SIG_get0, X509_SIG_get0_mutable - DigestInfo functions
=head1 SYNOPSIS
#include <openssl/x509.h>
- void X509_SIG_get0(X509_ALGOR **palg, ASN1_OCTET_STRING **pdigest,
- X509_SIG *sig);
+ void X509_SIG_get0(const X509_SIG *sig, const X509_ALGOR **palg,
+ const ASN1_OCTET_STRING **pdigest);
+ void X509_SIG_get0_mutable(X509_SIG *sig, X509_ALGOR **palg,
+ ASN1_OCTET_STRING **pdigest,
=head1 DESCRIPTION
X509_SIG_get0() returns pointers to the algorithm identifier and digest
-value in B<sig>. These values can then be examined or initialised.
+value in B<sig>. X509_SIG_get0_mutable() is identical to X509_SIG_get0()
+except the pointers returned are not constant and can be modified:
+for example to initialise them.
=head1 SEE ALSO
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);
+void PKCS12_get0_mac(const ASN1_OCTET_STRING **pmac,
+ const X509_ALGOR **pmacalg,
+ const ASN1_OCTET_STRING **psalt,
+ const ASN1_INTEGER **piter,
+ const PKCS12 *p12);
ASN1_TYPE *PKCS12_SAFEBAG_get0_attr(PKCS12_SAFEBAG *bag, int attr_nid);
ASN1_OBJECT *PKCS12_SAFEBAG_get0_type(PKCS12_SAFEBAG *bag);
PKCS12_SAFEBAG *PKCS12_item_pack_safebag(void *obj, const ASN1_ITEM *it,
int nid1, int nid2);
-PKCS8_PRIV_KEY_INFO *PKCS8_decrypt(X509_SIG *p8, const char *pass,
+PKCS8_PRIV_KEY_INFO *PKCS8_decrypt(const X509_SIG *p8, const char *pass,
int passlen);
PKCS8_PRIV_KEY_INFO *PKCS12_decrypt_skey(PKCS12_SAFEBAG *bag,
const char *pass, int passlen);
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 *PKCS12_pbe_crypt(const X509_ALGOR *algor,
+ const char *pass, int passlen,
+ const unsigned char *in, int inlen,
unsigned char **data, int *datalen,
int en_de);
-void *PKCS12_item_decrypt_d2i(X509_ALGOR *algor, const ASN1_ITEM *it,
+void *PKCS12_item_decrypt_d2i(const X509_ALGOR *algor, const ASN1_ITEM *it,
const char *pass, int passlen,
- ASN1_OCTET_STRING *oct, int zbuf);
+ const ASN1_OCTET_STRING *oct, int zbuf);
ASN1_OCTET_STRING *PKCS12_item_i2d_encrypt(X509_ALGOR *algor,
const ASN1_ITEM *it,
const char *pass, int passlen,
# endif
DECLARE_ASN1_FUNCTIONS(X509_SIG)
-void X509_SIG_get0(X509_ALGOR **palg, ASN1_OCTET_STRING **pdigest,
- X509_SIG *sig);
+void X509_SIG_get0(const X509_SIG *sig, const X509_ALGOR **palg,
+ const ASN1_OCTET_STRING **pdigest);
+void X509_SIG_get0_mutable(X509_SIG *sig, X509_ALGOR **palg,
+ ASN1_OCTET_STRING **pdigest);
DECLARE_ASN1_FUNCTIONS(X509_REQ_INFO)
DECLARE_ASN1_FUNCTIONS(X509_REQ)