X-Git-Url: https://git.openssl.org/?a=blobdiff_plain;f=crypto%2Fx509%2Fx_x509.c;h=8a216c49cf75b603caca9dd616e85f65a040d6a8;hb=f000e82898af251442ca52e81fc1ee45996090dc;hp=7d9f9816e64d6632e32821a67b8f14b0ffbd036e;hpb=f46c2597ab958ce970aec40ff3b7f5ba5ceb0bcb;p=openssl.git diff --git a/crypto/x509/x_x509.c b/crypto/x509/x_x509.c index 7d9f9816e6..8a216c49cf 100644 --- a/crypto/x509/x_x509.c +++ b/crypto/x509/x_x509.c @@ -1,7 +1,7 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html @@ -13,7 +13,11 @@ #include #include #include -#include "internal/x509_int.h" +#include "crypto/x509.h" + +#ifndef OPENSSL_NO_RFC3779 +DEFINE_STACK_OF(IPAddressFamily) +#endif ASN1_SEQUENCE_enc(X509_CINF, enc, 0) = { ASN1_EXP_OPT(X509_CINF, version, ASN1_INTEGER, 0), @@ -40,16 +44,41 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, switch (operation) { + case ASN1_OP_D2I_PRE: + CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data); + X509_CERT_AUX_free(ret->aux); + ASN1_OCTET_STRING_free(ret->skid); + AUTHORITY_KEYID_free(ret->akid); + CRL_DIST_POINTS_free(ret->crldp); + policy_cache_free(ret->policy_cache); + GENERAL_NAMES_free(ret->altname); + NAME_CONSTRAINTS_free(ret->nc); +#ifndef OPENSSL_NO_RFC3779 + sk_IPAddressFamily_pop_free(ret->rfc3779_addr, IPAddressFamily_free); + ASIdentifiers_free(ret->rfc3779_asid); +#endif + ASN1_OCTET_STRING_free(ret->distinguishing_id); + + /* fall thru */ + case ASN1_OP_NEW_POST: + ret->ex_cached = 0; + ret->ex_kusage = 0; + ret->ex_xkusage = 0; + ret->ex_nscert = 0; ret->ex_flags = 0; ret->ex_pathlen = -1; ret->ex_pcpathlen = -1; ret->skid = NULL; ret->akid = NULL; + ret->policy_cache = NULL; + ret->altname = NULL; + ret->nc = NULL; #ifndef OPENSSL_NO_RFC3779 ret->rfc3779_addr = NULL; ret->rfc3779_asid = NULL; #endif + ret->distinguishing_id = NULL; ret->aux = NULL; ret->crldp = NULL; if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data)) @@ -69,6 +98,7 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, sk_IPAddressFamily_pop_free(ret->rfc3779_addr, IPAddressFamily_free); ASIdentifiers_free(ret->rfc3779_asid); #endif + ASN1_OCTET_STRING_free(ret->distinguishing_id); break; } @@ -84,17 +114,16 @@ ASN1_SEQUENCE_ref(X509, x509_cb) = { } ASN1_SEQUENCE_END_ref(X509, X509) IMPLEMENT_ASN1_FUNCTIONS(X509) - IMPLEMENT_ASN1_DUP_FUNCTION(X509) int X509_set_ex_data(X509 *r, int idx, void *arg) { - return (CRYPTO_set_ex_data(&r->ex_data, idx, arg)); + return CRYPTO_set_ex_data(&r->ex_data, idx, arg); } -void *X509_get_ex_data(X509 *r, int idx) +void *X509_get_ex_data(const X509 *r, int idx) { - return (CRYPTO_get_ex_data(&r->ex_data, idx)); + return CRYPTO_get_ex_data(&r->ex_data, idx); } /* @@ -140,13 +169,11 @@ X509 *d2i_X509_AUX(X509 **a, const unsigned char **pp, long length) * error path, but that depends on similar hygiene in lower-level functions. * Here we avoid compounding the problem. */ -static int i2d_x509_aux_internal(X509 *a, unsigned char **pp) +static int i2d_x509_aux_internal(const X509 *a, unsigned char **pp) { int length, tmplen; unsigned char *start = pp != NULL ? *pp : NULL; - OPENSSL_assert(pp == NULL || *pp != NULL); - /* * This might perturb *pp on error, but fixing that belongs in i2d_X509() * not here. It should be that if a == NULL length is zero, but we check @@ -176,7 +203,7 @@ static int i2d_x509_aux_internal(X509 *a, unsigned char **pp) * the allocation, nor can we allow i2d_X509_CERT_AUX() to increment the * allocated buffer. */ -int i2d_X509_AUX(X509 *a, unsigned char **pp) +int i2d_X509_AUX(const X509 *a, unsigned char **pp) { int length; unsigned char *tmp; @@ -191,8 +218,10 @@ int i2d_X509_AUX(X509 *a, unsigned char **pp) /* Allocate requisite combined storage */ *pp = tmp = OPENSSL_malloc(length); - if (tmp == NULL) - return -1; /* Push error onto error stack? */ + if (tmp == NULL) { + X509err(X509_F_I2D_X509_AUX, ERR_R_MALLOC_FAILURE); + return -1; + } /* Encode, but keep *pp at the originally malloced pointer */ length = i2d_x509_aux_internal(a, &tmp); @@ -209,7 +238,8 @@ int i2d_re_X509_tbs(X509 *x, unsigned char **pp) return i2d_X509_CINF(&x->cert_info, pp); } -void X509_get0_signature(ASN1_BIT_STRING **psig, X509_ALGOR **palg, X509 *x) +void X509_get0_signature(const ASN1_BIT_STRING **psig, + const X509_ALGOR **palg, const X509 *x) { if (psig) *psig = &x->signature; @@ -221,3 +251,14 @@ int X509_get_signature_nid(const X509 *x) { return OBJ_obj2nid(x->sig_alg.algorithm); } + +void X509_set0_distinguishing_id(X509 *x, ASN1_OCTET_STRING *d_id) +{ + ASN1_OCTET_STRING_free(x->distinguishing_id); + x->distinguishing_id = d_id; +} + +ASN1_OCTET_STRING *X509_get0_distinguishing_id(X509 *x) +{ + return x->distinguishing_id; +}