2 * Written by Rob Percival (robpercival@google.com) for the OpenSSL project.
4 /* ====================================================================
5 * Copyright (c) 2016 The OpenSSL Project. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
19 * 3. All advertising materials mentioning features or use of this
20 * software must display the following acknowledgment:
21 * "This product includes software developed by the OpenSSL Project
22 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25 * endorse or promote products derived from this software without
26 * prior written permission. For written permission, please contact
27 * licensing@OpenSSL.org.
29 * 5. Products derived from this software may not be called "OpenSSL"
30 * nor may "OpenSSL" appear in their names without prior written
31 * permission of the OpenSSL Project.
33 * 6. Redistributions of any form whatsoever must retain the following
35 * "This product includes software developed by the OpenSSL Project
36 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49 * OF THE POSSIBILITY OF SUCH DAMAGE.
50 * ====================================================================
54 # error CT is disabled.
59 #include <openssl/ct.h>
60 #include <openssl/evp.h>
61 #include <openssl/x509.h>
62 #include <openssl/safestack.h>
65 * From RFC6962: opaque SerializedSCT<1..2^16-1>; struct { SerializedSCT
66 * sct_list <1..2^16-1>; } SignedCertificateTimestampList;
68 # define MAX_SCT_SIZE 65535
69 # define MAX_SCT_LIST_SIZE MAX_SCT_SIZE
72 * Macros to read and write integers in network-byte order.
75 #define n2s(c,s) ((s=(((unsigned int)((c)[0]))<< 8)| \
76 (((unsigned int)((c)[1])) )),c+=2)
78 #define s2n(s,c) ((c[0]=(unsigned char)(((s)>> 8)&0xff), \
79 c[1]=(unsigned char)(((s) )&0xff)),c+=2)
81 #define l2n3(l,c) ((c[0]=(unsigned char)(((l)>>16)&0xff), \
82 c[1]=(unsigned char)(((l)>> 8)&0xff), \
83 c[2]=(unsigned char)(((l) )&0xff)),c+=3)
85 #define n2l8(c,l) (l =((uint64_t)(*((c)++)))<<56, \
86 l|=((uint64_t)(*((c)++)))<<48, \
87 l|=((uint64_t)(*((c)++)))<<40, \
88 l|=((uint64_t)(*((c)++)))<<32, \
89 l|=((uint64_t)(*((c)++)))<<24, \
90 l|=((uint64_t)(*((c)++)))<<16, \
91 l|=((uint64_t)(*((c)++)))<< 8, \
92 l|=((uint64_t)(*((c)++))))
94 #define l2n8(l,c) (*((c)++)=(unsigned char)(((l)>>56)&0xff), \
95 *((c)++)=(unsigned char)(((l)>>48)&0xff), \
96 *((c)++)=(unsigned char)(((l)>>40)&0xff), \
97 *((c)++)=(unsigned char)(((l)>>32)&0xff), \
98 *((c)++)=(unsigned char)(((l)>>24)&0xff), \
99 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
100 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
101 *((c)++)=(unsigned char)(((l) )&0xff))
103 /* Signed Certificate Timestamp */
105 sct_version_t version;
106 /* If version is not SCT_VERSION_V1, this contains the encoded SCT */
109 /* If version is SCT_VERSION_V1, fields below contain components of the SCT */
110 unsigned char *log_id;
113 * Note, we cannot distinguish between an unset timestamp, and one
114 * that is set to 0. However since CT didn't exist in 1970, no real
115 * SCT should ever be set as such.
120 unsigned char hash_alg;
121 unsigned char sig_alg;
125 ct_log_entry_type_t entry_type;
126 /* Where this SCT was found, e.g. certificate, OCSP response, etc. */
128 /* The CT log that produced this SCT. */
130 /* The result of the last attempt to validate this SCT. */
131 sct_validation_status_t validation_status;
134 /* Miscellaneous data that is useful when verifying an SCT */
138 /* Hash of public key */
139 unsigned char *pkeyhash;
141 /* For pre-certificate: issuer public key hash */
142 unsigned char *ihash;
144 /* certificate encoding */
145 unsigned char *certder;
147 /* pre-certificate encoding */
148 unsigned char *preder;
152 /* Context when evaluating whether a Certificate Transparency policy is met */
153 struct ct_policy_eval_ctx_st {
156 CTLOG_STORE *log_store;
157 STACK_OF(SCT) *good_scts;
158 STACK_OF(SCT) *bad_scts;
162 * Creates a new context for verifying an SCT.
164 SCT_CTX *SCT_CTX_new(void);
166 * Deletes an SCT verification context.
168 void SCT_CTX_free(SCT_CTX *sctx);
170 /* Sets the certificate that the SCT is related to */
171 int SCT_CTX_set1_cert(SCT_CTX *sctx, X509 *cert, X509 *presigner);
172 /* Sets the issuer of the certificate that the SCT is related to */
173 int SCT_CTX_set1_issuer(SCT_CTX *sctx, const X509 *issuer);
174 /* Sets the public key of the issuer of the certificate that the SCT relates to */
175 int SCT_CTX_set1_issuer_pubkey(SCT_CTX *sctx, X509_PUBKEY *pubkey);
176 /* Sets the public key of the CT log that the SCT is from */
177 int SCT_CTX_set1_pubkey(SCT_CTX *sctx, X509_PUBKEY *pubkey);
180 * Does this SCT have the minimum fields populated to be usuable?
181 * Returns 1 if so, 0 otherwise.
183 int SCT_is_complete(const SCT *sct);
186 * Does this SCT have the signature-related fields populated?
187 * Returns 1 if so, 0 otherwise.
188 * This checks that the signature and hash algorithms are set to supported
189 * values and that the signature field is set.
191 int SCT_signature_is_complete(const SCT *sct);