diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libcrypto/ocsp/Makefile | 3 | ||||
| -rw-r--r-- | src/regress/lib/libcrypto/ocsp/ocsp_test.c | 25 |
2 files changed, 19 insertions, 9 deletions
diff --git a/src/regress/lib/libcrypto/ocsp/Makefile b/src/regress/lib/libcrypto/ocsp/Makefile index 5748b48c77..4178f3199f 100644 --- a/src/regress/lib/libcrypto/ocsp/Makefile +++ b/src/regress/lib/libcrypto/ocsp/Makefile | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2016/07/04 23:43:30 beck Exp $ | 1 | # $OpenBSD: Makefile,v 1.2 2016/07/05 00:16:23 beck Exp $ |
| 2 | 2 | ||
| 3 | TESTS = \ | 3 | TESTS = \ |
| 4 | ocsp_test | 4 | ocsp_test |
| @@ -16,6 +16,7 @@ CLEANFILES+= ${TESTS} | |||
| 16 | all_tests: ${TESTS} | 16 | all_tests: ${TESTS} |
| 17 | @for test in $>; do \ | 17 | @for test in $>; do \ |
| 18 | ./$$test www.amazon.com 443; \ | 18 | ./$$test www.amazon.com 443; \ |
| 19 | ./$$test cloudflare.com 443; \ | ||
| 19 | done | 20 | done |
| 20 | 21 | ||
| 21 | .include <bsd.regress.mk> | 22 | .include <bsd.regress.mk> |
diff --git a/src/regress/lib/libcrypto/ocsp/ocsp_test.c b/src/regress/lib/libcrypto/ocsp/ocsp_test.c index 11dcda7462..88675364cf 100644 --- a/src/regress/lib/libcrypto/ocsp/ocsp_test.c +++ b/src/regress/lib/libcrypto/ocsp/ocsp_test.c | |||
| @@ -2,21 +2,22 @@ | |||
| 2 | #include <netdb.h> | 2 | #include <netdb.h> |
| 3 | #include <stdlib.h> | 3 | #include <stdlib.h> |
| 4 | #include <unistd.h> | 4 | #include <unistd.h> |
| 5 | #include <err.h> | ||
| 5 | #include <sys/socket.h> | 6 | #include <sys/socket.h> |
| 6 | 7 | ||
| 7 | #include <openssl/ssl.h> | 8 | #include <openssl/ssl.h> |
| 8 | #include <openssl/ocsp.h> | 9 | #include <openssl/ocsp.h> |
| 9 | 10 | ||
| 10 | static int tcp_connect(char *host, char *port) { | 11 | static int tcp_connect(char *host, char *port) { |
| 11 | int err, sd = -1; | 12 | int error, sd = -1; |
| 12 | struct addrinfo hints, *res, *r; | 13 | struct addrinfo hints, *res, *r; |
| 13 | 14 | ||
| 14 | memset(&hints, 0, sizeof(struct addrinfo)); | 15 | memset(&hints, 0, sizeof(struct addrinfo)); |
| 15 | hints.ai_family = AF_INET; | 16 | hints.ai_family = AF_INET; |
| 16 | hints.ai_socktype = SOCK_STREAM; | 17 | hints.ai_socktype = SOCK_STREAM; |
| 17 | 18 | ||
| 18 | err = getaddrinfo(host, port, &hints, &res); | 19 | error = getaddrinfo(host, port, &hints, &res); |
| 19 | if (err != 0) { | 20 | if (error != 0) { |
| 20 | perror("getaddrinfo()"); | 21 | perror("getaddrinfo()"); |
| 21 | exit(-1); | 22 | exit(-1); |
| 22 | } | 23 | } |
| @@ -45,6 +46,7 @@ int main(int argc, char *argv[]) { | |||
| 45 | OCSP_BASICRESP *br = NULL; | 46 | OCSP_BASICRESP *br = NULL; |
| 46 | X509_STORE *st = NULL; | 47 | X509_STORE *st = NULL; |
| 47 | STACK_OF(X509) *ch = NULL; | 48 | STACK_OF(X509) *ch = NULL; |
| 49 | char *host, *port; | ||
| 48 | 50 | ||
| 49 | SSL *ssl; | 51 | SSL *ssl; |
| 50 | SSL_CTX *ctx; | 52 | SSL_CTX *ctx; |
| @@ -56,7 +58,14 @@ int main(int argc, char *argv[]) { | |||
| 56 | 58 | ||
| 57 | SSL_CTX_load_verify_locations(ctx, "/etc/ssl/cert.pem", NULL); | 59 | SSL_CTX_load_verify_locations(ctx, "/etc/ssl/cert.pem", NULL); |
| 58 | 60 | ||
| 59 | sd = tcp_connect(argv[1], argv[2]); | 61 | if (argc != 3) |
| 62 | errx(-1, "need a host and port to connect to"); | ||
| 63 | else { | ||
| 64 | host = argv[1]; | ||
| 65 | port = argv[2]; | ||
| 66 | } | ||
| 67 | |||
| 68 | sd = tcp_connect(host, port); | ||
| 60 | 69 | ||
| 61 | ssl = SSL_new(ctx); | 70 | ssl = SSL_new(ctx); |
| 62 | 71 | ||
| @@ -64,12 +73,12 @@ int main(int argc, char *argv[]) { | |||
| 64 | SSL_set_tlsext_status_type(ssl, TLSEXT_STATUSTYPE_ocsp); | 73 | SSL_set_tlsext_status_type(ssl, TLSEXT_STATUSTYPE_ocsp); |
| 65 | 74 | ||
| 66 | if (SSL_connect(ssl) <= 0) { | 75 | if (SSL_connect(ssl) <= 0) { |
| 67 | puts("SSL connect error"); | 76 | printf("SSL connect error\n"); |
| 68 | exit(-1); | 77 | exit(-1); |
| 69 | } | 78 | } |
| 70 | 79 | ||
| 71 | if (SSL_get_verify_result(ssl) != X509_V_OK) { | 80 | if (SSL_get_verify_result(ssl) != X509_V_OK) { |
| 72 | puts("Certificate doesn't verify"); | 81 | printf("Certificate doesn't verify from host %s port %s\n", host, port); |
| 73 | exit(-1); | 82 | exit(-1); |
| 74 | } | 83 | } |
| 75 | 84 | ||
| @@ -79,7 +88,7 @@ int main(int argc, char *argv[]) { | |||
| 79 | len = SSL_get_tlsext_status_ocsp_resp(ssl, &p); | 88 | len = SSL_get_tlsext_status_ocsp_resp(ssl, &p); |
| 80 | 89 | ||
| 81 | if (!p) { | 90 | if (!p) { |
| 82 | puts("No OCSP response received"); | 91 | printf("No OCSP response received for %s port %s\n", host, port); |
| 83 | exit(-1); | 92 | exit(-1); |
| 84 | } | 93 | } |
| 85 | 94 | ||
| @@ -110,7 +119,7 @@ int main(int argc, char *argv[]) { | |||
| 110 | exit(-1); | 119 | exit(-1); |
| 111 | } | 120 | } |
| 112 | 121 | ||
| 113 | printf("OCSP validated from %s %s\n", argv[1], argv[2]); | 122 | printf("OCSP validated from %s %s\n", host, port); |
| 114 | 123 | ||
| 115 | return 0; | 124 | return 0; |
| 116 | } | 125 | } |
