2 * Copyright (c) 2016 Thomas Pornin <pornin@bolet.org>
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 #include <sys/types.h>
32 #include <sys/socket.h>
34 #include <netinet/in.h>
35 #include <arpa/inet.h>
43 host_bind(const char *host
, const char *port
, int verbose
)
45 struct addrinfo hints
, *si
, *p
;
49 memset(&hints
, 0, sizeof hints
);
50 hints
.ai_family
= PF_UNSPEC
;
51 hints
.ai_socktype
= SOCK_STREAM
;
52 err
= getaddrinfo(host
, port
, &hints
, &si
);
54 fprintf(stderr
, "ERROR: getaddrinfo(): %s\n",
59 for (p
= si
; p
!= NULL
; p
= p
->ai_next
) {
61 struct sockaddr_in sa4
;
62 struct sockaddr_in6 sa6
;
65 char tmp
[INET6_ADDRSTRLEN
+ 50];
68 sa
= (struct sockaddr
*)p
->ai_addr
;
69 if (sa
->sa_family
== AF_INET
) {
70 sa4
= *(struct sockaddr_in
*)sa
;
71 sa
= (struct sockaddr
*)&sa4
;
75 sa4
.sin_addr
.s_addr
= INADDR_ANY
;
77 } else if (sa
->sa_family
== AF_INET6
) {
78 sa6
= *(struct sockaddr_in6
*)sa
;
79 sa
= (struct sockaddr
*)&sa6
;
81 addr
= &sa6
.sin6_addr
;
83 sa6
.sin6_addr
= in6addr_any
;
87 sa_len
= p
->ai_addrlen
;
90 inet_ntop(p
->ai_family
, addr
, tmp
, sizeof tmp
);
92 sprintf(tmp
, "<unknown family: %d>",
96 fprintf(stderr
, "binding to: %s\n", tmp
);
98 fd
= socket(p
->ai_family
, p
->ai_socktype
, p
->ai_protocol
);
106 setsockopt(fd
, SOL_SOCKET
, SO_REUSEADDR
, &opt
, sizeof opt
);
108 setsockopt(fd
, IPPROTO_IPV6
, IPV6_V6ONLY
, &opt
, sizeof opt
);
109 if (bind(fd
, sa
, sa_len
) < 0) {
120 fprintf(stderr
, "ERROR: failed to bind\n");
124 if (listen(fd
, 5) < 0) {
132 fprintf(stderr
, "bound.\n");
138 accept_client(int server_fd
, int verbose
)
145 fd
= accept(server_fd
, &sa
, &sa_len
);
153 char tmp
[INET6_ADDRSTRLEN
+ 50];
157 switch (sa
.sa_family
) {
159 name
= inet_ntop(AF_INET
,
160 &((struct sockaddr_in
*)&sa
)->sin_addr
,
164 name
= inet_ntop(AF_INET6
,
165 &((struct sockaddr_in6
*)&sa
)->sin6_addr
,
170 sprintf(tmp
, "<unknown: %lu>",
171 (unsigned long)sa
.sa_family
);
174 fprintf(stderr
, "accepting connection from: %s\n", name
);
178 * We make the socket non-blocking, since we are going to use
179 * poll() to organise I/O.
181 fcntl(fd
, F_SETFL
, O_NONBLOCK
);
189 "usage: brssl server [ options ]\n");
193 " -q suppress verbose messages\n");
195 " -trace activate extra debug messages (dump of all packets)\n");
197 " -b name bind to a specific address or host name\n");
199 " -p port bind to a specific port (default: 4433)\n");
201 " -mono use monodirectional buffering\n");
203 " -buf length set the I/O buffer length (in bytes)\n");
205 " -cache length set the session cache storage length (in bytes)\n");
207 " -cert fname read certificate chain from file 'fname'\n");
209 " -key fname read private key from file 'fname'\n");
211 " -list list supported names (protocols, algorithms...)\n");
213 " -vmin name set minimum supported version (default: TLS-1.0)\n");
215 " -vmax name set maximum supported version (default: TLS-1.2)\n");
217 " -cs names set list of supported cipher suites (comma-separated)\n");
219 " -hf names add support for some hash functions (comma-separated)\n");
221 " -serverpref enforce server's preferences for cipher suites\n");
226 const br_ssl_server_policy_class
*vtable
;
228 br_x509_certificate
*chain
;
230 int cert_signer_algo
;
235 get_cert_signer_algo(br_x509_certificate
*xc
)
237 br_x509_decoder_context dc
;
240 br_x509_decoder_init(&dc
, 0, 0);
241 br_x509_decoder_push(&dc
, xc
->data
, xc
->data_len
);
242 err
= br_x509_decoder_last_error(&dc
);
246 return br_x509_decoder_get_signer_key_type(&dc
);
251 sp_choose(const br_ssl_server_policy_class
**pctx
,
252 const br_ssl_server_context
*cc
,
253 br_ssl_server_choices
*choices
)
256 const br_suite_translated
*st
;
261 pc
= (policy_context
*)pctx
;
262 st
= br_ssl_server_get_client_suites(cc
, &st_num
);
263 chashes
= br_ssl_server_get_client_hashes(cc
);
264 for (hash_id
= 6; hash_id
>= 2; hash_id
--) {
265 if ((chashes
>> hash_id
) & 1) {
270 fprintf(stderr
, "Client parameters:\n");
271 fprintf(stderr
, " Maximum version: ");
272 switch (cc
->client_max_version
) {
274 fprintf(stderr
, "SSL 3.0");
277 fprintf(stderr
, "TLS 1.0");
280 fprintf(stderr
, "TLS 1.1");
283 fprintf(stderr
, "TLS 1.2");
286 fprintf(stderr
, "unknown (0x%04X)",
287 (unsigned)cc
->client_max_version
);
290 fprintf(stderr
, "\n");
291 fprintf(stderr
, " Compatible cipher suites:\n");
292 for (u
= 0; u
< st_num
; u
++) {
295 get_suite_name_ext(st
[u
][0], csn
, sizeof csn
);
296 fprintf(stderr
, " %s\n", csn
);
298 fprintf(stderr
, " Common hash functions:");
299 for (u
= 2; u
<= 6; u
++) {
300 if ((chashes
>> u
) & 1) {
304 case 3: z
= 224; break;
305 case 4: z
= 256; break;
306 case 5: z
= 384; break;
307 case 6: z
= 512; break;
312 fprintf(stderr
, " sha%d", z
);
315 fprintf(stderr
, "\n");
317 for (u
= 0; u
< st_num
; u
++) {
323 if (pc
->sk
->key_type
== BR_KEYTYPE_RSA
) {
324 choices
->cipher_suite
= st
[u
][0];
328 case BR_SSLKEYX_ECDHE_RSA
:
329 if (pc
->sk
->key_type
== BR_KEYTYPE_RSA
) {
330 choices
->cipher_suite
= st
[u
][0];
331 choices
->hash_id
= hash_id
;
335 case BR_SSLKEYX_ECDHE_ECDSA
:
336 if (pc
->sk
->key_type
== BR_KEYTYPE_EC
) {
337 choices
->cipher_suite
= st
[u
][0];
338 choices
->hash_id
= hash_id
;
342 case BR_SSLKEYX_ECDH_RSA
:
343 if (pc
->sk
->key_type
== BR_KEYTYPE_EC
344 && pc
->cert_signer_algo
== BR_KEYTYPE_RSA
)
346 choices
->cipher_suite
= st
[u
][0];
350 case BR_SSLKEYX_ECDH_ECDSA
:
351 if (pc
->sk
->key_type
== BR_KEYTYPE_EC
352 && pc
->cert_signer_algo
== BR_KEYTYPE_EC
)
354 choices
->cipher_suite
= st
[u
][0];
363 choices
->chain
= pc
->chain
;
364 choices
->chain_len
= pc
->chain_len
;
368 get_suite_name_ext(choices
->cipher_suite
, csn
, sizeof csn
);
369 fprintf(stderr
, "Using: %s\n", csn
);
375 sp_do_keyx(const br_ssl_server_policy_class
**pctx
,
376 unsigned char *data
, size_t len
)
380 pc
= (policy_context
*)pctx
;
381 switch (pc
->sk
->key_type
) {
383 return br_rsa_ssl_decrypt(
384 &br_rsa_i31_private
, &pc
->sk
->key
.rsa
,
387 return br_ec_prime_i31
.mul(data
, len
, pc
->sk
->key
.ec
.x
,
388 pc
->sk
->key
.ec
.xlen
, pc
->sk
->key
.ec
.curve
);
390 fprintf(stderr
, "ERROR: unknown private key type (%d)\n",
391 (int)pc
->sk
->key_type
);
397 * OID for hash functions in RSA signatures.
399 static const unsigned char HASH_OID_SHA1
[] = {
400 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A
403 static const unsigned char HASH_OID_SHA224
[] = {
404 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04
407 static const unsigned char HASH_OID_SHA256
[] = {
408 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01
411 static const unsigned char HASH_OID_SHA384
[] = {
412 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02
415 static const unsigned char HASH_OID_SHA512
[] = {
416 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03
419 static const unsigned char *HASH_OID
[] = {
427 static const br_hash_class
*
428 get_hash_impl(int hash_id
)
432 for (u
= 0; hash_functions
[u
].name
; u
++) {
433 const br_hash_class
*hc
;
436 hc
= hash_functions
[u
].hclass
;
437 id
= (hc
->desc
>> BR_HASHDESC_ID_OFF
) & BR_HASHDESC_ID_MASK
;
446 sp_do_sign(const br_ssl_server_policy_class
**pctx
,
447 int hash_id
, size_t hv_len
, unsigned char *data
, size_t len
)
450 unsigned char hv
[64];
452 pc
= (policy_context
*)pctx
;
453 memcpy(hv
, data
, hv_len
);
454 switch (pc
->sk
->key_type
) {
457 const unsigned char *hash_oid
;
458 const br_hash_class
*hc
;
463 } else if (hash_id
>= 2 && hash_id
<= 6) {
464 hash_oid
= HASH_OID
[hash_id
- 2];
467 fprintf(stderr
, "ERROR: cannot RSA-sign with"
468 " unknown hash function: %d\n",
473 sig_len
= (pc
->sk
->key
.rsa
.n_bitlen
+ 7) >> 3;
476 fprintf(stderr
, "ERROR: cannot RSA-sign,"
477 " buffer is too small"
478 " (sig=%lu, buf=%lu)\n",
479 (unsigned long)sig_len
,
484 x
= br_rsa_i31_pkcs1_sign(hash_oid
, hv
, hv_len
,
485 &pc
->sk
->key
.rsa
, data
);
488 fprintf(stderr
, "ERROR: RSA-sign failure\n");
495 hc
= get_hash_impl(hash_id
);
498 fprintf(stderr
, "ERROR: cannot RSA-sign with"
499 " unknown hash function: %d\n",
506 fprintf(stderr
, "ERROR: cannot ECDSA-sign"
507 " (output buffer = %lu)\n",
512 sig_len
= br_ecdsa_i31_sign_asn1(&br_ec_prime_i31
,
513 hc
, hv
, &pc
->sk
->key
.ec
, data
);
516 fprintf(stderr
, "ERROR: ECDSA-sign failure\n");
527 static const br_ssl_server_policy_class policy_vtable
= {
528 sizeof(policy_context
),
536 do_server(int argc
, char *argv
[])
542 const char *bind_name
;
545 cipher_suite
*suites
;
549 br_x509_certificate
*chain
;
551 int cert_signer_algo
;
554 br_ssl_server_context cc
;
556 br_ssl_session_cache_lru lru
;
557 unsigned char *iobuf
, *cache
;
558 size_t iobuf_len
, cache_len
;
580 cache_len
= (size_t)-1;
584 for (i
= 0; i
< argc
; i
++) {
590 goto server_exit_error
;
592 if (eqstr(arg
, "-v") || eqstr(arg
, "-verbose")) {
594 } else if (eqstr(arg
, "-q") || eqstr(arg
, "-quiet")) {
596 } else if (eqstr(arg
, "-trace")) {
598 } else if (eqstr(arg
, "-b")) {
601 "ERROR: no argument for '-b'\n");
603 goto server_exit_error
;
605 if (bind_name
!= NULL
) {
606 fprintf(stderr
, "ERROR: duplicate bind host\n");
608 goto server_exit_error
;
611 } else if (eqstr(arg
, "-p")) {
614 "ERROR: no argument for '-p'\n");
616 goto server_exit_error
;
619 fprintf(stderr
, "ERROR: duplicate bind port\n");
621 goto server_exit_error
;
624 } else if (eqstr(arg
, "-mono")) {
626 } else if (eqstr(arg
, "-buf")) {
629 "ERROR: no argument for '-buf'\n");
631 goto server_exit_error
;
634 if (iobuf_len
!= 0) {
636 "ERROR: duplicate I/O buffer length\n");
638 goto server_exit_error
;
640 iobuf_len
= parse_size(arg
);
641 if (iobuf_len
== (size_t)-1) {
643 goto server_exit_error
;
645 } else if (eqstr(arg
, "-cache")) {
648 "ERROR: no argument for '-cache'\n");
650 goto server_exit_error
;
653 if (cache_len
!= (size_t)-1) {
654 fprintf(stderr
, "ERROR: duplicate session"
657 goto server_exit_error
;
659 cache_len
= parse_size(arg
);
660 if (cache_len
== (size_t)-1) {
662 goto server_exit_error
;
664 } else if (eqstr(arg
, "-cert")) {
667 "ERROR: no argument for '-cert'\n");
669 goto server_exit_error
;
673 "ERROR: duplicate certificate chain\n");
675 goto server_exit_error
;
678 chain
= read_certificates(arg
, &chain_len
);
679 if (chain
== NULL
|| chain_len
== 0) {
680 goto server_exit_error
;
682 } else if (eqstr(arg
, "-key")) {
685 "ERROR: no argument for '-key'\n");
687 goto server_exit_error
;
691 "ERROR: duplicate private key\n");
693 goto server_exit_error
;
696 sk
= read_private_key(arg
);
698 goto server_exit_error
;
700 } else if (eqstr(arg
, "-list")) {
703 } else if (eqstr(arg
, "-vmin")) {
706 "ERROR: no argument for '-vmin'\n");
708 goto server_exit_error
;
713 "ERROR: duplicate minimum version\n");
715 goto server_exit_error
;
717 vmin
= parse_version(arg
, strlen(arg
));
720 "ERROR: unrecognised version '%s'\n",
723 goto server_exit_error
;
725 } else if (eqstr(arg
, "-vmax")) {
728 "ERROR: no argument for '-vmax'\n");
730 goto server_exit_error
;
735 "ERROR: duplicate maximum version\n");
737 goto server_exit_error
;
739 vmax
= parse_version(arg
, strlen(arg
));
742 "ERROR: unrecognised version '%s'\n",
745 goto server_exit_error
;
747 } else if (eqstr(arg
, "-cs")) {
750 "ERROR: no argument for '-cs'\n");
752 goto server_exit_error
;
755 if (suites
!= NULL
) {
756 fprintf(stderr
, "ERROR: duplicate list"
757 " of cipher suites\n");
759 goto server_exit_error
;
761 suites
= parse_suites(arg
, &num_suites
);
762 if (suites
== NULL
) {
764 goto server_exit_error
;
766 } else if (eqstr(arg
, "-hf")) {
771 "ERROR: no argument for '-hf'\n");
773 goto server_exit_error
;
776 x
= parse_hash_functions(arg
);
779 goto server_exit_error
;
782 } else if (eqstr(arg
, "-serverpref")) {
783 flags
|= BR_OPT_ENFORCE_SERVER_PREFERENCES
;
785 fprintf(stderr
, "ERROR: unknown option: '%s'\n", arg
);
787 goto server_exit_error
;
800 fprintf(stderr
, "ERROR: impossible minimum/maximum protocol"
801 " version combination\n");
803 goto server_exit_error
;
805 if (suites
== NULL
) {
808 for (u
= 0; cipher_suites
[u
].name
; u
++) {
809 if ((cipher_suites
[u
].req
& REQ_TLS12
) == 0
815 suites
= xmalloc(num_suites
* sizeof *suites
);
817 for (u
= 0; cipher_suites
[u
].name
; u
++) {
818 if ((cipher_suites
[u
].req
& REQ_TLS12
) == 0
821 suites
[num_suites
++] = cipher_suites
[u
];
826 hfuns
= (unsigned)-1;
828 if (chain
== NULL
|| chain_len
== 0) {
829 fprintf(stderr
, "ERROR: no certificate chain provided\n");
830 goto server_exit_error
;
833 fprintf(stderr
, "ERROR: no private key provided\n");
834 goto server_exit_error
;
836 switch (sk
->key_type
) {
843 curve
= sk
->key
.ec
.curve
;
844 supp
= br_ec_prime_i31
.supported_curves
;
845 if (curve
> 31 || !((supp
>> curve
) & 1)) {
846 fprintf(stderr
, "ERROR: private key curve (%d)"
847 " is not supported\n", curve
);
848 goto server_exit_error
;
852 fprintf(stderr
, "ERROR: unsupported private key type (%d)\n",
856 cert_signer_algo
= get_cert_signer_algo(chain
);
857 if (cert_signer_algo
< 0) {
858 fprintf(stderr
, "ERROR: server certificate cannot be"
859 " decoded (err=%d)\n", -cert_signer_algo
);
860 goto server_exit_error
;
861 } else if (verbose
) {
864 switch (cert_signer_algo
) {
865 case BR_KEYTYPE_RSA
: csas
= "RSA"; break;
866 case BR_KEYTYPE_EC
: csas
= "EC"; break;
871 fprintf(stderr
, "Issuing CA key type: %d (%s)\n",
872 cert_signer_algo
, csas
);
874 if (iobuf_len
== 0) {
876 iobuf_len
= BR_SSL_BUFSIZE_BIDI
;
878 iobuf_len
= BR_SSL_BUFSIZE_MONO
;
881 iobuf
= xmalloc(iobuf_len
);
882 if (cache_len
== (size_t)-1) {
885 cache
= xmalloc(cache_len
);
888 * Compute implementation requirements and inject implementations.
890 suite_ids
= xmalloc(num_suites
* sizeof *suite_ids
);
891 br_ssl_server_zero(&cc
);
892 br_ssl_engine_set_versions(&cc
.eng
, vmin
, vmax
);
893 br_ssl_server_set_all_flags(&cc
, flags
);
894 if (vmin
<= BR_TLS11
) {
895 if (!(hfuns
& (1 << br_md5_ID
))) {
896 fprintf(stderr
, "ERROR: TLS 1.0 and 1.1 need MD5\n");
897 goto server_exit_error
;
899 if (!(hfuns
& (1 << br_sha1_ID
))) {
900 fprintf(stderr
, "ERROR: TLS 1.0 and 1.1 need SHA-1\n");
901 goto server_exit_error
;
904 for (u
= 0; u
< num_suites
; u
++) {
908 suite_ids
[u
] = suites
[u
].suite
;
909 if ((req
& REQ_TLS12
) != 0 && vmax
< BR_TLS12
) {
911 "ERROR: cipher suite %s requires TLS 1.2\n",
913 goto server_exit_error
;
915 if ((req
& REQ_SHA1
) != 0 && !(hfuns
& (1 << br_sha1_ID
))) {
917 "ERROR: cipher suite %s requires SHA-1\n",
919 goto server_exit_error
;
921 if ((req
& REQ_SHA256
) != 0 && !(hfuns
& (1 << br_sha256_ID
))) {
923 "ERROR: cipher suite %s requires SHA-256\n",
925 goto server_exit_error
;
927 if ((req
& REQ_SHA384
) != 0 && !(hfuns
& (1 << br_sha384_ID
))) {
929 "ERROR: cipher suite %s requires SHA-384\n",
931 goto server_exit_error
;
933 /* TODO: algorithm implementation selection */
934 if ((req
& REQ_AESCBC
) != 0) {
935 br_ssl_engine_set_aes_cbc(&cc
.eng
,
936 &br_aes_ct_cbcenc_vtable
,
937 &br_aes_ct_cbcdec_vtable
);
938 br_ssl_engine_set_cbc(&cc
.eng
,
939 &br_sslrec_in_cbc_vtable
,
940 &br_sslrec_out_cbc_vtable
);
942 if ((req
& REQ_AESGCM
) != 0) {
943 br_ssl_engine_set_aes_ctr(&cc
.eng
,
944 &br_aes_ct_ctr_vtable
);
945 br_ssl_engine_set_ghash(&cc
.eng
,
947 br_ssl_engine_set_gcm(&cc
.eng
,
948 &br_sslrec_in_gcm_vtable
,
949 &br_sslrec_out_gcm_vtable
);
951 if ((req
& REQ_3DESCBC
) != 0) {
952 br_ssl_engine_set_des_cbc(&cc
.eng
,
953 &br_des_ct_cbcenc_vtable
,
954 &br_des_ct_cbcdec_vtable
);
955 br_ssl_engine_set_cbc(&cc
.eng
,
956 &br_sslrec_in_cbc_vtable
,
957 &br_sslrec_out_cbc_vtable
);
959 if ((req
& (REQ_ECDHE_RSA
| REQ_ECDHE_ECDSA
)) != 0) {
960 br_ssl_engine_set_ec(&cc
.eng
, &br_ec_prime_i31
);
963 br_ssl_engine_set_suites(&cc
.eng
, suite_ids
, num_suites
);
965 for (u
= 0; hash_functions
[u
].name
; u
++) {
966 const br_hash_class
*hc
;
969 hc
= hash_functions
[u
].hclass
;
970 id
= (hc
->desc
>> BR_HASHDESC_ID_OFF
) & BR_HASHDESC_ID_MASK
;
971 if ((hfuns
& ((unsigned)1 << id
)) != 0) {
972 br_ssl_engine_set_hash(&cc
.eng
, id
, hc
);
975 if (vmin
<= BR_TLS11
) {
976 br_ssl_engine_set_prf10(&cc
.eng
, &br_tls10_prf
);
978 if (vmax
>= BR_TLS12
) {
979 if ((hfuns
& ((unsigned)1 << br_sha256_ID
)) != 0) {
980 br_ssl_engine_set_prf_sha256(&cc
.eng
,
981 &br_tls12_sha256_prf
);
983 if ((hfuns
& ((unsigned)1 << br_sha384_ID
)) != 0) {
984 br_ssl_engine_set_prf_sha384(&cc
.eng
,
985 &br_tls12_sha384_prf
);
989 br_ssl_session_cache_lru_init(&lru
, cache
, cache_len
);
990 br_ssl_server_set_cache(&cc
, &lru
.vtable
);
992 pc
.vtable
= &policy_vtable
;
993 pc
.verbose
= verbose
;
995 pc
.chain_len
= chain_len
;
996 pc
.cert_signer_algo
= cert_signer_algo
;
998 br_ssl_server_set_policy(&cc
, &pc
.vtable
);
1000 br_ssl_engine_set_buffer(&cc
.eng
, iobuf
, iobuf_len
, bidi
);
1003 * Open the server socket.
1005 server_fd
= host_bind(bind_name
, port
, verbose
);
1006 if (server_fd
< 0) {
1007 goto server_exit_error
;
1011 * Process incoming clients, one at a time. Note that we do not
1012 * accept any client until the previous connection has finished:
1013 * this is voluntary, since the tool uses stdin/stdout for
1014 * application data, and thus cannot really run two connections
1020 fd
= accept_client(server_fd
, verbose
);
1022 goto server_exit_error
;
1024 br_ssl_server_reset(&cc
);
1025 x
= run_ssl_engine(&cc
.eng
, fd
,
1026 (verbose
? RUN_ENGINE_VERBOSE
: 0)
1027 | (trace
? RUN_ENGINE_TRACE
: 0));
1031 goto server_exit_error
;
1036 * Release allocated structures.
1041 if (chain
!= NULL
) {
1042 for (u
= 0; u
< chain_len
; u
++) {
1043 xfree(chain
[u
].data
);
1047 free_private_key(sk
);