x509asn1.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #ifndef HEADER_CURL_X509ASN1_H
  2. #define HEADER_CURL_X509ASN1_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, 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 http://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)
  26. #include "urldata.h"
  27. /*
  28. * Constants.
  29. */
  30. /* ASN.1 classes. */
  31. #define CURL_ASN1_UNIVERSAL 0
  32. #define CURL_ASN1_APPLICATION 1
  33. #define CURL_ASN1_CONTEXT_SPECIFIC 2
  34. #define CURL_ASN1_PRIVATE 3
  35. /* ASN.1 types. */
  36. #define CURL_ASN1_BOOLEAN 1
  37. #define CURL_ASN1_INTEGER 2
  38. #define CURL_ASN1_BIT_STRING 3
  39. #define CURL_ASN1_OCTET_STRING 4
  40. #define CURL_ASN1_NULL 5
  41. #define CURL_ASN1_OBJECT_IDENTIFIER 6
  42. #define CURL_ASN1_OBJECT_DESCRIPTOR 7
  43. #define CURL_ASN1_INSTANCE_OF 8
  44. #define CURL_ASN1_REAL 9
  45. #define CURL_ASN1_ENUMERATED 10
  46. #define CURL_ASN1_EMBEDDED 11
  47. #define CURL_ASN1_UTF8_STRING 12
  48. #define CURL_ASN1_RELATIVE_OID 13
  49. #define CURL_ASN1_SEQUENCE 16
  50. #define CURL_ASN1_SET 17
  51. #define CURL_ASN1_NUMERIC_STRING 18
  52. #define CURL_ASN1_PRINTABLE_STRING 19
  53. #define CURL_ASN1_TELETEX_STRING 20
  54. #define CURL_ASN1_VIDEOTEX_STRING 21
  55. #define CURL_ASN1_IA5_STRING 22
  56. #define CURL_ASN1_UTC_TIME 23
  57. #define CURL_ASN1_GENERALIZED_TIME 24
  58. #define CURL_ASN1_GRAPHIC_STRING 25
  59. #define CURL_ASN1_VISIBLE_STRING 26
  60. #define CURL_ASN1_GENERAL_STRING 27
  61. #define CURL_ASN1_UNIVERSAL_STRING 28
  62. #define CURL_ASN1_CHARACTER_STRING 29
  63. #define CURL_ASN1_BMP_STRING 30
  64. /*
  65. * Types.
  66. */
  67. /* ASN.1 parsed element. */
  68. typedef struct {
  69. const char * header; /* Pointer to header byte. */
  70. const char * beg; /* Pointer to element data. */
  71. const char * end; /* Pointer to 1st byte after element. */
  72. unsigned char class; /* ASN.1 element class. */
  73. unsigned char tag; /* ASN.1 element tag. */
  74. bool constructed; /* Element is constructed. */
  75. } curl_asn1Element;
  76. /* ASN.1 OID table entry. */
  77. typedef struct {
  78. const char * numoid; /* Dotted-numeric OID. */
  79. const char * textoid; /* OID name. */
  80. } curl_OID;
  81. /* X509 certificate: RFC 5280. */
  82. typedef struct {
  83. curl_asn1Element certificate;
  84. curl_asn1Element version;
  85. curl_asn1Element serialNumber;
  86. curl_asn1Element signatureAlgorithm;
  87. curl_asn1Element signature;
  88. curl_asn1Element issuer;
  89. curl_asn1Element notBefore;
  90. curl_asn1Element notAfter;
  91. curl_asn1Element subject;
  92. curl_asn1Element subjectPublicKeyInfo;
  93. curl_asn1Element subjectPublicKeyAlgorithm;
  94. curl_asn1Element subjectPublicKey;
  95. curl_asn1Element issuerUniqueID;
  96. curl_asn1Element subjectUniqueID;
  97. curl_asn1Element extensions;
  98. } curl_X509certificate;
  99. /*
  100. * Prototypes.
  101. */
  102. const char * Curl_getASN1Element(curl_asn1Element * elem,
  103. const char * beg, const char * end);
  104. const char * Curl_ASN1tostr(curl_asn1Element * elem, int type);
  105. const char * Curl_DNtostr(curl_asn1Element * dn);
  106. void Curl_parseX509(curl_X509certificate * cert,
  107. const char * beg, const char * end);
  108. CURLcode Curl_extract_certinfo(struct connectdata * conn, int certnum,
  109. const char * beg, const char * end);
  110. CURLcode Curl_verifyhost(struct connectdata * conn,
  111. const char * beg, const char * end);
  112. #endif /* USE_GSKIT or USE_NSS */
  113. #endif /* HEADER_CURL_X509ASN1_H */