| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/x509v3/v3_extku.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | /* $OpenBSD: v3_extku.c,v 1.15 2017/01/29 17:49:23 beck Exp $ */ | - | ||||||
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | - | ||||||
| 3 | * project 1999. | - | ||||||
| 4 | */ | - | ||||||
| 5 | /* ==================================================================== | - | ||||||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | - | ||||||
| 7 | * | - | ||||||
| 8 | * Redistribution and use in source and binary forms, with or without | - | ||||||
| 9 | * modification, are permitted provided that the following conditions | - | ||||||
| 10 | * are met: | - | ||||||
| 11 | * | - | ||||||
| 12 | * 1. Redistributions of source code must retain the above copyright | - | ||||||
| 13 | * notice, this list of conditions and the following disclaimer. | - | ||||||
| 14 | * | - | ||||||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | - | ||||||
| 16 | * notice, this list of conditions and the following disclaimer in | - | ||||||
| 17 | * the documentation and/or other materials provided with the | - | ||||||
| 18 | * distribution. | - | ||||||
| 19 | * | - | ||||||
| 20 | * 3. All advertising materials mentioning features or use of this | - | ||||||
| 21 | * software must display the following acknowledgment: | - | ||||||
| 22 | * "This product includes software developed by the OpenSSL Project | - | ||||||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | - | ||||||
| 24 | * | - | ||||||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | - | ||||||
| 26 | * endorse or promote products derived from this software without | - | ||||||
| 27 | * prior written permission. For written permission, please contact | - | ||||||
| 28 | * licensing@OpenSSL.org. | - | ||||||
| 29 | * | - | ||||||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | - | ||||||
| 31 | * nor may "OpenSSL" appear in their names without prior written | - | ||||||
| 32 | * permission of the OpenSSL Project. | - | ||||||
| 33 | * | - | ||||||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | - | ||||||
| 35 | * acknowledgment: | - | ||||||
| 36 | * "This product includes software developed by the OpenSSL Project | - | ||||||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | - | ||||||
| 38 | * | - | ||||||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | - | ||||||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | - | ||||||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | - | ||||||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | - | ||||||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | - | ||||||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | - | ||||||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | - | ||||||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | - | ||||||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | - | ||||||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | - | ||||||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | - | ||||||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | - | ||||||
| 51 | * ==================================================================== | - | ||||||
| 52 | * | - | ||||||
| 53 | * This product includes cryptographic software written by Eric Young | - | ||||||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | - | ||||||
| 55 | * Hudson (tjh@cryptsoft.com). | - | ||||||
| 56 | * | - | ||||||
| 57 | */ | - | ||||||
| 58 | - | |||||||
| 59 | #include <stdio.h> | - | ||||||
| 60 | - | |||||||
| 61 | #include <openssl/asn1t.h> | - | ||||||
| 62 | #include <openssl/conf.h> | - | ||||||
| 63 | #include <openssl/err.h> | - | ||||||
| 64 | #include <openssl/x509v3.h> | - | ||||||
| 65 | - | |||||||
| 66 | static void *v2i_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD *method, | - | ||||||
| 67 | X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); | - | ||||||
| 68 | static STACK_OF(CONF_VALUE) *i2v_EXTENDED_KEY_USAGE( | - | ||||||
| 69 | const X509V3_EXT_METHOD *method, void *eku, STACK_OF(CONF_VALUE) *extlist); | - | ||||||
| 70 | - | |||||||
| 71 | const X509V3_EXT_METHOD v3_ext_ku = { | - | ||||||
| 72 | .ext_nid = NID_ext_key_usage, | - | ||||||
| 73 | .ext_flags = 0, | - | ||||||
| 74 | .it = &EXTENDED_KEY_USAGE_it, | - | ||||||
| 75 | .ext_new = NULL, | - | ||||||
| 76 | .ext_free = NULL, | - | ||||||
| 77 | .d2i = NULL, | - | ||||||
| 78 | .i2d = NULL, | - | ||||||
| 79 | .i2s = NULL, | - | ||||||
| 80 | .s2i = NULL, | - | ||||||
| 81 | .i2v = i2v_EXTENDED_KEY_USAGE, | - | ||||||
| 82 | .v2i = v2i_EXTENDED_KEY_USAGE, | - | ||||||
| 83 | .i2r = NULL, | - | ||||||
| 84 | .r2i = NULL, | - | ||||||
| 85 | .usr_data = NULL, | - | ||||||
| 86 | }; | - | ||||||
| 87 | - | |||||||
| 88 | /* NB OCSP acceptable responses also is a SEQUENCE OF OBJECT */ | - | ||||||
| 89 | const X509V3_EXT_METHOD v3_ocsp_accresp = { | - | ||||||
| 90 | .ext_nid = NID_id_pkix_OCSP_acceptableResponses, | - | ||||||
| 91 | .ext_flags = 0, | - | ||||||
| 92 | .it = &EXTENDED_KEY_USAGE_it, | - | ||||||
| 93 | .ext_new = NULL, | - | ||||||
| 94 | .ext_free = NULL, | - | ||||||
| 95 | .d2i = NULL, | - | ||||||
| 96 | .i2d = NULL, | - | ||||||
| 97 | .i2s = NULL, | - | ||||||
| 98 | .s2i = NULL, | - | ||||||
| 99 | .i2v = i2v_EXTENDED_KEY_USAGE, | - | ||||||
| 100 | .v2i = v2i_EXTENDED_KEY_USAGE, | - | ||||||
| 101 | .i2r = NULL, | - | ||||||
| 102 | .r2i = NULL, | - | ||||||
| 103 | .usr_data = NULL, | - | ||||||
| 104 | }; | - | ||||||
| 105 | - | |||||||
| 106 | static const ASN1_TEMPLATE EXTENDED_KEY_USAGE_item_tt = { | - | ||||||
| 107 | .flags = ASN1_TFLG_SEQUENCE_OF, | - | ||||||
| 108 | .tag = 0, | - | ||||||
| 109 | .offset = 0, | - | ||||||
| 110 | .field_name = "EXTENDED_KEY_USAGE", | - | ||||||
| 111 | .item = &ASN1_OBJECT_it, | - | ||||||
| 112 | }; | - | ||||||
| 113 | - | |||||||
| 114 | const ASN1_ITEM EXTENDED_KEY_USAGE_it = { | - | ||||||
| 115 | .itype = ASN1_ITYPE_PRIMITIVE, | - | ||||||
| 116 | .utype = -1, | - | ||||||
| 117 | .templates = &EXTENDED_KEY_USAGE_item_tt, | - | ||||||
| 118 | .tcount = 0, | - | ||||||
| 119 | .funcs = NULL, | - | ||||||
| 120 | .size = 0, | - | ||||||
| 121 | .sname = "EXTENDED_KEY_USAGE", | - | ||||||
| 122 | }; | - | ||||||
| 123 | - | |||||||
| 124 | - | |||||||
| 125 | EXTENDED_KEY_USAGE * | - | ||||||
| 126 | d2i_EXTENDED_KEY_USAGE(EXTENDED_KEY_USAGE **a, const unsigned char **in, long len) | - | ||||||
| 127 | { | - | ||||||
| 128 | return (EXTENDED_KEY_USAGE *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, never executed: return (EXTENDED_KEY_USAGE *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, &EXTENDED_KEY_USAGE_it); | 0 | ||||||
| 129 | &EXTENDED_KEY_USAGE_it); never executed: return (EXTENDED_KEY_USAGE *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, &EXTENDED_KEY_USAGE_it); | 0 | ||||||
| 130 | } | - | ||||||
| 131 | - | |||||||
| 132 | int | - | ||||||
| 133 | i2d_EXTENDED_KEY_USAGE(EXTENDED_KEY_USAGE *a, unsigned char **out) | - | ||||||
| 134 | { | - | ||||||
| 135 | return ASN1_item_i2d((ASN1_VALUE *)a, out, &EXTENDED_KEY_USAGE_it); never executed: return ASN1_item_i2d((ASN1_VALUE *)a, out, &EXTENDED_KEY_USAGE_it); | 0 | ||||||
| 136 | } | - | ||||||
| 137 | - | |||||||
| 138 | EXTENDED_KEY_USAGE * | - | ||||||
| 139 | EXTENDED_KEY_USAGE_new(void) | - | ||||||
| 140 | { | - | ||||||
| 141 | return (EXTENDED_KEY_USAGE *)ASN1_item_new(&EXTENDED_KEY_USAGE_it); never executed: return (EXTENDED_KEY_USAGE *)ASN1_item_new(&EXTENDED_KEY_USAGE_it); | 0 | ||||||
| 142 | } | - | ||||||
| 143 | - | |||||||
| 144 | void | - | ||||||
| 145 | EXTENDED_KEY_USAGE_free(EXTENDED_KEY_USAGE *a) | - | ||||||
| 146 | { | - | ||||||
| 147 | ASN1_item_free((ASN1_VALUE *)a, &EXTENDED_KEY_USAGE_it); | - | ||||||
| 148 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||
| 149 | - | |||||||
| 150 | static STACK_OF(CONF_VALUE) * | - | ||||||
| 151 | i2v_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD *method, void *a, | - | ||||||
| 152 | STACK_OF(CONF_VALUE) *ext_list) | - | ||||||
| 153 | { | - | ||||||
| 154 | EXTENDED_KEY_USAGE *eku = a; | - | ||||||
| 155 | int i; | - | ||||||
| 156 | ASN1_OBJECT *obj; | - | ||||||
| 157 | char obj_tmp[80]; | - | ||||||
| 158 | - | |||||||
| 159 | for (i = 0; i < sk_ASN1_OBJECT_num(eku); i++) {
| 0 | ||||||
| 160 | obj = sk_ASN1_OBJECT_value(eku, i); | - | ||||||
| 161 | i2t_ASN1_OBJECT(obj_tmp, 80, obj); | - | ||||||
| 162 | X509V3_add_value(NULL, obj_tmp, &ext_list); | - | ||||||
| 163 | } never executed: end of block | 0 | ||||||
| 164 | return ext_list; never executed: return ext_list; | 0 | ||||||
| 165 | } | - | ||||||
| 166 | - | |||||||
| 167 | static void * | - | ||||||
| 168 | v2i_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx, | - | ||||||
| 169 | STACK_OF(CONF_VALUE) *nval) | - | ||||||
| 170 | { | - | ||||||
| 171 | EXTENDED_KEY_USAGE *extku; | - | ||||||
| 172 | char *extval; | - | ||||||
| 173 | ASN1_OBJECT *objtmp; | - | ||||||
| 174 | CONF_VALUE *val; | - | ||||||
| 175 | int i; | - | ||||||
| 176 | - | |||||||
| 177 | if (!(extku = sk_ASN1_OBJECT_new_null())) {
| 0 | ||||||
| 178 | X509V3error(ERR_R_MALLOC_FAILURE); | - | ||||||
| 179 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||
| 180 | } | - | ||||||
| 181 | - | |||||||
| 182 | for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
| 0 | ||||||
| 183 | val = sk_CONF_VALUE_value(nval, i); | - | ||||||
| 184 | if (val->value)
| 0 | ||||||
| 185 | extval = val->value; never executed: extval = val->value; | 0 | ||||||
| 186 | else | - | ||||||
| 187 | extval = val->name; never executed: extval = val->name; | 0 | ||||||
| 188 | if (!(objtmp = OBJ_txt2obj(extval, 0))) {
| 0 | ||||||
| 189 | sk_ASN1_OBJECT_pop_free(extku, ASN1_OBJECT_free); | - | ||||||
| 190 | X509V3error(X509V3_R_INVALID_OBJECT_IDENTIFIER); | - | ||||||
| 191 | X509V3_conf_err(val); | - | ||||||
| 192 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||
| 193 | } | - | ||||||
| 194 | if (sk_ASN1_OBJECT_push(extku, objtmp) == 0) {
| 0 | ||||||
| 195 | ASN1_OBJECT_free(objtmp); | - | ||||||
| 196 | sk_ASN1_OBJECT_pop_free(extku, ASN1_OBJECT_free); | - | ||||||
| 197 | X509V3error(ERR_R_MALLOC_FAILURE); | - | ||||||
| 198 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||
| 199 | } | - | ||||||
| 200 | } never executed: end of block | 0 | ||||||
| 201 | return extku; never executed: return extku; | 0 | ||||||
| 202 | } | - | ||||||
| Source code | Switch to Preprocessed file |