X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Ftlsopenssl%2Ftls_openssl.c;h=964230f178ffa083a1bb1257a53448ea04cc5f55;hb=b85de19145a01d3acdf326c3cfa4e94b585bb59f;hp=7a840f11b4a1e5c4e3e4a2fadcb33a2abd5e26ae;hpb=e3c6a54995b052045709b1d80039eede1757f43f;p=vpp.git diff --git a/src/plugins/tlsopenssl/tls_openssl.c b/src/plugins/tlsopenssl/tls_openssl.c index 7a840f11b4a..964230f178f 100644 --- a/src/plugins/tlsopenssl/tls_openssl.c +++ b/src/plugins/tlsopenssl/tls_openssl.c @@ -194,10 +194,10 @@ static int openssl_write_from_fifo_into_ssl (svm_fifo_t *f, SSL *ssl, u32 max_len) { int wrote = 0, rv, i = 0, len; - const int n_segs = 2; + u32 n_segs = 2; svm_fifo_seg_t fs[n_segs]; - len = svm_fifo_segments (f, 0, fs, n_segs, max_len); + len = svm_fifo_segments (f, 0, fs, &n_segs, max_len); if (len <= 0) return 0; @@ -341,9 +341,18 @@ openssl_ctx_handshake_rx (tls_ctx_t * ctx, session_t * tls_session) { /* Need to check transport status */ if (ctx->is_passive_close) - openssl_handle_handshake_failure (ctx); - else - tls_notify_app_accept (ctx); + { + openssl_handle_handshake_failure (ctx); + return -1; + } + + /* Accept failed, cleanup */ + if (tls_notify_app_accept (ctx)) + { + ctx->c_s_index = SESSION_INVALID_INDEX; + tls_disconnect_transport (ctx); + return -1; + } } TLS_DBG (1, "Handshake for %u complete. TLS cipher is %s", @@ -354,6 +363,8 @@ openssl_ctx_handshake_rx (tls_ctx_t * ctx, session_t * tls_session) static void openssl_confirm_app_close (tls_ctx_t * ctx) { + openssl_ctx_t *oc = (openssl_ctx_t *) ctx; + SSL_shutdown (oc->ssl); tls_disconnect_transport (ctx); session_transport_closed_notify (&ctx->connection); } @@ -422,10 +433,10 @@ openssl_ctx_write_dtls (tls_ctx_t *ctx, session_t *app_session, { openssl_main_t *om = &openssl_main; openssl_ctx_t *oc = (openssl_ctx_t *) ctx; + u32 read = 0, to_deq, dgram_sz, enq_max; session_dgram_pre_hdr_t hdr; session_t *us; int wrote, rv; - u32 read = 0, to_deq, dgram_sz; u8 *buf; us = session_get_from_handle (ctx->tls_session_handle); @@ -440,7 +451,9 @@ openssl_ctx_write_dtls (tls_ctx_t *ctx, session_t *app_session, ASSERT (to_deq >= hdr.data_length + SESSION_CONN_HDR_LEN); dgram_sz = hdr.data_length + SESSION_CONN_HDR_LEN; - if (svm_fifo_max_enqueue_prod (us->tx_fifo) < dgram_sz + TLSO_CTRL_BYTES) + enq_max = dgram_sz + TLSO_CTRL_BYTES; + if (svm_fifo_max_enqueue_prod (us->tx_fifo) < enq_max || + svm_fifo_provision_chunks (us->tx_fifo, 0, 0, enq_max)) { svm_fifo_add_want_deq_ntf (us->tx_fifo, SVM_FIFO_WANT_DEQ_NOTIF); transport_connection_deschedule (&ctx->connection); @@ -738,29 +751,59 @@ openssl_start_listen (tls_ctx_t * lctx) return -1; } + /* use the default OpenSSL built-in DH parameters */ + rv = SSL_CTX_set_dh_auto (ssl_ctx, 1); + if (rv != 1) + { + TLS_DBG (1, "Couldn't set temp DH parameters"); + return -1; + } + /* * Set the key and cert */ cert_bio = BIO_new (BIO_s_mem ()); + if (!cert_bio) + { + clib_warning ("unable to allocate memory"); + return -1; + } BIO_write (cert_bio, ckpair->cert, vec_len (ckpair->cert)); srvcert = PEM_read_bio_X509 (cert_bio, NULL, NULL, NULL); if (!srvcert) { clib_warning ("unable to parse certificate"); - return -1; + goto err; } - SSL_CTX_use_certificate (ssl_ctx, srvcert); + rv = SSL_CTX_use_certificate (ssl_ctx, srvcert); + if (rv != 1) + { + clib_warning ("unable to use SSL certificate"); + goto err; + } + BIO_free (cert_bio); cert_bio = BIO_new (BIO_s_mem ()); + if (!cert_bio) + { + clib_warning ("unable to allocate memory"); + return -1; + } BIO_write (cert_bio, ckpair->key, vec_len (ckpair->key)); pkey = PEM_read_bio_PrivateKey (cert_bio, NULL, NULL, NULL); if (!pkey) { clib_warning ("unable to parse pkey"); - return -1; + goto err; } - SSL_CTX_use_PrivateKey (ssl_ctx, pkey); + rv = SSL_CTX_use_PrivateKey (ssl_ctx, pkey); + if (rv != 1) + { + clib_warning ("unable to use SSL PrivateKey"); + goto err; + } + BIO_free (cert_bio); olc_index = openssl_listen_ctx_alloc (); @@ -774,6 +817,10 @@ openssl_start_listen (tls_ctx_t * lctx) return 0; +err: + if (cert_bio) + BIO_free (cert_bio); + return -1; } static int