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