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
32 #include <sys/types.h>
33 #include <sys/socket.h>
35 #include <netinet/in.h>
36 #include <arpa/inet.h>
44 host_connect(const char *host
, const char *port
, int verbose
)
46 struct addrinfo hints
, *si
, *p
;
50 memset(&hints
, 0, sizeof hints
);
51 hints
.ai_family
= PF_UNSPEC
;
52 hints
.ai_socktype
= SOCK_STREAM
;
53 err
= getaddrinfo(host
, port
, &hints
, &si
);
55 fprintf(stderr
, "ERROR: getaddrinfo(): %s\n",
60 for (p
= si
; p
!= NULL
; p
= p
->ai_next
) {
64 char tmp
[INET6_ADDRSTRLEN
+ 50];
66 sa
= (struct sockaddr
*)p
->ai_addr
;
67 if (sa
->sa_family
== AF_INET
) {
68 addr
= &((struct sockaddr_in
*)sa
)->sin_addr
;
69 } else if (sa
->sa_family
== AF_INET6
) {
70 addr
= &((struct sockaddr_in6
*)sa
)->sin6_addr
;
75 if (!inet_ntop(p
->ai_family
, addr
,
78 strcpy(tmp
, "<invalid>");
81 sprintf(tmp
, "<unknown family: %d>",
84 fprintf(stderr
, "connecting to: %s\n", tmp
);
86 fd
= socket(p
->ai_family
, p
->ai_socktype
, p
->ai_protocol
);
93 if (connect(fd
, p
->ai_addr
, p
->ai_addrlen
) < 0) {
104 fprintf(stderr
, "ERROR: failed to connect\n");
109 fprintf(stderr
, "connected.\n");
113 * We make the socket non-blocking, since we are going to use
114 * poll() to organise I/O.
116 fcntl(fd
, F_SETFL
, O_NONBLOCK
);
121 const br_ssl_client_certificate_class
*vtable
;
123 br_x509_certificate
*chain
;
130 cc_start_name_list(const br_ssl_client_certificate_class
**pctx
)
134 zc
= (ccert_context
*)pctx
;
136 fprintf(stderr
, "Server requests a client certificate.\n");
137 fprintf(stderr
, "--- anchor DN list start ---\n");
142 cc_start_name(const br_ssl_client_certificate_class
**pctx
, size_t len
)
146 zc
= (ccert_context
*)pctx
;
148 fprintf(stderr
, "new anchor name, length = %u\n",
154 cc_append_name(const br_ssl_client_certificate_class
**pctx
,
155 const unsigned char *data
, size_t len
)
159 zc
= (ccert_context
*)pctx
;
163 for (u
= 0; u
< len
; u
++) {
165 fprintf(stderr
, " ");
166 } else if (u
> 0 && u
% 16 == 0) {
167 fprintf(stderr
, "\n ");
169 fprintf(stderr
, " %02x", data
[u
]);
172 fprintf(stderr
, "\n");
178 cc_end_name(const br_ssl_client_certificate_class
**pctx
)
184 cc_end_name_list(const br_ssl_client_certificate_class
**pctx
)
188 zc
= (ccert_context
*)pctx
;
190 fprintf(stderr
, "--- anchor DN list end ---\n");
195 print_hashes(unsigned hh
, unsigned hh2
)
199 for (i
= 0; i
< 8; i
++) {
202 name
= hash_function_name(i
);
203 if (((hh
>> i
) & 1) != 0) {
204 fprintf(stderr
, " %s", name
);
205 } else if (((hh2
>> i
) & 1) != 0) {
206 fprintf(stderr
, " (%s)", name
);
212 choose_hash(unsigned hh
)
214 static const int f
[] = {
215 br_sha256_ID
, br_sha224_ID
, br_sha384_ID
, br_sha512_ID
,
216 br_sha1_ID
, br_md5sha1_ID
, -1
221 for (u
= 0; f
[u
] >= 0; u
++) {
222 if (((hh
>> f
[u
]) & 1) != 0) {
230 cc_choose(const br_ssl_client_certificate_class
**pctx
,
231 const br_ssl_client_context
*cc
, uint32_t auth_types
,
232 br_ssl_client_certificate
*choices
)
237 zc
= (ccert_context
*)pctx
;
238 scurve
= br_ssl_client_get_server_curve(cc
);
242 hashes
= br_ssl_client_get_server_hashes(cc
);
243 if ((auth_types
& 0x00FF) != 0) {
244 fprintf(stderr
, "supported: RSA signatures:");
245 print_hashes(auth_types
, hashes
);
246 fprintf(stderr
, "\n");
248 if ((auth_types
& 0xFF00) != 0) {
249 fprintf(stderr
, "supported: ECDSA signatures:");
250 print_hashes(auth_types
>> 8, hashes
>> 8);
251 fprintf(stderr
, "\n");
253 if ((auth_types
& 0x010000) != 0) {
254 fprintf(stderr
, "supported:"
255 " fixed ECDH (cert signed with RSA)\n");
257 if ((auth_types
& 0x020000) != 0) {
258 fprintf(stderr
, "supported:"
259 " fixed ECDH (cert signed with ECDSA)\n");
262 fprintf(stderr
, "server key curve: %s (%d)\n",
263 ec_curve_name(scurve
), scurve
);
265 fprintf(stderr
, "server key is not EC\n");
268 switch (zc
->sk
->key_type
) {
270 if ((choices
->hash_id
= choose_hash(auth_types
)) >= 0) {
272 fprintf(stderr
, "using RSA, hash = %d (%s)\n",
274 hash_function_name(choices
->hash_id
));
276 choices
->auth_type
= BR_AUTH_RSA
;
277 choices
->chain
= zc
->chain
;
278 choices
->chain_len
= zc
->chain_len
;
283 if (zc
->issuer_key_type
!= 0
284 && scurve
== zc
->sk
->key
.ec
.curve
)
288 x
= (zc
->issuer_key_type
== BR_KEYTYPE_RSA
) ? 16 : 17;
289 if (((auth_types
>> x
) & 1) != 0) {
291 fprintf(stderr
, "using static ECDH\n");
293 choices
->auth_type
= BR_AUTH_ECDH
;
294 choices
->hash_id
= -1;
295 choices
->chain
= zc
->chain
;
296 choices
->chain_len
= zc
->chain_len
;
300 if ((choices
->hash_id
= choose_hash(auth_types
>> 8)) >= 0) {
302 fprintf(stderr
, "using ECDSA, hash = %d (%s)\n",
304 hash_function_name(choices
->hash_id
));
306 choices
->auth_type
= BR_AUTH_ECDSA
;
307 choices
->chain
= zc
->chain
;
308 choices
->chain_len
= zc
->chain_len
;
314 fprintf(stderr
, "no matching client certificate\n");
316 choices
->chain
= NULL
;
317 choices
->chain_len
= 0;
321 cc_do_keyx(const br_ssl_client_certificate_class
**pctx
,
322 unsigned char *data
, size_t len
)
326 zc
= (ccert_context
*)pctx
;
327 return br_ec_prime_i31
.mul(data
, len
, zc
->sk
->key
.ec
.x
,
328 zc
->sk
->key
.ec
.xlen
, zc
->sk
->key
.ec
.curve
);
332 cc_do_sign(const br_ssl_client_certificate_class
**pctx
,
333 int hash_id
, size_t hv_len
, unsigned char *data
, size_t len
)
336 unsigned char hv
[64];
338 zc
= (ccert_context
*)pctx
;
339 memcpy(hv
, data
, hv_len
);
340 switch (zc
->sk
->key_type
) {
341 const br_hash_class
*hc
;
342 const unsigned char *hash_oid
;
347 hash_oid
= get_hash_oid(hash_id
);
348 if (hash_oid
== NULL
&& hash_id
!= 0) {
350 fprintf(stderr
, "ERROR: cannot RSA-sign with"
351 " unknown hash function: %d\n",
356 sig_len
= (zc
->sk
->key
.rsa
.n_bitlen
+ 7) >> 3;
359 fprintf(stderr
, "ERROR: cannot RSA-sign,"
360 " buffer is too small"
361 " (sig=%lu, buf=%lu)\n",
362 (unsigned long)sig_len
,
367 x
= br_rsa_i31_pkcs1_sign(hash_oid
, hv
, hv_len
,
368 &zc
->sk
->key
.rsa
, data
);
371 fprintf(stderr
, "ERROR: RSA-sign failure\n");
378 hc
= get_hash_impl(hash_id
);
381 fprintf(stderr
, "ERROR: cannot ECDSA-sign with"
382 " unknown hash function: %d\n",
389 fprintf(stderr
, "ERROR: cannot ECDSA-sign"
390 " (output buffer = %lu)\n",
395 sig_len
= br_ecdsa_i31_sign_asn1(&br_ec_prime_i31
,
396 hc
, hv
, &zc
->sk
->key
.ec
, data
);
399 fprintf(stderr
, "ERROR: ECDSA-sign failure\n");
410 static const br_ssl_client_certificate_class ccert_vtable
= {
411 sizeof(ccert_context
),
426 "usage: brssl client server[:port] [ options ]\n");
430 " -q suppress verbose messages\n");
432 " -trace activate extra debug messages (dump of all packets)\n");
434 " -sni name use this specific name for SNI\n");
436 " -nosni do not send any SNI\n");
438 " -mono use monodirectional buffering\n");
440 " -buf length set the I/O buffer length (in bytes)\n");
442 " -CA file add certificates in 'file' to trust anchors\n");
444 " -cert file set client certificate chain\n");
446 " -key file set client private key (for certificate authentication)\n");
448 " -nostaticecdh prohibit full-static ECDH (client certificate)\n");
450 " -list list supported names (protocols, algorithms...)\n");
452 " -vmin name set minimum supported version (default: TLS-1.0)\n");
454 " -vmax name set maximum supported version (default: TLS-1.2)\n");
456 " -cs names set list of supported cipher suites (comma-separated)\n");
458 " -hf names add support for some hash functions (comma-separated)\n");
460 " -minhello len set minimum ClientHello length (in bytes)\n");
462 " -fallback send the TLS_FALLBACK_SCSV (i.e. claim a downgrade)\n");
464 " -noreneg prohibit renegotiations\n");
469 do_client(int argc
, char *argv
[])
475 const char *server_name
;
479 anchor_list anchors
= VEC_INIT
;
481 cipher_suite
*suites
;
486 br_ssl_client_context cc
;
487 br_x509_minimal_context xc
;
488 x509_noanchor_context xwc
;
489 const br_hash_class
*dnhash
;
491 br_x509_certificate
*chain
;
495 unsigned char *iobuf
;
522 minhello_len
= (size_t)-1;
526 for (i
= 0; i
< argc
; i
++) {
531 if (server_name
!= NULL
) {
533 "ERROR: duplicate server name\n");
535 goto client_exit_error
;
540 if (eqstr(arg
, "-v") || eqstr(arg
, "-verbose")) {
542 } else if (eqstr(arg
, "-q") || eqstr(arg
, "-quiet")) {
544 } else if (eqstr(arg
, "-trace")) {
546 } else if (eqstr(arg
, "-sni")) {
549 "ERROR: no argument for '-sni'\n");
551 goto client_exit_error
;
554 fprintf(stderr
, "ERROR: duplicate SNI\n");
556 goto client_exit_error
;
559 } else if (eqstr(arg
, "-nosni")) {
561 fprintf(stderr
, "ERROR: duplicate SNI\n");
563 goto client_exit_error
;
566 } else if (eqstr(arg
, "-mono")) {
568 } else if (eqstr(arg
, "-buf")) {
571 "ERROR: no argument for '-buf'\n");
573 goto client_exit_error
;
576 if (iobuf_len
!= 0) {
578 "ERROR: duplicate I/O buffer length\n");
580 goto client_exit_error
;
582 iobuf_len
= parse_size(arg
);
583 if (iobuf_len
== (size_t)-1) {
585 goto client_exit_error
;
587 } else if (eqstr(arg
, "-CA")) {
590 "ERROR: no argument for '-CA'\n");
592 goto client_exit_error
;
595 if (read_trust_anchors(&anchors
, arg
) == 0) {
597 goto client_exit_error
;
599 } else if (eqstr(arg
, "-cert")) {
602 "ERROR: no argument for '-cert'\n");
604 goto client_exit_error
;
608 "ERROR: duplicate certificate chain\n");
610 goto client_exit_error
;
613 chain
= read_certificates(arg
, &chain_len
);
614 if (chain
== NULL
|| chain_len
== 0) {
615 goto client_exit_error
;
617 } else if (eqstr(arg
, "-key")) {
620 "ERROR: no argument for '-key'\n");
622 goto client_exit_error
;
626 "ERROR: duplicate private key\n");
628 goto client_exit_error
;
631 sk
= read_private_key(arg
);
633 goto client_exit_error
;
635 } else if (eqstr(arg
, "-nostaticecdh")) {
637 } else if (eqstr(arg
, "-list")) {
640 } else if (eqstr(arg
, "-vmin")) {
643 "ERROR: no argument for '-vmin'\n");
645 goto client_exit_error
;
650 "ERROR: duplicate minimum version\n");
652 goto client_exit_error
;
654 vmin
= parse_version(arg
, strlen(arg
));
657 "ERROR: unrecognised version '%s'\n",
660 goto client_exit_error
;
662 } else if (eqstr(arg
, "-vmax")) {
665 "ERROR: no argument for '-vmax'\n");
667 goto client_exit_error
;
672 "ERROR: duplicate maximum version\n");
674 goto client_exit_error
;
676 vmax
= parse_version(arg
, strlen(arg
));
679 "ERROR: unrecognised version '%s'\n",
682 goto client_exit_error
;
684 } else if (eqstr(arg
, "-cs")) {
687 "ERROR: no argument for '-cs'\n");
689 goto client_exit_error
;
692 if (suites
!= NULL
) {
693 fprintf(stderr
, "ERROR: duplicate list"
694 " of cipher suites\n");
696 goto client_exit_error
;
698 suites
= parse_suites(arg
, &num_suites
);
699 if (suites
== NULL
) {
701 goto client_exit_error
;
703 } else if (eqstr(arg
, "-hf")) {
708 "ERROR: no argument for '-hf'\n");
710 goto client_exit_error
;
713 x
= parse_hash_functions(arg
);
716 goto client_exit_error
;
719 } else if (eqstr(arg
, "-minhello")) {
722 "ERROR: no argument for '-minhello'\n");
724 goto client_exit_error
;
727 if (minhello_len
!= (size_t)-1) {
728 fprintf(stderr
, "ERROR: duplicate minium"
729 " ClientHello length\n");
731 goto client_exit_error
;
733 minhello_len
= parse_size(arg
);
735 * Minimum ClientHello length must fit on 16 bits.
737 if (minhello_len
== (size_t)-1
738 || (((minhello_len
>> 12) >> 4) != 0))
741 goto client_exit_error
;
743 } else if (eqstr(arg
, "-fallback")) {
745 } else if (eqstr(arg
, "-noreneg")) {
746 flags
|= BR_OPT_NO_RENEGOTIATION
;
748 fprintf(stderr
, "ERROR: unknown option: '%s'\n", arg
);
750 goto client_exit_error
;
753 if (server_name
== NULL
) {
754 fprintf(stderr
, "ERROR: no server name/address provided\n");
756 goto client_exit_error
;
758 for (u
= strlen(server_name
); u
> 0; u
--) {
759 int c
= server_name
[u
- 1];
763 if (c
< '0' || c
> '9') {
769 host
= xstrdup(server_name
);
770 port
= xstrdup("443");
772 port
= xstrdup(server_name
+ u
);
774 memcpy(host
, server_name
, u
- 1);
781 if (chain
== NULL
&& sk
!= NULL
) {
782 fprintf(stderr
, "ERROR: private key specified, but"
783 " no certificate chain\n");
785 goto client_exit_error
;
787 if (chain
!= NULL
&& sk
== NULL
) {
788 fprintf(stderr
, "ERROR: certificate chain specified, but"
789 " no private key\n");
791 goto client_exit_error
;
801 fprintf(stderr
, "ERROR: impossible minimum/maximum protocol"
802 " version combination\n");
804 goto client_exit_error
;
806 if (suites
== NULL
) {
809 for (u
= 0; cipher_suites
[u
].name
; u
++) {
810 if ((cipher_suites
[u
].req
& REQ_TLS12
) == 0
816 suites
= xmalloc(num_suites
* sizeof *suites
);
818 for (u
= 0; cipher_suites
[u
].name
; u
++) {
819 if ((cipher_suites
[u
].req
& REQ_TLS12
) == 0
822 suites
[num_suites
++] = cipher_suites
[u
];
827 hfuns
= (unsigned)-1;
829 if (iobuf_len
== 0) {
831 iobuf_len
= BR_SSL_BUFSIZE_BIDI
;
833 iobuf_len
= BR_SSL_BUFSIZE_MONO
;
836 iobuf
= xmalloc(iobuf_len
);
839 * Compute implementation requirements and inject implementations.
841 suite_ids
= xmalloc((num_suites
+ 1) * sizeof *suite_ids
);
842 br_ssl_client_zero(&cc
);
843 br_ssl_engine_set_versions(&cc
.eng
, vmin
, vmax
);
845 for (u
= 0; hash_functions
[u
].name
; u
++) {
846 const br_hash_class
*hc
;
849 hc
= hash_functions
[u
].hclass
;
850 id
= (hc
->desc
>> BR_HASHDESC_ID_OFF
) & BR_HASHDESC_ID_MASK
;
851 if ((hfuns
& ((unsigned)1 << id
)) != 0) {
855 if (dnhash
== NULL
) {
856 fprintf(stderr
, "ERROR: no supported hash function\n");
857 goto client_exit_error
;
859 br_x509_minimal_init(&xc
, dnhash
,
860 &VEC_ELT(anchors
, 0), VEC_LEN(anchors
));
861 if (vmin
<= BR_TLS11
) {
862 if (!(hfuns
& (1 << br_md5_ID
))) {
863 fprintf(stderr
, "ERROR: TLS 1.0 and 1.1 need MD5\n");
864 goto client_exit_error
;
866 if (!(hfuns
& (1 << br_sha1_ID
))) {
867 fprintf(stderr
, "ERROR: TLS 1.0 and 1.1 need SHA-1\n");
868 goto client_exit_error
;
871 for (u
= 0; u
< num_suites
; u
++) {
875 suite_ids
[u
] = suites
[u
].suite
;
876 if ((req
& REQ_TLS12
) != 0 && vmax
< BR_TLS12
) {
878 "ERROR: cipher suite %s requires TLS 1.2\n",
880 goto client_exit_error
;
882 if ((req
& REQ_SHA1
) != 0 && !(hfuns
& (1 << br_sha1_ID
))) {
884 "ERROR: cipher suite %s requires SHA-1\n",
886 goto client_exit_error
;
888 if ((req
& REQ_SHA256
) != 0 && !(hfuns
& (1 << br_sha256_ID
))) {
890 "ERROR: cipher suite %s requires SHA-256\n",
892 goto client_exit_error
;
894 if ((req
& REQ_SHA384
) != 0 && !(hfuns
& (1 << br_sha384_ID
))) {
896 "ERROR: cipher suite %s requires SHA-384\n",
898 goto client_exit_error
;
900 /* TODO: algorithm implementation selection */
901 if ((req
& REQ_AESCBC
) != 0) {
902 br_ssl_engine_set_aes_cbc(&cc
.eng
,
903 &br_aes_ct_cbcenc_vtable
,
904 &br_aes_ct_cbcdec_vtable
);
905 br_ssl_engine_set_cbc(&cc
.eng
,
906 &br_sslrec_in_cbc_vtable
,
907 &br_sslrec_out_cbc_vtable
);
909 if ((req
& REQ_AESGCM
) != 0) {
910 br_ssl_engine_set_aes_ctr(&cc
.eng
,
911 &br_aes_ct_ctr_vtable
);
912 br_ssl_engine_set_ghash(&cc
.eng
,
914 br_ssl_engine_set_gcm(&cc
.eng
,
915 &br_sslrec_in_gcm_vtable
,
916 &br_sslrec_out_gcm_vtable
);
918 if ((req
& REQ_CHAPOL
) != 0) {
919 br_ssl_engine_set_chacha20(&cc
.eng
,
920 &br_chacha20_ct_run
);
921 br_ssl_engine_set_poly1305(&cc
.eng
,
922 &br_poly1305_ctmul_run
);
923 br_ssl_engine_set_chapol(&cc
.eng
,
924 &br_sslrec_in_chapol_vtable
,
925 &br_sslrec_out_chapol_vtable
);
927 if ((req
& REQ_3DESCBC
) != 0) {
928 br_ssl_engine_set_des_cbc(&cc
.eng
,
929 &br_des_ct_cbcenc_vtable
,
930 &br_des_ct_cbcdec_vtable
);
931 br_ssl_engine_set_cbc(&cc
.eng
,
932 &br_sslrec_in_cbc_vtable
,
933 &br_sslrec_out_cbc_vtable
);
935 if ((req
& REQ_RSAKEYX
) != 0) {
936 br_ssl_client_set_rsapub(&cc
, &br_rsa_i31_public
);
938 if ((req
& REQ_ECDHE_RSA
) != 0) {
939 br_ssl_engine_set_ec(&cc
.eng
, &br_ec_prime_i31
);
940 br_ssl_engine_set_rsavrfy(&cc
.eng
,
941 &br_rsa_i31_pkcs1_vrfy
);
943 if ((req
& REQ_ECDHE_ECDSA
) != 0) {
944 br_ssl_engine_set_ec(&cc
.eng
, &br_ec_prime_i31
);
945 br_ssl_engine_set_ecdsa(&cc
.eng
,
946 &br_ecdsa_i31_vrfy_asn1
);
948 if ((req
& REQ_ECDH
) != 0) {
949 br_ssl_engine_set_ec(&cc
.eng
, &br_ec_prime_i31
);
953 suite_ids
[num_suites
++] = 0x5600;
955 br_ssl_engine_set_suites(&cc
.eng
, suite_ids
, num_suites
);
957 for (u
= 0; hash_functions
[u
].name
; u
++) {
958 const br_hash_class
*hc
;
961 hc
= hash_functions
[u
].hclass
;
962 id
= (hc
->desc
>> BR_HASHDESC_ID_OFF
) & BR_HASHDESC_ID_MASK
;
963 if ((hfuns
& ((unsigned)1 << id
)) != 0) {
964 br_ssl_engine_set_hash(&cc
.eng
, id
, hc
);
965 br_x509_minimal_set_hash(&xc
, id
, hc
);
968 if (vmin
<= BR_TLS11
) {
969 br_ssl_engine_set_prf10(&cc
.eng
, &br_tls10_prf
);
971 if (vmax
>= BR_TLS12
) {
972 if ((hfuns
& ((unsigned)1 << br_sha256_ID
)) != 0) {
973 br_ssl_engine_set_prf_sha256(&cc
.eng
,
974 &br_tls12_sha256_prf
);
976 if ((hfuns
& ((unsigned)1 << br_sha384_ID
)) != 0) {
977 br_ssl_engine_set_prf_sha384(&cc
.eng
,
978 &br_tls12_sha384_prf
);
981 br_x509_minimal_set_rsa(&xc
, &br_rsa_i31_pkcs1_vrfy
);
982 br_x509_minimal_set_ecdsa(&xc
,
983 &br_ec_prime_i31
, &br_ecdsa_i31_vrfy_asn1
);
986 * If there is no provided trust anchor, then certificate validation
987 * will always fail. In that situation, we use our custom wrapper
988 * that tolerates unknown anchors.
990 if (VEC_LEN(anchors
) == 0) {
993 "WARNING: no configured trust anchor\n");
995 x509_noanchor_init(&xwc
, &xc
.vtable
);
996 br_ssl_engine_set_x509(&cc
.eng
, &xwc
.vtable
);
998 br_ssl_engine_set_x509(&cc
.eng
, &xc
.vtable
);
1001 if (minhello_len
!= (size_t)-1) {
1002 br_ssl_client_set_min_clienthello_len(&cc
, minhello_len
);
1004 br_ssl_engine_set_all_flags(&cc
.eng
, flags
);
1006 if (chain
!= NULL
) {
1007 zc
.vtable
= &ccert_vtable
;
1008 zc
.verbose
= verbose
;
1010 zc
.chain_len
= chain_len
;
1012 if (nostaticecdh
|| sk
->key_type
!= BR_KEYTYPE_EC
) {
1013 zc
.issuer_key_type
= 0;
1015 zc
.issuer_key_type
= get_cert_signer_algo(&chain
[0]);
1016 if (zc
.issuer_key_type
== 0) {
1017 goto client_exit_error
;
1020 br_ssl_client_set_client_certificate(&cc
, &zc
.vtable
);
1023 br_ssl_engine_set_buffer(&cc
.eng
, iobuf
, iobuf_len
, bidi
);
1024 br_ssl_client_reset(&cc
, sni
, 0);
1027 * We need to avoid SIGPIPE.
1029 signal(SIGPIPE
, SIG_IGN
);
1032 * Connect to the peer.
1034 fd
= host_connect(host
, port
, verbose
);
1036 goto client_exit_error
;
1040 * Run the engine until completion.
1042 if (run_ssl_engine(&cc
.eng
, fd
,
1043 (verbose
? RUN_ENGINE_VERBOSE
: 0)
1044 | (trace
? RUN_ENGINE_TRACE
: 0)) != 0)
1046 goto client_exit_error
;
1052 * Release allocated structures.
1059 VEC_CLEAREXT(anchors
, &free_ta_contents
);
1060 free_certificates(chain
, chain_len
);
1061 free_private_key(sk
);