Add enum definitions to CT pods
[openssl.git] / doc / crypto / SCT_new.pod
1 =pod
2
3 =head1 NAME
4
5 SCT - A Certificate Transparency Signed Certificate Timestamp
6
7 =head1 SYNOPSIS
8
9  #include <openssl/ct.h>
10
11  typedef enum {
12   CT_LOG_ENTRY_TYPE_NOT_SET = -1,
13   CT_LOG_ENTRY_TYPE_X509 = 0,
14   CT_LOG_ENTRY_TYPE_PRECERT = 1
15  } ct_log_entry_type_t;
16
17  typedef enum {
18   SCT_VERSION_NOT_SET = -1,
19   SCT_VERSION_V1 = 0
20  } sct_version_t;
21
22  typedef enum {
23   SCT_SOURCE_UNKNOWN,
24   SCT_SOURCE_TLS_EXTENSION,
25   SCT_SOURCE_X509V3_EXTENSION,
26   SCT_SOURCE_OCSP_STAPLED_RESPONSE
27  } sct_source_t;
28
29  SCT *SCT_new(void);
30  SCT *SCT_new_from_base64(unsigned char version,
31                           const char *logid_base64,
32                           ct_log_entry_type_t entry_type,
33                           uint64_t timestamp,
34                           const char *extensions_base64,
35                           const char *signature_base64);
36
37  void SCT_free(SCT *sct);
38  void SCT_LIST_free(STACK_OF(SCT) *a);
39
40  sct_version_t SCT_get_version(const SCT *sct);
41  int SCT_set_version(SCT *sct, sct_version_t version);
42
43  ct_log_entry_type_t SCT_get_log_entry_type(const SCT *sct);
44  int SCT_set_log_entry_type(SCT *sct, ct_log_entry_type_t entry_type);
45
46  size_t SCT_get0_log_id(const SCT *sct, unsigned char **log_id);
47  int SCT_set0_log_id(SCT *sct, unsigned char *log_id, size_t log_id_len);
48  int SCT_set1_log_id(SCT *sct, const unsigned char *log_id, size_t log_id_len);
49
50  uint64_t SCT_get_timestamp(const SCT *sct);
51  void SCT_set_timestamp(SCT *sct, uint64_t timestamp);
52
53  int SCT_get_signature_nid(const SCT *sct);
54  int SCT_set_signature_nid(SCT *sct, int nid);
55
56  size_t SCT_get0_extensions(const SCT *sct, unsigned char **ext);
57  void SCT_set0_extensions(SCT *sct, unsigned char *ext, size_t ext_len);
58  int SCT_set1_extensions(SCT *sct, const unsigned char *ext, size_t ext_len);
59
60  size_t SCT_get0_signature(const SCT *sct, unsigned char **sig);
61  void SCT_set0_signature(SCT *sct, unsigned char *sig, size_t sig_len);
62  int SCT_set1_signature(SCT *sct, const unsigned char *sig, size_t sig_len);
63
64  sct_source_t SCT_get_source(const SCT *sct);
65  int SCT_set_source(SCT *sct, sct_source_t source);
66
67 =head1 DESCRIPTION
68
69 Signed Certificate Timestamps (SCTs) are defined by RFC 6962, Section 3.2.
70 They constitute a promise by a Certificate Transparency (CT) log to publicly
71 record a certificate. By cryptographically verifying that a log did indeed issue
72 an SCT, some confidence can be gained that the certificate is publicly known.
73
74 An internal representation of an SCT can be created in one of two ways.
75 The first option is to create a blank SCT, using SCT_new(), and then populate
76 it using:
77
78 =over
79
80 =item * SCT_set_version() to set the SCT version.
81
82 Only SCT_VERSION_V1 is currently supported.
83
84 =item * SCT_set_log_entry_type() to set the type of certificate the SCT was issued for:
85
86 B<CT_LOG_ENTRY_TYPE_X509> for a normal certificate.
87 B<CT_LOG_ENTRY_TYPE_PRECERT> for a pre-certificate.
88
89 =item * SCT_set0_log_id() or SCT_set1_log_id() to set the LogID of the CT log that the SCT came from.
90
91 The former takes ownership, whereas the latter makes a copy.
92 See RFC 6962, Section 3.2 for the definition of LogID.
93
94 =item * SCT_set_timestamp() to set the time the SCT was issued (epoch time in milliseconds).
95
96 =item * SCT_set_signature_nid() to set the NID of the signature.
97
98 =item * SCT_set0_signature() or SCT_set1_signature() to set the raw signature value.
99
100 The former takes ownership, whereas the latter makes a copy.
101
102 =item * SCT_set0_extensions() or B<SCT_set1_extensions> to provide SCT extensions.
103
104 The former takes ownership, whereas the latter makes a copy.
105
106 =back
107
108 Alternatively, the SCT can be pre-populated from the following data using
109 SCT_new_from_base64():
110
111 =over
112
113 =item * The SCT version (only SCT_VERSION_V1 is currently supported).
114
115 =item * The LogID (see RFC 6962, Section 3.2), base64 encoded.
116
117 =item * The type of certificate the SCT was issued for:
118
119 B<CT_LOG_ENTRY_TYPE_X509> for a normal certificate.
120 B<CT_LOG_ENTRY_TYPE_PRECERT> for a pre-certificate.
121
122 =item * The time that the SCT was issued (epoch time in milliseconds).
123
124 =item * The SCT extensions, base64 encoded.
125
126 =item * The SCT signature, base64 encoded.
127
128 =back
129
130 SCT_set_source() can be used to record where the SCT was found
131 (TLS extension, X.509 certificate extension or OCSP response). This is not
132 required for verifying the SCT.
133
134 =head1 NOTES
135
136 Some of the setters return int, instead of void. These will all return 1 on
137 success, 0 on failure. They will not make changes on failure.
138
139 Most of the setters will reset the validation status of the SCT to
140 SCT_VALIDATION_STATUS_NOT_SET (see L<SCT_verify(3)>).
141
142 SCT_set_source() will call SCT_set_log_entry_type() if the type of
143 certificate the SCT was issued for can be inferred from where the SCT was found.
144 For example, an SCT found in an X.509 extension must have been issued for a pre-
145 certificate.
146
147 SCT_set_source() will not refuse unknown values.
148
149 =head1 RETURN VALUES
150
151 SCT_set_version() returns 1 if the specified version is supported, 0 otherwise.
152
153 SCT_set_log_entry_type() returns 1 if the specified log entry type is supported, 0 otherwise.
154
155 SCT_set0_log_id() and B<SCT_set1_log_id> return 1 if the specified LogID is a
156 valid SHA-256 hash, 0 otherwise. Aditionally, B<SCT_set1_log_id> returns 0 if
157 malloc fails.
158
159 B<SCT_set_signature_nid> returns 1 if the specified NID is supported, 0 otherwise.
160
161 B<SCT_set1_extensions> and B<SCT_set1_signature> return 1 if the supplied buffer
162 is copied successfully, 0 otherwise (i.e. if malloc fails).
163
164 B<SCT_set_source> will always return 1.
165
166 =head1 SEE ALSO
167
168 L<ct(3)>,
169 L<SCT_verify(3)>,
170 L<OBJ_nid2obj(3)>
171
172 =head1 COPYRIGHT
173
174 Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
175
176 Licensed under the OpenSSL license (the "License").  You may not use
177 this file except in compliance with the License.  You can obtain a copy
178 in the file LICENSE in the source distribution or at
179 L<https://www.openssl.org/source/license.html>.
180
181 =cut