diff options
Diffstat (limited to '')
-rw-r--r-- | src/lib/libcrypto/ct/ct_sct.c | 603 |
1 files changed, 315 insertions, 288 deletions
diff --git a/src/lib/libcrypto/ct/ct_sct.c b/src/lib/libcrypto/ct/ct_sct.c index 4ff36e2fbd..ca915b763e 100644 --- a/src/lib/libcrypto/ct/ct_sct.c +++ b/src/lib/libcrypto/ct/ct_sct.c | |||
@@ -19,378 +19,405 @@ | |||
19 | 19 | ||
20 | #include "ct_local.h" | 20 | #include "ct_local.h" |
21 | 21 | ||
22 | SCT *SCT_new(void) | 22 | SCT * |
23 | SCT_new(void) | ||
23 | { | 24 | { |
24 | SCT *sct = OPENSSL_zalloc(sizeof(*sct)); | 25 | SCT *sct = OPENSSL_zalloc(sizeof(*sct)); |
25 | 26 | ||
26 | if (sct == NULL) { | 27 | if (sct == NULL) { |
27 | CTerr(CT_F_SCT_NEW, ERR_R_MALLOC_FAILURE); | 28 | CTerr(CT_F_SCT_NEW, ERR_R_MALLOC_FAILURE); |
28 | return NULL; | 29 | return NULL; |
29 | } | 30 | } |
30 | 31 | ||
31 | sct->entry_type = CT_LOG_ENTRY_TYPE_NOT_SET; | 32 | sct->entry_type = CT_LOG_ENTRY_TYPE_NOT_SET; |
32 | sct->version = SCT_VERSION_NOT_SET; | 33 | sct->version = SCT_VERSION_NOT_SET; |
33 | return sct; | 34 | return sct; |
34 | } | 35 | } |
35 | 36 | ||
36 | void SCT_free(SCT *sct) | 37 | void |
38 | SCT_free(SCT *sct) | ||
37 | { | 39 | { |
38 | if (sct == NULL) | 40 | if (sct == NULL) |
39 | return; | 41 | return; |
40 | 42 | ||
41 | OPENSSL_free(sct->log_id); | 43 | OPENSSL_free(sct->log_id); |
42 | OPENSSL_free(sct->ext); | 44 | OPENSSL_free(sct->ext); |
43 | OPENSSL_free(sct->sig); | 45 | OPENSSL_free(sct->sig); |
44 | OPENSSL_free(sct->sct); | 46 | OPENSSL_free(sct->sct); |
45 | OPENSSL_free(sct); | 47 | OPENSSL_free(sct); |
46 | } | 48 | } |
47 | 49 | ||
48 | void SCT_LIST_free(STACK_OF(SCT) *a) | 50 | void |
51 | SCT_LIST_free(STACK_OF(SCT) *a) | ||
49 | { | 52 | { |
50 | sk_SCT_pop_free(a, SCT_free); | 53 | sk_SCT_pop_free(a, SCT_free); |
51 | } | 54 | } |
52 | 55 | ||
53 | int SCT_set_version(SCT *sct, sct_version_t version) | 56 | int |
57 | SCT_set_version(SCT *sct, sct_version_t version) | ||
54 | { | 58 | { |
55 | if (version != SCT_VERSION_V1) { | 59 | if (version != SCT_VERSION_V1) { |
56 | CTerr(CT_F_SCT_SET_VERSION, CT_R_UNSUPPORTED_VERSION); | 60 | CTerr(CT_F_SCT_SET_VERSION, CT_R_UNSUPPORTED_VERSION); |
57 | return 0; | 61 | return 0; |
58 | } | 62 | } |
59 | sct->version = version; | 63 | sct->version = version; |
60 | sct->validation_status = SCT_VALIDATION_STATUS_NOT_SET; | 64 | sct->validation_status = SCT_VALIDATION_STATUS_NOT_SET; |
61 | return 1; | 65 | return 1; |
62 | } | 66 | } |
63 | 67 | ||
64 | int SCT_set_log_entry_type(SCT *sct, ct_log_entry_type_t entry_type) | 68 | int |
69 | SCT_set_log_entry_type(SCT *sct, ct_log_entry_type_t entry_type) | ||
65 | { | 70 | { |
66 | sct->validation_status = SCT_VALIDATION_STATUS_NOT_SET; | 71 | sct->validation_status = SCT_VALIDATION_STATUS_NOT_SET; |
67 | 72 | ||
68 | switch (entry_type) { | 73 | switch (entry_type) { |
69 | case CT_LOG_ENTRY_TYPE_X509: | 74 | case CT_LOG_ENTRY_TYPE_X509: |
70 | case CT_LOG_ENTRY_TYPE_PRECERT: | 75 | case CT_LOG_ENTRY_TYPE_PRECERT: |
71 | sct->entry_type = entry_type; | 76 | sct->entry_type = entry_type; |
72 | return 1; | 77 | return 1; |
73 | case CT_LOG_ENTRY_TYPE_NOT_SET: | 78 | case CT_LOG_ENTRY_TYPE_NOT_SET: |
74 | break; | 79 | break; |
75 | } | 80 | } |
76 | CTerr(CT_F_SCT_SET_LOG_ENTRY_TYPE, CT_R_UNSUPPORTED_ENTRY_TYPE); | 81 | CTerr(CT_F_SCT_SET_LOG_ENTRY_TYPE, CT_R_UNSUPPORTED_ENTRY_TYPE); |
77 | return 0; | 82 | return 0; |
78 | } | 83 | } |
79 | 84 | ||
80 | int SCT_set0_log_id(SCT *sct, unsigned char *log_id, size_t log_id_len) | 85 | int |
86 | SCT_set0_log_id(SCT *sct, unsigned char *log_id, size_t log_id_len) | ||
81 | { | 87 | { |
82 | if (sct->version == SCT_VERSION_V1 && log_id_len != CT_V1_HASHLEN) { | 88 | if (sct->version == SCT_VERSION_V1 && log_id_len != CT_V1_HASHLEN) { |
83 | CTerr(CT_F_SCT_SET0_LOG_ID, CT_R_INVALID_LOG_ID_LENGTH); | 89 | CTerr(CT_F_SCT_SET0_LOG_ID, CT_R_INVALID_LOG_ID_LENGTH); |
84 | return 0; | 90 | return 0; |
85 | } | 91 | } |
86 | 92 | ||
87 | OPENSSL_free(sct->log_id); | 93 | OPENSSL_free(sct->log_id); |
88 | sct->log_id = log_id; | 94 | sct->log_id = log_id; |
89 | sct->log_id_len = log_id_len; | 95 | sct->log_id_len = log_id_len; |
90 | sct->validation_status = SCT_VALIDATION_STATUS_NOT_SET; | 96 | sct->validation_status = SCT_VALIDATION_STATUS_NOT_SET; |
91 | return 1; | 97 | return 1; |
92 | } | 98 | } |
93 | 99 | ||
94 | int SCT_set1_log_id(SCT *sct, const unsigned char *log_id, size_t log_id_len) | 100 | int |
101 | SCT_set1_log_id(SCT *sct, const unsigned char *log_id, size_t log_id_len) | ||
95 | { | 102 | { |
96 | if (sct->version == SCT_VERSION_V1 && log_id_len != CT_V1_HASHLEN) { | 103 | if (sct->version == SCT_VERSION_V1 && log_id_len != CT_V1_HASHLEN) { |
97 | CTerr(CT_F_SCT_SET1_LOG_ID, CT_R_INVALID_LOG_ID_LENGTH); | 104 | CTerr(CT_F_SCT_SET1_LOG_ID, CT_R_INVALID_LOG_ID_LENGTH); |
98 | return 0; | 105 | return 0; |
99 | } | 106 | } |
100 | 107 | ||
101 | OPENSSL_free(sct->log_id); | 108 | OPENSSL_free(sct->log_id); |
102 | sct->log_id = NULL; | 109 | sct->log_id = NULL; |
103 | sct->log_id_len = 0; | 110 | sct->log_id_len = 0; |
104 | sct->validation_status = SCT_VALIDATION_STATUS_NOT_SET; | 111 | sct->validation_status = SCT_VALIDATION_STATUS_NOT_SET; |
105 | 112 | ||
106 | if (log_id != NULL && log_id_len > 0) { | 113 | if (log_id != NULL && log_id_len > 0) { |
107 | sct->log_id = OPENSSL_memdup(log_id, log_id_len); | 114 | sct->log_id = OPENSSL_memdup(log_id, log_id_len); |
108 | if (sct->log_id == NULL) { | 115 | if (sct->log_id == NULL) { |
109 | CTerr(CT_F_SCT_SET1_LOG_ID, ERR_R_MALLOC_FAILURE); | 116 | CTerr(CT_F_SCT_SET1_LOG_ID, ERR_R_MALLOC_FAILURE); |
110 | return 0; | 117 | return 0; |
111 | } | 118 | } |
112 | sct->log_id_len = log_id_len; | 119 | sct->log_id_len = log_id_len; |
113 | } | 120 | } |
114 | return 1; | 121 | return 1; |
115 | } | 122 | } |
116 | 123 | ||
117 | 124 | ||
118 | void SCT_set_timestamp(SCT *sct, uint64_t timestamp) | 125 | void |
126 | SCT_set_timestamp(SCT *sct, uint64_t timestamp) | ||
119 | { | 127 | { |
120 | sct->timestamp = timestamp; | 128 | sct->timestamp = timestamp; |
121 | sct->validation_status = SCT_VALIDATION_STATUS_NOT_SET; | 129 | sct->validation_status = SCT_VALIDATION_STATUS_NOT_SET; |
122 | } | 130 | } |
123 | 131 | ||
124 | int SCT_set_signature_nid(SCT *sct, int nid) | 132 | int |
133 | SCT_set_signature_nid(SCT *sct, int nid) | ||
125 | { | 134 | { |
126 | switch (nid) { | 135 | switch (nid) { |
127 | case NID_sha256WithRSAEncryption: | 136 | case NID_sha256WithRSAEncryption: |
128 | sct->hash_alg = TLSEXT_hash_sha256; | 137 | sct->hash_alg = TLSEXT_hash_sha256; |
129 | sct->sig_alg = TLSEXT_signature_rsa; | 138 | sct->sig_alg = TLSEXT_signature_rsa; |
130 | sct->validation_status = SCT_VALIDATION_STATUS_NOT_SET; | 139 | sct->validation_status = SCT_VALIDATION_STATUS_NOT_SET; |
131 | return 1; | 140 | return 1; |
132 | case NID_ecdsa_with_SHA256: | 141 | case NID_ecdsa_with_SHA256: |
133 | sct->hash_alg = TLSEXT_hash_sha256; | 142 | sct->hash_alg = TLSEXT_hash_sha256; |
134 | sct->sig_alg = TLSEXT_signature_ecdsa; | 143 | sct->sig_alg = TLSEXT_signature_ecdsa; |
135 | sct->validation_status = SCT_VALIDATION_STATUS_NOT_SET; | 144 | sct->validation_status = SCT_VALIDATION_STATUS_NOT_SET; |
136 | return 1; | 145 | return 1; |
137 | default: | 146 | default: |
138 | CTerr(CT_F_SCT_SET_SIGNATURE_NID, CT_R_UNRECOGNIZED_SIGNATURE_NID); | 147 | CTerr(CT_F_SCT_SET_SIGNATURE_NID, CT_R_UNRECOGNIZED_SIGNATURE_NID); |
139 | return 0; | 148 | return 0; |
140 | } | 149 | } |
141 | } | 150 | } |
142 | 151 | ||
143 | void SCT_set0_extensions(SCT *sct, unsigned char *ext, size_t ext_len) | 152 | void |
153 | SCT_set0_extensions(SCT *sct, unsigned char *ext, size_t ext_len) | ||
144 | { | 154 | { |
145 | OPENSSL_free(sct->ext); | 155 | OPENSSL_free(sct->ext); |
146 | sct->ext = ext; | 156 | sct->ext = ext; |
147 | sct->ext_len = ext_len; | 157 | sct->ext_len = ext_len; |
148 | sct->validation_status = SCT_VALIDATION_STATUS_NOT_SET; | 158 | sct->validation_status = SCT_VALIDATION_STATUS_NOT_SET; |
149 | } | 159 | } |
150 | 160 | ||
151 | int SCT_set1_extensions(SCT *sct, const unsigned char *ext, size_t ext_len) | 161 | int |
162 | SCT_set1_extensions(SCT *sct, const unsigned char *ext, size_t ext_len) | ||
152 | { | 163 | { |
153 | OPENSSL_free(sct->ext); | 164 | OPENSSL_free(sct->ext); |
154 | sct->ext = NULL; | 165 | sct->ext = NULL; |
155 | sct->ext_len = 0; | 166 | sct->ext_len = 0; |
156 | sct->validation_status = SCT_VALIDATION_STATUS_NOT_SET; | 167 | sct->validation_status = SCT_VALIDATION_STATUS_NOT_SET; |
157 | 168 | ||
158 | if (ext != NULL && ext_len > 0) { | 169 | if (ext != NULL && ext_len > 0) { |
159 | sct->ext = OPENSSL_memdup(ext, ext_len); | 170 | sct->ext = OPENSSL_memdup(ext, ext_len); |
160 | if (sct->ext == NULL) { | 171 | if (sct->ext == NULL) { |
161 | CTerr(CT_F_SCT_SET1_EXTENSIONS, ERR_R_MALLOC_FAILURE); | 172 | CTerr(CT_F_SCT_SET1_EXTENSIONS, ERR_R_MALLOC_FAILURE); |
162 | return 0; | 173 | return 0; |
163 | } | 174 | } |
164 | sct->ext_len = ext_len; | 175 | sct->ext_len = ext_len; |
165 | } | 176 | } |
166 | return 1; | 177 | return 1; |
167 | } | 178 | } |
168 | 179 | ||
169 | void SCT_set0_signature(SCT *sct, unsigned char *sig, size_t sig_len) | 180 | void |
181 | SCT_set0_signature(SCT *sct, unsigned char *sig, size_t sig_len) | ||
170 | { | 182 | { |
171 | OPENSSL_free(sct->sig); | 183 | OPENSSL_free(sct->sig); |
172 | sct->sig = sig; | 184 | sct->sig = sig; |
173 | sct->sig_len = sig_len; | 185 | sct->sig_len = sig_len; |
174 | sct->validation_status = SCT_VALIDATION_STATUS_NOT_SET; | 186 | sct->validation_status = SCT_VALIDATION_STATUS_NOT_SET; |
175 | } | 187 | } |
176 | 188 | ||
177 | int SCT_set1_signature(SCT *sct, const unsigned char *sig, size_t sig_len) | 189 | int |
190 | SCT_set1_signature(SCT *sct, const unsigned char *sig, size_t sig_len) | ||
178 | { | 191 | { |
179 | OPENSSL_free(sct->sig); | 192 | OPENSSL_free(sct->sig); |
180 | sct->sig = NULL; | 193 | sct->sig = NULL; |
181 | sct->sig_len = 0; | 194 | sct->sig_len = 0; |
182 | sct->validation_status = SCT_VALIDATION_STATUS_NOT_SET; | 195 | sct->validation_status = SCT_VALIDATION_STATUS_NOT_SET; |
183 | 196 | ||
184 | if (sig != NULL && sig_len > 0) { | 197 | if (sig != NULL && sig_len > 0) { |
185 | sct->sig = OPENSSL_memdup(sig, sig_len); | 198 | sct->sig = OPENSSL_memdup(sig, sig_len); |
186 | if (sct->sig == NULL) { | 199 | if (sct->sig == NULL) { |
187 | CTerr(CT_F_SCT_SET1_SIGNATURE, ERR_R_MALLOC_FAILURE); | 200 | CTerr(CT_F_SCT_SET1_SIGNATURE, ERR_R_MALLOC_FAILURE); |
188 | return 0; | 201 | return 0; |
189 | } | 202 | } |
190 | sct->sig_len = sig_len; | 203 | sct->sig_len = sig_len; |
191 | } | 204 | } |
192 | return 1; | 205 | return 1; |
193 | } | 206 | } |
194 | 207 | ||
195 | sct_version_t SCT_get_version(const SCT *sct) | 208 | sct_version_t |
209 | SCT_get_version(const SCT *sct) | ||
196 | { | 210 | { |
197 | return sct->version; | 211 | return sct->version; |
198 | } | 212 | } |
199 | 213 | ||
200 | ct_log_entry_type_t SCT_get_log_entry_type(const SCT *sct) | 214 | ct_log_entry_type_t |
215 | SCT_get_log_entry_type(const SCT *sct) | ||
201 | { | 216 | { |
202 | return sct->entry_type; | 217 | return sct->entry_type; |
203 | } | 218 | } |
204 | 219 | ||
205 | size_t SCT_get0_log_id(const SCT *sct, unsigned char **log_id) | 220 | size_t |
221 | SCT_get0_log_id(const SCT *sct, unsigned char **log_id) | ||
206 | { | 222 | { |
207 | *log_id = sct->log_id; | 223 | *log_id = sct->log_id; |
208 | return sct->log_id_len; | 224 | return sct->log_id_len; |
209 | } | 225 | } |
210 | 226 | ||
211 | uint64_t SCT_get_timestamp(const SCT *sct) | 227 | uint64_t |
228 | SCT_get_timestamp(const SCT *sct) | ||
212 | { | 229 | { |
213 | return sct->timestamp; | 230 | return sct->timestamp; |
214 | } | 231 | } |
215 | 232 | ||
216 | int SCT_get_signature_nid(const SCT *sct) | 233 | int |
234 | SCT_get_signature_nid(const SCT *sct) | ||
217 | { | 235 | { |
218 | if (sct->version == SCT_VERSION_V1) { | 236 | if (sct->version == SCT_VERSION_V1) { |
219 | if (sct->hash_alg == TLSEXT_hash_sha256) { | 237 | if (sct->hash_alg == TLSEXT_hash_sha256) { |
220 | switch (sct->sig_alg) { | 238 | switch (sct->sig_alg) { |
221 | case TLSEXT_signature_ecdsa: | 239 | case TLSEXT_signature_ecdsa: |
222 | return NID_ecdsa_with_SHA256; | 240 | return NID_ecdsa_with_SHA256; |
223 | case TLSEXT_signature_rsa: | 241 | case TLSEXT_signature_rsa: |
224 | return NID_sha256WithRSAEncryption; | 242 | return NID_sha256WithRSAEncryption; |
225 | default: | 243 | default: |
226 | return NID_undef; | 244 | return NID_undef; |
227 | } | 245 | } |
228 | } | 246 | } |
229 | } | 247 | } |
230 | return NID_undef; | 248 | return NID_undef; |
231 | } | 249 | } |
232 | 250 | ||
233 | size_t SCT_get0_extensions(const SCT *sct, unsigned char **ext) | 251 | size_t |
252 | SCT_get0_extensions(const SCT *sct, unsigned char **ext) | ||
234 | { | 253 | { |
235 | *ext = sct->ext; | 254 | *ext = sct->ext; |
236 | return sct->ext_len; | 255 | return sct->ext_len; |
237 | } | 256 | } |
238 | 257 | ||
239 | size_t SCT_get0_signature(const SCT *sct, unsigned char **sig) | 258 | size_t |
259 | SCT_get0_signature(const SCT *sct, unsigned char **sig) | ||
240 | { | 260 | { |
241 | *sig = sct->sig; | 261 | *sig = sct->sig; |
242 | return sct->sig_len; | 262 | return sct->sig_len; |
243 | } | 263 | } |
244 | 264 | ||
245 | int SCT_is_complete(const SCT *sct) | 265 | int |
266 | SCT_is_complete(const SCT *sct) | ||
246 | { | 267 | { |
247 | switch (sct->version) { | 268 | switch (sct->version) { |
248 | case SCT_VERSION_NOT_SET: | 269 | case SCT_VERSION_NOT_SET: |
249 | return 0; | 270 | return 0; |
250 | case SCT_VERSION_V1: | 271 | case SCT_VERSION_V1: |
251 | return sct->log_id != NULL && SCT_signature_is_complete(sct); | 272 | return sct->log_id != NULL && SCT_signature_is_complete(sct); |
252 | default: | 273 | default: |
253 | return sct->sct != NULL; /* Just need cached encoding */ | 274 | return sct->sct != NULL; /* Just need cached encoding */ |
254 | } | 275 | } |
255 | } | 276 | } |
256 | 277 | ||
257 | int SCT_signature_is_complete(const SCT *sct) | 278 | int |
279 | SCT_signature_is_complete(const SCT *sct) | ||
258 | { | 280 | { |
259 | return SCT_get_signature_nid(sct) != NID_undef && | 281 | return SCT_get_signature_nid(sct) != NID_undef && sct->sig != NULL && |
260 | sct->sig != NULL && sct->sig_len > 0; | 282 | sct->sig_len > 0; |
261 | } | 283 | } |
262 | 284 | ||
263 | sct_source_t SCT_get_source(const SCT *sct) | 285 | sct_source_t |
286 | SCT_get_source(const SCT *sct) | ||
264 | { | 287 | { |
265 | return sct->source; | 288 | return sct->source; |
266 | } | 289 | } |
267 | 290 | ||
268 | int SCT_set_source(SCT *sct, sct_source_t source) | 291 | int |
292 | SCT_set_source(SCT *sct, sct_source_t source) | ||
269 | { | 293 | { |
270 | sct->source = source; | 294 | sct->source = source; |
271 | sct->validation_status = SCT_VALIDATION_STATUS_NOT_SET; | 295 | sct->validation_status = SCT_VALIDATION_STATUS_NOT_SET; |
272 | switch (source) { | 296 | switch (source) { |
273 | case SCT_SOURCE_TLS_EXTENSION: | 297 | case SCT_SOURCE_TLS_EXTENSION: |
274 | case SCT_SOURCE_OCSP_STAPLED_RESPONSE: | 298 | case SCT_SOURCE_OCSP_STAPLED_RESPONSE: |
275 | return SCT_set_log_entry_type(sct, CT_LOG_ENTRY_TYPE_X509); | 299 | return SCT_set_log_entry_type(sct, CT_LOG_ENTRY_TYPE_X509); |
276 | case SCT_SOURCE_X509V3_EXTENSION: | 300 | case SCT_SOURCE_X509V3_EXTENSION: |
277 | return SCT_set_log_entry_type(sct, CT_LOG_ENTRY_TYPE_PRECERT); | 301 | return SCT_set_log_entry_type(sct, CT_LOG_ENTRY_TYPE_PRECERT); |
278 | case SCT_SOURCE_UNKNOWN: | 302 | case SCT_SOURCE_UNKNOWN: |
279 | break; | 303 | break; |
280 | } | 304 | } |
281 | /* if we aren't sure, leave the log entry type alone */ | 305 | /* if we aren't sure, leave the log entry type alone */ |
282 | return 1; | 306 | return 1; |
283 | } | 307 | } |
284 | 308 | ||
285 | sct_validation_status_t SCT_get_validation_status(const SCT *sct) | 309 | sct_validation_status_t |
310 | SCT_get_validation_status(const SCT *sct) | ||
286 | { | 311 | { |
287 | return sct->validation_status; | 312 | return sct->validation_status; |
288 | } | 313 | } |
289 | 314 | ||
290 | int SCT_validate(SCT *sct, const CT_POLICY_EVAL_CTX *ctx) | 315 | int |
316 | SCT_validate(SCT *sct, const CT_POLICY_EVAL_CTX *ctx) | ||
291 | { | 317 | { |
292 | int is_sct_valid = -1; | 318 | int is_sct_valid = -1; |
293 | SCT_CTX *sctx = NULL; | 319 | SCT_CTX *sctx = NULL; |
294 | X509_PUBKEY *pub = NULL, *log_pkey = NULL; | 320 | X509_PUBKEY *pub = NULL, *log_pkey = NULL; |
295 | const CTLOG *log; | 321 | const CTLOG *log; |
296 | 322 | ||
297 | /* | 323 | /* |
298 | * With an unrecognized SCT version we don't know what such an SCT means, | 324 | * With an unrecognized SCT version we don't know what such an SCT means, |
299 | * let alone validate one. So we return validation failure (0). | 325 | * let alone validate one. So we return validation failure (0). |
300 | */ | 326 | */ |
301 | if (sct->version != SCT_VERSION_V1) { | 327 | if (sct->version != SCT_VERSION_V1) { |
302 | sct->validation_status = SCT_VALIDATION_STATUS_UNKNOWN_VERSION; | 328 | sct->validation_status = SCT_VALIDATION_STATUS_UNKNOWN_VERSION; |
303 | return 0; | 329 | return 0; |
304 | } | 330 | } |
305 | 331 | ||
306 | log = CTLOG_STORE_get0_log_by_id(ctx->log_store, | 332 | log = CTLOG_STORE_get0_log_by_id(ctx->log_store, sct->log_id, |
307 | sct->log_id, sct->log_id_len); | 333 | sct->log_id_len); |
308 | 334 | ||
309 | /* Similarly, an SCT from an unknown log also cannot be validated. */ | 335 | /* Similarly, an SCT from an unknown log also cannot be validated. */ |
310 | if (log == NULL) { | 336 | if (log == NULL) { |
311 | sct->validation_status = SCT_VALIDATION_STATUS_UNKNOWN_LOG; | 337 | sct->validation_status = SCT_VALIDATION_STATUS_UNKNOWN_LOG; |
312 | return 0; | 338 | return 0; |
313 | } | 339 | } |
314 | 340 | ||
315 | sctx = SCT_CTX_new(); | 341 | sctx = SCT_CTX_new(); |
316 | if (sctx == NULL) | 342 | if (sctx == NULL) |
317 | goto err; | 343 | goto err; |
318 | 344 | ||
319 | if (X509_PUBKEY_set(&log_pkey, CTLOG_get0_public_key(log)) != 1) | 345 | if (X509_PUBKEY_set(&log_pkey, CTLOG_get0_public_key(log)) != 1) |
320 | goto err; | 346 | goto err; |
321 | if (SCT_CTX_set1_pubkey(sctx, log_pkey) != 1) | 347 | if (SCT_CTX_set1_pubkey(sctx, log_pkey) != 1) |
322 | goto err; | 348 | goto err; |
323 | 349 | ||
324 | if (SCT_get_log_entry_type(sct) == CT_LOG_ENTRY_TYPE_PRECERT) { | 350 | if (SCT_get_log_entry_type(sct) == CT_LOG_ENTRY_TYPE_PRECERT) { |
325 | EVP_PKEY *issuer_pkey; | 351 | EVP_PKEY *issuer_pkey; |
326 | 352 | ||
327 | if (ctx->issuer == NULL) { | 353 | if (ctx->issuer == NULL) { |
328 | sct->validation_status = SCT_VALIDATION_STATUS_UNVERIFIED; | 354 | sct->validation_status = SCT_VALIDATION_STATUS_UNVERIFIED; |
329 | goto end; | 355 | goto end; |
330 | } | 356 | } |
331 | 357 | ||
332 | issuer_pkey = X509_get0_pubkey(ctx->issuer); | 358 | issuer_pkey = X509_get0_pubkey(ctx->issuer); |
333 | 359 | ||
334 | if (X509_PUBKEY_set(&pub, issuer_pkey) != 1) | 360 | if (X509_PUBKEY_set(&pub, issuer_pkey) != 1) |
335 | goto err; | 361 | goto err; |
336 | if (SCT_CTX_set1_issuer_pubkey(sctx, pub) != 1) | 362 | if (SCT_CTX_set1_issuer_pubkey(sctx, pub) != 1) |
337 | goto err; | 363 | goto err; |
338 | } | 364 | } |
339 | 365 | ||
340 | SCT_CTX_set_time(sctx, ctx->epoch_time_in_ms); | 366 | SCT_CTX_set_time(sctx, ctx->epoch_time_in_ms); |
341 | 367 | ||
342 | /* | 368 | /* |
343 | * XXX: Potential for optimization. This repeats some idempotent heavy | 369 | * XXX: Potential for optimization. This repeats some idempotent heavy |
344 | * lifting on the certificate for each candidate SCT, and appears to not | 370 | * lifting on the certificate for each candidate SCT, and appears to not |
345 | * use any information in the SCT itself, only the certificate is | 371 | * use any information in the SCT itself, only the certificate is |
346 | * processed. So it may make more sense to to do this just once, perhaps | 372 | * processed. So it may make more sense to to do this just once, perhaps |
347 | * associated with the shared (by all SCTs) policy eval ctx. | 373 | * associated with the shared (by all SCTs) policy eval ctx. |
348 | * | 374 | * |
349 | * XXX: Failure here is global (SCT independent) and represents either an | 375 | * XXX: Failure here is global (SCT independent) and represents either an |
350 | * issue with the certificate (e.g. duplicate extensions) or an out of | 376 | * issue with the certificate (e.g. duplicate extensions) or an out of |
351 | * memory condition. When the certificate is incompatible with CT, we just | 377 | * memory condition. When the certificate is incompatible with CT, we just |
352 | * mark the SCTs invalid, rather than report a failure to determine the | 378 | * mark the SCTs invalid, rather than report a failure to determine the |
353 | * validation status. That way, callbacks that want to do "soft" SCT | 379 | * validation status. That way, callbacks that want to do "soft" SCT |
354 | * processing will not abort handshakes with false positive internal | 380 | * processing will not abort handshakes with false positive internal |
355 | * errors. Since the function does not distinguish between certificate | 381 | * errors. Since the function does not distinguish between certificate |
356 | * issues (peer's fault) and internal problems (out fault) the safe thing | 382 | * issues (peer's fault) and internal problems (out fault) the safe thing |
357 | * to do is to report a validation failure and let the callback or | 383 | * to do is to report a validation failure and let the callback or |
358 | * application decide what to do. | 384 | * application decide what to do. |
359 | */ | 385 | */ |
360 | if (SCT_CTX_set1_cert(sctx, ctx->cert, NULL) != 1) | 386 | if (SCT_CTX_set1_cert(sctx, ctx->cert, NULL) != 1) |
361 | sct->validation_status = SCT_VALIDATION_STATUS_UNVERIFIED; | 387 | sct->validation_status = SCT_VALIDATION_STATUS_UNVERIFIED; |
362 | else | 388 | else |
363 | sct->validation_status = SCT_CTX_verify(sctx, sct) == 1 ? | 389 | sct->validation_status = SCT_CTX_verify(sctx, sct) == 1 ? |
364 | SCT_VALIDATION_STATUS_VALID : SCT_VALIDATION_STATUS_INVALID; | 390 | SCT_VALIDATION_STATUS_VALID : SCT_VALIDATION_STATUS_INVALID; |
365 | 391 | ||
366 | end: | 392 | end: |
367 | is_sct_valid = sct->validation_status == SCT_VALIDATION_STATUS_VALID; | 393 | is_sct_valid = sct->validation_status == SCT_VALIDATION_STATUS_VALID; |
368 | err: | 394 | err: |
369 | X509_PUBKEY_free(pub); | 395 | X509_PUBKEY_free(pub); |
370 | X509_PUBKEY_free(log_pkey); | 396 | X509_PUBKEY_free(log_pkey); |
371 | SCT_CTX_free(sctx); | 397 | SCT_CTX_free(sctx); |
372 | 398 | ||
373 | return is_sct_valid; | 399 | return is_sct_valid; |
374 | } | 400 | } |
375 | 401 | ||
376 | int SCT_LIST_validate(const STACK_OF(SCT) *scts, CT_POLICY_EVAL_CTX *ctx) | 402 | int |
403 | SCT_LIST_validate(const STACK_OF(SCT) *scts, CT_POLICY_EVAL_CTX *ctx) | ||
377 | { | 404 | { |
378 | int are_scts_valid = 1; | 405 | int are_scts_valid = 1; |
379 | int sct_count = scts != NULL ? sk_SCT_num(scts) : 0; | 406 | int sct_count = scts != NULL ? sk_SCT_num(scts) : 0; |
380 | int i; | 407 | int i; |
381 | 408 | ||
382 | for (i = 0; i < sct_count; ++i) { | 409 | for (i = 0; i < sct_count; ++i) { |
383 | int is_sct_valid = -1; | 410 | int is_sct_valid = -1; |
384 | SCT *sct = sk_SCT_value(scts, i); | 411 | SCT *sct = sk_SCT_value(scts, i); |
385 | 412 | ||
386 | if (sct == NULL) | 413 | if (sct == NULL) |
387 | continue; | 414 | continue; |
388 | 415 | ||
389 | is_sct_valid = SCT_validate(sct, ctx); | 416 | is_sct_valid = SCT_validate(sct, ctx); |
390 | if (is_sct_valid < 0) | 417 | if (is_sct_valid < 0) |
391 | return is_sct_valid; | 418 | return is_sct_valid; |
392 | are_scts_valid &= is_sct_valid; | 419 | are_scts_valid &= is_sct_valid; |
393 | } | 420 | } |
394 | 421 | ||
395 | return are_scts_valid; | 422 | return are_scts_valid; |
396 | } | 423 | } |