11cb0ef41Sopenharmony_ci/* 21cb0ef41Sopenharmony_ci * Copyright 1999-2021 The OpenSSL Project Authors. All Rights Reserved. 31cb0ef41Sopenharmony_ci * 41cb0ef41Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License"). You may not use 51cb0ef41Sopenharmony_ci * this file except in compliance with the License. You can obtain a copy 61cb0ef41Sopenharmony_ci * in the file LICENSE in the source distribution or at 71cb0ef41Sopenharmony_ci * https://www.openssl.org/source/license.html 81cb0ef41Sopenharmony_ci */ 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci#include <stdio.h> 111cb0ef41Sopenharmony_ci#include "internal/cryptlib.h" 121cb0ef41Sopenharmony_ci#include <openssl/asn1t.h> 131cb0ef41Sopenharmony_ci#include <openssl/conf.h> 141cb0ef41Sopenharmony_ci#include <openssl/x509v3.h> 151cb0ef41Sopenharmony_ci#include "ext_dat.h" 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_cistatic void *v2i_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD *method, 181cb0ef41Sopenharmony_ci X509V3_CTX *ctx, 191cb0ef41Sopenharmony_ci STACK_OF(CONF_VALUE) *nval); 201cb0ef41Sopenharmony_cistatic STACK_OF(CONF_VALUE) *i2v_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD 211cb0ef41Sopenharmony_ci *method, void *eku, STACK_OF(CONF_VALUE) 221cb0ef41Sopenharmony_ci *extlist); 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ciconst X509V3_EXT_METHOD ossl_v3_ext_ku = { 251cb0ef41Sopenharmony_ci NID_ext_key_usage, 0, 261cb0ef41Sopenharmony_ci ASN1_ITEM_ref(EXTENDED_KEY_USAGE), 271cb0ef41Sopenharmony_ci 0, 0, 0, 0, 281cb0ef41Sopenharmony_ci 0, 0, 291cb0ef41Sopenharmony_ci i2v_EXTENDED_KEY_USAGE, 301cb0ef41Sopenharmony_ci v2i_EXTENDED_KEY_USAGE, 311cb0ef41Sopenharmony_ci 0, 0, 321cb0ef41Sopenharmony_ci NULL 331cb0ef41Sopenharmony_ci}; 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci/* NB OCSP acceptable responses also is a SEQUENCE OF OBJECT */ 361cb0ef41Sopenharmony_ciconst X509V3_EXT_METHOD ossl_v3_ocsp_accresp = { 371cb0ef41Sopenharmony_ci NID_id_pkix_OCSP_acceptableResponses, 0, 381cb0ef41Sopenharmony_ci ASN1_ITEM_ref(EXTENDED_KEY_USAGE), 391cb0ef41Sopenharmony_ci 0, 0, 0, 0, 401cb0ef41Sopenharmony_ci 0, 0, 411cb0ef41Sopenharmony_ci i2v_EXTENDED_KEY_USAGE, 421cb0ef41Sopenharmony_ci v2i_EXTENDED_KEY_USAGE, 431cb0ef41Sopenharmony_ci 0, 0, 441cb0ef41Sopenharmony_ci NULL 451cb0ef41Sopenharmony_ci}; 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_ciASN1_ITEM_TEMPLATE(EXTENDED_KEY_USAGE) = 481cb0ef41Sopenharmony_ci ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, EXTENDED_KEY_USAGE, ASN1_OBJECT) 491cb0ef41Sopenharmony_ciASN1_ITEM_TEMPLATE_END(EXTENDED_KEY_USAGE) 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ciIMPLEMENT_ASN1_FUNCTIONS(EXTENDED_KEY_USAGE) 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_cistatic STACK_OF(CONF_VALUE) *i2v_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD 541cb0ef41Sopenharmony_ci *method, void *a, STACK_OF(CONF_VALUE) 551cb0ef41Sopenharmony_ci *ext_list) 561cb0ef41Sopenharmony_ci{ 571cb0ef41Sopenharmony_ci EXTENDED_KEY_USAGE *eku = a; 581cb0ef41Sopenharmony_ci int i; 591cb0ef41Sopenharmony_ci ASN1_OBJECT *obj; 601cb0ef41Sopenharmony_ci char obj_tmp[80]; 611cb0ef41Sopenharmony_ci for (i = 0; i < sk_ASN1_OBJECT_num(eku); i++) { 621cb0ef41Sopenharmony_ci obj = sk_ASN1_OBJECT_value(eku, i); 631cb0ef41Sopenharmony_ci i2t_ASN1_OBJECT(obj_tmp, 80, obj); 641cb0ef41Sopenharmony_ci X509V3_add_value(NULL, obj_tmp, &ext_list); 651cb0ef41Sopenharmony_ci } 661cb0ef41Sopenharmony_ci return ext_list; 671cb0ef41Sopenharmony_ci} 681cb0ef41Sopenharmony_ci 691cb0ef41Sopenharmony_cistatic void *v2i_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD *method, 701cb0ef41Sopenharmony_ci X509V3_CTX *ctx, 711cb0ef41Sopenharmony_ci STACK_OF(CONF_VALUE) *nval) 721cb0ef41Sopenharmony_ci{ 731cb0ef41Sopenharmony_ci EXTENDED_KEY_USAGE *extku; 741cb0ef41Sopenharmony_ci char *extval; 751cb0ef41Sopenharmony_ci ASN1_OBJECT *objtmp; 761cb0ef41Sopenharmony_ci CONF_VALUE *val; 771cb0ef41Sopenharmony_ci const int num = sk_CONF_VALUE_num(nval); 781cb0ef41Sopenharmony_ci int i; 791cb0ef41Sopenharmony_ci 801cb0ef41Sopenharmony_ci extku = sk_ASN1_OBJECT_new_reserve(NULL, num); 811cb0ef41Sopenharmony_ci if (extku == NULL) { 821cb0ef41Sopenharmony_ci ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE); 831cb0ef41Sopenharmony_ci sk_ASN1_OBJECT_free(extku); 841cb0ef41Sopenharmony_ci return NULL; 851cb0ef41Sopenharmony_ci } 861cb0ef41Sopenharmony_ci 871cb0ef41Sopenharmony_ci for (i = 0; i < num; i++) { 881cb0ef41Sopenharmony_ci val = sk_CONF_VALUE_value(nval, i); 891cb0ef41Sopenharmony_ci if (val->value) 901cb0ef41Sopenharmony_ci extval = val->value; 911cb0ef41Sopenharmony_ci else 921cb0ef41Sopenharmony_ci extval = val->name; 931cb0ef41Sopenharmony_ci if ((objtmp = OBJ_txt2obj(extval, 0)) == NULL) { 941cb0ef41Sopenharmony_ci sk_ASN1_OBJECT_pop_free(extku, ASN1_OBJECT_free); 951cb0ef41Sopenharmony_ci ERR_raise_data(ERR_LIB_X509V3, X509V3_R_INVALID_OBJECT_IDENTIFIER, 961cb0ef41Sopenharmony_ci "%s", extval); 971cb0ef41Sopenharmony_ci return NULL; 981cb0ef41Sopenharmony_ci } 991cb0ef41Sopenharmony_ci sk_ASN1_OBJECT_push(extku, objtmp); /* no failure as it was reserved */ 1001cb0ef41Sopenharmony_ci } 1011cb0ef41Sopenharmony_ci return extku; 1021cb0ef41Sopenharmony_ci} 103