1*4002f84fSriastradh /* $NetBSD: ssl-bozo.c,v 1.34 2023/12/18 03:48:57 riastradh Exp $ */
218c80b65Stls
341f9e942Smrg /* $eterna: ssl-bozo.c,v 1.15 2011/11/18 09:21:15 mrg Exp $ */
460dbe745Stls
560dbe745Stls /*
6f655db1dSmrg * Copyright (c) 1997-2023 Matthew R. Green
760dbe745Stls * All rights reserved.
860dbe745Stls *
960dbe745Stls * Redistribution and use in source and binary forms, with or without
1060dbe745Stls * modification, are permitted provided that the following conditions
1160dbe745Stls * are met:
1260dbe745Stls * 1. Redistributions of source code must retain the above copyright
1360dbe745Stls * notice, this list of conditions and the following disclaimer.
1460dbe745Stls * 2. Redistributions in binary form must reproduce the above copyright
1560dbe745Stls * notice, this list of conditions and the following disclaimer and
1660dbe745Stls * dedication in the documentation and/or other materials provided
1760dbe745Stls * with the distribution.
1860dbe745Stls *
1960dbe745Stls * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2060dbe745Stls * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2160dbe745Stls * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2260dbe745Stls * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2360dbe745Stls * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
2460dbe745Stls * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2560dbe745Stls * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
2660dbe745Stls * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2760dbe745Stls * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2860dbe745Stls * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2960dbe745Stls * SUCH DAMAGE.
3060dbe745Stls *
3160dbe745Stls */
3260dbe745Stls
3371b444f2Smrg /* this code implements SSL and backend IO for bozohttpd */
3460dbe745Stls
35ce206308Smrg #include <stdarg.h>
36ce206308Smrg #include <stdio.h>
375f8b254cSchristos #include <string.h>
381fe1233eSmrg #include <syslog.h>
3960dbe745Stls #include <unistd.h>
4060dbe745Stls
41ce206308Smrg #include "bozohttpd.h"
42ce206308Smrg
434864410bSmrg #ifndef USE_ARG
444864410bSmrg #define USE_ARG(x) /*LINTED*/(void)&(x)
454864410bSmrg #endif
464864410bSmrg
47ce206308Smrg #ifndef NO_SSL_SUPPORT
48ce206308Smrg
4960dbe745Stls #include <openssl/ssl.h>
5060dbe745Stls #include <openssl/err.h>
5160dbe745Stls
5214ba2569Schristos #ifndef BOZO_SSL_CIPHERS
5314ba2569Schristos #define BOZO_SSL_CIPHERS \
54876508f6Smrg "HIGH:" \
55876508f6Smrg "-SHA:-ADH:" \
56876508f6Smrg "-PSK-AES128-CCM:-PSK-AES256-CCM:" \
57876508f6Smrg "-DHE-PSK-AES128-CCM8:-DHE-PSK-AES256-CCM8:" \
58876508f6Smrg "-AES128-CCM8:-AES256-CCM8:" \
59876508f6Smrg "-DHE-RSA-AES128-CCM8:-DHE-RSA-AES256-CCM8:" \
60876508f6Smrg "-PSK-AES128-CCM8:-PSK-AES256-CCM8:" \
61876508f6Smrg "-CAMELLIA128:-CAMELLIA256:" \
62876508f6Smrg "-RSA-PSK-CHACHA20-POLY1305:" \
6314ba2569Schristos "!aNULL:!eNULL:" \
6414ba2569Schristos "!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:" \
6514ba2569Schristos "!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:" \
6614ba2569Schristos "!KRB5-DES-CBC3-SHA"
6714ba2569Schristos #endif
6814ba2569Schristos
69ce206308Smrg /* this structure encapsulates the ssl info */
70ce206308Smrg typedef struct sslinfo_t {
71ce206308Smrg SSL_CTX *ssl_context;
72ce206308Smrg const SSL_METHOD *ssl_method;
73ce206308Smrg SSL *bozossl;
74ce206308Smrg char *certificate_file;
75ce206308Smrg char *privatekey_file;
7614ba2569Schristos char *ciphers;
77ce206308Smrg } sslinfo_t;
7860dbe745Stls
7919f40606Smrg /* Default to TLS 1.3. */
8019f40606Smrg struct {
8119f40606Smrg unsigned proto;
8219f40606Smrg const char *name;
8319f40606Smrg } protos[] = {
8419f40606Smrg { TLS1_3_VERSION, "TLSv1.3" },
8519f40606Smrg { TLS1_2_VERSION, "TLSv1.2" },
8619f40606Smrg { TLS1_1_VERSION, "TLSv1.1" },
8719f40606Smrg { 0, NULL },
8819f40606Smrg };
8919f40606Smrg
9019f40606Smrg static int
bozo_ssl_proto(const char * name)9119f40606Smrg bozo_ssl_proto(const char *name)
9219f40606Smrg {
9319f40606Smrg unsigned i;
9419f40606Smrg
9519f40606Smrg if (name)
9619f40606Smrg for (i = 0; protos[0].proto != 0; i++)
9719f40606Smrg if (strcasecmp(name, protos[i].name) == 0)
9819f40606Smrg return protos[i].proto;
9919f40606Smrg return protos[0].proto;
10019f40606Smrg }
10119f40606Smrg
10219f40606Smrg static const char *
bozo_ssl_name(unsigned version)10319f40606Smrg bozo_ssl_name(unsigned version)
10419f40606Smrg {
10519f40606Smrg unsigned i;
10619f40606Smrg
10719f40606Smrg for (i = 0; protos[0].proto != 0; i++)
10819f40606Smrg if (version == protos[i].proto)
10919f40606Smrg return protos[i].name;
11019f40606Smrg return protos[0].name;
11119f40606Smrg }
11219f40606Smrg
1131fe1233eSmrg /*
11471b444f2Smrg * bozo_clear_ssl_queue: print the contents of the SSL error queue
1151fe1233eSmrg */
11671b444f2Smrg static void
bozo_clear_ssl_queue(bozohttpd_t * httpd)11771b444f2Smrg bozo_clear_ssl_queue(bozohttpd_t *httpd)
1181fe1233eSmrg {
11971b444f2Smrg unsigned long sslcode = ERR_get_error();
1201fe1233eSmrg
1211fe1233eSmrg do {
1220456a9b5Shannken static const char sslfmt[] = "SSL Error: %s:%s:%s";
1231fe1233eSmrg
1243e94b887Smartin if (httpd->nolog)
1253e94b887Smartin continue;
1263e94b887Smartin
1271fe1233eSmrg if (httpd->logstderr || isatty(STDERR_FILENO)) {
1281fe1233eSmrg fprintf(stderr, sslfmt,
1291fe1233eSmrg ERR_lib_error_string(sslcode),
1301fe1233eSmrg ERR_func_error_string(sslcode),
1311fe1233eSmrg ERR_reason_error_string(sslcode));
132*4002f84fSriastradh fputs("\n", stderr);
1331fe1233eSmrg } else {
1341fe1233eSmrg syslog(LOG_ERR, sslfmt,
1351fe1233eSmrg ERR_lib_error_string(sslcode),
1361fe1233eSmrg ERR_func_error_string(sslcode),
1371fe1233eSmrg ERR_reason_error_string(sslcode));
1381fe1233eSmrg }
1391fe1233eSmrg } while (0 != (sslcode = ERR_get_error()));
14071b444f2Smrg }
14171b444f2Smrg
14271b444f2Smrg /*
143881b8188Smrg * bozo_ssl_warn works just like bozowarn, plus the SSL error queue
14471b444f2Smrg */
14571b444f2Smrg BOZO_PRINTFLIKE(2, 3) static void
bozo_ssl_warn(bozohttpd_t * httpd,const char * fmt,...)14671b444f2Smrg bozo_ssl_warn(bozohttpd_t *httpd, const char *fmt, ...)
14771b444f2Smrg {
14871b444f2Smrg va_list ap;
14971b444f2Smrg
15071b444f2Smrg va_start(ap, fmt);
1513e94b887Smartin if (!httpd->nolog) {
15271b444f2Smrg if (httpd->logstderr || isatty(STDERR_FILENO)) {
15371b444f2Smrg vfprintf(stderr, fmt, ap);
15471b444f2Smrg fputs("\n", stderr);
15571b444f2Smrg } else
15671b444f2Smrg vsyslog(LOG_ERR, fmt, ap);
1573e94b887Smartin }
15871b444f2Smrg va_end(ap);
15971b444f2Smrg
16071b444f2Smrg bozo_clear_ssl_queue(httpd);
16171b444f2Smrg }
16271b444f2Smrg
16371b444f2Smrg
16471b444f2Smrg /*
165881b8188Smrg * bozo_ssl_err works just like bozoerr, plus the SSL error queue
16671b444f2Smrg */
16771b444f2Smrg BOZO_PRINTFLIKE(3, 4) BOZO_DEAD static void
bozo_ssl_err(bozohttpd_t * httpd,int code,const char * fmt,...)16871b444f2Smrg bozo_ssl_err(bozohttpd_t *httpd, int code, const char *fmt, ...)
16971b444f2Smrg {
17071b444f2Smrg va_list ap;
17171b444f2Smrg
17271b444f2Smrg va_start(ap, fmt);
1733e94b887Smartin if (!httpd->nolog) {
17471b444f2Smrg if (httpd->logstderr || isatty(STDERR_FILENO)) {
17571b444f2Smrg vfprintf(stderr, fmt, ap);
17671b444f2Smrg fputs("\n", stderr);
17771b444f2Smrg } else
17871b444f2Smrg vsyslog(LOG_ERR, fmt, ap);
1793e94b887Smartin }
18071b444f2Smrg va_end(ap);
18171b444f2Smrg
18271b444f2Smrg bozo_clear_ssl_queue(httpd);
1831fe1233eSmrg exit(code);
1841fe1233eSmrg }
1851fe1233eSmrg
18671b444f2Smrg /*
18771b444f2Smrg * bozo_check_error_queue: print warnings if the error isn't expected
18871b444f2Smrg */
18971b444f2Smrg static void
bozo_check_error_queue(bozohttpd_t * httpd,const char * tag,int ret)19071b444f2Smrg bozo_check_error_queue(bozohttpd_t *httpd, const char *tag, int ret)
19171b444f2Smrg {
19271b444f2Smrg if (ret > 0)
19371b444f2Smrg return;
19471b444f2Smrg
19571b444f2Smrg const sslinfo_t *sslinfo = httpd->sslinfo;
19671b444f2Smrg const int sslerr = SSL_get_error(sslinfo->bozossl, ret);
19771b444f2Smrg
19871b444f2Smrg if (sslerr != SSL_ERROR_ZERO_RETURN &&
19971b444f2Smrg sslerr != SSL_ERROR_SYSCALL &&
20071b444f2Smrg sslerr != SSL_ERROR_NONE)
20171b444f2Smrg bozo_ssl_warn(httpd, "%s: SSL_ERROR %d", tag, sslerr);
20271b444f2Smrg }
20371b444f2Smrg
20462451b58Sjoerg static BOZO_PRINTFLIKE(2, 0) int
bozo_ssl_printf(bozohttpd_t * httpd,const char * fmt,va_list ap)2051fe1233eSmrg bozo_ssl_printf(bozohttpd_t *httpd, const char * fmt, va_list ap)
20660dbe745Stls {
207ce206308Smrg char *buf;
208ce206308Smrg int nbytes;
20960dbe745Stls
21071b444f2Smrg if ((nbytes = vasprintf(&buf, fmt, ap)) != -1) {
21171b444f2Smrg const sslinfo_t *sslinfo = httpd->sslinfo;
21271b444f2Smrg int ret = SSL_write(sslinfo->bozossl, buf, nbytes);
21371b444f2Smrg bozo_check_error_queue(httpd, "write", ret);
21471b444f2Smrg }
215ce206308Smrg
216ac9efee5Sagc free(buf);
21760dbe745Stls
21860dbe745Stls return nbytes;
21960dbe745Stls }
22060dbe745Stls
22160dbe745Stls static ssize_t
bozo_ssl_read(bozohttpd_t * httpd,int fd,void * buf,size_t nbytes)222ce206308Smrg bozo_ssl_read(bozohttpd_t *httpd, int fd, void *buf, size_t nbytes)
22360dbe745Stls {
224002519bfSmrg const sslinfo_t *sslinfo = httpd->sslinfo;
22571b444f2Smrg int ret;
22660dbe745Stls
227ce206308Smrg USE_ARG(fd);
22871b444f2Smrg ret = SSL_read(sslinfo->bozossl, buf, (int)nbytes);
22971b444f2Smrg bozo_check_error_queue(httpd, "read", ret);
23060dbe745Stls
23171b444f2Smrg return (ssize_t)ret;
23260dbe745Stls }
23360dbe745Stls
23460dbe745Stls static ssize_t
bozo_ssl_write(bozohttpd_t * httpd,int fd,const void * buf,size_t nbytes)235ce206308Smrg bozo_ssl_write(bozohttpd_t *httpd, int fd, const void *buf, size_t nbytes)
23660dbe745Stls {
237002519bfSmrg const sslinfo_t *sslinfo = httpd->sslinfo;
23871b444f2Smrg int ret;
23960dbe745Stls
240ce206308Smrg USE_ARG(fd);
24171b444f2Smrg ret = SSL_write(sslinfo->bozossl, buf, (int)nbytes);
24271b444f2Smrg bozo_check_error_queue(httpd, "write", ret);
24360dbe745Stls
24471b444f2Smrg return (ssize_t)ret;
24560dbe745Stls }
246ce206308Smrg
247ce206308Smrg void
bozo_ssl_init(bozohttpd_t * httpd)248ce206308Smrg bozo_ssl_init(bozohttpd_t *httpd)
249ce206308Smrg {
250002519bfSmrg sslinfo_t *sslinfo = httpd->sslinfo;
25119f40606Smrg int proto;
252ce206308Smrg
253ce206308Smrg if (sslinfo == NULL || !sslinfo->certificate_file)
254ce206308Smrg return;
255ce206308Smrg SSL_library_init();
256ce206308Smrg SSL_load_error_strings();
257ce206308Smrg
258ce206308Smrg sslinfo->ssl_method = SSLv23_server_method();
259ce206308Smrg sslinfo->ssl_context = SSL_CTX_new(sslinfo->ssl_method);
260ce206308Smrg
2611fe1233eSmrg if (NULL == sslinfo->ssl_context)
2621fe1233eSmrg bozo_ssl_err(httpd, EXIT_FAILURE,
2631fe1233eSmrg "SSL context creation failed");
264ce206308Smrg
26519f40606Smrg proto = bozo_ssl_proto(httpd->ssl_min_proto);
26619f40606Smrg
26719f40606Smrg if (!SSL_CTX_set_min_proto_version(sslinfo->ssl_context, proto))
26814ba2569Schristos bozo_ssl_err(httpd, EXIT_FAILURE,
26919f40606Smrg "Error setting minimum protocol version '%s'",
27019f40606Smrg bozo_ssl_name(proto));
27114ba2569Schristos
27214ba2569Schristos if (!SSL_CTX_set_cipher_list(sslinfo->ssl_context,
27314ba2569Schristos sslinfo->ciphers ? sslinfo->ciphers : BOZO_SSL_CIPHERS))
27414ba2569Schristos bozo_ssl_err(httpd, EXIT_FAILURE,
27514ba2569Schristos "Error setting cipher list '%s'", sslinfo->ciphers);
27614ba2569Schristos
277982f9a19Selric if (1 != SSL_CTX_use_certificate_chain_file(sslinfo->ssl_context,
278982f9a19Selric sslinfo->certificate_file))
2791fe1233eSmrg bozo_ssl_err(httpd, EXIT_FAILURE,
2801fe1233eSmrg "Unable to use certificate file '%s'",
2811fe1233eSmrg sslinfo->certificate_file);
2821fe1233eSmrg
2831fe1233eSmrg if (1 != SSL_CTX_use_PrivateKey_file(sslinfo->ssl_context,
2841fe1233eSmrg sslinfo->privatekey_file, SSL_FILETYPE_PEM))
2851fe1233eSmrg bozo_ssl_err(httpd, EXIT_FAILURE,
2861fe1233eSmrg "Unable to use private key file '%s'",
2871fe1233eSmrg sslinfo->privatekey_file);
288ce206308Smrg
289ce206308Smrg /* check consistency of key vs certificate */
290ce206308Smrg if (!SSL_CTX_check_private_key(sslinfo->ssl_context))
2911fe1233eSmrg bozo_ssl_err(httpd, EXIT_FAILURE,
2921fe1233eSmrg "Check private key failed");
293ce206308Smrg }
294ce206308Smrg
29571b444f2Smrg /*
29671b444f2Smrg * returns non-zero for failure
29771b444f2Smrg */
29871b444f2Smrg int
bozo_ssl_accept(bozohttpd_t * httpd)299ce206308Smrg bozo_ssl_accept(bozohttpd_t *httpd)
300ce206308Smrg {
301002519bfSmrg sslinfo_t *sslinfo = httpd->sslinfo;
302ce206308Smrg
30371b444f2Smrg if (sslinfo == NULL || !sslinfo->ssl_context)
30471b444f2Smrg return 0;
30571b444f2Smrg
30608dbfa23Smrg alarm(httpd->ssl_timeout);
30708dbfa23Smrg
308ce206308Smrg sslinfo->bozossl = SSL_new(sslinfo->ssl_context);
30971b444f2Smrg if (sslinfo->bozossl == NULL)
310881b8188Smrg bozoerr(httpd, 1, "SSL_new failed");
31171b444f2Smrg
312ce206308Smrg SSL_set_rfd(sslinfo->bozossl, 0);
313ce206308Smrg SSL_set_wfd(sslinfo->bozossl, 1);
31471b444f2Smrg
31571b444f2Smrg const int ret = SSL_accept(sslinfo->bozossl);
31671b444f2Smrg bozo_check_error_queue(httpd, "accept", ret);
31771b444f2Smrg
31808dbfa23Smrg alarm(0);
31908dbfa23Smrg
32008dbfa23Smrg if (bozo_timeout_hit) {
32108dbfa23Smrg SSL_free(sslinfo->bozossl);
32208dbfa23Smrg sslinfo->bozossl = NULL;
32308dbfa23Smrg return 1;
32408dbfa23Smrg }
32508dbfa23Smrg
32671b444f2Smrg return ret != 1;
327ce206308Smrg }
328ce206308Smrg
329ce206308Smrg void
bozo_ssl_shutdown(bozohttpd_t * httpd)3300acfa6caSspz bozo_ssl_shutdown(bozohttpd_t *httpd)
3310acfa6caSspz {
3320acfa6caSspz const sslinfo_t *sslinfo = httpd->sslinfo;
3330acfa6caSspz
3340acfa6caSspz if (sslinfo && sslinfo->bozossl)
3350acfa6caSspz SSL_shutdown(sslinfo->bozossl);
3360acfa6caSspz }
3370acfa6caSspz
3380acfa6caSspz void
bozo_ssl_destroy(bozohttpd_t * httpd)339ce206308Smrg bozo_ssl_destroy(bozohttpd_t *httpd)
340ce206308Smrg {
341002519bfSmrg const sslinfo_t *sslinfo = httpd->sslinfo;
342ce206308Smrg
343ce206308Smrg if (sslinfo && sslinfo->bozossl)
344ce206308Smrg SSL_free(sslinfo->bozossl);
345ce206308Smrg }
346ce206308Smrg
34714ba2569Schristos static sslinfo_t *
bozo_get_sslinfo(bozohttpd_t * httpd)34814ba2569Schristos bozo_get_sslinfo(bozohttpd_t *httpd)
349ce206308Smrg {
35014ba2569Schristos sslinfo_t *sslinfo;
35114ba2569Schristos if (httpd->sslinfo)
35214ba2569Schristos return httpd->sslinfo;
353ce206308Smrg sslinfo = bozomalloc(httpd, sizeof(*sslinfo));
35471b444f2Smrg if (sslinfo == NULL)
355881b8188Smrg bozoerr(httpd, 1, "sslinfo allocation failed");
35614ba2569Schristos memset(sslinfo, 0, sizeof(*sslinfo));
35714ba2569Schristos return httpd->sslinfo = sslinfo;
358ce206308Smrg }
35914ba2569Schristos
36014ba2569Schristos void
bozo_ssl_set_opts(bozohttpd_t * httpd,const char * cert,const char * priv)36114ba2569Schristos bozo_ssl_set_opts(bozohttpd_t *httpd, const char *cert, const char *priv)
36214ba2569Schristos {
36314ba2569Schristos sslinfo_t *sslinfo = bozo_get_sslinfo(httpd);
36414ba2569Schristos
365cff2d956Smrg sslinfo->certificate_file = bozostrdup(httpd, NULL, cert);
366cff2d956Smrg sslinfo->privatekey_file = bozostrdup(httpd, NULL, priv);
367ce206308Smrg debug((httpd, DEBUG_NORMAL, "using cert/priv files: %s & %s",
368ce206308Smrg sslinfo->certificate_file,
369ce206308Smrg sslinfo->privatekey_file));
370002519bfSmrg if (!httpd->bindport)
371bf53dc23Smrg httpd->bindport = bozostrdup(httpd, NULL, BOZO_HTTPS_PORT);
37214ba2569Schristos }
37314ba2569Schristos
37414ba2569Schristos void
bozo_ssl_set_ciphers(bozohttpd_t * httpd,const char * ciphers)37514ba2569Schristos bozo_ssl_set_ciphers(bozohttpd_t *httpd, const char *ciphers)
37614ba2569Schristos {
37714ba2569Schristos sslinfo_t *sslinfo = bozo_get_sslinfo(httpd);
37814ba2569Schristos
379cff2d956Smrg sslinfo->ciphers = bozostrdup(httpd, NULL, ciphers);
38014ba2569Schristos debug((httpd, DEBUG_NORMAL, "using ciphers: %s", sslinfo->ciphers));
381ce206308Smrg }
382ce206308Smrg
38360dbe745Stls #endif /* NO_SSL_SUPPORT */
384ce206308Smrg
3854cfb2183Smrg /*
3864cfb2183Smrg * These functions are always present, so that caller code can simply
3874cfb2183Smrg * use bozo_*() for IO, regardless of SSL.
3884cfb2183Smrg */
389ce206308Smrg int
bozo_printf(bozohttpd_t * httpd,const char * fmt,...)390ce206308Smrg bozo_printf(bozohttpd_t *httpd, const char *fmt, ...)
391ce206308Smrg {
392ce206308Smrg va_list args;
393ce206308Smrg int cc;
394ce206308Smrg
3954864410bSmrg USE_ARG(httpd);
3964864410bSmrg
397ce206308Smrg va_start(args, fmt);
398ce206308Smrg #ifndef NO_SSL_SUPPORT
399002519bfSmrg if (httpd->sslinfo)
400ce206308Smrg cc = bozo_ssl_printf(httpd, fmt, args);
401002519bfSmrg else
402ce206308Smrg #endif
403ce206308Smrg cc = vprintf(fmt, args);
404ce206308Smrg va_end(args);
405ce206308Smrg return cc;
406ce206308Smrg }
407ce206308Smrg
408ce206308Smrg ssize_t
bozo_read(bozohttpd_t * httpd,int fd,void * buf,size_t len)409ce206308Smrg bozo_read(bozohttpd_t *httpd, int fd, void *buf, size_t len)
410ce206308Smrg {
411ce206308Smrg #ifndef NO_SSL_SUPPORT
412002519bfSmrg if (httpd->sslinfo)
413ce206308Smrg return bozo_ssl_read(httpd, fd, buf, len);
414ce206308Smrg #endif
4154864410bSmrg USE_ARG(httpd);
416ce206308Smrg return read(fd, buf, len);
417ce206308Smrg }
418ce206308Smrg
419ce206308Smrg ssize_t
bozo_write(bozohttpd_t * httpd,int fd,const void * buf,size_t len)420ce206308Smrg bozo_write(bozohttpd_t *httpd, int fd, const void *buf, size_t len)
421ce206308Smrg {
422ce206308Smrg #ifndef NO_SSL_SUPPORT
423002519bfSmrg if (httpd->sslinfo)
424ce206308Smrg return bozo_ssl_write(httpd, fd, buf, len);
425ce206308Smrg #endif
4264864410bSmrg USE_ARG(httpd);
427ce206308Smrg return write(fd, buf, len);
428ce206308Smrg }
429ce206308Smrg
430ce206308Smrg int
bozo_flush(bozohttpd_t * httpd,FILE * fp)431ce206308Smrg bozo_flush(bozohttpd_t *httpd, FILE *fp)
432ce206308Smrg {
433ce206308Smrg #ifndef NO_SSL_SUPPORT
434002519bfSmrg if (httpd->sslinfo)
43571b444f2Smrg return 0;
436ce206308Smrg #endif
4374864410bSmrg USE_ARG(httpd);
438ce206308Smrg return fflush(fp);
439ce206308Smrg }
440