You've already forked linux-packaging-mono
Imported Upstream version 4.8.0.309
Former-commit-id: 5f9c6ae75f295e057a7d2971f3a6df4656fa8850
This commit is contained in:
parent
ee1447783b
commit
94b2861243
68
external/boringssl/crypto/x509v3/CMakeLists.txt
vendored
Normal file
68
external/boringssl/crypto/x509v3/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
include_directories(../../include)
|
||||
|
||||
add_library(
|
||||
x509v3
|
||||
|
||||
OBJECT
|
||||
|
||||
# v3_addr.c - disabled by upstream by default.
|
||||
# v3_asid.c - disabled by upstream by default.
|
||||
# v3_ocsp.c - missing OCSP for now.
|
||||
|
||||
pcy_cache.c
|
||||
pcy_data.c
|
||||
pcy_lib.c
|
||||
pcy_map.c
|
||||
pcy_node.c
|
||||
pcy_tree.c
|
||||
v3_akey.c
|
||||
v3_akeya.c
|
||||
v3_alt.c
|
||||
v3_bcons.c
|
||||
v3_bitst.c
|
||||
v3_conf.c
|
||||
v3_cpols.c
|
||||
v3_crld.c
|
||||
v3_enum.c
|
||||
v3_extku.c
|
||||
v3_genn.c
|
||||
v3_ia5.c
|
||||
v3_info.c
|
||||
v3_int.c
|
||||
v3_lib.c
|
||||
v3_ncons.c
|
||||
v3_pci.c
|
||||
v3_pcia.c
|
||||
v3_pcons.c
|
||||
v3_pku.c
|
||||
v3_pmaps.c
|
||||
v3_prn.c
|
||||
v3_purp.c
|
||||
v3_skey.c
|
||||
v3_sxnet.c
|
||||
v3_utl.c
|
||||
)
|
||||
|
||||
if(ENABLE_TESTS)
|
||||
add_executable(
|
||||
v3name_test
|
||||
|
||||
v3name_test.c
|
||||
|
||||
$<TARGET_OBJECTS:test_support>
|
||||
)
|
||||
|
||||
target_link_libraries(v3name_test crypto)
|
||||
add_dependencies(all_tests v3name_test)
|
||||
|
||||
add_executable(
|
||||
tab_test
|
||||
|
||||
tab_test.c
|
||||
|
||||
$<TARGET_OBJECTS:test_support>
|
||||
)
|
||||
|
||||
target_link_libraries(tab_test crypto)
|
||||
add_dependencies(all_tests tab_test)
|
||||
endif()
|
||||
135
external/boringssl/crypto/x509v3/ext_dat.h
vendored
Normal file
135
external/boringssl/crypto/x509v3/ext_dat.h
vendored
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
|
||||
* 1999.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999-2004 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com). */
|
||||
|
||||
/* This file contains a table of "standard" extensions */
|
||||
|
||||
extern const X509V3_EXT_METHOD v3_bcons, v3_nscert, v3_key_usage, v3_ext_ku;
|
||||
extern const X509V3_EXT_METHOD v3_pkey_usage_period, v3_sxnet, v3_info,
|
||||
v3_sinfo;
|
||||
extern const X509V3_EXT_METHOD v3_ns_ia5_list[], v3_alt[], v3_skey_id,
|
||||
v3_akey_id;
|
||||
extern const X509V3_EXT_METHOD v3_crl_num, v3_crl_reason, v3_crl_invdate;
|
||||
extern const X509V3_EXT_METHOD v3_delta_crl, v3_cpols, v3_crld,
|
||||
v3_freshest_crl;
|
||||
extern const X509V3_EXT_METHOD v3_ocsp_nonce, v3_ocsp_accresp,
|
||||
v3_ocsp_acutoff;
|
||||
extern const X509V3_EXT_METHOD v3_ocsp_crlid, v3_ocsp_nocheck,
|
||||
v3_ocsp_serviceloc;
|
||||
extern const X509V3_EXT_METHOD v3_crl_hold, v3_pci;
|
||||
extern const X509V3_EXT_METHOD v3_policy_mappings, v3_policy_constraints;
|
||||
extern const X509V3_EXT_METHOD v3_name_constraints, v3_inhibit_anyp, v3_idp;
|
||||
extern const X509V3_EXT_METHOD v3_addr, v3_asid;
|
||||
|
||||
/*
|
||||
* This table will be searched using OBJ_bsearch so it *must* kept in order
|
||||
* of the ext_nid values.
|
||||
*/
|
||||
|
||||
/* TODO(fork): OCSP support */
|
||||
#define OPENSSL_NO_OCSP
|
||||
|
||||
static const X509V3_EXT_METHOD *const standard_exts[] = {
|
||||
&v3_nscert,
|
||||
&v3_ns_ia5_list[0],
|
||||
&v3_ns_ia5_list[1],
|
||||
&v3_ns_ia5_list[2],
|
||||
&v3_ns_ia5_list[3],
|
||||
&v3_ns_ia5_list[4],
|
||||
&v3_ns_ia5_list[5],
|
||||
&v3_ns_ia5_list[6],
|
||||
&v3_skey_id,
|
||||
&v3_key_usage,
|
||||
&v3_pkey_usage_period,
|
||||
&v3_alt[0],
|
||||
&v3_alt[1],
|
||||
&v3_bcons,
|
||||
&v3_crl_num,
|
||||
&v3_cpols,
|
||||
&v3_akey_id,
|
||||
&v3_crld,
|
||||
&v3_ext_ku,
|
||||
&v3_delta_crl,
|
||||
&v3_crl_reason,
|
||||
#ifndef OPENSSL_NO_OCSP
|
||||
&v3_crl_invdate,
|
||||
#endif
|
||||
&v3_sxnet,
|
||||
&v3_info,
|
||||
#ifndef OPENSSL_NO_OCSP
|
||||
&v3_ocsp_nonce,
|
||||
&v3_ocsp_crlid,
|
||||
&v3_ocsp_accresp,
|
||||
&v3_ocsp_nocheck,
|
||||
&v3_ocsp_acutoff,
|
||||
&v3_ocsp_serviceloc,
|
||||
#endif
|
||||
&v3_sinfo,
|
||||
&v3_policy_constraints,
|
||||
#ifndef OPENSSL_NO_OCSP
|
||||
&v3_crl_hold,
|
||||
#endif
|
||||
&v3_pci,
|
||||
&v3_name_constraints,
|
||||
&v3_policy_mappings,
|
||||
&v3_inhibit_anyp,
|
||||
&v3_idp,
|
||||
&v3_alt[2],
|
||||
&v3_freshest_crl,
|
||||
};
|
||||
|
||||
/* Number of standard extensions */
|
||||
|
||||
#define STANDARD_EXTENSION_COUNT (sizeof(standard_exts)/sizeof(X509V3_EXT_METHOD *))
|
||||
284
external/boringssl/crypto/x509v3/pcy_cache.c
vendored
Normal file
284
external/boringssl/crypto/x509v3/pcy_cache.c
vendored
Normal file
@@ -0,0 +1,284 @@
|
||||
/*
|
||||
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
|
||||
* 2004.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2004 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com). */
|
||||
|
||||
#include <openssl/mem.h>
|
||||
#include <openssl/obj.h>
|
||||
#include <openssl/thread.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
#include "pcy_int.h"
|
||||
#include "../internal.h"
|
||||
|
||||
static int policy_data_cmp(const X509_POLICY_DATA **a,
|
||||
const X509_POLICY_DATA **b);
|
||||
static int policy_cache_set_int(long *out, ASN1_INTEGER *value);
|
||||
|
||||
/*
|
||||
* Set cache entry according to CertificatePolicies extension. Note: this
|
||||
* destroys the passed CERTIFICATEPOLICIES structure.
|
||||
*/
|
||||
|
||||
static int policy_cache_create(X509 *x,
|
||||
CERTIFICATEPOLICIES *policies, int crit)
|
||||
{
|
||||
size_t i;
|
||||
int ret = 0;
|
||||
X509_POLICY_CACHE *cache = x->policy_cache;
|
||||
X509_POLICY_DATA *data = NULL;
|
||||
POLICYINFO *policy;
|
||||
if (sk_POLICYINFO_num(policies) == 0)
|
||||
goto bad_policy;
|
||||
cache->data = sk_X509_POLICY_DATA_new(policy_data_cmp);
|
||||
if (!cache->data)
|
||||
goto bad_policy;
|
||||
for (i = 0; i < sk_POLICYINFO_num(policies); i++) {
|
||||
policy = sk_POLICYINFO_value(policies, i);
|
||||
data = policy_data_new(policy, NULL, crit);
|
||||
if (!data)
|
||||
goto bad_policy;
|
||||
/*
|
||||
* Duplicate policy OIDs are illegal: reject if matches found.
|
||||
*/
|
||||
if (OBJ_obj2nid(data->valid_policy) == NID_any_policy) {
|
||||
if (cache->anyPolicy) {
|
||||
ret = -1;
|
||||
goto bad_policy;
|
||||
}
|
||||
cache->anyPolicy = data;
|
||||
} else if (sk_X509_POLICY_DATA_find(cache->data, NULL, data)) {
|
||||
ret = -1;
|
||||
goto bad_policy;
|
||||
} else if (!sk_X509_POLICY_DATA_push(cache->data, data))
|
||||
goto bad_policy;
|
||||
data = NULL;
|
||||
}
|
||||
ret = 1;
|
||||
bad_policy:
|
||||
if (ret == -1)
|
||||
x->ex_flags |= EXFLAG_INVALID_POLICY;
|
||||
if (data)
|
||||
policy_data_free(data);
|
||||
sk_POLICYINFO_pop_free(policies, POLICYINFO_free);
|
||||
if (ret <= 0) {
|
||||
sk_X509_POLICY_DATA_pop_free(cache->data, policy_data_free);
|
||||
cache->data = NULL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int policy_cache_new(X509 *x)
|
||||
{
|
||||
X509_POLICY_CACHE *cache;
|
||||
ASN1_INTEGER *ext_any = NULL;
|
||||
POLICY_CONSTRAINTS *ext_pcons = NULL;
|
||||
CERTIFICATEPOLICIES *ext_cpols = NULL;
|
||||
POLICY_MAPPINGS *ext_pmaps = NULL;
|
||||
int i;
|
||||
cache = OPENSSL_malloc(sizeof(X509_POLICY_CACHE));
|
||||
if (!cache)
|
||||
return 0;
|
||||
cache->anyPolicy = NULL;
|
||||
cache->data = NULL;
|
||||
cache->any_skip = -1;
|
||||
cache->explicit_skip = -1;
|
||||
cache->map_skip = -1;
|
||||
|
||||
x->policy_cache = cache;
|
||||
|
||||
/*
|
||||
* Handle requireExplicitPolicy *first*. Need to process this even if we
|
||||
* don't have any policies.
|
||||
*/
|
||||
ext_pcons = X509_get_ext_d2i(x, NID_policy_constraints, &i, NULL);
|
||||
|
||||
if (!ext_pcons) {
|
||||
if (i != -1)
|
||||
goto bad_cache;
|
||||
} else {
|
||||
if (!ext_pcons->requireExplicitPolicy
|
||||
&& !ext_pcons->inhibitPolicyMapping)
|
||||
goto bad_cache;
|
||||
if (!policy_cache_set_int(&cache->explicit_skip,
|
||||
ext_pcons->requireExplicitPolicy))
|
||||
goto bad_cache;
|
||||
if (!policy_cache_set_int(&cache->map_skip,
|
||||
ext_pcons->inhibitPolicyMapping))
|
||||
goto bad_cache;
|
||||
}
|
||||
|
||||
/* Process CertificatePolicies */
|
||||
|
||||
ext_cpols = X509_get_ext_d2i(x, NID_certificate_policies, &i, NULL);
|
||||
/*
|
||||
* If no CertificatePolicies extension or problem decoding then there is
|
||||
* no point continuing because the valid policies will be NULL.
|
||||
*/
|
||||
if (!ext_cpols) {
|
||||
/* If not absent some problem with extension */
|
||||
if (i != -1)
|
||||
goto bad_cache;
|
||||
return 1;
|
||||
}
|
||||
|
||||
i = policy_cache_create(x, ext_cpols, i);
|
||||
|
||||
/* NB: ext_cpols freed by policy_cache_set_policies */
|
||||
|
||||
if (i <= 0)
|
||||
return i;
|
||||
|
||||
ext_pmaps = X509_get_ext_d2i(x, NID_policy_mappings, &i, NULL);
|
||||
|
||||
if (!ext_pmaps) {
|
||||
/* If not absent some problem with extension */
|
||||
if (i != -1)
|
||||
goto bad_cache;
|
||||
} else {
|
||||
i = policy_cache_set_mapping(x, ext_pmaps);
|
||||
if (i <= 0)
|
||||
goto bad_cache;
|
||||
}
|
||||
|
||||
ext_any = X509_get_ext_d2i(x, NID_inhibit_any_policy, &i, NULL);
|
||||
|
||||
if (!ext_any) {
|
||||
if (i != -1)
|
||||
goto bad_cache;
|
||||
} else if (!policy_cache_set_int(&cache->any_skip, ext_any))
|
||||
goto bad_cache;
|
||||
|
||||
if (0) {
|
||||
bad_cache:
|
||||
x->ex_flags |= EXFLAG_INVALID_POLICY;
|
||||
}
|
||||
|
||||
if (ext_pcons)
|
||||
POLICY_CONSTRAINTS_free(ext_pcons);
|
||||
|
||||
if (ext_any)
|
||||
ASN1_INTEGER_free(ext_any);
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
void policy_cache_free(X509_POLICY_CACHE *cache)
|
||||
{
|
||||
if (!cache)
|
||||
return;
|
||||
if (cache->anyPolicy)
|
||||
policy_data_free(cache->anyPolicy);
|
||||
if (cache->data)
|
||||
sk_X509_POLICY_DATA_pop_free(cache->data, policy_data_free);
|
||||
OPENSSL_free(cache);
|
||||
}
|
||||
|
||||
/*
|
||||
* g_x509_policy_cache_lock is used to protect against concurrent calls to
|
||||
* |policy_cache_new|. Ideally this would be done with a |CRYPTO_once_t| in
|
||||
* the |X509| structure, but |CRYPTO_once_t| isn't public.
|
||||
*/
|
||||
static struct CRYPTO_STATIC_MUTEX g_x509_policy_cache_lock =
|
||||
CRYPTO_STATIC_MUTEX_INIT;
|
||||
|
||||
const X509_POLICY_CACHE *policy_cache_set(X509 *x)
|
||||
{
|
||||
X509_POLICY_CACHE *cache;
|
||||
|
||||
CRYPTO_STATIC_MUTEX_lock_read(&g_x509_policy_cache_lock);
|
||||
cache = x->policy_cache;
|
||||
CRYPTO_STATIC_MUTEX_unlock_read(&g_x509_policy_cache_lock);
|
||||
|
||||
if (cache != NULL)
|
||||
return cache;
|
||||
|
||||
CRYPTO_STATIC_MUTEX_lock_write(&g_x509_policy_cache_lock);
|
||||
if (x->policy_cache == NULL)
|
||||
policy_cache_new(x);
|
||||
cache = x->policy_cache;
|
||||
CRYPTO_STATIC_MUTEX_unlock_write(&g_x509_policy_cache_lock);
|
||||
|
||||
return cache;
|
||||
}
|
||||
|
||||
X509_POLICY_DATA *policy_cache_find_data(const X509_POLICY_CACHE *cache,
|
||||
const ASN1_OBJECT *id)
|
||||
{
|
||||
size_t idx;
|
||||
X509_POLICY_DATA tmp;
|
||||
|
||||
tmp.valid_policy = (ASN1_OBJECT *)id;
|
||||
if (!sk_X509_POLICY_DATA_find(cache->data, &idx, &tmp))
|
||||
return NULL;
|
||||
return sk_X509_POLICY_DATA_value(cache->data, idx);
|
||||
}
|
||||
|
||||
static int policy_data_cmp(const X509_POLICY_DATA **a,
|
||||
const X509_POLICY_DATA **b)
|
||||
{
|
||||
return OBJ_cmp((*a)->valid_policy, (*b)->valid_policy);
|
||||
}
|
||||
|
||||
static int policy_cache_set_int(long *out, ASN1_INTEGER *value)
|
||||
{
|
||||
if (value == NULL)
|
||||
return 1;
|
||||
if (value->type == V_ASN1_NEG_INTEGER)
|
||||
return 0;
|
||||
*out = ASN1_INTEGER_get(value);
|
||||
return 1;
|
||||
}
|
||||
130
external/boringssl/crypto/x509v3/pcy_data.c
vendored
Normal file
130
external/boringssl/crypto/x509v3/pcy_data.c
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
/* pcy_data.c */
|
||||
/*
|
||||
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
|
||||
* 2004.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2004 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <openssl/mem.h>
|
||||
#include <openssl/obj.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
#include "pcy_int.h"
|
||||
|
||||
/* Policy Node routines */
|
||||
|
||||
void policy_data_free(X509_POLICY_DATA *data)
|
||||
{
|
||||
ASN1_OBJECT_free(data->valid_policy);
|
||||
/* Don't free qualifiers if shared */
|
||||
if (!(data->flags & POLICY_DATA_FLAG_SHARED_QUALIFIERS))
|
||||
sk_POLICYQUALINFO_pop_free(data->qualifier_set, POLICYQUALINFO_free);
|
||||
sk_ASN1_OBJECT_pop_free(data->expected_policy_set, ASN1_OBJECT_free);
|
||||
OPENSSL_free(data);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a data based on an existing policy. If 'id' is NULL use the oid in
|
||||
* the policy, otherwise use 'id'. This behaviour covers the two types of
|
||||
* data in RFC3280: data with from a CertificatePolcies extension and
|
||||
* additional data with just the qualifiers of anyPolicy and ID from another
|
||||
* source.
|
||||
*/
|
||||
|
||||
X509_POLICY_DATA *policy_data_new(POLICYINFO *policy,
|
||||
const ASN1_OBJECT *cid, int crit)
|
||||
{
|
||||
X509_POLICY_DATA *ret;
|
||||
ASN1_OBJECT *id;
|
||||
if (!policy && !cid)
|
||||
return NULL;
|
||||
if (cid) {
|
||||
id = OBJ_dup(cid);
|
||||
if (!id)
|
||||
return NULL;
|
||||
} else
|
||||
id = NULL;
|
||||
ret = OPENSSL_malloc(sizeof(X509_POLICY_DATA));
|
||||
if (!ret)
|
||||
return NULL;
|
||||
ret->expected_policy_set = sk_ASN1_OBJECT_new_null();
|
||||
if (!ret->expected_policy_set) {
|
||||
OPENSSL_free(ret);
|
||||
if (id)
|
||||
ASN1_OBJECT_free(id);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (crit)
|
||||
ret->flags = POLICY_DATA_FLAG_CRITICAL;
|
||||
else
|
||||
ret->flags = 0;
|
||||
|
||||
if (id)
|
||||
ret->valid_policy = id;
|
||||
else {
|
||||
ret->valid_policy = policy->policyid;
|
||||
policy->policyid = NULL;
|
||||
}
|
||||
|
||||
if (policy) {
|
||||
ret->qualifier_set = policy->qualifiers;
|
||||
policy->qualifiers = NULL;
|
||||
} else
|
||||
ret->qualifier_set = NULL;
|
||||
|
||||
return ret;
|
||||
}
|
||||
217
external/boringssl/crypto/x509v3/pcy_int.h
vendored
Normal file
217
external/boringssl/crypto/x509v3/pcy_int.h
vendored
Normal file
@@ -0,0 +1,217 @@
|
||||
/* pcy_int.h */
|
||||
/*
|
||||
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
|
||||
* 2004.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2004 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
typedef struct X509_POLICY_DATA_st X509_POLICY_DATA;
|
||||
|
||||
DECLARE_STACK_OF(X509_POLICY_DATA)
|
||||
|
||||
/* Internal structures */
|
||||
|
||||
/*
|
||||
* This structure and the field names correspond to the Policy 'node' of
|
||||
* RFC3280. NB this structure contains no pointers to parent or child data:
|
||||
* X509_POLICY_NODE contains that. This means that the main policy data can
|
||||
* be kept static and cached with the certificate.
|
||||
*/
|
||||
|
||||
struct X509_POLICY_DATA_st {
|
||||
unsigned int flags;
|
||||
/* Policy OID and qualifiers for this data */
|
||||
ASN1_OBJECT *valid_policy;
|
||||
STACK_OF(POLICYQUALINFO) *qualifier_set;
|
||||
STACK_OF(ASN1_OBJECT) *expected_policy_set;
|
||||
};
|
||||
|
||||
/* X509_POLICY_DATA flags values */
|
||||
|
||||
/*
|
||||
* This flag indicates the structure has been mapped using a policy mapping
|
||||
* extension. If policy mapping is not active its references get deleted.
|
||||
*/
|
||||
|
||||
#define POLICY_DATA_FLAG_MAPPED 0x1
|
||||
|
||||
/*
|
||||
* This flag indicates the data doesn't correspond to a policy in Certificate
|
||||
* Policies: it has been mapped to any policy.
|
||||
*/
|
||||
|
||||
#define POLICY_DATA_FLAG_MAPPED_ANY 0x2
|
||||
|
||||
/* AND with flags to see if any mapping has occurred */
|
||||
|
||||
#define POLICY_DATA_FLAG_MAP_MASK 0x3
|
||||
|
||||
/* qualifiers are shared and shouldn't be freed */
|
||||
|
||||
#define POLICY_DATA_FLAG_SHARED_QUALIFIERS 0x4
|
||||
|
||||
/* Parent node is an extra node and should be freed */
|
||||
|
||||
#define POLICY_DATA_FLAG_EXTRA_NODE 0x8
|
||||
|
||||
/* Corresponding CertificatePolicies is critical */
|
||||
|
||||
#define POLICY_DATA_FLAG_CRITICAL 0x10
|
||||
|
||||
/* This structure is cached with a certificate */
|
||||
|
||||
struct X509_POLICY_CACHE_st {
|
||||
/* anyPolicy data or NULL if no anyPolicy */
|
||||
X509_POLICY_DATA *anyPolicy;
|
||||
/* other policy data */
|
||||
STACK_OF(X509_POLICY_DATA) *data;
|
||||
/* If InhibitAnyPolicy present this is its value or -1 if absent. */
|
||||
long any_skip;
|
||||
/*
|
||||
* If policyConstraints and requireExplicitPolicy present this is its
|
||||
* value or -1 if absent.
|
||||
*/
|
||||
long explicit_skip;
|
||||
/*
|
||||
* If policyConstraints and policyMapping present this is its value or -1
|
||||
* if absent.
|
||||
*/
|
||||
long map_skip;
|
||||
};
|
||||
|
||||
/*
|
||||
* #define POLICY_CACHE_FLAG_CRITICAL POLICY_DATA_FLAG_CRITICAL
|
||||
*/
|
||||
|
||||
/* This structure represents the relationship between nodes */
|
||||
|
||||
struct X509_POLICY_NODE_st {
|
||||
/* node data this refers to */
|
||||
const X509_POLICY_DATA *data;
|
||||
/* Parent node */
|
||||
X509_POLICY_NODE *parent;
|
||||
/* Number of child nodes */
|
||||
int nchild;
|
||||
};
|
||||
|
||||
struct X509_POLICY_LEVEL_st {
|
||||
/* Cert for this level */
|
||||
X509 *cert;
|
||||
/* nodes at this level */
|
||||
STACK_OF(X509_POLICY_NODE) *nodes;
|
||||
/* anyPolicy node */
|
||||
X509_POLICY_NODE *anyPolicy;
|
||||
/* Extra data */
|
||||
/*
|
||||
* STACK_OF(X509_POLICY_DATA) *extra_data;
|
||||
*/
|
||||
unsigned int flags;
|
||||
};
|
||||
|
||||
struct X509_POLICY_TREE_st {
|
||||
/* This is the tree 'level' data */
|
||||
X509_POLICY_LEVEL *levels;
|
||||
int nlevel;
|
||||
/*
|
||||
* Extra policy data when additional nodes (not from the certificate) are
|
||||
* required.
|
||||
*/
|
||||
STACK_OF(X509_POLICY_DATA) *extra_data;
|
||||
/* This is the authority constained policy set */
|
||||
STACK_OF(X509_POLICY_NODE) *auth_policies;
|
||||
STACK_OF(X509_POLICY_NODE) *user_policies;
|
||||
unsigned int flags;
|
||||
};
|
||||
|
||||
/* Set if anyPolicy present in user policies */
|
||||
#define POLICY_FLAG_ANY_POLICY 0x2
|
||||
|
||||
/* Useful macros */
|
||||
|
||||
#define node_data_critical(data) (data->flags & POLICY_DATA_FLAG_CRITICAL)
|
||||
#define node_critical(node) node_data_critical(node->data)
|
||||
|
||||
/* Internal functions */
|
||||
|
||||
X509_POLICY_DATA *policy_data_new(POLICYINFO *policy, const ASN1_OBJECT *id,
|
||||
int crit);
|
||||
void policy_data_free(X509_POLICY_DATA *data);
|
||||
|
||||
X509_POLICY_DATA *policy_cache_find_data(const X509_POLICY_CACHE *cache,
|
||||
const ASN1_OBJECT *id);
|
||||
int policy_cache_set_mapping(X509 *x, POLICY_MAPPINGS *maps);
|
||||
|
||||
STACK_OF(X509_POLICY_NODE) *policy_node_cmp_new(void);
|
||||
|
||||
void policy_cache_init(void);
|
||||
|
||||
void policy_cache_free(X509_POLICY_CACHE *cache);
|
||||
|
||||
X509_POLICY_NODE *level_find_node(const X509_POLICY_LEVEL *level,
|
||||
const X509_POLICY_NODE *parent,
|
||||
const ASN1_OBJECT *id);
|
||||
|
||||
X509_POLICY_NODE *tree_find_sk(STACK_OF(X509_POLICY_NODE) *sk,
|
||||
const ASN1_OBJECT *id);
|
||||
|
||||
X509_POLICY_NODE *level_add_node(X509_POLICY_LEVEL *level,
|
||||
const X509_POLICY_DATA *data,
|
||||
X509_POLICY_NODE *parent,
|
||||
X509_POLICY_TREE *tree);
|
||||
void policy_node_free(X509_POLICY_NODE *node);
|
||||
int policy_node_match(const X509_POLICY_LEVEL *lvl,
|
||||
const X509_POLICY_NODE *node, const ASN1_OBJECT *oid);
|
||||
|
||||
const X509_POLICY_CACHE *policy_cache_set(X509 *x);
|
||||
164
external/boringssl/crypto/x509v3/pcy_lib.c
vendored
Normal file
164
external/boringssl/crypto/x509v3/pcy_lib.c
vendored
Normal file
@@ -0,0 +1,164 @@
|
||||
/* pcy_lib.c */
|
||||
/*
|
||||
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
|
||||
* 2004.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2004 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com). */
|
||||
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
#include "pcy_int.h"
|
||||
|
||||
/* accessor functions */
|
||||
|
||||
/* X509_POLICY_TREE stuff */
|
||||
|
||||
int X509_policy_tree_level_count(const X509_POLICY_TREE *tree)
|
||||
{
|
||||
if (!tree)
|
||||
return 0;
|
||||
return tree->nlevel;
|
||||
}
|
||||
|
||||
X509_POLICY_LEVEL *X509_policy_tree_get0_level(const X509_POLICY_TREE *tree,
|
||||
int i)
|
||||
{
|
||||
if (!tree || (i < 0) || (i >= tree->nlevel))
|
||||
return NULL;
|
||||
return tree->levels + i;
|
||||
}
|
||||
|
||||
STACK_OF(X509_POLICY_NODE) *X509_policy_tree_get0_policies(const
|
||||
X509_POLICY_TREE
|
||||
*tree)
|
||||
{
|
||||
if (!tree)
|
||||
return NULL;
|
||||
return tree->auth_policies;
|
||||
}
|
||||
|
||||
STACK_OF(X509_POLICY_NODE) *X509_policy_tree_get0_user_policies(const
|
||||
X509_POLICY_TREE
|
||||
*tree)
|
||||
{
|
||||
if (!tree)
|
||||
return NULL;
|
||||
if (tree->flags & POLICY_FLAG_ANY_POLICY)
|
||||
return tree->auth_policies;
|
||||
else
|
||||
return tree->user_policies;
|
||||
}
|
||||
|
||||
/* X509_POLICY_LEVEL stuff */
|
||||
|
||||
int X509_policy_level_node_count(X509_POLICY_LEVEL *level)
|
||||
{
|
||||
int n;
|
||||
if (!level)
|
||||
return 0;
|
||||
if (level->anyPolicy)
|
||||
n = 1;
|
||||
else
|
||||
n = 0;
|
||||
if (level->nodes)
|
||||
n += sk_X509_POLICY_NODE_num(level->nodes);
|
||||
return n;
|
||||
}
|
||||
|
||||
X509_POLICY_NODE *X509_policy_level_get0_node(X509_POLICY_LEVEL *level, int i)
|
||||
{
|
||||
if (!level)
|
||||
return NULL;
|
||||
if (level->anyPolicy) {
|
||||
if (i == 0)
|
||||
return level->anyPolicy;
|
||||
i--;
|
||||
}
|
||||
return sk_X509_POLICY_NODE_value(level->nodes, i);
|
||||
}
|
||||
|
||||
/* X509_POLICY_NODE stuff */
|
||||
|
||||
const ASN1_OBJECT *X509_policy_node_get0_policy(const X509_POLICY_NODE *node)
|
||||
{
|
||||
if (!node)
|
||||
return NULL;
|
||||
return node->data->valid_policy;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int X509_policy_node_get_critical(const X509_POLICY_NODE *node)
|
||||
{
|
||||
if (node_critical(node))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
STACK_OF(POLICYQUALINFO) *X509_policy_node_get0_qualifiers(const
|
||||
X509_POLICY_NODE
|
||||
*node)
|
||||
{
|
||||
if (!node)
|
||||
return NULL;
|
||||
return node->data->qualifier_set;
|
||||
}
|
||||
|
||||
const X509_POLICY_NODE *X509_policy_node_get0_parent(const X509_POLICY_NODE
|
||||
*node)
|
||||
{
|
||||
if (!node)
|
||||
return NULL;
|
||||
return node->parent;
|
||||
}
|
||||
130
external/boringssl/crypto/x509v3/pcy_map.c
vendored
Normal file
130
external/boringssl/crypto/x509v3/pcy_map.c
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
/* pcy_map.c */
|
||||
/*
|
||||
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
|
||||
* 2004.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2004 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <openssl/obj.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
#include "pcy_int.h"
|
||||
|
||||
/*
|
||||
* Set policy mapping entries in cache. Note: this modifies the passed
|
||||
* POLICY_MAPPINGS structure
|
||||
*/
|
||||
|
||||
int policy_cache_set_mapping(X509 *x, POLICY_MAPPINGS *maps)
|
||||
{
|
||||
POLICY_MAPPING *map;
|
||||
X509_POLICY_DATA *data;
|
||||
X509_POLICY_CACHE *cache = x->policy_cache;
|
||||
size_t i;
|
||||
int ret = 0;
|
||||
if (sk_POLICY_MAPPING_num(maps) == 0) {
|
||||
ret = -1;
|
||||
goto bad_mapping;
|
||||
}
|
||||
for (i = 0; i < sk_POLICY_MAPPING_num(maps); i++) {
|
||||
map = sk_POLICY_MAPPING_value(maps, i);
|
||||
/* Reject if map to or from anyPolicy */
|
||||
if ((OBJ_obj2nid(map->subjectDomainPolicy) == NID_any_policy)
|
||||
|| (OBJ_obj2nid(map->issuerDomainPolicy) == NID_any_policy)) {
|
||||
ret = -1;
|
||||
goto bad_mapping;
|
||||
}
|
||||
|
||||
/* Attempt to find matching policy data */
|
||||
data = policy_cache_find_data(cache, map->issuerDomainPolicy);
|
||||
/* If we don't have anyPolicy can't map */
|
||||
if (!data && !cache->anyPolicy)
|
||||
continue;
|
||||
|
||||
/* Create a NODE from anyPolicy */
|
||||
if (!data) {
|
||||
data = policy_data_new(NULL, map->issuerDomainPolicy,
|
||||
cache->anyPolicy->flags
|
||||
& POLICY_DATA_FLAG_CRITICAL);
|
||||
if (!data)
|
||||
goto bad_mapping;
|
||||
data->qualifier_set = cache->anyPolicy->qualifier_set;
|
||||
/*
|
||||
* map->issuerDomainPolicy = NULL;
|
||||
*/
|
||||
data->flags |= POLICY_DATA_FLAG_MAPPED_ANY;
|
||||
data->flags |= POLICY_DATA_FLAG_SHARED_QUALIFIERS;
|
||||
if (!sk_X509_POLICY_DATA_push(cache->data, data)) {
|
||||
policy_data_free(data);
|
||||
goto bad_mapping;
|
||||
}
|
||||
} else
|
||||
data->flags |= POLICY_DATA_FLAG_MAPPED;
|
||||
if (!sk_ASN1_OBJECT_push(data->expected_policy_set,
|
||||
map->subjectDomainPolicy))
|
||||
goto bad_mapping;
|
||||
map->subjectDomainPolicy = NULL;
|
||||
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
bad_mapping:
|
||||
if (ret == -1)
|
||||
x->ex_flags |= EXFLAG_INVALID_POLICY;
|
||||
sk_POLICY_MAPPING_pop_free(maps, POLICY_MAPPING_free);
|
||||
return ret;
|
||||
|
||||
}
|
||||
188
external/boringssl/crypto/x509v3/pcy_node.c
vendored
Normal file
188
external/boringssl/crypto/x509v3/pcy_node.c
vendored
Normal file
@@ -0,0 +1,188 @@
|
||||
/* pcy_node.c */
|
||||
/*
|
||||
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
|
||||
* 2004.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2004 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com). */
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/mem.h>
|
||||
#include <openssl/obj.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
#include "pcy_int.h"
|
||||
|
||||
static int node_cmp(const X509_POLICY_NODE **a, const X509_POLICY_NODE **b)
|
||||
{
|
||||
return OBJ_cmp((*a)->data->valid_policy, (*b)->data->valid_policy);
|
||||
}
|
||||
|
||||
STACK_OF(X509_POLICY_NODE) *policy_node_cmp_new(void)
|
||||
{
|
||||
return sk_X509_POLICY_NODE_new(node_cmp);
|
||||
}
|
||||
|
||||
X509_POLICY_NODE *tree_find_sk(STACK_OF(X509_POLICY_NODE) *nodes,
|
||||
const ASN1_OBJECT *id)
|
||||
{
|
||||
X509_POLICY_DATA n;
|
||||
X509_POLICY_NODE l;
|
||||
size_t idx;
|
||||
|
||||
n.valid_policy = (ASN1_OBJECT *)id;
|
||||
l.data = &n;
|
||||
|
||||
if (!sk_X509_POLICY_NODE_find(nodes, &idx, &l))
|
||||
return NULL;
|
||||
|
||||
return sk_X509_POLICY_NODE_value(nodes, idx);
|
||||
|
||||
}
|
||||
|
||||
X509_POLICY_NODE *level_find_node(const X509_POLICY_LEVEL *level,
|
||||
const X509_POLICY_NODE *parent,
|
||||
const ASN1_OBJECT *id)
|
||||
{
|
||||
X509_POLICY_NODE *node;
|
||||
size_t i;
|
||||
for (i = 0; i < sk_X509_POLICY_NODE_num(level->nodes); i++) {
|
||||
node = sk_X509_POLICY_NODE_value(level->nodes, i);
|
||||
if (node->parent == parent) {
|
||||
if (!OBJ_cmp(node->data->valid_policy, id))
|
||||
return node;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
X509_POLICY_NODE *level_add_node(X509_POLICY_LEVEL *level,
|
||||
const X509_POLICY_DATA *data,
|
||||
X509_POLICY_NODE *parent,
|
||||
X509_POLICY_TREE *tree)
|
||||
{
|
||||
X509_POLICY_NODE *node;
|
||||
node = OPENSSL_malloc(sizeof(X509_POLICY_NODE));
|
||||
if (!node)
|
||||
return NULL;
|
||||
node->data = data;
|
||||
node->parent = parent;
|
||||
node->nchild = 0;
|
||||
if (level) {
|
||||
if (OBJ_obj2nid(data->valid_policy) == NID_any_policy) {
|
||||
if (level->anyPolicy)
|
||||
goto node_error;
|
||||
level->anyPolicy = node;
|
||||
} else {
|
||||
|
||||
if (!level->nodes)
|
||||
level->nodes = policy_node_cmp_new();
|
||||
if (!level->nodes)
|
||||
goto node_error;
|
||||
if (!sk_X509_POLICY_NODE_push(level->nodes, node))
|
||||
goto node_error;
|
||||
}
|
||||
}
|
||||
|
||||
if (tree) {
|
||||
if (!tree->extra_data)
|
||||
tree->extra_data = sk_X509_POLICY_DATA_new_null();
|
||||
if (!tree->extra_data)
|
||||
goto node_error;
|
||||
if (!sk_X509_POLICY_DATA_push(tree->extra_data, data))
|
||||
goto node_error;
|
||||
}
|
||||
|
||||
if (parent)
|
||||
parent->nchild++;
|
||||
|
||||
return node;
|
||||
|
||||
node_error:
|
||||
policy_node_free(node);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
void policy_node_free(X509_POLICY_NODE *node)
|
||||
{
|
||||
OPENSSL_free(node);
|
||||
}
|
||||
|
||||
/*
|
||||
* See if a policy node matches a policy OID. If mapping enabled look through
|
||||
* expected policy set otherwise just valid policy.
|
||||
*/
|
||||
|
||||
int policy_node_match(const X509_POLICY_LEVEL *lvl,
|
||||
const X509_POLICY_NODE *node, const ASN1_OBJECT *oid)
|
||||
{
|
||||
size_t i;
|
||||
ASN1_OBJECT *policy_oid;
|
||||
const X509_POLICY_DATA *x = node->data;
|
||||
|
||||
if ((lvl->flags & X509_V_FLAG_INHIBIT_MAP)
|
||||
|| !(x->flags & POLICY_DATA_FLAG_MAP_MASK)) {
|
||||
if (!OBJ_cmp(x->valid_policy, oid))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < sk_ASN1_OBJECT_num(x->expected_policy_set); i++) {
|
||||
policy_oid = sk_ASN1_OBJECT_value(x->expected_policy_set, i);
|
||||
if (!OBJ_cmp(policy_oid, oid))
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
828
external/boringssl/crypto/x509v3/pcy_tree.c
vendored
Normal file
828
external/boringssl/crypto/x509v3/pcy_tree.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
108
external/boringssl/crypto/x509v3/tab_test.c
vendored
Normal file
108
external/boringssl/crypto/x509v3/tab_test.c
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
/* tabtest.c */
|
||||
/*
|
||||
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
|
||||
* 1999.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Simple program to check the ext_dat.h is correct and print out problems if
|
||||
* it is not.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <openssl/base.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/obj.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
#if !defined(BORINGSSL_SHARED_LIBRARY)
|
||||
# include "ext_dat.h"
|
||||
#endif
|
||||
|
||||
int main(void)
|
||||
{
|
||||
#if !defined(BORINGSSL_SHARED_LIBRARY)
|
||||
unsigned i;
|
||||
int prev = -1, bad = 0;
|
||||
const X509V3_EXT_METHOD *const *tmp;
|
||||
CRYPTO_library_init();
|
||||
i = sizeof(standard_exts) / sizeof(X509V3_EXT_METHOD *);
|
||||
if (i != STANDARD_EXTENSION_COUNT)
|
||||
fprintf(stderr, "Extension number invalid expecting %d\n", i);
|
||||
tmp = standard_exts;
|
||||
for (i = 0; i < STANDARD_EXTENSION_COUNT; i++, tmp++) {
|
||||
if ((*tmp)->ext_nid < prev)
|
||||
bad = 1;
|
||||
prev = (*tmp)->ext_nid;
|
||||
|
||||
}
|
||||
if (bad) {
|
||||
tmp = standard_exts;
|
||||
fprintf(stderr, "Extensions out of order!\n");
|
||||
for (i = 0; i < STANDARD_EXTENSION_COUNT; i++, tmp++)
|
||||
printf("%d : %s\n", (*tmp)->ext_nid, OBJ_nid2sn((*tmp)->ext_nid));
|
||||
return 1;
|
||||
} else {
|
||||
printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
/* TODO(davidben): Fix this test in the shared library build. */
|
||||
printf("PASS\n");
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
204
external/boringssl/crypto/x509v3/v3_akey.c
vendored
Normal file
204
external/boringssl/crypto/x509v3/v3_akey.c
vendored
Normal file
@@ -0,0 +1,204 @@
|
||||
/* v3_akey.c */
|
||||
/*
|
||||
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
|
||||
* 1999.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com). */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/conf.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
#include <openssl/obj.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
|
||||
AUTHORITY_KEYID *akeyid,
|
||||
STACK_OF(CONF_VALUE)
|
||||
*extlist);
|
||||
static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
|
||||
X509V3_CTX *ctx,
|
||||
STACK_OF(CONF_VALUE) *values);
|
||||
|
||||
const X509V3_EXT_METHOD v3_akey_id = {
|
||||
NID_authority_key_identifier,
|
||||
X509V3_EXT_MULTILINE, ASN1_ITEM_ref(AUTHORITY_KEYID),
|
||||
0, 0, 0, 0,
|
||||
0, 0,
|
||||
(X509V3_EXT_I2V) i2v_AUTHORITY_KEYID,
|
||||
(X509V3_EXT_V2I)v2i_AUTHORITY_KEYID,
|
||||
0, 0,
|
||||
NULL
|
||||
};
|
||||
|
||||
static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
|
||||
AUTHORITY_KEYID *akeyid,
|
||||
STACK_OF(CONF_VALUE)
|
||||
*extlist)
|
||||
{
|
||||
char *tmp;
|
||||
if (akeyid->keyid) {
|
||||
tmp = hex_to_string(akeyid->keyid->data, akeyid->keyid->length);
|
||||
X509V3_add_value("keyid", tmp, &extlist);
|
||||
OPENSSL_free(tmp);
|
||||
}
|
||||
if (akeyid->issuer)
|
||||
extlist = i2v_GENERAL_NAMES(NULL, akeyid->issuer, extlist);
|
||||
if (akeyid->serial) {
|
||||
tmp = hex_to_string(akeyid->serial->data, akeyid->serial->length);
|
||||
X509V3_add_value("serial", tmp, &extlist);
|
||||
OPENSSL_free(tmp);
|
||||
}
|
||||
return extlist;
|
||||
}
|
||||
|
||||
/*
|
||||
* Currently two options: keyid: use the issuers subject keyid, the value
|
||||
* 'always' means its is an error if the issuer certificate doesn't have a
|
||||
* key id. issuer: use the issuers cert issuer and serial number. The default
|
||||
* is to only use this if keyid is not present. With the option 'always' this
|
||||
* is always included.
|
||||
*/
|
||||
|
||||
static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
|
||||
X509V3_CTX *ctx,
|
||||
STACK_OF(CONF_VALUE) *values)
|
||||
{
|
||||
char keyid = 0, issuer = 0;
|
||||
size_t i;
|
||||
int j;
|
||||
CONF_VALUE *cnf;
|
||||
ASN1_OCTET_STRING *ikeyid = NULL;
|
||||
X509_NAME *isname = NULL;
|
||||
GENERAL_NAMES *gens = NULL;
|
||||
GENERAL_NAME *gen = NULL;
|
||||
ASN1_INTEGER *serial = NULL;
|
||||
X509_EXTENSION *ext;
|
||||
X509 *cert;
|
||||
AUTHORITY_KEYID *akeyid;
|
||||
|
||||
for (i = 0; i < sk_CONF_VALUE_num(values); i++) {
|
||||
cnf = sk_CONF_VALUE_value(values, i);
|
||||
if (!strcmp(cnf->name, "keyid")) {
|
||||
keyid = 1;
|
||||
if (cnf->value && !strcmp(cnf->value, "always"))
|
||||
keyid = 2;
|
||||
} else if (!strcmp(cnf->name, "issuer")) {
|
||||
issuer = 1;
|
||||
if (cnf->value && !strcmp(cnf->value, "always"))
|
||||
issuer = 2;
|
||||
} else {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_UNKNOWN_OPTION);
|
||||
ERR_add_error_data(2, "name=", cnf->name);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ctx || !ctx->issuer_cert) {
|
||||
if (ctx && (ctx->flags == CTX_TEST))
|
||||
return AUTHORITY_KEYID_new();
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_NO_ISSUER_CERTIFICATE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cert = ctx->issuer_cert;
|
||||
|
||||
if (keyid) {
|
||||
j = X509_get_ext_by_NID(cert, NID_subject_key_identifier, -1);
|
||||
if ((j >= 0) && (ext = X509_get_ext(cert, j)))
|
||||
ikeyid = X509V3_EXT_d2i(ext);
|
||||
if (keyid == 2 && !ikeyid) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_UNABLE_TO_GET_ISSUER_KEYID);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if ((issuer && !ikeyid) || (issuer == 2)) {
|
||||
isname = X509_NAME_dup(X509_get_issuer_name(cert));
|
||||
serial = M_ASN1_INTEGER_dup(X509_get_serialNumber(cert));
|
||||
if (!isname || !serial) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(akeyid = AUTHORITY_KEYID_new()))
|
||||
goto err;
|
||||
|
||||
if (isname) {
|
||||
if (!(gens = sk_GENERAL_NAME_new_null())
|
||||
|| !(gen = GENERAL_NAME_new())
|
||||
|| !sk_GENERAL_NAME_push(gens, gen)) {
|
||||
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
gen->type = GEN_DIRNAME;
|
||||
gen->d.dirn = isname;
|
||||
}
|
||||
|
||||
akeyid->issuer = gens;
|
||||
akeyid->serial = serial;
|
||||
akeyid->keyid = ikeyid;
|
||||
|
||||
return akeyid;
|
||||
|
||||
err:
|
||||
X509_NAME_free(isname);
|
||||
M_ASN1_INTEGER_free(serial);
|
||||
M_ASN1_OCTET_STRING_free(ikeyid);
|
||||
return NULL;
|
||||
}
|
||||
72
external/boringssl/crypto/x509v3/v3_akeya.c
vendored
Normal file
72
external/boringssl/crypto/x509v3/v3_akeya.c
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
/* v3_akey_asn1.c */
|
||||
/*
|
||||
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
|
||||
* 1999.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com). */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/conf.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
|
||||
ASN1_SEQUENCE(AUTHORITY_KEYID) = {
|
||||
ASN1_IMP_OPT(AUTHORITY_KEYID, keyid, ASN1_OCTET_STRING, 0),
|
||||
ASN1_IMP_SEQUENCE_OF_OPT(AUTHORITY_KEYID, issuer, GENERAL_NAME, 1),
|
||||
ASN1_IMP_OPT(AUTHORITY_KEYID, serial, ASN1_INTEGER, 2)
|
||||
} ASN1_SEQUENCE_END(AUTHORITY_KEYID)
|
||||
|
||||
IMPLEMENT_ASN1_FUNCTIONS(AUTHORITY_KEYID)
|
||||
614
external/boringssl/crypto/x509v3/v3_alt.c
vendored
Normal file
614
external/boringssl/crypto/x509v3/v3_alt.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
133
external/boringssl/crypto/x509v3/v3_bcons.c
vendored
Normal file
133
external/boringssl/crypto/x509v3/v3_bcons.c
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
/* v3_bcons.c */
|
||||
/*
|
||||
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
|
||||
* 1999.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com). */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/conf.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/obj.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
|
||||
BASIC_CONSTRAINTS *bcons,
|
||||
STACK_OF(CONF_VALUE)
|
||||
*extlist);
|
||||
static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
|
||||
X509V3_CTX *ctx,
|
||||
STACK_OF(CONF_VALUE) *values);
|
||||
|
||||
const X509V3_EXT_METHOD v3_bcons = {
|
||||
NID_basic_constraints, 0,
|
||||
ASN1_ITEM_ref(BASIC_CONSTRAINTS),
|
||||
0, 0, 0, 0,
|
||||
0, 0,
|
||||
(X509V3_EXT_I2V) i2v_BASIC_CONSTRAINTS,
|
||||
(X509V3_EXT_V2I)v2i_BASIC_CONSTRAINTS,
|
||||
NULL, NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
ASN1_SEQUENCE(BASIC_CONSTRAINTS) = {
|
||||
ASN1_OPT(BASIC_CONSTRAINTS, ca, ASN1_FBOOLEAN),
|
||||
ASN1_OPT(BASIC_CONSTRAINTS, pathlen, ASN1_INTEGER)
|
||||
} ASN1_SEQUENCE_END(BASIC_CONSTRAINTS)
|
||||
|
||||
IMPLEMENT_ASN1_FUNCTIONS(BASIC_CONSTRAINTS)
|
||||
|
||||
static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
|
||||
BASIC_CONSTRAINTS *bcons,
|
||||
STACK_OF(CONF_VALUE)
|
||||
*extlist)
|
||||
{
|
||||
X509V3_add_value_bool("CA", bcons->ca, &extlist);
|
||||
X509V3_add_value_int("pathlen", bcons->pathlen, &extlist);
|
||||
return extlist;
|
||||
}
|
||||
|
||||
static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
|
||||
X509V3_CTX *ctx,
|
||||
STACK_OF(CONF_VALUE) *values)
|
||||
{
|
||||
BASIC_CONSTRAINTS *bcons = NULL;
|
||||
CONF_VALUE *val;
|
||||
size_t i;
|
||||
if (!(bcons = BASIC_CONSTRAINTS_new())) {
|
||||
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i < sk_CONF_VALUE_num(values); i++) {
|
||||
val = sk_CONF_VALUE_value(values, i);
|
||||
if (!strcmp(val->name, "CA")) {
|
||||
if (!X509V3_get_value_bool(val, &bcons->ca))
|
||||
goto err;
|
||||
} else if (!strcmp(val->name, "pathlen")) {
|
||||
if (!X509V3_get_value_int(val, &bcons->pathlen))
|
||||
goto err;
|
||||
} else {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_NAME);
|
||||
X509V3_conf_err(val);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
return bcons;
|
||||
err:
|
||||
BASIC_CONSTRAINTS_free(bcons);
|
||||
return NULL;
|
||||
}
|
||||
141
external/boringssl/crypto/x509v3/v3_bitst.c
vendored
Normal file
141
external/boringssl/crypto/x509v3/v3_bitst.c
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
/* v3_bitst.c */
|
||||
/*
|
||||
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
|
||||
* 1999.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com). */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/conf.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/obj.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
static const BIT_STRING_BITNAME ns_cert_type_table[] = {
|
||||
{0, "SSL Client", "client"},
|
||||
{1, "SSL Server", "server"},
|
||||
{2, "S/MIME", "email"},
|
||||
{3, "Object Signing", "objsign"},
|
||||
{4, "Unused", "reserved"},
|
||||
{5, "SSL CA", "sslCA"},
|
||||
{6, "S/MIME CA", "emailCA"},
|
||||
{7, "Object Signing CA", "objCA"},
|
||||
{-1, NULL, NULL}
|
||||
};
|
||||
|
||||
static const BIT_STRING_BITNAME key_usage_type_table[] = {
|
||||
{0, "Digital Signature", "digitalSignature"},
|
||||
{1, "Non Repudiation", "nonRepudiation"},
|
||||
{2, "Key Encipherment", "keyEncipherment"},
|
||||
{3, "Data Encipherment", "dataEncipherment"},
|
||||
{4, "Key Agreement", "keyAgreement"},
|
||||
{5, "Certificate Sign", "keyCertSign"},
|
||||
{6, "CRL Sign", "cRLSign"},
|
||||
{7, "Encipher Only", "encipherOnly"},
|
||||
{8, "Decipher Only", "decipherOnly"},
|
||||
{-1, NULL, NULL}
|
||||
};
|
||||
|
||||
const X509V3_EXT_METHOD v3_nscert =
|
||||
EXT_BITSTRING(NID_netscape_cert_type, ns_cert_type_table);
|
||||
const X509V3_EXT_METHOD v3_key_usage =
|
||||
EXT_BITSTRING(NID_key_usage, key_usage_type_table);
|
||||
|
||||
STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
|
||||
ASN1_BIT_STRING *bits,
|
||||
STACK_OF(CONF_VALUE) *ret)
|
||||
{
|
||||
const BIT_STRING_BITNAME *bnam;
|
||||
for (bnam = method->usr_data; bnam->lname; bnam++) {
|
||||
if (ASN1_BIT_STRING_get_bit(bits, bnam->bitnum))
|
||||
X509V3_add_value(bnam->lname, NULL, &ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
|
||||
X509V3_CTX *ctx,
|
||||
STACK_OF(CONF_VALUE) *nval)
|
||||
{
|
||||
CONF_VALUE *val;
|
||||
ASN1_BIT_STRING *bs;
|
||||
size_t i;
|
||||
const BIT_STRING_BITNAME *bnam;
|
||||
if (!(bs = M_ASN1_BIT_STRING_new())) {
|
||||
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
|
||||
val = sk_CONF_VALUE_value(nval, i);
|
||||
for (bnam = method->usr_data; bnam->lname; bnam++) {
|
||||
if (!strcmp(bnam->sname, val->name) ||
|
||||
!strcmp(bnam->lname, val->name)) {
|
||||
if (!ASN1_BIT_STRING_set_bit(bs, bnam->bitnum, 1)) {
|
||||
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
||||
M_ASN1_BIT_STRING_free(bs);
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!bnam->lname) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT);
|
||||
X509V3_conf_err(val);
|
||||
M_ASN1_BIT_STRING_free(bs);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return bs;
|
||||
}
|
||||
460
external/boringssl/crypto/x509v3/v3_conf.c
vendored
Normal file
460
external/boringssl/crypto/x509v3/v3_conf.c
vendored
Normal file
@@ -0,0 +1,460 @@
|
||||
/* v3_conf.c */
|
||||
/*
|
||||
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
|
||||
* 1999.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com). */
|
||||
|
||||
/* extension creation utilities */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/conf.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
#include <openssl/obj.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
static int v3_check_critical(char **value);
|
||||
static int v3_check_generic(char **value);
|
||||
static X509_EXTENSION *do_ext_nconf(CONF *conf, X509V3_CTX *ctx, int ext_nid,
|
||||
int crit, char *value);
|
||||
static X509_EXTENSION *v3_generic_extension(const char *ext, char *value,
|
||||
int crit, int type,
|
||||
X509V3_CTX *ctx);
|
||||
static X509_EXTENSION *do_ext_i2d(const X509V3_EXT_METHOD *method,
|
||||
int ext_nid, int crit, void *ext_struc);
|
||||
static unsigned char *generic_asn1(char *value, X509V3_CTX *ctx,
|
||||
long *ext_len);
|
||||
/* CONF *conf: Config file */
|
||||
/* char *name: Name */
|
||||
/* char *value: Value */
|
||||
X509_EXTENSION *X509V3_EXT_nconf(CONF *conf, X509V3_CTX *ctx, char *name,
|
||||
char *value)
|
||||
{
|
||||
int crit;
|
||||
int ext_type;
|
||||
X509_EXTENSION *ret;
|
||||
crit = v3_check_critical(&value);
|
||||
if ((ext_type = v3_check_generic(&value)))
|
||||
return v3_generic_extension(name, value, crit, ext_type, ctx);
|
||||
ret = do_ext_nconf(conf, ctx, OBJ_sn2nid(name), crit, value);
|
||||
if (!ret) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_ERROR_IN_EXTENSION);
|
||||
ERR_add_error_data(4, "name=", name, ", value=", value);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* CONF *conf: Config file */
|
||||
/* char *value: Value */
|
||||
X509_EXTENSION *X509V3_EXT_nconf_nid(CONF *conf, X509V3_CTX *ctx, int ext_nid,
|
||||
char *value)
|
||||
{
|
||||
int crit;
|
||||
int ext_type;
|
||||
crit = v3_check_critical(&value);
|
||||
if ((ext_type = v3_check_generic(&value)))
|
||||
return v3_generic_extension(OBJ_nid2sn(ext_nid),
|
||||
value, crit, ext_type, ctx);
|
||||
return do_ext_nconf(conf, ctx, ext_nid, crit, value);
|
||||
}
|
||||
|
||||
/* CONF *conf: Config file */
|
||||
/* char *value: Value */
|
||||
static X509_EXTENSION *do_ext_nconf(CONF *conf, X509V3_CTX *ctx, int ext_nid,
|
||||
int crit, char *value)
|
||||
{
|
||||
const X509V3_EXT_METHOD *method;
|
||||
X509_EXTENSION *ext;
|
||||
STACK_OF(CONF_VALUE) *nval;
|
||||
void *ext_struc;
|
||||
if (ext_nid == NID_undef) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_UNKNOWN_EXTENSION_NAME);
|
||||
return NULL;
|
||||
}
|
||||
if (!(method = X509V3_EXT_get_nid(ext_nid))) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_UNKNOWN_EXTENSION);
|
||||
return NULL;
|
||||
}
|
||||
/* Now get internal extension representation based on type */
|
||||
if (method->v2i) {
|
||||
if (*value == '@')
|
||||
nval = NCONF_get_section(conf, value + 1);
|
||||
else
|
||||
nval = X509V3_parse_list(value);
|
||||
if (sk_CONF_VALUE_num(nval) <= 0) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_EXTENSION_STRING);
|
||||
ERR_add_error_data(4, "name=", OBJ_nid2sn(ext_nid), ",section=",
|
||||
value);
|
||||
return NULL;
|
||||
}
|
||||
ext_struc = method->v2i(method, ctx, nval);
|
||||
if (*value != '@')
|
||||
sk_CONF_VALUE_pop_free(nval, X509V3_conf_free);
|
||||
if (!ext_struc)
|
||||
return NULL;
|
||||
} else if (method->s2i) {
|
||||
if (!(ext_struc = method->s2i(method, ctx, value)))
|
||||
return NULL;
|
||||
} else if (method->r2i) {
|
||||
if (!ctx->db || !ctx->db_meth) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_NO_CONFIG_DATABASE);
|
||||
return NULL;
|
||||
}
|
||||
if (!(ext_struc = method->r2i(method, ctx, value)))
|
||||
return NULL;
|
||||
} else {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED);
|
||||
ERR_add_error_data(2, "name=", OBJ_nid2sn(ext_nid));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ext = do_ext_i2d(method, ext_nid, crit, ext_struc);
|
||||
if (method->it)
|
||||
ASN1_item_free(ext_struc, ASN1_ITEM_ptr(method->it));
|
||||
else
|
||||
method->ext_free(ext_struc);
|
||||
return ext;
|
||||
|
||||
}
|
||||
|
||||
static X509_EXTENSION *do_ext_i2d(const X509V3_EXT_METHOD *method,
|
||||
int ext_nid, int crit, void *ext_struc)
|
||||
{
|
||||
unsigned char *ext_der;
|
||||
int ext_len;
|
||||
ASN1_OCTET_STRING *ext_oct;
|
||||
X509_EXTENSION *ext;
|
||||
/* Convert internal representation to DER */
|
||||
if (method->it) {
|
||||
ext_der = NULL;
|
||||
ext_len =
|
||||
ASN1_item_i2d(ext_struc, &ext_der, ASN1_ITEM_ptr(method->it));
|
||||
if (ext_len < 0)
|
||||
goto merr;
|
||||
} else {
|
||||
unsigned char *p;
|
||||
ext_len = method->i2d(ext_struc, NULL);
|
||||
if (!(ext_der = OPENSSL_malloc(ext_len)))
|
||||
goto merr;
|
||||
p = ext_der;
|
||||
method->i2d(ext_struc, &p);
|
||||
}
|
||||
if (!(ext_oct = M_ASN1_OCTET_STRING_new()))
|
||||
goto merr;
|
||||
ext_oct->data = ext_der;
|
||||
ext_oct->length = ext_len;
|
||||
|
||||
ext = X509_EXTENSION_create_by_NID(NULL, ext_nid, crit, ext_oct);
|
||||
if (!ext)
|
||||
goto merr;
|
||||
M_ASN1_OCTET_STRING_free(ext_oct);
|
||||
|
||||
return ext;
|
||||
|
||||
merr:
|
||||
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
/* Given an internal structure, nid and critical flag create an extension */
|
||||
|
||||
X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc)
|
||||
{
|
||||
const X509V3_EXT_METHOD *method;
|
||||
if (!(method = X509V3_EXT_get_nid(ext_nid))) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_UNKNOWN_EXTENSION);
|
||||
return NULL;
|
||||
}
|
||||
return do_ext_i2d(method, ext_nid, crit, ext_struc);
|
||||
}
|
||||
|
||||
/* Check the extension string for critical flag */
|
||||
static int v3_check_critical(char **value)
|
||||
{
|
||||
char *p = *value;
|
||||
if ((strlen(p) < 9) || strncmp(p, "critical,", 9))
|
||||
return 0;
|
||||
p += 9;
|
||||
while (isspace((unsigned char)*p))
|
||||
p++;
|
||||
*value = p;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Check extension string for generic extension and return the type */
|
||||
static int v3_check_generic(char **value)
|
||||
{
|
||||
int gen_type = 0;
|
||||
char *p = *value;
|
||||
if ((strlen(p) >= 4) && !strncmp(p, "DER:", 4)) {
|
||||
p += 4;
|
||||
gen_type = 1;
|
||||
} else if ((strlen(p) >= 5) && !strncmp(p, "ASN1:", 5)) {
|
||||
p += 5;
|
||||
gen_type = 2;
|
||||
} else
|
||||
return 0;
|
||||
|
||||
while (isspace((unsigned char)*p))
|
||||
p++;
|
||||
*value = p;
|
||||
return gen_type;
|
||||
}
|
||||
|
||||
/* Create a generic extension: for now just handle DER type */
|
||||
static X509_EXTENSION *v3_generic_extension(const char *ext, char *value,
|
||||
int crit, int gen_type,
|
||||
X509V3_CTX *ctx)
|
||||
{
|
||||
unsigned char *ext_der = NULL;
|
||||
long ext_len = 0;
|
||||
ASN1_OBJECT *obj = NULL;
|
||||
ASN1_OCTET_STRING *oct = NULL;
|
||||
X509_EXTENSION *extension = NULL;
|
||||
if (!(obj = OBJ_txt2obj(ext, 0))) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_EXTENSION_NAME_ERROR);
|
||||
ERR_add_error_data(2, "name=", ext);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (gen_type == 1)
|
||||
ext_der = string_to_hex(value, &ext_len);
|
||||
else if (gen_type == 2)
|
||||
ext_der = generic_asn1(value, ctx, &ext_len);
|
||||
|
||||
if (ext_der == NULL) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_EXTENSION_VALUE_ERROR);
|
||||
ERR_add_error_data(2, "value=", value);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!(oct = M_ASN1_OCTET_STRING_new())) {
|
||||
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
oct->data = ext_der;
|
||||
oct->length = ext_len;
|
||||
ext_der = NULL;
|
||||
|
||||
extension = X509_EXTENSION_create_by_OBJ(NULL, obj, crit, oct);
|
||||
|
||||
err:
|
||||
ASN1_OBJECT_free(obj);
|
||||
M_ASN1_OCTET_STRING_free(oct);
|
||||
if (ext_der)
|
||||
OPENSSL_free(ext_der);
|
||||
return extension;
|
||||
|
||||
}
|
||||
|
||||
static unsigned char *generic_asn1(char *value, X509V3_CTX *ctx,
|
||||
long *ext_len)
|
||||
{
|
||||
ASN1_TYPE *typ;
|
||||
unsigned char *ext_der = NULL;
|
||||
typ = ASN1_generate_v3(value, ctx);
|
||||
if (typ == NULL)
|
||||
return NULL;
|
||||
*ext_len = i2d_ASN1_TYPE(typ, &ext_der);
|
||||
ASN1_TYPE_free(typ);
|
||||
return ext_der;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is the main function: add a bunch of extensions based on a config
|
||||
* file section to an extension STACK.
|
||||
*/
|
||||
|
||||
int X509V3_EXT_add_nconf_sk(CONF *conf, X509V3_CTX *ctx, char *section,
|
||||
STACK_OF(X509_EXTENSION) **sk)
|
||||
{
|
||||
X509_EXTENSION *ext;
|
||||
STACK_OF(CONF_VALUE) *nval;
|
||||
CONF_VALUE *val;
|
||||
size_t i;
|
||||
if (!(nval = NCONF_get_section(conf, section)))
|
||||
return 0;
|
||||
for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
|
||||
val = sk_CONF_VALUE_value(nval, i);
|
||||
if (!(ext = X509V3_EXT_nconf(conf, ctx, val->name, val->value)))
|
||||
return 0;
|
||||
if (sk)
|
||||
X509v3_add_ext(sk, ext, -1);
|
||||
X509_EXTENSION_free(ext);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convenience functions to add extensions to a certificate, CRL and request
|
||||
*/
|
||||
|
||||
int X509V3_EXT_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section,
|
||||
X509 *cert)
|
||||
{
|
||||
STACK_OF(X509_EXTENSION) **sk = NULL;
|
||||
if (cert)
|
||||
sk = &cert->cert_info->extensions;
|
||||
return X509V3_EXT_add_nconf_sk(conf, ctx, section, sk);
|
||||
}
|
||||
|
||||
/* Same as above but for a CRL */
|
||||
|
||||
int X509V3_EXT_CRL_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section,
|
||||
X509_CRL *crl)
|
||||
{
|
||||
STACK_OF(X509_EXTENSION) **sk = NULL;
|
||||
if (crl)
|
||||
sk = &crl->crl->extensions;
|
||||
return X509V3_EXT_add_nconf_sk(conf, ctx, section, sk);
|
||||
}
|
||||
|
||||
/* Add extensions to certificate request */
|
||||
|
||||
int X509V3_EXT_REQ_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section,
|
||||
X509_REQ *req)
|
||||
{
|
||||
STACK_OF(X509_EXTENSION) *extlist = NULL, **sk = NULL;
|
||||
int i;
|
||||
if (req)
|
||||
sk = &extlist;
|
||||
i = X509V3_EXT_add_nconf_sk(conf, ctx, section, sk);
|
||||
if (!i || !sk)
|
||||
return i;
|
||||
i = X509_REQ_add_extensions(req, extlist);
|
||||
sk_X509_EXTENSION_pop_free(extlist, X509_EXTENSION_free);
|
||||
return i;
|
||||
}
|
||||
|
||||
/* Config database functions */
|
||||
|
||||
char *X509V3_get_string(X509V3_CTX *ctx, char *name, char *section)
|
||||
{
|
||||
if (!ctx->db || !ctx->db_meth || !ctx->db_meth->get_string) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_OPERATION_NOT_DEFINED);
|
||||
return NULL;
|
||||
}
|
||||
if (ctx->db_meth->get_string)
|
||||
return ctx->db_meth->get_string(ctx->db, name, section);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STACK_OF(CONF_VALUE) *X509V3_get_section(X509V3_CTX *ctx, char *section)
|
||||
{
|
||||
if (!ctx->db || !ctx->db_meth || !ctx->db_meth->get_section) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_OPERATION_NOT_DEFINED);
|
||||
return NULL;
|
||||
}
|
||||
if (ctx->db_meth->get_section)
|
||||
return ctx->db_meth->get_section(ctx->db, section);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void X509V3_string_free(X509V3_CTX *ctx, char *str)
|
||||
{
|
||||
if (!str)
|
||||
return;
|
||||
if (ctx->db_meth->free_string)
|
||||
ctx->db_meth->free_string(ctx->db, str);
|
||||
}
|
||||
|
||||
void X509V3_section_free(X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section)
|
||||
{
|
||||
if (!section)
|
||||
return;
|
||||
if (ctx->db_meth->free_section)
|
||||
ctx->db_meth->free_section(ctx->db, section);
|
||||
}
|
||||
|
||||
static char *nconf_get_string(void *db, char *section, char *value)
|
||||
{
|
||||
/* TODO(fork): this should return a const value. */
|
||||
return (char *)NCONF_get_string(db, section, value);
|
||||
}
|
||||
|
||||
static STACK_OF(CONF_VALUE) *nconf_get_section(void *db, char *section)
|
||||
{
|
||||
return NCONF_get_section(db, section);
|
||||
}
|
||||
|
||||
static const X509V3_CONF_METHOD nconf_method = {
|
||||
nconf_get_string,
|
||||
nconf_get_section,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
void X509V3_set_nconf(X509V3_CTX *ctx, CONF *conf)
|
||||
{
|
||||
ctx->db_meth = &nconf_method;
|
||||
ctx->db = conf;
|
||||
}
|
||||
|
||||
void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subj, X509_REQ *req,
|
||||
X509_CRL *crl, int flags)
|
||||
{
|
||||
ctx->issuer_cert = issuer;
|
||||
ctx->subject_cert = subj;
|
||||
ctx->crl = crl;
|
||||
ctx->subject_req = req;
|
||||
ctx->flags = flags;
|
||||
}
|
||||
496
external/boringssl/crypto/x509v3/v3_cpols.c
vendored
Normal file
496
external/boringssl/crypto/x509v3/v3_cpols.c
vendored
Normal file
@@ -0,0 +1,496 @@
|
||||
/* v3_cpols.c */
|
||||
/*
|
||||
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
|
||||
* 1999.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999-2004 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/conf.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/mem.h>
|
||||
#include <openssl/obj.h>
|
||||
#include <openssl/stack.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
#include "pcy_int.h"
|
||||
|
||||
/* Certificate policies extension support: this one is a bit complex... */
|
||||
|
||||
static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol,
|
||||
BIO *out, int indent);
|
||||
static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method,
|
||||
X509V3_CTX *ctx, char *value);
|
||||
static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals,
|
||||
int indent);
|
||||
static void print_notice(BIO *out, USERNOTICE *notice, int indent);
|
||||
static POLICYINFO *policy_section(X509V3_CTX *ctx,
|
||||
STACK_OF(CONF_VALUE) *polstrs, int ia5org);
|
||||
static POLICYQUALINFO *notice_section(X509V3_CTX *ctx,
|
||||
STACK_OF(CONF_VALUE) *unot, int ia5org);
|
||||
static int nref_nos(STACK_OF(ASN1_INTEGER) *nnums, STACK_OF(CONF_VALUE) *nos);
|
||||
|
||||
const X509V3_EXT_METHOD v3_cpols = {
|
||||
NID_certificate_policies, 0, ASN1_ITEM_ref(CERTIFICATEPOLICIES),
|
||||
0, 0, 0, 0,
|
||||
0, 0,
|
||||
0, 0,
|
||||
(X509V3_EXT_I2R)i2r_certpol,
|
||||
(X509V3_EXT_R2I)r2i_certpol,
|
||||
NULL
|
||||
};
|
||||
|
||||
ASN1_ITEM_TEMPLATE(CERTIFICATEPOLICIES) =
|
||||
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, CERTIFICATEPOLICIES, POLICYINFO)
|
||||
ASN1_ITEM_TEMPLATE_END(CERTIFICATEPOLICIES)
|
||||
|
||||
IMPLEMENT_ASN1_FUNCTIONS(CERTIFICATEPOLICIES)
|
||||
|
||||
ASN1_SEQUENCE(POLICYINFO) = {
|
||||
ASN1_SIMPLE(POLICYINFO, policyid, ASN1_OBJECT),
|
||||
ASN1_SEQUENCE_OF_OPT(POLICYINFO, qualifiers, POLICYQUALINFO)
|
||||
} ASN1_SEQUENCE_END(POLICYINFO)
|
||||
|
||||
IMPLEMENT_ASN1_FUNCTIONS(POLICYINFO)
|
||||
|
||||
ASN1_ADB_TEMPLATE(policydefault) = ASN1_SIMPLE(POLICYQUALINFO, d.other, ASN1_ANY);
|
||||
|
||||
ASN1_ADB(POLICYQUALINFO) = {
|
||||
ADB_ENTRY(NID_id_qt_cps, ASN1_SIMPLE(POLICYQUALINFO, d.cpsuri, ASN1_IA5STRING)),
|
||||
ADB_ENTRY(NID_id_qt_unotice, ASN1_SIMPLE(POLICYQUALINFO, d.usernotice, USERNOTICE))
|
||||
} ASN1_ADB_END(POLICYQUALINFO, 0, pqualid, 0, &policydefault_tt, NULL);
|
||||
|
||||
ASN1_SEQUENCE(POLICYQUALINFO) = {
|
||||
ASN1_SIMPLE(POLICYQUALINFO, pqualid, ASN1_OBJECT),
|
||||
ASN1_ADB_OBJECT(POLICYQUALINFO)
|
||||
} ASN1_SEQUENCE_END(POLICYQUALINFO)
|
||||
|
||||
IMPLEMENT_ASN1_FUNCTIONS(POLICYQUALINFO)
|
||||
|
||||
ASN1_SEQUENCE(USERNOTICE) = {
|
||||
ASN1_OPT(USERNOTICE, noticeref, NOTICEREF),
|
||||
ASN1_OPT(USERNOTICE, exptext, DISPLAYTEXT)
|
||||
} ASN1_SEQUENCE_END(USERNOTICE)
|
||||
|
||||
IMPLEMENT_ASN1_FUNCTIONS(USERNOTICE)
|
||||
|
||||
ASN1_SEQUENCE(NOTICEREF) = {
|
||||
ASN1_SIMPLE(NOTICEREF, organization, DISPLAYTEXT),
|
||||
ASN1_SEQUENCE_OF(NOTICEREF, noticenos, ASN1_INTEGER)
|
||||
} ASN1_SEQUENCE_END(NOTICEREF)
|
||||
|
||||
IMPLEMENT_ASN1_FUNCTIONS(NOTICEREF)
|
||||
|
||||
static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method,
|
||||
X509V3_CTX *ctx, char *value)
|
||||
{
|
||||
STACK_OF(POLICYINFO) *pols = NULL;
|
||||
char *pstr;
|
||||
POLICYINFO *pol;
|
||||
ASN1_OBJECT *pobj;
|
||||
STACK_OF(CONF_VALUE) *vals;
|
||||
CONF_VALUE *cnf;
|
||||
size_t i;
|
||||
int ia5org;
|
||||
pols = sk_POLICYINFO_new_null();
|
||||
if (pols == NULL) {
|
||||
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
vals = X509V3_parse_list(value);
|
||||
if (vals == NULL) {
|
||||
OPENSSL_PUT_ERROR(X509V3, ERR_R_X509V3_LIB);
|
||||
goto err;
|
||||
}
|
||||
ia5org = 0;
|
||||
for (i = 0; i < sk_CONF_VALUE_num(vals); i++) {
|
||||
cnf = sk_CONF_VALUE_value(vals, i);
|
||||
if (cnf->value || !cnf->name) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_POLICY_IDENTIFIER);
|
||||
X509V3_conf_err(cnf);
|
||||
goto err;
|
||||
}
|
||||
pstr = cnf->name;
|
||||
if (!strcmp(pstr, "ia5org")) {
|
||||
ia5org = 1;
|
||||
continue;
|
||||
} else if (*pstr == '@') {
|
||||
STACK_OF(CONF_VALUE) *polsect;
|
||||
polsect = X509V3_get_section(ctx, pstr + 1);
|
||||
if (!polsect) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_SECTION);
|
||||
|
||||
X509V3_conf_err(cnf);
|
||||
goto err;
|
||||
}
|
||||
pol = policy_section(ctx, polsect, ia5org);
|
||||
X509V3_section_free(ctx, polsect);
|
||||
if (!pol)
|
||||
goto err;
|
||||
} else {
|
||||
if (!(pobj = OBJ_txt2obj(cnf->name, 0))) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_OBJECT_IDENTIFIER);
|
||||
X509V3_conf_err(cnf);
|
||||
goto err;
|
||||
}
|
||||
pol = POLICYINFO_new();
|
||||
if (pol == NULL) {
|
||||
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
||||
ASN1_OBJECT_free(pobj);
|
||||
goto err;
|
||||
}
|
||||
pol->policyid = pobj;
|
||||
}
|
||||
if (!sk_POLICYINFO_push(pols, pol)) {
|
||||
POLICYINFO_free(pol);
|
||||
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
sk_CONF_VALUE_pop_free(vals, X509V3_conf_free);
|
||||
return pols;
|
||||
err:
|
||||
sk_CONF_VALUE_pop_free(vals, X509V3_conf_free);
|
||||
sk_POLICYINFO_pop_free(pols, POLICYINFO_free);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static POLICYINFO *policy_section(X509V3_CTX *ctx,
|
||||
STACK_OF(CONF_VALUE) *polstrs, int ia5org)
|
||||
{
|
||||
size_t i;
|
||||
CONF_VALUE *cnf;
|
||||
POLICYINFO *pol;
|
||||
POLICYQUALINFO *qual;
|
||||
if (!(pol = POLICYINFO_new()))
|
||||
goto merr;
|
||||
for (i = 0; i < sk_CONF_VALUE_num(polstrs); i++) {
|
||||
cnf = sk_CONF_VALUE_value(polstrs, i);
|
||||
if (!strcmp(cnf->name, "policyIdentifier")) {
|
||||
ASN1_OBJECT *pobj;
|
||||
if (!(pobj = OBJ_txt2obj(cnf->value, 0))) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_OBJECT_IDENTIFIER);
|
||||
X509V3_conf_err(cnf);
|
||||
goto err;
|
||||
}
|
||||
pol->policyid = pobj;
|
||||
|
||||
} else if (!name_cmp(cnf->name, "CPS")) {
|
||||
if (!pol->qualifiers)
|
||||
pol->qualifiers = sk_POLICYQUALINFO_new_null();
|
||||
if (!(qual = POLICYQUALINFO_new()))
|
||||
goto merr;
|
||||
if (!sk_POLICYQUALINFO_push(pol->qualifiers, qual))
|
||||
goto merr;
|
||||
/* TODO(fork): const correctness */
|
||||
qual->pqualid = (ASN1_OBJECT *)OBJ_nid2obj(NID_id_qt_cps);
|
||||
if (qual->pqualid == NULL) {
|
||||
OPENSSL_PUT_ERROR(X509V3, ERR_R_INTERNAL_ERROR);
|
||||
goto err;
|
||||
}
|
||||
qual->d.cpsuri = M_ASN1_IA5STRING_new();
|
||||
if (qual->d.cpsuri == NULL) {
|
||||
goto err;
|
||||
}
|
||||
if (!ASN1_STRING_set(qual->d.cpsuri, cnf->value,
|
||||
strlen(cnf->value)))
|
||||
goto merr;
|
||||
} else if (!name_cmp(cnf->name, "userNotice")) {
|
||||
STACK_OF(CONF_VALUE) *unot;
|
||||
if (*cnf->value != '@') {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_EXPECTED_A_SECTION_NAME);
|
||||
X509V3_conf_err(cnf);
|
||||
goto err;
|
||||
}
|
||||
unot = X509V3_get_section(ctx, cnf->value + 1);
|
||||
if (!unot) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_SECTION);
|
||||
|
||||
X509V3_conf_err(cnf);
|
||||
goto err;
|
||||
}
|
||||
qual = notice_section(ctx, unot, ia5org);
|
||||
X509V3_section_free(ctx, unot);
|
||||
if (!qual)
|
||||
goto err;
|
||||
if (!pol->qualifiers)
|
||||
pol->qualifiers = sk_POLICYQUALINFO_new_null();
|
||||
if (!sk_POLICYQUALINFO_push(pol->qualifiers, qual))
|
||||
goto merr;
|
||||
} else {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_OPTION);
|
||||
|
||||
X509V3_conf_err(cnf);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
if (!pol->policyid) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_NO_POLICY_IDENTIFIER);
|
||||
goto err;
|
||||
}
|
||||
|
||||
return pol;
|
||||
|
||||
merr:
|
||||
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
||||
|
||||
err:
|
||||
POLICYINFO_free(pol);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
static POLICYQUALINFO *notice_section(X509V3_CTX *ctx,
|
||||
STACK_OF(CONF_VALUE) *unot, int ia5org)
|
||||
{
|
||||
size_t i;
|
||||
int ret;
|
||||
CONF_VALUE *cnf;
|
||||
USERNOTICE *not;
|
||||
POLICYQUALINFO *qual;
|
||||
if (!(qual = POLICYQUALINFO_new()))
|
||||
goto merr;
|
||||
/* TODO(fork): const correctness */
|
||||
qual->pqualid = (ASN1_OBJECT *)OBJ_nid2obj(NID_id_qt_unotice);
|
||||
if (qual->pqualid == NULL) {
|
||||
OPENSSL_PUT_ERROR(X509V3, ERR_R_INTERNAL_ERROR);
|
||||
goto err;
|
||||
}
|
||||
if (!(not = USERNOTICE_new()))
|
||||
goto merr;
|
||||
qual->d.usernotice = not;
|
||||
for (i = 0; i < sk_CONF_VALUE_num(unot); i++) {
|
||||
cnf = sk_CONF_VALUE_value(unot, i);
|
||||
if (!strcmp(cnf->name, "explicitText")) {
|
||||
not->exptext = M_ASN1_VISIBLESTRING_new();
|
||||
if (not->exptext == NULL)
|
||||
goto merr;
|
||||
if (!ASN1_STRING_set(not->exptext, cnf->value,
|
||||
strlen(cnf->value)))
|
||||
goto merr;
|
||||
} else if (!strcmp(cnf->name, "organization")) {
|
||||
NOTICEREF *nref;
|
||||
if (!not->noticeref) {
|
||||
if (!(nref = NOTICEREF_new()))
|
||||
goto merr;
|
||||
not->noticeref = nref;
|
||||
} else
|
||||
nref = not->noticeref;
|
||||
if (ia5org)
|
||||
nref->organization->type = V_ASN1_IA5STRING;
|
||||
else
|
||||
nref->organization->type = V_ASN1_VISIBLESTRING;
|
||||
if (!ASN1_STRING_set(nref->organization, cnf->value,
|
||||
strlen(cnf->value)))
|
||||
goto merr;
|
||||
} else if (!strcmp(cnf->name, "noticeNumbers")) {
|
||||
NOTICEREF *nref;
|
||||
STACK_OF(CONF_VALUE) *nos;
|
||||
if (!not->noticeref) {
|
||||
if (!(nref = NOTICEREF_new()))
|
||||
goto merr;
|
||||
not->noticeref = nref;
|
||||
} else
|
||||
nref = not->noticeref;
|
||||
nos = X509V3_parse_list(cnf->value);
|
||||
if (!nos || !sk_CONF_VALUE_num(nos)) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_NUMBERS);
|
||||
X509V3_conf_err(cnf);
|
||||
goto err;
|
||||
}
|
||||
ret = nref_nos(nref->noticenos, nos);
|
||||
sk_CONF_VALUE_pop_free(nos, X509V3_conf_free);
|
||||
if (!ret)
|
||||
goto err;
|
||||
} else {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_OPTION);
|
||||
X509V3_conf_err(cnf);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if (not->noticeref &&
|
||||
(!not->noticeref->noticenos || !not->noticeref->organization)) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_NEED_ORGANIZATION_AND_NUMBERS);
|
||||
goto err;
|
||||
}
|
||||
|
||||
return qual;
|
||||
|
||||
merr:
|
||||
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
||||
|
||||
err:
|
||||
POLICYQUALINFO_free(qual);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int nref_nos(STACK_OF(ASN1_INTEGER) *nnums, STACK_OF(CONF_VALUE) *nos)
|
||||
{
|
||||
CONF_VALUE *cnf;
|
||||
ASN1_INTEGER *aint;
|
||||
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < sk_CONF_VALUE_num(nos); i++) {
|
||||
cnf = sk_CONF_VALUE_value(nos, i);
|
||||
if (!(aint = s2i_ASN1_INTEGER(NULL, cnf->name))) {
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_NUMBER);
|
||||
goto err;
|
||||
}
|
||||
if (!sk_ASN1_INTEGER_push(nnums, aint))
|
||||
goto merr;
|
||||
}
|
||||
return 1;
|
||||
|
||||
merr:
|
||||
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
||||
|
||||
err:
|
||||
sk_ASN1_INTEGER_pop_free(nnums, ASN1_STRING_free);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol,
|
||||
BIO *out, int indent)
|
||||
{
|
||||
size_t i;
|
||||
POLICYINFO *pinfo;
|
||||
/* First print out the policy OIDs */
|
||||
for (i = 0; i < sk_POLICYINFO_num(pol); i++) {
|
||||
pinfo = sk_POLICYINFO_value(pol, i);
|
||||
BIO_printf(out, "%*sPolicy: ", indent, "");
|
||||
i2a_ASN1_OBJECT(out, pinfo->policyid);
|
||||
BIO_puts(out, "\n");
|
||||
if (pinfo->qualifiers)
|
||||
print_qualifiers(out, pinfo->qualifiers, indent + 2);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals,
|
||||
int indent)
|
||||
{
|
||||
POLICYQUALINFO *qualinfo;
|
||||
size_t i;
|
||||
for (i = 0; i < sk_POLICYQUALINFO_num(quals); i++) {
|
||||
qualinfo = sk_POLICYQUALINFO_value(quals, i);
|
||||
switch (OBJ_obj2nid(qualinfo->pqualid)) {
|
||||
case NID_id_qt_cps:
|
||||
BIO_printf(out, "%*sCPS: %s\n", indent, "",
|
||||
qualinfo->d.cpsuri->data);
|
||||
break;
|
||||
|
||||
case NID_id_qt_unotice:
|
||||
BIO_printf(out, "%*sUser Notice:\n", indent, "");
|
||||
print_notice(out, qualinfo->d.usernotice, indent + 2);
|
||||
break;
|
||||
|
||||
default:
|
||||
BIO_printf(out, "%*sUnknown Qualifier: ", indent + 2, "");
|
||||
|
||||
i2a_ASN1_OBJECT(out, qualinfo->pqualid);
|
||||
BIO_puts(out, "\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void print_notice(BIO *out, USERNOTICE *notice, int indent)
|
||||
{
|
||||
size_t i;
|
||||
if (notice->noticeref) {
|
||||
NOTICEREF *ref;
|
||||
ref = notice->noticeref;
|
||||
BIO_printf(out, "%*sOrganization: %s\n", indent, "",
|
||||
ref->organization->data);
|
||||
BIO_printf(out, "%*sNumber%s: ", indent, "",
|
||||
sk_ASN1_INTEGER_num(ref->noticenos) > 1 ? "s" : "");
|
||||
for (i = 0; i < sk_ASN1_INTEGER_num(ref->noticenos); i++) {
|
||||
ASN1_INTEGER *num;
|
||||
char *tmp;
|
||||
num = sk_ASN1_INTEGER_value(ref->noticenos, i);
|
||||
if (i)
|
||||
BIO_puts(out, ", ");
|
||||
tmp = i2s_ASN1_INTEGER(NULL, num);
|
||||
BIO_puts(out, tmp);
|
||||
OPENSSL_free(tmp);
|
||||
}
|
||||
BIO_puts(out, "\n");
|
||||
}
|
||||
if (notice->exptext)
|
||||
BIO_printf(out, "%*sExplicit Text: %s\n", indent, "",
|
||||
notice->exptext->data);
|
||||
}
|
||||
|
||||
void X509_POLICY_NODE_print(BIO *out, X509_POLICY_NODE *node, int indent)
|
||||
{
|
||||
const X509_POLICY_DATA *dat = node->data;
|
||||
|
||||
BIO_printf(out, "%*sPolicy: ", indent, "");
|
||||
|
||||
i2a_ASN1_OBJECT(out, dat->valid_policy);
|
||||
BIO_puts(out, "\n");
|
||||
BIO_printf(out, "%*s%s\n", indent + 2, "",
|
||||
node_data_critical(dat) ? "Critical" : "Non Critical");
|
||||
if (dat->qualifier_set)
|
||||
print_qualifiers(out, dat->qualifier_set, indent + 2);
|
||||
else
|
||||
BIO_printf(out, "%*sNo Qualifiers\n", indent + 2, "");
|
||||
}
|
||||
561
external/boringssl/crypto/x509v3/v3_crld.c
vendored
Normal file
561
external/boringssl/crypto/x509v3/v3_crld.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
100
external/boringssl/crypto/x509v3/v3_enum.c
vendored
Normal file
100
external/boringssl/crypto/x509v3/v3_enum.c
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
/* v3_enum.c */
|
||||
/*
|
||||
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
|
||||
* 1999.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com). */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <openssl/buf.h>
|
||||
#include <openssl/obj.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
static const ENUMERATED_NAMES crl_reasons[] = {
|
||||
{CRL_REASON_UNSPECIFIED, "Unspecified", "unspecified"},
|
||||
{CRL_REASON_KEY_COMPROMISE, "Key Compromise", "keyCompromise"},
|
||||
{CRL_REASON_CA_COMPROMISE, "CA Compromise", "CACompromise"},
|
||||
{CRL_REASON_AFFILIATION_CHANGED, "Affiliation Changed",
|
||||
"affiliationChanged"},
|
||||
{CRL_REASON_SUPERSEDED, "Superseded", "superseded"},
|
||||
{CRL_REASON_CESSATION_OF_OPERATION,
|
||||
"Cessation Of Operation", "cessationOfOperation"},
|
||||
{CRL_REASON_CERTIFICATE_HOLD, "Certificate Hold", "certificateHold"},
|
||||
{CRL_REASON_REMOVE_FROM_CRL, "Remove From CRL", "removeFromCRL"},
|
||||
{CRL_REASON_PRIVILEGE_WITHDRAWN, "Privilege Withdrawn",
|
||||
"privilegeWithdrawn"},
|
||||
{CRL_REASON_AA_COMPROMISE, "AA Compromise", "AACompromise"},
|
||||
{-1, NULL, NULL}
|
||||
};
|
||||
|
||||
const X509V3_EXT_METHOD v3_crl_reason = {
|
||||
NID_crl_reason, 0, ASN1_ITEM_ref(ASN1_ENUMERATED),
|
||||
0, 0, 0, 0,
|
||||
(X509V3_EXT_I2S)i2s_ASN1_ENUMERATED_TABLE,
|
||||
0,
|
||||
0, 0, 0, 0,
|
||||
(void *)crl_reasons
|
||||
};
|
||||
|
||||
char *i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *method, ASN1_ENUMERATED *e)
|
||||
{
|
||||
const ENUMERATED_NAMES *enam;
|
||||
long strval;
|
||||
strval = ASN1_ENUMERATED_get(e);
|
||||
for (enam = method->usr_data; enam->lname; enam++) {
|
||||
if (strval == enam->bitnum)
|
||||
return BUF_strdup(enam->lname);
|
||||
}
|
||||
return i2s_ASN1_ENUMERATED(method, e);
|
||||
}
|
||||
148
external/boringssl/crypto/x509v3/v3_extku.c
vendored
Normal file
148
external/boringssl/crypto/x509v3/v3_extku.c
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
/* v3_extku.c */
|
||||
/*
|
||||
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
|
||||
* 1999.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com). */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/conf.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/obj.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
static void *v2i_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD *method,
|
||||
X509V3_CTX *ctx,
|
||||
STACK_OF(CONF_VALUE) *nval);
|
||||
static STACK_OF(CONF_VALUE) *i2v_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD
|
||||
*method, void *eku, STACK_OF(CONF_VALUE)
|
||||
*extlist);
|
||||
|
||||
const X509V3_EXT_METHOD v3_ext_ku = {
|
||||
NID_ext_key_usage, 0,
|
||||
ASN1_ITEM_ref(EXTENDED_KEY_USAGE),
|
||||
0, 0, 0, 0,
|
||||
0, 0,
|
||||
i2v_EXTENDED_KEY_USAGE,
|
||||
v2i_EXTENDED_KEY_USAGE,
|
||||
0, 0,
|
||||
NULL
|
||||
};
|
||||
|
||||
/* NB OCSP acceptable responses also is a SEQUENCE OF OBJECT */
|
||||
const X509V3_EXT_METHOD v3_ocsp_accresp = {
|
||||
NID_id_pkix_OCSP_acceptableResponses, 0,
|
||||
ASN1_ITEM_ref(EXTENDED_KEY_USAGE),
|
||||
0, 0, 0, 0,
|
||||
0, 0,
|
||||
i2v_EXTENDED_KEY_USAGE,
|
||||
v2i_EXTENDED_KEY_USAGE,
|
||||
0, 0,
|
||||
NULL
|
||||
};
|
||||
|
||||
ASN1_ITEM_TEMPLATE(EXTENDED_KEY_USAGE) =
|
||||
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, EXTENDED_KEY_USAGE, ASN1_OBJECT)
|
||||
ASN1_ITEM_TEMPLATE_END(EXTENDED_KEY_USAGE)
|
||||
|
||||
IMPLEMENT_ASN1_FUNCTIONS(EXTENDED_KEY_USAGE)
|
||||
|
||||
static STACK_OF(CONF_VALUE) *i2v_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD
|
||||
*method, void *a, STACK_OF(CONF_VALUE)
|
||||
*ext_list)
|
||||
{
|
||||
EXTENDED_KEY_USAGE *eku = a;
|
||||
size_t i;
|
||||
ASN1_OBJECT *obj;
|
||||
char obj_tmp[80];
|
||||
for (i = 0; i < sk_ASN1_OBJECT_num(eku); i++) {
|
||||
obj = sk_ASN1_OBJECT_value(eku, i);
|
||||
i2t_ASN1_OBJECT(obj_tmp, 80, obj);
|
||||
X509V3_add_value(NULL, obj_tmp, &ext_list);
|
||||
}
|
||||
return ext_list;
|
||||
}
|
||||
|
||||
static void *v2i_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD *method,
|
||||
X509V3_CTX *ctx,
|
||||
STACK_OF(CONF_VALUE) *nval)
|
||||
{
|
||||
EXTENDED_KEY_USAGE *extku;
|
||||
char *extval;
|
||||
ASN1_OBJECT *objtmp;
|
||||
CONF_VALUE *val;
|
||||
size_t i;
|
||||
|
||||
if (!(extku = sk_ASN1_OBJECT_new_null())) {
|
||||
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
|
||||
val = sk_CONF_VALUE_value(nval, i);
|
||||
if (val->value)
|
||||
extval = val->value;
|
||||
else
|
||||
extval = val->name;
|
||||
if (!(objtmp = OBJ_txt2obj(extval, 0))) {
|
||||
sk_ASN1_OBJECT_pop_free(extku, ASN1_OBJECT_free);
|
||||
OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_OBJECT_IDENTIFIER);
|
||||
X509V3_conf_err(val);
|
||||
return NULL;
|
||||
}
|
||||
sk_ASN1_OBJECT_push(extku, objtmp);
|
||||
}
|
||||
return extku;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user