2015-01-22 11:40:55 +08:00
|
|
|
/*
|
2016-05-18 02:51:26 +08:00
|
|
|
* Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
|
1999-01-24 08:50:01 +08:00
|
|
|
*
|
2018-12-06 21:00:54 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:51:26 +08:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
1999-01-24 08:50:01 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2015-05-14 22:56:48 +08:00
|
|
|
#include "internal/cryptlib.h"
|
2000-12-09 03:09:35 +08:00
|
|
|
#include <openssl/asn1t.h>
|
1999-04-24 06:13:45 +08:00
|
|
|
#include <openssl/conf.h>
|
|
|
|
#include <openssl/x509v3.h>
|
2015-09-05 20:32:58 +08:00
|
|
|
#include "ext_dat.h"
|
1999-01-24 08:50:01 +08:00
|
|
|
|
2008-10-12 22:32:47 +08:00
|
|
|
static void *v2i_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD *method,
|
2015-01-22 11:40:55 +08:00
|
|
|
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);
|
2000-12-09 03:09:35 +08:00
|
|
|
|
2007-01-21 21:07:17 +08:00
|
|
|
const X509V3_EXT_METHOD v3_ext_ku = {
|
2015-01-22 11:40:55 +08:00
|
|
|
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
|
2000-12-15 21:42:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* NB OCSP acceptable responses also is a SEQUENCE OF OBJECT */
|
2007-01-21 21:07:17 +08:00
|
|
|
const X509V3_EXT_METHOD v3_ocsp_accresp = {
|
2015-01-22 11:40:55 +08:00
|
|
|
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
|
1999-01-24 08:50:01 +08:00
|
|
|
};
|
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
ASN1_ITEM_TEMPLATE(EXTENDED_KEY_USAGE) =
|
|
|
|
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, EXTENDED_KEY_USAGE, ASN1_OBJECT)
|
2001-02-23 20:47:06 +08:00
|
|
|
ASN1_ITEM_TEMPLATE_END(EXTENDED_KEY_USAGE)
|
1999-01-24 08:50:01 +08:00
|
|
|
|
2000-12-09 03:09:35 +08:00
|
|
|
IMPLEMENT_ASN1_FUNCTIONS(EXTENDED_KEY_USAGE)
|
1999-01-24 08:50:01 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
static STACK_OF(CONF_VALUE) *i2v_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD
|
|
|
|
*method, void *a, STACK_OF(CONF_VALUE)
|
|
|
|
*ext_list)
|
1999-01-24 08:50:01 +08:00
|
|
|
{
|
2015-01-22 11:40:55 +08:00
|
|
|
EXTENDED_KEY_USAGE *eku = a;
|
|
|
|
int 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;
|
1999-01-24 08:50:01 +08:00
|
|
|
}
|
|
|
|
|
2008-10-12 22:32:47 +08:00
|
|
|
static void *v2i_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD *method,
|
2015-01-22 11:40:55 +08:00
|
|
|
X509V3_CTX *ctx,
|
|
|
|
STACK_OF(CONF_VALUE) *nval)
|
1999-01-24 08:50:01 +08:00
|
|
|
{
|
2015-01-22 11:40:55 +08:00
|
|
|
EXTENDED_KEY_USAGE *extku;
|
|
|
|
char *extval;
|
|
|
|
ASN1_OBJECT *objtmp;
|
|
|
|
CONF_VALUE *val;
|
2017-09-29 05:30:22 +08:00
|
|
|
const int num = sk_CONF_VALUE_num(nval);
|
2015-01-22 11:40:55 +08:00
|
|
|
int i;
|
1999-01-24 08:50:01 +08:00
|
|
|
|
2017-10-27 01:56:14 +08:00
|
|
|
extku = sk_ASN1_OBJECT_new_reserve(NULL, num);
|
|
|
|
if (extku == NULL) {
|
2015-01-22 11:40:55 +08:00
|
|
|
X509V3err(X509V3_F_V2I_EXTENDED_KEY_USAGE, ERR_R_MALLOC_FAILURE);
|
2017-09-29 05:30:22 +08:00
|
|
|
sk_ASN1_OBJECT_free(extku);
|
2015-01-22 11:40:55 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2000-12-15 21:42:00 +08:00
|
|
|
|
2017-09-29 05:30:22 +08:00
|
|
|
for (i = 0; i < num; i++) {
|
2015-01-22 11:40:55 +08:00
|
|
|
val = sk_CONF_VALUE_value(nval, i);
|
|
|
|
if (val->value)
|
|
|
|
extval = val->value;
|
|
|
|
else
|
|
|
|
extval = val->name;
|
2015-05-07 01:43:59 +08:00
|
|
|
if ((objtmp = OBJ_txt2obj(extval, 0)) == NULL) {
|
2015-01-22 11:40:55 +08:00
|
|
|
sk_ASN1_OBJECT_pop_free(extku, ASN1_OBJECT_free);
|
|
|
|
X509V3err(X509V3_F_V2I_EXTENDED_KEY_USAGE,
|
|
|
|
X509V3_R_INVALID_OBJECT_IDENTIFIER);
|
|
|
|
X509V3_conf_err(val);
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-09-29 05:30:22 +08:00
|
|
|
sk_ASN1_OBJECT_push(extku, objtmp); /* no failure as it was reserved */
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
return extku;
|
1999-01-24 08:50:01 +08:00
|
|
|
}
|