diff options
Diffstat (limited to 'src/regress/lib/libssl/interop/util.c')
| -rw-r--r-- | src/regress/lib/libssl/interop/util.c | 93 |
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 | |||
| 30 | void | ||
| 31 | print_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 | |||
| 42 | void | ||
| 43 | print_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 | |||
| 63 | void | ||
| 64 | print_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 | |||
| 84 | void | ||
| 85 | err_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 | } | ||
