1 #include <openssl/err.h>
2 #include <openssl/ssl.h>
4 int main(int argc, char **argv)
6 BIO *sbio = NULL, *out = NULL;
12 char **args = argv + 1;
13 const char *connect_str = "localhost:4433";
16 ERR_load_crypto_strings();
17 ERR_load_SSL_strings();
20 ctx = SSL_CTX_new(SSLv23_client_method());
21 cctx = SSL_CONF_CTX_new();
22 SSL_CONF_CTX_set_flags(cctx, SSL_CONF_FLAG_CLIENT);
23 SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
24 while(*args && **args == '-')
27 /* Parse standard arguments */
28 rv = SSL_CONF_cmd_argv(cctx, &nargs, &args);
31 fprintf(stderr, "Missing argument for %s\n", *args);
36 fprintf(stderr, "Error in command %s\n", *args);
37 ERR_print_errors_fp(stderr);
40 /* If rv > 0 we processed something so proceed to next arg */
43 /* Otherwise application specific argument processing */
44 if (!strcmp(*args, "-connect"))
46 connect_str = args[1];
47 if (connect_str == NULL)
49 fprintf(stderr, "Missing -connect argument\n");
58 fprintf(stderr, "Unknown argument %s\n", *args);
63 if (!SSL_CONF_CTX_finish(cctx))
65 fprintf(stderr, "Finish error\n");
66 ERR_print_errors_fp(stderr);
70 /* We'd normally set some stuff like the verify paths and
71 * mode here because as things stand this will connect to
72 * any server whose certificate is signed by any CA.
75 sbio = BIO_new_ssl_connect(ctx);
77 BIO_get_ssl(sbio, &ssl);
81 fprintf(stderr, "Can't locate SSL pointer\n");
85 /* Don't want any retries */
86 SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);
88 /* We might want to do other things with ssl here */
90 BIO_set_conn_hostname(sbio, connect_str);
92 out = BIO_new_fp(stdout, BIO_NOCLOSE);
93 if(BIO_do_connect(sbio) <= 0)
95 fprintf(stderr, "Error connecting to server\n");
96 ERR_print_errors_fp(stderr);
100 if(BIO_do_handshake(sbio) <= 0)
102 fprintf(stderr, "Error establishing SSL connection\n");
103 ERR_print_errors_fp(stderr);
107 /* Could examine ssl here to get connection info */
109 BIO_puts(sbio, "GET / HTTP/1.0\n\n");
112 len = BIO_read(sbio, tmpbuf, 1024);
114 BIO_write(out, tmpbuf, len);
117 SSL_CONF_CTX_free(cctx);