diff options
author | beck <> | 2017-01-31 16:18:57 +0000 |
---|---|---|
committer | beck <> | 2017-01-31 16:18:57 +0000 |
commit | fb9dca0f0ed93924626f04529bb4dfa85e3ef25e (patch) | |
tree | 6cf82628d4d8b9b0ed4d03dd90872a7deae8fcb3 | |
parent | 5dc75c022fd90332aaa1050db40f77ae54a9f43d (diff) | |
download | openbsd-fb9dca0f0ed93924626f04529bb4dfa85e3ef25e.tar.gz openbsd-fb9dca0f0ed93924626f04529bb4dfa85e3ef25e.tar.bz2 openbsd-fb9dca0f0ed93924626f04529bb4dfa85e3ef25e.zip |
Add tls_config_[add|set]keypair_ocsp functions so that ocsp staples may be
added associated to a keypair used for SNI, and are usable for more than
just the "main" certificate. Modify httpd to use this.
Bump libtls minor.
ok jsing@
-rw-r--r-- | src/lib/libtls/Symbols.list | 4 | ||||
-rw-r--r-- | src/lib/libtls/man/tls_config_ocsp_require_stapling.3 | 33 | ||||
-rw-r--r-- | src/lib/libtls/man/tls_load_file.3 | 97 | ||||
-rw-r--r-- | src/lib/libtls/shlib_version | 2 | ||||
-rw-r--r-- | src/lib/libtls/tls.h | 18 | ||||
-rw-r--r-- | src/lib/libtls/tls_config.c | 113 |
6 files changed, 209 insertions, 58 deletions
diff --git a/src/lib/libtls/Symbols.list b/src/lib/libtls/Symbols.list index a033e3e242..eb704ecbd2 100644 --- a/src/lib/libtls/Symbols.list +++ b/src/lib/libtls/Symbols.list | |||
@@ -5,6 +5,8 @@ tls_client | |||
5 | tls_close | 5 | tls_close |
6 | tls_config_add_keypair_file | 6 | tls_config_add_keypair_file |
7 | tls_config_add_keypair_mem | 7 | tls_config_add_keypair_mem |
8 | tls_config_add_keypair_ocsp_file | ||
9 | tls_config_add_keypair_ocsp_mem | ||
8 | tls_config_add_ticket_key | 10 | tls_config_add_ticket_key |
9 | tls_config_clear_keys | 11 | tls_config_clear_keys |
10 | tls_config_error | 12 | tls_config_error |
@@ -30,6 +32,8 @@ tls_config_set_key_file | |||
30 | tls_config_set_key_mem | 32 | tls_config_set_key_mem |
31 | tls_config_set_keypair_file | 33 | tls_config_set_keypair_file |
32 | tls_config_set_keypair_mem | 34 | tls_config_set_keypair_mem |
35 | tls_config_set_keypair_ocsp_file | ||
36 | tls_config_set_keypair_ocsp_mem | ||
33 | tls_config_set_ocsp_staple_mem | 37 | tls_config_set_ocsp_staple_mem |
34 | tls_config_set_ocsp_staple_file | 38 | tls_config_set_ocsp_staple_file |
35 | tls_config_set_protocols | 39 | tls_config_set_protocols |
diff --git a/src/lib/libtls/man/tls_config_ocsp_require_stapling.3 b/src/lib/libtls/man/tls_config_ocsp_require_stapling.3 index 0f532cf8c0..b8b7600904 100644 --- a/src/lib/libtls/man/tls_config_ocsp_require_stapling.3 +++ b/src/lib/libtls/man/tls_config_ocsp_require_stapling.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $OpenBSD: tls_config_ocsp_require_stapling.3,v 1.3 2017/01/28 00:59:36 schwarze Exp $ | 1 | .\" $OpenBSD: tls_config_ocsp_require_stapling.3,v 1.4 2017/01/31 16:18:57 beck Exp $ |
2 | .\" | 2 | .\" |
3 | .\" Copyright (c) 2016 Bob Beck <beck@openbsd.org> | 3 | .\" Copyright (c) 2016 Bob Beck <beck@openbsd.org> |
4 | .\" | 4 | .\" |
@@ -14,46 +14,25 @@ | |||
14 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | 14 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
15 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 15 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
16 | .\" | 16 | .\" |
17 | .Dd $Mdocdate: January 28 2017 $ | 17 | .Dd $Mdocdate: January 31 2017 $ |
18 | .Dt TLS_CONFIG_OCSP_REQUIRE_STAPLING 3 | 18 | .Dt TLS_CONFIG_OCSP_REQUIRE_STAPLING 3 |
19 | .Os | 19 | .Os |
20 | .Sh NAME | 20 | .Sh NAME |
21 | .Nm tls_config_ocsp_require_stapling , | 21 | .Nm tls_config_ocsp_require_stapling , |
22 | .Nm tls_config_set_ocsp_staple_mem , | ||
23 | .Nm tls_config_set_ocsp_staple_file | ||
24 | .Nd OCSP configuration for libtls | 22 | .Nd OCSP configuration for libtls |
25 | .Sh SYNOPSIS | 23 | .Sh SYNOPSIS |
26 | .In tls.h | 24 | .In tls.h |
27 | .Ft void | 25 | .Ft void |
28 | .Fn tls_config_ocsp_require_stapling "struct tls_config *config" | 26 | .Fn tls_config_ocsp_require_stapling "struct tls_config *config" |
29 | .Ft int | ||
30 | .Fo tls_config_set_ocsp_staple_mem | ||
31 | .Fa "struct tls_config *config" | ||
32 | .Fa "const char *staple" | ||
33 | .Fa "size_t len" | ||
34 | .Fc | ||
35 | .Ft int | ||
36 | .Fo tls_config_set_ocsp_staple_file | ||
37 | .Fa "struct tls_config *config" | ||
38 | .Fa "const char *staple_file" | ||
39 | .Fc | 27 | .Fc |
40 | .Sh DESCRIPTION | 28 | .Sh DESCRIPTION |
41 | .Fn tls_config_ocsp_require_stapling | 29 | .Fn tls_config_ocsp_require_stapling |
42 | requires that a valid stapled OCSP response be provided during the TLS handshake. | 30 | requires that a valid stapled OCSP response be provided during the TLS handshake. |
43 | .Pp | ||
44 | .Fn tls_config_set_ocsp_staple_file | ||
45 | sets a DER-encoded OCSP response to be stapled during the TLS handshake from | ||
46 | the specified file. | ||
47 | .Pp | ||
48 | .Fn tls_config_set_ocsp_staple_mem | ||
49 | sets a DER-encoded OCSP response to be stapled during the TLS handshake from | ||
50 | memory. | ||
51 | .Sh RETURN VALUES | ||
52 | .Fn tls_config_set_ocsp_staple_mem | ||
53 | and | ||
54 | .Fn tls_config_set_ocsp_staple_file | ||
55 | return 0 on success or -1 on error. | ||
56 | .Sh SEE ALSO | 31 | .Sh SEE ALSO |
32 | .Xr tls_config_set_keypair_file 3 , | ||
33 | .Xr tls_config_set_keypair_mem 3 , | ||
34 | .Xr tls_config_add_keypair_file 3 , | ||
35 | .Xr tls_config_add_keypair_mem 3 , | ||
57 | .Xr tls_handshake 3 , | 36 | .Xr tls_handshake 3 , |
58 | .Xr tls_init 3 , | 37 | .Xr tls_init 3 , |
59 | .Xr tls_ocsp_process_response 3 | 38 | .Xr tls_ocsp_process_response 3 |
diff --git a/src/lib/libtls/man/tls_load_file.3 b/src/lib/libtls/man/tls_load_file.3 index eeebd0339e..6c0a025955 100644 --- a/src/lib/libtls/man/tls_load_file.3 +++ b/src/lib/libtls/man/tls_load_file.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $OpenBSD: tls_load_file.3,v 1.3 2017/01/28 00:59:36 schwarze Exp $ | 1 | .\" $OpenBSD: tls_load_file.3,v 1.4 2017/01/31 16:18:57 beck Exp $ |
2 | .\" | 2 | .\" |
3 | .\" Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> | 3 | .\" Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> |
4 | .\" Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> | 4 | .\" Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> |
@@ -17,7 +17,7 @@ | |||
17 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | 17 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
18 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 18 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
19 | .\" | 19 | .\" |
20 | .Dd $Mdocdate: January 28 2017 $ | 20 | .Dd $Mdocdate: January 31 2017 $ |
21 | .Dt TLS_LOAD_FILE 3 | 21 | .Dt TLS_LOAD_FILE 3 |
22 | .Os | 22 | .Os |
23 | .Sh NAME | 23 | .Sh NAME |
@@ -29,9 +29,15 @@ | |||
29 | .Nm tls_config_set_cert_mem , | 29 | .Nm tls_config_set_cert_mem , |
30 | .Nm tls_config_set_key_file , | 30 | .Nm tls_config_set_key_file , |
31 | .Nm tls_config_set_key_mem , | 31 | .Nm tls_config_set_key_mem , |
32 | .Nm tls_config_set_ocsp_staple_mem , | ||
33 | .Nm tls_config_set_ocsp_staple_file | ||
32 | .Nm tls_config_set_keypair_file , | 34 | .Nm tls_config_set_keypair_file , |
33 | .Nm tls_config_set_keypair_mem , | 35 | .Nm tls_config_set_keypair_mem , |
36 | .Nm tls_config_set_keypair_ocsp_file , | ||
37 | .Nm tls_config_set_keypair_ocsp_mem , | ||
34 | .Nm tls_config_add_keypair_file , | 38 | .Nm tls_config_add_keypair_file , |
39 | .Nm tls_config_add_keypair_ocsp_mem , | ||
40 | .Nm tls_config_add_keypair_ocsp_file , | ||
35 | .Nm tls_config_add_keypair_mem , | 41 | .Nm tls_config_add_keypair_mem , |
36 | .Nm tls_config_clear_keys , | 42 | .Nm tls_config_clear_keys , |
37 | .Nm tls_config_set_verify_depth , | 43 | .Nm tls_config_set_verify_depth , |
@@ -83,6 +89,17 @@ | |||
83 | .Fa "struct tls_config *config" | 89 | .Fa "struct tls_config *config" |
84 | .Fa "const uint8_t *key" | 90 | .Fa "const uint8_t *key" |
85 | .Fa "size_t len" | 91 | .Fa "size_t len" |
92 | .Ft int | ||
93 | .Fc | ||
94 | .Fo tls_config_set_ocsp_staple_mem | ||
95 | .Fa "struct tls_config *config" | ||
96 | .Fa "const uint8_t *staple" | ||
97 | .Fa "size_t len" | ||
98 | .Fc | ||
99 | .Ft int | ||
100 | .Fo tls_config_set_ocsp_staple_file | ||
101 | .Fa "struct tls_config *config" | ||
102 | .Fa "const uint8_t *staple_file" | ||
86 | .Fc | 103 | .Fc |
87 | .Ft int | 104 | .Ft int |
88 | .Fo tls_config_set_keypair_file | 105 | .Fo tls_config_set_keypair_file |
@@ -99,6 +116,23 @@ | |||
99 | .Fa "size_t key_len" | 116 | .Fa "size_t key_len" |
100 | .Fc | 117 | .Fc |
101 | .Ft int | 118 | .Ft int |
119 | .Fo tls_config_set_keypair_ocsp_file | ||
120 | .Fa "struct tls_config *config" | ||
121 | .Fa "const char *cert_file" | ||
122 | .Fa "const char *key_file" | ||
123 | .Fa "const char *staple_file" | ||
124 | .Fc | ||
125 | .Ft int | ||
126 | .Fo tls_config_set_keypair_ocsp_mem | ||
127 | .Fa "struct tls_config *config" | ||
128 | .Fa "const uint8_t *cert" | ||
129 | .Fa "size_t cert_len" | ||
130 | .Fa "const uint8_t *key" | ||
131 | .Fa "size_t key_len" | ||
132 | .Fa "const uint8_t *staple" | ||
133 | .Fa "size_t staple_len" | ||
134 | .Fc | ||
135 | .Ft int | ||
102 | .Fo tls_config_add_keypair_file | 136 | .Fo tls_config_add_keypair_file |
103 | .Fa "struct tls_config *config" | 137 | .Fa "struct tls_config *config" |
104 | .Fa "const char *cert_file" | 138 | .Fa "const char *cert_file" |
@@ -112,6 +146,23 @@ | |||
112 | .Fa "const uint8_t *key" | 146 | .Fa "const uint8_t *key" |
113 | .Fa "size_t key_len" | 147 | .Fa "size_t key_len" |
114 | .Fc | 148 | .Fc |
149 | .Ft int | ||
150 | .Fo tls_config_add_keypair_ocsp_file | ||
151 | .Fa "struct tls_config *config" | ||
152 | .Fa "const char *cert_file" | ||
153 | .Fa "const char *key_file" | ||
154 | .Fa "const char *staple_file" | ||
155 | .Fc | ||
156 | .Ft int | ||
157 | .Fo tls_config_add_keypair_ocsp_mem | ||
158 | .Fa "struct tls_config *config" | ||
159 | .Fa "const uint8_t *cert" | ||
160 | .Fa "size_t cert_len" | ||
161 | .Fa "const uint8_t *key" | ||
162 | .Fa "size_t key_len" | ||
163 | .Fa "const uint8_t *staple" | ||
164 | .Fa "size_t staple_len" | ||
165 | .Fc | ||
115 | .Ft void | 166 | .Ft void |
116 | .Fn tls_config_clear_keys "struct tls_config *config" | 167 | .Fn tls_config_clear_keys "struct tls_config *config" |
117 | .Ft int | 168 | .Ft int |
@@ -157,19 +208,46 @@ sets the file from which the private key will be read. | |||
157 | .Fn tls_config_set_key_mem | 208 | .Fn tls_config_set_key_mem |
158 | directly sets the private key from memory. | 209 | directly sets the private key from memory. |
159 | .Pp | 210 | .Pp |
211 | .Fn tls_config_set_ocsp_staple_file | ||
212 | sets a DER-encoded OCSP response to be stapled during the TLS handshake from | ||
213 | the specified file. | ||
214 | .Pp | ||
215 | .Fn tls_config_set_ocsp_staple_mem | ||
216 | sets a DER-encoded OCSP response to be stapled during the TLS handshake from | ||
217 | memory. | ||
218 | .Pp | ||
160 | .Fn tls_config_set_keypair_file | 219 | .Fn tls_config_set_keypair_file |
161 | sets the files from which the public certificate and private key will be read. | 220 | sets the files from which the public certificate, and private key will be read. |
162 | .Pp | 221 | .Pp |
163 | .Fn tls_config_set_keypair_mem | 222 | .Fn tls_config_set_keypair_mem |
164 | directly sets the public certificate and private key from memory. | 223 | directly sets the public certificate, and private key from memory. |
224 | .Pp | ||
225 | .Fn tls_config_set_keypair_file | ||
226 | sets the files from which the public certificate, private key, and DER encoded | ||
227 | ocsp staple will be read. | ||
228 | .Pp | ||
229 | .Fn tls_config_set_keypair_ocsp_mem | ||
230 | directly sets the public certificate, private key, and DER encoded OCSP staple | ||
231 | from memory. | ||
165 | .Pp | 232 | .Pp |
166 | .Fn tls_config_add_keypair_file | 233 | .Fn tls_config_add_keypair_file |
167 | adds an additional public certificate and private key from the specified files, | 234 | adds an additional public certificate, and private key from the specified files, |
168 | used as an alternative certificate for Server Name Indication (server only). | 235 | used as an alternative certificate for Server Name Indication (server only). |
169 | .Pp | 236 | .Pp |
170 | .Fn tls_config_add_keypair_mem | 237 | .Fn tls_config_add_keypair_mem |
171 | adds an additional public certificate and private key from memory, | 238 | adds an additional public certificate, and private key from memory, used as an |
172 | used as an alternative certificate for Server Name Indication (server only). | 239 | alternative certificate for Server Name Indication (server only). |
240 | .Pp | ||
241 | .Pp | ||
242 | .Fn tls_config_add_keypair_ocsp_file | ||
243 | adds an additional public certificate, private key, and DER encoded OCSP staple | ||
244 | from the specified files, used as an alternative certificate for Server Name | ||
245 | Indication (server only). | ||
246 | .Pp | ||
247 | .Fn tls_config_add_keypair_ocsp_mem | ||
248 | adds an additional public certificate, private key, and DER encoded OCSP staple | ||
249 | from memory, used as an alternative certificate for Server Name Indication | ||
250 | (server only). | ||
173 | .Pp | 251 | .Pp |
174 | .Fn tls_config_clear_keys | 252 | .Fn tls_config_clear_keys |
175 | clears any secret keys from memory. | 253 | clears any secret keys from memory. |
@@ -240,12 +318,7 @@ in | |||
240 | .An Joel Sing Aq Mt jsing@openbsd.org | 318 | .An Joel Sing Aq Mt jsing@openbsd.org |
241 | with contibutions from | 319 | with contibutions from |
242 | .An Ted Unangst Aq Mt tedu@openbsd.org | 320 | .An Ted Unangst Aq Mt tedu@openbsd.org |
243 | .Pp | ||
244 | .An -nosplit | ||
245 | .Fn tls_config_verify_client | ||
246 | and | 321 | and |
247 | .Fn tls_config_verify_client_optional | ||
248 | were written by | ||
249 | .An Bob Beck Aq Mt beck@openbsd.org . | 322 | .An Bob Beck Aq Mt beck@openbsd.org . |
250 | .Pp | 323 | .Pp |
251 | .Fn tls_load_file | 324 | .Fn tls_load_file |
diff --git a/src/lib/libtls/shlib_version b/src/lib/libtls/shlib_version index 998729533f..a822f1f180 100644 --- a/src/lib/libtls/shlib_version +++ b/src/lib/libtls/shlib_version | |||
@@ -1,2 +1,2 @@ | |||
1 | major=15 | 1 | major=15 |
2 | minor=2 | 2 | minor=3 |
diff --git a/src/lib/libtls/tls.h b/src/lib/libtls/tls.h index 5680c74182..d9b2972e92 100644 --- a/src/lib/libtls/tls.h +++ b/src/lib/libtls/tls.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tls.h,v 1.46 2017/01/26 12:53:17 jsing Exp $ */ | 1 | /* $OpenBSD: tls.h,v 1.47 2017/01/31 16:18:57 beck Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -89,7 +89,12 @@ int tls_config_add_keypair_file(struct tls_config *_config, | |||
89 | const char *_cert_file, const char *_key_file); | 89 | const char *_cert_file, const char *_key_file); |
90 | int tls_config_add_keypair_mem(struct tls_config *_config, const uint8_t *_cert, | 90 | int tls_config_add_keypair_mem(struct tls_config *_config, const uint8_t *_cert, |
91 | size_t _cert_len, const uint8_t *_key, size_t _key_len); | 91 | size_t _cert_len, const uint8_t *_key, size_t _key_len); |
92 | 92 | int tls_config_add_keypair_ocsp_file(struct tls_config *_config, | |
93 | const char *_cert_file, const char *_key_file, | ||
94 | const char *_ocsp_staple_file); | ||
95 | int tls_config_add_keypair_ocsp_mem(struct tls_config *_config, const uint8_t *_cert, | ||
96 | size_t _cert_len, const uint8_t *_key, size_t _key_len, | ||
97 | const uint8_t *_staple, size_t _staple_len); | ||
93 | int tls_config_set_alpn(struct tls_config *_config, const char *_alpn); | 98 | int tls_config_set_alpn(struct tls_config *_config, const char *_alpn); |
94 | int tls_config_set_ca_file(struct tls_config *_config, const char *_ca_file); | 99 | int tls_config_set_ca_file(struct tls_config *_config, const char *_ca_file); |
95 | int tls_config_set_ca_path(struct tls_config *_config, const char *_ca_path); | 100 | int tls_config_set_ca_path(struct tls_config *_config, const char *_ca_path); |
@@ -109,8 +114,13 @@ int tls_config_set_keypair_file(struct tls_config *_config, | |||
109 | const char *_cert_file, const char *_key_file); | 114 | const char *_cert_file, const char *_key_file); |
110 | int tls_config_set_keypair_mem(struct tls_config *_config, const uint8_t *_cert, | 115 | int tls_config_set_keypair_mem(struct tls_config *_config, const uint8_t *_cert, |
111 | size_t _cert_len, const uint8_t *_key, size_t _key_len); | 116 | size_t _cert_len, const uint8_t *_key, size_t _key_len); |
112 | int tls_config_set_ocsp_staple_mem(struct tls_config *_config, char *_staple, | 117 | int tls_config_set_keypair_ocsp_file(struct tls_config *_config, |
113 | size_t _len); | 118 | const char *_cert_file, const char *_key_file, const char *_staple_file); |
119 | int tls_config_set_keypair_ocsp_mem(struct tls_config *_config, const uint8_t *_cert, | ||
120 | size_t _cert_len, const uint8_t *_key, size_t _key_len, | ||
121 | const uint8_t *_staple, size_t staple_len); | ||
122 | int tls_config_set_ocsp_staple_mem(struct tls_config *_config, | ||
123 | const uint8_t *_staple, size_t _len); | ||
114 | int tls_config_set_ocsp_staple_file(struct tls_config *_config, | 124 | int tls_config_set_ocsp_staple_file(struct tls_config *_config, |
115 | const char *_staple_file); | 125 | const char *_staple_file); |
116 | int tls_config_set_protocols(struct tls_config *_config, uint32_t _protocols); | 126 | int tls_config_set_protocols(struct tls_config *_config, uint32_t _protocols); |
diff --git a/src/lib/libtls/tls_config.c b/src/lib/libtls/tls_config.c index 83c649fd51..87c2166f9e 100644 --- a/src/lib/libtls/tls_config.c +++ b/src/lib/libtls/tls_config.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tls_config.c,v 1.35 2017/01/29 17:52:11 beck Exp $ */ | 1 | /* $OpenBSD: tls_config.c,v 1.36 2017/01/31 16:18:57 beck Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -416,9 +416,9 @@ tls_config_set_alpn(struct tls_config *config, const char *alpn) | |||
416 | &config->alpn_len); | 416 | &config->alpn_len); |
417 | } | 417 | } |
418 | 418 | ||
419 | int | 419 | static int |
420 | tls_config_add_keypair_file(struct tls_config *config, | 420 | tls_config_add_keypair_file_internal(struct tls_config *config, |
421 | const char *cert_file, const char *key_file) | 421 | const char *cert_file, const char *key_file, const char *ocsp_file) |
422 | { | 422 | { |
423 | struct tls_keypair *keypair; | 423 | struct tls_keypair *keypair; |
424 | 424 | ||
@@ -428,6 +428,10 @@ tls_config_add_keypair_file(struct tls_config *config, | |||
428 | goto err; | 428 | goto err; |
429 | if (tls_keypair_set_key_file(keypair, &config->error, key_file) != 0) | 429 | if (tls_keypair_set_key_file(keypair, &config->error, key_file) != 0) |
430 | goto err; | 430 | goto err; |
431 | if (ocsp_file != NULL && | ||
432 | tls_keypair_set_ocsp_staple_file(keypair, &config->error, | ||
433 | ocsp_file) != 0) | ||
434 | goto err; | ||
431 | 435 | ||
432 | tls_config_keypair_add(config, keypair); | 436 | tls_config_keypair_add(config, keypair); |
433 | 437 | ||
@@ -438,9 +442,10 @@ tls_config_add_keypair_file(struct tls_config *config, | |||
438 | return (-1); | 442 | return (-1); |
439 | } | 443 | } |
440 | 444 | ||
441 | int | 445 | static int |
442 | tls_config_add_keypair_mem(struct tls_config *config, const uint8_t *cert, | 446 | tls_config_add_keypair_mem_internal(struct tls_config *config, const uint8_t *cert, |
443 | size_t cert_len, const uint8_t *key, size_t key_len) | 447 | size_t cert_len, const uint8_t *key, size_t key_len, |
448 | const uint8_t *staple, size_t staple_len) | ||
444 | { | 449 | { |
445 | struct tls_keypair *keypair; | 450 | struct tls_keypair *keypair; |
446 | 451 | ||
@@ -450,6 +455,9 @@ tls_config_add_keypair_mem(struct tls_config *config, const uint8_t *cert, | |||
450 | goto err; | 455 | goto err; |
451 | if (tls_keypair_set_key_mem(keypair, key, key_len) != 0) | 456 | if (tls_keypair_set_key_mem(keypair, key, key_len) != 0) |
452 | goto err; | 457 | goto err; |
458 | if (staple != NULL && | ||
459 | tls_keypair_set_ocsp_staple_mem(keypair, staple, staple_len) != 0) | ||
460 | goto err; | ||
453 | 461 | ||
454 | tls_config_keypair_add(config, keypair); | 462 | tls_config_keypair_add(config, keypair); |
455 | 463 | ||
@@ -461,6 +469,39 @@ tls_config_add_keypair_mem(struct tls_config *config, const uint8_t *cert, | |||
461 | } | 469 | } |
462 | 470 | ||
463 | int | 471 | int |
472 | tls_config_add_keypair_mem(struct tls_config *config, const uint8_t *cert, | ||
473 | size_t cert_len, const uint8_t *key, size_t key_len) | ||
474 | { | ||
475 | return tls_config_add_keypair_mem_internal(config, cert, cert_len, key, | ||
476 | key_len, NULL, 0); | ||
477 | } | ||
478 | |||
479 | int | ||
480 | tls_config_add_keypair_file(struct tls_config *config, | ||
481 | const char *cert_file, const char *key_file) | ||
482 | { | ||
483 | return tls_config_add_keypair_file_internal(config, cert_file, | ||
484 | key_file, NULL); | ||
485 | } | ||
486 | |||
487 | int | ||
488 | tls_config_add_keypair_ocsp_mem(struct tls_config *config, const uint8_t *cert, | ||
489 | size_t cert_len, const uint8_t *key, size_t key_len, const uint8_t *staple, | ||
490 | size_t staple_len) | ||
491 | { | ||
492 | return tls_config_add_keypair_mem_internal(config, cert, cert_len, key, | ||
493 | key_len, staple, staple_len); | ||
494 | } | ||
495 | |||
496 | int | ||
497 | tls_config_add_keypair_ocsp_file(struct tls_config *config, | ||
498 | const char *cert_file, const char *key_file, const char *ocsp_file) | ||
499 | { | ||
500 | return tls_config_add_keypair_file_internal(config, cert_file, | ||
501 | key_file, ocsp_file); | ||
502 | } | ||
503 | |||
504 | int | ||
464 | tls_config_set_ca_file(struct tls_config *config, const char *ca_file) | 505 | tls_config_set_ca_file(struct tls_config *config, const char *ca_file) |
465 | { | 506 | { |
466 | return tls_config_load_file(&config->error, "CA", ca_file, | 507 | return tls_config_load_file(&config->error, "CA", ca_file, |
@@ -581,31 +622,74 @@ tls_config_set_key_mem(struct tls_config *config, const uint8_t *key, | |||
581 | return tls_keypair_set_key_mem(config->keypair, key, len); | 622 | return tls_keypair_set_key_mem(config->keypair, key, len); |
582 | } | 623 | } |
583 | 624 | ||
584 | int | 625 | static int |
585 | tls_config_set_keypair_file(struct tls_config *config, | 626 | tls_config_set_keypair_file_internal(struct tls_config *config, |
586 | const char *cert_file, const char *key_file) | 627 | const char *cert_file, const char *key_file, const char *ocsp_file) |
587 | { | 628 | { |
588 | if (tls_config_set_cert_file(config, cert_file) != 0) | 629 | if (tls_config_set_cert_file(config, cert_file) != 0) |
589 | return (-1); | 630 | return (-1); |
590 | if (tls_config_set_key_file(config, key_file) != 0) | 631 | if (tls_config_set_key_file(config, key_file) != 0) |
591 | return (-1); | 632 | return (-1); |
633 | if (tls_config_set_key_file(config, key_file) != 0) | ||
634 | return (-1); | ||
635 | if (ocsp_file != NULL && | ||
636 | tls_config_set_ocsp_staple_file(config, ocsp_file) != 0) | ||
637 | return (-1); | ||
592 | 638 | ||
593 | return (0); | 639 | return (0); |
594 | } | 640 | } |
595 | 641 | ||
596 | int | 642 | static int |
597 | tls_config_set_keypair_mem(struct tls_config *config, const uint8_t *cert, | 643 | tls_config_set_keypair_mem_internal(struct tls_config *config, const uint8_t *cert, |
598 | size_t cert_len, const uint8_t *key, size_t key_len) | 644 | size_t cert_len, const uint8_t *key, size_t key_len, |
645 | const uint8_t *staple, size_t staple_len) | ||
599 | { | 646 | { |
600 | if (tls_config_set_cert_mem(config, cert, cert_len) != 0) | 647 | if (tls_config_set_cert_mem(config, cert, cert_len) != 0) |
601 | return (-1); | 648 | return (-1); |
602 | if (tls_config_set_key_mem(config, key, key_len) != 0) | 649 | if (tls_config_set_key_mem(config, key, key_len) != 0) |
603 | return (-1); | 650 | return (-1); |
651 | if ((staple != NULL) && | ||
652 | (tls_config_set_ocsp_staple_mem(config, staple, staple_len) != 0)) | ||
653 | return (-1); | ||
604 | 654 | ||
605 | return (0); | 655 | return (0); |
606 | } | 656 | } |
607 | 657 | ||
608 | int | 658 | int |
659 | tls_config_set_keypair_file(struct tls_config *config, | ||
660 | const char *cert_file, const char *key_file) | ||
661 | { | ||
662 | return tls_config_set_keypair_file_internal(config, cert_file, key_file, | ||
663 | NULL); | ||
664 | } | ||
665 | |||
666 | int | ||
667 | tls_config_set_keypair_mem(struct tls_config *config, const uint8_t *cert, | ||
668 | size_t cert_len, const uint8_t *key, size_t key_len) | ||
669 | { | ||
670 | return tls_config_set_keypair_mem_internal(config, cert, cert_len, | ||
671 | key, key_len, NULL, 0); | ||
672 | } | ||
673 | |||
674 | int | ||
675 | tls_config_set_keypair_ocsp_file(struct tls_config *config, | ||
676 | const char *cert_file, const char *key_file, const char *ocsp_file) | ||
677 | { | ||
678 | return tls_config_set_keypair_file_internal(config, cert_file, key_file, | ||
679 | ocsp_file); | ||
680 | } | ||
681 | |||
682 | int | ||
683 | tls_config_set_keypair_ocsp_mem(struct tls_config *config, const uint8_t *cert, | ||
684 | size_t cert_len, const uint8_t *key, size_t key_len, | ||
685 | const uint8_t *staple, size_t staple_len) | ||
686 | { | ||
687 | return tls_config_set_keypair_mem_internal(config, cert, cert_len, | ||
688 | key, key_len, staple, staple_len); | ||
689 | } | ||
690 | |||
691 | |||
692 | int | ||
609 | tls_config_set_protocols(struct tls_config *config, uint32_t protocols) | 693 | tls_config_set_protocols(struct tls_config *config, uint32_t protocols) |
610 | { | 694 | { |
611 | config->protocols = protocols; | 695 | config->protocols = protocols; |
@@ -685,7 +769,8 @@ tls_config_set_ocsp_staple_file(struct tls_config *config, const char *staple_fi | |||
685 | } | 769 | } |
686 | 770 | ||
687 | int | 771 | int |
688 | tls_config_set_ocsp_staple_mem(struct tls_config *config, char *staple, size_t len) | 772 | tls_config_set_ocsp_staple_mem(struct tls_config *config, const uint8_t *staple, |
773 | size_t len) | ||
689 | { | 774 | { |
690 | return tls_keypair_set_ocsp_staple_mem(config->keypair, staple, len); | 775 | return tls_keypair_set_ocsp_staple_mem(config->keypair, staple, len); |
691 | } | 776 | } |