diff options
author | Viktor Dukhovni <openssl-users@dukhovni.org> | 2015-12-29 13:28:28 -0500 |
---|---|---|
committer | Viktor Dukhovni <openssl-users@dukhovni.org> | 2016-01-05 19:31:49 -0500 |
commit | 919ba009429b3617e975933f37a23be996a33b8d (patch) | |
tree | ffe91f4f27fd4d8b3d3401f1e860212f15c8b993 /demos/bio | |
parent | e29c73c93b88a4b7f492c7c8c7343223e7548612 (diff) | |
download | openssl-919ba009429b3617e975933f37a23be996a33b8d.tar.gz |
DANE support structures, constructructors and accessors
Also tweak some of the code in demos/bio, to enable interactive
testing of BIO_s_accept's use of SSL_dup. Changed the sconnect
client to authenticate the server, which now exercises the new
SSL_set1_host() function.
Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'demos/bio')
-rw-r--r-- | demos/bio/client-arg.c | 3 | ||||
-rw-r--r-- | demos/bio/client-conf.c | 3 | ||||
-rw-r--r-- | demos/bio/saccept.c | 29 | ||||
-rw-r--r-- | demos/bio/sconnect.c | 33 | ||||
-rw-r--r-- | demos/bio/server.pem | 64 |
5 files changed, 97 insertions, 35 deletions
diff --git a/demos/bio/client-arg.c b/demos/bio/client-arg.c index 99ebff1f2a..630b166779 100644 --- a/demos/bio/client-arg.c +++ b/demos/bio/client-arg.c @@ -1,3 +1,4 @@ +#include <string.h> #include <openssl/err.h> #include <openssl/ssl.h> @@ -56,7 +57,7 @@ int main(int argc, char **argv) if (!SSL_CONF_CTX_finish(cctx)) { fprintf(stderr, "Finish error\n"); ERR_print_errors_fp(stderr); - goto err; + goto end; } /* diff --git a/demos/bio/client-conf.c b/demos/bio/client-conf.c index 2a78315165..4e4d4bc8df 100644 --- a/demos/bio/client-conf.c +++ b/demos/bio/client-conf.c @@ -1,3 +1,4 @@ +#include <string.h> #include <openssl/err.h> #include <openssl/ssl.h> #include <openssl/conf.h> @@ -64,7 +65,7 @@ int main(int argc, char **argv) if (!SSL_CONF_CTX_finish(cctx)) { fprintf(stderr, "Finish error\n"); ERR_print_errors_fp(stderr); - goto err; + goto end; } /* diff --git a/demos/bio/saccept.c b/demos/bio/saccept.c index 0d173aa039..b6d0361a9c 100644 --- a/demos/bio/saccept.c +++ b/demos/bio/saccept.c @@ -18,16 +18,30 @@ #define CERT_FILE "server.pem" -BIO *in = NULL; +static int done = 0; -void close_up() +void interrupt() { - BIO_free(in); + done = 1; +} + +void sigsetup(void) +{ + struct sigaction sa; + + /* + * Catch at most once, and don't restart the accept system call. + */ + sa.sa_flags = SA_RESETHAND; + sa.sa_handler = interrupt; + sigemptyset(&sa.sa_mask); + sigaction(SIGINT, &sa, NULL); } int main(int argc, char *argv[]) { char *port = NULL; + BIO *in = NULL; BIO *ssl_bio, *tmp; SSL_CTX *ctx; char buf[512]; @@ -38,15 +52,13 @@ int main(int argc, char *argv[]) else port = argv[1]; - signal(SIGINT, close_up); - SSL_load_error_strings(); /* Add ciphers and message digests */ OpenSSL_add_ssl_algorithms(); ctx = SSL_CTX_new(TLS_server_method()); - if (!SSL_CTX_use_certificate_file(ctx, CERT_FILE, SSL_FILETYPE_PEM)) + if (!SSL_CTX_use_certificate_chain_file(ctx, CERT_FILE)) goto err; if (!SSL_CTX_use_PrivateKey_file(ctx, CERT_FILE, SSL_FILETYPE_PEM)) goto err; @@ -66,6 +78,9 @@ int main(int argc, char *argv[]) */ BIO_set_accept_bios(in, ssl_bio); + /* Arrange to leave server loop on interrupt */ + sigsetup(); + again: /* * The first call will setup the accept socket, and the second will get a @@ -76,7 +91,7 @@ int main(int argc, char *argv[]) if (BIO_do_accept(in) <= 0) goto err; - for (;;) { + while (!done) { i = BIO_read(in, buf, 512); if (i == 0) { /* diff --git a/demos/bio/sconnect.c b/demos/bio/sconnect.c index 865d503956..2b610cc8b5 100644 --- a/demos/bio/sconnect.c +++ b/demos/bio/sconnect.c @@ -11,27 +11,38 @@ #include <stdio.h> #include <stdlib.h> #include <unistd.h> +#include <string.h> #include <openssl/err.h> #include <openssl/ssl.h> +#define HOSTPORT "localhost:4433" +#define CAFILE "root.pem" + extern int errno; int main(argc, argv) int argc; char *argv[]; { - char *host; - BIO *out; + const char *hostport = HOSTPORT; + const char *CAfile = CAFILE; + char *hostname; + char *cp; + BIO *out = NULL; char buf[1024 * 10], *p; SSL_CTX *ssl_ctx = NULL; SSL *ssl; BIO *ssl_bio; int i, len, off, ret = 1; - if (argc <= 1) - host = "localhost:4433"; - else - host = argv[1]; + if (argc > 1) + hostport = argv[1]; + if (argc > 2) + CAfile = argv[2]; + + hostname = OPENSSL_strdup(hostport); + if ((cp = strchr(hostname, ':')) != NULL) + *cp = 0; #ifdef WATT32 dbug_init(); @@ -45,17 +56,25 @@ char *argv[]; OpenSSL_add_ssl_algorithms(); ssl_ctx = SSL_CTX_new(TLS_client_method()); + /* Enable trust chain verification */ + SSL_CTX_set_verify(ssl_ctx, SSL_VERIFY_PEER, NULL); + SSL_CTX_load_verify_locations(ssl_ctx, CAfile, NULL); + /* Lets make a SSL structure */ ssl = SSL_new(ssl_ctx); SSL_set_connect_state(ssl); + /* Enable peername verification */ + if (SSL_set1_host(ssl, hostname) <= 0) + goto err; + /* Use it inside an SSL BIO */ ssl_bio = BIO_new(BIO_f_ssl()); BIO_set_ssl(ssl_bio, ssl, BIO_CLOSE); /* Lets use a connect BIO under the SSL BIO */ out = BIO_new(BIO_s_connect()); - BIO_set_conn_hostname(out, host); + BIO_set_conn_hostname(out, hostport); BIO_set_nbio(out, 1); out = BIO_push(ssl_bio, out); diff --git a/demos/bio/server.pem b/demos/bio/server.pem index ef0d22a67b..8a4a51f9f0 100644 --- a/demos/bio/server.pem +++ b/demos/bio/server.pem @@ -1,26 +1,52 @@ subject= C = UK, O = OpenSSL Group, OU = FOR TESTING PURPOSES ONLY, CN = Test Server Cert issuer= C = UK, O = OpenSSL Group, OU = FOR TESTING PURPOSES ONLY, CN = OpenSSL Test Intermediate CA -----BEGIN CERTIFICATE----- -MIIDpTCCAo2gAwIBAgIJAK8ArbvjIOQlMA0GCSqGSIb3DQEBCwUAMHAxCzAJB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5Ipv923sSeCZcu0nuNex3v9/x72ldYikZNhQOsw+2kr +hx3OvE9R7xl9eyjz7BknsbY7PC3kiUY8SDdc5Fr/XMkHm3ge65oWYOHBjC5tAr5K +FGCEjM3syxS+Li5X6yfDGiVSjOU4gJuZDCYbl7cEQexU2deds8EmpJJrrI7s4JcQ +rraHI8+Hu8X9VLpZE1jl/fKJw3D0i53PoN2WhukIOg1Zv+ajMKQ4ubVfISH2ebox ++ybAZO8hxL6/I08/GQ== +-----END CERTIFICATE----- +subject= C = UK, O = OpenSSL Group, OU = FOR TESTING PURPOSES ONLY, CN = OpenSSL Test Intermediate CA +issuer= C = UK, O = OpenSSL Group, OU = FOR TESTING PURPOSES ONLY, CN = OpenSSL Test Root CA +-----BEGIN CERTIFICATE----- +MIIDvjCCAqagAwIBAgIJAPzCy4CUW9/qMA0GCSqGSIb3DQEBCwUAMGgxCzAJBgNV BAYTAlVLMRYwFAYDVQQKDA1PcGVuU1NMIEdyb3VwMSIwIAYDVQQLDBlGT1IgVEVT -VElORyBQVVJQT1NFUyBPTkxZMSUwIwYDVQQDDBxPcGVuU1NMIFRlc3QgSW50ZXJt -ZWRpYXRlIENBMB4XDTE1MDcxNDEzMjIwNVoXDTI1MDUyMjEzMjIwNVowZDELMAkG -A1UEBhMCVUsxFjAUBgNVBAoMDU9wZW5TU0wgR3JvdXAxIjAgBgNVBAsMGUZPUiBU -RVNUSU5HIFBVUlBPU0VTIE9OTFkxGTAXBgNVBAMMEFRlc3QgU2VydmVyIENlcnQw -ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDzhPOSNtyyRspmeuUpxfNJ -KCLTuf7g3uQ4zu4iHOmRO5TQci+HhVlLZrHF9XqFXcIP0y4pWDbMSGuiorUmzmfi -R7bfSdI/+qIQt8KXRH6HNG1t8ou0VSvWId5TS5Dq/er5ODUr9OaaDva7EquHIcMv -vPQGuI+OEAcnleVCy9HVEIySrO4P3CNIicnGkwwiAud05yUAq/gPXBC1hTtm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