x509asn1.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #ifndef HEADER_CURL_X509ASN1_H
  2. #define HEADER_CURL_X509ASN1_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2016, Daniel Stenberg, <[email protected]>, et al.
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at https://curl.haxx.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. ***************************************************************************/
  24. #include "curl_setup.h"
  25. #if defined(USE_GSKIT) || defined(USE_NSS) || defined(USE_GNUTLS) || \
  26. defined(USE_CYASSL) || defined(USE_SCHANNEL)
  27. #include "urldata.h"
  28. /*
  29. * Constants.
  30. */
  31. /* Largest supported ASN.1 structure. */
  32. #define CURL_ASN1_MAX ((size_t) 0x40000) /* 256K */
  33. /* ASN.1 classes. */
  34. #define CURL_ASN1_UNIVERSAL 0
  35. #define CURL_ASN1_APPLICATION 1
  36. #define CURL_ASN1_CONTEXT_SPECIFIC 2
  37. #define CURL_ASN1_PRIVATE 3
  38. /* ASN.1 types. */
  39. #define CURL_ASN1_BOOLEAN 1
  40. #define CURL_ASN1_INTEGER 2
  41. #define CURL_ASN1_BIT_STRING 3
  42. #define CURL_ASN1_OCTET_STRING 4
  43. #define CURL_ASN1_NULL 5
  44. #define CURL_ASN1_OBJECT_IDENTIFIER 6
  45. #define CURL_ASN1_OBJECT_DESCRIPTOR 7
  46. #define CURL_ASN1_INSTANCE_OF 8
  47. #define CURL_ASN1_REAL 9
  48. #define CURL_ASN1_ENUMERATED 10
  49. #define CURL_ASN1_EMBEDDED 11
  50. #define CURL_ASN1_UTF8_STRING 12
  51. #define CURL_ASN1_RELATIVE_OID 13
  52. #define CURL_ASN1_SEQUENCE 16
  53. #define CURL_ASN1_SET 17
  54. #define CURL_ASN1_NUMERIC_STRING 18
  55. #define CURL_ASN1_PRINTABLE_STRING 19
  56. #define CURL_ASN1_TELETEX_STRING 20
  57. #define CURL_ASN1_VIDEOTEX_STRING 21
  58. #define CURL_ASN1_IA5_STRING 22
  59. #define CURL_ASN1_UTC_TIME 23
  60. #define CURL_ASN1_GENERALIZED_TIME 24
  61. #define CURL_ASN1_GRAPHIC_STRING 25
  62. #define CURL_ASN1_VISIBLE_STRING 26
  63. #define CURL_ASN1_GENERAL_STRING 27
  64. #define CURL_ASN1_UNIVERSAL_STRING 28
  65. #define CURL_ASN1_CHARACTER_STRING 29
  66. #define CURL_ASN1_BMP_STRING 30
  67. /*
  68. * Types.
  69. */
  70. /* ASN.1 parsed element. */
  71. typedef struct {
  72. const char * header; /* Pointer to header byte. */
  73. const char * beg; /* Pointer to element data. */
  74. const char * end; /* Pointer to 1st byte after element. */
  75. unsigned char class; /* ASN.1 element class. */
  76. unsigned char tag; /* ASN.1 element tag. */
  77. bool constructed; /* Element is constructed. */
  78. } curl_asn1Element;
  79. /* ASN.1 OID table entry. */
  80. typedef struct {
  81. const char * numoid; /* Dotted-numeric OID. */
  82. const char * textoid; /* OID name. */
  83. } curl_OID;
  84. /* X509 certificate: RFC 5280. */
  85. typedef struct {
  86. curl_asn1Element certificate;
  87. curl_asn1Element version;
  88. curl_asn1Element serialNumber;
  89. curl_asn1Element signatureAlgorithm;
  90. curl_asn1Element signature;
  91. curl_asn1Element issuer;
  92. curl_asn1Element notBefore;
  93. curl_asn1Element notAfter;
  94. curl_asn1Element subject;
  95. curl_asn1Element subjectPublicKeyInfo;
  96. curl_asn1Element subjectPublicKeyAlgorithm;
  97. curl_asn1Element subjectPublicKey;
  98. curl_asn1Element issuerUniqueID;
  99. curl_asn1Element subjectUniqueID;
  100. curl_asn1Element extensions;
  101. } curl_X509certificate;
  102. /*
  103. * Prototypes.
  104. */
  105. const char *Curl_getASN1Element(curl_asn1Element *elem,
  106. const char *beg, const char *end);
  107. const char *Curl_ASN1tostr(curl_asn1Element *elem, int type);
  108. const char *Curl_DNtostr(curl_asn1Element *dn);
  109. int Curl_parseX509(curl_X509certificate *cert,
  110. const char *beg, const char *end);
  111. CURLcode Curl_extract_certinfo(struct connectdata *conn, int certnum,
  112. const char *beg, const char *end);
  113. CURLcode Curl_verifyhost(struct connectdata *conn,
  114. const char *beg, const char *end);
  115. #endif /* USE_GSKIT or USE_NSS or USE_GNUTLS or USE_CYASSL or USE_SCHANNEL */
  116. #endif /* HEADER_CURL_X509ASN1_H */