summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libtls/tls.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/lib/libtls/tls.c b/src/lib/libtls/tls.c
index 3012ea62a6..cb2833cb54 100644
--- a/src/lib/libtls/tls.c
+++ b/src/lib/libtls/tls.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls.c,v 1.29 2015/09/13 15:39:15 beck Exp $ */ 1/* $OpenBSD: tls.c,v 1.30 2015/09/14 12:20:40 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -380,6 +380,11 @@ tls_handshake(struct tls *ctx)
380{ 380{
381 int rv = -1; 381 int rv = -1;
382 382
383 if ((ctx->flags & (TLS_CLIENT | TLS_SERVER_CONN)) == 0) {
384 tls_set_errorx(ctx, "invalid operation for context");
385 goto out;
386 }
387
383 if (ctx->conninfo == NULL && 388 if (ctx->conninfo == NULL &&
384 (ctx->conninfo = calloc(1, sizeof(*ctx->conninfo))) == NULL) 389 (ctx->conninfo = calloc(1, sizeof(*ctx->conninfo))) == NULL)
385 goto out; 390 goto out;
@@ -393,7 +398,7 @@ tls_handshake(struct tls *ctx)
393 (ctx->ssl_peer_cert = SSL_get_peer_certificate(ctx->ssl_conn)) && 398 (ctx->ssl_peer_cert = SSL_get_peer_certificate(ctx->ssl_conn)) &&
394 (tls_get_conninfo(ctx) == -1)) 399 (tls_get_conninfo(ctx) == -1))
395 rv = -1; 400 rv = -1;
396out: 401 out:
397 /* Prevent callers from performing incorrect error handling */ 402 /* Prevent callers from performing incorrect error handling */
398 errno = 0; 403 errno = 0;
399 return (rv); 404 return (rv);
@@ -463,6 +468,12 @@ tls_close(struct tls *ctx)
463 int ssl_ret; 468 int ssl_ret;
464 int rv = 0; 469 int rv = 0;
465 470
471 if ((ctx->flags & (TLS_CLIENT | TLS_SERVER_CONN)) == 0) {
472 tls_set_errorx(ctx, "invalid operation for context");
473 rv = -1;
474 goto out;
475 }
476
466 if (ctx->ssl_conn != NULL) { 477 if (ctx->ssl_conn != NULL) {
467 ERR_clear_error(); 478 ERR_clear_error();
468 ssl_ret = SSL_shutdown(ctx->ssl_conn); 479 ssl_ret = SSL_shutdown(ctx->ssl_conn);