summaryrefslogtreecommitdiff
path: root/src/regress/lib/libssl/interop/util.c
diff options
context:
space:
mode:
authorbluhm <>2018-11-07 01:08:49 +0000
committerbluhm <>2018-11-07 01:08:49 +0000
commitbe03b61c1b8f59ccdd34dbe5f6c6b30de697d28b (patch)
treea8266eebb496a361bb45e73920260a5f766bd201 /src/regress/lib/libssl/interop/util.c
parent29618fb6c2a365d42aec39a074aba2f6dc4934d9 (diff)
downloadopenbsd-be03b61c1b8f59ccdd34dbe5f6c6b30de697d28b.tar.gz
openbsd-be03b61c1b8f59ccdd34dbe5f6c6b30de697d28b.tar.bz2
openbsd-be03b61c1b8f59ccdd34dbe5f6c6b30de697d28b.zip
Test TLS interoperability between LibreSSL and OpenSSL.
Implement simple SSL client and server in C. Create four binaries by linking them with LibreSSL or OpenSSL. This way API compatibility is tested. Connect and accept with netcat to test protocol compatibility with libtls. Currently OpenSSL 1.0.2p from ports is used. Plan is to move to OpenSSL 1.1 and and test TLS 1.3. idea from beck@; help from jsing@
Diffstat (limited to 'src/regress/lib/libssl/interop/util.c')
-rw-r--r--src/regress/lib/libssl/interop/util.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/regress/lib/libssl/interop/util.c b/src/regress/lib/libssl/interop/util.c
new file mode 100644
index 0000000000..3f1c221d51
--- /dev/null
+++ b/src/regress/lib/libssl/interop/util.c
@@ -0,0 +1,93 @@
1/* $OpenBSD: util.c,v 1.1.1.1 2018/11/07 01:08:49 bluhm Exp $ */
2/*
3 * Copyright (c) 2018 Alexander Bluhm <bluhm@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <sys/types.h>
19#include <sys/socket.h>
20
21#include <err.h>
22#include <netdb.h>
23#include <stdio.h>
24
25#include <openssl/err.h>
26#include <openssl/ssl.h>
27
28#include "util.h"
29
30void
31print_ciphers(STACK_OF(SSL_CIPHER) *cstack)
32{
33 SSL_CIPHER *cipher;
34 int i;
35
36 for (i = 0; (cipher = sk_SSL_CIPHER_value(cstack, i)) != NULL; i++)
37 printf("cipher %s\n", SSL_CIPHER_get_name(cipher));
38 if (fflush(stdout) != 0)
39 err(1, "fflush stdout");
40}
41
42void
43print_sockname(BIO *bio)
44{
45 struct sockaddr_storage ss;
46 socklen_t slen;
47 char host[NI_MAXHOST], port[NI_MAXSERV];
48 int fd;
49
50 if (BIO_get_fd(bio, &fd) <= 0)
51 err_ssl(1, "BIO_get_fd");
52 slen = sizeof(ss);
53 if (getsockname(fd, (struct sockaddr *)&ss, &slen) == -1)
54 err(1, "getsockname");
55 if (getnameinfo((struct sockaddr *)&ss, ss.ss_len, host,
56 sizeof(host), port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV))
57 errx(1, "getnameinfo");
58 printf("sock: %s %s\n", host, port);
59 if (fflush(stdout) != 0)
60 err(1, "fflush stdout");
61}
62
63void
64print_peername(BIO *bio)
65{
66 struct sockaddr_storage ss;
67 socklen_t slen;
68 char host[NI_MAXHOST], port[NI_MAXSERV];
69 int fd;
70
71 if (BIO_get_fd(bio, &fd) <= 0)
72 err_ssl(1, "BIO_get_fd");
73 slen = sizeof(ss);
74 if (getpeername(fd, (struct sockaddr *)&ss, &slen) == -1)
75 err(1, "getpeername");
76 if (getnameinfo((struct sockaddr *)&ss, ss.ss_len, host,
77 sizeof(host), port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV))
78 errx(1, "getnameinfo");
79 printf("peer: %s %s\n", host, port);
80 if (fflush(stdout) != 0)
81 err(1, "fflush stdout");
82}
83
84void
85err_ssl(int eval, const char *fmt, ...)
86{
87 va_list ap;
88
89 ERR_print_errors_fp(stderr);
90 va_start(ap, fmt);
91 verrx(eval, fmt, ap);
92 va_end(ap);
93}