Go to the documentation of this file.
19 #if !defined(OPENSSL_WINDOWS)
20 #include <sys/select.h>
31 #include "../crypto/internal.h"
39 "The hostname and port of the server to connect to, e.g. foo.com:443",
43 "An OpenSSL-style cipher suite string that configures the offered "
48 "An OpenSSL-style ECDH curves list that configures the offered curves",
52 "An OpenSSL-style signature algorithms list that configures the "
53 "signature algorithm preferences",
57 "The maximum acceptable protocol version",
61 "The minimum acceptable protocol version",
71 "Path to file containing serialized ECHConfigs",
75 "An NPN protocol to select if the server supports NPN",
79 "A comma-separated list of ALPN protocols to advertise",
86 "Advertise support for OCSP stabling",
90 "Advertise support for signed certificate timestamps",
94 "The key to use for signing a channel ID",
101 "A file containing a session to resume.",
105 "A file to write the negotiated session to.",
109 "PEM-encoded file containing the private key.",
113 "PEM-encoded file containing the leaf certificate and optional "
114 "certificate chain. This is taken from the -key argument if this "
115 "argument is not provided.",
119 "A STARTTLS mini-protocol to run before the TLS handshake. Supported"
126 "-permute-extensions",
128 "Permute extensions in handshake messages",
132 "Connect to the server twice. The first connection is closed once a "
133 "session is established. The second connection offers it.",
137 "A filename containing one or more PEM root certificates. Implies that "
138 "verification is required.",
142 "A directory containing one or more root certificate PEM files in "
143 "OpenSSL's hashed-directory format. Implies that verification is "
148 "this flag is the early data to send or if it starts with '@', the "
149 "file to read from for early data.",
153 "An HTTP proxy server to tunnel the TCP connection through",
157 "Allow renegotiations from the peer.",
161 "Print debug information about the handshake",
181 *outlen = strlen(
reinterpret_cast<const char *
>(
arg));
199 fprintf(
stderr,
"Error while saving session:\n");
217 #if defined(OPENSSL_WINDOWS)
222 FD_SET(
static_cast<SOCKET
>(sock), &read_fds);
224 FD_SET(sock, &read_fds);
226 int ret = select(sock + 1, &read_fds, NULL, NULL, NULL);
249 std::map<std::string, std::string> args_map,
250 bool (*
cb)(
SSL *ssl,
int sock)) {
252 if (args_map.count(
"-http-tunnel") != 0) {
253 if (!
Connect(&sock, args_map[
"-http-tunnel"]) ||
257 }
else if (!
Connect(&sock, args_map[
"-connect"])) {
261 if (args_map.count(
"-starttls") != 0) {
262 const std::string& starttls = args_map[
"-starttls"];
263 if (starttls ==
"smtp") {
268 fprintf(
stderr,
"Unknown value for -starttls: %s\n", starttls.c_str());
276 if (args_map.count(
"-server-name") != 0) {
280 if (args_map.count(
"-ech-grease") != 0) {
284 if (args_map.count(
"-ech-config-list") != 0) {
285 const char *
filename = args_map[
"-ech-config-list"].c_str();
287 std::vector<uint8_t>
data;
293 fprintf(
stderr,
"Error setting ECHConfigList\n");
298 if (args_map.count(
"-session-in") != 0) {
302 fprintf(
stderr,
"Error reading session\n");
307 nullptr,
nullptr,
nullptr));
309 fprintf(
stderr,
"Error reading session\n");
316 if (args_map.count(
"-renegotiate-freely") != 0) {
336 if (early_data.size() > 0 && early_data[0] ==
'@') {
337 const char *
filename = early_data.c_str() + 1;
338 std::vector<uint8_t>
data;
346 if (!early_data.empty()) {
347 int ed_size = early_data.size();
348 int ssl_ret =
SSL_write(ssl.get(), early_data.data(), ed_size);
353 }
else if (ssl_ret != ed_size) {
354 fprintf(
stderr,
"Short write from SSL_write.\n");
360 fprintf(
stderr,
"Connected.\n");
364 return cb(ssl.get(), sock);
370 fprintf(
stderr,
"Handshake started.\n");
373 fprintf(
stderr,
"Handshake done.\n");
386 std::map<std::string, std::string> args_map;
395 const char *keylog_file =
getenv(
"SSLKEYLOGFILE");
405 if (args_map.count(
"-cipher") != 0 &&
407 fprintf(
stderr,
"Failed setting cipher list\n");
411 if (args_map.count(
"-curves") != 0 &&
413 fprintf(
stderr,
"Failed setting curves list\n");
417 if (args_map.count(
"-sigalgs") != 0 &&
419 fprintf(
stderr,
"Failed setting signature algorithms list\n");
424 if (args_map.count(
"-max-version") != 0 &&
426 fprintf(
stderr,
"Unknown protocol version: '%s'\n",
427 args_map[
"-max-version"].
c_str());
435 if (args_map.count(
"-min-version") != 0) {
438 fprintf(
stderr,
"Unknown protocol version: '%s'\n",
439 args_map[
"-min-version"].
c_str());
447 if (args_map.count(
"-select-next-proto") != 0) {
448 const std::string &proto = args_map[
"-select-next-proto"];
449 if (proto.size() > 255) {
450 fprintf(
stderr,
"Bad NPN protocol: '%s'\n", proto.c_str());
455 const_cast<char *
>(proto.c_str()));
458 if (args_map.count(
"-alpn-protos") != 0) {
459 const std::string &alpn_protos = args_map[
"-alpn-protos"];
460 std::vector<uint8_t> wire;
462 while (
i <= alpn_protos.size()) {
463 size_t j = alpn_protos.find(
',',
i);
464 if (j == std::string::npos) {
465 j = alpn_protos.size();
469 fprintf(
stderr,
"Invalid ALPN protocols: '%s'\n", alpn_protos.c_str());
473 wire.resize(wire.size() +
len);
483 if (args_map.count(
"-fallback-scsv") != 0) {
487 if (args_map.count(
"-ocsp-stapling") != 0) {
491 if (args_map.count(
"-signed-certificate-timestamps") != 0) {
495 if (args_map.count(
"-channel-id-key") != 0) {
496 bssl::UniquePtr<EVP_PKEY> pkey =
503 if (args_map.count(
"-false-start") != 0) {
507 if (args_map.count(
"-key") != 0) {
511 fprintf(
stderr,
"Failed to load private key: %s\n",
key.c_str());
515 args_map.count(
"-cert") != 0 ? args_map[
"-cert"] :
key;
517 fprintf(
stderr,
"Failed to load cert chain: %s\n", cert.c_str());
525 if (args_map.count(
"-session-out") != 0) {
528 fprintf(
stderr,
"Error while opening %s:\n",
529 args_map[
"-session-out"].
c_str());
535 if (args_map.count(
"-grease") != 0) {
539 if (args_map.count(
"-permute-extensions") != 0) {
543 if (args_map.count(
"-root-certs") != 0) {
545 ctx.get(), args_map[
"-root-certs"].c_str(),
nullptr)) {
546 fprintf(
stderr,
"Failed to load root certificates.\n");
553 if (args_map.count(
"-root-cert-dir") != 0) {
555 ctx.get(),
nullptr, args_map[
"-root-cert-dir"].c_str())) {
556 fprintf(
stderr,
"Failed to load root certificates.\n");
563 if (args_map.count(
"-early-data") != 0) {
567 if (args_map.count(
"-debug") != 0) {
571 if (args_map.count(
"-test-resumption") != 0) {
572 if (args_map.count(
"-session-in") != 0) {
574 "Flags -session-in and -test-resumption are incompatible.\n");
#define SSL_CB_HANDSHAKE_START
bool ParseKeyValueArguments(std::map< std::string, std::string > *out_args, const std::vector< std::string > &args, const struct argument *templates)
#define SSL_CTX_set_verify
static int Connect(uint16_t port)
#define SSL_CTX_set_strict_cipher_list
#define SSL_CB_CONNECT_LOOP
#define SSL_CB_HANDSHAKE_DONE
#define SSL_ERROR_WANT_READ
#define SSL_TLSEXT_ERR_OK
bool VersionFromString(uint16_t *out_version, const std::string &version)
#define ERR_print_errors_fp
#define SSL_CTX_sess_set_new_cb
#define SSL_MODE_ENABLE_FALSE_START
#define SSL_CTX_set_session_cache_mode
static struct test_ctx ctx
#define SSL_CTX_load_verify_locations
EVP_PKEY * PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u)
#define SSL_CTX_set_max_proto_version
#define SSL_CTX_set_permute_extensions
#define SSL_CTX_set1_curves_list
void PrintSSLError(FILE *file, const char *msg, int ssl_err, int ret)
#define SSL_CTX_set1_sigalgs_list
#define SSL_set1_ech_config_list
bool DoHTTPTunnel(int sock, const std::string &hostname_and_port)
def c_str(s, encoding='ascii')
bool DoSMTPStartTLS(int sock)
static void * OPENSSL_memcpy(void *dst, const void *src, size_t n)
#define SSL_CTX_set1_tls_channel_id
#define SSL_CTX_enable_ocsp_stapling
#define SSL_CTX_enable_signed_cert_timestamps
#define SSL_CTX_set_keylog_callback
OPENSSL_MSVC_PRAGMA(warning(disable:4702))
#define SSL_set_tlsext_host_name
#define SSL_SESS_CACHE_CLIENT
#define PEM_read_bio_SSL_SESSION
#define SSL_CTX_set_info_callback
void PrintUsage(const struct argument *templates)
int push(void *desc, unsigned char *buf, unsigned len)
#define SSL_CTX_set_early_data_enabled
#define SSL_set_enable_ech_grease
#define SSL_CTX_use_certificate_chain_file
void PrintConnectionInfo(BIO *bio, const SSL *ssl)
#define BIO_read_filename
#define PEM_write_bio_SSL_SESSION
#define SSL_MODE_SEND_FALLBACK_SCSV
UniquePtr< SSL_SESSION > ret
#define SSL_CTX_use_PrivateKey_file
#define SSL_CTX_set_alpn_protos
#define SSL_set_renegotiate_mode
#define SSL_CTX_set_next_proto_select_cb
#define SSL_in_early_data
#define SSL_CTX_set_min_proto_version
bool SocketSetNonBlocking(int sock, bool is_non_blocking)
#define SSL_state_string_long
bool TransferData(SSL *ssl, int sock)
OPENSSL_EXPORT pem_password_cb * cb
#define SSL_CTX_set_grease_enabled
grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:54