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