Thanks! On Wed, Sep 14, 2016 at 4:48 AM, <tob...@netshed.de> wrote:
> Hi again, > > On 07.09.2016, at 18:08, tob...@netshed.de wrote: > [..] > >> On 05.09.2016, at 15:50, bust...@gmail.com wrote: > >> > >>> Hey, the typedef came in handy :) Ok bcook@ > >>> > >>> On Sep 5, 2016, at 11:52 AM, Bob Beck <b...@obtuse.com> wrote: > >>> > >>>> I am in agreement in principle, but please coordinate with bcook@ > and/or jsing@ who were possibly doing > >>>> some related adjustments. > >>>> > >>>> > >> > >> I have a minor adjustment: it should be able to instruct POLLIN/POLLOUT > via the callbacks. > >> I added this, see the diff. > > > > Aaand: a fix for the FLUSH BIO cntl, that happens at the end of SSL > handshakes… > > Next fix: put the callback on the right context for tls_accept. > > Updated diff at the end. > > Best regards > -Tobias > > diff --git src/lib/libtls/tls_bio_cb.c src/lib/libtls/tls_bio_cb.c > index c4220df..e52f43c 100644 > --- src/lib/libtls/tls_bio_cb.c > +++ src/lib/libtls/tls_bio_cb.c > @@ -154,6 +154,7 @@ ctrl_cb(BIO *b, int cmd, long num, void *ptr) > b->shutdown = (int)num; > break; > case BIO_CTRL_DUP: > + case BIO_CTRL_FLUSH: > break; > case BIO_CTRL_INFO: > case BIO_CTRL_GET: > @@ -169,14 +170,32 @@ static int > tls_bio_write_cb(BIO *h, const char *buf, int num, void *cb_arg) > { > struct tls *ctx = cb_arg; > - return (ctx->write_cb)(ctx, buf, num, ctx->cb_arg); > + BIO_clear_retry_flags(h); > + int rv = (ctx->write_cb)(ctx, buf, num, ctx->cb_arg); > + if (rv == TLS_WANT_POLLIN) { > + BIO_set_retry_read(h); > + rv = -1; > + } else if (rv == TLS_WANT_POLLOUT) { > + BIO_set_retry_write(h); > + rv = -1; > + } > + return (rv); > } > > static int > tls_bio_read_cb(BIO *h, char *buf, int size, void *cb_arg) > { > struct tls *ctx = cb_arg; > - return (ctx->read_cb)(ctx, buf, size, ctx->cb_arg); > + BIO_clear_retry_flags(h); > + int rv = (ctx->read_cb)(ctx, buf, size, ctx->cb_arg); > + if (rv == TLS_WANT_POLLIN) { > + BIO_set_retry_read(h); > + rv = -1; > + } else if (rv == TLS_WANT_POLLOUT) { > + BIO_set_retry_write(h); > + rv = -1; > + } > + return (rv); > } > Once the expectations of the callbacks are finalized, this needs a good explanation in the manual. > static BIO * > diff --git src/lib/libtls/tls_server.c src/lib/libtls/tls_server.c > index 09a83ca..ea37700 100644 > --- src/lib/libtls/tls_server.c > +++ src/lib/libtls/tls_server.c > @@ -346,12 +346,13 @@ int > tls_accept_cbs(struct tls *ctx, struct tls **cctx, > tls_read_cb read_cb, tls_write_cb write_cb, void *cb_arg) > { > - struct tls *conn_ctx; > + struct tls *conn_ctx = NULL; > + > > if ((conn_ctx = tls_accept_common(ctx)) == NULL) > goto err; > > - if (tls_set_cbs(ctx, read_cb, write_cb, cb_arg) != 0) { > + if (tls_set_cbs(conn_ctx, read_cb, write_cb, cb_arg) != 0) { > tls_set_errorx(ctx, "callback registration failure"); > goto err; > } > > Oops. I took out the extra NULL assignment, but otherwise looks good, applied.