xref: /curl/lib/vtls/x509asn1.h (revision 27959ecc)
1 #ifndef HEADER_CURL_X509ASN1_H
2 #define HEADER_CURL_X509ASN1_H
3 
4 /***************************************************************************
5  *                                  _   _ ____  _
6  *  Project                     ___| | | |  _ \| |
7  *                             / __| | | | |_) | |
8  *                            | (__| |_| |  _ <| |___
9  *                             \___|\___/|_| \_\_____|
10  *
11  * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
12  *
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.se/docs/copyright.html.
16  *
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.
20  *
21  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
22  * KIND, either express or implied.
23  *
24  * SPDX-License-Identifier: curl
25  *
26  ***************************************************************************/
27 
28 #include "curl_setup.h"
29 
30 #if defined(USE_GNUTLS) || defined(USE_WOLFSSL) || \
31   defined(USE_SCHANNEL) || defined(USE_SECTRANSP) || \
32   defined(USE_MBEDTLS)
33 
34 #include "cfilters.h"
35 #include "urldata.h"
36 
37 /*
38  * Types.
39  */
40 
41 /* ASN.1 parsed element. */
42 struct Curl_asn1Element {
43   const char *header;         /* Pointer to header byte. */
44   const char *beg;            /* Pointer to element data. */
45   const char *end;            /* Pointer to 1st byte after element. */
46   unsigned char class;        /* ASN.1 element class. */
47   unsigned char tag;          /* ASN.1 element tag. */
48   bool          constructed;  /* Element is constructed. */
49 };
50 
51 /* X509 certificate: RFC 5280. */
52 struct Curl_X509certificate {
53   struct Curl_asn1Element certificate;
54   struct Curl_asn1Element version;
55   struct Curl_asn1Element serialNumber;
56   struct Curl_asn1Element signatureAlgorithm;
57   struct Curl_asn1Element signature;
58   struct Curl_asn1Element issuer;
59   struct Curl_asn1Element notBefore;
60   struct Curl_asn1Element notAfter;
61   struct Curl_asn1Element subject;
62   struct Curl_asn1Element subjectPublicKeyInfo;
63   struct Curl_asn1Element subjectPublicKeyAlgorithm;
64   struct Curl_asn1Element subjectPublicKey;
65   struct Curl_asn1Element issuerUniqueID;
66   struct Curl_asn1Element subjectUniqueID;
67   struct Curl_asn1Element extensions;
68 };
69 
70 /*
71  * Prototypes.
72  */
73 
74 int Curl_parseX509(struct Curl_X509certificate *cert,
75                    const char *beg, const char *end);
76 CURLcode Curl_extract_certinfo(struct Curl_easy *data, int certnum,
77                                const char *beg, const char *end);
78 CURLcode Curl_verifyhost(struct Curl_cfilter *cf, struct Curl_easy *data,
79                          const char *beg, const char *end);
80 
81 #ifdef UNITTESTS
82 #if defined(USE_GNUTLS) || defined(USE_SCHANNEL) || defined(USE_SECTRANSP) || \
83   defined(USE_MBEDTLS)
84 
85 /* used by unit1656.c */
86 CURLcode Curl_x509_GTime2str(struct dynbuf *store,
87                              const char *beg, const char *end);
88 #endif
89 #endif
90 
91 #endif /* USE_GNUTLS or USE_WOLFSSL or USE_SCHANNEL or USE_SECTRANSP */
92 #endif /* HEADER_CURL_X509ASN1_H */
93