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