-int MAIN(int argc, char **argv)
- {
- int build_chain = 0;
- SSL *con=NULL;
-#ifndef OPENSSL_NO_KRB5
- KSSL_CTX *kctx;
-#endif
- int s,k,width,state=0;
- char *cbuf=NULL,*sbuf=NULL,*mbuf=NULL;
- int cbuf_len,cbuf_off;
- int sbuf_len,sbuf_off;
- fd_set readfds,writefds;
- short port=PORT;
- int full_log=1;
- char *host=SSL_HOST_NAME;
- const char *unix_path = NULL;
- char *xmpphost = NULL;
- char *cert_file=NULL,*key_file=NULL,*chain_file=NULL;
- int cert_format = FORMAT_PEM, key_format = FORMAT_PEM;
- char *passarg = NULL, *pass = NULL;
- X509 *cert = NULL;
- EVP_PKEY *key = NULL;
- STACK_OF(X509) *chain = NULL;
- char *CApath=NULL,*CAfile=NULL;
- char *chCApath=NULL,*chCAfile=NULL;
- char *vfyCApath=NULL,*vfyCAfile=NULL;
- int reconnect=0,badop=0,verify=SSL_VERIFY_NONE;
- int crlf=0;
- int write_tty,read_tty,write_ssl,read_ssl,tty_on,ssl_pending;
- SSL_CTX *ctx=NULL;
- int ret=1,in_init=1,i,nbio_test=0;
- int starttls_proto = PROTO_OFF;
- int prexit = 0;
- X509_VERIFY_PARAM *vpm = NULL;
- int badarg = 0;
- const SSL_METHOD *meth=NULL;
- int socket_type=SOCK_STREAM;
- BIO *sbio;
- char *inrand=NULL;
- int mbuf_len=0;
- struct timeval timeout, *timeoutp;
-#ifndef OPENSSL_NO_ENGINE
- char *engine_id=NULL;
- char *ssl_client_engine_id=NULL;
- ENGINE *ssl_client_engine=NULL;
-#endif
- ENGINE *e=NULL;
-#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_NETWARE)
- struct timeval tv;
-#endif
-#ifndef OPENSSL_NO_TLSEXT
- char *servername = NULL;
- tlsextctx tlsextcbp =
- {NULL,0};
-# ifndef OPENSSL_NO_NEXTPROTONEG
- const char *next_proto_neg_in = NULL;
-# endif
- const char *alpn_in = NULL;
-# define MAX_SI_TYPES 100
- unsigned short serverinfo_types[MAX_SI_TYPES];
- int serverinfo_types_count = 0;
-#endif
- char *sess_in = NULL;
- char *sess_out = NULL;
- struct sockaddr peer;
- int peerlen = sizeof(peer);
- int fallback_scsv = 0;
- int enable_timeouts = 0 ;
- long socket_mtu = 0;
-#ifndef OPENSSL_NO_JPAKE
-static char *jpake_secret = NULL;
-#define no_jpake !jpake_secret
-#else
-#define no_jpake 1
-#endif
-#ifndef OPENSSL_NO_SRP
- char * srppass = NULL;
- int srp_lateuser = 0;
- SRP_ARG srp_arg = {NULL,NULL,0,0,0,1024};
+typedef enum OPTION_choice {
+ OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
+ OPT_HOST, OPT_PORT, OPT_CONNECT, OPT_UNIX, OPT_XMPPHOST, OPT_VERIFY,
+ OPT_CERT, OPT_CRL, OPT_CRL_DOWNLOAD, OPT_SESS_OUT, OPT_SESS_IN,
+ OPT_CERTFORM, OPT_CRLFORM, OPT_VERIFY_RET_ERROR, OPT_VERIFY_QUIET,
+ OPT_BRIEF, OPT_PREXIT, OPT_CRLF, OPT_QUIET, OPT_NBIO,
+ OPT_SSL_CLIENT_ENGINE, OPT_RAND, OPT_IGN_EOF, OPT_NO_IGN_EOF,
+ OPT_PAUSE, OPT_DEBUG, OPT_TLSEXTDEBUG, OPT_STATUS, OPT_WDEBUG,
+ OPT_MSG, OPT_MSGFILE, OPT_ENGINE, OPT_TRACE, OPT_SECURITY_DEBUG,
+ OPT_SECURITY_DEBUG_VERBOSE, OPT_SHOWCERTS, OPT_NBIO_TEST, OPT_STATE,
+ OPT_PSK_IDENTITY, OPT_PSK, OPT_SRPUSER, OPT_SRPPASS, OPT_SRP_STRENGTH,
+ OPT_SRP_LATEUSER, OPT_SRP_MOREGROUPS, OPT_SSL3,
+ OPT_TLS1_2, OPT_TLS1_1, OPT_TLS1, OPT_DTLS, OPT_DTLS1,
+ OPT_DTLS1_2, OPT_TIMEOUT, OPT_MTU, OPT_KEYFORM, OPT_PASS,
+ OPT_CERT_CHAIN, OPT_CAPATH, OPT_NOCAPATH, OPT_CHAINCAPATH, OPT_VERIFYCAPATH,
+ OPT_KEY, OPT_RECONNECT, OPT_BUILD_CHAIN, OPT_CAFILE, OPT_NOCAFILE,
+ OPT_CHAINCAFILE, OPT_VERIFYCAFILE, OPT_NEXTPROTONEG, OPT_ALPN,
+ OPT_SERVERINFO, OPT_STARTTLS, OPT_SERVERNAME, OPT_JPAKE,
+ OPT_USE_SRTP, OPT_KEYMATEXPORT, OPT_KEYMATEXPORTLEN, OPT_SMTPHOST,
+ OPT_V_ENUM,
+ OPT_X_ENUM,
+ OPT_S_ENUM,
+ OPT_FALLBACKSCSV, OPT_NOCMDS, OPT_PROXY
+} OPTION_CHOICE;
+
+OPTIONS s_client_options[] = {
+ {"help", OPT_HELP, '-', "Display this summary"},
+ {"host", OPT_HOST, 's', "Use -connect instead"},
+ {"port", OPT_PORT, 'p', "Use -connect instead"},
+ {"connect", OPT_CONNECT, 's',
+ "TCP/IP where to connect (default is " SSL_HOST_NAME ":" PORT_STR ")"},
+ {"proxy", OPT_PROXY, 's',
+ "Connect to via specified proxy to the real server"},
+ {"unix", OPT_UNIX, 's', "Connect over unix domain sockets"},
+ {"verify", OPT_VERIFY, 'p', "Turn on peer certificate verification"},
+ {"cert", OPT_CERT, '<', "Certificate file to use, PEM format assumed"},
+ {"certform", OPT_CERTFORM, 'F',
+ "Certificate format (PEM or DER) PEM default"},
+ {"key", OPT_KEY, '<', "Private key file to use, if not in -cert file"},
+ {"keyform", OPT_KEYFORM, 'F', "Key format (PEM or DER) PEM default"},
+ {"pass", OPT_PASS, 's', "Private key file pass phrase source"},
+ {"CApath", OPT_CAPATH, '/', "PEM format directory of CA's"},
+ {"CAfile", OPT_CAFILE, '<', "PEM format file of CA's"},
+ {"no-CAfile", OPT_NOCAFILE, '-',
+ "Do not load the default certificates file"},
+ {"no-CApath", OPT_NOCAPATH, '-',
+ "Do not load certificates from the default certificates directory"},
+ {"reconnect", OPT_RECONNECT, '-',
+ "Drop and re-make the connection with the same Session-ID"},
+ {"pause", OPT_PAUSE, '-', "Sleep after each read and write system call"},
+ {"showcerts", OPT_SHOWCERTS, '-', "Show all certificates in the chain"},
+ {"debug", OPT_DEBUG, '-', "Extra output"},
+ {"msg", OPT_MSG, '-', "Show protocol messages"},
+ {"msgfile", OPT_MSGFILE, '>'},
+ {"nbio_test", OPT_NBIO_TEST, '-', "More ssl protocol testing"},
+ {"state", OPT_STATE, '-', "Print the ssl states"},
+ {"crlf", OPT_CRLF, '-', "Convert LF from terminal into CRLF"},
+ {"quiet", OPT_QUIET, '-', "No s_client output"},
+ {"ign_eof", OPT_IGN_EOF, '-', "Ignore input eof (default when -quiet)"},
+ {"no_ign_eof", OPT_NO_IGN_EOF, '-', "Don't ignore input eof"},
+ {"tls1_2", OPT_TLS1_2, '-', "Just use TLSv1.2"},
+ {"tls1_1", OPT_TLS1_1, '-', "Just use TLSv1.1"},
+ {"tls1", OPT_TLS1, '-', "Just use TLSv1"},
+ {"starttls", OPT_STARTTLS, 's',
+ "Use the STARTTLS command before starting TLS"},
+ {"xmpphost", OPT_XMPPHOST, 's',
+ "Host to use with \"-starttls xmpp[-server]\""},
+ {"rand", OPT_RAND, 's',
+ "Load the file(s) into the random number generator"},
+ {"sess_out", OPT_SESS_OUT, '>', "File to write SSL session to"},
+ {"sess_in", OPT_SESS_IN, '<', "File to read SSL session from"},
+ {"use_srtp", OPT_USE_SRTP, 's',
+ "Offer SRTP key management with a colon-separated profile list"},
+ {"keymatexport", OPT_KEYMATEXPORT, 's',
+ "Export keying material using label"},
+ {"keymatexportlen", OPT_KEYMATEXPORTLEN, 'p',
+ "Export len bytes of keying material (default 20)"},
+ {"fallback_scsv", OPT_FALLBACKSCSV, '-', "Send the fallback SCSV"},
+ {"name", OPT_SMTPHOST, 's', "Hostname to use for \"-starttls smtp\""},
+ {"CRL", OPT_CRL, '<'},
+ {"crl_download", OPT_CRL_DOWNLOAD, '-'},
+ {"CRLform", OPT_CRLFORM, 'F'},
+ {"verify_return_error", OPT_VERIFY_RET_ERROR, '-'},
+ {"verify_quiet", OPT_VERIFY_QUIET, '-'},
+ {"brief", OPT_BRIEF, '-'},
+ {"prexit", OPT_PREXIT, '-'},
+ {"security_debug", OPT_SECURITY_DEBUG, '-'},
+ {"security_debug_verbose", OPT_SECURITY_DEBUG_VERBOSE, '-'},
+ {"cert_chain", OPT_CERT_CHAIN, '<'},
+ {"chainCApath", OPT_CHAINCAPATH, '/'},
+ {"verifyCApath", OPT_VERIFYCAPATH, '/'},
+ {"build_chain", OPT_BUILD_CHAIN, '-'},
+ {"chainCAfile", OPT_CHAINCAFILE, '<'},
+ {"verifyCAfile", OPT_VERIFYCAFILE, '<'},
+ {"nocommands", OPT_NOCMDS, '-', "Do not use interactive command letters"},
+ {"servername", OPT_SERVERNAME, 's',
+ "Set TLS extension servername in ClientHello"},
+ {"tlsextdebug", OPT_TLSEXTDEBUG, '-',
+ "Hex dump of all TLS extensions received"},
+ {"status", OPT_STATUS, '-', "Request certificate status from server"},
+ {"serverinfo", OPT_SERVERINFO, 's',
+ "types Send empty ClientHello extensions (comma-separated numbers)"},
+ {"alpn", OPT_ALPN, 's',
+ "Enable ALPN extension, considering named protocols supported (comma-separated list)"},
+ OPT_S_OPTIONS,
+ OPT_V_OPTIONS,
+ OPT_X_OPTIONS,
+#ifndef OPENSSL_NO_SSL3
+ {"ssl3", OPT_SSL3, '-', "Just use SSLv3"},