• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
3  * 2004.
4  */
5 /* ====================================================================
6  * Copyright (c) 2004 The OpenSSL Project.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in
17  *    the documentation and/or other materials provided with the
18  *    distribution.
19  *
20  * 3. All advertising materials mentioning features or use of this
21  *    software must display the following acknowledgment:
22  *    "This product includes software developed by the OpenSSL Project
23  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24  *
25  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26  *    endorse or promote products derived from this software without
27  *    prior written permission. For written permission, please contact
28  *    licensing@OpenSSL.org.
29  *
30  * 5. Products derived from this software may not be called "OpenSSL"
31  *    nor may "OpenSSL" appear in their names without prior written
32  *    permission of the OpenSSL Project.
33  *
34  * 6. Redistributions of any form whatsoever must retain the following
35  *    acknowledgment:
36  *    "This product includes software developed by the OpenSSL Project
37  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38  *
39  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
43  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50  * OF THE POSSIBILITY OF SUCH DAMAGE.
51  * ====================================================================
52  *
53  * This product includes cryptographic software written by Eric Young
54  * (eay@cryptsoft.com).  This product includes software written by Tim
55  * Hudson (tjh@cryptsoft.com).
56  *
57  */
58 
59 #ifndef OPENSSL_HEADER_X509V3_INTERNAL_H
60 #define OPENSSL_HEADER_X509V3_INTERNAL_H
61 
62 #include <openssl/base.h>
63 
64 #include <openssl/conf.h>
65 #include <openssl/stack.h>
66 #include <openssl/x509v3.h>
67 
68 // TODO(davidben): Merge x509 and x509v3. This include is needed because some
69 // internal typedefs are shared between the two, but the two modules depend on
70 // each other circularly.
71 #include "../x509/internal.h"
72 
73 #if defined(__cplusplus)
74 extern "C" {
75 #endif
76 
77 
78 // x509v3_bytes_to_hex encodes |len| bytes from |in| to hex and returns a
79 // newly-allocated NUL-terminated string containing the result, or NULL on
80 // allocation error.
81 //
82 // This function was historically named |hex_to_string| in OpenSSL. Despite the
83 // name, |hex_to_string| converted to hex.
84 OPENSSL_EXPORT char *x509v3_bytes_to_hex(const uint8_t *in, size_t len);
85 
86 // x509v3_hex_string_to_bytes decodes |str| in hex and returns a newly-allocated
87 // array containing the result, or NULL on error. On success, it sets |*len| to
88 // the length of the result. Colon separators between bytes in the input are
89 // allowed and ignored.
90 //
91 // This function was historically named |string_to_hex| in OpenSSL. Despite the
92 // name, |string_to_hex| converted from hex.
93 unsigned char *x509v3_hex_to_bytes(const char *str, size_t *len);
94 
95 // x509v3_conf_name_matches returns one if |name| is equal to |cmp| or begins
96 // with |cmp| followed by '.', and zero otherwise.
97 int x509v3_conf_name_matches(const char *name, const char *cmp);
98 
99 // x509v3_looks_like_dns_name returns one if |in| looks like a DNS name and zero
100 // otherwise.
101 OPENSSL_EXPORT int x509v3_looks_like_dns_name(const unsigned char *in,
102                                               size_t len);
103 
104 // x509v3_cache_extensions fills in a number of fields relating to X.509
105 // extensions in |x|. It returns one on success and zero if some extensions were
106 // invalid.
107 OPENSSL_EXPORT int x509v3_cache_extensions(X509 *x);
108 
109 // x509v3_a2i_ipadd decodes |ipasc| as an IPv4 or IPv6 address. IPv6 addresses
110 // use colon-separated syntax while IPv4 addresses use dotted decimal syntax. If
111 // it decodes an IPv4 address, it writes the result to the first four bytes of
112 // |ipout| and returns four. If it decodes an IPv6 address, it writes the result
113 // to all 16 bytes of |ipout| and returns 16. Otherwise, it returns zero.
114 int x509v3_a2i_ipadd(unsigned char ipout[16], const char *ipasc);
115 
116 // A |BIT_STRING_BITNAME| is used to contain a list of bit names.
117 typedef struct {
118   int bitnum;
119   const char *lname;
120   const char *sname;
121 } BIT_STRING_BITNAME;
122 
123 // x509V3_add_value_asn1_string appends a |CONF_VALUE| with the specified name
124 // and value to |*extlist|. if |*extlist| is NULL, it sets |*extlist| to a
125 // newly-allocated |STACK_OF(CONF_VALUE)| first. It returns one on success and
126 // zero on error.
127 int x509V3_add_value_asn1_string(const char *name, const ASN1_STRING *value,
128                                  STACK_OF(CONF_VALUE) **extlist);
129 
130 // X509V3_NAME_from_section adds attributes to |nm| by interpreting the
131 // key/value pairs in |dn_sk|. It returns one on success and zero on error.
132 // |chtype|, which should be one of |MBSTRING_*| constants, determines the
133 // character encoding used to interpret values.
134 int X509V3_NAME_from_section(X509_NAME *nm, const STACK_OF(CONF_VALUE) *dn_sk,
135                              int chtype);
136 
137 // X509V3_bool_from_string decodes |str| as a boolean. On success, it returns
138 // one and sets |*out_bool| to resulting value. Otherwise, it returns zero.
139 int X509V3_bool_from_string(const char *str, ASN1_BOOLEAN *out_bool);
140 
141 // X509V3_get_value_bool decodes |value| as a boolean. On success, it returns
142 // one and sets |*out_bool| to the resulting value. Otherwise, it returns zero.
143 int X509V3_get_value_bool(const CONF_VALUE *value, ASN1_BOOLEAN *out_bool);
144 
145 // X509V3_get_value_int decodes |value| as an integer. On success, it returns
146 // one and sets |*aint| to the resulting value. Otherwise, it returns zero. If
147 // |*aint| was non-NULL at the start of the function, it frees the previous
148 // value before writing a new one.
149 int X509V3_get_value_int(const CONF_VALUE *value, ASN1_INTEGER **aint);
150 
151 // X509V3_get_section behaves like |NCONF_get_section| but queries |ctx|'s
152 // config database.
153 const STACK_OF(CONF_VALUE) *X509V3_get_section(const X509V3_CTX *ctx,
154                                                const char *section);
155 
156 // X509V3_add_value appends a |CONF_VALUE| containing |name| and |value| to
157 // |*extlist|. It returns one on success and zero on error. If |*extlist| is
158 // NULL, it sets |*extlist| to a newly-allocated |STACK_OF(CONF_VALUE)|
159 // containing the result. Either |name| or |value| may be NULL to omit the
160 // field.
161 //
162 // On failure, if |*extlist| was NULL, |*extlist| will remain NULL when the
163 // function returns.
164 int X509V3_add_value(const char *name, const char *value,
165                      STACK_OF(CONF_VALUE) **extlist);
166 
167 // X509V3_add_value_bool behaves like |X509V3_add_value| but stores the value
168 // "TRUE" if |asn1_bool| is non-zero and "FALSE" otherwise.
169 int X509V3_add_value_bool(const char *name, int asn1_bool,
170                           STACK_OF(CONF_VALUE) **extlist);
171 
172 // X509V3_add_value_bool behaves like |X509V3_add_value| but stores a string
173 // representation of |aint|. Note this string representation may be decimal or
174 // hexadecimal, depending on the size of |aint|.
175 int X509V3_add_value_int(const char *name, const ASN1_INTEGER *aint,
176                          STACK_OF(CONF_VALUE) **extlist);
177 
178 STACK_OF(CONF_VALUE) *X509V3_parse_list(const char *line);
179 
180 #define X509V3_conf_err(val)                                               \
181   ERR_add_error_data(6, "section:", (val)->section, ",name:", (val)->name, \
182                      ",value:", (val)->value);
183 
184 // GENERAL_NAME_cmp returns zero if |a| and |b| are equal and a non-zero
185 // value otherwise. Note this function does not provide a comparison suitable
186 // for sorting.
187 //
188 // This function is exported for testing.
189 OPENSSL_EXPORT int GENERAL_NAME_cmp(const GENERAL_NAME *a,
190                                     const GENERAL_NAME *b);
191 
192 
193 #if defined(__cplusplus)
194 }  // extern C
195 #endif
196 
197 #endif  // OPENSSL_HEADER_X509V3_INTERNAL_H
198