2
0

v3_extku.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <stdio.h>
  10. #include "internal/cryptlib.h"
  11. #include <openssl/asn1t.h>
  12. #include <openssl/conf.h>
  13. #include <openssl/x509v3.h>
  14. #include "ext_dat.h"
  15. static void *v2i_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD *method,
  16. X509V3_CTX *ctx,
  17. STACK_OF(CONF_VALUE) *nval);
  18. static STACK_OF(CONF_VALUE) *i2v_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD
  19. *method, void *eku, STACK_OF(CONF_VALUE)
  20. *extlist);
  21. const X509V3_EXT_METHOD v3_ext_ku = {
  22. NID_ext_key_usage, 0,
  23. ASN1_ITEM_ref(EXTENDED_KEY_USAGE),
  24. 0, 0, 0, 0,
  25. 0, 0,
  26. i2v_EXTENDED_KEY_USAGE,
  27. v2i_EXTENDED_KEY_USAGE,
  28. 0, 0,
  29. NULL
  30. };
  31. /* NB OCSP acceptable responses also is a SEQUENCE OF OBJECT */
  32. const X509V3_EXT_METHOD v3_ocsp_accresp = {
  33. NID_id_pkix_OCSP_acceptableResponses, 0,
  34. ASN1_ITEM_ref(EXTENDED_KEY_USAGE),
  35. 0, 0, 0, 0,
  36. 0, 0,
  37. i2v_EXTENDED_KEY_USAGE,
  38. v2i_EXTENDED_KEY_USAGE,
  39. 0, 0,
  40. NULL
  41. };
  42. ASN1_ITEM_TEMPLATE(EXTENDED_KEY_USAGE) =
  43. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, EXTENDED_KEY_USAGE, ASN1_OBJECT)
  44. ASN1_ITEM_TEMPLATE_END(EXTENDED_KEY_USAGE)
  45. IMPLEMENT_ASN1_FUNCTIONS(EXTENDED_KEY_USAGE)
  46. static STACK_OF(CONF_VALUE) *i2v_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD
  47. *method, void *a, STACK_OF(CONF_VALUE)
  48. *ext_list)
  49. {
  50. EXTENDED_KEY_USAGE *eku = a;
  51. int i;
  52. ASN1_OBJECT *obj;
  53. char obj_tmp[80];
  54. for (i = 0; i < sk_ASN1_OBJECT_num(eku); i++) {
  55. obj = sk_ASN1_OBJECT_value(eku, i);
  56. i2t_ASN1_OBJECT(obj_tmp, 80, obj);
  57. X509V3_add_value(NULL, obj_tmp, &ext_list);
  58. }
  59. return ext_list;
  60. }
  61. static void *v2i_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD *method,
  62. X509V3_CTX *ctx,
  63. STACK_OF(CONF_VALUE) *nval)
  64. {
  65. EXTENDED_KEY_USAGE *extku;
  66. char *extval;
  67. ASN1_OBJECT *objtmp;
  68. CONF_VALUE *val;
  69. const int num = sk_CONF_VALUE_num(nval);
  70. int i;
  71. extku = sk_ASN1_OBJECT_new_reserve(NULL, num);
  72. if (extku == NULL) {
  73. X509V3err(X509V3_F_V2I_EXTENDED_KEY_USAGE, ERR_R_MALLOC_FAILURE);
  74. sk_ASN1_OBJECT_free(extku);
  75. return NULL;
  76. }
  77. for (i = 0; i < num; i++) {
  78. val = sk_CONF_VALUE_value(nval, i);
  79. if (val->value)
  80. extval = val->value;
  81. else
  82. extval = val->name;
  83. if ((objtmp = OBJ_txt2obj(extval, 0)) == NULL) {
  84. sk_ASN1_OBJECT_pop_free(extku, ASN1_OBJECT_free);
  85. X509V3err(X509V3_F_V2I_EXTENDED_KEY_USAGE,
  86. X509V3_R_INVALID_OBJECT_IDENTIFIER);
  87. X509V3_conf_err(val);
  88. return NULL;
  89. }
  90. sk_ASN1_OBJECT_push(extku, objtmp); /* no failure as it was reserved */
  91. }
  92. return extku;
  93. }