diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libtls/tls_bio_cb.c | 33 | 
1 files changed, 11 insertions, 22 deletions
| diff --git a/src/lib/libtls/tls_bio_cb.c b/src/lib/libtls/tls_bio_cb.c index 75d9685cb3..034cbd60bf 100644 --- a/src/lib/libtls/tls_bio_cb.c +++ b/src/lib/libtls/tls_bio_cb.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: tls_bio_cb.c,v 1.17 2017/01/12 16:08:49 jsing Exp $ */ | 1 | /* $OpenBSD: tls_bio_cb.c,v 1.18 2017/01/12 16:17:22 jsing Exp $ */ | 
| 2 | /* | 2 | /* | 
| 3 | * Copyright (c) 2016 Tobias Pape <tobias@netshed.de> | 3 | * Copyright (c) 2016 Tobias Pape <tobias@netshed.de> | 
| 4 | * | 4 | * | 
| @@ -114,26 +114,6 @@ bio_cb_read(BIO *bio, char *buf, int size) | |||
| 114 | return (rv); | 114 | return (rv); | 
| 115 | } | 115 | } | 
| 116 | 116 | ||
| 117 | static BIO * | ||
| 118 | tls_get_new_cb_bio(struct tls *ctx) | ||
| 119 | { | ||
| 120 | BIO *bio; | ||
| 121 | |||
| 122 | if (ctx->read_cb == NULL || ctx->write_cb == NULL) { | ||
| 123 | tls_set_errorx(ctx, "no callbacks registered"); | ||
| 124 | return (NULL); | ||
| 125 | } | ||
| 126 | if ((bio = BIO_new(bio_s_cb())) == NULL) { | ||
| 127 | tls_set_errorx(ctx, "failed to create callback i/o"); | ||
| 128 | return (NULL); | ||
| 129 | } | ||
| 130 | |||
| 131 | bio->ptr = ctx; | ||
| 132 | bio->init = 1; | ||
| 133 | |||
| 134 | return (bio); | ||
| 135 | } | ||
| 136 | |||
| 137 | int | 117 | int | 
| 138 | tls_set_cbs(struct tls *ctx, tls_read_cb read_cb, tls_write_cb write_cb, | 118 | tls_set_cbs(struct tls *ctx, tls_read_cb read_cb, tls_write_cb write_cb, | 
| 139 | void *cb_arg) | 119 | void *cb_arg) | 
| @@ -141,12 +121,21 @@ tls_set_cbs(struct tls *ctx, tls_read_cb read_cb, tls_write_cb write_cb, | |||
| 141 | int rv = -1; | 121 | int rv = -1; | 
| 142 | BIO *bio; | 122 | BIO *bio; | 
| 143 | 123 | ||
| 124 | if (read_cb == NULL || write_cb == NULL) { | ||
| 125 | tls_set_errorx(ctx, "no callbacks provided"); | ||
| 126 | goto err; | ||
| 127 | } | ||
| 128 | |||
| 144 | ctx->read_cb = read_cb; | 129 | ctx->read_cb = read_cb; | 
| 145 | ctx->write_cb = write_cb; | 130 | ctx->write_cb = write_cb; | 
| 146 | ctx->cb_arg = cb_arg; | 131 | ctx->cb_arg = cb_arg; | 
| 147 | 132 | ||
| 148 | if ((bio = tls_get_new_cb_bio(ctx)) == NULL) | 133 | if ((bio = BIO_new(bio_s_cb())) == NULL) { | 
| 134 | tls_set_errorx(ctx, "failed to create callback i/o"); | ||
| 149 | goto err; | 135 | goto err; | 
| 136 | } | ||
| 137 | bio->ptr = ctx; | ||
| 138 | bio->init = 1; | ||
| 150 | 139 | ||
| 151 | SSL_set_bio(ctx->ssl_conn, bio, bio); | 140 | SSL_set_bio(ctx->ssl_conn, bio, bio); | 
| 152 | 141 | ||
