]>
Commit | Line | Data |
---|---|---|
3149baf8 AE |
1 | /* |
2 | * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project | |
3 | * 2015. | |
4 | */ | |
5 | /* ==================================================================== | |
6 | * Copyright (c) 2015 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 | */ | |
54 | #ifndef HEADER_CT_LOCL_H | |
55 | # define HEADER_CT_LOCL_H | |
56 | ||
57 | # ifdef __cplusplus | |
58 | extern "C" { | |
59 | # endif | |
60 | ||
61 | # ifndef OPENSSL_NO_CT | |
62 | ||
63 | /* All hashes are currently SHA256 */ | |
64 | # define SCT_V1_HASHLEN 32 | |
65 | /* Minimum RSA key size, from RFC6962 */ | |
66 | # define SCT_MIN_RSA_BITS 2048 | |
67 | ||
68 | /* | |
69 | * From RFC6962: opaque SerializedSCT<1..2^16-1>; struct { SerializedSCT | |
70 | * sct_list <1..2^16-1>; } SignedCertificateTimestampList; | |
71 | */ | |
72 | ||
73 | # define MAX_SCT_SIZE 65535 | |
74 | # define MAX_SCT_LIST_SIZE MAX_SCT_SIZE | |
75 | ||
76 | typedef enum { | |
77 | UNSET_ENTRY = -1, | |
78 | X509_ENTRY = 0, | |
79 | PRECERT_ENTRY = 1 | |
80 | } log_entry_type_t; | |
81 | ||
82 | typedef enum { | |
83 | UNSET_VERSION = -1, | |
84 | SCT_V1 = 0 | |
85 | } sct_version_t; | |
86 | ||
87 | typedef struct { | |
88 | sct_version_t version; | |
89 | /* If version is not SCT_V1 this contains the encoded SCT */ | |
90 | unsigned char *sct; | |
91 | size_t sct_len; | |
92 | /* | |
b84939cc EK |
93 | * If version is SCT_V1, fields below contain components of the SCT. |
94 | * "log_id", "ext" and "sig" point to buffers allocated with | |
95 | * OPENSSL_malloc(). | |
3149baf8 AE |
96 | */ |
97 | unsigned char *log_id; | |
98 | size_t log_id_len; | |
99 | ||
100 | /* | |
101 | * Note, we cannot distinguish between an unset timestamp, and one | |
102 | * that is set to 0. However since CT didn't exist in 1970, no real | |
103 | * SCT should ever be set as such. | |
104 | */ | |
105 | uint64_t timestamp; | |
106 | unsigned char *ext; | |
107 | size_t ext_len; | |
108 | unsigned char hash_alg; | |
109 | unsigned char sig_alg; | |
110 | unsigned char *sig; | |
111 | size_t sig_len; | |
112 | /* Log entry type */ | |
113 | log_entry_type_t entry_type; | |
114 | } SCT; | |
115 | ||
85885715 | 116 | DEFINE_STACK_OF(SCT) |
3149baf8 AE |
117 | |
118 | /* | |
119 | * Allocate new SCT. | |
120 | * Caller is responsible for calling SCT_free when done. | |
121 | */ | |
122 | SCT *SCT_new(void); | |
123 | ||
124 | /* | |
125 | * Free SCT and underlying datastructures. | |
126 | */ | |
127 | void SCT_free(SCT *sct); | |
128 | ||
129 | /* | |
130 | * Set the version of an SCT. | |
131 | * Returns 1 on success, 0 if the version is unrecognized. | |
132 | */ | |
133 | int SCT_set_version(SCT *sct, sct_version_t version); | |
134 | ||
135 | /* | |
136 | * Set the log entry type of an SCT. | |
137 | * Returns 1 on success. | |
138 | */ | |
139 | int SCT_set_log_entry_type(SCT *sct, log_entry_type_t entry_type); | |
140 | ||
141 | /* | |
b84939cc | 142 | * Set the log id of an SCT to point directly to the *log_id specified. |
3149baf8 AE |
143 | * The SCT takes ownership of the specified pointer. |
144 | * Returns 1 on success. | |
145 | */ | |
146 | int SCT_set0_log_id(SCT *sct, unsigned char *log_id, size_t log_id_len); | |
147 | ||
148 | /* | |
149 | * Set the timestamp of an SCT. | |
150 | */ | |
151 | void SCT_set_timestamp(SCT *sct, uint64_t timestamp); | |
152 | ||
153 | /* | |
154 | * Set the signature type of an SCT | |
155 | * Currently NID_sha256WithRSAEncryption or NID_ecdsa_with_SHA256. | |
156 | * Returns 1 on success. | |
157 | */ | |
158 | int SCT_set_signature_nid(SCT *sct, int nid); | |
159 | ||
160 | /* | |
161 | * Set the extensions of an SCT to point directly to the *ext specified. | |
162 | * The SCT takes ownership of the specified pointer. | |
163 | */ | |
164 | void SCT_set0_extensions(SCT *sct, unsigned char *ext, size_t ext_len); | |
165 | ||
166 | /* | |
167 | * Set the signature of an SCT to point directly to the *sig specified. | |
168 | * The SCT takes ownership of the specified pointer. | |
169 | */ | |
170 | void SCT_set0_signature(SCT *sct, unsigned char *sig, size_t sig_len); | |
171 | ||
172 | /* | |
173 | * Returns the version of the SCT. | |
174 | */ | |
175 | sct_version_t SCT_get_version(const SCT *sct); | |
176 | ||
177 | /* | |
178 | * Returns the log entry type of the SCT. | |
179 | */ | |
180 | log_entry_type_t SCT_get_log_entry_type(const SCT *sct); | |
181 | ||
182 | /* | |
b84939cc | 183 | * Set *log_id to point to the log id for the SCT. log_id must not be NULL. |
3149baf8 AE |
184 | * The SCT retains ownership of this pointer. |
185 | * Returns length of the data pointed to. | |
186 | */ | |
187 | size_t SCT_get0_log_id(const SCT *sct, unsigned char **log_id); | |
188 | ||
189 | /* | |
190 | * Returns the timestamp for the SCT. | |
191 | */ | |
192 | uint64_t SCT_get_timestamp(const SCT *sct); | |
193 | ||
194 | /* | |
195 | * Return the nid for the signature used by the SCT. | |
b84939cc EK |
196 | * Currently NID_sha256WithRSAEncryption or NID_ecdsa_with_SHA256 |
197 | * (or NID_undef). | |
3149baf8 AE |
198 | */ |
199 | int SCT_get_signature_nid(const SCT *sct); | |
200 | ||
201 | /* | |
202 | * Set *ext to point to the extension data for the SCT. ext must not be NULL. | |
203 | * The SCT retains ownership of this pointer. | |
204 | * Returns length of the data pointed to. | |
205 | */ | |
206 | size_t SCT_get0_extensions(const SCT *sct, unsigned char **ext); | |
207 | ||
208 | /* | |
209 | * Set *sig to point to the signature for the SCT. sig must not be NULL. | |
210 | * The SCT retains ownership of this pointer. | |
211 | * Returns length of the data pointed to. | |
212 | */ | |
213 | size_t SCT_get0_signature(const SCT *sct, unsigned char **sig); | |
214 | ||
215 | ||
216 | # endif | |
217 | ||
218 | /* BEGIN ERROR CODES */ | |
219 | /* | |
220 | * The following lines are auto generated by the script mkerr.pl. Any changes | |
221 | * made after this point may be overwritten when the script is next run. | |
222 | */ | |
223 | void ERR_load_CT_strings(void); | |
224 | ||
225 | /* Error codes for the CT functions. */ | |
226 | ||
227 | /* Function codes. */ | |
228 | # define CT_F_SCT_NEW 100 | |
229 | # define CT_F_SCT_SET0_LOG_ID 101 | |
230 | # define CT_F_SCT_SET_LOG_ENTRY_TYPE 102 | |
231 | # define CT_F_SCT_SET_SIGNATURE_NID 103 | |
232 | # define CT_F_SCT_SET_VERSION 104 | |
233 | ||
234 | /* Reason codes. */ | |
235 | # define CT_R_INVALID_LOG_ID_LENGTH 100 | |
236 | # define CT_R_UNRECOGNIZED_SIGNATURE_NID 101 | |
237 | # define CT_R_UNSUPPORTED_ENTRY_TYPE 102 | |
238 | # define CT_R_UNSUPPORTED_VERSION 103 | |
239 | ||
240 | #ifdef __cplusplus | |
241 | } | |
242 | #endif | |
243 | #endif |