diff -NurBbp gnutls28-3.6.6/AUTHORS gnutls28-3.6.7/AUTHORS
--- gnutls28-3.6.6/AUTHORS	2019-01-25 08:33:11.000000000 +0100
+++ gnutls28-3.6.7/AUTHORS	2019-03-27 08:00:41.000000000 +0100
@@ -2,8 +2,8 @@ The authors list is autogenerated from t
 
 Nikos Mavrogiannopoulos <nmav at gnutls.org>
 Simon Josefsson <jas at josefsson.org>
-Dmitry Eremin-Solenikov <dbaryshkov at gmail.com>
 Tim Rühsen <tim.ruehsen at gmx.de>
+Dmitry Eremin-Solenikov <dbaryshkov at gmail.com>
 Daiki Ueno <ueno at gnu.org>
 Ludovic Courtès <ludo at gnu.org>
 Timo Schulz <twoaday at gnutls.org>
@@ -23,17 +23,18 @@ Alex Gaynor <alex.gaynor at gmail.com>
 Martin Ukrop <mukrop at redhat.com>
 Jaak Ristioja <jaak.ristioja at cyber.ee>
 Attila Molnar <attilamolnar at hush.com>
+Hugo Beauzée-Luyssen <hugo at beauzee.fr>
 Simo Sorce <simo at redhat.com>
 Martin Sucha <anty.sk+git at gmail.com>
 Stefan Berger <stefanb at linux.ibm.com>
 David Woodhouse <dwmw2 at infradead.org>
 Jan Vcelak <jan.vcelak at nic.cz>
 Kevin Cernekee <cernekee at gmail.com>
-Hugo Beauzée-Luyssen <hugo at beauzee.fr>
 Ander Juaristi <a at juaristi.eus>
 Stefan Sørensen <stefan.sorensen at spectralink.com>
 Adam Sampson <ats at offog.org>
 Alfredo Pironti <alfredo at pironti.eu>
+Anderson Toshiyuki Sasaki <ansasaki at redhat.com>
 Brad Hards <bradh at frogmouth.net>
 Michael Weiser <michael.weiser at gmx.de>
 Patrick Pelletier <code at funwithsoftware.org>
@@ -60,6 +61,7 @@ Hubert Kario <hkario at redhat.com>
 Ilya Tumaykin <itumaykin at gmail.com>
 James Bottomley <James.Bottomley at HansenPartnership.com>
 Karl Tarbe <karl.tarbe at cyber.ee>
+Ke Zhao <kzhao at redhat.com>
 Mark Brand <mabrand at mabrand.nl>
 Matthias-Christian Ott <ott at mirix.org>
 Maya Rashish <coypu at sdf.org>
@@ -75,6 +77,7 @@ Alexandre Bique <bique.alexandre at gmai
 Andreas Schneider <asn at samba.org>
 Andreas Schwab <schwab at suse.de>
 Avinash Sonawane <rootkea at gmail.com>
+Bas van Schaik <gitlab.com at s.traiectum.net>
 Bjørn Christensen <bhc at insight.dk>
 Carolin Latze <latze at angry-red-pla.net>
 Chen Hongzhi <hongzhi.chen at me.com>
@@ -112,6 +115,7 @@ Nils Maier <maierman at web.de>
 Olga <olyasib12 at gmail.com>
 Philippe Proulx <eeppeliteloop at gmail.com>
 Philippe Widmer <pw at earthwave.ch>
+R. Andrew Bailey <bailey at akamai.com>
 Raj Raman <rajramanca at gmail.com>
 Rical Jasan <ricaljasan at pacific.net>
 Rickard Bellgrim <rickard at opendnssec.org>
@@ -122,6 +126,7 @@ SUMIT AGGARWAL <aggarwal.s at samsung.co
 Saurav Babu <saurav.babu at samsung.com>
 Sebastian Dröge <sebastian at centricular.com>
 Simon Arlott <sa.me.uk>
+Steve Lhomme <robux4 at ycbcr.xyz>
 Thomas Klausner <wiz at NetBSD.org>
 Tobias Polzer <tobias.polzer at fau.de>
 Tomas Hoger <thoger at redhat.com>
diff -NurBbp gnutls28-3.6.6/cfg.mk gnutls28-3.6.7/cfg.mk
--- gnutls28-3.6.6/cfg.mk	2019-01-11 07:32:55.000000000 +0100
+++ gnutls28-3.6.7/cfg.mk	2019-02-12 05:51:35.000000000 +0100
@@ -23,7 +23,7 @@ ADDFLAGS ?=
 CFGFLAGS ?= --enable-gtk-doc --enable-gtk-doc-pdf --enable-gtk-doc-html $(ADDFLAGS) $(WFLAGS)
 PACKAGE ?= gnutls
 
-.PHONY: config
+.PHONY: config glimport
 
 INDENT_SOURCES = `find . -name \*.[ch] -o -name gnutls.h.in | grep -v -e ^./build-aux/ -e ^./lib/minitasn1/ -e ^./lib/build-aux/ -e ^./gl/ -e ^./src/libopts/ -e -args.[ch] -e asn1_tab.c -e ^./tests/suite/`
 
@@ -56,7 +56,6 @@ exclude_file_name_regexp--sc_m4_quote_ch
 exclude_file_name_regexp--sc_makefile_at_at_check='lib/unistring/Makefile.am'
 exclude_file_name_regexp--sc_prohibit_stddef_without_use='u*-normalize.c'
 exclude_file_name_regexp--sc_prohibit_strncpy='unistr.in.h'
-exclude_file_name_regexp--sc_prohibit_always-defined_macros='lib/system/inet_pton.c'
 gl_public_submodule_commit =
 
 autoreconf:
@@ -72,19 +71,10 @@ config:
 
 bootstrap: autoreconf .submodule.stamp
 
-UNISTRING_MODULES = "unistr/u8-check unistr/u8-to-u16 unistr/u8-to-u32 unistr/u32-to-u8 \
-	unistr/u16-to-u8 uninorm/nfc uninorm/nfkc uninorm/u8-normalize uninorm/u16-normalize \
-	uninorm/u32-normalize unictype/category-all unictype/property-not-a-character \
-	unictype/property-default-ignorable-code-point unictype/property-join-control"
-
-unistringimport:
-	../gnulib/gnulib-tool --without-tests --libtool --macro-prefix=unistring --lgpl=3orGPLv2 --dir=. --local-dir=lib/unistring/override --lib=libunistring --without-tests --source-base=lib/unistring --m4-base=lib/unistring/m4 --doc-base=doc --aux-dir=build-aux --import $(UNISTRING_MODULES)
-
-# The only non-lgpl modules used are: gettime progname timespec. Those
-# are not used (and must not be used) in the library)
-glimport: unistringimport
-	../gnulib/gnulib-tool --dir=. --local-dir=gl/override --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --lgpl=2 --add-import
-	../gnulib/gnulib-tool --dir=. --local-dir=src/gl/override --lib=libgnu_gpl --source-base=src/gl --m4-base=src/gl/m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --add-import
+glimport:
+	pushd gnulib && git checkout master && git pull && popd
+	echo "If everything looks well, commit the gnulib update with:"
+	echo "  git commit -m "Update gnulib submodule" gnulib"
 
 # Code Coverage
 
diff -NurBbp gnutls28-3.6.6/ChangeLog gnutls28-3.6.7/ChangeLog
--- gnutls28-3.6.6/ChangeLog	2019-01-25 08:33:22.000000000 +0100
+++ gnutls28-3.6.7/ChangeLog	2019-03-27 08:00:52.000000000 +0100
@@ -1,4 +1,969 @@
 Author: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+Date:   Wed Mar 27 07:21:31 2019 +0100
+
+    released 3.6.7
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+
+Author: Daiki Ueno <dueno@redhat.com>
+Date:   Mon Mar 25 16:06:39 2019 +0100
+
+    handshake: add missing initialization of local variable
+    
+    Resolves: #704
+    
+    Signed-off-by: Daiki Ueno <dueno@redhat.com>
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
+
+Author: Nikos Mavrogiannopoulos <nmav@redhat.com>
+Date:   Mon Mar 25 15:47:51 2019 +0100
+
+    fuzz: added fuzzer for certificate verification
+    
+    This also adds a reproducer for CVE-2019-3829.
+    
+    Resolves: #694
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
+
+Author: Nikos Mavrogiannopoulos <nmav@redhat.com>
+Date:   Tue Mar 26 16:11:42 2019 +0100
+
+    bumped version
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
+
+Author: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
+Date:   Tue Mar 26 11:05:06 2019 +0100
+
+    fips140: Perform SHA-3 self tests
+    
+    It is required to perform the self tests to validate SHA-3
+    implementation.
+    
+    Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
+
+Author: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+Date:   Sun Mar 24 08:37:05 2019 +0100
+
+    tools: removed unused code
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+
+Author: Ke Zhao <kzhao@redhat.com>
+Date:   Thu Mar 21 11:27:24 2019 -0400
+
+    gnutls-cli: Fix output with option "--logfile"
+    
+    The X.509 connection would still print informational message to the
+    stdout by default. Move that output to logfile and add x509 functionality
+    test in the test suite.
+    
+    Signed-off-by: Ke Zhao <kzhao@redhat.com>
+
+Author: Alon Bar-Lev <alon.barlev@gmail.com>
+Date:   Sat Mar 23 00:38:17 2019 +0200
+
+    configure.ac: remove --with-guile-site-dir
+    
+    The hack of distcheck is not known and should not be the default as the
+    GUILE_SITE_DIR macro is the default expected behavior.
+    
+    There is little value in specifying any other location of the site-dir as it
+    is out of the guile configuration so best to remove.
+    
+    Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
+
+Author: Nikos Mavrogiannopoulos <nmav@redhat.com>
+Date:   Wed Mar 20 11:40:15 2019 +0100
+
+    _x509_en/decode_provable_seed: clarified purpose of functions [ci skip]
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
+
+Author: Nikos Mavrogiannopoulos <nmav@redhat.com>
+Date:   Fri Mar 1 11:15:47 2019 +0100
+
+    handshake: increase the default number of tickets we send to 2
+    
+    This makes it easier for clients which perform multiple connections
+    to the server to use the tickets sent by a default server. That's
+    because 2 tickets allow for 2 new connections (if one is using each
+    ticket once as recommended), which in turn lead to 4 new and so on.
+    
+    Resolves: #596
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
+
+Author: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+Date:   Sat Feb 23 21:02:56 2019 +0100
+
+    Improved estimation of wait in gnutls_session_get_data2
+    
+    Previously we would wait an arbitrary value of 50ms for the
+    server to send session tickets. This change makes the client
+    wait for the estimated single trip time + 60 ms for the server
+    to calculate the session tickets. This improves the chance
+    to obtain tickets from internet servers during the call of
+    gnutls_session_get_data2().
+    
+    Resolves: #706
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+
+Author: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+Date:   Sat Mar 16 19:59:07 2019 +0100
+
+    doc update
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+
+Author: Ke Zhao <kzhao@redhat.com>
+Date:   Wed Mar 6 13:23:24 2019 -0500
+
+    gnutls-cli: Add option "--logfile" to redirect information message output
+    
+    First, add an option "--logfile" so user could choose a specific file to
+    store all the informational messages. In some cases, informational
+    messages may cause unexpected result if the output is standard output.
+    
+    With this option, user could redirect these messages to a specific
+    file. This will be helpful in testing and tracking.
+    
+    Second, replace printf() function with log_msg() function
+    
+    This log_msg() function is used when "--logfile" is enabled.
+    
+    Third, add a functionality test for "--logfile" option
+    
+    Add a test script to test if "--logfile" option works as it should be.
+    
+    Signed-off-by: Ke Zhao <kzhao@redhat.com>
+
+Author: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+Date:   Fri Mar 15 17:00:17 2019 +0100
+
+    Removed all FIXME comments in code [ci skip]
+    
+    We expand informational comments on limitations, but with removing
+    FIXME (keyword didn't help fixing these), and remove completely unhelpful
+    comments, obsolete ones, or comments about ideas.
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+
+Author: Nikos Mavrogiannopoulos <nmav@redhat.com>
+Date:   Wed Mar 13 15:14:37 2019 +0100
+
+    pkcs11: security officer login implies writable session
+    
+    According to the PKCS#11 v2.30, 6.7.1 there are no read-only Security Officer
+    sessions.
+    
+    Resolves: #721
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
+
+Author: Steve Lhomme <robux4@ycbcr.xyz>
+Date:   Wed Mar 13 14:54:28 2019 +0000
+
+    inet_ntop is available in Windows but not via arpa/inet.h
+    
+    It's found in ws2tcpip.h which is already included in gnutls_int.h
+    
+    arpa/inet.h doesn't exist on Windows, so add arpa_inet to the list of headers
+    replaced by gnulib if not found.
+    
+    Signed-off-by: Steve Lhomme <robux4@ycbcr.xyz>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Thu Mar 7 10:16:46 2019 +0100
+
+    Update the GNU Free Documentation License (FDL)
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Mon Feb 25 10:36:36 2019 +0100
+
+    Fix URL of ABI compliance checker
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Mon Feb 25 10:32:24 2019 +0100
+
+    Fix URLs of p11-kit
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Tue Feb 5 17:00:41 2019 +0100
+
+    Use https:// in lib/, src/, and m4/
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Tue Feb 5 16:56:08 2019 +0100
+
+    Use https:// for arbitrary files #1
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Tue Feb 5 16:44:37 2019 +0100
+
+    Use https:// for www.iana.org
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Tue Feb 5 16:25:25 2019 +0100
+
+    Use https:// for csrc.nist.gov
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Tue Feb 5 16:22:43 2019 +0100
+
+    Use https:// for www.gnu.org and www.example.com
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: Nikos Mavrogiannopoulos <nmav@redhat.com>
+Date:   Wed Mar 13 09:03:39 2019 +0100
+
+    .gitlab-ci.yml: updated cache key name
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
+
+Author: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+Date:   Sun Mar 10 13:59:32 2019 +0100
+
+    tests: verify that 'certtool -i --outder' does not output text
+    
+    A common regression in the past, was certtool outputting text while
+    writing raw DER data. Ensure that the certificate-info option does not
+    regress.
+    
+    Resolves: #627
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+
+Author: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+Date:   Sat Mar 9 21:50:46 2019 +0100
+
+    SECURITY.md: updated to reflect the current practice [ci skip]
+    
+    This change updates the SECURITY guidelines to reflect the current
+    practice (no special security releases), and thus refer directly
+    to the upcoming or following release. Furthermore, it removes
+    any mention of absolute time, as the release cadence is already
+    fixed to bi-monthly.
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+
+Author: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+Date:   Sat Mar 9 21:14:39 2019 +0100
+
+    doc: removed cyclo subdir
+    
+    This directory had a makefile which was intended to calculate the cyclomatic
+    complexity, however that was not functional, and not related with gnutls'
+    documentation.
+    
+    Resolves: #727
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+
+Author: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+Date:   Fri Mar 8 20:17:49 2019 +0100
+
+    NEWS: fix NEWS entries [ci skip]
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+
+Author: Daiki Ueno <dueno@redhat.com>
+Date:   Mon Mar 4 17:17:47 2019 +0100
+
+    tls13/certificate: utilize "certificate_required" alert
+    
+    This could make errors more distinguishable when the client sends no
+    certificates or a bad certificate.
+    
+    Signed-off-by: Daiki Ueno <dueno@redhat.com>
+
+Author: Daiki Ueno <dueno@redhat.com>
+Date:   Wed Feb 27 18:38:09 2019 +0100
+
+    alert: recognize "certificate_required"
+    
+    This may be sent if the server received an empty Certificate message.
+    
+    Signed-off-by: Daiki Ueno <dueno@redhat.com>
+
+Author: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
+Date:   Fri Jan 18 13:17:46 2019 +0100
+
+    .gitlab-ci.yml: Test FIPS HMAC self-test
+    
+    This enables the integrity self-tests in FIPS140 test build.
+    
+    Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
+
+Author: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
+Date:   Fri Jan 11 11:23:21 2019 +0100
+
+    fips140: Ignore newlines read at the end of HMAC file
+    
+    This makes the integrity check to ignore newlines appended after the
+    HMAC value.
+    
+    Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
+
+Author: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
+Date:   Thu Jan 10 14:04:02 2019 +0100
+
+    fips140: Fix the names of files used in integrity checks
+    
+    The names of the libraries haven't been updated when the soname version
+    were bumped.
+    
+    Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
+
+Author: Bas van Schaik <gitlab.com@s.traiectum.net>
+Date:   Thu Feb 28 22:15:26 2019 +0000
+
+    Create .lgtm.yml for LGTM.com C/C++ analysis
+    
+    Signed-off-by: Bas van Schaik <gitlab.com@s.traiectum.net>
+
+Author: Nikos Mavrogiannopoulos <nmav@redhat.com>
+Date:   Mon Feb 25 14:41:24 2019 +0100
+
+    .gitlab-ci.yml: added thread sanitizer run
+    
+    This checks for unsafe uses of variables in our included threaded
+    tests.
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
+
+Author: Nikos Mavrogiannopoulos <nmav@redhat.com>
+Date:   Mon Feb 25 14:35:16 2019 +0100
+
+    Protected _gnutls_epoch_get from _gnutls_epoch_gc on false start
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
+
+Author: Nikos Mavrogiannopoulos <nmav@redhat.com>
+Date:   Mon Feb 25 15:11:19 2019 +0100
+
+    gnutls_record_send2: try to ensure integrity of operations on false and early start
+    
+    This adds a double check in the sanity check of gnutls_record_send2()
+    for the initial_negotiation_completed value, making sure that the
+    check will be successful even in parallel operation of send/recv.
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
+
+Author: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+Date:   Sun Feb 24 21:13:27 2019 +0100
+
+    mini-dtls-pthread: renamed and fixed several shortcomings
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+
+Author: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+Date:   Sun Feb 24 00:19:21 2019 +0100
+
+    Make false start and early start multi-thread recv/send safe
+    
+    An application that is sending and receiving from different threads
+    after handshake is complete cannot take advantage of false start because
+    gnutls_record_send2() detects operations during the handshake process
+    as invalid.
+    
+    Because in early start and false start the remaining handshake process needs
+    only to receive data, and the sending side is already set-up, this error
+    detection is bogus. With this patch we remove it.
+    
+    Resolves: #713
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+
+Author: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+Date:   Sat Feb 23 18:57:09 2019 +0100
+
+    doc: added more information on operation under multiple threads
+    
+    Relates: #713
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Fri Mar 1 20:13:38 2019 +0100
+
+    Update ./bootstrap from latest gnulib
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: Nikos Mavrogiannopoulos <nmav@redhat.com>
+Date:   Wed Feb 27 10:01:47 2019 +0100
+
+    Clarifications on AEAD ciphers
+    
+    Relates: #716
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
+
+Author: Nikos Mavrogiannopoulos <nmav@redhat.com>
+Date:   Wed Feb 27 09:29:04 2019 +0100
+
+    Improve documentation for gnutls_cipher_get_iv_size
+    
+    This clarifies what is returned and what is to be expected on algorithms
+    with variable IV sizes.
+    
+    Resolves: #717
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
+
+Author: Nikos Mavrogiannopoulos <nmav@redhat.com>
+Date:   Tue Feb 26 15:42:01 2019 +0100
+
+    pkcs11: clarify GNUTLS_PKCS11_TOKEN_MODNAME presence [ci skip]
+    
+    Resolves: #633
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
+
+Author: Nikos Mavrogiannopoulos <nmav@redhat.com>
+Date:   Tue Feb 26 15:21:48 2019 +0100
+
+    cppcheck: suppress warning on nettle code [ci skip]
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
+
+Author: Andreas Metzler <ametzler@bebt.de>
+Date:   Sat Feb 23 18:43:49 2019 +0100
+
+    gnutls-cli: fix --benchmark-ciphers type overflow
+    
+    Signed-off-by: Andreas Metzler <ametzler@bebt.de>
+
+Author: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+Date:   Sat Feb 23 21:19:06 2019 +0100
+
+    _gnutls_recv_handshake: added explicit sanity checks
+    
+    Although, this function acts on the message provided as expected and thus
+    it should never call a message parsing function on unexpected
+    messages, we make a more explicit sanity check. This unifies the
+    sanity checks existing within the involved functions.
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Tue Feb 12 15:20:23 2019 +0100
+
+    gnutls_x509_crt_init: Fix dereference of NULL pointer
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Tue Feb 12 15:14:07 2019 +0100
+
+    Remove redundant resets of variables after free()
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Tue Feb 12 15:09:11 2019 +0100
+
+    Automatically NULLify after gnutls_free()
+    
+    This method prevents direct use-after-free and
+    double-free issues.
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: Daiki Ueno <dueno@redhat.com>
+Date:   Tue Feb 19 13:56:35 2019 +0100
+
+    tlsfuzzer: update to the latest upstream for downgrade protection tests
+    
+    Signed-off-by: Daiki Ueno <dueno@redhat.com>
+
+Author: Daiki Ueno <dueno@redhat.com>
+Date:   Sat Feb 9 10:26:56 2019 +0100
+
+    ext/supported_versions: regenerate server random
+    
+    This adds a call to _gnutls_gen_server_random() in handling the
+    "supported_versions" extension, so that the TLS 1.3 downgrade sentinel
+    is set only when the earlier versions are selected.
+    
+    Signed-off-by: Daiki Ueno <dueno@redhat.com>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Tue Feb 5 11:01:20 2019 +0100
+
+    Update ax_code_coverage.m4 to latest release of autoconf-archive
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
+Date:   Thu Feb 21 14:49:36 2019 +0100
+
+    lib: x509: Minor directory browsing simplification
+    
+    Signed-off-by: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
+
+Author: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
+Date:   Mon Feb 18 14:41:56 2019 +0100
+
+    Revert "Revert "verify-high2: Fix cert dir iteration on Win32""
+    
+    This reverts commit 681330882da19099eea360fab141cab937c45677.
+    
+    Signed-off-by: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
+    
+    This revert also contains the fix to the original commit (invalid
+    utf8->utf16 conversion) and a minor simplification of the _treaddir loop.
+
+Author: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
+Date:   Mon Feb 18 17:12:54 2019 +0100
+
+    iconv: Allow _gnutls_utf8_to_ucs2 to output little endian
+    
+    Signed-off-by: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
+
+Author: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
+Date:   Mon Feb 18 09:37:04 2019 +0100
+
+    lib: Provide _Thread_local on MSVC
+    
+    Signed-off-by: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Mon Feb 18 21:38:38 2019 +0100
+
+    Add test for starttls XMPP
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Wed Feb 6 11:30:06 2019 +0100
+
+    gnutls-cli: Fix --starttls-proto=xmpp
+    
+    Fixes two issues with gnutls-cli --starttls-proto=xmpp:
+    1. Print 'Timeout' on timeout instead of random errno message
+    2. Do not wait for linefeed when using XMPP (XML)
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Mon Feb 18 15:38:56 2019 +0100
+
+    check_if_signed: Get source branch if not set
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: R. Andrew Bailey <bailey@akamai.com>
+Date:   Thu Feb 14 09:38:33 2019 -0500
+
+    tests: wrap ADD_SYSCALL for getrandom in test for SYS_getrandom
+    
+    Signed-off-by: R. Andrew Bailey <bailey@akamai.com>
+
+Author: Daiki Ueno <dueno@redhat.com>
+Date:   Fri Feb 8 14:46:33 2019 +0100
+
+    gnutls_record_set_max_size: make it work on server side
+    
+    The record_size_limit extension can also be specified by the server to
+    indicate the maximum plaintext.  Also add test cases for asymmetric
+    settings between server and client.
+    
+    Signed-off-by: Daiki Ueno <dueno@redhat.com>
+
+Author: Daiki Ueno <dueno@redhat.com>
+Date:   Thu Jan 31 13:39:35 2019 +0100
+
+    tlsfuzzer: update to the latest upstream for record_size_limit test
+    
+    Signed-off-by: Daiki Ueno <dueno@redhat.com>
+
+Author: Daiki Ueno <dueno@redhat.com>
+Date:   Fri Feb 8 13:22:13 2019 +0100
+
+    ext/record_size_limit: account for content type octet in TLS 1.3
+    
+    In TLS 1.3, the protocol maximum of plaintext size is 2^14+1, while
+    it is 2^14 in TLS 1.2.  To accommodate that, this introduces the
+    following invariant:
+    - when the maximum is set by the user with
+      gnutls_record_set_max_size(), store it as is.  The value range is
+      [511, 16834].
+    - when the maximum is negotiated through record_size_limit extension,
+      it can be [512, 16385].  In TLS 1.3, subtract by 1 to fit in [511,
+      16384].
+    
+    Signed-off-by: Daiki Ueno <dueno@redhat.com>
+
+Author: Daiki Ueno <dueno@redhat.com>
+Date:   Thu Jan 31 16:56:55 2019 +0100
+
+    decrypt_packet_tls13: add check for max plaintext size
+    
+    There is check in _gnutls_recv_in_buffers already, but for TLS 1.3 we
+    need to take account of the padding.
+    
+    Signed-off-by: Daiki Ueno <dueno@redhat.com>
+
+Author: Daiki Ueno <dueno@redhat.com>
+Date:   Fri Jan 25 17:00:44 2019 +0100
+
+    record: reject too large plaintext after decryption
+    
+    Signed-off-by: Daiki Ueno <dueno@redhat.com>
+
+Author: Daiki Ueno <dueno@redhat.com>
+Date:   Wed Jan 30 16:45:08 2019 +0100
+
+    constate: reset max_record_recv_size upon renegotiation
+    
+    Signed-off-by: Daiki Ueno <dueno@redhat.com>
+
+Author: Daiki Ueno <dueno@redhat.com>
+Date:   Wed Jan 30 10:21:07 2019 +0100
+
+    session_pack: reset max_record_recv_size when packing
+    
+    Signed-off-by: Daiki Ueno <dueno@redhat.com>
+
+Author: Daiki Ueno <dueno@redhat.com>
+Date:   Thu Jan 17 11:53:35 2019 +0100
+
+    ext/record_size_limit: don't confuse with negotiated/user-supplied maximum
+    
+    As documented in gnutls_int.h, max_record_send_size is for tracking
+    the user-supplied maximum, while max_record_recv_size for the
+    protocol negotiated maximum.
+    
+    Signed-off-by: Daiki Ueno <dueno@redhat.com>
+
+Author: Daiki Ueno <dueno@redhat.com>
+Date:   Sun Jan 20 09:18:21 2019 +0100
+
+    ext/max_record: server shouldn't send it with record_size_limit
+    
+    Otherwise, the connection will be disconnected by the client, as
+    suggested in RFC: A client MUST treat receipt of both
+    "max_fragment_length" and "record_size_limit" as a fatal error, and it
+    SHOULD generate an "illegal_parameter" alert.
+    
+    Signed-off-by: Daiki Ueno <dueno@redhat.com>
+
+Author: Daiki Ueno <dueno@redhat.com>
+Date:   Thu Feb 7 16:28:52 2019 +0100
+
+    _gnutls_hello_ext_is_present: don't ignore max_fragment_length
+    
+    The extension is assigned the internal ID 0.
+    
+    Signed-off-by: Daiki Ueno <dueno@redhat.com>
+
+Author: Daiki Ueno <dueno@redhat.com>
+Date:   Fri Jan 25 17:04:40 2019 +0100
+
+    .dir-locals.el: disable indent-tabs-mode in js-mode
+    
+    Signed-off-by: Daiki Ueno <dueno@redhat.com>
+
+Author: Nikos Mavrogiannopoulos <nmav@redhat.com>
+Date:   Thu Feb 14 13:01:34 2019 +0100
+
+    bootstrap.conf: do not override GNULIB_SRCDIR
+    
+    This was not set in all of our CI platforms, and was causing
+    issues in MacOSX.
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
+
+Author: Nikos Mavrogiannopoulos <nmav@redhat.com>
+Date:   Mon Feb 11 09:18:46 2019 +0100
+
+    x509: corrected issue in the algorithm parameters comparison
+    
+    Each certificate has two fields to set the signature algorithm
+    and parameters used for the digital signature. One of the fields is
+    authenticated and the other is not. It is required from RFC5280 to
+    enforce the equality of these fields, but currently due to an issue
+    we wouldn't enforce the equality of the parameters fields. This
+    fix corrects the issue.
+    
+    We also move an RSA-PSS certificate in chainverify that was relying
+    on invalid parameters, to this set of invalid certificates.
+    
+    Resolves: #698
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
+
+Author: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+Date:   Wed Feb 13 07:54:59 2019 +0000
+
+    tests: added further checks for gnutls_pkcs11_token_get_info
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Tue Jan 29 16:10:59 2019 +0100
+
+    Fix uninitialized warning in pkcs11.c
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Wed Feb 13 17:22:21 2019 +0100
+
+    Cleanup lib/auth/cert.c as suggested by cppcheck
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Mon Feb 11 10:41:47 2019 +0100
+
+    Fix 32bit overflow issue in src/serv-args.def
+    
+    Fixing this warning seen on 32bit architectures:
+    
+    serv-args.c: In function 'doOptMaxearlydata':
+    serv-args.c:1431:14: warning: overflow in conversion from 'long long int' to 'long int' changes value from '4294967296' to '0' [-Woverflow]
+             { 1, 4294967296 } };
+                  ^~~~~~~~~~
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Fri Feb 8 13:03:30 2019 +0100
+
+    Remove typedef'ing ssize_t in gnutls.h
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Wed Feb 6 20:54:45 2019 +0100
+
+    Use inet_pton() from gnulib
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+Date:   Sat Feb 9 10:52:29 2019 +0100
+
+    bootstrap: refuse to bootstrap if any dependencies bring gnulib's network stack
+    
+    If gnulib's network stack is brought (due to a dependency) in the library
+    it will make the library unusable to non-gnulib using applications. This
+    prevents windows applications for example to use gnutls, and so on. Even
+    more it is quite hard to catch that issue because our testsuite uses
+    gnulib as well. Instead we try to catch the these modules at import time.
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Wed Feb 6 20:35:11 2019 +0100
+
+    Use inet_ntop() from gnulib
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: Nikos Mavrogiannopoulos <nmav@redhat.com>
+Date:   Sun Feb 3 12:18:30 2019 +0100
+
+    _gnutls_gen_rawpk_crt: corrected the use of assert
+    
+    The API could return 0 or 1 matching certificates. The case of zero
+    can only happen in client side.
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
+
+Author: Nikos Mavrogiannopoulos <nmav@redhat.com>
+Date:   Sun Feb 3 08:47:50 2019 +0100
+
+    raw public keys: apply the key usage bits the same way as X.509
+    
+    That is, we require a signing certificate when negotiating
+    TLS1.3, or when sending a client certificate (on all cases).
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
+
+Author: Nikos Mavrogiannopoulos <nmav@redhat.com>
+Date:   Sat Feb 2 09:13:40 2019 +0100
+
+    Fallback to TLS 1.2 when incompatible with signature certs are provided
+    
+    This only takes into account certificates in the credentials structure.
+    If certificates are provided in a callback, these must be checked by
+    the provider. For that we assume that the credentials structure is
+    filled when associated with a session; if not then the fallback mechanism
+    will not work and the handshake will fail.
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
+
+Author: Nikos Mavrogiannopoulos <nmav@redhat.com>
+Date:   Sat Feb 2 07:10:10 2019 +0100
+
+    Enforce the certificate key usage restrictions on all cases
+    
+    That is, we require a signing certificate when negotiating
+    TLS1.3, or when sending a client certificate (on all cases).
+    
+    Before we would not perform any checks under TLS1.3 or when client
+    certificates are sent, assuming that the certificates used will always
+    be signing ones. However if the user sets up incorrectly a decryption
+    certificate we would use it for signing. This fix makes sure that an
+    error is returned early when these scenarios are detected.
+    
+    Resolves: #690
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Mon Jan 21 12:54:58 2019 +0100
+
+    Fetch OSS-Fuzz corpora much faster [skip ci]
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: Nikos Mavrogiannopoulos <nmav@redhat.com>
+Date:   Mon Feb 4 15:10:19 2019 +0100
+
+    .triage-policies.yml: added [ci skip]
+    
+    This adds a set of policies regarding issues and merge requests
+    to be enforced by the gitlab-triage bot. That is:
+     - Issues without any label for more than a month are marked
+       with needs attention label
+     - Issues with needinfo label are closed if they are not updated
+       within a month
+     - Merge requests marked as WIP with no update within 5 months
+       are closed.
+    
+    These rules are not enforced automatically; we have to schedule
+    a run of the gitlab-triage bot.
+    
+    Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
+
+Author: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
+Date:   Sat Feb 2 17:47:48 2019 +0300
+
+    build: do not generate mech-list.h if p11-kit is not available
+    
+    Compiling GnuTLS with no p11-kit installed will result in a serie of
+    warnings during build time because mech-list.h will be generated even if
+    pkcs11 tool compilation is disabled. Move mech-list.h generation to
+    happen only if pkcs11 is enabled, thus removing these warnings.
+    
+    Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
+
+Author: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
+Date:   Sat Feb 2 17:32:01 2019 +0300
+
+    build: pass NETTLE_LIBS together with HOGWEED_LIBS
+    
+    libhogweed might depend on exact non-system-wide nettle, so let's pass
+    NETTLE_LIBS flags together when using HOGWEED_LIBS.
+    
+    Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Sat Jan 26 21:44:28 2019 +0100
+
+    Add GNUTLS_E_RECEIVED_DISALLOWED_NAME for illegal SNI names
+    
+    An illegal/disallowed SNI server name previously generated
+    the misleading message "An illegal parameter has been received.".
+    
+    This commit changes it to
+      "A disallowed SNI server name has been received.".
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
+Date:   Wed Jan 30 21:58:34 2019 +0300
+
+    lib/nettle: replace nettle-stdint.h with just stdint.h
+    
+    Nettle library is going to drop nettle-stdint.h. Replace this include
+    with with just <stdint.h>.
+    
+    Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Mon Jan 28 15:25:30 2019 +0100
+
+    Fix 'make glimport' and update CONTRIBUTING.md
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: Alon Bar-Lev <alon.barlev@gmail.com>
+Date:   Sun Jan 27 13:59:56 2019 +0200
+
+    .gitignore: add test files
+    
+    Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
+
+Author: Alon Bar-Lev <alon.barlev@gmail.com>
+Date:   Sun Jan 27 13:17:35 2019 +0200
+
+    build: detect previous supported guile
+    
+    A recent change in the m4 macro of guile enforces latest guile:
+    ---
+    AC_DEFUN([GUILE_PROGS],
+     [_guile_required_version="m4_default([$1], [$GUILE_EFFECTIVE_VERSION])"
+      if test -z "$_guile_required_version"; then
+        _guile_required_version=2.2
+      fi
+    ---
+    
+    The result:
+    ---
+    checking for guile-snarf... /usr/bin/guile-snarf
+    checking for guild... /usr/bin/guild
+    checking for guile-2.2... no
+    checking for guile2.2... no
+    checking for guile-2... no
+    checking for guile2... no
+    checking for guile... /usr/bin/guile
+    checking for Guile version >= 2.2... configure: error: Guile 2.2 required, but 2.0.14 found
+    ---
+    
+    Probably best to specify the supported version explicitly when calling
+    GUILE_PROGS, to keep existing behavior calling the GUILE_PKG detects the
+    existing packages.
+    
+    Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Fri Jan 25 11:51:56 2019 +0100
+
+    Fix unused var warning in guile/src/core.c
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: Tim Rühsen <tim.ruehsen@gmx.de>
+Date:   Fri Jan 25 12:26:46 2019 +0100
+
+    Fix abi-check failure
+    
+    Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
+
+Author: Nikos Mavrogiannopoulos <nmav@gnutls.org>
 Date:   Fri Jan 25 08:32:17 2019 +0100
 
     NEWS: updated
diff -NurBbp gnutls28-3.6.6/config.h.in gnutls28-3.6.7/config.h.in
--- gnutls28-3.6.6/config.h.in	2019-01-25 08:27:05.000000000 +0100
+++ gnutls28-3.6.7/config.h.in	2019-03-27 07:21:23.000000000 +0100
@@ -882,9 +882,6 @@
 /* nettle is enabled */
 #undef HAVE_LIBNETTLE
 
-/* Define if you have the libnsl library. */
-#undef HAVE_LIBNSL
-
 /* Define if you have the libpthread library. */
 #undef HAVE_LIBPTHREAD
 
@@ -1043,9 +1040,6 @@
 /* Define to 1 if you have the <setjmp.h> header file. */
 #undef HAVE_SETJMP_H
 
-/* Define to 1 if you have the `setlocale' function. */
-#undef HAVE_SETLOCALE
-
 /* Define to 1 if you have the `shutdown' function. */
 #undef HAVE_SHUTDOWN
 
@@ -1468,9 +1462,6 @@
 /* Define this if optional arguments are disallowed */
 #undef NO_OPTIONAL_OPT_ARGS
 
-/* no ssize_t type was found */
-#undef NO_SSIZE_T
-
 /* Define to 1 if open() fails to recognize a trailing slash. */
 #undef OPEN_TRAILING_SLASH_BUG
 
diff -NurBbp gnutls28-3.6.6/configure.ac gnutls28-3.6.7/configure.ac
--- gnutls28-3.6.6/configure.ac	2019-01-25 08:26:15.000000000 +0100
+++ gnutls28-3.6.7/configure.ac	2019-04-04 19:26:47.316159006 +0200
@@ -23,7 +23,7 @@ dnl Process this file with autoconf to p
 AC_PREREQ(2.63)
 
 dnl when updating version also update LT_REVISION in m4/hooks.m4
-AC_INIT([GnuTLS], [3.6.6], [bugs@gnutls.org])
+AC_INIT([GnuTLS], [3.6.7], [bugs@gnutls.org])
 AC_CONFIG_AUX_DIR([build-aux])
 AC_CONFIG_MACRO_DIRS([m4 src/gl/m4 src/libopts/m4 lib/unistring/m4])
 AC_CANONICAL_HOST
@@ -301,7 +302,7 @@ AC_C_BIGENDIAN
 
 dnl No fork on MinGW, disable some self-tests until we fix them.
 dnl Check clock_gettime and pthread_mutex_lock in libc (avoid linking to other libs)
-AC_CHECK_FUNCS([fork setitimer inet_ntop inet_pton getrusage getpwuid_r nanosleep daemon getpid localtime mmap explicit_bzero],,)
+AC_CHECK_FUNCS([fork setitimer getrusage getpwuid_r nanosleep daemon getpid localtime mmap explicit_bzero],,)
 dnl Manually check some functions by including headers first. On macOS, you
 dnl normally only have the latest SDK available, containing all existing
 dnl functions, but having them restricted according to target version in
@@ -356,10 +357,6 @@ if test "$ac_cv_func_nanosleep" != "yes"
   gnutls_needs_librt=yes
 fi
 
-if test "$ac_cv_func_inet_pton" != "yes";then
-  AC_LIB_HAVE_LINKFLAGS(nsl,, [#include <arpa/inet.h>], [inet_pton(0,0,0);])
-fi
-
 if test "$ac_cv_func_clock_gettime" != "yes";then
   AC_LIB_HAVE_LINKFLAGS(rt,, [#include <time.h>], [clock_gettime (0, 0);])
   gnutls_needs_librt=yes
@@ -537,7 +534,7 @@ AC_ARG_ENABLE(non-suiteb-curves,
 
 if test "$enable_non_suiteb" = "yes";then
 	dnl nettle_secp_192r1 is not really a function
-	AC_CHECK_LIB(hogweed, nettle_secp_192r1, enable_non_suiteb=yes, enable_non_suiteb=no, [$HOGWEED_LIBS])
+	AC_CHECK_LIB(hogweed, nettle_secp_192r1, enable_non_suiteb=yes, enable_non_suiteb=no, [$HOGWEED_LIBS $NETTLE_LIBS])
 
 	if test "$enable_non_suiteb" = "yes";then
 		AC_DEFINE([ENABLE_NON_SUITEB_CURVES], 1, [Enable all curves])
@@ -547,7 +544,7 @@ AM_CONDITIONAL(ENABLE_NON_SUITEB_CURVES,
 
 # We MUST require a Nettle version that has rsa_sec_decrypt now.
 save_LIBS=$LIBS
-LIBS="$LIBS $HOGWEED_LIBS"
+LIBS="$LIBS $HOGWEED_LIBS $NETTLE_LIBS"
 AC_CHECK_FUNCS(nettle_rsa_sec_decrypt,
     [],
     [AC_MSG_ERROR([Nettle lacks the required rsa_sec_decrypt function])]
@@ -739,18 +736,6 @@ fi
 
 AM_CONDITIONAL(NEED_LIBOPTS, test "$included_libopts" = "yes")
 
-AC_CHECK_TYPE(ssize_t,
-  [
-    DEFINE_SSIZE_T="#include <sys/types.h>"
-    AC_SUBST(DEFINE_SSIZE_T)
-  ], [
-    AC_DEFINE([NO_SSIZE_T], 1, [no ssize_t type was found])
-    DEFINE_SSIZE_T="typedef int ssize_t;"
-    AC_SUBST(DEFINE_SSIZE_T)
-  ], [
-    #include <sys/types.h>
-  ])
-
 # For minitasn1.
 AC_CHECK_SIZEOF(unsigned long int, 4)
 AC_CHECK_SIZEOF(unsigned int, 4)
@@ -840,10 +825,6 @@ AC_ARG_ENABLE(guile,
 opt_guile_bindings=$enableval)
 AC_MSG_RESULT($opt_guile_bindings)
 
-AC_ARG_WITH([guile-site-dir],
-  [AS_HELP_STRING([--with-guile-site-dir],
-     [use the given directory as the Guile site (use with care)])])
-
 if test "$opt_guile_bindings" = "yes"; then
    AC_MSG_RESULT([***
 *** Detecting GNU Guile...
@@ -859,7 +840,9 @@ if test "$opt_guile_bindings" = "yes"; t
       AC_PATH_PROG([GUILD], [guild])
       AC_SUBST([GUILD])
 
+      GUILE_PKG
       GUILE_PROGS
+      GUILE_SITE_DIR
       GUILE_FLAGS
 
       save_CFLAGS="$CFLAGS"
@@ -878,24 +861,6 @@ if test "$opt_guile_bindings" = "yes"; t
 
       if test "$opt_guile_bindings" = "yes"; then
         AC_MSG_RESULT([yes])
-	case "x$with_guile_site_dir" in 
-	     xno)
-		# Use the default $(GUILE_SITE).
-		GUILE_SITE_DIR
-		;;
-	     x|xyes)
-		# Automatically derive $(GUILE_SITE) from $(pkgdatadir).  This
-		# hack is used to allow `distcheck' to work (see
-		# `DISTCHECK_CONFIGURE_FLAGS' in the top-level `Makefile.am').
-		GUILE_SITE="\$(datadir)/guile/site/$guile_effective_version"
-		AC_SUBST(GUILE_SITE)
-		;;
-	     *)
-		# Use the user-specified directory as $(GUILE_SITE).
-		GUILE_SITE="$with_guile_site_dir"
-		AC_SUBST(GUILE_SITE)
-		;;
-	esac
         AC_MSG_CHECKING([whether gcc supports -fgnu89-inline])
         _gcc_cflags_save="$CFLAGS"
         CFLAGS="${CFLAGS} -fgnu89-inline"
@@ -956,7 +921,6 @@ AC_CONFIG_FILES([
   doc/credentials/Makefile
   doc/credentials/srp/Makefile
   doc/credentials/x509/Makefile
-  doc/cyclo/Makefile
   doc/doxygen/Doxyfile
   doc/examples/Makefile
   doc/latex/Makefile
diff -NurBbp gnutls28-3.6.6/CONTRIBUTING.md gnutls28-3.6.7/CONTRIBUTING.md
--- gnutls28-3.6.6/CONTRIBUTING.md	2018-12-20 17:39:32.000000000 +0100
+++ gnutls28-3.6.7/CONTRIBUTING.md	2019-02-04 19:07:18.000000000 +0100
@@ -278,18 +278,16 @@ are always active.
 
 # Gnulib
 
-The files at `gl/`, `src/gl/` and `lib/unistring` directories are part of
-gnulib project and are included mainly for systems which may miss functionality
-available in glibc and unistring libraries. These files are updated when new
-functionality is needed or bug fixes affecting gnutls are required.
+The directories `gl/`, `src/gl/` and `lib/unistring` contain gnulib files
+copied/created by `./bootstrap`. Gnulib is a portability source code library
+to handle API or behavior incompatibilities between target systems.
 
-They can be updated by the following make rule.
+To take advantage of the latest gnulib files, we have to update the
+`gnulib/` submodule from time to time:
 ```
 $ make glimport
 ```
 
-That rule assumes that an updated gnulib is present at `../gnulib/`.
-
 Note that the gnulib library in `gl/` is used by the GnuTLS library
 and is kept separate from the gnulib used by the GnuTLS tools because
 of license issues, and also to prevent any gnulib networking modules
diff -NurBbp gnutls28-3.6.6/debian/changelog gnutls28-3.6.7/debian/changelog
--- gnutls28-3.6.6/debian/changelog	2019-01-26 17:57:52.000000000 +0100
+++ gnutls28-3.6.7/debian/changelog	2019-03-28 15:09:02.000000000 +0100
@@ -1,3 +1,34 @@
+gnutls28 (3.6.7-2) unstable; urgency=medium
+
+  * Upload to unstable.
+
+ -- Andreas Metzler <ametzler@debian.org>  Thu, 28 Mar 2019 15:09:02 +0100
+
+gnutls28 (3.6.7-1) experimental; urgency=medium
+
+  * New upstream version.
+    + Update AUTHOR list in copyright file.
+    + Update symbol file.
+    + Fixes issue preventing sending and receiving from different
+      threads when false start was enabled. Closes: #922879
+    + gnutls-cli: fix --benchmark-ciphers type overflow. Closes: #920477
+    + Fixes a memory corruption (double free) vulnerability in the
+      certificate verification API.
+      https://gitlab.com/gnutls/gnutls/issues/694 CVE-2019-3829
+      GNUTLS-SA-2019-03-27
+    + Fixes an invalid pointer access via malformed TLS1.3 async messages;
+      https://gitlab.com/gnutls/gnutls/issues/704 CVE-2019-3836
+      GNUTLS-SA-2019-03-27
+
+ -- Andreas Metzler <ametzler@debian.org>  Thu, 28 Mar 2019 07:44:36 +0100
+
+gnutls28 (3.6.6-3) unstable; urgency=low
+
+  * Add @ to autopkgtest's Depends.
+  * Use DH 11 compat.
+
+ -- Andreas Metzler <ametzler@debian.org>  Sat, 09 Mar 2019 13:44:49 +0100
+
 gnutls28 (3.6.6-2) unstable; urgency=low
 
   * Upload to unstable.
diff -NurBbp gnutls28-3.6.6/debian/compat gnutls28-3.6.7/debian/compat
--- gnutls28-3.6.6/debian/compat	2018-12-16 14:18:19.000000000 +0100
+++ gnutls28-3.6.7/debian/compat	1970-01-01 01:00:00.000000000 +0100
@@ -1 +0,0 @@
-10
diff -NurBbp gnutls28-3.6.6/debian/control gnutls28-3.6.7/debian/control
--- gnutls28-3.6.6/debian/control	2019-01-26 17:57:30.000000000 +0100
+++ gnutls28-3.6.7/debian/control	2019-03-27 19:21:14.000000000 +0100
@@ -13,7 +13,7 @@ Build-Depends:
  ca-certificates <!nocheck>,
  chrpath,
  datefudge <!nocheck>,
- debhelper (>= 10),
+ debhelper-compat (=11),
  freebsd-net-tools [kfreebsd-i386 kfreebsd-amd64] <!nocheck>,
  libcmocka-dev <!nocheck>,
  libgmp-dev (>= 2:6),
diff -NurBbp gnutls28-3.6.6/debian/copyright gnutls28-3.6.7/debian/copyright
--- gnutls28-3.6.6/debian/copyright	2019-01-26 17:57:30.000000000 +0100
+++ gnutls28-3.6.7/debian/copyright	2019-03-28 15:08:47.000000000 +0100
@@ -9,10 +9,13 @@ It was downloaded from https://www.gnupg
 
 Upstream Authors (from AUTHORS file):
 ------------------------------------
+
+The authors list is autogenerated from the git history; sorted by number of commits
+
 Nikos Mavrogiannopoulos <nmav at gnutls.org>
 Simon Josefsson <jas at josefsson.org>
-Dmitry Eremin-Solenikov <dbaryshkov at gmail.com>
 Tim Rühsen <tim.ruehsen at gmx.de>
+Dmitry Eremin-Solenikov <dbaryshkov at gmail.com>
 Daiki Ueno <ueno at gnu.org>
 Ludovic Courtès <ludo at gnu.org>
 Timo Schulz <twoaday at gnutls.org>
@@ -32,17 +35,18 @@ Alex Gaynor <alex.gaynor at gmail.com>
 Martin Ukrop <mukrop at redhat.com>
 Jaak Ristioja <jaak.ristioja at cyber.ee>
 Attila Molnar <attilamolnar at hush.com>
+Hugo Beauzée-Luyssen <hugo at beauzee.fr>
 Simo Sorce <simo at redhat.com>
 Martin Sucha <anty.sk+git at gmail.com>
 Stefan Berger <stefanb at linux.ibm.com>
 David Woodhouse <dwmw2 at infradead.org>
 Jan Vcelak <jan.vcelak at nic.cz>
 Kevin Cernekee <cernekee at gmail.com>
-Hugo Beauzée-Luyssen <hugo at beauzee.fr>
 Ander Juaristi <a at juaristi.eus>
 Stefan Sørensen <stefan.sorensen at spectralink.com>
 Adam Sampson <ats at offog.org>
 Alfredo Pironti <alfredo at pironti.eu>
+Anderson Toshiyuki Sasaki <ansasaki at redhat.com>
 Brad Hards <bradh at frogmouth.net>
 Michael Weiser <michael.weiser at gmx.de>
 Patrick Pelletier <code at funwithsoftware.org>
@@ -69,6 +73,7 @@ Hubert Kario <hkario at redhat.com>
 Ilya Tumaykin <itumaykin at gmail.com>
 James Bottomley <James.Bottomley at HansenPartnership.com>
 Karl Tarbe <karl.tarbe at cyber.ee>
+Ke Zhao <kzhao at redhat.com>
 Mark Brand <mabrand at mabrand.nl>
 Matthias-Christian Ott <ott at mirix.org>
 Maya Rashish <coypu at sdf.org>
@@ -84,6 +89,7 @@ Alexandre Bique <bique.alexandre at gmai
 Andreas Schneider <asn at samba.org>
 Andreas Schwab <schwab at suse.de>
 Avinash Sonawane <rootkea at gmail.com>
+Bas van Schaik <gitlab.com at s.traiectum.net>
 Bjørn Christensen <bhc at insight.dk>
 Carolin Latze <latze at angry-red-pla.net>
 Chen Hongzhi <hongzhi.chen at me.com>
@@ -121,6 +127,7 @@ Nils Maier <maierman at web.de>
 Olga <olyasib12 at gmail.com>
 Philippe Proulx <eeppeliteloop at gmail.com>
 Philippe Widmer <pw at earthwave.ch>
+R. Andrew Bailey <bailey at akamai.com>
 Raj Raman <rajramanca at gmail.com>
 Rical Jasan <ricaljasan at pacific.net>
 Rickard Bellgrim <rickard at opendnssec.org>
@@ -131,6 +138,7 @@ SUMIT AGGARWAL <aggarwal.s at samsung.co
 Saurav Babu <saurav.babu at samsung.com>
 Sebastian Dröge <sebastian at centricular.com>
 Simon Arlott <sa.me.uk>
+Steve Lhomme <robux4 at ycbcr.xyz>
 Thomas Klausner <wiz at NetBSD.org>
 Tobias Polzer <tobias.polzer at fau.de>
 Tomas Hoger <thoger at redhat.com>
diff -NurBbp gnutls28-3.6.6/debian/gnutls-bin.manpages gnutls28-3.6.7/debian/gnutls-bin.manpages
--- gnutls28-3.6.6/debian/gnutls-bin.manpages	2018-01-28 18:18:27.000000000 +0100
+++ gnutls28-3.6.7/debian/gnutls-bin.manpages	2019-03-27 19:21:14.000000000 +0100
@@ -1,2 +1 @@
 debian/tmp/usr/share/man/*/*.1
-debian/tmp/usr/share/man/*/*.8
diff -NurBbp gnutls28-3.6.6/debian/libgnutls30.symbols gnutls28-3.6.7/debian/libgnutls30.symbols
--- gnutls28-3.6.6/debian/libgnutls30.symbols	2019-01-26 17:57:30.000000000 +0100
+++ gnutls28-3.6.7/debian/libgnutls30.symbols	2019-03-28 15:08:47.000000000 +0100
@@ -8,16 +8,16 @@ libgnutls.so.30 libgnutls30 #MINVER#
  GNUTLS_3_6_5@GNUTLS_3_6_5 3.6.5
  GNUTLS_3_6_6@GNUTLS_3_6_6 3.6.6
  GNUTLS_FIPS140_3_4@GNUTLS_FIPS140_3_4 3.6.5
- (regex|optional)"@GNUTLS_PRIVATE_3_4$" 3.6.6-0+private+1
- _dsa_generate_dss_g@GNUTLS_FIPS140_3_4 3.6.6-0+private+1
- _dsa_generate_dss_pq@GNUTLS_FIPS140_3_4 3.6.6-0+private+1
- _dsa_validate_dss_g@GNUTLS_FIPS140_3_4 3.6.6-0+private+1
- _dsa_validate_dss_pq@GNUTLS_FIPS140_3_4 3.6.6-0+private+1
- _gnutls_decode_ber_rs_raw@GNUTLS_FIPS140_3_4 3.6.6-0+private+1
- _gnutls_encode_ber_rs_raw@GNUTLS_FIPS140_3_4 3.6.6-0+private+1
+ (regex|optional)"@GNUTLS_PRIVATE_3_4$" 3.6.7-0+private+1
+ _dsa_generate_dss_g@GNUTLS_FIPS140_3_4 3.6.7-0+private+1
+ _dsa_generate_dss_pq@GNUTLS_FIPS140_3_4 3.6.7-0+private+1
+ _dsa_validate_dss_g@GNUTLS_FIPS140_3_4 3.6.7-0+private+1
+ _dsa_validate_dss_pq@GNUTLS_FIPS140_3_4 3.6.7-0+private+1
+ _gnutls_decode_ber_rs_raw@GNUTLS_FIPS140_3_4 3.6.7-0+private+1
+ _gnutls_encode_ber_rs_raw@GNUTLS_FIPS140_3_4 3.6.7-0+private+1
  _gnutls_global_init_skip@GNUTLS_3_4 3.6.5
  _gnutls_prf_raw@GNUTLS_FIPS140_3_4 3.6.5
- _rsa_generate_fips186_4_keypair@GNUTLS_FIPS140_3_4 3.6.6-0+private+1
+ _rsa_generate_fips186_4_keypair@GNUTLS_FIPS140_3_4 3.6.7-0+private+1
  dsa_generate_dss_keypair@GNUTLS_FIPS140_3_4 3.6.5
  gnutls_aead_cipher_decrypt@GNUTLS_3_4 3.6.5
  gnutls_aead_cipher_deinit@GNUTLS_3_4 3.6.5
diff -NurBbp gnutls28-3.6.6/debian/tests/control gnutls28-3.6.7/debian/tests/control
--- gnutls28-3.6.6/debian/tests/control	2018-12-16 14:18:19.000000000 +0100
+++ gnutls28-3.6.7/debian/tests/control	2019-03-27 19:21:14.000000000 +0100
@@ -2,5 +2,5 @@ Tests: run-upstream-testsuite
 Depends: ca-certificates, datefudge,
  freebsd-net-tools [kfreebsd-i386 kfreebsd-amd64],
  net-tools [!kfreebsd-i386 !kfreebsd-amd64],
- openssl, softhsm2
+ openssl, softhsm2, @
 Restrictions: rw-build-tree, allow-stderr
diff -NurBbp gnutls28-3.6.6/doc/alerts.texi gnutls28-3.6.7/doc/alerts.texi
--- gnutls28-3.6.6/doc/alerts.texi	2019-01-24 20:25:00.000000000 +0100
+++ gnutls28-3.6.7/doc/alerts.texi	2019-03-27 07:34:14.000000000 +0100
@@ -91,6 +91,9 @@
 @item GNUTLS_@-A_@-UNKNOWN_@-PSK_@-IDENTITY
 @tab 115
 @tab The SRP/PSK username is missing or not known
+@item GNUTLS_@-A_@-CERTIFICATE_@-REQUIRED
+@tab 116
+@tab Certificate is required
 @item GNUTLS_@-A_@-NO_@-APPLICATION_@-PROTOCOL
 @tab 120
 @tab No supported application protocol could be negotiated
diff -NurBbp gnutls28-3.6.6/doc/algorithms.texi gnutls28-3.6.7/doc/algorithms.texi
--- gnutls28-3.6.6/doc/algorithms.texi	2018-11-30 08:22:54.000000000 +0100
+++ gnutls28-3.6.7/doc/algorithms.texi	2019-03-27 07:24:26.000000000 +0100
@@ -568,6 +568,7 @@
 @heading Certificate types
 @table @code
 @item X.509
+@item Raw Public Key
 @end table
 
 @heading Protocols
diff -NurBbp gnutls28-3.6.6/doc/cha-gtls-app.texi gnutls28-3.6.7/doc/cha-gtls-app.texi
--- gnutls28-3.6.6/doc/cha-gtls-app.texi	2019-01-25 08:24:54.000000000 +0100
+++ gnutls28-3.6.7/doc/cha-gtls-app.texi	2019-04-04 19:26:47.564151611 +0200
@@ -234,11 +234,21 @@ Read-only access to objects, for example
 is also thread-safe. 
 
 A @code{gnutls_session_t} object could also be shared by two threads, one sending,
-the other receiving. In that case however, care must be taken during key
-updates and re-handshakes to be handled only by a single thread. The termination of a session 
-should be handled, either by a single thread being active, or by the sender thread 
-using @funcref{gnutls_bye} with @code{GNUTLS_SHUT_WR} and the receiving thread 
-waiting for a return value of zero.
+the other receiving. However, care must be taken on the following use cases:
+@itemize
+@item The re-handshake process in TLS 1.2 or earlier must be handled only in
+a single thread and no other thread may be performing any operation.
+@item The flag @code{GNUTLS_AUTO_REAUTH} cannot be used safely in this mode of operation.
+@item Any other operation which may send or receive data, like key update (c.f.,
+@funcref{gnutls_session_key_update}), must not be performed while threads
+are receiving or writing.
+@item The termination of a session should be handled, either by a single thread being
+active, or by the sender thread using @funcref{gnutls_bye} with @code{GNUTLS_SHUT_WR}
+and the receiving thread waiting for a return value of zero (or timeout on
+certain servers which do not respond).
+@item The functions @funcref{gnutls_transport_set_errno} and @funcref{gnutls_record_get_direction}
+should not be relied during parallel operation.
+@end itemize
 
 For several aspects of the library (e.g., the random generator, PKCS#11
 operations), the library may utilize mutex locks (e.g., pthreads on GNU/Linux and CriticalSection on Windows)
@@ -1908,8 +1918,8 @@ is set using @funcref{gnutls_db_set_cach
 the ticket key rotation period. Currently, the session key rotation interval is set
 to 3 times the expiration time set by this function.
 
-Under TLS 1.3, the server can send a new session ticket at any time
-using @funcref{gnutls_session_ticket_send}.
+Under TLS 1.3, the server sends by default 2 tickets, and can send
+additional session tickets at any time using @funcref{gnutls_session_ticket_send}.
 
 @showfuncdesc{gnutls_session_ticket_send}
 
diff -NurBbp gnutls28-3.6.6/doc/crypto-api.texi gnutls28-3.6.7/doc/crypto-api.texi
--- gnutls28-3.6.6/doc/crypto-api.texi	2019-01-11 07:36:51.000000000 +0100
+++ gnutls28-3.6.7/doc/crypto-api.texi	2019-03-27 07:34:57.000000000 +0100
@@ -8,13 +8,13 @@
 
 @var{nonce_len}: The length of the nonce
 
-@var{auth}: the data to be authenticated
+@var{auth}: additional data to be authenticated
 
 @var{auth_len}: The length of the data
 
 @var{tag_size}: The size of the tag to use (use zero for the default)
 
-@var{ctext}: the data to decrypt
+@var{ctext}: the data to decrypt (including the authentication tag)
 
 @var{ctext_len}: the length of data to decrypt (includes tag size)
 
@@ -23,11 +23,13 @@
 @var{ptext_len}: the length of decrypted data (initially must hold the maximum available size)
 
 This function will decrypt the given data using the algorithm
-specified by the context. This function must be provided the whole
-data to be decrypted, including the tag, and will fail if the tag
-verification fails.
+specified by the context. This function must be provided the complete
+data to be decrypted, including the authentication tag. On several
+AEAD ciphers, the authentication tag is appended to the ciphertext,
+though this is not a general rule. This function will fail if
+the tag verification fails.
 
-@strong{Returns:} Zero or a negative error code on error.
+@strong{Returns:} Zero or a negative error code on verification failure or other error.
 
 @strong{Since:} 3.4.0
 @end deftypefun
@@ -52,7 +54,7 @@ authenticated-encryption context.
 
 @var{nonce_len}: The length of the nonce
 
-@var{auth}: the data to be authenticated
+@var{auth}: additional data to be authenticated
 
 @var{auth_len}: The length of the data
 
@@ -62,7 +64,7 @@ authenticated-encryption context.
 
 @var{ptext_len}: The length of data to encrypt
 
-@var{ctext}: the encrypted data
+@var{ctext}: the encrypted data including authentication tag
 
 @var{ctext_len}: the length of encrypted data (initially must hold the maximum available size, including space for tag)
 
@@ -84,7 +86,7 @@ authentication tag.
 
 @var{nonce_len}: The length of the nonce
 
-@var{auth_iov}: the data to be authenticated
+@var{auth_iov}: additional data to be authenticated
 
 @var{auth_iovcnt}: The number of buffers in  @code{auth_iov} 
 
@@ -94,7 +96,7 @@ authentication tag.
 
 @var{iovcnt}: The number of buffers in  @code{iov} 
 
-@var{ctext}: the encrypted data
+@var{ctext}: the encrypted data including authentication tag
 
 @var{ctext_len}: the length of encrypted data (initially must hold the maximum available size, including space for tag)
 
@@ -258,7 +260,9 @@ data length will equal the plaintext siz
 @deftypefun {unsigned} {gnutls_cipher_get_iv_size} (gnutls_cipher_algorithm_t @var{algorithm})
 @var{algorithm}: is an encryption algorithm
 
-Get block size for encryption algorithm.
+This function returns the size of the initialization vector (IV) for the
+provided algorithm. For algorithms with variable size IV (e.g., AES-CCM),
+the returned size will be the one used by TLS.
 
 @strong{Returns:} block size for encryption algorithm.
 
diff -NurBbp gnutls28-3.6.6/doc/cyclo/Makefile.am gnutls28-3.6.7/doc/cyclo/Makefile.am
--- gnutls28-3.6.6/doc/cyclo/Makefile.am	2012-12-03 20:36:48.000000000 +0100
+++ gnutls28-3.6.7/doc/cyclo/Makefile.am	1970-01-01 01:00:00.000000000 +0100
@@ -1,37 +0,0 @@
-## Process this file with automake to produce Makefile.in
-# Copyright (C) 2008-2012 Free Software Foundation, Inc.
-#
-# Author: Simon Josefsson
-#
-# This file is part of GnuTLS.
-#
-# This file is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# This file is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this file; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-
-EXTRA_DIST = cyclo-gnutls.html
-
-vcurl = "http://git.savannah.gnu.org/gitweb/?p=gnutls.git;a=blob;f=lib/%FILENAME%;hb=HEAD"
-
-cyclo-gnutls.html:
-	(cd ${top_srcdir}/lib && \
-		$(PMCCABE) `find . -type f -name \*.[ch] \
-				| grep -v /minitasn1/ | sed 's,^./,,'` \
-		| sort -nr \
-		| LANG=C $(AWK) -f ${abs_top_srcdir}/build-aux/pmccabe2html \
-			-v lang=html -v name="$(PACKAGE_STRING)" \
-			-v vcurl=$(vcurl) \
-			-v url="http://www.gnu.org/software/gnutls/" \
-			-v css=${abs_top_srcdir}/build-aux/pmccabe.css) \
-			> tmp
-	mv tmp $@
diff -NurBbp gnutls28-3.6.6/doc/enums.texi gnutls28-3.6.7/doc/enums.texi
--- gnutls28-3.6.6/doc/enums.texi	2019-01-05 12:34:17.000000000 +0100
+++ gnutls28-3.6.7/doc/enums.texi	2019-03-27 07:24:26.000000000 +0100
@@ -392,6 +392,8 @@ recognized.
 @item GNUTLS_@-A_@-UNKNOWN_@-PSK_@-IDENTITY
 The SRP/PSK username is missing
 or not known.
+@item GNUTLS_@-A_@-CERTIFICATE_@-REQUIRED
+Certificate is required.
 @item GNUTLS_@-A_@-NO_@-APPLICATION_@-PROTOCOL
 The ALPN protocol requested is
 not supported by the peer.
@@ -1347,7 +1349,8 @@ The token's manufacturer (string)
 @item GNUTLS_@-PKCS11_@-TOKEN_@-MODEL
 The token's model (string)
 @item GNUTLS_@-PKCS11_@-TOKEN_@-MODNAME
-The token's module name (string - since 3.4.3)
+The token's module name (string - since 3.4.3). This value is
+unavailable for providers which were manually loaded.
 @end table
 
 @c gnutls_pkcs11_obj_type_t
diff -NurBbp gnutls28-3.6.6/doc/error_codes.texi gnutls28-3.6.7/doc/error_codes.texi
--- gnutls28-3.6.6/doc/error_codes.texi	2018-12-21 07:59:43.000000000 +0100
+++ gnutls28-3.6.7/doc/error_codes.texi	2019-03-27 07:24:26.000000000 +0100
@@ -67,6 +67,7 @@
 @item -79 @tab GNUTLS_@-E_@-OPENPGP_@-UID_@-REVOKED @tab The OpenPGP User ID is revoked.
 @item -80 @tab GNUTLS_@-E_@-UNKNOWN_@-PK_@-ALGORITHM @tab An unknown public key algorithm was encountered.
 @item -81 @tab GNUTLS_@-E_@-TOO_@-MANY_@-HANDSHAKE_@-PACKETS @tab Too many handshake packets have been received.
+@item -82 @tab GNUTLS_@-E_@-RECEIVED_@-DISALLOWED_@-NAME @tab A disallowed SNI server name has been received.
 @item -84 @tab GNUTLS_@-E_@-NO_@-TEMPORARY_@-RSA_@-PARAMS @tab No temporary RSA parameters were found.
 @item -86 @tab GNUTLS_@-E_@-NO_@-COMPRESSION_@-ALGORITHMS @tab No supported compression algorithms have been found.
 @item -87 @tab GNUTLS_@-E_@-NO_@-CIPHER_@-SUITES @tab No supported cipher suites have been found.
@@ -91,6 +92,7 @@
 @item -109 @tab GNUTLS_@-E_@-UNKNOWN_@-SRP_@-USERNAME @tab The username supplied is unknown.
 @item -110 @tab GNUTLS_@-E_@-PREMATURE_@-TERMINATION @tab The TLS connection was non-properly terminated.
 @item -111 @tab GNUTLS_@-E_@-MALFORMED_@-CIDR @tab CIDR name constraint is malformed in size or structure.
+@item -112 @tab GNUTLS_@-E_@-CERTIFICATE_@-REQUIRED @tab Certificate is required.
 @item -201 @tab GNUTLS_@-E_@-BASE64_@-ENCODING_@-ERROR @tab Base64 encoding error.
 @item -202 @tab GNUTLS_@-E_@-INCOMPATIBLE_@-GCRYPT_@-LIBRARY @tab The crypto library version is too old.
 @item -203 @tab GNUTLS_@-E_@-INCOMPATIBLE_@-LIBTASN1_@-LIBRARY @tab The tasn1 library version is too old.
diff -NurBbp gnutls28-3.6.6/doc/gnutls-api.texi gnutls28-3.6.7/doc/gnutls-api.texi
--- gnutls28-3.6.6/doc/gnutls-api.texi	2019-01-11 07:37:37.000000000 +0100
+++ gnutls28-3.6.7/doc/gnutls-api.texi	2019-03-27 07:35:33.000000000 +0100
@@ -64,7 +64,7 @@ an error code is returned.
 @deftypefun {int} {gnutls_alert_send_appropriate} (gnutls_session_t @var{session}, int @var{err})
 @var{session}: is a @code{gnutls_session_t}  type.
 
-@var{err}: is an integer
+@var{err}: is an error code returned by another GnuTLS function
 
 Sends an alert to the peer depending on the error code returned by
 a gnutls function. This function will call @code{gnutls_error_to_alert()} 
@@ -73,8 +73,11 @@ to determine the appropriate alert to se
 This function may also return @code{GNUTLS_E_AGAIN} , or
 @code{GNUTLS_E_INTERRUPTED} .
 
-If the return value is @code{GNUTLS_E_INVALID_REQUEST} , then no alert has
-been sent to the peer.
+This function historically was always sending an alert to the
+peer, even if  @code{err} was inappropriate to respond with an alert
+(e.g., @code{GNUTLS_E_SUCCESS} ). Since 3.6.6 this function returns
+success without transmitting any data on error codes that
+should not result to an alert.
 
 @strong{Returns:} On success, @code{GNUTLS_E_SUCCESS}  (0) is returned, otherwise
 an error code is returned.
@@ -529,10 +532,9 @@ clients.
 @deftypefun {void} {gnutls_certificate_free_cas} (gnutls_certificate_credentials_t @var{sc})
 @var{sc}: is a @code{gnutls_certificate_credentials_t}  type.
 
-This function will delete all the CAs associated with the given
-credentials. Servers that do not use
-@code{gnutls_certificate_verify_peers2()}  may call this to save some
-memory.
+This function was operational on very early versions of gnutls.
+Due to internal refactorings and the fact that this was hardly ever
+used, it is currently a no-op.
 @end deftypefun
 
 @subheading gnutls_certificate_free_credentials
@@ -2018,7 +2020,7 @@ the specified cipher, or @code{GNUTLS_CI
 @deftypefun {size_t} {gnutls_cipher_get_key_size} (gnutls_cipher_algorithm_t @var{algorithm})
 @var{algorithm}: is an encryption algorithm
 
-Get key size for cipher.
+This function returns the key size of the provided algorithm.
 
 @strong{Returns:} length (in bytes) of the given cipher's key size, or 0 if
 the given cipher is invalid.
@@ -2788,7 +2790,7 @@ where a warning alert should be sent to
 renegotiation will be performed.
 
 If there is no mapping to a valid alert the alert to indicate
-internal error is returned.
+internal error (@code{GNUTLS_A_INTERNAL_ERROR} ) is returned.
 
 @strong{Returns:} the alert code to use for a particular error code.
 @end deftypefun
@@ -5243,7 +5245,7 @@ applications may call @code{select()}  o
 interrupted GnuTLS function.
 
 This function's output is unreliable if you are using the same
- @code{session} in different threads, for sending and receiving.
+ @code{session} in different threads for sending and receiving.
 
 @strong{Returns:} 0 if interrupted while trying to read data, or 1 while trying to write data.
 @end deftypefun
@@ -5566,8 +5568,7 @@ otherwise a negative error code is retur
 @var{size}: is the new size
 
 This function sets the maximum record packet size in this
-connection.  This property can only be set to clients.  The server
-may choose not to accept the requested size.
+connection.
 
 The requested record size does get in effect immediately only while
 sending data. The receive part will take effect after a successful
@@ -5581,6 +5582,9 @@ doesn't have the limitation, as long as
 512 and 16384.  Note that not all TLS implementations use or even
 understand those extension.
 
+In TLS 1.3, the value is the length of plaintext content plus its
+padding, excluding content type octet.
+
 @strong{Returns:} On success, @code{GNUTLS_E_SUCCESS}  (0) is returned,
 otherwise a negative error code is returned.
 @end deftypefun
@@ -5968,8 +5972,10 @@ Under TLS1.3 session resumption is possi
 is received by the client. To ensure that such a ticket has been received use
 @code{gnutls_session_get_flags()}  and check for flag @code{GNUTLS_SFLAGS_SESSION_TICKET} ;
 if this flag is not set, this function will wait for a new ticket within
-50ms, and if not received will return dummy data which cannot lead to
-resumption. To get notified when new tickets are received by the server
+an estimated rountrip, and if not received will return dummy data which
+cannot lead to resumption.
+
+To get notified when new tickets are received by the server
 use @code{gnutls_handshake_set_hook_function()}  to wait for @code{GNUTLS_HANDSHAKE_NEW_SESSION_TICKET} 
 messages. Each call of @code{gnutls_session_get_data2()}  after a ticket is
 received, will return session resumption data corresponding to the last
@@ -6442,7 +6448,7 @@ error code.
 
 Sends a fresh session ticket to the peer. This is relevant only
 in server side under TLS1.3. This function may also return @code{GNUTLS_E_AGAIN} 
-or @code{GNUTLS_E_INTERRUPTED} .
+or @code{GNUTLS_E_INTERRUPTED}  and in that case it must be called again.
 
 @strong{Returns:} @code{GNUTLS_E_SUCCESS}  on success, or a negative error code.
 @end deftypefun
@@ -7457,6 +7463,9 @@ This function is useful in replacement p
 @code{gnutls_transport_set_pull_function()}  under Windows, where the
 replacements may not have access to the same  @code{errno} variable that is used by GnuTLS (e.g., the application is linked to
 msvcr71.dll and gnutls is linked to msvcrt.dll).
+
+This function is unreliable if you are using the same
+ @code{session} in different threads for sending and receiving.
 @end deftypefun
 
 @subheading gnutls_transport_set_errno_function
Binärdateien gnutls28-3.6.6/doc/gnutls-guile.pdf und gnutls28-3.6.7/doc/gnutls-guile.pdf sind verschieden.
Binärdateien gnutls28-3.6.6/doc/gnutls.info-7 und gnutls28-3.6.7/doc/gnutls.info-7 sind verschieden.
Binärdateien gnutls28-3.6.6/doc/gnutls.pdf und gnutls28-3.6.7/doc/gnutls.pdf sind verschieden.
diff -NurBbp gnutls28-3.6.6/doc/Makefile.am gnutls28-3.6.7/doc/Makefile.am
--- gnutls28-3.6.6/doc/Makefile.am	2018-12-15 22:10:46.000000000 +0100
+++ gnutls28-3.6.7/doc/Makefile.am	2019-03-10 13:43:16.000000000 +0100
@@ -32,7 +32,7 @@ IMAGES = \
 	gnutls-logo.png gnutls-x509.png	\
 	pkcs11-vision.png
 
-SUBDIRS = examples cyclo scripts credentials latex
+SUBDIRS = examples scripts credentials latex
 if ENABLE_GTK_DOC
 SUBDIRS += reference
 endif
diff -NurBbp gnutls28-3.6.6/doc/stamp-1 gnutls28-3.6.7/doc/stamp-1
--- gnutls28-3.6.6/doc/stamp-1	2019-01-25 08:27:14.000000000 +0100
+++ gnutls28-3.6.7/doc/stamp-1	2019-03-27 07:24:25.000000000 +0100
@@ -1,4 +1,4 @@
-@set UPDATED 6 March 2017
-@set UPDATED-MONTH March 2017
-@set EDITION 3.6.6
-@set VERSION 3.6.6
+@set UPDATED 15 March 2019
+@set UPDATED-MONTH March 2019
+@set EDITION 3.6.7
+@set VERSION 3.6.7
diff -NurBbp gnutls28-3.6.6/doc/version-guile.texi gnutls28-3.6.7/doc/version-guile.texi
--- gnutls28-3.6.6/doc/version-guile.texi	2019-01-25 08:22:59.000000000 +0100
+++ gnutls28-3.6.7/doc/version-guile.texi	2019-03-27 07:24:25.000000000 +0100
@@ -1,4 +1,4 @@
-@set UPDATED 6 March 2017
-@set UPDATED-MONTH March 2017
-@set EDITION 3.6.6
-@set VERSION 3.6.6
+@set UPDATED 15 March 2019
+@set UPDATED-MONTH March 2019
+@set EDITION 3.6.7
+@set VERSION 3.6.7
diff -NurBbp gnutls28-3.6.6/doc/x509-api.texi gnutls28-3.6.7/doc/x509-api.texi
--- gnutls28-3.6.6/doc/x509-api.texi	2019-01-11 07:37:34.000000000 +0100
+++ gnutls28-3.6.7/doc/x509-api.texi	2019-03-27 07:35:30.000000000 +0100
@@ -4922,28 +4922,6 @@ negative error value.
 @strong{Since:} 3.6.0
 @end deftypefun
 
-@subheading gnutls_x509_crt_set_subject_alternative_name
-@anchor{gnutls_x509_crt_set_subject_alternative_name}
-@deftypefun {int} {gnutls_x509_crt_set_subject_alternative_name} (gnutls_x509_crt_t @var{crt}, gnutls_x509_subject_alt_name_t           @var{type}, const char * @var{data_string})
-@var{crt}: a certificate of type @code{gnutls_x509_crt_t} 
-
-@var{type}: is one of the gnutls_x509_subject_alt_name_t enumerations
-
-@var{data_string}: The data to be set, a (0) terminated string
-
-This function will set the subject alternative name certificate
-extension. This function assumes that data can be expressed as a null
-terminated string.
-
-The name of the function is unfortunate since it is inconsistent with
-@code{gnutls_x509_crt_get_subject_alt_name()} .
-
-See @code{gnutls_x509_crt_set_subject_alt_name()}  for more information.
-
-@strong{Returns:} On success, @code{GNUTLS_E_SUCCESS}  (0) is returned, otherwise a
-negative error value.
-@end deftypefun
-
 @subheading gnutls_x509_crt_set_subject_alt_name
 @anchor{gnutls_x509_crt_set_subject_alt_name}
 @deftypefun {int} {gnutls_x509_crt_set_subject_alt_name} (gnutls_x509_crt_t @var{crt}, gnutls_x509_subject_alt_name_t @var{type}, const void * @var{data}, unsigned int @var{data_size}, unsigned int @var{flags})
@@ -4998,6 +4976,28 @@ negative error value.
 @strong{Since:} 3.5.0
 @end deftypefun
 
+@subheading gnutls_x509_crt_set_subject_alternative_name
+@anchor{gnutls_x509_crt_set_subject_alternative_name}
+@deftypefun {int} {gnutls_x509_crt_set_subject_alternative_name} (gnutls_x509_crt_t @var{crt}, gnutls_x509_subject_alt_name_t           @var{type}, const char * @var{data_string})
+@var{crt}: a certificate of type @code{gnutls_x509_crt_t} 
+
+@var{type}: is one of the gnutls_x509_subject_alt_name_t enumerations
+
+@var{data_string}: The data to be set, a (0) terminated string
+
+This function will set the subject alternative name certificate
+extension. This function assumes that data can be expressed as a null
+terminated string.
+
+The name of the function is unfortunate since it is inconsistent with
+@code{gnutls_x509_crt_get_subject_alt_name()} .
+
+See @code{gnutls_x509_crt_set_subject_alt_name()}  for more information.
+
+@strong{Returns:} On success, @code{GNUTLS_E_SUCCESS}  (0) is returned, otherwise a
+negative error value.
+@end deftypefun
+
 @subheading gnutls_x509_crt_set_subject_key_id
 @anchor{gnutls_x509_crt_set_subject_key_id}
 @deftypefun {int} {gnutls_x509_crt_set_subject_key_id} (gnutls_x509_crt_t @var{cert}, const void * @var{id}, size_t @var{id_size})
diff -NurBbp gnutls28-3.6.6/fuzz/gnutls_x509_verify_fuzzer.c gnutls28-3.6.7/fuzz/gnutls_x509_verify_fuzzer.c
--- gnutls28-3.6.6/fuzz/gnutls_x509_verify_fuzzer.c	1970-01-01 01:00:00.000000000 +0100
+++ gnutls28-3.6.7/fuzz/gnutls_x509_verify_fuzzer.c	2019-03-27 07:20:12.000000000 +0100
@@ -0,0 +1,201 @@
+/*
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ * Author: Nikos Mavrogiannopoulos
+ *
+ * This file is part of GnuTLS.
+ *
+ * The GnuTLS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>
+ *
+ */
+
+#include <assert.h>
+#include <stdint.h>
+
+#include <gnutls/gnutls.h>
+#include <gnutls/x509.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "fuzzer.h"
+
+unsigned char _ca_der[] = {
+  0x30, 0x82, 0x05, 0xe2, 0x30, 0x82, 0x04, 0xca, 0xa0, 0x03, 0x02, 0x01,
+  0x02, 0x02, 0x10, 0x27, 0x53, 0xf8, 0x06, 0xfe, 0x91, 0x37, 0x32, 0x2f,
+  0x5b, 0x40, 0x9f, 0x1c, 0x31, 0x87, 0x5c, 0x30, 0x0d, 0x06, 0x09, 0x2a,
+  0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x81,
+  0xca, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
+  0x55, 0x53, 0x31, 0x17, 0x30, 0x15, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13,
+  0x0e, 0x56, 0x65, 0x72, 0x69, 0x53, 0x69, 0x67, 0x6e, 0x2c, 0x20, 0x49,
+  0x6e, 0x63, 0x2e, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x0b,
+  0x13, 0x16, 0x56, 0x65, 0x72, 0x69, 0x53, 0x69, 0x67, 0x6e, 0x20, 0x54,
+  0x72, 0x75, 0x73, 0x74, 0x20, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b,
+  0x31, 0x3a, 0x30, 0x38, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x31, 0x28,
+  0x63, 0x29, 0x20, 0x32, 0x30, 0x30, 0x36, 0x20, 0x56, 0x65, 0x72, 0x69,
+  0x53, 0x69, 0x67, 0x6e, 0x2c, 0x20, 0x49, 0x6e, 0x63, 0x2e, 0x20, 0x2d,
+  0x20, 0x46, 0x6f, 0x72, 0x20, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69,
+  0x7a, 0x65, 0x64, 0x20, 0x75, 0x73, 0x65, 0x20, 0x6f, 0x6e, 0x6c, 0x79,
+  0x31, 0x45, 0x30, 0x43, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x3c, 0x56,
+  0x65, 0x72, 0x69, 0x53, 0x69, 0x67, 0x6e, 0x20, 0x43, 0x6c, 0x61, 0x73,
+  0x73, 0x20, 0x33, 0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, 0x50,
+  0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x20, 0x43, 0x65, 0x72, 0x74, 0x69,
+  0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x41, 0x75, 0x74,
+  0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x20, 0x2d, 0x20, 0x47, 0x35, 0x30,
+  0x1e, 0x17, 0x0d, 0x31, 0x30, 0x30, 0x32, 0x30, 0x38, 0x30, 0x30, 0x30,
+  0x30, 0x30, 0x30, 0x5a, 0x17, 0x0d, 0x32, 0x30, 0x30, 0x32, 0x30, 0x37,
+  0x32, 0x33, 0x35, 0x39, 0x35, 0x39, 0x5a, 0x30, 0x81, 0xb4, 0x31, 0x0b,
+  0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31,
+  0x17, 0x30, 0x15, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0e, 0x56, 0x65,
+  0x72, 0x69, 0x53, 0x69, 0x67, 0x6e, 0x2c, 0x20, 0x49, 0x6e, 0x63, 0x2e,
+  0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x16, 0x56,
+  0x65, 0x72, 0x69, 0x53, 0x69, 0x67, 0x6e, 0x20, 0x54, 0x72, 0x75, 0x73,
+  0x74, 0x20, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x31, 0x3b, 0x30,
+  0x39, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x32, 0x54, 0x65, 0x72, 0x6d,
+  0x73, 0x20, 0x6f, 0x66, 0x20, 0x75, 0x73, 0x65, 0x20, 0x61, 0x74, 0x20,
+  0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e,
+  0x76, 0x65, 0x72, 0x69, 0x73, 0x69, 0x67, 0x6e, 0x2e, 0x63, 0x6f, 0x6d,
+  0x2f, 0x72, 0x70, 0x61, 0x20, 0x28, 0x63, 0x29, 0x31, 0x30, 0x31, 0x2e,
+  0x30, 0x2c, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x25, 0x56, 0x65, 0x72,
+  0x69, 0x53, 0x69, 0x67, 0x6e, 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x20,
+  0x33, 0x20, 0x43, 0x6f, 0x64, 0x65, 0x20, 0x53, 0x69, 0x67, 0x6e, 0x69,
+  0x6e, 0x67, 0x20, 0x32, 0x30, 0x31, 0x30, 0x20, 0x43, 0x41, 0x30, 0x82,
+  0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
+  0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82,
+  0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xf5, 0x23, 0x4b, 0x5e, 0xa5,
+  0xd7, 0x8a, 0xbb, 0x32, 0xe9, 0xd4, 0x57, 0xf7, 0xef, 0xe4, 0xc7, 0x26,
+  0x7e, 0xad, 0x19, 0x98, 0xfe, 0xa8, 0x9d, 0x7d, 0x94, 0xf6, 0x36, 0x6b,
+  0x10, 0xd7, 0x75, 0x81, 0x30, 0x7f, 0x04, 0x68, 0x7f, 0xcb, 0x2b, 0x75,
+  0x1e, 0xcd, 0x1d, 0x08, 0x8c, 0xdf, 0x69, 0x94, 0xa7, 0x37, 0xa3, 0x9c,
+  0x7b, 0x80, 0xe0, 0x99, 0xe1, 0xee, 0x37, 0x4d, 0x5f, 0xce, 0x3b, 0x14,
+  0xee, 0x86, 0xd4, 0xd0, 0xf5, 0x27, 0x35, 0xbc, 0x25, 0x0b, 0x38, 0xa7,
+  0x8c, 0x63, 0x9d, 0x17, 0xa3, 0x08, 0xa5, 0xab, 0xb0, 0xfb, 0xcd, 0x6a,
+  0x62, 0x82, 0x4c, 0xd5, 0x21, 0xda, 0x1b, 0xd9, 0xf1, 0xe3, 0x84, 0x3b,
+  0x8a, 0x2a, 0x4f, 0x85, 0x5b, 0x90, 0x01, 0x4f, 0xc9, 0xa7, 0x76, 0x10,
+  0x7f, 0x27, 0x03, 0x7c, 0xbe, 0xae, 0x7e, 0x7d, 0xc1, 0xdd, 0xf9, 0x05,
+  0xbc, 0x1b, 0x48, 0x9c, 0x69, 0xe7, 0xc0, 0xa4, 0x3c, 0x3c, 0x41, 0x00,
+  0x3e, 0xdf, 0x96, 0xe5, 0xc5, 0xe4, 0x94, 0x71, 0xd6, 0x55, 0x01, 0xc7,
+  0x00, 0x26, 0x4a, 0x40, 0x3c, 0xb5, 0xa1, 0x26, 0xa9, 0x0c, 0xa7, 0x6d,
+  0x80, 0x8e, 0x90, 0x25, 0x7b, 0xcf, 0xbf, 0x3f, 0x1c, 0xeb, 0x2f, 0x96,
+  0xfa, 0xe5, 0x87, 0x77, 0xc6, 0xb5, 0x56, 0xb2, 0x7a, 0x3b, 0x54, 0x30,
+  0x53, 0x1b, 0xdf, 0x62, 0x34, 0xff, 0x1e, 0xd1, 0xf4, 0x5a, 0x93, 0x28,
+  0x85, 0xe5, 0x4c, 0x17, 0x4e, 0x7e, 0x5b, 0xfd, 0xa4, 0x93, 0x99, 0x7f,
+  0xdf, 0xcd, 0xef, 0xa4, 0x75, 0xef, 0xef, 0x15, 0xf6, 0x47, 0xe7, 0xf8,
+  0x19, 0x72, 0xd8, 0x2e, 0x34, 0x1a, 0xa6, 0xb4, 0xa7, 0x4c, 0x7e, 0xbd,
+  0xbb, 0x4f, 0x0c, 0x3d, 0x57, 0xf1, 0x30, 0xd6, 0xa6, 0x36, 0x8e, 0xd6,
+  0x80, 0x76, 0xd7, 0x19, 0x2e, 0xa5, 0xcd, 0x7e, 0x34, 0x2d, 0x89, 0x02,
+  0x03, 0x01, 0x00, 0x01, 0xa3, 0x82, 0x01, 0xd6, 0x30, 0x82, 0x01, 0xd2,
+  0x30, 0x12, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x08,
+  0x30, 0x06, 0x01, 0x01, 0xff, 0x02, 0x01, 0x00, 0x30, 0x70, 0x06, 0x03,
+  0x55, 0x1d, 0x20, 0x04, 0x69, 0x30, 0x67, 0x30, 0x65, 0x06, 0x0b, 0x60,
+  0x86, 0x48, 0x01, 0x86, 0xf8, 0x45, 0x01, 0x07, 0x17, 0x03, 0x30, 0x56,
+  0x30, 0x28, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x02, 0x01,
+  0x16, 0x1c, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x77, 0x77,
+  0x77, 0x2e, 0x76, 0x65, 0x72, 0x69, 0x73, 0x69, 0x67, 0x6e, 0x2e, 0x63,
+  0x6f, 0x6d, 0x2f, 0x63, 0x70, 0x73, 0x30, 0x2a, 0x06, 0x08, 0x2b, 0x06,
+  0x01, 0x05, 0x05, 0x07, 0x02, 0x02, 0x30, 0x1e, 0x1a, 0x1c, 0x68, 0x74,
+  0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x76, 0x65,
+  0x72, 0x69, 0x73, 0x69, 0x67, 0x6e, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x72,
+  0x70, 0x61, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff,
+  0x04, 0x04, 0x03, 0x02, 0x01, 0x06, 0x30, 0x6d, 0x06, 0x08, 0x2b, 0x06,
+  0x01, 0x05, 0x05, 0x07, 0x01, 0x0c, 0x04, 0x61, 0x30, 0x5f, 0xa1, 0x5d,
+  0xa0, 0x5b, 0x30, 0x59, 0x30, 0x57, 0x30, 0x55, 0x16, 0x09, 0x69, 0x6d,
+  0x61, 0x67, 0x65, 0x2f, 0x67, 0x69, 0x66, 0x30, 0x21, 0x30, 0x1f, 0x30,
+  0x07, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x04, 0x14, 0x8f, 0xe5,
+  0xd3, 0x1a, 0x86, 0xac, 0x8d, 0x8e, 0x6b, 0xc3, 0xcf, 0x80, 0x6a, 0xd4,
+  0x48, 0x18, 0x2c, 0x7b, 0x19, 0x2e, 0x30, 0x25, 0x16, 0x23, 0x68, 0x74,
+  0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x6c, 0x6f, 0x67, 0x6f, 0x2e, 0x76, 0x65,
+  0x72, 0x69, 0x73, 0x69, 0x67, 0x6e, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x76,
+  0x73, 0x6c, 0x6f, 0x67, 0x6f, 0x2e, 0x67, 0x69, 0x66, 0x30, 0x34, 0x06,
+  0x03, 0x55, 0x1d, 0x1f, 0x04, 0x2d, 0x30, 0x2b, 0x30, 0x29, 0xa0, 0x27,
+  0xa0, 0x25, 0x86, 0x23, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x63,
+  0x72, 0x6c, 0x2e, 0x76, 0x65, 0x72, 0x69, 0x73, 0x69, 0x67, 0x6e, 0x2e,
+  0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x63, 0x61, 0x33, 0x2d, 0x67, 0x35, 0x2e,
+  0x63, 0x72, 0x6c, 0x30, 0x28, 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x21,
+  0x30, 0x1f, 0xa4, 0x1d, 0x30, 0x1b, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03,
+  0x55, 0x04, 0x03, 0x13, 0x10, 0x56, 0x65, 0x72, 0x69, 0x53, 0x69, 0x67,
+  0x6e, 0x4d, 0x50, 0x4b, 0x49, 0x2d, 0x32, 0x2d, 0x38, 0x30, 0x1d, 0x06,
+  0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xcf, 0x99, 0xa9, 0xea,
+  0x7b, 0x26, 0xf4, 0x4b, 0xc9, 0x8e, 0x8f, 0xd7, 0xf0, 0x05, 0x26, 0xef,
+  0xe3, 0xd2, 0xa7, 0x9d, 0x30, 0x2b, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04,
+  0x24, 0x30, 0x22, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03,
+  0x02, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x03, 0x06,
+  0x0c, 0x2a, 0x86, 0x3a, 0x00, 0x01, 0x83, 0x8f, 0x89, 0x0d, 0x01, 0x01,
+  0x01, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16,
+  0x80, 0x14, 0x7f, 0xd3, 0x65, 0xa7, 0xc2, 0xdd, 0xec, 0xbb, 0xf0, 0x30,
+  0x09, 0xf3, 0x43, 0x39, 0xfa, 0x02, 0xaf, 0x33, 0x31, 0x33, 0x30, 0x0d,
+  0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05,
+  0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x5b, 0x8e, 0x9f, 0xd3, 0xba, 0xbe,
+  0xa9, 0xaf, 0x1a, 0x3e, 0x65, 0x81, 0xb7, 0xc1, 0x64, 0xf6, 0xa2, 0x78,
+  0xeb, 0x4c, 0x80, 0x06, 0x3a, 0xac, 0x22, 0x6e, 0x8c, 0x2b, 0xbc, 0x5d,
+  0x85, 0x7f, 0xc0, 0x8f, 0x10, 0x2a, 0xca, 0xc4, 0xad, 0x96, 0x24, 0x01,
+  0x68, 0xff, 0x65, 0xb5, 0xd1, 0x14, 0x2c, 0x2a, 0xa5, 0xda, 0x49, 0x96,
+  0xaf, 0xe9, 0xd4, 0xff, 0x71, 0x9c, 0x93, 0x09, 0x4a, 0x6a, 0x61, 0xf4,
+  0x4b, 0xd1, 0xcb, 0xb6, 0x5f, 0x29, 0xfc, 0x68, 0x11, 0xe5, 0x72, 0xff,
+  0x46, 0x0f, 0x36, 0x29, 0x99, 0x43, 0x9e, 0xb3, 0xd9, 0xac, 0x47, 0x93,
+  0x7b, 0xef, 0xc4, 0xeb, 0x66, 0x86, 0xa7, 0xd6, 0x89, 0x54, 0x3e, 0x94,
+  0x9b, 0x0d, 0x91, 0xf0, 0xd2, 0x23, 0x6a, 0xc0, 0x0d, 0x37, 0xce, 0x46,
+  0xdf, 0x95, 0xae, 0xa4, 0x65, 0xc6, 0x18, 0xbf, 0xa4, 0x69, 0x73, 0x3f,
+  0xe8, 0x85, 0xd0, 0x48, 0x7d, 0x28, 0xef, 0xf3, 0x5f, 0xb0, 0x01, 0xb4,
+  0x75, 0xb4, 0xd1, 0x53, 0x4b, 0xf4, 0x6f, 0xf6, 0xa4, 0x8b, 0x66, 0xb6,
+  0xef, 0x78, 0x39, 0xc5, 0x88, 0x2b, 0x67, 0x32, 0x1a, 0xef, 0x40, 0xc0,
+  0x94, 0xf6, 0xb7, 0xd2, 0x8b, 0x84, 0xa0, 0x26, 0x6f, 0x8a, 0x4b, 0xc5,
+  0xd8, 0xdc, 0x54, 0xee, 0xe2, 0x4a, 0x56, 0xaa, 0xbc, 0x72, 0xe5, 0x93,
+  0xe6, 0x3f, 0xb6, 0xde, 0x6d, 0x6c, 0x7b, 0x25, 0x5b, 0x01, 0xec, 0x6f,
+  0x29, 0x64, 0xb7, 0xf3, 0x2e, 0x23, 0xf6, 0x1f, 0xae, 0x11, 0x2d, 0xc6,
+  0xba, 0xb9, 0xeb, 0x08, 0x60, 0xb1, 0x2d, 0x1b, 0x2b, 0x9e, 0xbe, 0x85,
+  0x74, 0x0a, 0x1d, 0x2e, 0x2a, 0x52, 0x91, 0x18, 0x20, 0xd7, 0xc9, 0xb2,
+  0x97, 0x84, 0x8f, 0x16, 0x2c, 0x32, 0xca, 0x18, 0x12, 0xaa, 0xc5, 0x20,
+  0x59, 0xca, 0xfb, 0x6d, 0x37, 0x32, 0xe3, 0xc5, 0xa3, 0x84
+};
+unsigned int _ca_der_len = 1510;
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
+{
+	gnutls_datum_t raw;
+	gnutls_datum_t ca;
+	gnutls_x509_crt_t crt, ca_crt;
+	int ret;
+	unsigned status;
+
+	raw.data = (unsigned char *)data;
+	raw.size = size;
+
+	ca.data = _ca_der;
+	ca.size = _ca_der_len;
+
+	ret = gnutls_x509_crt_init(&ca_crt);
+	assert(ret >= 0);
+
+	ret = gnutls_x509_crt_init(&crt);
+	assert(ret >= 0);
+
+	ret = gnutls_x509_crt_import(ca_crt, &ca, GNUTLS_X509_FMT_DER);
+	if (ret < 0)
+		goto fail;
+
+	ret = gnutls_x509_crt_import(crt, &raw, GNUTLS_X509_FMT_DER);
+	if (ret < 0)
+		goto fail;
+
+	ret = gnutls_x509_crt_list_verify(&crt, 1, &ca_crt, 1, NULL, 0,
+					  GNUTLS_VERIFY_ALLOW_UNSORTED_CHAIN|GNUTLS_VERIFY_ALLOW_BROKEN|
+					  GNUTLS_VERIFY_DISABLE_TRUSTED_TIME_CHECKS,
+					  &status);
+	assert(ret >= 0 || status != 0);
+
+ fail:
+	gnutls_x509_crt_deinit(crt);
+	gnutls_x509_crt_deinit(ca_crt);
+	return 0;
+}
Binärdateien gnutls28-3.6.6/fuzz/gnutls_x509_verify_fuzzer.repro/cacdb69aaf394120d761291f43983336d15c7be3 und gnutls28-3.6.7/fuzz/gnutls_x509_verify_fuzzer.repro/cacdb69aaf394120d761291f43983336d15c7be3 sind verschieden.
diff -NurBbp gnutls28-3.6.6/fuzz/Makefile.am gnutls28-3.6.7/fuzz/Makefile.am
--- gnutls28-3.6.6/fuzz/Makefile.am	2018-12-30 16:02:07.000000000 +0100
+++ gnutls28-3.6.7/fuzz/Makefile.am	2019-03-27 07:20:12.000000000 +0100
@@ -9,6 +9,7 @@ LDADD = ../gl/libgnu.la ../lib/libgnutls
  $(LIBS)
 
 FUZZERS = \
+ gnutls_x509_verify_fuzzer$(EXEEXT) \
  gnutls_base64_decoder_fuzzer$(EXEEXT) \
  gnutls_base64_encoder_fuzzer$(EXEEXT) \
  gnutls_client_fuzzer$(EXEEXT) \
@@ -31,6 +32,7 @@ FUZZERS = \
 
 check_PROGRAMS = $(FUZZERS)
 
+gnutls_x509_verify_fuzzer_SOURCES = gnutls_x509_verify_fuzzer.c main.c fuzzer.h
 gnutls_base64_decoder_fuzzer_SOURCES = gnutls_base64_decoder_fuzzer.c main.c fuzzer.h
 gnutls_base64_encoder_fuzzer_SOURCES = gnutls_base64_encoder_fuzzer.c main.c fuzzer.h
 gnutls_client_fuzzer_SOURCES = gnutls_client_fuzzer.c main.c fuzzer.h mem.h certs.h
diff -NurBbp gnutls28-3.6.6/guile/src/core.c gnutls28-3.6.7/guile/src/core.c
--- gnutls28-3.6.6/guile/src/core.c	2018-06-16 15:32:48.000000000 +0200
+++ gnutls28-3.6.7/guile/src/core.c	2019-04-04 19:26:47.804144455 +0200
@@ -791,6 +791,10 @@ SCM_DEFINE (scm_gnutls_record_receive_x,
    so we have a separate implementation for these newer versions.  */
 #if USING_GUILE_BEFORE_2_2
 static scm_t_bits session_record_port_type;
+
+/* Hint for the `scm_gc_' functions.  */
+static const char session_record_port_gc_hint[] =
+  "gnutls-session-record-port";
 #else
 static scm_t_port_type *session_record_port_type;
 #endif
@@ -802,10 +806,6 @@ static scm_t_port_type *session_record_p
 /* Size of a session port's input buffer.  */
 #define SCM_GNUTLS_SESSION_RECORD_PORT_BUFFER_SIZE 4096
 
-/* Hint for the `scm_gc_' functions.  */
-static const char session_record_port_gc_hint[] =
-  "gnutls-session-record-port";
-
 
 #if SCM_MAJOR_VERSION == 1 && SCM_MINOR_VERSION <= 8
 
diff -NurBbp gnutls28-3.6.6/lib/alert.c gnutls28-3.6.7/lib/alert.c
--- gnutls28-3.6.6/lib/alert.c	2019-01-23 20:33:37.000000000 +0100
+++ gnutls28-3.6.7/lib/alert.c	2019-04-04 19:26:47.812144217 +0200
@@ -84,6 +84,8 @@ static const gnutls_alert_entry sup_aler
 	ALERT_ENTRY(GNUTLS_A_NO_APPLICATION_PROTOCOL,
 		    N_
 		    ("No supported application protocol could be negotiated")),
+	ALERT_ENTRY(GNUTLS_A_CERTIFICATE_REQUIRED,
+		    N_("Certificate is required")),
 	{0, NULL, NULL}
 };
 
@@ -224,6 +226,7 @@ int gnutls_error_to_alert(int err, int *
 	case GNUTLS_E_ILLEGAL_SRP_USERNAME:
 	case GNUTLS_E_PK_INVALID_PUBKEY:
 	case GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM:
+	case GNUTLS_E_RECEIVED_DISALLOWED_NAME:
 		ret = GNUTLS_A_ILLEGAL_PARAMETER;
 		_level = GNUTLS_AL_FATAL;
 		break;
@@ -325,6 +328,10 @@ int gnutls_error_to_alert(int err, int *
 		ret = GNUTLS_A_UNRECOGNIZED_NAME;
 		_level = GNUTLS_AL_FATAL;
 		break;
+	case GNUTLS_E_CERTIFICATE_REQUIRED:
+		ret = GNUTLS_A_CERTIFICATE_REQUIRED;
+		_level = GNUTLS_AL_FATAL;
+		break;
 	default:
 		ret = GNUTLS_A_INTERNAL_ERROR;
 		_level = GNUTLS_AL_FATAL;
diff -NurBbp gnutls28-3.6.6/lib/algorithms/ciphers.c gnutls28-3.6.7/lib/algorithms/ciphers.c
--- gnutls28-3.6.6/lib/algorithms/ciphers.c	2018-11-18 19:53:49.000000000 +0100
+++ gnutls28-3.6.7/lib/algorithms/ciphers.c	2019-04-04 19:26:47.812144217 +0200
@@ -341,7 +341,9 @@ unsigned gnutls_cipher_get_tag_size(gnut
  * gnutls_cipher_get_iv_size:
  * @algorithm: is an encryption algorithm
  *
- * Get block size for encryption algorithm.
+ * This function returns the size of the initialization vector (IV) for the
+ * provided algorithm. For algorithms with variable size IV (e.g., AES-CCM),
+ * the returned size will be the one used by TLS.
  *
  * Returns: block size for encryption algorithm.
  *
@@ -358,7 +360,7 @@ unsigned gnutls_cipher_get_iv_size(gnutl
  * gnutls_cipher_get_key_size:
  * @algorithm: is an encryption algorithm
  *
- * Get key size for cipher.
+ * This function returns the key size of the provided algorithm.
  *
  * Returns: length (in bytes) of the given cipher's key size, or 0 if
  *   the given cipher is invalid.
diff -NurBbp gnutls28-3.6.6/lib/algorithms/ciphersuites.c gnutls28-3.6.7/lib/algorithms/ciphersuites.c
--- gnutls28-3.6.6/lib/algorithms/ciphersuites.c	2018-11-18 19:53:49.000000000 +0100
+++ gnutls28-3.6.7/lib/algorithms/ciphersuites.c	2019-04-04 19:26:47.812144217 +0200
@@ -1578,7 +1578,7 @@ _gnutls_figure_common_ciphersuite(gnutls
 	/* RFC7919 requires that we reply with insufficient security if we have
 	 * negotiated an FFDHE group, but cannot find a common ciphersuite. However,
 	 * we must also distinguish between not matching a ciphersuite due to an
-	 * incompatible certificate which we traditionally return GNUTLS_E_INSUFFICIENT_SECURITY.
+	 * incompatible certificate which we traditionally return GNUTLS_E_NO_CIPHER_SUITES.
 	 */
 	if (!no_cert_found && (session->internals.hsk_flags & HSK_HAVE_FFDHE) &&
 	    session->internals.priorities->groups.have_ffdhe && !version->tls13_sem)
diff -NurBbp gnutls28-3.6.6/lib/algorithms/kx.c gnutls28-3.6.7/lib/algorithms/kx.c
--- gnutls28-3.6.6/lib/algorithms/kx.c	2018-11-18 19:53:49.000000000 +0100
+++ gnutls28-3.6.7/lib/algorithms/kx.c	2019-04-04 19:26:47.812144217 +0200
@@ -44,7 +44,7 @@ extern mod_auth_st srp_dss_auth_struct;
 
 
 /* Cred type mappings to KX algorithms
- * FIXME: The mappings are not 1-1. Some KX such as SRP_RSA require
+ * The mappings are not 1-1. Some KX such as SRP_RSA require
  * more than one credentials type.
  */
 typedef struct {
diff -NurBbp gnutls28-3.6.6/lib/auth/cert.c gnutls28-3.6.7/lib/auth/cert.c
--- gnutls28-3.6.6/lib/auth/cert.c	2018-12-15 22:10:46.000000000 +0100
+++ gnutls28-3.6.7/lib/auth/cert.c	2019-04-04 19:26:47.812144217 +0200
@@ -181,6 +181,7 @@ find_x509_client_cert(gnutls_session_t s
 	ssize_t data_size = _data_size;
 	unsigned i, j;
 	int result, cert_pk;
+	unsigned key_usage;
 
 	*indx = -1;
 
@@ -191,8 +192,16 @@ find_x509_client_cert(gnutls_session_t s
 	    (data_size == 0
 	     || (session->internals.flags & GNUTLS_FORCE_CLIENT_CERT))) {
 		if (cred->certs[0].cert_list[0].type == GNUTLS_CRT_X509) {
-			/* This check is necessary to prevent sending other certificate
-			 * credentials that are set (e.g. raw public-key). */
+
+			key_usage = get_key_usage(session, cred->certs[0].cert_list[0].pubkey);
+
+			/* For client certificates we require signatures */
+			result = _gnutls_check_key_usage_for_sig(session, key_usage, 1);
+			if (result < 0) {
+				_gnutls_debug_log("Client certificate is not suitable for signing\n");
+				return gnutls_assert_val(result);
+			}
+
 			*indx = 0;
 			return 0;
 		}
@@ -221,6 +230,14 @@ find_x509_client_cert(gnutls_session_t s
 				if (odn.size == 0 || odn.size != asked_dn.size)
 					continue;
 
+				key_usage = get_key_usage(session, cred->certs[i].cert_list[0].pubkey);
+
+				/* For client certificates we require signatures */
+				if (_gnutls_check_key_usage_for_sig(session, key_usage, 1) < 0) {
+					_gnutls_debug_log("Client certificate is not suitable for signing\n");
+					continue;
+				}
+
 				/* If the DN matches and
 				 * the *_SIGN algorithm matches
 				 * the cert is our cert!
@@ -268,6 +285,7 @@ find_rawpk_client_cert(gnutls_session_t
 			int pk_algos_length, int* indx)
 {
 	unsigned i;
+	int ret;
 	gnutls_pk_algorithm_t pk;
 
 	*indx = -1;
@@ -276,15 +294,22 @@ find_rawpk_client_cert(gnutls_session_t
 		/* We know that our list length will be 1, therefore we can
 		 * ignore the rest.
 		 */
-		if (cred->certs[i].cert_list_length == 1) {
-			pk = gnutls_pubkey_get_pk_algorithm(cred->certs[i].
-																					cert_list[0].pubkey, NULL);
+		if (cred->certs[i].cert_list_length == 1 && cred->certs[i].cert_list[0].type == GNUTLS_CRT_RAWPK) {
+			pk = gnutls_pubkey_get_pk_algorithm(cred->certs[i].cert_list[0].pubkey, NULL);
+
+			/* For client certificates we require signatures */
+			ret = _gnutls_check_key_usage_for_sig(session, get_key_usage(session, cred->certs[i].cert_list[0].pubkey), 1);
+			if (ret < 0) {
+				/* we return an error instead of skipping so that the user is notified about
+				 * the key incompatibility */
+				_gnutls_debug_log("Client certificate is not suitable for signing\n");
+				return gnutls_assert_val(ret);
+			}
 
 			/* Check whether the public-key algorithm of our credential is in
 			 * the list with supported public-key algorithms and whether the
 			 * cert type matches. */
-			if ((check_pk_algo_in_list(pk_algos, pk_algos_length, pk) == 0)
-			   && (cred->certs[i].cert_list[0].type == GNUTLS_CRT_RAWPK))	{
+			if ((check_pk_algo_in_list(pk_algos, pk_algos_length, pk) == 0)) {
 				// We found a compatible credential
 				*indx = i;
 				break;
@@ -302,7 +327,7 @@ find_rawpk_client_cert(gnutls_session_t
 static int
 get_issuers_num(gnutls_session_t session, const uint8_t * data, ssize_t data_size)
 {
-	int issuers_dn_len = 0, result;
+	int issuers_dn_len = 0;
 	unsigned size;
 
 	/* Count the number of the given issuers;
@@ -313,16 +338,13 @@ get_issuers_num(gnutls_session_t session
 	if (data_size == 0 || data == NULL)
 		return 0;
 
-	if (data_size > 0)
-		do {
+	while (data_size > 0) {
 			/* This works like DECR_LEN()
 			 */
-			result = GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
-			DECR_LENGTH_COM(data_size, 2, goto error);
+		DECR_LENGTH_RET(data_size, 2, GNUTLS_E_UNEXPECTED_PACKET_LENGTH);
 			size = _gnutls_read_uint16(data);
 
-			result = GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
-			DECR_LENGTH_COM(data_size, size, goto error);
+		DECR_LENGTH_RET(data_size, size, GNUTLS_E_UNEXPECTED_PACKET_LENGTH);
 
 			data += 2;
 
@@ -330,17 +352,9 @@ get_issuers_num(gnutls_session_t session
 				issuers_dn_len++;
 				data += size;
 			}
-
-			if (data_size == 0)
-				break;
-
 		}
-		while (1);
 
 	return issuers_dn_len;
-
- error:
-	return result;
 }
 
 /* Returns the issuers in the server's certificate request
@@ -643,21 +657,24 @@ _gnutls_gen_rawpk_crt(gnutls_session_t s
 	/* Since we are transmitting a raw public key with no additional
 	 * certificate credentials attached to it, it doesn't make sense to
 	 * have more than one certificate set (i.e. to have a certificate chain).
-	 * This is enforced by the API so having a value other than 1 should
-	 * be an impossible situation.
 	 */
-	assert(apr_cert_list_length == 1);
+	assert(apr_cert_list_length <= 1);
 	
 	/* Write our certificate containing only the SubjectPublicKeyInfo to
 	 * the output buffer. We always have exactly one certificate that
 	 * contains our raw public key. Our message looks like:
 	 * <length++certificate> where
-	 * length = 3 bytes and
+	 * length = 3 bytes (or 24 bits) and
 	 * certificate = length bytes.
 	 */
+	if (apr_cert_list_length == 0) {
+		ret = _gnutls_buffer_append_prefix(data, 24, 0);
+	} else {
 	ret = _gnutls_buffer_append_data_prefix(data, 24,
 					apr_cert_list[0].cert.data,
 					apr_cert_list[0].cert.size);
+	}
+
 
 	if (ret < 0) return gnutls_assert_val(ret);
 
@@ -962,7 +979,6 @@ cleanup:
 
 int _gnutls_proc_crt(gnutls_session_t session, uint8_t * data, size_t data_size)
 {
-	int ret;
 	gnutls_certificate_credentials_t cred;
 	gnutls_certificate_type_t cert_type;
 
@@ -986,8 +1002,6 @@ int _gnutls_proc_crt(gnutls_session_t se
 		default:
 			return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR);
 	}
-
-	return ret;
 }
 
 /* Checks if we support the given signature algorithm
@@ -1462,11 +1476,11 @@ int cert_select_sign_algorithm(gnutls_se
 		return gnutls_assert_val(GNUTLS_E_INSUFFICIENT_CREDENTIALS);
 	}
 
-	if (unlikely(session->internals.priorities->allow_server_key_usage_violation)) {
-		key_usage = 0;
-	} else {
-		key_usage = pubkey->key_usage;
-	}
+	key_usage = get_key_usage(session, pubkey);
+
+	/* In TLS1.3 we support only signatures; ensure the selected key supports them */
+	if (ver->tls13_sem && _gnutls_check_key_usage_for_sig(session, key_usage, 1) < 0)
+		return gnutls_assert_val(GNUTLS_E_INSUFFICIENT_CREDENTIALS);
 
 	if (!ver->tls13_sem && !_gnutls_kx_supports_pk_usage(cs->kx_algorithm, pk, key_usage)) {
 		return gnutls_assert_val(GNUTLS_E_INSUFFICIENT_CREDENTIALS);
diff -NurBbp gnutls28-3.6.6/lib/auth/cert.h gnutls28-3.6.7/lib/auth/cert.h
--- gnutls28-3.6.6/lib/auth/cert.h	2018-12-15 22:10:46.000000000 +0100
+++ gnutls28-3.6.7/lib/auth/cert.h	2019-04-04 19:26:47.812144217 +0200
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2002-2012 Free Software Foundation, Inc.
- * Copyright (C) 2016-2017 Red Hat, Inc.
+ * Copyright (C) 2016-2019 Red Hat, Inc.
  *
  * Author: Nikos Mavrogiannopoulos
  *
@@ -29,6 +29,7 @@
 #include <gnutls/abstract.h>
 #include <gnutls/compat.h>
 #include <str_array.h>
+#include "abstract_int.h"
 
 #define MAX_OCSP_RESPONSES 8
 
@@ -171,5 +172,13 @@ int _gnutls_gen_rawpk_crt(gnutls_session
 int _gnutls_proc_rawpk_crt(gnutls_session_t session,
 				uint8_t * data, size_t data_size);
 
+inline static unsigned get_key_usage(gnutls_session_t session, gnutls_pubkey_t pubkey)
+{
+	if (unlikely(session->internals.priorities &&
+	    session->internals.priorities->allow_server_key_usage_violation))
+		return 0;
+	else
+		return pubkey->key_usage;
+}
 
 #endif
diff -NurBbp gnutls28-3.6.6/lib/auth/rsa.c gnutls28-3.6.7/lib/auth/rsa.c
--- gnutls28-3.6.6/lib/auth/rsa.c	2019-01-05 12:28:47.000000000 +0100
+++ gnutls28-3.6.7/lib/auth/rsa.c	2019-04-04 19:26:47.812144217 +0200
@@ -201,7 +201,6 @@ proc_rsa_client_kx(gnutls_session_t sess
 			 GNUTLS_MASTER_SIZE);
 	if (ret < 0) {
                 gnutls_free(session->key.key.data);
-                session->key.key.data = NULL;
                 session->key.key.size = 0;
 		gnutls_assert();
 		return ret;
diff -NurBbp gnutls28-3.6.6/lib/auth/rsa_psk.c gnutls28-3.6.7/lib/auth/rsa_psk.c
--- gnutls28-3.6.6/lib/auth/rsa_psk.c	2019-01-05 12:28:47.000000000 +0100
+++ gnutls28-3.6.7/lib/auth/rsa_psk.c	2019-02-25 19:14:55.000000000 +0100
@@ -341,7 +341,6 @@ _gnutls_proc_rsa_psk_client_kx(gnutls_se
 		    ("auth_rsa_psk: Possible PKCS #1 format attack\n");
 		if (ret >= 0) {
 			gnutls_free(plaintext.data);
-			plaintext.data = NULL;
 		}
 		randomize_key = 1;
 	} else {
diff -NurBbp gnutls28-3.6.6/lib/auth/srp_sb64.c gnutls28-3.6.7/lib/auth/srp_sb64.c
--- gnutls28-3.6.6/lib/auth/srp_sb64.c	2018-04-01 13:56:15.000000000 +0200
+++ gnutls28-3.6.7/lib/auth/srp_sb64.c	2019-04-04 19:26:47.812144217 +0200
@@ -263,7 +263,6 @@ _gnutls_sbase64_decode(char *data, size_
 		tmp = decode(tmpres, datrev);
 		if (tmp < 0) {
 			gnutls_free((*result));
-			*result = NULL;
 			return tmp;
 		}
 
@@ -277,7 +276,6 @@ _gnutls_sbase64_decode(char *data, size_
 		tmp = decode(tmpres, (uint8_t *) & data[i]);
 		if (tmp < 0) {
 			gnutls_free((*result));
-			*result = NULL;
 			return tmp;
 		}
 		memcpy(&(*result)[j], tmpres, tmp);
diff -NurBbp gnutls28-3.6.6/lib/auth.c gnutls28-3.6.7/lib/auth.c
--- gnutls28-3.6.6/lib/auth.c	2018-11-18 19:53:49.000000000 +0100
+++ gnutls28-3.6.7/lib/auth.c	2019-04-04 19:26:47.812144217 +0200
@@ -138,6 +138,29 @@ gnutls_credentials_set(gnutls_session_t
 		}
 	}
 
+	/* sanity tests */
+	if (type == GNUTLS_CRD_CERTIFICATE) {
+		gnutls_certificate_credentials_t c = cred;
+		unsigned i;
+		bool allow_tls13 = 0;
+		unsigned key_usage;
+
+		if (c != NULL && c->ncerts != 0) {
+			for (i = 0; i < c->ncerts; i++) {
+				key_usage = get_key_usage(session, c->certs[i].cert_list[0].pubkey);
+				if (key_usage == 0 || (key_usage & GNUTLS_KEY_DIGITAL_SIGNATURE)) {
+					allow_tls13 = 1;
+					break;
+				}
+			}
+
+			if (!allow_tls13) {
+				/* to prevent the server random indicate TLS1.3 support */
+				session->internals.flags |= INT_FLAG_NO_TLS13;
+			}
+		}
+	}
+
 	return 0;
 }
 
@@ -349,8 +372,6 @@ void _gnutls_free_auth_info(gnutls_sessi
 
 			gnutls_free(info->raw_certificate_list);
 			gnutls_free(info->raw_ocsp_list);
-			info->raw_certificate_list = NULL;
-			info->raw_ocsp_list = NULL;
 			info->ncerts = 0;
 			info->nocsp = 0;
 
@@ -367,7 +388,6 @@ void _gnutls_free_auth_info(gnutls_sessi
 	}
 
 	gnutls_free(session->key.auth_info);
-	session->key.auth_info = NULL;
 	session->key.auth_info_size = 0;
 	session->key.auth_info_type = 0;
 
diff -NurBbp gnutls28-3.6.6/lib/buffers.c gnutls28-3.6.7/lib/buffers.c
--- gnutls28-3.6.6/lib/buffers.c	2018-11-18 19:53:49.000000000 +0100
+++ gnutls28-3.6.7/lib/buffers.c	2019-04-04 19:26:47.812144217 +0200
@@ -277,7 +277,7 @@ _gnutls_dgram_read(gnutls_session_t sess
 				 fd);
 		if (i == 0) {
 			/* If we get here, we likely have a stream socket.
-			 * FIXME: this probably breaks DCCP. */
+			 * That assumption may not work on DCCP. */
 			gnutls_assert();
 			ret = 0;
 			goto cleanup;
diff -NurBbp gnutls28-3.6.6/lib/cert-cred.c gnutls28-3.6.7/lib/cert-cred.c
--- gnutls28-3.6.6/lib/cert-cred.c	2018-12-15 22:10:46.000000000 +0100
+++ gnutls28-3.6.7/lib/cert-cred.c	2019-04-04 19:26:47.812144217 +0200
@@ -258,7 +258,6 @@ void gnutls_certificate_free_keys(gnutls
 
 		for (j = 0; j < sc->certs[i].ocsp_data_length; j++) {
 			gnutls_free(sc->certs[i].ocsp_data[j].response.data);
-			sc->certs[i].ocsp_data[j].response.data = NULL;
 		}
 		_gnutls_str_array_clear(&sc->certs[i].names);
 		gnutls_privkey_deinit(sc->certs[i].pkey);
@@ -266,8 +265,6 @@ void gnutls_certificate_free_keys(gnutls
 
 	gnutls_free(sc->certs);
 	gnutls_free(sc->sorted_cert_idx);
-	sc->certs = NULL;
-	sc->sorted_cert_idx = NULL;
 
 	sc->ncerts = 0;
 }
@@ -276,14 +273,13 @@ void gnutls_certificate_free_keys(gnutls
  * gnutls_certificate_free_cas:
  * @sc: is a #gnutls_certificate_credentials_t type.
  *
- * This function will delete all the CAs associated with the given
- * credentials. Servers that do not use
- * gnutls_certificate_verify_peers2() may call this to save some
- * memory.
+ * This function was operational on very early versions of gnutls.
+ * Due to internal refactorings and the fact that this was hardly ever
+ * used, it is currently a no-op.
+ *
  **/
 void gnutls_certificate_free_cas(gnutls_certificate_credentials_t sc)
 {
-	/* FIXME: do nothing for now */
 	return;
 }
 
diff -NurBbp gnutls28-3.6.6/lib/cert-cred-x509.c gnutls28-3.6.7/lib/cert-cred-x509.c
--- gnutls28-3.6.6/lib/cert-cred-x509.c	2018-12-15 22:10:46.000000000 +0100
+++ gnutls28-3.6.7/lib/cert-cred-x509.c	2019-04-04 19:26:47.812144217 +0200
@@ -265,7 +265,6 @@ parse_pem_cert_mem(gnutls_certificate_cr
 	    gnutls_pcert_import_x509_list(pcerts, unsorted, &ncerts, GNUTLS_X509_CRT_LIST_SORT);
 	if (ret < 0) {
 		gnutls_free(pcerts);
-		pcerts = NULL;
 		gnutls_assert();
 		goto cleanup;
 	}
@@ -508,7 +507,6 @@ read_cert_url(gnutls_certificate_credent
 			goto cleanup;
 		}
 		gnutls_free(t.data);
-		t.data = NULL;
 	}
 
 	ret = _gnutls_certificate_credential_append_keypair(res, key, names, ccert, count);
@@ -908,7 +906,6 @@ gnutls_certificate_get_x509_crt(gnutls_c
 			while (i--)
 				gnutls_x509_crt_deinit((*crt_list)[i]);
 			gnutls_free(*crt_list);
-			*crt_list = NULL;
 
 			return gnutls_assert_val(ret);
 		}
diff -NurBbp gnutls28-3.6.6/lib/cipher.c gnutls28-3.6.7/lib/cipher.c
--- gnutls28-3.6.6/lib/cipher.c	2018-11-18 19:53:49.000000000 +0100
+++ gnutls28-3.6.7/lib/cipher.c	2019-04-04 19:26:47.812144217 +0200
@@ -872,6 +872,15 @@ decrypt_packet_tls13(gnutls_session_t se
 	if (unlikely(ret < 0))
 		return gnutls_assert_val(ret);
 
+	/* 1 octet for content type */
+	if (length > max_decrypted_size(session) + 1) {
+		_gnutls_audit_log
+		    (session, "Received packet with illegal length: %u\n",
+		     (unsigned int) length);
+
+		return gnutls_assert_val(GNUTLS_E_RECORD_OVERFLOW);
+	}
+
 	length_set = 0;
 
 	/* now figure the actual data size. We intentionally iterate through all data,
diff -NurBbp gnutls28-3.6.6/lib/constate.c gnutls28-3.6.7/lib/constate.c
--- gnutls28-3.6.6/lib/constate.c	2019-01-24 20:15:38.000000000 +0100
+++ gnutls28-3.6.7/lib/constate.c	2019-04-04 19:26:47.812144217 +0200
@@ -39,6 +39,7 @@
 #include "secrets.h"
 #include "handshake.h"
 #include "crypto-api.h"
+#include "locks.h"
 
 static const char keyexp[] = "key expansion";
 static const int keyexp_length = sizeof(keyexp) - 1;
@@ -55,8 +56,6 @@ static int
 _gnutls_set_keys(gnutls_session_t session, record_parameters_st * params,
 		 unsigned hash_size, unsigned IV_size, unsigned key_size)
 {
-	/* FIXME: This function is too long
-	 */
 	uint8_t rnd[2 * GNUTLS_RANDOM_SIZE];
 	int pos, ret;
 	int block_size;
@@ -822,6 +821,15 @@ int _gnutls_write_connection_state_init(
 	    session->security_parameters.epoch_next;
 	int ret;
 
+	/* reset max_record_recv_size if it was negotiated in the
+	 * previous handshake using the record_size_limit extension */
+	if (session->security_parameters.max_record_recv_size !=
+	    session->security_parameters.max_record_send_size &&
+	    !(session->internals.hsk_flags & HSK_RECORD_SIZE_LIMIT_NEGOTIATED) &&
+	    session->security_parameters.entity == GNUTLS_SERVER)
+		session->security_parameters.max_record_recv_size =
+			session->security_parameters.max_record_send_size;
+
 /* Update internals from CipherSuite selected.
  * If we are resuming just copy the connection session
  */
@@ -897,18 +905,28 @@ _gnutls_epoch_get(gnutls_session_t sessi
 	record_parameters_st **params;
 	int ret;
 
+	gnutls_mutex_lock(&session->internals.epoch_lock);
+
 	ret = epoch_resolve(session, epoch_rel, &epoch);
-	if (ret < 0)
-		return gnutls_assert_val(ret);
+	if (ret < 0) {
+		gnutls_assert();
+		goto cleanup;
+	}
 
 	params = epoch_get_slot(session, epoch);
-	if (params == NULL || *params == NULL)
-		return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
+	if (params == NULL || *params == NULL) {
+		ret = gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
+		goto cleanup;
+	}
 
 	if (params_out)
 		*params_out = *params;
 
-	return 0;
+	ret = 0;
+
+cleanup:
+	gnutls_mutex_unlock(&session->internals.epoch_lock);
+	return ret;
 }
 
 /* Ensures that the next epoch is setup. When an epoch will null ciphers
@@ -999,6 +1017,8 @@ void _gnutls_epoch_gc(gnutls_session_t s
 
 	_gnutls_record_log("REC[%p]: Start of epoch cleanup\n", session);
 
+	gnutls_mutex_lock(&session->internals.epoch_lock);
+
 	/* Free all dead cipher state */
 	for (i = 0; i < MAX_EPOCH_INDEX; i++) {
 		if (session->record_parameters[i] != NULL) {
@@ -1041,6 +1061,8 @@ void _gnutls_epoch_gc(gnutls_session_t s
 		session->security_parameters.epoch_min =
 		    session->record_parameters[0]->epoch;
 
+	gnutls_mutex_unlock(&session->internals.epoch_lock);
+
 	_gnutls_record_log("REC[%p]: End of epoch cleanup\n", session);
 }
 
diff -NurBbp gnutls28-3.6.6/lib/crypto-api.c gnutls28-3.6.7/lib/crypto-api.c
--- gnutls28-3.6.6/lib/crypto-api.c	2018-07-02 20:00:33.000000000 +0200
+++ gnutls28-3.6.7/lib/crypto-api.c	2019-04-04 19:26:47.812144217 +0200
@@ -668,20 +668,22 @@ int gnutls_aead_cipher_init(gnutls_aead_
  * @handle: is a #gnutls_aead_cipher_hd_t type.
  * @nonce: the nonce to set
  * @nonce_len: The length of the nonce
- * @auth: the data to be authenticated
+ * @auth: additional data to be authenticated
  * @auth_len: The length of the data
  * @tag_size: The size of the tag to use (use zero for the default)
- * @ctext: the data to decrypt
+ * @ctext: the data to decrypt (including the authentication tag)
  * @ctext_len: the length of data to decrypt (includes tag size)
  * @ptext: the decrypted data
  * @ptext_len: the length of decrypted data (initially must hold the maximum available size)
  *
  * This function will decrypt the given data using the algorithm
- * specified by the context. This function must be provided the whole
- * data to be decrypted, including the tag, and will fail if the tag
- * verification fails.
+ * specified by the context. This function must be provided the complete
+ * data to be decrypted, including the authentication tag. On several
+ * AEAD ciphers, the authentication tag is appended to the ciphertext,
+ * though this is not a general rule. This function will fail if
+ * the tag verification fails.
  *
- * Returns: Zero or a negative error code on error.
+ * Returns: Zero or a negative error code on verification failure or other error.
  *
  * Since: 3.4.0
  **/
@@ -725,12 +727,12 @@ gnutls_aead_cipher_decrypt(gnutls_aead_c
  * @handle: is a #gnutls_aead_cipher_hd_t type.
  * @nonce: the nonce to set
  * @nonce_len: The length of the nonce
- * @auth: the data to be authenticated
+ * @auth: additional data to be authenticated
  * @auth_len: The length of the data
  * @tag_size: The size of the tag to use (use zero for the default)
  * @ptext: the data to encrypt
  * @ptext_len: The length of data to encrypt
- * @ctext: the encrypted data
+ * @ctext: the encrypted data including authentication tag
  * @ctext_len: the length of encrypted data (initially must hold the maximum available size, including space for tag)
  *
  * This function will encrypt the given data using the algorithm
@@ -919,12 +921,12 @@ static int copy_iov(struct iov_store_st
  * @handle: is a #gnutls_aead_cipher_hd_t type.
  * @nonce: the nonce to set
  * @nonce_len: The length of the nonce
- * @auth_iov: the data to be authenticated
+ * @auth_iov: additional data to be authenticated
  * @auth_iovcnt: The number of buffers in @auth_iov
  * @tag_size: The size of the tag to use (use zero for the default)
  * @iov: the data to be encrypted
  * @iovcnt: The number of buffers in @iov
- * @ctext: the encrypted data
+ * @ctext: the encrypted data including authentication tag
  * @ctext_len: the length of encrypted data (initially must hold the maximum available size, including space for tag)
  *
  * This function will encrypt the provided data buffers using the algorithm
diff -NurBbp gnutls28-3.6.6/lib/errors.c gnutls28-3.6.7/lib/errors.c
--- gnutls28-3.6.6/lib/errors.c	2018-12-20 17:39:32.000000000 +0100
+++ gnutls28-3.6.7/lib/errors.c	2019-04-04 19:26:47.816144097 +0200
@@ -93,6 +93,8 @@ static const gnutls_error_entry error_en
 		    GNUTLS_E_ERROR_IN_FINISHED_PACKET),
 	ERROR_ENTRY(N_("No certificate was found."),
 		    GNUTLS_E_NO_CERTIFICATE_FOUND),
+	ERROR_ENTRY(N_("Certificate is required."),
+		    GNUTLS_E_CERTIFICATE_REQUIRED),
 	ERROR_ENTRY(N_
 		    ("The given DSA key is incompatible with the selected TLS protocol."),
 		    GNUTLS_E_INCOMPAT_DSA_KEY_WITH_TLS_PROTOCOL),
@@ -206,6 +208,8 @@ static const gnutls_error_entry error_en
 	ERROR_ENTRY(N_("An illegal parameter was found."),
 		    GNUTLS_E_ILLEGAL_PARAMETER),
 	ERROR_ENTRY(N_("Error while reading file."), GNUTLS_E_FILE_ERROR),
+	ERROR_ENTRY(N_("A disallowed SNI server name has been received."),
+		    GNUTLS_E_RECEIVED_DISALLOWED_NAME),
 
 	ERROR_ENTRY(N_("ASN1 parser: Element was not found."),
 		    GNUTLS_E_ASN1_ELEMENT_NOT_FOUND),
diff -NurBbp gnutls28-3.6.6/lib/ext/max_record.c gnutls28-3.6.7/lib/ext/max_record.c
--- gnutls28-3.6.6/lib/ext/max_record.c	2018-08-20 21:47:04.000000000 +0200
+++ gnutls28-3.6.7/lib/ext/max_record.c	2019-04-04 19:26:47.816144097 +0200
@@ -153,16 +153,16 @@ _gnutls_max_record_send_params(gnutls_se
 
 	} else {		/* server side */
 
+		if (session->internals.hsk_flags & HSK_RECORD_SIZE_LIMIT_SENT)
+			return 0;
+
 		if (session->security_parameters.max_record_recv_size !=
 		    DEFAULT_MAX_RECORD_SIZE) {
 			ret = _gnutls_mre_record2num
 			      (session->security_parameters.
 			       max_record_recv_size);
-
-			/* it's not an error, as long as we send the
-			 * record_size_limit extension with that value */
 			if (ret < 0)
-				return 0;
+				return gnutls_assert_val(ret);
 
 			p = (uint8_t) ret;
 			ret = _gnutls_buffer_append_data(extdata, &p, 1);
@@ -240,8 +240,7 @@ size_t gnutls_record_get_max_size(gnutls
  * @size: is the new size
  *
  * This function sets the maximum record packet size in this
- * connection.  This property can only be set to clients.  The server
- * may choose not to accept the requested size.
+ * connection.
  *
  * The requested record size does get in effect immediately only while
  * sending data. The receive part will take effect after a successful
@@ -255,14 +254,14 @@ size_t gnutls_record_get_max_size(gnutls
  * 512 and 16384.  Note that not all TLS implementations use or even
  * understand those extension.
  *
+ * In TLS 1.3, the value is the length of plaintext content plus its
+ * padding, excluding content type octet.
+ *
  * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned,
  *   otherwise a negative error code is returned.
  **/
 ssize_t gnutls_record_set_max_size(gnutls_session_t session, size_t size)
 {
-	if (session->security_parameters.entity == GNUTLS_SERVER)
-		return GNUTLS_E_INVALID_REQUEST;
-
 	if (size < MIN_RECORD_SIZE || size > DEFAULT_MAX_RECORD_SIZE)
 		return GNUTLS_E_INVALID_REQUEST;
 
diff -NurBbp gnutls28-3.6.6/lib/ext/record_size_limit.c gnutls28-3.6.7/lib/ext/record_size_limit.c
--- gnutls28-3.6.6/lib/ext/record_size_limit.c	2019-01-24 20:15:38.000000000 +0100
+++ gnutls28-3.6.7/lib/ext/record_size_limit.c	2019-04-04 19:26:47.816144097 +0200
@@ -52,6 +52,7 @@ _gnutls_record_size_limit_recv_params(gn
 {
 	ssize_t new_size;
 	ssize_t data_size = _data_size;
+	const version_entry_st *vers;
 
 	DECR_LEN(data_size, 2);
 	if (data_size != 0)
@@ -62,19 +63,35 @@ _gnutls_record_size_limit_recv_params(gn
 	if (new_size < 64)
 		return gnutls_assert_val(GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER);
 
-	/* we do not want to accept sizes less than our minimum */
-	if (new_size < MIN_RECORD_SIZE)
-		return 0;
+	session->internals.hsk_flags |= HSK_RECORD_SIZE_LIMIT_RECEIVED;
+
+	/* we do not want to accept sizes outside of our supported range */
+	if (new_size < MIN_RECORD_SIZE) {
+		/* for server, reject it by omitting the extension in the reply */
+		if (session->security_parameters.entity == GNUTLS_SERVER) {
+			_gnutls_handshake_log("EXT[%p]: client requested too small record_size_limit %u; ignoring\n",
+					      session, (unsigned)new_size);
+			return gnutls_assert_val(0);
+		} else {
+			_gnutls_handshake_log("EXT[%p]: server requested too small record_size_limit %u; closing the connection\n",
+					      session, (unsigned)new_size);
+			return gnutls_assert_val(GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER);
+		}
+	}
 
 	session->internals.hsk_flags |= HSK_RECORD_SIZE_LIMIT_NEGOTIATED;
 
-	/* if a larger record size limit than the protocol limit is
-	 * provided by the peer, ignore it and stick to the default */
-	if (unlikely(new_size > DEFAULT_MAX_RECORD_SIZE))
-		return gnutls_assert_val(0);
+	_gnutls_handshake_log("EXT[%p]: record_size_limit %u negotiated\n",
+			      session, (unsigned)new_size);
+
+	/* subtract 1 octet for content type */
+	vers = get_version(session);
+	if (unlikely(vers == NULL))
+		return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR);
 
-	session->security_parameters.max_record_send_size = new_size;
-	session->security_parameters.max_record_recv_size = new_size;
+	session->security_parameters.max_record_recv_size =
+		MIN(new_size - vers->tls13_sem,
+		    session->security_parameters.max_record_send_size);
 
 	return 0;
 }
@@ -86,15 +103,44 @@ _gnutls_record_size_limit_send_params(gn
 				      gnutls_buffer_st * extdata)
 {
 	int ret;
+	uint16_t send_size;
 
 	assert(session->security_parameters.max_record_send_size >= 64 &&
 	       session->security_parameters.max_record_send_size <=
 	       DEFAULT_MAX_RECORD_SIZE);
 
-	ret = _gnutls_buffer_append_prefix(extdata, 16,
-					   session->security_parameters.max_record_send_size);
+	send_size = session->security_parameters.max_record_send_size;
+
+	if (session->security_parameters.entity == GNUTLS_SERVER) {
+		const version_entry_st *vers;
+
+		/* if we had received the extension and rejected, don't send it */
+		if (session->internals.hsk_flags & HSK_RECORD_SIZE_LIMIT_RECEIVED &&
+		    !(session->internals.hsk_flags & HSK_RECORD_SIZE_LIMIT_NEGOTIATED))
+			return gnutls_assert_val(0);
+
+		/* add 1 octet for content type */
+		vers = get_version(session);
+		if (unlikely(vers == NULL))
+			return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR);
+
+		send_size += vers->tls13_sem;
+	} else {
+		const version_entry_st *vers;
+
+		/* add 1 octet for content type */
+		vers = _gnutls_version_max(session);
+		if (unlikely(vers == NULL))
+			return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR);
+
+		send_size += vers->tls13_sem;
+	}
+
+	ret = _gnutls_buffer_append_prefix(extdata, 16, send_size);
 	if (ret < 0)
 		return gnutls_assert_val(ret);
 
+	session->internals.hsk_flags |= HSK_RECORD_SIZE_LIMIT_SENT;
+
 	return 2;
 }
diff -NurBbp gnutls28-3.6.6/lib/ext/server_name.c gnutls28-3.6.7/lib/ext/server_name.c
--- gnutls28-3.6.6/lib/ext/server_name.c	2018-05-19 11:52:01.000000000 +0200
+++ gnutls28-3.6.7/lib/ext/server_name.c	2019-04-04 19:26:47.816144097 +0200
@@ -105,8 +105,12 @@ _gnutls_server_name_recv_params(gnutls_s
 			DECR_LEN(data_size, len);
 
 			if (type == 0) { /* NAME_DNS */
-				if (!_gnutls_dnsname_is_valid((char*)p, len))
-					return gnutls_assert_val(GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER);
+				if (!_gnutls_dnsname_is_valid((char*)p, len)) {
+					_gnutls_handshake_log
+					    ("HSK[%p]: Server name is not acceptable: '%.*s'\n",
+					     session, (int) len, p);
+					return gnutls_assert_val(GNUTLS_E_RECEIVED_DISALLOWED_NAME);
+				}
 
 				name.data = (void*)p;
 				name.size = len;
diff -NurBbp gnutls28-3.6.6/lib/ext/supported_versions.c gnutls28-3.6.7/lib/ext/supported_versions.c
--- gnutls28-3.6.6/lib/ext/supported_versions.c	2018-09-12 17:06:52.000000000 +0200
+++ gnutls28-3.6.7/lib/ext/supported_versions.c	2019-04-04 19:26:47.816144097 +0200
@@ -63,7 +63,10 @@ supported_versions_recv_params(gnutls_se
 	int ret;
 
 	if (session->security_parameters.entity == GNUTLS_SERVER) {
+		const version_entry_st *old_vers;
+
 		vers = _gnutls_version_max(session);
+		old_vers = get_version(session);
 
 		/* do not parse this extension when we haven't TLS1.3
 		 * enabled. That is because we cannot handle earlier protocol
@@ -97,6 +100,18 @@ supported_versions_recv_params(gnutls_se
 
 				_gnutls_handshake_log("EXT[%p]: Negotiated version: %d.%d\n",
 						      session, (int)major, (int)minor);
+
+				vers = get_version(session);
+				if (old_vers != vers) {
+					/* regenerate the random value to set
+					 * downgrade sentinel if necessary
+					 */
+					ret = _gnutls_gen_server_random(session,
+									vers->id);
+					if (ret < 0)
+						return gnutls_assert_val(ret);
+				}
+
 				return 0;
 			}
 		}
diff -NurBbp gnutls28-3.6.6/lib/fips.c gnutls28-3.6.7/lib/fips.c
--- gnutls28-3.6.6/lib/fips.c	2018-04-01 13:56:13.000000000 +0200
+++ gnutls28-3.6.7/lib/fips.c	2019-04-04 19:26:47.816144097 +0200
@@ -135,9 +135,9 @@ void _gnutls_fips_mode_reset_zombie(void
 	}
 }
 
-#define GNUTLS_LIBRARY_NAME "libgnutls.so.28"
-#define NETTLE_LIBRARY_NAME "libnettle.so.4"
-#define HOGWEED_LIBRARY_NAME "libhogweed.so.2"
+#define GNUTLS_LIBRARY_NAME "libgnutls.so.30"
+#define NETTLE_LIBRARY_NAME "libnettle.so.6"
+#define HOGWEED_LIBRARY_NAME "libhogweed.so.4"
 #define GMP_LIBRARY_NAME "libgmp.so.10"
 
 #define HMAC_SUFFIX ".hmac"
@@ -250,6 +250,13 @@ static unsigned check_binary_integrity(c
 	}
 
 	hmac_size = hex_data_size(data.size);
+
+	/* trim eventual newlines from the end of the data read from file */
+	while ((data.size > 0) && (data.data[data.size - 1] == '\n')) {
+		data.data[data.size - 1] = 0;
+		data.size--;
+	}
+
 	ret = gnutls_hex_decode(&data, hmac, &hmac_size);
 	gnutls_free(data.data);
 
@@ -314,6 +321,31 @@ int _gnutls_fips_perform_self_checks2(vo
 	if (ret < 0) {
 		gnutls_assert();
 		goto error;
+	}
+
+	/* Digest tests */
+	ret = gnutls_digest_self_test(0, GNUTLS_DIG_SHA3_224);
+	if (ret < 0) {
+		gnutls_assert();
+		goto error;
+	}
+
+	ret = gnutls_digest_self_test(0, GNUTLS_DIG_SHA3_256);
+	if (ret < 0) {
+		gnutls_assert();
+		goto error;
+	}
+
+	ret = gnutls_digest_self_test(0, GNUTLS_DIG_SHA3_384);
+	if (ret < 0) {
+		gnutls_assert();
+		goto error;
+	}
+
+	ret = gnutls_digest_self_test(0, GNUTLS_DIG_SHA3_512);
+	if (ret < 0) {
+		gnutls_assert();
+		goto error;
 	}
 
 	/* MAC (includes message digest test) */
diff -NurBbp gnutls28-3.6.6/lib/gnutls_int.h gnutls28-3.6.7/lib/gnutls_int.h
--- gnutls28-3.6.6/lib/gnutls_int.h	2019-01-10 07:51:12.000000000 +0100
+++ gnutls28-3.6.7/lib/gnutls_int.h	2019-04-04 19:26:47.816144097 +0200
@@ -127,16 +127,9 @@ typedef struct {
 #define GNUTLS_MASTER_SIZE 48
 #define GNUTLS_RANDOM_SIZE 32
 
-#define HRR_RANDOM \
-	 "\xCF\x21\xAD\x74\xE5\x9A\x61\x11\xBE\x1D\x8C\x02\x1E\x65\xB8\x91" \
-	 "\xC2\xA2\x11\x16\x7A\xBB\x8C\x5E\x07\x9E\x09\xE2\xC8\xA8\x33\x9C"
-
 /* Under TLS1.3 a hello retry request is sent as server hello */
 #define REAL_HSK_TYPE(t) ((t)==GNUTLS_HANDSHAKE_HELLO_RETRY_REQUEST?GNUTLS_HANDSHAKE_SERVER_HELLO:t)
 
-/* Enable: Appendix D4.  Middlebox Compatibility Mode */
-#define TLS13_APPENDIX_D4 1
-
 /* DTLS */
 #define DTLS_RETRANS_TIMEOUT 1000
 
@@ -325,8 +318,7 @@ typedef enum recv_state_t {
 /* IDs are allocated in a way that all values fit in 64-bit integer as (1<<val) */
 typedef enum extensions_t {
 	GNUTLS_EXTENSION_INVALID = 0xffff,
-	GNUTLS_EXTENSION_MAX_RECORD_SIZE = 0,
-	GNUTLS_EXTENSION_STATUS_REQUEST,
+	GNUTLS_EXTENSION_STATUS_REQUEST = 0,
 	GNUTLS_EXTENSION_CERT_TYPE,
 	GNUTLS_EXTENSION_CLIENT_CERT_TYPE,
 	GNUTLS_EXTENSION_SERVER_CERT_TYPE,
@@ -349,6 +341,7 @@ typedef enum extensions_t {
 	GNUTLS_EXTENSION_EARLY_DATA,
 	GNUTLS_EXTENSION_PSK_KE_MODES,
 	GNUTLS_EXTENSION_RECORD_SIZE_LIMIT,
+	GNUTLS_EXTENSION_MAX_RECORD_SIZE,
 	/*
 	 * pre_shared_key and dumbfw must always be the last extensions,
 	 * in that order */
@@ -1281,6 +1274,9 @@ typedef struct {
 
 	/* A handshake process has been completed */
 	bool initial_negotiation_completed;
+	void *post_negotiation_lock; /* protects access to the variable above
+				      * in the cases where negotiation is incomplete
+				      * after gnutls_handshake() - early/false start */
 
 	/* The type of transport protocol; stream or datagram */
 	transport_t transport;
@@ -1303,8 +1299,12 @@ typedef struct {
 	/* starting time of current handshake */
 	struct timespec handshake_start_time;
 
-	/* end time of current handshake */
-	struct timespec handshake_endtime;
+	/* expected end time of current handshake (start+timeout);
+	 * this is only filled if a handshake_time_ms is set. */
+	struct timespec handshake_abs_timeout;
+
+	/* An estimation of round-trip time under TLS1.3; populated in client side only */
+	unsigned ertt;
 
 	unsigned int handshake_timeout_ms;	/* timeout in milliseconds */
 	unsigned int record_timeout_ms;	/* timeout in milliseconds */
@@ -1357,6 +1357,8 @@ typedef struct {
 					 * server: intend to process early data
 					 */
 #define HSK_RECORD_SIZE_LIMIT_NEGOTIATED (1<<24)
+#define HSK_RECORD_SIZE_LIMIT_SENT (1<<25) /* record_size_limit extension was sent */
+#define HSK_RECORD_SIZE_LIMIT_RECEIVED (1<<26) /* server: record_size_limit extension was seen but not accepted yet */
 
 	/* The hsk_flags are for use within the ongoing handshake;
 	 * they are reset to zero prior to handshake start by gnutls_handshake. */
@@ -1464,6 +1466,10 @@ typedef struct {
 	/* anti-replay measure for 0-RTT mode */
 	gnutls_anti_replay_t anti_replay;
 
+	/* Protects _gnutls_epoch_gc() from _gnutls_epoch_get(); these may be
+	 * called in parallel when false start is used and false start is used. */
+	void *epoch_lock;
+
 	/* If you add anything here, check _gnutls_handshake_internal_state_clear().
 	 */
 } internals_st;
@@ -1546,17 +1552,20 @@ inline static int _gnutls_set_current_ve
 	return 0;
 }
 
+/* Returns the maximum size of the plaintext to be sent, considering
+ * both user-specified/negotiated maximum values.
+ */
 inline static size_t max_user_send_size(gnutls_session_t session,
 					record_parameters_st *
 					record_params)
 {
 	size_t max;
 
-	if (IS_DTLS(session)) {
-		max = MIN(gnutls_dtls_get_data_mtu(session), session->security_parameters.max_record_send_size);
-	} else {
-		max = session->security_parameters.max_record_send_size;
-	}
+	max = MIN(session->security_parameters.max_record_send_size,
+		  session->security_parameters.max_record_recv_size);
+
+	if (IS_DTLS(session))
+		max = MIN(gnutls_dtls_get_data_mtu(session), max);
 
 	return max;
 }
@@ -1566,7 +1575,7 @@ inline static size_t max_user_send_size(
  *
  * This function is made static inline for optimization reasons.
  */
-static inline gnutls_certificate_type_t
+inline static gnutls_certificate_type_t
 get_certificate_type(gnutls_session_t session,
 								gnutls_ctype_target_t target)
 {
diff -NurBbp gnutls28-3.6.6/lib/gnutls.pc.in gnutls28-3.6.7/lib/gnutls.pc.in
--- gnutls28-3.6.6/lib/gnutls.pc.in	2019-01-23 20:33:37.000000000 +0100
+++ gnutls28-3.6.7/lib/gnutls.pc.in	2019-04-04 19:26:47.816144097 +0200
@@ -19,6 +19,6 @@ Description: Transport Security Layer im
 URL: http://www.gnutls.org/
 Version: @VERSION@
 Libs: -L${libdir} -lgnutls
-Libs.private: @LIBINTL@ @LIBSOCKET@ @LIBNSL@ @LIBPTHREAD@ @LIB_SELECT@ @TSS_LIBS@ @GMP_LIBS@ @LIBUNISTRING@ @LIBIDN2_LIBS@ @LIBATOMIC_LIBS@
+Libs.private: @LIBINTL@ @LIBSOCKET@ @INET_PTON_LIB@ @LIBPTHREAD@ @LIB_SELECT@ @TSS_LIBS@ @GMP_LIBS@ @LIBUNISTRING@ @LIBIDN2_LIBS@ @LIBATOMIC_LIBS@
 @GNUTLS_REQUIRES_PRIVATE@
 Cflags: -I${includedir}
diff -NurBbp gnutls28-3.6.6/lib/gthreads.h gnutls28-3.6.7/lib/gthreads.h
--- gnutls28-3.6.6/lib/gthreads.h	2018-03-22 08:56:48.000000000 +0100
+++ gnutls28-3.6.7/lib/gthreads.h	2019-04-04 19:26:47.816144097 +0200
@@ -26,6 +26,8 @@
 # include <threads.h>
 #elif defined(__GNUC__)
 # define _Thread_local __thread
+#elif defined(_MSC_VER)
+# define _Thread_local __declspec(thread)
 #else
 # error Unsupported platform
 #endif
diff -NurBbp gnutls28-3.6.6/lib/handshake.c gnutls28-3.6.7/lib/handshake.c
--- gnutls28-3.6.6/lib/handshake.c	2019-01-05 12:28:47.000000000 +0100
+++ gnutls28-3.6.7/lib/handshake.c	2019-04-04 19:26:47.816144097 +0200
@@ -55,6 +55,7 @@
 #include <dtls.h>
 #include "secrets.h"
 #include "tls13/session_ticket.h"
+#include "locks.h"
 
 #define TRUE 1
 #define FALSE 0
@@ -444,6 +445,9 @@ _gnutls_negotiate_version(gnutls_session
 
 		if (aversion && aversion->id == GNUTLS_TLS1_2) {
 			vers = _gnutls_version_max(session);
+			if (unlikely(vers == NULL))
+				return gnutls_assert_val(GNUTLS_E_NO_CIPHER_SUITES);
+
 			if (vers->id >= GNUTLS_TLS1_2) {
 				session->security_parameters.pversion = aversion;
 				return 0;
@@ -1005,8 +1009,6 @@ int _gnutls_recv_finished(gnutls_session
 	}
 
 
-	session->internals.initial_negotiation_completed = 1;
-
       cleanup:
 	_gnutls_buffer_clear(&buf);
 
@@ -1523,6 +1525,11 @@ _gnutls_recv_handshake(gnutls_session_t
 	switch (hsk.htype) {
 	case GNUTLS_HANDSHAKE_CLIENT_HELLO_V2:
 	case GNUTLS_HANDSHAKE_CLIENT_HELLO:
+		if (!(IS_SERVER(session))) {
+			ret = gnutls_assert_val(GNUTLS_E_UNEXPECTED_PACKET);
+			goto cleanup;
+		}
+
 #ifdef ENABLE_SSL2
 		if (hsk.htype == GNUTLS_HANDSHAKE_CLIENT_HELLO_V2)
 			ret =
@@ -1549,6 +1556,11 @@ _gnutls_recv_handshake(gnutls_session_t
 		break;
 
 	case GNUTLS_HANDSHAKE_SERVER_HELLO:
+		if (IS_SERVER(session)) {
+			ret = gnutls_assert_val(GNUTLS_E_UNEXPECTED_PACKET);
+			goto cleanup;
+		}
+
 		ret = read_server_hello(session, hsk.data.data,
 					hsk.data.length);
 
@@ -1559,6 +1571,11 @@ _gnutls_recv_handshake(gnutls_session_t
 
 		break;
 	case GNUTLS_HANDSHAKE_HELLO_VERIFY_REQUEST:
+		if (IS_SERVER(session)) {
+			ret = gnutls_assert_val(GNUTLS_E_UNEXPECTED_PACKET);
+			goto cleanup;
+		}
+
 		ret =
 		    recv_hello_verify_request(session,
 					      hsk.data.data,
@@ -1576,6 +1593,12 @@ _gnutls_recv_handshake(gnutls_session_t
 	case GNUTLS_HANDSHAKE_HELLO_RETRY_REQUEST: {
 		/* hash buffer synth message is generated during hello retry parsing */
 		gnutls_datum_t hrr = {hsk.data.data, hsk.data.length};
+
+		if (IS_SERVER(session)) {
+			ret = gnutls_assert_val(GNUTLS_E_UNEXPECTED_PACKET);
+			goto cleanup;
+		}
+
 		ret =
 		    _gnutls13_recv_hello_retry_request(session,
 						       &hsk.data);
@@ -2138,6 +2161,9 @@ static int send_client_hello(gnutls_sess
 
 		if (hver == NULL) {
 			gnutls_assert();
+			if (session->internals.flags & INT_FLAG_NO_TLS13)
+				ret = GNUTLS_E_INSUFFICIENT_CREDENTIALS;
+			else
 			ret = GNUTLS_E_NO_PRIORITIES_WERE_SET;
 			goto cleanup;
 		}
@@ -2460,10 +2486,9 @@ recv_hello_verify_request(gnutls_session
 	unsigned int nb_verifs;
 	int ret;
 
-	if (!IS_DTLS(session)
-	    || session->security_parameters.entity == GNUTLS_SERVER) {
+	if (!IS_DTLS(session)) {
 		gnutls_assert();
-		return GNUTLS_E_INTERNAL_ERROR;
+		return GNUTLS_E_UNEXPECTED_PACKET;
 	}
 
 	nb_verifs = ++session->internals.dtls.hsk_hello_verify_requests;
@@ -2474,7 +2499,6 @@ recv_hello_verify_request(gnutls_session
 		return GNUTLS_E_UNEXPECTED_PACKET;
 	}
 
-	/* TODO: determine if we need to do anything with the server version field */
 	DECR_LEN(len, 2);
 	pos += 2;
 
@@ -2758,7 +2782,7 @@ int gnutls_handshake(gnutls_session_t se
 		gnutls_gettime(&session->internals.handshake_start_time);
 
 		tmo_ms = session->internals.handshake_timeout_ms;
-		end = &session->internals.handshake_endtime;
+		end = &session->internals.handshake_abs_timeout;
 		start = &session->internals.handshake_start_time;
 
 		if (tmo_ms && end->tv_sec == 0 && end->tv_nsec == 0) {
@@ -2811,6 +2835,18 @@ int gnutls_handshake(gnutls_session_t se
 		_gnutls_epoch_bump(session);
 	}
 
+	/* Give an estimation of the round-trip under TLS1.3, used by gnutls_session_get_data2() */
+	if (!IS_SERVER(session) && vers->tls13_sem) {
+		struct timespec handshake_finish_time;
+		gnutls_gettime(&handshake_finish_time);
+
+		if (!(session->internals.hsk_flags & HSK_HRR_RECEIVED)) {
+			session->internals.ertt = timespec_sub_ms(&handshake_finish_time, &session->internals.handshake_start_time)/2;
+		} else {
+			session->internals.ertt = timespec_sub_ms(&handshake_finish_time, &session->internals.handshake_start_time)/4;
+		}
+	}
+
 	return 0;
 }
 
@@ -3138,7 +3174,10 @@ static int handshake_client(gnutls_sessi
 	}
 
 	/* explicitly reset any false start flags */
+	gnutls_mutex_lock(&session->internals.post_negotiation_lock);
+	session->internals.initial_negotiation_completed = 1;
 	session->internals.recv_state = RECV_STATE_0;
+	gnutls_mutex_unlock(&session->internals.post_negotiation_lock);
 
 	return 0;
 }
@@ -3554,6 +3592,10 @@ static int handshake_server(gnutls_sessi
 		break;
 	}
 
+	/* no lock of post_negotiation_lock is required here as this is not run
+	 * after handshake */
+	session->internals.initial_negotiation_completed = 1;
+
 	return _gnutls_check_id_for_change(session);
 }
 
@@ -3640,9 +3682,6 @@ gnutls_handshake_get_last_out(gnutls_ses
 }
 
 /* This returns the session hash as in draft-ietf-tls-session-hash-02.
- *
- * FIXME: It duplicates some of the actions in _gnutls_handshake_sign_crt_vrfy*.
- * See whether they can be merged.
  */
 int _gnutls_handshake_get_session_hash(gnutls_session_t session, gnutls_datum_t *shash)
 {
diff -NurBbp gnutls28-3.6.6/lib/handshake-defs.h gnutls28-3.6.7/lib/handshake-defs.h
--- gnutls28-3.6.6/lib/handshake-defs.h	1970-01-01 01:00:00.000000000 +0100
+++ gnutls28-3.6.7/lib/handshake-defs.h	2019-03-27 07:15:41.000000000 +0100
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ * Author: Nikos Mavrogiannopoulos
+ *
+ * This file is part of GnuTLS.
+ *
+ * The GnuTLS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>
+ *
+ */
+#ifndef HANDSHAKE_DEFS_H
+#define HANDSHAKE_DEFS_H
+
+#define EARLY_TRAFFIC_LABEL "c e traffic"
+#define EXT_BINDER_LABEL "ext binder"
+#define RES_BINDER_LABEL "res binder"
+#define EARLY_EXPORTER_MASTER_LABEL "e exp master"
+#define HANDSHAKE_CLIENT_TRAFFIC_LABEL "c hs traffic"
+#define HANDSHAKE_SERVER_TRAFFIC_LABEL "s hs traffic"
+#define DERIVED_LABEL "derived"
+#define APPLICATION_CLIENT_TRAFFIC_LABEL "c ap traffic"
+#define APPLICATION_SERVER_TRAFFIC_LABEL "s ap traffic"
+#define APPLICATION_TRAFFIC_UPDATE "traffic upd"
+#define EXPORTER_MASTER_LABEL "exp master"
+#define RMS_MASTER_LABEL "res master"
+#define EXPORTER_LABEL "exp master"
+#define RESUMPTION_LABEL "resumption"
+
+#define HRR_RANDOM \
+	 "\xCF\x21\xAD\x74\xE5\x9A\x61\x11\xBE\x1D\x8C\x02\x1E\x65\xB8\x91" \
+	 "\xC2\xA2\x11\x16\x7A\xBB\x8C\x5E\x07\x9E\x09\xE2\xC8\xA8\x33\x9C"
+
+#define TLS13_TICKETS_TO_SEND 2
+
+/* Enable: Appendix D4.  Middlebox Compatibility Mode */
+#define TLS13_APPENDIX_D4 1
+
+#endif /* HANDSHAKE_DEFS_H */
diff -NurBbp gnutls28-3.6.6/lib/handshake.h gnutls28-3.6.7/lib/handshake.h
--- gnutls28-3.6.6/lib/handshake.h	2018-12-12 06:18:37.000000000 +0100
+++ gnutls28-3.6.7/lib/handshake.h	2019-04-04 19:26:47.816144097 +0200
@@ -115,7 +115,7 @@ int _gnutls13_handshake_hash_buffers_syn
 /* return the remaining time in ms */
 inline static int handshake_remaining_time(gnutls_session_t session)
 {
-	struct timespec *end = &session->internals.handshake_endtime;
+	struct timespec *end = &session->internals.handshake_abs_timeout;
 
 	if (end->tv_sec || end->tv_nsec) {
 		struct timespec now;
@@ -153,20 +153,7 @@ int _gnutls_handshake_get_session_hash(g
 int _gnutls_check_id_for_change(gnutls_session_t session);
 int _gnutls_check_if_cert_hash_is_same(gnutls_session_t session, gnutls_certificate_credentials_t cred);
 
-#define EARLY_TRAFFIC_LABEL "c e traffic"
-#define EXT_BINDER_LABEL "ext binder"
-#define RES_BINDER_LABEL "res binder"
-#define EARLY_EXPORTER_MASTER_LABEL "e exp master"
-#define HANDSHAKE_CLIENT_TRAFFIC_LABEL "c hs traffic"
-#define HANDSHAKE_SERVER_TRAFFIC_LABEL "s hs traffic"
-#define DERIVED_LABEL "derived"
-#define APPLICATION_CLIENT_TRAFFIC_LABEL "c ap traffic"
-#define APPLICATION_SERVER_TRAFFIC_LABEL "s ap traffic"
-#define APPLICATION_TRAFFIC_UPDATE "traffic upd"
-#define EXPORTER_MASTER_LABEL "exp master"
-#define RMS_MASTER_LABEL "res master"
-#define EXPORTER_LABEL "exp master"
-#define RESUMPTION_LABEL "resumption"
+#include "handshake-defs.h"
 
 int _gnutls_call_hook_func(gnutls_session_t session,
 			   gnutls_handshake_description_t type,
diff -NurBbp gnutls28-3.6.6/lib/handshake-tls13.c gnutls28-3.6.7/lib/handshake-tls13.c
--- gnutls28-3.6.6/lib/handshake-tls13.c	2018-11-18 19:53:49.000000000 +0100
+++ gnutls28-3.6.7/lib/handshake-tls13.c	2019-04-04 19:26:47.816144097 +0200
@@ -56,6 +56,7 @@
 #include "tls13/finished.h"
 #include "tls13/key_update.h"
 #include "ext/pre_shared_key.h"
+#include "locks.h"
 
 static int generate_rms_keys(gnutls_session_t session);
 static int generate_hs_traffic_keys(gnutls_session_t session);
@@ -202,8 +203,8 @@ int _gnutls13_handshake_client(gnutls_se
 		return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR);
 	}
 
-
-	/* explicitly reset any false start flags */
+	/* no lock of post_negotiation_lock is required here as this is not run
+	 * after handshake */
 	session->internals.recv_state = RECV_STATE_0;
 	session->internals.initial_negotiation_completed = 1;
 
@@ -361,8 +362,6 @@ static int generate_hs_traffic_keys(gnut
 	return 0;
 }
 
-#define TICKETS_TO_SEND 1
-
 /*
  * _gnutls13_handshake_server
  * This function does the server stuff of the handshake protocol.
@@ -509,7 +508,7 @@ int _gnutls13_handshake_server(gnutls_se
 			_gnutls_set_resumed_parameters(session);
 
 		if (session->internals.hsk_flags & HSK_EARLY_START_USED) {
-			ret = _gnutls13_send_session_ticket(session, TICKETS_TO_SEND,
+			ret = _gnutls13_send_session_ticket(session, TLS13_TICKETS_TO_SEND,
 							    AGAIN(STATE109));
 
 			STATE = STATE109;
@@ -565,7 +564,7 @@ int _gnutls13_handshake_server(gnutls_se
 		FALLTHROUGH;
 	case STATE115:
 		if (!(session->internals.hsk_flags & (HSK_TLS13_TICKET_SENT|HSK_EARLY_START_USED))) {
-			ret = _gnutls13_send_session_ticket(session, TICKETS_TO_SEND,
+			ret = _gnutls13_send_session_ticket(session, TLS13_TICKETS_TO_SEND,
 							    AGAIN(STATE115));
 			STATE = STATE115;
 			IMED_RET("send session ticket", ret, 0);
@@ -577,9 +576,11 @@ int _gnutls13_handshake_server(gnutls_se
 		return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR);
 	}
 
-	/* explicitly reset any false start flags */
+	/* explicitly reset any early start flags */
+	gnutls_mutex_lock(&session->internals.post_negotiation_lock);
 	session->internals.recv_state = RECV_STATE_0;
 	session->internals.initial_negotiation_completed = 1;
+	gnutls_mutex_unlock(&session->internals.post_negotiation_lock);
 
 	SAVE_TRANSCRIPT;
 
@@ -604,6 +605,8 @@ _gnutls13_recv_async_handshake(gnutls_se
 		return gnutls_assert_val(GNUTLS_E_UNEXPECTED_PACKET);
 
 	do {
+		_gnutls_handshake_buffer_init(&hsk);
+
 		/* the received handshake message has already been pushed into
 		 * handshake buffers. As we do not need to use the handshake hash
 		 * buffers we call the lower level receive functions */
@@ -735,7 +738,7 @@ _gnutls13_recv_async_handshake(gnutls_se
  *
  * Sends a fresh session ticket to the peer. This is relevant only
  * in server side under TLS1.3. This function may also return %GNUTLS_E_AGAIN
- * or %GNUTLS_E_INTERRUPTED.
+ * or %GNUTLS_E_INTERRUPTED and in that case it must be called again.
  *
  * Returns: %GNUTLS_E_SUCCESS on success, or a negative error code.
  **/
diff -NurBbp gnutls28-3.6.6/lib/hello_ext.c gnutls28-3.6.7/lib/hello_ext.c
--- gnutls28-3.6.6/lib/hello_ext.c	2019-01-10 07:41:58.000000000 +0100
+++ gnutls28-3.6.7/lib/hello_ext.c	2019-04-04 19:26:47.820143979 +0200
@@ -64,7 +64,6 @@ unset_ext_data(gnutls_session_t session,
 static void unset_resumed_ext_data(gnutls_session_t session, const struct hello_ext_entry_st *, unsigned idx);
 
 static hello_ext_entry_st const *extfunc[MAX_EXT_TYPES+1] = {
-	[GNUTLS_EXTENSION_MAX_RECORD_SIZE] = &ext_mod_max_record_size,
 	[GNUTLS_EXTENSION_EXT_MASTER_SECRET] = &ext_mod_ext_master_secret,
 	[GNUTLS_EXTENSION_SUPPORTED_VERSIONS] = &ext_mod_supported_versions,
 	[GNUTLS_EXTENSION_POST_HANDSHAKE] = &ext_mod_post_handshake,
@@ -95,9 +94,10 @@ static hello_ext_entry_st const *extfunc
 #ifdef ENABLE_ALPN
 	[GNUTLS_EXTENSION_ALPN] = &ext_mod_alpn,
 #endif
+	[GNUTLS_EXTENSION_RECORD_SIZE_LIMIT] = &ext_mod_record_size_limit,
+	[GNUTLS_EXTENSION_MAX_RECORD_SIZE] = &ext_mod_max_record_size,
 	[GNUTLS_EXTENSION_PSK_KE_MODES] = &ext_mod_psk_ke_modes,
 	[GNUTLS_EXTENSION_PRE_SHARED_KEY] = &ext_mod_pre_shared_key,
-	[GNUTLS_EXTENSION_RECORD_SIZE_LIMIT] = &ext_mod_record_size_limit,
 	/* This must be the last extension registered.
 	 */
 	[GNUTLS_EXTENSION_DUMBFW] = &ext_mod_dumbfw,
@@ -464,9 +464,8 @@ void _gnutls_hello_ext_deinit(void)
 			continue;
 
 		if (extfunc[i]->free_struct != 0) {
-			gnutls_free((void*)extfunc[i]->name);
-			gnutls_free((void*)extfunc[i]);
-			extfunc[i] = NULL;
+			gnutls_free(((hello_ext_entry_st *)extfunc[i])->name);
+			gnutls_free(extfunc[i]);
 		}
 	}
 }
diff -NurBbp gnutls28-3.6.6/lib/hello_ext.h gnutls28-3.6.7/lib/hello_ext.h
--- gnutls28-3.6.6/lib/hello_ext.h	2018-08-20 21:47:04.000000000 +0200
+++ gnutls28-3.6.7/lib/hello_ext.h	2019-04-04 19:26:47.820143979 +0200
@@ -159,7 +159,7 @@ typedef struct hello_ext_entry_st {
 inline static unsigned
 _gnutls_hello_ext_is_present(gnutls_session_t session, extensions_t id)
 {
-	if (id != 0 && ((1 << id) & session->internals.used_exts))
+	if ((1 << id) & session->internals.used_exts)
 		return 1;
 
 	return 0;
diff -NurBbp gnutls28-3.6.6/lib/includes/gnutls/gnutls.h.in gnutls28-3.6.7/lib/includes/gnutls/gnutls.h.in
--- gnutls28-3.6.6/lib/includes/gnutls/gnutls.h.in	2018-12-15 22:12:46.000000000 +0100
+++ gnutls28-3.6.7/lib/includes/gnutls/gnutls.h.in	2019-04-04 19:26:47.820143979 +0200
@@ -37,15 +37,12 @@
 #ifndef GNUTLS_H
 #define GNUTLS_H
 
+/* Get ssize_t. */
+#include <sys/types.h>
+
 /* Get size_t. */
 #include <stddef.h>
-/* Get ssize_t. */
-#ifndef HAVE_SSIZE_T
-#define HAVE_SSIZE_T
-/* *INDENT-OFF* */
-@DEFINE_SSIZE_T@
-/* *INDENT-ON* */
-#endif
+
 /* Get time_t. */
 #include <time.h>
 
@@ -529,6 +526,7 @@ typedef enum {
  *   recognized.
  * @GNUTLS_A_UNKNOWN_PSK_IDENTITY: The SRP/PSK username is missing
  *   or not known.
+ * @GNUTLS_A_CERTIFICATE_REQUIRED: Certificate is required.
  * @GNUTLS_A_NO_APPLICATION_PROTOCOL: The ALPN protocol requested is
  *   not supported by the peer.
  *
@@ -565,6 +563,7 @@ typedef enum {
 	GNUTLS_A_CERTIFICATE_UNOBTAINABLE = 111,
 	GNUTLS_A_UNRECOGNIZED_NAME = 112,
 	GNUTLS_A_UNKNOWN_PSK_IDENTITY = 115,
+	GNUTLS_A_CERTIFICATE_REQUIRED = 116,
 	GNUTLS_A_NO_APPLICATION_PROTOCOL = 120,
 	GNUTLS_A_MAX = GNUTLS_A_NO_APPLICATION_PROTOCOL
 } gnutls_alert_description_t;
@@ -2197,6 +2196,10 @@ extern _SYM_EXPORT gnutls_realloc_functi
 extern _SYM_EXPORT gnutls_calloc_function gnutls_calloc;
 extern _SYM_EXPORT gnutls_free_function gnutls_free;
 
+#ifdef GNUTLS_INTERNAL_BUILD
+#define gnutls_free(a) gnutls_free((void *) (a)), a=NULL
+#endif
+
 extern _SYM_EXPORT char *(*gnutls_strdup) (const char *);
 
 /* a variant of memset that doesn't get optimized out */
@@ -3141,6 +3144,8 @@ void gnutls_fips140_set_mode(gnutls_fips
 #define GNUTLS_E_TOO_MANY_EMPTY_PACKETS -78
 #define GNUTLS_E_UNKNOWN_PK_ALGORITHM -80
 #define GNUTLS_E_TOO_MANY_HANDSHAKE_PACKETS -81
+#define GNUTLS_E_RECEIVED_DISALLOWED_NAME -82 /* GNUTLS_A_ILLEGAL_PARAMETER */
+#define GNUTLS_E_CERTIFICATE_REQUIRED -112 /* GNUTLS_A_CERTIFICATE_REQUIRED */
 
   /* returned if you need to generate temporary RSA
    * parameters. These are needed for export cipher suites.
diff -NurBbp gnutls28-3.6.6/lib/includes/gnutls/pkcs11.h gnutls28-3.6.7/lib/includes/gnutls/pkcs11.h
--- gnutls28-3.6.6/lib/includes/gnutls/pkcs11.h	2018-05-26 05:44:29.000000000 +0200
+++ gnutls28-3.6.7/lib/includes/gnutls/pkcs11.h	2019-04-04 19:26:47.820143979 +0200
@@ -324,7 +324,8 @@ int gnutls_pkcs11_obj_set_info(gnutls_pk
  * @GNUTLS_PKCS11_TOKEN_SERIAL: The token's serial number (string)
  * @GNUTLS_PKCS11_TOKEN_MANUFACTURER: The token's manufacturer (string)
  * @GNUTLS_PKCS11_TOKEN_MODEL: The token's model (string)
- * @GNUTLS_PKCS11_TOKEN_MODNAME: The token's module name (string - since 3.4.3)
+ * @GNUTLS_PKCS11_TOKEN_MODNAME: The token's module name (string - since 3.4.3). This value is
+ *   unavailable for providers which were manually loaded.
  *
  * Enumeration of types for retrieving token information.
  */
diff -NurBbp gnutls28-3.6.6/lib/Makefile.am gnutls28-3.6.7/lib/Makefile.am
--- gnutls28-3.6.6/lib/Makefile.am	2019-01-24 20:15:38.000000000 +0100
+++ gnutls28-3.6.7/lib/Makefile.am	2019-04-04 19:26:47.808144337 +0200
@@ -72,11 +72,11 @@ COBJECTS = range.c record.c compress.c d
 	pk.c cert-cred.c global.c constate.c anon_cred.c pkix_asn1_tab.c gnutls_asn1_tab.c	\
 	mem.c fingerprint.c tls-sig.c ecc.c alert.c privkey_raw.c atomic.h	\
 	system/certs.c system/threads.c system/fastopen.c system/sockets.c	\
-	system/inet_ntop.c str-iconv.c system.c \
+	str-iconv.c system.c \
 	str.c str-unicode.c str-idna.c state.c cert-cred-x509.c file.c supplemental.c	\
 	random.c crypto-api.c crypto-api.h privkey.c pcert.c pubkey.c locks.c dtls.c \
 	system_override.c crypto-backend.c verify-tofu.c pin.c tpm.c fips.c	\
-	safe-memfuncs.c system/inet_pton.c atfork.c atfork.h randomart.c \
+	safe-memfuncs.c atfork.c atfork.h randomart.c \
 	system-keys.h urls.c urls.h prf.c auto-verify.c dh-session.c \
 	cert-session.c handshake-checks.c dtls-sw.c dh-primes.c openpgp_compat.c \
 	crypto-selftests.c crypto-selftests-pk.c secrets.c extv.c extv.h \
@@ -115,7 +115,7 @@ HFILES = abstract_int.h debug.h cipher.h
 	buffers.h errors.h gnutls_int.h dtls.h	\
 	handshake.h num.h algorithms.h		\
 	dh.h kx.h hash_int.h cipher_int.h	\
-	db.h auth.h hello_ext.h	\
+	db.h auth.h hello_ext.h	handshake-defs.h \
 	x509_b64.h sslv2_compat.h datum.h \
 	mpi.h pk.h record.h		\
 	constate.h global.h tls-sig.h mem.h	\
diff -NurBbp gnutls28-3.6.6/lib/mpi.c gnutls28-3.6.7/lib/mpi.c
--- gnutls28-3.6.6/lib/mpi.c	2018-09-23 08:33:07.000000000 +0200
+++ gnutls28-3.6.7/lib/mpi.c	2019-04-04 19:26:47.820143979 +0200
@@ -88,7 +88,6 @@ _gnutls_mpi_random_modp(bigint_t r, bigi
 
 	if (buf_release != 0) {
 		gnutls_free(buf);
-		buf = NULL;
 	}
 
 	if (r != NULL) {
diff -NurBbp gnutls28-3.6.6/lib/nettle/gost/nettle-write.h gnutls28-3.6.7/lib/nettle/gost/nettle-write.h
--- gnutls28-3.6.6/lib/nettle/gost/nettle-write.h	2018-06-24 21:33:16.000000000 +0200
+++ gnutls28-3.6.7/lib/nettle/gost/nettle-write.h	2019-04-04 19:26:47.820143979 +0200
@@ -37,7 +37,7 @@
 /* For size_t */
 #include <stddef.h>
 
-#include <nettle/nettle-stdint.h>
+#include <stdint.h>
 
 /* Write the word array at SRC to the byte array at DST, using little
    endian (le) or big endian (be) byte order, and truncating the
diff -NurBbp gnutls28-3.6.6/lib/nettle/mpi.c gnutls28-3.6.7/lib/nettle/mpi.c
--- gnutls28-3.6.6/lib/nettle/mpi.c	2018-06-24 21:33:16.000000000 +0200
+++ gnutls28-3.6.7/lib/nettle/mpi.c	2019-04-04 19:26:47.820143979 +0200
@@ -122,7 +122,6 @@ static int wrap_nettle_mpi_init_multi(bi
 fail:
 	mpz_clear(TOMPZ(*w));
 	gnutls_free(*w);
-	*w = NULL;
 
 	va_start(args, w);
 	
@@ -131,7 +130,6 @@ fail:
 		if (next != last_failed) {
 			mpz_clear(TOMPZ(*next));
 			gnutls_free(*next);
-			*next = NULL;
 		}
 	} while(next != last_failed);
 	
diff -NurBbp gnutls28-3.6.6/lib/nettle/pk.c gnutls28-3.6.7/lib/nettle/pk.c
--- gnutls28-3.6.6/lib/nettle/pk.c	2018-12-01 06:21:11.000000000 +0100
+++ gnutls28-3.6.7/lib/nettle/pk.c	2019-04-04 19:26:47.820143979 +0200
@@ -371,7 +371,6 @@ dh_cleanup:
 
 			if (_gnutls_mem_is_zero(out->data, out->size)) {
 				gnutls_free(out->data);
-				out->data = NULL;
 				gnutls_assert();
 				ret = GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER;
 				goto cleanup;
@@ -2254,8 +2253,6 @@ wrap_nettle_pk_generate_keys(gnutls_pk_a
 	params->params_nr = 0;
 	gnutls_free(params->raw_priv.data);
 	gnutls_free(params->raw_pub.data);
-	params->raw_priv.data = NULL;
-	params->raw_pub.data = NULL;
 
 	FAIL_IF_LIB_ERROR;
 	return ret;
diff -NurBbp gnutls28-3.6.6/lib/ocsp-api.c gnutls28-3.6.7/lib/ocsp-api.c
--- gnutls28-3.6.6/lib/ocsp-api.c	2018-04-30 11:04:44.000000000 +0200
+++ gnutls28-3.6.7/lib/ocsp-api.c	2019-04-04 19:26:47.820143979 +0200
@@ -473,7 +473,6 @@ gnutls_certificate_set_ocsp_status_reque
 			nresp++;
 
 			gnutls_free(der.data);
-			der.data = NULL;
 
 			p.data++;
 			p.size--;
diff -NurBbp gnutls28-3.6.6/lib/pk.c gnutls28-3.6.7/lib/pk.c
--- gnutls28-3.6.6/lib/pk.c	2018-09-23 08:33:07.000000000 +0200
+++ gnutls28-3.6.7/lib/pk.c	2019-04-04 19:26:47.824143860 +0200
@@ -537,8 +537,6 @@ void gnutls_pk_params_release(gnutls_pk_
 	}
 	gnutls_free(p->raw_priv.data);
 	gnutls_free(p->raw_pub.data);
-	p->raw_priv.data = NULL;
-	p->raw_pub.data = NULL;
 
 	p->params_nr = 0;
 }
diff -NurBbp gnutls28-3.6.6/lib/pkcs11.c gnutls28-3.6.7/lib/pkcs11.c
--- gnutls28-3.6.6/lib/pkcs11.c	2019-01-05 12:28:47.000000000 +0100
+++ gnutls28-3.6.7/lib/pkcs11.c	2019-04-04 19:26:47.824143860 +0200
@@ -1236,7 +1236,6 @@ int gnutls_pkcs11_obj_init(gnutls_pkcs11
 	(*obj)->info = p11_kit_uri_new();
 	if ((*obj)->info == NULL) {
 		gnutls_free(*obj);
-		*obj = NULL;
 		gnutls_assert();
 		return GNUTLS_E_MEMORY_ERROR;
 	}
@@ -2255,7 +2254,7 @@ unsigned int pkcs11_obj_flags_to_int(uns
 		ret_flags |= SESSION_LOGIN | SESSION_FORCE_LOGIN;
 
 	if (flags & GNUTLS_PKCS11_OBJ_FLAG_LOGIN_SO)
-		ret_flags |= SESSION_LOGIN | SESSION_SO | SESSION_FORCE_LOGIN;
+		ret_flags |= SESSION_LOGIN | SESSION_SO | SESSION_FORCE_LOGIN | SESSION_WRITE;
 
 	if (flags & GNUTLS_PKCS11_OBJ_FLAG_PRESENT_IN_TRUSTED_MODULE)
 		ret_flags |= SESSION_TRUSTED;
@@ -2475,7 +2474,6 @@ gnutls_pkcs11_token_get_info(const char
 {
 	struct p11_kit_uri *info = NULL;
 	const uint8_t *str;
-	size_t str_max;
 	char *temp_str = NULL;
 	size_t len;
 	int ret;
@@ -2491,19 +2489,19 @@ gnutls_pkcs11_token_get_info(const char
 	switch (ttype) {
 	case GNUTLS_PKCS11_TOKEN_LABEL:
 		str = p11_kit_uri_get_token_info(info)->label;
-		str_max = 32;
+		len = p11_kit_space_strlen(str, 32);
 		break;
 	case GNUTLS_PKCS11_TOKEN_SERIAL:
 		str = p11_kit_uri_get_token_info(info)->serial_number;
-		str_max = 16;
+		len = p11_kit_space_strlen(str, 16);
 		break;
 	case GNUTLS_PKCS11_TOKEN_MANUFACTURER:
 		str = p11_kit_uri_get_token_info(info)->manufacturer_id;
-		str_max = 32;
+		len = p11_kit_space_strlen(str, 32);
 		break;
 	case GNUTLS_PKCS11_TOKEN_MODEL:
 		str = p11_kit_uri_get_token_info(info)->model;
-		str_max = 16;
+		len = p11_kit_space_strlen(str, 16);
 		break;
 	case GNUTLS_PKCS11_TOKEN_MODNAME: {
 		struct find_token_modname tn;
@@ -2518,11 +2516,12 @@ gnutls_pkcs11_token_get_info(const char
 		}
 
 		temp_str = tn.modname;
-		if (temp_str == NULL) {
-			gnutls_assert();
-			str_max = 0;
-		} else {
+		if (temp_str) {
 			str = (uint8_t *)temp_str;
+			len = strlen(temp_str);
+		} else {
+			gnutls_assert();
+			len = 0;
 		}
 		break;
 	}
@@ -2532,19 +2531,7 @@ gnutls_pkcs11_token_get_info(const char
 		goto cleanup;
 	}
 
-	if (temp_str)
-		len = strlen(temp_str);
-	else if (str_max == 0)
-		len = 0;
-	else
-		len = p11_kit_space_strlen(str, str_max);
-
-	if (len + 1 > *output_size) {
-		*output_size = len + 1;
-		ret = GNUTLS_E_SHORT_MEMORY_BUFFER;
-		goto cleanup;
-	}
-
+	if (len < *output_size) {
 	if (len)
 		memcpy(output, str, len);
 	((char *) output)[len] = '\0';
@@ -2548,10 +2535,12 @@ gnutls_pkcs11_token_get_info(const char
 	if (len)
 		memcpy(output, str, len);
 	((char *) output)[len] = '\0';
-
 	*output_size = len;
-
 	ret = 0;
+	} else {
+		*output_size = len + 1;
+		ret = GNUTLS_E_SHORT_MEMORY_BUFFER;
+	}
 
  cleanup:
 	free(temp_str);
@@ -3010,7 +2999,6 @@ find_privkeys(struct pkcs11_session_info
 
 	/* Find an object with private key class and a certificate ID
 	 * which matches the certificate. */
-	/* FIXME: also match the cert subject. */
 	a[0].type = CKA_CLASS;
 	a[0].value = &class;
 	a[0].value_len = sizeof class;
diff -NurBbp gnutls28-3.6.6/lib/pkcs11_privkey.c gnutls28-3.6.7/lib/pkcs11_privkey.c
--- gnutls28-3.6.6/lib/pkcs11_privkey.c	2019-01-23 20:33:37.000000000 +0100
+++ gnutls28-3.6.7/lib/pkcs11_privkey.c	2019-04-04 19:26:47.824143860 +0200
@@ -443,7 +443,6 @@ _gnutls_pkcs11_privkey_sign(gnutls_pkcs1
 		}
 
 		gnutls_free(tmp.data);
-		tmp.data = NULL;
 	} else {
 		signature->size = siglen;
 		signature->data = tmp.data;
@@ -521,10 +520,8 @@ gnutls_pkcs11_privkey_import_url(gnutls_
 
 	memset(&pkey->sinfo, 0, sizeof(pkey->sinfo));
 
-	if (pkey->url) {
+	if (pkey->url)
 		gnutls_free(pkey->url);
-		pkey->url = NULL;
-	}
 
 	if (pkey->uinfo) {
 		p11_kit_uri_free(pkey->uinfo);
@@ -621,7 +618,6 @@ gnutls_pkcs11_privkey_import_url(gnutls_
 		pkey->uinfo = NULL;
 	}
 	gnutls_free(pkey->url);
-	pkey->url = NULL;
 
 	return ret;
 }
diff -NurBbp gnutls28-3.6.6/lib/pkcs11_secret.c gnutls28-3.6.7/lib/pkcs11_secret.c
--- gnutls28-3.6.6/lib/pkcs11_secret.c	2018-05-12 21:38:18.000000000 +0200
+++ gnutls28-3.6.7/lib/pkcs11_secret.c	2019-04-04 19:26:47.824143860 +0200
@@ -89,8 +89,8 @@ gnutls_pkcs11_copy_secret_key(const char
 		return ret;
 	}
 
-	/* FIXME: copy key usage flags */
-
+	/* We do not copy key usage flags.
+	 */
 	a[0].type = CKA_CLASS;
 	a[0].value = &class;
 	a[0].value_len = sizeof(class);
diff -NurBbp gnutls28-3.6.6/lib/pkcs11_write.c gnutls28-3.6.7/lib/pkcs11_write.c
--- gnutls28-3.6.6/lib/pkcs11_write.c	2018-12-01 06:21:11.000000000 +0100
+++ gnutls28-3.6.7/lib/pkcs11_write.c	2019-04-04 19:26:47.824143860 +0200
@@ -187,6 +187,8 @@ gnutls_pkcs11_copy_x509_crt2(const char
 		a[1].value_len = cid->size;
 	}
 
+	/* we do not use the key usage flags; these are apparent from
+	 * the certificate itself. */
 	a[2].type = CKA_VALUE;
 	a[2].value = der;
 	a[2].value_len = der_size;
@@ -196,7 +198,6 @@ gnutls_pkcs11_copy_x509_crt2(const char
 	a[4].type = CKA_CERTIFICATE_TYPE;
 	a[4].value = &type;
 	a[4].value_len = sizeof(type);
-	/* FIXME: copy key usage flags */
 
 	a_val = 5;
 
@@ -268,7 +269,6 @@ static void clean_pubkey(struct ck_attri
 			case CKA_EC_PARAMS:
 			case CKA_EC_POINT:
 				gnutls_free(a[i].value);
-				a[i].value = NULL;
 				break;
 		}
 	}
@@ -716,7 +716,6 @@ gnutls_pkcs11_copy_x509_privkey2(const c
 	pk = gnutls_x509_privkey_get_pk_algorithm(key);
 	FIX_KEY_USAGE(pk, key_usage);
 
-	/* FIXME: copy key usage flags */
 	a_val = 0;
 	a[a_val].type = CKA_CLASS;
 	a[a_val].value = &class;
diff -NurBbp gnutls28-3.6.6/lib/record.c gnutls28-3.6.7/lib/record.c
--- gnutls28-3.6.6/lib/record.c	2019-01-05 12:28:47.000000000 +0100
+++ gnutls28-3.6.7/lib/record.c	2019-04-04 19:26:47.824143860 +0200
@@ -53,6 +53,7 @@
 #include <dh.h>
 #include <random.h>
 #include <xsize.h>
+#include "locks.h"
 
 struct tls_record_st {
 	uint16_t header_size;
@@ -1547,6 +1548,15 @@ _gnutls_recv_in_buffers(gnutls_session_t
 		goto begin;
 	}
 
+	if (_mbuffer_get_udata_size(decrypted) > max_decrypted_size(session)) {
+		_gnutls_audit_log
+		    (session, "Received packet with illegal length: %u\n",
+		     (unsigned int) ret);
+
+		ret = gnutls_assert_val(GNUTLS_E_RECORD_OVERFLOW);
+		goto sanity_check_error;
+	}
+
 #ifdef ENABLE_SSL2
 	if (record.v2) {
 		decrypted->htype = GNUTLS_HANDSHAKE_CLIENT_HELLO_V2;
@@ -1685,8 +1695,7 @@ check_session_status(gnutls_session_t se
 		    !(session->internals.flags & GNUTLS_ENABLE_FALSE_START))
 			return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR);
 
-		/* Attempt to complete handshake */
-
+		/* Attempt to complete handshake - we only need to receive */
 		session->internals.recv_state = RECV_STATE_FALSE_START_HANDLING;
 		ret = gnutls_handshake(session);
 		if (ret < 0) {
@@ -1705,7 +1714,7 @@ check_session_status(gnutls_session_t se
 		    !(session->internals.flags & GNUTLS_ENABLE_EARLY_START))
 			return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR);
 
-		/* Attempt to complete handshake */
+		/* Attempt to complete handshake - we only need to receive */
 		session->internals.recv_state = RECV_STATE_EARLY_START_HANDLING;
 		ret = gnutls_handshake(session);
 		if (ret < 0) {
@@ -1978,13 +1987,24 @@ gnutls_record_send2(gnutls_session_t ses
 
 	if (unlikely(!session->internals.initial_negotiation_completed)) {
 		/* this is to protect buggy applications from sending unencrypted
-		 * data. We allow sending however, if we are in false start handshake
-		 * state. */
-		if (session->internals.recv_state != RECV_STATE_FALSE_START &&
+		 * data. We allow sending however, if we are in false or early start
+		 * handshake state. */
+		gnutls_mutex_lock(&session->internals.post_negotiation_lock);
+
+		/* we intentionally re-check the initial_negotation_completed variable
+		 * to avoid locking during normal operation of gnutls_record_send2() */
+		if (!session->internals.initial_negotiation_completed &&
+		    session->internals.recv_state != RECV_STATE_FALSE_START &&
+		    session->internals.recv_state != RECV_STATE_FALSE_START_HANDLING &&
 		    session->internals.recv_state != RECV_STATE_EARLY_START &&
-		    !(session->internals.hsk_flags & HSK_EARLY_DATA_IN_FLIGHT))
+		    session->internals.recv_state != RECV_STATE_EARLY_START_HANDLING &&
+		    !(session->internals.hsk_flags & HSK_EARLY_DATA_IN_FLIGHT)) {
+
+			gnutls_mutex_unlock(&session->internals.post_negotiation_lock);
 			return gnutls_assert_val(GNUTLS_E_UNAVAILABLE_DURING_HANDSHAKE);
 	}
+		gnutls_mutex_unlock(&session->internals.post_negotiation_lock);
+	}
 
 	if (unlikely(!vers))
 		return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR);
diff -NurBbp gnutls28-3.6.6/lib/session.c gnutls28-3.6.7/lib/session.c
--- gnutls28-3.6.6/lib/session.c	2018-12-15 22:10:46.000000000 +0100
+++ gnutls28-3.6.7/lib/session.c	2019-04-04 19:26:47.824143860 +0200
@@ -28,6 +28,7 @@
 #include "buffers.h"
 #include "state.h"
 #include "ext/cert_types.h"
+#include <minmax.h>
 
 /**
  * gnutls_session_get_data:
@@ -99,8 +100,10 @@ gnutls_session_get_data(gnutls_session_t
  * is received by the client. To ensure that such a ticket has been received use
  * gnutls_session_get_flags() and check for flag %GNUTLS_SFLAGS_SESSION_TICKET;
  * if this flag is not set, this function will wait for a new ticket within
- * 50ms, and if not received will return dummy data which cannot lead to
- * resumption. To get notified when new tickets are received by the server
+ * an estimated rountrip, and if not received will return dummy data which
+ * cannot lead to resumption.
+ *
+ * To get notified when new tickets are received by the server
  * use gnutls_handshake_set_hook_function() to wait for %GNUTLS_HANDSHAKE_NEW_SESSION_TICKET
  * messages. Each call of gnutls_session_get_data2() after a ticket is
  * received, will return session resumption data corresponding to the last
@@ -120,8 +123,13 @@ gnutls_session_get_data2(gnutls_session_
 	}
 
 	if (vers->tls13_sem && !(session->internals.hsk_flags & HSK_TICKET_RECEIVED)) {
-		/* wait for a message with timeout of 1ms */
-		ret = _gnutls_recv_in_buffers(session, GNUTLS_APPLICATION_DATA, -1, 50);
+		unsigned ertt = session->internals.ertt;
+		/* use our estimation of round-trip + some time for the server to calculate
+		 * the value(s). */
+		ertt += 60;
+
+		/* wait for a message with timeout */
+		ret = _gnutls_recv_in_buffers(session, GNUTLS_APPLICATION_DATA, -1, ertt);
 		if (ret < 0 && (gnutls_error_is_fatal(ret) && ret != GNUTLS_E_TIMEDOUT)) {
 			return gnutls_assert_val(ret);
 		}
diff -NurBbp gnutls28-3.6.6/lib/session_pack.c gnutls28-3.6.7/lib/session_pack.c
--- gnutls28-3.6.6/lib/session_pack.c	2018-11-20 20:10:51.000000000 +0100
+++ gnutls28-3.6.7/lib/session_pack.c	2019-04-04 19:26:47.824143860 +0200
@@ -574,8 +574,6 @@ unpack_certificate_auth_info(gnutls_sess
 
 		gnutls_free(info->raw_certificate_list);
 		gnutls_free(info->raw_ocsp_list);
-		info->raw_certificate_list = NULL;
-		info->raw_ocsp_list = NULL;
 	}
 
 	return ret;
@@ -923,9 +921,18 @@ pack_security_parameters(gnutls_session_
 		BUFFER_APPEND_NUM(ps,
 				  session->security_parameters.
 				  max_record_send_size);
+
+		/* reset max_record_recv_size if it was negotiated
+		 * using the record_size_limit extension */
+		if (session->internals.hsk_flags & HSK_RECORD_SIZE_LIMIT_NEGOTIATED) {
+			BUFFER_APPEND_NUM(ps,
+					  session->security_parameters.
+					  max_record_send_size);
+		} else {
 		BUFFER_APPEND_NUM(ps,
 				  session->security_parameters.
 				  max_record_recv_size);
+		}
 
 		if (session->security_parameters.grp) {
 			BUFFER_APPEND_NUM(ps, session->security_parameters.grp->id);
diff -NurBbp gnutls28-3.6.6/lib/srp.c gnutls28-3.6.7/lib/srp.c
--- gnutls28-3.6.6/lib/srp.c	2018-12-15 22:10:46.000000000 +0100
+++ gnutls28-3.6.7/lib/srp.c	2019-04-04 19:26:47.824143860 +0200
@@ -609,7 +609,6 @@ gnutls_srp_set_server_credentials_file(g
 	if (res->password_conf_file == NULL) {
 		gnutls_assert();
 		gnutls_free(res->password_file);
-		res->password_file = NULL;
 		return GNUTLS_E_MEMORY_ERROR;
 	}
 
diff -NurBbp gnutls28-3.6.6/lib/state.c gnutls28-3.6.7/lib/state.c
--- gnutls28-3.6.6/lib/state.c	2018-12-15 22:10:46.000000000 +0100
+++ gnutls28-3.6.7/lib/state.c	2019-04-04 19:26:47.824143860 +0200
@@ -53,6 +53,7 @@
 #include "dtls.h"
 #include "tls13/session_ticket.h"
 #include "ext/cert_types.h"
+#include "locks.h"
 
 /* to be used by supplemental data support to disable TLS1.3
  * when supplemental data have been globally registered */
@@ -414,8 +415,8 @@ void _gnutls_handshake_internal_state_cl
 
 	_gnutls_epoch_gc(session);
 
-	session->internals.handshake_endtime.tv_sec = 0;
-	session->internals.handshake_endtime.tv_nsec = 0;
+	session->internals.handshake_abs_timeout.tv_sec = 0;
+	session->internals.handshake_abs_timeout.tv_nsec = 0;
 	session->internals.handshake_in_progress = 0;
 
 	session->internals.tfo.connect_addrlen = 0;
@@ -451,8 +452,25 @@ int gnutls_init(gnutls_session_t * sessi
 	if (*session == NULL)
 		return GNUTLS_E_MEMORY_ERROR;
 
+	ret = gnutls_mutex_init(&(*session)->internals.post_negotiation_lock);
+	if (ret < 0) {
+		gnutls_assert();
+		gnutls_free(*session);
+		return ret;
+	}
+
+	ret = gnutls_mutex_init(&(*session)->internals.epoch_lock);
+	if (ret < 0) {
+		gnutls_assert();
+		gnutls_mutex_deinit(&(*session)->internals.post_negotiation_lock);
+		gnutls_free(*session);
+		return ret;
+	}
+
 	ret = _gnutls_epoch_setup_next(*session, 1, NULL);
 	if (ret < 0) {
+		gnutls_mutex_deinit(&(*session)->internals.post_negotiation_lock);
+		gnutls_mutex_deinit(&(*session)->internals.epoch_lock);
 		gnutls_free(*session);
 		return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
 	}
@@ -640,6 +658,9 @@ void gnutls_deinit(gnutls_session_t sess
 	/* overwrite any temp TLS1.3 keys */
 	gnutls_memset(&session->key.proto, 0, sizeof(session->key.proto));
 
+	gnutls_mutex_deinit(&session->internals.post_negotiation_lock);
+	gnutls_mutex_deinit(&session->internals.epoch_lock);
+
 	gnutls_free(session);
 }
 
@@ -1058,7 +1079,7 @@ void
  * interrupted GnuTLS function.
  *
  * This function's output is unreliable if you are using the same
- * @session in different threads, for sending and receiving.
+ * @session in different threads for sending and receiving.
  *
  * Returns: 0 if interrupted while trying to read data, or 1 while trying to write data.
  **/
diff -NurBbp gnutls28-3.6.6/lib/str.c gnutls28-3.6.7/lib/str.c
--- gnutls28-3.6.6/lib/str.c	2019-01-05 12:28:47.000000000 +0100
+++ gnutls28-3.6.7/lib/str.c	2019-04-04 19:26:47.824143860 +0200
@@ -80,7 +80,7 @@ void _gnutls_buffer_clear(gnutls_buffer_
 		return;
 	gnutls_free(str->allocd);
 
-	str->data = str->allocd = NULL;
+	str->data = NULL;
 	str->max_length = 0;
 	str->length = 0;
 }
diff -NurBbp gnutls28-3.6.6/lib/str-iconv.c gnutls28-3.6.7/lib/str-iconv.c
--- gnutls28-3.6.6/lib/str-iconv.c	2018-04-01 13:56:13.000000000 +0200
+++ gnutls28-3.6.7/lib/str-iconv.c	2019-04-04 19:26:47.824143860 +0200
@@ -117,9 +117,8 @@ int _gnutls_ucs2_to_utf8(const void *dat
 	return ret;
 }
 
-/* This is big-endian output only */
 int _gnutls_utf8_to_ucs2(const void *data, size_t size,
-			 gnutls_datum_t * output)
+			 gnutls_datum_t * output, unsigned be)
 {
 	int ret;
 	size_t dstlen, nrm_size = 0, tmp_size = 0;
@@ -150,7 +149,7 @@ int _gnutls_utf8_to_ucs2(const void *dat
 	}
 
 	/* convert to BE */
-	change_u16_endianness(dst, (uint8_t*)tmp_dst, dstlen, 1);
+	change_u16_endianness(dst, (uint8_t*)tmp_dst, dstlen, be);
 	dst[dstlen] = 0;
 	dst[dstlen+1] = 0;
 
diff -NurBbp gnutls28-3.6.6/lib/str-unicode.c gnutls28-3.6.7/lib/str-unicode.c
--- gnutls28-3.6.6/lib/str-unicode.c	2018-04-01 13:56:13.000000000 +0200
+++ gnutls28-3.6.7/lib/str-unicode.c	2019-04-04 19:26:47.824143860 +0200
@@ -123,7 +123,7 @@ static int check_for_valid_freeformclass
 
 		/* Disallowed 
 		   o  Old Hangul Jamo characters, i.e., the OldHangulJamo ("I") category
-		      [FIXME: not handled in this code]
+		      (not handled in this code)
 
 		   o  Control characters, i.e., the Controls ("L") category
 
diff -NurBbp gnutls28-3.6.6/lib/system/fastopen.c gnutls28-3.6.7/lib/system/fastopen.c
--- gnutls28-3.6.6/lib/system/fastopen.c	2018-06-10 11:34:18.000000000 +0200
+++ gnutls28-3.6.7/lib/system/fastopen.c	2019-04-04 19:26:47.824143860 +0200
@@ -26,6 +26,7 @@
 #include "errors.h"
 
 #include <sys/socket.h>
+#include <netinet/in.h> /* IPPROTO_TCP */
 #include <errno.h>
 #include <sys/stat.h>
 #include <sys/types.h>
diff -NurBbp gnutls28-3.6.6/lib/system/inet_ntop.c gnutls28-3.6.7/lib/system/inet_ntop.c
--- gnutls28-3.6.6/lib/system/inet_ntop.c	2018-04-01 13:56:15.000000000 +0200
+++ gnutls28-3.6.7/lib/system/inet_ntop.c	1970-01-01 01:00:00.000000000 +0100
@@ -1,250 +0,0 @@
-/* inet_ntop.c -- convert IPv4 and IPv6 addresses from binary to text form
-
-   Copyright (C) 2005-2006, 2008-2015 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
-
-/*
- * Copyright (c) 1996-1999 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-#include <config.h>
-
-#ifndef HAVE_INET_NTOP
-
-# include <stdio.h>
-# include <string.h>
-# include <errno.h>
-# include <sys/socket.h>
-# include "system.h"
-
-# ifndef IF_LINT
-#  define IF_LINT
-#endif
-
-# ifndef HAVE_IPV6
-#  define HAVE_IPV6 1
-# endif
-
-# ifndef HAVE_IPV4
-#  define HAVE_IPV4 1
-# endif
-
-# define NS_IN6ADDRSZ 16
-# define NS_INT16SZ 2
-
-/*
- * WARNING: Don't even consider trying to compile this on a system where
- * sizeof(int) < 4.  sizeof(int) > 4 is fine; all the world's not a VAX.
- */
-typedef int verify_int_size[4 <= sizeof (int) ? 1 : -1];
-
-static const char *inet_ntop4 (const unsigned char *src, char *dst, unsigned size);
-# if HAVE_IPV6
-static const char *inet_ntop6 (const unsigned char *src, char *dst, unsigned size);
-# endif
-
-
-/* char *
- * inet_ntop(af, src, dst, size)
- *      convert a network format address to presentation format.
- * return:
- *      pointer to presentation format address ('dst'), or NULL (see errno).
- * author:
- *      Paul Vixie, 1996.
- */
-const char *
-inet_ntop (int af, const void *restrict src,
-	   char *restrict dst, unsigned cnt)
-{
-  switch (af)
-    {
-# if HAVE_IPV4
-    case AF_INET:
-      return (inet_ntop4 (src, dst, cnt));
-# endif
-
-# if HAVE_IPV6
-    case AF_INET6:
-      return (inet_ntop6 (src, dst, cnt));
-# endif
-
-    default:
-      errno = EAFNOSUPPORT;
-      return (NULL);
-    }
-  /* NOTREACHED */
-}
-
-/* const char *
- * inet_ntop4(src, dst, size)
- *      format an IPv4 address
- * return:
- *      'dst' (as a const)
- * notes:
- *      (1) uses no statics
- *      (2) takes a u_char* not an in_addr as input
- * author:
- *      Paul Vixie, 1996.
- */
-static const char *
-inet_ntop4 (const unsigned char *src, char *dst, unsigned size)
-{
-  char tmp[sizeof "255.255.255.255"];
-  int len;
-
-  len = sprintf (tmp, "%u.%u.%u.%u", src[0], src[1], src[2], src[3]);
-  if (len < 0)
-    return NULL;
-
-  if ((unsigned)len > size)
-    {
-      errno = ENOSPC;
-      return NULL;
-    }
-
-  return strcpy (dst, tmp);
-}
-
-# if HAVE_IPV6
-
-/* const char *
- * inet_ntop6(src, dst, size)
- *      convert IPv6 binary address into presentation (printable) format
- * author:
- *      Paul Vixie, 1996.
- */
-static const char *
-inet_ntop6 (const unsigned char *src, char *dst, unsigned size)
-{
-  /*
-   * Note that int32_t and int16_t need only be "at least" large enough
-   * to contain a value of the specified size.  On some systems, like
-   * Crays, there is no such thing as an integer variable with 16 bits.
-   * Keep this in mind if you think this function should have been coded
-   * to use pointer overlays.  All the world's not a VAX.
-   */
-  char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
-  struct
-  {
-    int base, len;
-  } best, cur;
-  unsigned int words[NS_IN6ADDRSZ / NS_INT16SZ];
-  int i;
-
-  /*
-   * Preprocess:
-   *      Copy the input (bytewise) array into a wordwise array.
-   *      Find the longest run of 0x00's in src[] for :: shorthanding.
-   */
-  memset (words, '\0', sizeof words);
-  for (i = 0; i < NS_IN6ADDRSZ; i += 2)
-    words[i / 2] = (src[i] << 8) | src[i + 1];
-  best.base = -1;
-  cur.base = -1;
-  IF_LINT(best.len = 0);
-  IF_LINT(cur.len = 0);
-  for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++)
-    {
-      if (words[i] == 0)
-	{
-	  if (cur.base == -1)
-	    cur.base = i, cur.len = 1;
-	  else
-	    cur.len++;
-	}
-      else
-	{
-	  if (cur.base != -1)
-	    {
-	      if (best.base == -1 || cur.len > best.len)
-		best = cur;
-	      cur.base = -1;
-	    }
-	}
-    }
-  if (cur.base != -1)
-    {
-      if (best.base == -1 || cur.len > best.len)
-	best = cur;
-    }
-  if (best.base != -1 && best.len < 2)
-    best.base = -1;
-
-  /*
-   * Format the result.
-   */
-  tp = tmp;
-  for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++)
-    {
-      /* Are we inside the best run of 0x00's? */
-      if (best.base != -1 && i >= best.base && i < (best.base + best.len))
-	{
-	  if (i == best.base)
-	    *tp++ = ':';
-	  continue;
-	}
-      /* Are we following an initial run of 0x00s or any real hex? */
-      if (i != 0)
-	*tp++ = ':';
-      /* Is this address an encapsulated IPv4? */
-      if (i == 6 && best.base == 0 &&
-	  (best.len == 6 || (best.len == 5 && words[5] == 0xffff)))
-	{
-	  if (!inet_ntop4 (src + 12, tp, sizeof tmp - (tp - tmp)))
-	    return (NULL);
-	  tp += strlen (tp);
-	  break;
-	}
-      {
-	int len = sprintf (tp, "%x", words[i]);
-	if (len < 0)
-	  return NULL;
-	tp += len;
-      }
-    }
-  /* Was it a trailing run of 0x00's? */
-  if (best.base != -1 && (best.base + best.len) ==
-      (NS_IN6ADDRSZ / NS_INT16SZ))
-    *tp++ = ':';
-  *tp++ = '\0';
-
-  /*
-   * Check for overflow, copy, and we're done.
-   */
-  if ((unsigned) (tp - tmp) > size)
-    {
-      errno = ENOSPC;
-      return NULL;
-    }
-
-  return strcpy (dst, tmp);
-}
-
-# endif
-
-#endif
diff -NurBbp gnutls28-3.6.6/lib/system/inet_pton.c gnutls28-3.6.7/lib/system/inet_pton.c
--- gnutls28-3.6.6/lib/system/inet_pton.c	2018-04-01 13:56:15.000000000 +0200
+++ gnutls28-3.6.7/lib/system/inet_pton.c	1970-01-01 01:00:00.000000000 +0100
@@ -1,266 +0,0 @@
-/*
- * Copyright (c) 1996,1999 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-#include <config.h>
-
-#ifdef HAVE_SYS_PARAM_H
-#include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>		/* needed to define AF_ values on UNIX */
-#endif
-
-#ifdef HAVE_WINSOCK2_H
-#include <winsock2.h>	/* needed to define AF_ values on Windows */
-#if _MSC_VER < 1600	/* errno.h defines EAFNOSUPPORT in Windows VC10 (and presumably eventually in VC11 ...) */
-#define EAFNOSUPPORT    WSAEAFNOSUPPORT
-#endif
-#endif
-
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-
-#ifdef HAVE_ARPA_NAMESER_H
-#include <arpa/nameser.h>
-#endif
-
-#include <string.h>
-#include <errno.h>
-
-#include <system.h>
-
-#ifndef HAVE_INET_PTON
-
-#ifndef NS_INADDRSZ
-#define NS_INADDRSZ	4
-#endif
-#ifndef NS_IN6ADDRSZ
-#define NS_IN6ADDRSZ	16
-#endif
-#ifndef NS_INT16SZ
-#define NS_INT16SZ	2
-#endif
-
-/*
- * WARNING: Don't even consider trying to compile this on a system where
- * sizeof(int) < 4.  sizeof(int) > 4 is fine; all the world's not a VAX.
- */
-
-static int	inet_pton4 (const char *src, u_char *dst);
-static int	inet_pton6 (const char *src, u_char *dst);
-
-/* int
- * inet_pton(af, src, dst)
- *	convert from presentation format (which usually means ASCII printable)
- *	to network format (which is usually some kind of binary format).
- * return:
- *	1 if the address was valid for the specified address family
- *	0 if the address wasn't valid (`dst' is untouched in this case)
- *	-1 if some other error occurred (`dst' is untouched in this case, too)
- * author:
- *	Paul Vixie, 1996.
- */
-int
-inet_pton(af, src, dst)
-	int af;
-	const char *src;
-	void *dst;
-{
-	switch (af) {
-	case AF_INET:
-		return (inet_pton4(src, dst));
-	case AF_INET6:
-		return (inet_pton6(src, dst));
-	default:
-		errno = EAFNOSUPPORT;
-		return (-1);
-	}
-	/* NOTREACHED */
-}
-#endif
-
-#ifdef _WIN32
-int inet_aton(const char *cp, struct in_addr *inp)
-{
-	return inet_pton(AF_INET, cp, inp);
-}
-#endif
-
-#ifndef HAVE_INET_PTON
-/* int
- * inet_pton4(src, dst)
- *	like inet_aton() but without all the hexadecimal and shorthand.
- * return:
- *	1 if `src' is a valid dotted quad, else 0.
- * notice:
- *	does not touch `dst' unless it's returning 1.
- * author:
- *	Paul Vixie, 1996.
- */
-static int
-inet_pton4(src, dst)
-	const char *src;
-	u_char *dst;
-{
-	static const char digits[] = "0123456789";
-	int saw_digit, octets, ch;
-	u_char tmp[NS_INADDRSZ], *tp;
-
-	saw_digit = 0;
-	octets = 0;
-	*(tp = tmp) = 0;
-	while ((ch = *src++) != '\0') {
-		const char *pch;
-
-		if ((pch = strchr(digits, ch)) != NULL) {
-			size_t new = *tp * 10 + (pch - digits);
-
-			if (new > 255)
-				return (0);
-			*tp = (u_char) new;
-			if (! saw_digit) {
-				if (++octets > 4)
-					return (0);
-				saw_digit = 1;
-			}
-		} else if (ch == '.' && saw_digit) {
-			if (octets == 4)
-				return (0);
-			*++tp = 0;
-			saw_digit = 0;
-		} else
-			return (0);
-	}
-	if (octets < 4)
-		return (0);
-	memcpy(dst, tmp, NS_INADDRSZ);
-	return (1);
-}
-
-/* int
- * inet_pton6(src, dst)
- *	convert presentation level address to network order binary form.
- * return:
- *	1 if `src' is a valid [RFC1884 2.2] address, else 0.
- * notice:
- *	(1) does not touch `dst' unless it's returning 1.
- *	(2) :: in a full address is silently ignored.
- * credit:
- *	inspired by Mark Andrews.
- * author:
- *	Paul Vixie, 1996.
- */
-static int
-inet_pton6(src, dst)
-	const char *src;
-	u_char *dst;
-{
-	static const char xdigits_l[] = "0123456789abcdef",
-			  xdigits_u[] = "0123456789ABCDEF";
-	u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
-	const char *xdigits, *curtok;
-	int ch, saw_xdigit;
-	u_int val;
-
-	memset((tp = tmp), '\0', NS_IN6ADDRSZ);
-	endp = tp + NS_IN6ADDRSZ;
-	colonp = NULL;
-	/* Leading :: requires some special handling. */
-	if (*src == ':')
-		if (*++src != ':')
-			return (0);
-	curtok = src;
-	saw_xdigit = 0;
-	val = 0;
-	while ((ch = *src++) != '\0') {
-		const char *pch;
-
-		if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
-			pch = strchr((xdigits = xdigits_u), ch);
-		if (pch != NULL) {
-			val <<= 4;
-			val |= (pch - xdigits);
-			if (val > 0xffff)
-				return (0);
-			saw_xdigit = 1;
-			continue;
-		}
-		if (ch == ':') {
-			curtok = src;
-			if (!saw_xdigit) {
-				if (colonp)
-					return (0);
-				colonp = tp;
-				continue;
-			} else if (*src == '\0') {
-				return (0);
-			}
-			if (tp + NS_INT16SZ > endp)
-				return (0);
-			*tp++ = (u_char) (val >> 8) & 0xff;
-			*tp++ = (u_char) val & 0xff;
-			saw_xdigit = 0;
-			val = 0;
-			continue;
-		}
-		if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
-		    inet_pton4(curtok, tp) > 0) {
-			tp += NS_INADDRSZ;
-			saw_xdigit = 0;
-			break;	/* '\0' was seen by inet_pton4(). */
-		}
-		return (0);
-	}
-	if (saw_xdigit) {
-		if (tp + NS_INT16SZ > endp)
-			return (0);
-		*tp++ = (u_char) (val >> 8) & 0xff;
-		*tp++ = (u_char) val & 0xff;
-	}
-	if (colonp != NULL) {
-		/*
-		 * Since some memmove()'s erroneously fail to handle
-		 * overlapping regions, we'll do the shift by hand.
-		 */
-		const int n = (int) (tp - colonp);
-		int i;
-
-		if (tp == endp)
-			return (0);
-		for (i = 1; i <= n; i++) {
-			endp[- i] = colonp[n - i];
-			colonp[n - i] = 0;
-		}
-		tp = endp;
-	}
-	if (tp != endp)
-		return (0);
-	memcpy(dst, tmp, NS_IN6ADDRSZ);
-	return (1);
-}
-
-#endif /* HAVE_INET_PTON */
diff -NurBbp gnutls28-3.6.6/lib/system.h gnutls28-3.6.7/lib/system.h
--- gnutls28-3.6.6/lib/system.h	2018-11-18 19:53:49.000000000 +0100
+++ gnutls28-3.6.7/lib/system.h	2019-04-04 19:26:47.824143860 +0200
@@ -100,35 +100,11 @@ int _gnutls_find_config_path(char *path,
 int _gnutls_ucs2_to_utf8(const void *data, size_t size,
 			 gnutls_datum_t * output, unsigned bigendian);
 int _gnutls_utf8_to_ucs2(const void *data, size_t size,
-			 gnutls_datum_t * output);
+			 gnutls_datum_t * output, unsigned be);
 
 void _gnutls_global_set_gettime_function(gnutls_gettime_func gettime_func);
 
 int gnutls_system_global_init(void);
 void gnutls_system_global_deinit(void);
 
-#ifndef _WIN32
-# if defined(HAVE_NETINET_IN_H)
-#  include <netinet/in.h>
-# endif
-# include <arpa/inet.h>
-#else
-# undef inet_aton
-# define inet_aton _gnutls_inet_aton
-int inet_aton(const char *cp, struct in_addr *inp);
-#endif
-
-#ifndef HAVE_INET_PTON
-# undef inet_pton
-# define inet_pton _gnutls_inet_pton
-int inet_pton(int af, const char *src, void *dst);
-#endif
-
-#ifndef HAVE_INET_NTOP
-# undef inet_ntop
-# define inet_ntop _gnutls_inet_ntop
-const char *inet_ntop(int af, const void *src,
-		      char *dst, unsigned size);
-#endif
-
 #endif				/* SYSTEM_H */
diff -NurBbp gnutls28-3.6.6/lib/system_override.c gnutls28-3.6.7/lib/system_override.c
--- gnutls28-3.6.6/lib/system_override.c	2018-04-01 13:56:13.000000000 +0200
+++ gnutls28-3.6.7/lib/system_override.c	2019-04-04 19:26:47.824143860 +0200
@@ -55,6 +55,9 @@
  * variable that is used by GnuTLS (e.g., the application is linked to
  * msvcr71.dll and gnutls is linked to msvcrt.dll).
  *
+ * This function is unreliable if you are using the same
+ * @session in different threads for sending and receiving.
+ *
  **/
 void gnutls_transport_set_errno(gnutls_session_t session, int err)
 {
diff -NurBbp gnutls28-3.6.6/lib/tls13/certificate.c gnutls28-3.6.7/lib/tls13/certificate.c
--- gnutls28-3.6.6/lib/tls13/certificate.c	2019-01-10 07:41:58.000000000 +0100
+++ gnutls28-3.6.7/lib/tls13/certificate.c	2019-04-04 19:26:47.824143860 +0200
@@ -100,8 +100,13 @@ int _gnutls13_recv_certificate(gnutls_se
 
 	ret = parse_cert_list(session, buf.data, buf.length);
 	if (ret < 0) {
-		if (ret == GNUTLS_E_NO_CERTIFICATE_FOUND && optional)
+		if (ret == GNUTLS_E_NO_CERTIFICATE_FOUND) {
+			if (optional)
 			ret = 0;
+			else if (session->security_parameters.entity ==
+				 GNUTLS_SERVER)
+				ret = GNUTLS_E_CERTIFICATE_REQUIRED;
+		}
 		gnutls_assert();
 		goto cleanup;
 	}
diff -NurBbp gnutls28-3.6.6/lib/tls13/certificate_request.c gnutls28-3.6.7/lib/tls13/certificate_request.c
--- gnutls28-3.6.6/lib/tls13/certificate_request.c	2019-01-10 07:41:58.000000000 +0100
+++ gnutls28-3.6.7/lib/tls13/certificate_request.c	2019-04-04 19:26:47.824143860 +0200
@@ -152,7 +152,6 @@ int _gnutls13_recv_certificate_request_i
 			return gnutls_assert_val(ret);
 
 		gnutls_free(session->internals.post_handshake_cr_context.data);
-		session->internals.post_handshake_cr_context.data = NULL;
 		ret = _gnutls_set_datum(&session->internals.post_handshake_cr_context,
 					context.data, context.size);
 		if (ret < 0)
@@ -279,7 +278,6 @@ int _gnutls13_send_certificate_request(g
 			}
 
 			gnutls_free(session->internals.post_handshake_cr_context.data);
-			session->internals.post_handshake_cr_context.data = NULL;
 			ret = _gnutls_set_datum(&session->internals.post_handshake_cr_context,
 						rnd, sizeof(rnd));
 			if (ret < 0) {
diff -NurBbp gnutls28-3.6.6/lib/tls13/hello_retry.c gnutls28-3.6.7/lib/tls13/hello_retry.c
--- gnutls28-3.6.6/lib/tls13/hello_retry.c	2018-06-09 06:30:17.000000000 +0200
+++ gnutls28-3.6.7/lib/tls13/hello_retry.c	2019-04-04 19:26:47.824143860 +0200
@@ -115,7 +115,7 @@ _gnutls13_recv_hello_retry_request(gnutl
 
 	/* only under TLS 1.3 */
 	if (IS_DTLS(session))
-		return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR);
+		return gnutls_assert_val(GNUTLS_E_UNEXPECTED_PACKET);
 
 	if (session->internals.hsk_flags & HSK_HRR_RECEIVED)
 		return gnutls_assert_val(GNUTLS_E_UNEXPECTED_PACKET);
diff -NurBbp gnutls28-3.6.6/lib/tls13-sig.c gnutls28-3.6.7/lib/tls13-sig.c
--- gnutls28-3.6.6/lib/tls13-sig.c	2019-01-05 12:28:47.000000000 +0100
+++ gnutls28-3.6.7/lib/tls13-sig.c	2019-04-04 19:26:47.824143860 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017-2018 Red Hat, Inc.
+ * Copyright (C) 2017-2019 Red Hat, Inc.
  *
  * Author: Nikos Mavrogiannopoulos
  *
@@ -27,6 +27,7 @@
 #include <ext/signature.h>
 #include <abstract_int.h>
 #include "tls13-sig.h"
+#include "tls-sig.h"
 #include "hash_int.h"
 
 #undef PREFIX_SIZE
@@ -48,6 +49,7 @@ _gnutls13_handshake_verify_data(gnutls_s
 	const version_entry_st *ver = get_version(session);
 	gnutls_buffer_st buf;
 	uint8_t prefix[PREFIX_SIZE];
+	unsigned key_usage = 0;
 	gnutls_datum_t p;
 
 	_gnutls_handshake_log
@@ -75,6 +77,12 @@ _gnutls13_handshake_verify_data(gnutls_s
 	if (se->tls13_ok == 0) /* explicitly prohibited */
 		return gnutls_assert_val(GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER);
 
+	gnutls_pubkey_get_key_usage(cert->pubkey, &key_usage);
+
+	ret = _gnutls_check_key_usage_for_sig(session, key_usage, 0);
+	if (ret < 0)
+		return gnutls_assert_val(ret);
+
 	_gnutls_buffer_init(&buf);
 
 	memset(prefix, 0x20, sizeof(prefix));
@@ -150,6 +158,7 @@ _gnutls13_handshake_sign_data(gnutls_ses
 	if (unlikely(sign_supports_priv_pk_algorithm(se, pkey->pk_algorithm) == 0))
 		return gnutls_assert_val(GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER);
 
+	/* when we reach here we know we have a signing certificate */
 	_gnutls_handshake_log
 	    ("HSK[%p]: signing TLS 1.3 handshake data: using %s and PRF: %s\n", session, se->name,
 	     session->security_parameters.prf->name);
diff -NurBbp gnutls28-3.6.6/lib/tls-sig.c gnutls28-3.6.7/lib/tls-sig.c
--- gnutls28-3.6.6/lib/tls-sig.c	2019-01-10 07:41:58.000000000 +0100
+++ gnutls28-3.6.7/lib/tls-sig.c	2019-04-04 19:26:47.824143860 +0200
@@ -40,8 +40,7 @@
 #include <x509/common.h>
 #include <abstract_int.h>
 
-static
-int check_key_usage_for_sig(gnutls_session_t session, unsigned key_usage, unsigned our_cert)
+int _gnutls_check_key_usage_for_sig(gnutls_session_t session, unsigned key_usage, unsigned our_cert)
 {
 	const char *lstr;
 	unsigned allow_key_usage_violation;
@@ -192,7 +191,7 @@ _gnutls_handshake_sign_data(gnutls_sessi
 
 	gnutls_pubkey_get_key_usage(cert->pubkey, &key_usage);
 
-	ret = check_key_usage_for_sig(session, key_usage, 1);
+	ret = _gnutls_check_key_usage_for_sig(session, key_usage, 1);
 	if (ret < 0)
 		return gnutls_assert_val(ret);
 
@@ -336,7 +335,7 @@ _gnutls_handshake_verify_data(gnutls_ses
 
 	gnutls_pubkey_get_key_usage(cert->pubkey, &key_usage);
 
-	ret = check_key_usage_for_sig(session, key_usage, 0);
+	ret = _gnutls_check_key_usage_for_sig(session, key_usage, 0);
 	if (ret < 0)
 		return gnutls_assert_val(ret);
 
@@ -497,7 +496,7 @@ _gnutls_handshake_verify_crt_vrfy(gnutls
 
 	gnutls_pubkey_get_key_usage(cert->pubkey, &key_usage);
 
-	ret = check_key_usage_for_sig(session, key_usage, 0);
+	ret = _gnutls_check_key_usage_for_sig(session, key_usage, 0);
 	if (ret < 0)
 		return gnutls_assert_val(ret);
 
@@ -708,7 +707,7 @@ _gnutls_handshake_sign_crt_vrfy(gnutls_s
 
 	gnutls_pubkey_get_key_usage(cert->pubkey, &key_usage);
 
-	ret = check_key_usage_for_sig(session, key_usage, 1);
+	ret = _gnutls_check_key_usage_for_sig(session, key_usage, 1);
 	if (ret < 0)
 		return gnutls_assert_val(ret);
 
diff -NurBbp gnutls28-3.6.6/lib/tls-sig.h gnutls28-3.6.7/lib/tls-sig.h
--- gnutls28-3.6.6/lib/tls-sig.h	2017-12-14 11:00:19.000000000 +0100
+++ gnutls28-3.6.7/lib/tls-sig.h	2019-04-04 19:26:47.824143860 +0200
@@ -32,6 +32,9 @@
  */
 #define MAX_SIG_SIZE (19 + MAX_HASH_SIZE)
 
+int _gnutls_check_key_usage_for_sig(gnutls_session_t session, unsigned key_usage,
+				    unsigned our_cert);
+
 int _gnutls_handshake_sign_crt_vrfy(gnutls_session_t session,
 				    gnutls_pcert_st * cert,
 				    gnutls_privkey_t pkey,
diff -NurBbp gnutls28-3.6.6/lib/tpm.c gnutls28-3.6.7/lib/tpm.c
--- gnutls28-3.6.6/lib/tpm.c	2018-11-18 19:54:13.000000000 +0100
+++ gnutls28-3.6.7/lib/tpm.c	2019-04-04 19:26:47.828143739 +0200
@@ -1641,10 +1641,8 @@ gnutls_tpm_privkey_generate(gnutls_pk_al
 	gnutls_pubkey_deinit(pub);
       privkey_cleanup:
 	gnutls_free(privkey->data);
-	privkey->data = NULL;
       cleanup:
 	gnutls_free(tmpkey.data);
-	tmpkey.data = NULL;
       err_sa:
 	pTspi_Context_CloseObject(s.tpm_ctx, key_ctx);
       err_cc:
diff -NurBbp gnutls28-3.6.6/lib/x509/hostname-verify.c gnutls28-3.6.7/lib/x509/hostname-verify.c
--- gnutls28-3.6.6/lib/x509/hostname-verify.c	2018-04-01 13:56:15.000000000 +0200
+++ gnutls28-3.6.7/lib/x509/hostname-verify.c	2019-04-04 19:26:47.828143739 +0200
@@ -26,6 +26,8 @@
 #include <common.h>
 #include "errors.h"
 #include <system.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
 
 /**
  * gnutls_x509_crt_check_hostname:
@@ -170,7 +172,7 @@ gnutls_x509_crt_check_hostname2(gnutls_x
 
 	/* check whether @hostname is an ip address */
 	if (!(flags & GNUTLS_VERIFY_DO_NOT_ALLOW_IP_MATCHES) &&
-	    ((p=strchr(hostname, ':')) != NULL || inet_aton(hostname, &ipv4) != 0)) {
+	    ((p=strchr(hostname, ':')) != NULL || inet_pton(AF_INET, hostname, &ipv4) != 0)) {
 
 		if (p != NULL) {
 			struct in6_addr ipv6;
diff -NurBbp gnutls28-3.6.6/lib/x509/ip.c gnutls28-3.6.7/lib/x509/ip.c
--- gnutls28-3.6.6/lib/x509/ip.c	2018-04-01 13:56:15.000000000 +0200
+++ gnutls28-3.6.7/lib/x509/ip.c	2019-04-04 19:26:47.828143739 +0200
@@ -24,10 +24,7 @@
 #include "gnutls_int.h"
 #include "ip.h"
 #include <gnutls/x509.h>
-
-#ifdef HAVE_INET_NTOP
-# include <arpa/inet.h>
-#endif
+#include <arpa/inet.h>
 
 /*-
  * _gnutls_mask_to_prefix:
diff -NurBbp gnutls28-3.6.6/lib/x509/key_decode.c gnutls28-3.6.7/lib/x509/key_decode.c
--- gnutls28-3.6.6/lib/x509/key_decode.c	2018-11-18 19:54:13.000000000 +0100
+++ gnutls28-3.6.7/lib/x509/key_decode.c	2019-04-04 19:26:47.828143739 +0200
@@ -193,9 +193,9 @@ _gnutls_x509_read_dsa_params(uint8_t * d
 		return _gnutls_asn2err(result);
 	}
 
-	/* FIXME: If the parameters are not included in the certificate
+	/* If the parameters are not included in the certificate
 	 * then the issuer's parameters should be used. This is not
-	 * done yet.
+	 * implemented, and is not used in practice (along with DSA).
 	 */
 
 	/* Read p */
diff -NurBbp gnutls28-3.6.6/lib/x509/mpi.c gnutls28-3.6.7/lib/x509/mpi.c
--- gnutls28-3.6.6/lib/x509/mpi.c	2019-01-05 12:28:47.000000000 +0100
+++ gnutls28-3.6.7/lib/x509/mpi.c	2019-04-04 19:26:47.828143739 +0200
@@ -134,10 +134,6 @@ _gnutls_get_asn_mpis(ASN1_TYPE asn, cons
 	_asnstr_append_name(name, sizeof(name), root,
 			    ".algorithm.parameters");
 
-	/* FIXME: If the parameters are not included in the certificate
-	 * then the issuer's parameters should be used. This is not
-	 * needed in practice though.
-	 */
 	if (pk_algorithm != GNUTLS_PK_RSA && pk_algorithm != GNUTLS_PK_EDDSA_ED25519 && pk_algorithm != GNUTLS_PK_ECDH_X25519) {
 		/* RSA and EdDSA do not use parameters */
 		result = _gnutls_x509_read_value(asn, name, &tmp);
diff -NurBbp gnutls28-3.6.6/lib/x509/ocsp.c gnutls28-3.6.7/lib/x509/ocsp.c
--- gnutls28-3.6.6/lib/x509/ocsp.c	2019-01-05 12:28:47.000000000 +0100
+++ gnutls28-3.6.7/lib/x509/ocsp.c	2019-04-04 19:26:47.828143739 +0200
@@ -162,7 +162,6 @@ void gnutls_ocsp_resp_deinit(gnutls_ocsp
 		asn1_delete_structure(&resp->basicresp);
 
 	resp->resp = NULL;
-	resp->response_type_oid.data = NULL;
 	resp->basicresp = NULL;
 
 	gnutls_free(resp->der.data);
@@ -299,7 +298,6 @@ gnutls_ocsp_resp_import2(gnutls_ocsp_res
 		}
 
 		gnutls_free(resp->der.data);
-		resp->der.data = NULL;
 	}
 
 	resp->init = 1;
@@ -1668,18 +1666,12 @@ gnutls_ocsp_resp_get_single(gnutls_ocsp_
 
 	return GNUTLS_E_SUCCESS;
  fail:
-	if (issuer_name_hash) {
+	if (issuer_name_hash)
 		gnutls_free(issuer_name_hash->data);
-		issuer_name_hash->data = NULL;
-	}
-	if (issuer_key_hash) {
+	if (issuer_key_hash)
 		gnutls_free(issuer_key_hash->data);
-		issuer_key_hash->data = NULL;
-	}
-	if (serial_number) {
+	if (serial_number)
 		gnutls_free(serial_number->data);
-		serial_number->data = NULL;
-	}
 	return ret;
 }
 
@@ -1955,7 +1947,6 @@ gnutls_ocsp_resp_get_certs(gnutls_ocsp_r
 		}
 
 		gnutls_free(c.data);
-		c.data = NULL;
 	}
 
 	tmpcerts[ctr] = NULL;
diff -NurBbp gnutls28-3.6.6/lib/x509/pkcs12_bag.c gnutls28-3.6.7/lib/x509/pkcs12_bag.c
--- gnutls28-3.6.6/lib/x509/pkcs12_bag.c	2018-04-01 13:56:15.000000000 +0200
+++ gnutls28-3.6.7/lib/x509/pkcs12_bag.c	2019-04-04 19:26:47.828143739 +0200
@@ -62,7 +62,6 @@ static inline void _pkcs12_bag_free_data
 		_gnutls_free_datum(&bag->element[i].data);
 		_gnutls_free_datum(&bag->element[i].local_key_id);
 		gnutls_free(bag->element[i].friendly_name);
-		bag->element[i].friendly_name = NULL;
 		bag->element[i].type = 0;
 	}
 
diff -NurBbp gnutls28-3.6.6/lib/x509/pkcs12_encr.c gnutls28-3.6.7/lib/x509/pkcs12_encr.c
--- gnutls28-3.6.6/lib/x509/pkcs12_encr.c	2018-06-24 21:33:16.000000000 +0200
+++ gnutls28-3.6.7/lib/x509/pkcs12_encr.c	2019-04-04 19:26:47.828143739 +0200
@@ -96,7 +96,7 @@ _gnutls_pkcs12_string_to_key(const mac_e
 				return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
 			ucs2.size = 2;
 		} else {
-			rc = _gnutls_utf8_to_ucs2(pw, pwlen, &ucs2);
+			rc = _gnutls_utf8_to_ucs2(pw, pwlen, &ucs2, 1);
 			if (rc < 0)
 				return gnutls_assert_val(rc);
 
diff -NurBbp gnutls28-3.6.6/lib/x509/pkcs7.c gnutls28-3.6.7/lib/x509/pkcs7.c
--- gnutls28-3.6.6/lib/x509/pkcs7.c	2018-11-18 19:53:49.000000000 +0100
+++ gnutls28-3.6.7/lib/x509/pkcs7.c	2019-04-04 19:26:47.828143739 +0200
@@ -692,7 +692,6 @@ int gnutls_pkcs7_get_signature_info(gnut
 
 		ret = gnutls_pkcs7_add_attr(&info->signed_attrs, oid, &tmp, 0);
 		gnutls_free(tmp.data);
-		tmp.data = NULL;
 
 		if (ret < 0) {
 			gnutls_assert();
@@ -730,7 +729,6 @@ int gnutls_pkcs7_get_signature_info(gnut
 		ret =
 		    gnutls_pkcs7_add_attr(&info->unsigned_attrs, oid, &tmp, 0);
 		gnutls_free(tmp.data);
-		tmp.data = NULL;
 
 		if (ret < 0) {
 			gnutls_assert();
@@ -842,9 +840,7 @@ static int verify_hash_attr(gnutls_pkcs7
 		}
 
 		gnutls_free(tmp.data);
-		tmp.data = NULL;
 		gnutls_free(tmp2.data);
-		tmp2.data = NULL;
 	}
 
 	if (msg_digest_ok)
@@ -1087,7 +1083,6 @@ static gnutls_x509_crt_t find_verified_i
 			gnutls_x509_crt_deinit(issuer);
 			issuer = NULL;
 			gnutls_free(tmp.data);
-			tmp.data = NULL;
 			continue;
 		}
 
@@ -1204,7 +1199,6 @@ static gnutls_x509_crt_t find_child_of_w
 				gnutls_x509_crt_deinit(crt);
 				crt = NULL;
 				gnutls_free(tmpdata.data);
-				tmpdata.data = NULL;
 				continue;
 			}
 		} else {
diff -NurBbp gnutls28-3.6.6/lib/x509/pkcs7-crypt.c gnutls28-3.6.7/lib/x509/pkcs7-crypt.c
--- gnutls28-3.6.6/lib/x509/pkcs7-crypt.c	2018-06-24 21:33:16.000000000 +0200
+++ gnutls28-3.6.7/lib/x509/pkcs7-crypt.c	2019-04-04 19:26:47.828143739 +0200
@@ -1269,7 +1269,6 @@ _gnutls_pkcs_raw_decrypt_data(schema_id
 	    _gnutls_cipher_init(&ch, ce, &dkey, &d_iv, 0);
 
 	gnutls_free(key);
-	key = NULL;
 
 	if (ret < 0) {
 		gnutls_assert();
diff -NurBbp gnutls28-3.6.6/lib/x509/privkey_pkcs8.c gnutls28-3.6.7/lib/x509/privkey_pkcs8.c
--- gnutls28-3.6.6/lib/x509/privkey_pkcs8.c	2018-11-18 19:54:13.000000000 +0100
+++ gnutls28-3.6.7/lib/x509/privkey_pkcs8.c	2019-04-04 19:26:47.828143739 +0200
@@ -601,7 +601,6 @@ gnutls_pkcs8_info(const gnutls_datum_t *
  cleanup:
 	if (ret != GNUTLS_E_UNKNOWN_CIPHER_TYPE && oid) {
 		gnutls_free(*oid);
-		*oid = NULL;
 	}
 	if (need_free)
 		_gnutls_free_datum(&_data);
diff -NurBbp gnutls28-3.6.6/lib/x509/prov-seed.c gnutls28-3.6.7/lib/x509/prov-seed.c
--- gnutls28-3.6.6/lib/x509/prov-seed.c	2018-04-01 13:56:15.000000000 +0200
+++ gnutls28-3.6.7/lib/x509/prov-seed.c	2019-04-04 19:26:47.828143739 +0200
@@ -30,6 +30,9 @@
 #include <mpi.h>
 #include "prov-seed.h"
 
+/* This function encodes a seed value and a hash algorithm OID to the format
+ * described in RFC8479. The output is the DER encoded form.
+ */
 int _x509_encode_provable_seed(gnutls_x509_privkey_t pkey, gnutls_datum_t *der)
 {
 
@@ -76,6 +79,9 @@ int _x509_encode_provable_seed(gnutls_x5
 	return ret;
 }
 
+/* This function decodes a DER encoded form of seed and a hash algorithm, as in
+ * RFC8479.
+ */
 int _x509_decode_provable_seed(gnutls_x509_privkey_t pkey, const gnutls_datum_t *der)
 {
 
diff -NurBbp gnutls28-3.6.6/lib/x509/verify-high2.c gnutls28-3.6.7/lib/x509/verify-high2.c
--- gnutls28-3.6.6/lib/x509/verify-high2.c	2019-01-05 12:28:47.000000000 +0100
+++ gnutls28-3.6.7/lib/x509/verify-high2.c	2019-04-04 19:26:47.828143739 +0200
@@ -45,6 +45,10 @@
 # endif
 #endif
 
+#ifdef _WIN32
+# include <tchar.h>
+#endif
+
 /* Convenience functions for verify-high functionality 
  */
 
@@ -180,7 +184,6 @@ int remove_pkcs11_url(gnutls_x509_trust_
 {
 	if (strcmp(ca_file, list->pkcs11_token) == 0) {
 		gnutls_free(list->pkcs11_token);
-		list->pkcs11_token = NULL;
 	}
 	return 0;
 }
@@ -386,21 +389,21 @@ int load_dir_certs(const char *dirname,
 			  unsigned int tl_flags, unsigned int tl_vflags,
 			  unsigned type, unsigned crl)
 {
-	DIR *dirp;
-	struct dirent *d;
 	int ret;
 	int r = 0;
 	char path[GNUTLS_PATH_MAX];
 
+#if !defined(_WIN32) || !defined(_UNICODE)
+	DIR *dirp;
+	struct dirent *d;
+
 	dirp = opendir(dirname);
 	if (dirp != NULL) {
-		do {
-			d = readdir(dirp);
-			if (d != NULL
+		while ((d = readdir(dirp)) != NULL) {
 #ifdef _DIRENT_HAVE_D_TYPE
-				&& (d->d_type == DT_REG || d->d_type == DT_LNK || d->d_type == DT_UNKNOWN)
+				if (d->d_type == DT_REG || d->d_type == DT_LNK || d->d_type == DT_UNKNOWN)
 #endif
-			) {
+			{
 				snprintf(path, sizeof(path), "%s/%s",
 					 dirname, d->d_name);
 
@@ -419,10 +422,50 @@ int load_dir_certs(const char *dirname,
 					r += ret;
 			}
 		}
-		while (d != NULL);
 		closedir(dirp);
 	}
+#else /* _WIN32 */
 
+	_TDIR *dirp;
+	struct _tdirent *d;
+	gnutls_datum_t utf16 = {NULL, 0};
+
+#ifdef WORDS_BIGENDIAN
+	r = _gnutls_utf8_to_ucs2(dirname, strlen(dirname), &utf16, 1);
+#else
+	r = _gnutls_utf8_to_ucs2(dirname, strlen(dirname), &utf16, 0);
+#endif
+	if (r < 0)
+		return gnutls_assert_val(r);
+	dirp = _topendir((_TCHAR*)utf16.data);
+	gnutls_free(utf16.data);
+	if (dirp != NULL) {
+		while ((d = _treaddir(dirp)) != NULL) {
+#ifdef _DIRENT_HAVE_D_TYPE
+			if (d->d_type == DT_REG || d->d_type == DT_LNK || d->d_type == DT_UNKNOWN)
+#endif
+			{
+				snprintf(path, sizeof(path), "%s/%ls",
+					dirname, d->d_name);
+
+				if (crl != 0) {
+					ret =
+					    gnutls_x509_trust_list_add_trust_file
+					    (list, NULL, path, type, tl_flags,
+					     tl_vflags);
+				} else {
+					ret =
+					    gnutls_x509_trust_list_add_trust_file
+					    (list, path, NULL, type, tl_flags,
+					     tl_vflags);
+				}
+				if (ret >= 0)
+					r += ret;
+			}
+		}
+		_tclosedir(dirp);
+	}
+#endif /* _WIN32 */
 	return r;
 }
 
diff -NurBbp gnutls28-3.6.6/lib/x509/verify-high.c gnutls28-3.6.7/lib/x509/verify-high.c
--- gnutls28-3.6.6/lib/x509/verify-high.c	2019-01-05 12:28:47.000000000 +0100
+++ gnutls28-3.6.7/lib/x509/verify-high.c	2019-04-04 19:26:47.828143739 +0200
@@ -186,14 +186,6 @@ add_new_ca_to_rdn_seq(gnutls_x509_trust_
 	 * This will be sent to clients when a certificate
 	 * request message is sent.
 	 */
-
-	/* FIXME: in case of a client it is not needed
-	 * to do that. This would save time and memory.
-	 * However we don't have that information available
-	 * here.
-	 * Further, this function is now much more efficient,
-	 * so optimizing that is less important.
-	 */
 	tmp.data = ca->raw_dn.data;
 	tmp.size = ca->raw_dn.size;
 
diff -NurBbp gnutls28-3.6.6/lib/x509/virt-san.c gnutls28-3.6.7/lib/x509/virt-san.c
--- gnutls28-3.6.6/lib/x509/virt-san.c	2018-04-01 13:56:15.000000000 +0200
+++ gnutls28-3.6.7/lib/x509/virt-san.c	2019-04-04 19:26:47.828143739 +0200
@@ -70,7 +70,6 @@ int _gnutls_alt_name_assign_virt_type(st
 		if (ret < 0)
 			return gnutls_assert_val(ret);
 		gnutls_free(san->data);
-		san->data = NULL;
 
 		if (othername_oid) {
 			name->othername_oid.data = (uint8_t *) othername_oid;
diff -NurBbp gnutls28-3.6.6/lib/x509/x509.c gnutls28-3.6.7/lib/x509/x509.c
--- gnutls28-3.6.6/lib/x509/x509.c	2018-12-21 19:43:54.000000000 +0100
+++ gnutls28-3.6.7/lib/x509/x509.c	2019-04-04 19:26:47.828143739 +0200
@@ -227,8 +227,8 @@ int gnutls_x509_crt_init(gnutls_x509_crt
 	if (result < 0) {
 		gnutls_assert();
 		asn1_delete_structure(&tmp->cert);
-		gnutls_free(tmp);
 		gnutls_subject_alt_names_deinit(tmp->san);
+		gnutls_free(tmp);
 		return result;
 	}
 
@@ -338,7 +338,7 @@ static int compare_sig_algorithm(gnutls_
 		return ret;
 	}
 
-	ret = _gnutls_x509_read_value(cert->cert, "signatureAlgorithm.parameters", &sp2);
+	ret = _gnutls_x509_read_value(cert->cert, "tbsCertificate.signature.parameters", &sp2);
 	if (ret == GNUTLS_E_ASN1_ELEMENT_NOT_FOUND) {
 		empty2 = 1;
 	} else if (ret < 0) {
@@ -386,7 +386,6 @@ static int cache_alt_names(gnutls_x509_c
 	if (ret >= 0) {
 		ret = gnutls_x509_ext_import_subject_alt_names(&tmpder, cert->san, 0);
 		gnutls_free(tmpder.data);
-		tmpder.data = NULL;
 		if (ret < 0)
 			return gnutls_assert_val(ret);
 	}
@@ -3684,7 +3683,6 @@ gnutls_x509_crt_list_import2(gnutls_x509
 
 	if (ret < 0) {
 		gnutls_free(*certs);
-		*certs = NULL;
 		return ret;
 	}
 
@@ -4316,7 +4314,6 @@ gnutls_x509_crt_list_import_url(gnutls_x
 
 		if (gnutls_x509_crt_equals2(crts[i-1], &issuer)) {
 			gnutls_free(issuer.data);
-			issuer.data = NULL;
 			break;
 		}
 
@@ -4337,7 +4334,6 @@ gnutls_x509_crt_list_import_url(gnutls_x
 		}
 
 		gnutls_free(issuer.data);
-		issuer.data = NULL;
 	}
 
 	*certs = gnutls_malloc(total*sizeof(gnutls_x509_crt_t));
diff -NurBbp gnutls28-3.6.6/lib/x509/x509_ext.c gnutls28-3.6.7/lib/x509/x509_ext.c
--- gnutls28-3.6.6/lib/x509/x509_ext.c	2019-01-08 20:07:08.000000000 +0100
+++ gnutls28-3.6.7/lib/x509/x509_ext.c	2019-04-04 19:26:47.832143621 +0200
@@ -1994,7 +1994,6 @@ int gnutls_x509_ext_import_policies(cons
 				ret =
 				    decode_user_notice(td.data, td.size, &txt);
 				gnutls_free(td.data);
-				td.data = NULL;
 
 				if (ret < 0) {
 					gnutls_assert();
diff -NurBbp gnutls28-3.6.6/lib/x509_b64.c gnutls28-3.6.7/lib/x509_b64.c
--- gnutls28-3.6.6/lib/x509_b64.c	2018-04-01 13:56:13.000000000 +0200
+++ gnutls28-3.6.7/lib/x509_b64.c	2019-04-04 19:26:47.832143621 +0200
@@ -302,7 +302,6 @@ _gnutls_base64_decode(const uint8_t * da
 
  fail:
 	gnutls_free(result->data);
-	result->data = NULL;
 
  cleanup:
 	gnutls_free(pdata.data);
diff -NurBbp gnutls28-3.6.6/maint.mk gnutls28-3.6.7/maint.mk
--- gnutls28-3.6.6/maint.mk	2019-01-11 07:40:08.000000000 +0100
+++ gnutls28-3.6.7/maint.mk	2019-02-09 10:31:05.000000000 +0100
@@ -21,6 +21,12 @@
 # ME := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
 ME := maint.mk
 
+# These variables ought to be defined through the configure.ac section
+# of the module description. But some packages import this file directly,
+# ignoring the module description.
+GREP ?= grep
+SED ?= sed
+
 # Helper variables.
 _empty =
 _sp = $(_empty) $(_empty)
@@ -46,7 +52,7 @@ member-check =								\
 # Do not save the original name or timestamp in the .tar.gz file.
 # Use --rsyncable if available.
 gzip_rsyncable := \
-  $(shell gzip --help 2>/dev/null|grep rsyncable >/dev/null \
+  $(shell gzip --help 2>/dev/null|$(GREP) rsyncable >/dev/null \
     && printf %s --rsyncable)
 GZIP_ENV = '--no-name --best $(gzip_rsyncable)'
 
@@ -83,9 +89,9 @@ _sc_excl = \
   $(or $(exclude_file_name_regexp--$@),^$$)
 VC_LIST_EXCEPT = \
   $(VC_LIST) | $(SED) 's|^$(_dot_escaped_srcdir)/||' \
-	| if test -f $(srcdir)/.x-$@; then grep -vEf $(srcdir)/.x-$@; \
-	  else grep -Ev -e "$${VC_LIST_EXCEPT_DEFAULT-ChangeLog}"; fi \
-	| grep -Ev -e '($(VC_LIST_ALWAYS_EXCLUDE_REGEX)|$(_sc_excl))' \
+	| if test -f $(srcdir)/.x-$@; then $(GREP) -vEf $(srcdir)/.x-$@; \
+	  else $(GREP) -Ev -e "$${VC_LIST_EXCEPT_DEFAULT-ChangeLog}"; fi \
+	| $(GREP) -Ev -e '($(VC_LIST_ALWAYS_EXCLUDE_REGEX)|$(_sc_excl))' \
 	$(_prepend_srcdir_prefix)
 
 ifeq ($(origin prev_version_file), undefined)
@@ -292,42 +298,56 @@ define _sc_search_regexp
 									\
    : Filter by file name;						\
    if test -n "$$in_files"; then					\
-     files=$$(find $(srcdir) | grep -E "$$in_files"			\
-              | grep -Ev '$(_sc_excl)');				\
+     files=$$(find $(srcdir) | $(GREP) -E "$$in_files"			\
+              | $(GREP) -Ev '$(_sc_excl)');				\
    else									\
      files=$$($(VC_LIST_EXCEPT));					\
      if test -n "$$in_vc_files"; then					\
-       files=$$(echo "$$files" | grep -E "$$in_vc_files");		\
+       files=$$(echo "$$files" | $(GREP) -E "$$in_vc_files");		\
      fi;								\
    fi;									\
 									\
    : Filter by content;							\
-   test -n "$$files" && test -n "$$containing"				\
-     && { files=$$(grep -l "$$containing" $$files); } || :;		\
-   test -n "$$files" && test -n "$$non_containing"			\
-     && { files=$$(grep -vl "$$non_containing" $$files); } || :;	\
+   test -n "$$files"							\
+     && test -n "$$containing"						\
+     && { files=$$(echo "$$files" | xargs $(GREP) -l "$$containing"); }	\
+     || :;								\
+   test -n "$$files"							\
+     && test -n "$$non_containing"					\
+     && { files=$$(echo "$$files" | xargs $(GREP) -vl "$$non_containing"); } \
+     || :;								\
 									\
    : Check for the construct;						\
    if test -n "$$files"; then						\
      if test -n "$$prohibit"; then					\
-       grep $$with_grep_options $(_ignore_case) -nE "$$prohibit" $$files \
-         | grep -vE "$${exclude:-^$$}"					\
-         && { msg="$$halt" $(_sc_say_and_exit) } || :;			\
+       echo "$$files"							\
+         | xargs $(GREP) $$with_grep_options $(_ignore_case) -nE	\
+		"$$prohibit" /dev/null					\
+         | $(GREP) -vE "$${exclude:-^$$}"				\
+         && { msg="$$halt" $(_sc_say_and_exit) }			\
+         || :;								\
      else								\
-       grep $$with_grep_options $(_ignore_case) -LE "$$require" $$files \
-           | grep .							\
-         && { msg="$$halt" $(_sc_say_and_exit) } || :;			\
+       echo "$$files"							\
+         | xargs							\
+             $(GREP) $$with_grep_options $(_ignore_case) -LE "$$require" \
+         | $(GREP) .							\
+         && { msg="$$halt" $(_sc_say_and_exit) }			\
+         || :;								\
      fi									\
    else :;								\
    fi || :;
 endef
 
 sc_avoid_if_before_free:
-	@$(srcdir)/$(_build-aux)/useless-if-before-free			\
+	@$(VC_LIST_EXCEPT)						\
+	  | $(GREP) -v useless-if-before-free				\
+	  | xargs							\
+	      $(srcdir)/$(_build-aux)/useless-if-before-free		\
 		$(useless_free_options)					\
-	    $$($(VC_LIST_EXCEPT) | grep -v useless-if-before-free) &&	\
-	  { echo '$(ME): found useless "if" before "free" above' 1>&2;	\
-	    exit 1; } || :
+	  && { printf '$(ME): found useless "if"'			\
+		      ' before "free" above\n' 1>&2;			\
+	       exit 1; }						\
+	  || :
 
 sc_cast_of_argument_to_free:
 	@prohibit='\<free *\( *\(' halt="don't cast free argument"	\
@@ -399,25 +419,31 @@ sc_error_exit_success:
 # "FATAL:" should be fully upper-cased in error messages
 # "WARNING:" should be fully upper-cased, or fully lower-cased
 sc_error_message_warn_fatal:
-	@grep -nEA2 '[^rp]error *\(' $$($(VC_LIST_EXCEPT))		\
-	    | grep -E '"Warning|"Fatal|"fatal' &&			\
-	  { echo '$(ME): use FATAL, WARNING or warning'	1>&2;		\
-	    exit 1; } || :
+	@$(VC_LIST_EXCEPT)						\
+	  | xargs $(GREP) -nEA2 '[^rp]error *\(' /dev/null		\
+	  | $(GREP) -E '"Warning|"Fatal|"fatal'				\
+	  && { echo '$(ME): use FATAL, WARNING or warning' 1>&2;	\
+	       exit 1; }						\
+	  || :
 
 # Error messages should not start with a capital letter
 sc_error_message_uppercase:
-	@grep -nEA2 '[^rp]error *\(' $$($(VC_LIST_EXCEPT))		\
-	    | grep -E '"[A-Z]'						\
-	    | grep -vE '"FATAL|"WARNING|"Java|"C#|PRIuMAX' &&		\
-	  { echo '$(ME): found capitalized error message' 1>&2;		\
-	    exit 1; } || :
+	@$(VC_LIST_EXCEPT)						\
+	  | xargs $(GREP) -nEA2 '[^rp]error *\(' /dev/null		\
+	  | $(GREP) -E '"[A-Z]'						\
+	  | $(GREP) -vE '"FATAL|"WARNING|"Java|"C#|PRIuMAX'		\
+	  && { echo '$(ME): found capitalized error message' 1>&2;	\
+	       exit 1; }						\
+	  || :
 
 # Error messages should not end with a period
 sc_error_message_period:
-	@grep -nEA2 '[^rp]error *\(' $$($(VC_LIST_EXCEPT))		\
-	    | grep -E '[^."]\."' &&					\
-	  { echo '$(ME): found error message ending in period' 1>&2;	\
-	    exit 1; } || :
+	@$(VC_LIST_EXCEPT)						\
+	  | xargs $(GREP) -nEA2 '[^rp]error *\(' /dev/null		\
+	  | $(GREP) -E '[^."]\."'					\
+	  && { echo '$(ME): found error message ending in period' 1>&2;	\
+	       exit 1; }						\
+	  || :
 
 sc_file_system:
 	@prohibit=file''system						\
@@ -459,8 +485,8 @@ perl_config_h_first_ =							\
 # You must include <config.h> before including any other header file.
 # This can possibly be via a package-specific header, if given by cfg.mk.
 sc_require_config_h_first:
-	@if $(VC_LIST_EXCEPT) | grep '\.c$$' > /dev/null; then		\
-	  files=$$($(VC_LIST_EXCEPT) | grep '\.c$$') &&			\
+	@if $(VC_LIST_EXCEPT) | $(GREP) '\.c$$' > /dev/null; then	\
+	  files=$$($(VC_LIST_EXCEPT) | $(GREP) '\.c$$') &&		\
 	  perl -n $(perl_config_h_first_) $$files ||			\
 	    { echo '$(ME): the above files include some other header'	\
 		'before <config.h>' 1>&2; exit 1; } || :;		\
@@ -478,10 +504,10 @@ sc_prohibit_HAVE_MBRTOWC:
 define _sc_header_without_use
   dummy=; : so we do not need a semicolon before each use;		\
   h_esc=`echo '[<"]'"$$h"'[">]'|$(SED) 's/\./\\\\./g'`;			\
-  if $(VC_LIST_EXCEPT) | grep '\.c$$' > /dev/null; then			\
-    files=$$(grep -l '^# *include '"$$h_esc"				\
-	     $$($(VC_LIST_EXCEPT) | grep '\.c$$')) &&			\
-    grep -LE "$$re" $$files | grep . &&					\
+  if $(VC_LIST_EXCEPT) | $(GREP) '\.c$$' > /dev/null; then		\
+    files=$$($(GREP) -l '^# *include '"$$h_esc"				\
+	     $$($(VC_LIST_EXCEPT) | $(GREP) '\.c$$')) &&		\
+    $(GREP) -LE "$$re" $$files | $(GREP) . &&				\
       { echo "$(ME): the above files include $$h but don't use it"	\
 	1>&2; exit 1; } || :;						\
   else :;								\
@@ -735,9 +761,9 @@ Exit_base := $(notdir $(Exit_witness_fil
 sc_require_test_exit_idiom:
 	@if test -f $(srcdir)/$(Exit_witness_file); then		\
 	  die=0;							\
-	  for i in $$(grep -l -F 'srcdir/$(Exit_base)'			\
+	  for i in $$($(GREP) -l -F 'srcdir/$(Exit_base)'		\
 		$$($(VC_LIST) tests)); do				\
-	    tail -n1 $$i | grep '^Exit .' > /dev/null			\
+	    tail -n1 $$i | $(GREP) '^Exit .' > /dev/null		\
 	      && : || { die=1; echo $$i; }				\
 	  done;								\
 	  test $$die = 1 &&						\
@@ -842,18 +868,23 @@ endef
 # Don't define macros that we already get from gnulib header files.
 sc_prohibit_always-defined_macros:
 	@if test -d $(gnulib_dir); then					\
-	  case $$(echo all: | grep -l -f - Makefile) in Makefile);; *)	\
+	  case $$(echo all: | $(GREP) -l -f - Makefile) in Makefile);; *) \
 	    echo '$(ME): skipping $@: you lack GNU grep' 1>&2; exit 0;;	\
 	  esac;								\
-	  $(def_sym_regex) | grep -E -f - $$($(VC_LIST_EXCEPT))		\
-	    && { echo '$(ME): define the above via some gnulib .h file'	\
-		  1>&2;  exit 1; } || :;				\
+	  regex=$$($(def_sym_regex)); export regex;			\
+	  $(VC_LIST_EXCEPT)						\
+	    | xargs sh -c 'echo $$regex | $(GREP) -E -f - "$$@"'	\
+		dummy /dev/null						\
+	    && { printf '$(ME): define the above'			\
+			' via some gnulib .h file\n' 1>&2;		\
+	         exit 1; }						\
+	    || :;							\
 	fi
 # ==================================================================
 
 # Prohibit checked in backup files.
 sc_prohibit_backup_files:
-	@$(VC_LIST) | grep '~$$' &&				\
+	@$(VC_LIST) | $(GREP) '~$$' &&					\
 	  { echo '$(ME): found version controlled backup file' 1>&2;	\
 	    exit 1; } || :
 
@@ -927,9 +958,11 @@ require_exactly_one_NL_at_EOF_ =					\
     }									\
   END { exit defined $$fail }
 sc_prohibit_empty_lines_at_EOF:
-	@perl -le '$(require_exactly_one_NL_at_EOF_)' $$($(VC_LIST_EXCEPT)) \
-	  || { echo '$(ME): empty line(s) or no newline at EOF'		\
-		1>&2; exit 1; } || :
+	@$(VC_LIST_EXCEPT)						\
+	  | xargs perl -le '$(require_exactly_one_NL_at_EOF_)'		\
+	  || { echo '$(ME): empty line(s) or no newline at EOF' 1>&2;	\
+	       exit 1; }						\
+	  || :
 
 # Make sure we don't use st_blocks.  Use ST_NBLOCKS instead.
 # This is a bit of a kludge, since it prevents use of the string
@@ -972,9 +1005,12 @@ prohibit_doubled_word_ =						\
 ignore_doubled_word_match_RE_ ?= ^$$
 
 sc_prohibit_doubled_word:
-	@perl -n -0777 $(prohibit_doubled_word_) $$($(VC_LIST_EXCEPT))	\
-	  | grep -vE '$(ignore_doubled_word_match_RE_)'			\
-	  | grep . && { echo '$(ME): doubled words' 1>&2; exit 1; } || :
+	@$(VC_LIST_EXCEPT)						\
+	  | xargs perl -n -0777 $(prohibit_doubled_word_)		\
+	  | $(GREP) -vE '$(ignore_doubled_word_match_RE_)'		\
+	  | $(GREP) .							\
+	  && { echo '$(ME): doubled words' 1>&2; exit 1; }		\
+	  || :
 
 # A regular expression matching undesirable combinations of words like
 # "can not"; this matches them even when the two words appear on different
@@ -998,10 +1034,12 @@ prohibit_undesirable_word_seq_ =					\
 ignore_undesirable_word_sequence_RE_ ?= ^$$
 
 sc_prohibit_undesirable_word_seq:
-	@perl -n -0777 $(prohibit_undesirable_word_seq_)		\
-	     $$($(VC_LIST_EXCEPT))					\
-	  | grep -vE '$(ignore_undesirable_word_sequence_RE_)' | grep .	\
-	  && { echo '$(ME): undesirable word sequence' >&2; exit 1; } || :
+	@$(VC_LIST_EXCEPT)						\
+	  | xargs perl -n -0777 $(prohibit_undesirable_word_seq_)	\
+	  | $(GREP) -vE '$(ignore_undesirable_word_sequence_RE_)'	\
+	  | $(GREP) .							\
+	  && { echo '$(ME): undesirable word sequence' >&2; exit 1; }   \
+	  || :
 
 # Except for shell files and for loops, double semicolon is probably a mistake
 sc_prohibit_double_semicolon:
@@ -1033,7 +1071,8 @@ sc_prohibit_test_double_equal:
 # definition of LDADD from the appropriate Makefile.am and exits 0
 # when it contains "ICONV".
 sc_proper_name_utf8_requires_ICONV:
-	@progs=$$(grep -l 'proper_name_utf8 ''("' $$($(VC_LIST_EXCEPT)));\
+	@progs=$$($(VC_LIST_EXCEPT)					\
+		    | xargs $(GREP) -l 'proper_name_utf8 ''("');	\
 	if test "x$$progs" != x; then					\
 	  fail=0;							\
 	  for p in $$progs; do						\
@@ -1042,7 +1081,7 @@ sc_proper_name_utf8_requires_ICONV:
 	      -ne 'exit !(/^LDADD =(.+?[^\\]\n)/ms && $$1 =~ /ICONV/)'	\
 	      $$dir/Makefile.am && continue;				\
 	    base=$$(basename "$$p" .c);					\
-	    grep "$${base}_LDADD.*ICONV)" $$dir/Makefile.am > /dev/null	\
+	    $(GREP) "$${base}_LDADD.*ICONV)" $$dir/Makefile.am > /dev/null	\
 	      || { fail=1; echo 1>&2 "$(ME): $$p uses proper_name_utf8"; }; \
 	  done;								\
 	  test $$fail = 1 &&						\
@@ -1103,12 +1142,12 @@ sc_makefile_at_at_check:
           -e ' && !/(\w+)\s+=.*\@\1\@$$/'				\
           -e ''$(_makefile_at_at_check_exceptions)			\
 	  -e 'and (print "$$ARGV:$$.: $$_"), $$m=1; END {exit !$$m}'	\
-	    $$($(VC_LIST_EXCEPT) | grep -E '(^|/)(Makefile\.am|[^/]+\.mk)$$') \
+	    $$($(VC_LIST_EXCEPT) | $(GREP) -E '(^|/)(Makefile\.am|[^/]+\.mk)$$') \
 	  && { echo '$(ME): use $$(...), not @...@' 1>&2; exit 1; } || :
 
 news-check: NEWS
 	$(AM_V_GEN)if $(SED) -n $(news-check-lines-spec)p $<		\
-	    | grep -E $(news-check-regexp) >/dev/null; then		\
+	    | $(GREP) -E $(news-check-regexp) >/dev/null; then		\
 	  :;								\
 	else								\
 	  echo 'NEWS: $$(news-check-regexp) failed to match' 1>&2;	\
@@ -1153,12 +1192,13 @@ generated_files ?= $(srcdir)/lib/*.[ch]
 _gl_translatable_string_re ?= \b(N?_|gettext *)\([^)"]*("|$$)
 sc_po_check:
 	@if test -f $(po_file); then					\
-	  grep -E -v '^(#|$$)' $(po_file)				\
-	    | grep -v '^src/false\.c$$' | sort > $@-1;			\
-	  files=$$(perl $(perl_translatable_files_list_)		\
-	    $$($(VC_LIST_EXCEPT)) $(generated_files));			\
-	  grep -E -l '$(_gl_translatable_string_re)' $$files		\
-	    | $(SED) 's|^$(_dot_escaped_srcdir)/||' | sort -u > $@-2;	\
+	  $(GREP) -E -v '^(#|$$)' $(po_file)				\
+	    | $(GREP) -v '^src/false\.c$$' | sort > $@-1;		\
+	  { $(VC_LIST_EXCEPT); echo $(generated_files); }		\
+	    | xargs perl $(perl_translatable_files_list_)		\
+	    | xargs $(GREP) -E -l '$(_gl_translatable_string_re)'	\
+	    | $(SED) 's|^$(_dot_escaped_srcdir)/||'			\
+	    | sort -u > $@-2;						\
 	  diff -u -L $(po_file) -L $(po_file) $@-1 $@-2			\
 	    || { printf '$(ME): '$(fix_po_file_diag) 1>&2; exit 1; };	\
 	  rm -f $@-1 $@-2;						\
@@ -1222,18 +1262,21 @@ _hv_regex_weak ?= ^ *\. .*/init\.sh"
 _hv_regex_strong ?= ^ *\. "\$${srcdir=\.}/init\.sh"
 sc_cross_check_PATH_usage_in_tests:
 	@if test -f $(_hv_file); then					\
-	  grep -l 'VERSION mismatch' $(_hv_file) >/dev/null		\
+	  $(GREP) -l 'VERSION mismatch' $(_hv_file) >/dev/null		\
 	    || { echo "$@: skipped: no such file: $(_hv_file)" 1>&2;	\
 		 exit 0; };						\
-	  grep -lE '$(_hv_regex_strong)' $(_hv_file) >/dev/null		\
+	  $(GREP) -lE '$(_hv_regex_strong)' $(_hv_file) >/dev/null	\
 	    || { echo "$@: $(_hv_file) lacks conforming use of init.sh" 1>&2; \
 		 exit 1; };						\
-	  good=$$(grep -E '$(_hv_regex_strong)' $(_hv_file));		\
-	  grep -LFx "$$good"						\
-		$$(grep -lE '$(_hv_regex_weak)' $$($(VC_LIST_EXCEPT)))	\
-	      | grep . &&						\
-	    { echo "$(ME): the above files use path_prepend_ inconsistently" \
-		1>&2; exit 1; } || :;					\
+	  good=$$($(GREP) -E '$(_hv_regex_strong)' $(_hv_file));	\
+	  $(VC_LIST_EXCEPT)						\
+	    | xargs $(GREP) -lE '$(_hv_regex_weak)'			\
+	    | xargs $(GREP) -LFx "$$good"				\
+	    | $(GREP) .							\
+	    && { printf "$(ME): the above files use"			\
+			" path_prepend_ inconsistently\n" 1>&2;		\
+		 exit 1; }						\
+	    || :;							\
 	fi
 
 # BRE regex of file contents to identify a test script.
@@ -1426,7 +1469,7 @@ check: $(gl_public_submodule_commit)
 ALL_RECURSIVE_TARGETS += alpha beta stable
 alpha beta stable: $(local-check) writable-files $(submodule-checks)
 	$(AM_V_GEN)test $@ = stable					\
-	  && { echo $(VERSION) | grep -E '^[0-9]+(\.[0-9]+)+$$'		\
+	  && { echo $(VERSION) | $(GREP) -E '^[0-9]+(\.[0-9]+)+$$'	\
 	       || { echo "invalid version string: $(VERSION)" 1>&2; exit 1;};}\
 	  || :
 	$(AM_V_at)$(MAKE) vc-diff-check
@@ -1524,7 +1567,7 @@ refresh-gnulib-patches:
 	       -e 'END{defined $$d and print $$d}' bootstrap.conf);	\
 	  test -n "$$t" && gl=$$t;					\
 	fi;								\
-	for diff in $$(cd $$gl; git ls-files | grep '\.diff$$'); do	\
+	for diff in $$(cd $$gl; git ls-files | $(GREP) '\.diff$$'); do	\
 	  b=$$(printf %s "$$diff"|$(SED) 's/\.diff$$//');		\
 	  VERSION_CONTROL=none						\
 	    patch "$(gnulib_dir)/$$b" "$$gl/$$diff" || exit 1;		\
@@ -1567,7 +1610,7 @@ update-copyright-env ?=
 # in the file .x-update-copyright.
 .PHONY: update-copyright
 update-copyright:
-	$(AM_V_GEN)grep -l -w Copyright                                  \
+	$(AM_V_GEN)$(GREP) -l -w Copyright                               \
 	  $$(export VC_LIST_EXCEPT_DEFAULT=COPYING && $(VC_LIST_EXCEPT)) \
 	  | $(update-copyright-env) xargs $(srcdir)/$(_build-aux)/$@
 
@@ -1581,9 +1624,9 @@ _gl_TS_dir ?= src
 ALL_RECURSIVE_TARGETS += sc_tight_scope
 sc_tight_scope: tight-scope.mk
 	@fail=0;							\
-	if ! grep '^ *export _gl_TS_headers *=' $(srcdir)/cfg.mk	\
+	if ! $(GREP) '^ *export _gl_TS_headers *=' $(srcdir)/cfg.mk	\
 		> /dev/null						\
-	   && ! grep -w noinst_HEADERS $(srcdir)/$(_gl_TS_dir)/Makefile.am \
+	   && ! $(GREP) -w noinst_HEADERS $(srcdir)/$(_gl_TS_dir)/Makefile.am \
 		> /dev/null 2>&1; then					\
 	    echo '$(ME): skipping $@';					\
 	else								\
@@ -1655,12 +1698,12 @@ _gl_tight_scope: $(bin_PROGRAMS)
 	hdr=`for f in $(_gl_TS_headers); do				\
 	       test -f $$f && d= || d=$(srcdir)/; echo $$d$$f; done`;	\
 	( printf '%s\n' '__.*' $(_gl_TS_unmarked_extern_functions);	\
-	  grep -h -A1 '^extern .*[^;]$$' $$src				\
-	    | grep -vE '^(extern |--|#)' | $(SED) 's/ .*//; /^$$/d';	\
+	  $(GREP) -h -A1 '^extern .*[^;]$$' $$src			\
+	    | $(GREP) -vE '^(extern |--|#)' | $(SED) 's/ .*//; /^$$/d';	\
 	  perl -lne							\
 	     '$(_gl_TS_function_match) and print $$1' $$hdr;		\
 	) | sort -u | $(SED) "$$sed_wrap" > $$t;			\
-	nm -g $(_gl_TS_obj_files)|$(SED) -n 's/.* T //p'|grep -Ev -f $$t \
+	nm -g $(_gl_TS_obj_files)|$(SED) -n 's/.* T //p'|$(GREP) -Ev -f $$t \
 	  && { echo the above functions should have static scope >&2;	\
 	       exit 1; } || : ;						\
 	( printf '%s\n' '__.*' main $(_gl_TS_unmarked_extern_vars);	\
@@ -1668,7 +1711,7 @@ _gl_tight_scope: $(bin_PROGRAMS)
 		$$hdr $(_gl_TS_other_headers)				\
 	) | sort -u | $(SED) "$$sed_wrap" > $$t;			\
 	nm -g $(_gl_TS_obj_files) | $(SED) -n 's/.* [BCDGRS] //p'	\
-            | sort -u | grep -Ev -f $$t					\
+            | sort -u | $(GREP) -Ev -f $$t				\
 	  && { echo the above variables should have static scope >&2;	\
 	       exit 1; } || :
 # TS-end
diff -NurBbp gnutls28-3.6.6/Makefile.am gnutls28-3.6.7/Makefile.am
--- gnutls28-3.6.6/Makefile.am	2019-01-25 08:25:39.000000000 +0100
+++ gnutls28-3.6.7/Makefile.am	2019-02-25 19:14:55.000000000 +0100
@@ -85,7 +85,7 @@ ABIVERCMD="git for-each-ref --sort=tagge
 	cd $(ABI_TMPCLONEDIR) && \
 	  git fetch --tags https://gitlab.com/gnutls/gnutls.git && \
 	  git checkout $$(eval $(ABIREFCMD)) && \
-	  $(MAKE) autoreconf && if test -f ../cache/config.cache;then \
+	  SUBMODULE_NOFETCH=1 ./bootstrap && if test -f ../cache/config.cache;then \
 	    CFLAGS="-g -Og" ./configure --disable-doc --cache-file ../cache/config.cache;\
 	  else\
 	    CFLAGS="-g -Og" ./configure --disable-doc;\
@@ -149,7 +149,9 @@ symbol-check:
 	fi
 	rm -f symbols.last.tmp symbols.diff.tmp
 
-@CODE_COVERAGE_RULES@
+include $(top_srcdir)/aminclude_static.am
+clean-local: code-coverage-clean
+distclean-local: code-coverage-dist-clean
 
 local-code-coverage-output: code-coverage-capture
 	cat GnuTLS-$(VERSION)-coverage/index.html|grep headerCovTableEntry|grep '%'|head -1|sed 's/^.*>\([0-9]\+\.[0-9]\+\s*%\)<.*$$/ coverage lines: \1/' || true
diff -NurBbp gnutls28-3.6.6/NEWS gnutls28-3.6.7/NEWS
--- gnutls28-3.6.6/NEWS	2019-01-25 08:31:36.000000000 +0100
+++ gnutls28-3.6.7/NEWS	2019-04-04 19:26:46.164193376 +0200
@@ -2,9 +2,55 @@ GnuTLS NEWS -- History of user-visible c
 Bug numbers referenced in this log correspond to bug numbers at our issue tracker,
 available at https://gitlab.com/gnutls/gnutls/issues
 Copyright (C) 2000-2016 Free Software Foundation, Inc.
-Copyright (C) 2013-2017 Nikos Mavrogiannopoulos
+Copyright (C) 2013-2019 Nikos Mavrogiannopoulos
 See the end for copying conditions.
 
+* Version 3.6.7 (released 2019-03-27)
+
+** libgnutls, gnutls tools: Every gnutls_free() will automatically set
+   the free'd pointer to NULL. This prevents possible use-after-free and
+   double free issues. Use-after-free will be turned into NULL dereference.
+   The counter-measure does not extend to applications using gnutls_free().
+
+** libgnutls: Fixed a memory corruption (double free) vulnerability in the
+   certificate verification API. Reported by Tavis Ormandy; addressed with
+   the change above. [GNUTLS-SA-2019-03-27, #694]
+
+** libgnutls: Fixed an invalid pointer access via malformed TLS1.3 async messages;
+   Found using tlsfuzzer. [GNUTLS-SA-2019-03-27, #704]
+
+** libgnutls: enforce key usage limitations on certificates more actively.
+   Previously we would enforce it for TLS1.2 protocol, now we enforce it
+   even when TLS1.3 is negotiated, or on client certificates as well. When
+   an inappropriate for TLS1.3 certificate is seen on the credentials structure
+   GnuTLS will disable TLS1.3 support for that session (#690).
+
+** libgnutls: the default number of tickets sent under TLS 1.3 was increased to
+   two. This makes it easier for clients which perform multiple connections
+   to the server to use the tickets sent by a default server.
+
+** libgnutls: enforce the equality of the two signature parameters fields in
+   a certificate. We were already enforcing the signature algorithm, but there
+   was a bug in parameter checking code.
+
+** libgnutls: fixed issue preventing sending and receiving from different
+   threads when false start was enabled (#713).
+
+** libgnutls: the flag GNUTLS_PKCS11_OBJ_FLAG_LOGIN_SO now implies a writable
+   session, as non-writeable security officer sessions are undefined in PKCS#11
+   (#721).
+
+** libgnutls: no longer send downgrade sentinel in TLS 1.3.
+   Previously the sentinel value was embedded to early in version
+   negotiation and was sent even on TLS 1.3. It is now sent only when
+   TLS 1.2 or earlier is negotiated (#689).
+
+** gnutls-cli: Added option --logfile to redirect informational messages output.
+
+** API and ABI modifications:
+No changes since last version.
+
+
 * Version 3.6.6 (released 2019-01-25)
 
 ** libgnutls: gnutls_pubkey_import_ecc_raw() was fixed to set the number bits
diff -NurBbp gnutls28-3.6.6/.pc/30_guile-snarf.diff/guile/src/Makefile.am gnutls28-3.6.7/.pc/30_guile-snarf.diff/guile/src/Makefile.am
--- gnutls28-3.6.6/.pc/30_guile-snarf.diff/guile/src/Makefile.am	2016-02-17 05:37:00.000000000 +0100
+++ gnutls28-3.6.7/.pc/30_guile-snarf.diff/guile/src/Makefile.am	2019-03-15 10:10:27.000000000 +0100
@@ -38,7 +38,7 @@ guileextension_LTLIBRARIES  = guile-gnut
 
 # Use '-module' to build a "dlopenable module", in Libtool terms.
 # Use '-undefined' to placate Libtool on Windows; see
-# <http://lists.gnutls.org/pipermail/gnutls-devel/2014-December/007294.html>.
+# <https://lists.gnutls.org/pipermail/gnutls-devel/2014-December/007294.html>.
 guile_gnutls_v_2_la_LDFLAGS = -module -no-undefined
 
 # Linking against GnuTLS.
@@ -113,7 +113,7 @@ snarfcppopts = $(DEFS) $(INCLUDES) $(AM_
 
 # Note: we cannot use the portable ".c.x" form, since that leads
 # prerequisites to be ignored:
-# <http://lists.gnutls.org/pipermail/gnutls-devel/2013-September/006453.html>.
+# <https://lists.gnutls.org/pipermail/gnutls-devel/2013-September/006453.html>.
 %.x: %.c $(GENERATED_BINDINGS)
 	$(AM_V_GEN)$(guile_snarf) -o $@ $< $(snarfcppopts)
 
diff -NurBbp gnutls28-3.6.6/po/gnutls.pot gnutls28-3.6.7/po/gnutls.pot
--- gnutls28-3.6.6/po/gnutls.pot	2019-01-25 08:20:58.000000000 +0100
+++ gnutls28-3.6.7/po/gnutls.pot	2019-03-27 07:36:32.000000000 +0100
@@ -6,9 +6,9 @@
 #, fuzzy
 msgid ""
 msgstr ""
-"Project-Id-Version: gnutls 3.6.6\n"
+"Project-Id-Version: gnutls 3.6.7\n"
 "Report-Msgid-Bugs-To: bug-gnutls@gnu.org\n"
-"POT-Creation-Date: 2019-01-25 08:20+0100\n"
+"POT-Creation-Date: 2019-03-27 07:36+0100\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -141,6 +141,10 @@ msgstr ""
 msgid "No supported application protocol could be negotiated"
 msgstr ""
 
+#: lib/alert.c:88
+msgid "Certificate is required"
+msgstr ""
+
 #: lib/errors.c:43
 msgid "Could not negotiate a supported cipher suite."
 msgstr ""
@@ -231,711 +235,719 @@ msgstr ""
 msgid "No certificate was found."
 msgstr ""
 
-#: lib/errors.c:97
+#: lib/errors.c:96
+msgid "Certificate is required."
+msgstr ""
+
+#: lib/errors.c:99
 msgid "The given DSA key is incompatible with the selected TLS protocol."
 msgstr ""
 
-#: lib/errors.c:100
+#: lib/errors.c:102
 msgid "There is already a crypto algorithm with lower priority."
 msgstr ""
 
-#: lib/errors.c:103
+#: lib/errors.c:105
 msgid "No temporary RSA parameters were found."
 msgstr ""
 
-#: lib/errors.c:105
+#: lib/errors.c:107
 msgid "No temporary DH parameters were found."
 msgstr ""
 
-#: lib/errors.c:107
+#: lib/errors.c:109
 msgid "An unexpected TLS handshake packet was received."
 msgstr ""
 
-#: lib/errors.c:109
+#: lib/errors.c:111
 msgid "The scanning of a large integer has failed."
 msgstr ""
 
-#: lib/errors.c:111
+#: lib/errors.c:113
 msgid "Could not export a large integer."
 msgstr ""
 
-#: lib/errors.c:113
+#: lib/errors.c:115
 msgid "Decryption has failed."
 msgstr ""
 
-#: lib/errors.c:115
+#: lib/errors.c:117
 msgid "Encryption has failed."
 msgstr ""
 
-#: lib/errors.c:117
+#: lib/errors.c:119
 msgid "Public key decryption has failed."
 msgstr ""
 
-#: lib/errors.c:119
+#: lib/errors.c:121
 msgid "Public key encryption has failed."
 msgstr ""
 
-#: lib/errors.c:121
+#: lib/errors.c:123
 msgid "Public key signing has failed."
 msgstr ""
 
-#: lib/errors.c:123
+#: lib/errors.c:125
 msgid "Public key signature verification has failed."
 msgstr ""
 
-#: lib/errors.c:126
+#: lib/errors.c:128
 msgid "Decompression of the TLS record packet has failed."
 msgstr ""
 
-#: lib/errors.c:128
+#: lib/errors.c:130
 msgid "Compression of the TLS record packet has failed."
 msgstr ""
 
-#: lib/errors.c:131
+#: lib/errors.c:133
 msgid "Internal error in memory allocation."
 msgstr ""
 
-#: lib/errors.c:134
+#: lib/errors.c:136
 msgid "An unimplemented or disabled feature has been requested."
 msgstr ""
 
-#: lib/errors.c:136
+#: lib/errors.c:138
 msgid "Insufficient credentials for that request."
 msgstr ""
 
-#: lib/errors.c:138
+#: lib/errors.c:140
 msgid "Error in password/key file."
 msgstr ""
 
-#: lib/errors.c:139
+#: lib/errors.c:141
 msgid "Wrong padding in PKCS1 packet."
 msgstr ""
 
-#: lib/errors.c:141
+#: lib/errors.c:143
 msgid "The session or certificate has expired."
 msgstr ""
 
-#: lib/errors.c:143
+#: lib/errors.c:145
 msgid "The certificate is not yet activated."
 msgstr ""
 
-#: lib/errors.c:145
+#: lib/errors.c:147
 msgid "Hashing has failed."
 msgstr ""
 
-#: lib/errors.c:146
+#: lib/errors.c:148
 msgid "Base64 decoding error."
 msgstr ""
 
-#: lib/errors.c:148
+#: lib/errors.c:150
 msgid "Base64 unexpected header error."
 msgstr ""
 
-#: lib/errors.c:150
+#: lib/errors.c:152
 msgid "Base64 encoding error."
 msgstr ""
 
-#: lib/errors.c:152
+#: lib/errors.c:154
 msgid "Parsing error in password/key file."
 msgstr ""
 
-#: lib/errors.c:154
+#: lib/errors.c:156
 msgid "The requested data were not available."
 msgstr ""
 
-#: lib/errors.c:156
+#: lib/errors.c:158
 msgid "There are no embedded data in the structure."
 msgstr ""
 
-#: lib/errors.c:158
+#: lib/errors.c:160
 msgid "Error in the pull function."
 msgstr ""
 
-#: lib/errors.c:159
+#: lib/errors.c:161
 msgid "Error in the push function."
 msgstr ""
 
-#: lib/errors.c:161
+#: lib/errors.c:163
 msgid ""
 "The upper limit of record packet sequence numbers has been reached. Wow!"
 msgstr ""
 
-#: lib/errors.c:163
+#: lib/errors.c:165
 msgid "Error in the certificate."
 msgstr ""
 
-#: lib/errors.c:165
+#: lib/errors.c:167
 msgid "Error in the time fields of certificate."
 msgstr ""
 
-#: lib/errors.c:167
+#: lib/errors.c:169
 msgid "Error in the certificate verification."
 msgstr ""
 
-#: lib/errors.c:169
+#: lib/errors.c:171
 msgid "Error in the CRL verification."
 msgstr ""
 
-#: lib/errors.c:171
+#: lib/errors.c:173
 msgid "Error in the private key verification; seed doesn't match."
 msgstr ""
 
-#: lib/errors.c:173
+#: lib/errors.c:175
 msgid "Could not authenticate peer."
 msgstr ""
 
-#: lib/errors.c:176
+#: lib/errors.c:178
 msgid "Unknown Subject Alternative name in X.509 certificate."
 msgstr ""
 
-#: lib/errors.c:179
+#: lib/errors.c:181
 msgid "CIDR name constraint is malformed in size or structure."
 msgstr ""
 
-#: lib/errors.c:183
+#: lib/errors.c:185
 msgid "Unsupported critical extension in X.509 certificate."
 msgstr ""
 
-#: lib/errors.c:185
+#: lib/errors.c:187
 msgid "Unsupported extension in X.509 certificate."
 msgstr ""
 
-#: lib/errors.c:188
+#: lib/errors.c:190
 msgid "Key usage violation in certificate has been detected."
 msgstr ""
 
-#: lib/errors.c:190 lib/errors.c:450
+#: lib/errors.c:192 lib/errors.c:454
 msgid "Function was interrupted."
 msgstr ""
 
-#: lib/errors.c:192
+#: lib/errors.c:194
 msgid "TLS Application data were received, while expecting handshake data."
 msgstr ""
 
-#: lib/errors.c:194
+#: lib/errors.c:196
 msgid "Error in Database backend."
 msgstr ""
 
-#: lib/errors.c:195
+#: lib/errors.c:197
 msgid "The Database entry already exists."
 msgstr ""
 
-#: lib/errors.c:196
+#: lib/errors.c:198
 msgid "The certificate type is not supported."
 msgstr ""
 
-#: lib/errors.c:199
+#: lib/errors.c:201
 msgid "The given memory buffer is too short to hold parameters."
 msgstr ""
 
-#: lib/errors.c:201 libdane/errors.c:61
+#: lib/errors.c:203 libdane/errors.c:61
 msgid "The request is invalid."
 msgstr ""
 
-#: lib/errors.c:203
+#: lib/errors.c:205
 msgid "The cookie was bad."
 msgstr ""
 
-#: lib/errors.c:204
+#: lib/errors.c:206
 msgid "An illegal parameter has been received."
 msgstr ""
 
-#: lib/errors.c:206
+#: lib/errors.c:208
 msgid "An illegal parameter was found."
 msgstr ""
 
-#: lib/errors.c:208
+#: lib/errors.c:210
 msgid "Error while reading file."
 msgstr ""
 
-#: lib/errors.c:210
+#: lib/errors.c:211
+msgid "A disallowed SNI server name has been received."
+msgstr ""
+
+#: lib/errors.c:214
 msgid "ASN1 parser: Element was not found."
 msgstr ""
 
-#: lib/errors.c:212
+#: lib/errors.c:216
 msgid "ASN1 parser: Identifier was not found"
 msgstr ""
 
-#: lib/errors.c:214
+#: lib/errors.c:218
 msgid "ASN1 parser: Error in DER parsing."
 msgstr ""
 
-#: lib/errors.c:216
+#: lib/errors.c:220
 msgid "ASN1 parser: Value was not found."
 msgstr ""
 
-#: lib/errors.c:218
+#: lib/errors.c:222
 msgid "ASN1 parser: Generic parsing error."
 msgstr ""
 
-#: lib/errors.c:220
+#: lib/errors.c:224
 msgid "ASN1 parser: Value is not valid."
 msgstr ""
 
-#: lib/errors.c:222
+#: lib/errors.c:226
 msgid "ASN1 parser: Error in TAG."
 msgstr ""
 
-#: lib/errors.c:224
+#: lib/errors.c:228
 msgid "ASN1 parser: error in implicit tag"
 msgstr ""
 
-#: lib/errors.c:226
+#: lib/errors.c:230
 msgid "ASN1 parser: Error in type 'ANY'."
 msgstr ""
 
-#: lib/errors.c:228
+#: lib/errors.c:232
 msgid "ASN1 parser: Syntax error."
 msgstr ""
 
-#: lib/errors.c:230
+#: lib/errors.c:234
 msgid "ASN1 parser: Overflow in DER parsing."
 msgstr ""
 
-#: lib/errors.c:234
+#: lib/errors.c:238
 msgid "Too many empty record packets have been received."
 msgstr ""
 
-#: lib/errors.c:236
+#: lib/errors.c:240
 msgid "Too many handshake packets have been received."
 msgstr ""
 
-#: lib/errors.c:238
+#: lib/errors.c:242
 msgid "More than a single object matches the criteria."
 msgstr ""
 
-#: lib/errors.c:240
+#: lib/errors.c:244
 msgid "The crypto library version is too old."
 msgstr ""
 
-#: lib/errors.c:243
+#: lib/errors.c:247
 msgid "The tasn1 library version is too old."
 msgstr ""
 
-#: lib/errors.c:245
+#: lib/errors.c:249
 msgid "The OpenPGP User ID is revoked."
 msgstr ""
 
-#: lib/errors.c:247
+#: lib/errors.c:251
 msgid "The OpenPGP key has not a preferred key set."
 msgstr ""
 
-#: lib/errors.c:249
+#: lib/errors.c:253
 msgid "Error loading the keyring."
 msgstr ""
 
-#: lib/errors.c:251
+#: lib/errors.c:255
 msgid "The initialization of crypto backend has failed."
 msgstr ""
 
-#: lib/errors.c:254
+#: lib/errors.c:258
 msgid "No supported compression algorithms have been found."
 msgstr ""
 
-#: lib/errors.c:256
+#: lib/errors.c:260
 msgid "No supported cipher suites have been found."
 msgstr ""
 
-#: lib/errors.c:258
+#: lib/errors.c:262
 msgid "Could not get OpenPGP key."
 msgstr ""
 
-#: lib/errors.c:260
+#: lib/errors.c:264
 msgid "Could not find OpenPGP subkey."
 msgstr ""
 
-#: lib/errors.c:262
+#: lib/errors.c:266
 msgid "Safe renegotiation failed."
 msgstr ""
 
-#: lib/errors.c:264
+#: lib/errors.c:268
 msgid "Unsafe renegotiation denied."
 msgstr ""
 
-#: lib/errors.c:267
+#: lib/errors.c:271
 msgid "The SRP username supplied is illegal."
 msgstr ""
 
-#: lib/errors.c:269
+#: lib/errors.c:273
 msgid "The username supplied is unknown."
 msgstr ""
 
-#: lib/errors.c:272
+#: lib/errors.c:276
 msgid "The OpenPGP fingerprint is not supported."
 msgstr ""
 
-#: lib/errors.c:274
+#: lib/errors.c:278
 msgid "The signature algorithm is not supported."
 msgstr ""
 
-#: lib/errors.c:276
+#: lib/errors.c:280
 msgid "The certificate has unsupported attributes."
 msgstr ""
 
-#: lib/errors.c:278
+#: lib/errors.c:282
 msgid "The OID is not supported."
 msgstr ""
 
-#: lib/errors.c:280
+#: lib/errors.c:284
 msgid "The hash algorithm is unknown."
 msgstr ""
 
-#: lib/errors.c:282
+#: lib/errors.c:286
 msgid "The PKCS structure's content type is unknown."
 msgstr ""
 
-#: lib/errors.c:284
+#: lib/errors.c:288
 msgid "The PKCS structure's bag type is unknown."
 msgstr ""
 
-#: lib/errors.c:286 lib/errors.c:292
+#: lib/errors.c:290 lib/errors.c:296
 msgid "The given password contains invalid characters."
 msgstr ""
 
-#: lib/errors.c:288
+#: lib/errors.c:292
 msgid "The given string contains invalid UTF-8 characters."
 msgstr ""
 
-#: lib/errors.c:290
+#: lib/errors.c:294
 msgid "The given email string contains non-ASCII characters before '@'."
 msgstr ""
 
-#: lib/errors.c:295
+#: lib/errors.c:299
 msgid "The Message Authentication Code verification failed."
 msgstr ""
 
-#: lib/errors.c:297
+#: lib/errors.c:301
 msgid "Some constraint limits were reached."
 msgstr ""
 
-#: lib/errors.c:299
+#: lib/errors.c:303
 msgid "Failed to acquire random data."
 msgstr ""
 
-#: lib/errors.c:301
+#: lib/errors.c:305
 msgid "Verifying TLS/IA phase checksum failed"
 msgstr ""
 
-#: lib/errors.c:304
+#: lib/errors.c:308
 msgid "The specified algorithm or protocol is unknown."
 msgstr ""
 
-#: lib/errors.c:307
+#: lib/errors.c:311
 msgid "The handshake data size is too large."
 msgstr ""
 
-#: lib/errors.c:310
+#: lib/errors.c:314
 msgid "Error opening /dev/crypto"
 msgstr ""
 
-#: lib/errors.c:313
+#: lib/errors.c:317
 msgid "Error interfacing with /dev/crypto"
 msgstr ""
 
-#: lib/errors.c:315
+#: lib/errors.c:319
 msgid "Peer has terminated the connection"
 msgstr ""
 
-#: lib/errors.c:317
+#: lib/errors.c:321
 msgid "Channel binding data not available"
 msgstr ""
 
-#: lib/errors.c:320
+#: lib/errors.c:324
 msgid "TPM error."
 msgstr ""
 
-#: lib/errors.c:322
+#: lib/errors.c:326
 msgid "The TPM library (trousers) cannot be found."
 msgstr ""
 
-#: lib/errors.c:324
+#: lib/errors.c:328
 msgid "TPM is not initialized."
 msgstr ""
 
-#: lib/errors.c:326
+#: lib/errors.c:330
 msgid "TPM key was not found in persistent storage."
 msgstr ""
 
-#: lib/errors.c:328
+#: lib/errors.c:332
 msgid "Cannot initialize a session with the TPM."
 msgstr ""
 
-#: lib/errors.c:330
+#: lib/errors.c:334
 msgid "PKCS #11 error."
 msgstr ""
 
-#: lib/errors.c:332
+#: lib/errors.c:336
 msgid "PKCS #11 initialization error."
 msgstr ""
 
-#: lib/errors.c:334
+#: lib/errors.c:338
 msgid "Error in parsing."
 msgstr ""
 
-#: lib/errors.c:336
+#: lib/errors.c:340
 msgid "Error in provided PIN."
 msgstr ""
 
-#: lib/errors.c:338
+#: lib/errors.c:342
 msgid "Error in provided SRK password for TPM."
 msgstr ""
 
-#: lib/errors.c:341
+#: lib/errors.c:345
 msgid "Error in provided password for key to be loaded in TPM."
 msgstr ""
 
-#: lib/errors.c:343
+#: lib/errors.c:347
 msgid "PKCS #11 error in slot"
 msgstr ""
 
-#: lib/errors.c:345
+#: lib/errors.c:349
 msgid "Thread locking error"
 msgstr ""
 
-#: lib/errors.c:347
+#: lib/errors.c:351
 msgid "PKCS #11 error in attribute"
 msgstr ""
 
-#: lib/errors.c:349
+#: lib/errors.c:353
 msgid "PKCS #11 error in device"
 msgstr ""
 
-#: lib/errors.c:351
+#: lib/errors.c:355
 msgid "PKCS #11 error in data"
 msgstr ""
 
-#: lib/errors.c:353
+#: lib/errors.c:357
 msgid "PKCS #11 unsupported feature"
 msgstr ""
 
-#: lib/errors.c:355
+#: lib/errors.c:359
 msgid "PKCS #11 error in key"
 msgstr ""
 
-#: lib/errors.c:357
+#: lib/errors.c:361
 msgid "PKCS #11 PIN expired"
 msgstr ""
 
-#: lib/errors.c:359
+#: lib/errors.c:363
 msgid "PKCS #11 PIN locked"
 msgstr ""
 
-#: lib/errors.c:361
+#: lib/errors.c:365
 msgid "PKCS #11 error in session"
 msgstr ""
 
-#: lib/errors.c:363
+#: lib/errors.c:367
 msgid "PKCS #11 error in signature"
 msgstr ""
 
-#: lib/errors.c:365
+#: lib/errors.c:369
 msgid "PKCS #11 error in token"
 msgstr ""
 
-#: lib/errors.c:367
+#: lib/errors.c:371
 msgid "PKCS #11 user error"
 msgstr ""
 
-#: lib/errors.c:369
+#: lib/errors.c:373
 msgid "The operation timed out"
 msgstr ""
 
-#: lib/errors.c:371
+#: lib/errors.c:375
 msgid "The operation was cancelled due to user error"
 msgstr ""
 
-#: lib/errors.c:373
+#: lib/errors.c:377
 msgid "No supported ECC curves were found"
 msgstr ""
 
-#: lib/errors.c:375
+#: lib/errors.c:379
 msgid "The curve is unsupported"
 msgstr ""
 
-#: lib/errors.c:377
+#: lib/errors.c:381
 msgid "The requested PKCS #11 object is not available"
 msgstr ""
 
-#: lib/errors.c:380
+#: lib/errors.c:384
 msgid ""
 "The provided X.509 certificate list is not sorted (in subject to issuer "
 "order)"
 msgstr ""
 
-#: lib/errors.c:382
+#: lib/errors.c:386
 msgid "The OCSP response is invalid"
 msgstr ""
 
-#: lib/errors.c:384
+#: lib/errors.c:388
 msgid "The OCSP response provided doesn't match the available certificates"
 msgstr ""
 
-#: lib/errors.c:386
+#: lib/errors.c:390
 msgid "There is no certificate status (OCSP)."
 msgstr ""
 
-#: lib/errors.c:388
+#: lib/errors.c:392
 msgid "Error in the system's randomness device."
 msgstr ""
 
-#: lib/errors.c:391
+#: lib/errors.c:395
 msgid "No common application protocol could be negotiated."
 msgstr ""
 
-#: lib/errors.c:393
+#: lib/errors.c:397
 msgid "Error while performing self checks."
 msgstr ""
 
-#: lib/errors.c:395
+#: lib/errors.c:399
 msgid "There is no self test for this algorithm."
 msgstr ""
 
-#: lib/errors.c:397
+#: lib/errors.c:401
 msgid ""
 "An error has been detected in the library and cannot continue operations."
 msgstr ""
 
-#: lib/errors.c:399
+#: lib/errors.c:403
 msgid "Error in sockets initialization."
 msgstr ""
 
-#: lib/errors.c:401
+#: lib/errors.c:405
 msgid "Error in public key generation."
 msgstr ""
 
-#: lib/errors.c:403
+#: lib/errors.c:407
 msgid "Invalid TLS extensions length field."
 msgstr ""
 
-#: lib/errors.c:405
+#: lib/errors.c:409
 msgid "Peer's certificate or username has changed during a rehandshake."
 msgstr ""
 
-#: lib/errors.c:407
+#: lib/errors.c:411
 msgid "The provided string has an embedded null."
 msgstr ""
 
-#: lib/errors.c:409
+#: lib/errors.c:413
 msgid "Attempted handshake during false start."
 msgstr ""
 
-#: lib/errors.c:411
+#: lib/errors.c:415
 msgid "The SNI host name not recognised."
 msgstr ""
 
-#: lib/errors.c:413
+#: lib/errors.c:417
 msgid "There was an issue converting to or from UTF8."
 msgstr ""
 
-#: lib/errors.c:415
+#: lib/errors.c:419
 msgid "Cannot perform this action while handshake is in progress."
 msgstr ""
 
-#: lib/errors.c:417
+#: lib/errors.c:421
 msgid "The public key is invalid."
 msgstr ""
 
-#: lib/errors.c:419
+#: lib/errors.c:423
 msgid "There are no validation parameters present."
 msgstr ""
 
-#: lib/errors.c:421
+#: lib/errors.c:425
 msgid "The public key parameters are invalid."
 msgstr ""
 
-#: lib/errors.c:423
+#: lib/errors.c:427
 msgid "The private key is invalid."
 msgstr ""
 
-#: lib/errors.c:425
+#: lib/errors.c:429
 msgid "The DER time encoding is invalid."
 msgstr ""
 
-#: lib/errors.c:427
+#: lib/errors.c:431
 msgid "The signature is incompatible with the public key."
 msgstr ""
 
-#: lib/errors.c:429
+#: lib/errors.c:433
 msgid "One of the involved algorithms has insufficient security level."
 msgstr ""
 
-#: lib/errors.c:431
+#: lib/errors.c:435
 msgid "No common key share with peer."
 msgstr ""
 
-#: lib/errors.c:433
+#: lib/errors.c:437
 msgid "The early data were rejected."
 msgstr ""
 
-#: lib/errors.c:439 libdane/errors.c:42
+#: lib/errors.c:443 libdane/errors.c:42
 msgid "Success."
 msgstr ""
 
-#: lib/errors.c:440
+#: lib/errors.c:444
 msgid "A TLS warning alert has been received."
 msgstr ""
 
-#: lib/errors.c:442
+#: lib/errors.c:446
 msgid "A heartbeat pong message was received."
 msgstr ""
 
-#: lib/errors.c:444
+#: lib/errors.c:448
 msgid "A heartbeat ping message was received."
 msgstr ""
 
-#: lib/errors.c:446
+#: lib/errors.c:450
 msgid "Resource temporarily unavailable, try again."
 msgstr ""
 
-#: lib/errors.c:448
+#: lib/errors.c:452
 msgid "The transmitted packet is too large (EMSGSIZE)."
 msgstr ""
 
-#: lib/errors.c:451
+#: lib/errors.c:455
 msgid "Rehandshake was requested by the peer."
 msgstr ""
 
-#: lib/errors.c:453
+#: lib/errors.c:457
 msgid "Re-authentication was requested by the peer."
 msgstr ""
 
-#: lib/errors.c:545 libdane/errors.c:100
+#: lib/errors.c:549 libdane/errors.c:100
 msgid "(unknown error code)"
 msgstr ""
 
-#: lib/x509/ocsp.c:2611
+#: lib/x509/ocsp.c:2602
 msgid "The OCSP response is trusted. "
 msgstr ""
 
-#: lib/x509/ocsp.c:2616
+#: lib/x509/ocsp.c:2607
 msgid "The OCSP response's signer could not be found. "
 msgstr ""
 
-#: lib/x509/ocsp.c:2621
+#: lib/x509/ocsp.c:2612
 msgid "Error in the signer's key usageflags. "
 msgstr ""
 
-#: lib/x509/ocsp.c:2626
+#: lib/x509/ocsp.c:2617
 msgid "The OCSP response's signer is not trusted. "
 msgstr ""
 
-#: lib/x509/ocsp.c:2631
+#: lib/x509/ocsp.c:2622
 msgid "The OCSP response depends on insecure algorithms. "
 msgstr ""
 
-#: lib/x509/ocsp.c:2636
+#: lib/x509/ocsp.c:2627
 msgid "The OCSP response's signature cannot be validated. "
 msgstr ""
 
-#: lib/x509/ocsp.c:2641
+#: lib/x509/ocsp.c:2632
 msgid "The OCSP response's signer's certificate is not activated. "
 msgstr ""
 
-#: lib/x509/ocsp.c:2646
+#: lib/x509/ocsp.c:2637
 msgid "The OCSP response's signer's certificate is expired. "
 msgstr ""
 
-#: lib/x509/ocsp.c:2650
+#: lib/x509/ocsp.c:2641
 msgid "Memory error"
 msgstr ""
 
diff -NurBbp gnutls28-3.6.6/src/benchmark.c gnutls28-3.6.7/src/benchmark.c
--- gnutls28-3.6.6/src/benchmark.c	2018-06-29 21:57:31.000000000 +0200
+++ gnutls28-3.6.7/src/benchmark.c	2019-04-04 19:26:47.832143621 +0200
@@ -47,7 +47,7 @@ static void alarm_handler(int signo)
 #endif
 
 static void
-value2human(unsigned long bytes, double time, double *data, double *speed,
+value2human(uint64_t bytes, double time, double *data, double *speed,
 	    char *metric)
 {
 	if (bytes > 1000 && bytes < 1000 * 1000) {
diff -NurBbp gnutls28-3.6.6/src/benchmark.h gnutls28-3.6.7/src/benchmark.h
--- gnutls28-3.6.6/src/benchmark.h	2018-06-29 21:57:31.000000000 +0200
+++ gnutls28-3.6.7/src/benchmark.h	2019-04-04 19:26:47.832143621 +0200
@@ -24,6 +24,9 @@
 #include <windows.h>
 #endif
 
+/* for uint64_t */
+# include <stdint.h>
+
 #if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_PROCESS_CPUTIME_ID)
 #undef gettime
 #define gettime(x) clock_gettime(CLOCK_PROCESS_CPUTIME_ID, x)
@@ -44,7 +47,7 @@ void benchmark_tls(int debug_level, int
 
 struct benchmark_st {
 	struct timespec start;
-	unsigned long size;
+	uint64_t size;
 	sighandler_t old_handler;
 #if defined(_WIN32)
 	HANDLE wtimer;
diff -NurBbp gnutls28-3.6.6/src/certtool.c gnutls28-3.6.7/src/certtool.c
--- gnutls28-3.6.6/src/certtool.c	2018-11-28 19:56:17.000000000 +0100
+++ gnutls28-3.6.7/src/certtool.c	2019-04-04 19:26:47.832143621 +0200
@@ -3702,8 +3702,7 @@ void smime_to_pkcs7(void)
 	char *lineptr = NULL;
 	ssize_t len;
 
-	/* Find body.  FIXME: Handle non-b64 Content-Transfer-Encoding.
-	   Reject non-S/MIME tagged Content-Type's? */
+	/* Find body. We do not handle non-b64 Content-Transfer-Encoding. */
 	do {
 		len = getline(&lineptr, &linesize, infile);
 		if (len == -1) {
diff -NurBbp gnutls28-3.6.6/src/cli-args.def gnutls28-3.6.7/src/cli-args.def
--- gnutls28-3.6.6/src/cli-args.def	2018-11-18 19:53:49.000000000 +0100
+++ gnutls28-3.6.7/src/cli-args.def	2019-03-16 19:55:13.000000000 +0100
@@ -416,6 +416,13 @@ flag = {
     doc      = "";
 };
 
+flag = {
+    name      = logfile;
+    arg-type  = string;
+    descrip   = "Redirect informational messages to a specific file.";
+    doc       = "";
+};
+
 doc-section = {
   ds-type   = 'SEE ALSO'; // or anything else
   ds-format = 'texi';      // or texi or mdoc format
diff -NurBbp gnutls28-3.6.6/src/cli.c gnutls28-3.6.7/src/cli.c
--- gnutls28-3.6.6/src/cli.c	2018-11-18 19:53:49.000000000 +0100
+++ gnutls28-3.6.7/src/cli.c	2019-04-04 19:26:47.832143621 +0200
@@ -363,21 +363,21 @@ static int cert_verify_callback(gnutls_s
 	if (ca_verify) {
 		rc = cert_verify(session, host, GNUTLS_KP_TLS_WWW_SERVER);
 		if (rc == 0) {
-			printf
-			    ("*** PKI verification of server certificate failed...\n");
+			log_msg
+			    (stdout, "*** PKI verification of server certificate failed...\n");
 			if (!insecure && !ssh)
 				return -1;
 		} else if (ENABLED_OPT(OCSP) && gnutls_ocsp_status_request_is_checked(session, 0) == 0) {	/* off-line verification succeeded. Try OCSP */
 			rc = cert_verify_ocsp(session);
 			if (rc == -1) {
-				printf
-				    ("*** Verifying (with OCSP) server certificate chain failed...\n");
+				log_msg
+				    (stdout, "*** Verifying (with OCSP) server certificate chain failed...\n");
 				if (!insecure && !ssh)
 					return -1;
 			} else if (rc == 0)
-				printf("*** OCSP: nothing to check.\n");
+				log_msg(stdout, "*** OCSP: nothing to check.\n");
 			else
-				printf("*** OCSP: verified %d certificate(s).\n", rc);
+				log_msg(stdout, "*** OCSP: verified %d certificate(s).\n", rc);
 		}
 	}
 
@@ -518,10 +518,10 @@ cert_callback(gnutls_session_t session,
 		/* Print the server's trusted CAs
 		 */
 		if (nreqs > 0)
-			printf("- Server's trusted authorities:\n");
+			log_msg(stdout, "- Server's trusted authorities:\n");
 		else
-			printf
-			    ("- Server did not send us any trusted authorities names.\n");
+			log_msg
+			    (stdout, "- Server did not send us any trusted authorities names.\n");
 
 		/* print the names (if any) */
 		for (i = 0; i < nreqs; i++) {
@@ -530,8 +530,8 @@ cert_callback(gnutls_session_t session,
 			    gnutls_x509_rdn_get(&req_ca_rdn[i], issuer_dn,
 						&len);
 			if (ret >= 0) {
-				printf("   [%d]: ", i);
-				printf("%s\n", issuer_dn);
+				log_msg(stdout, "   [%d]: ", i);
+				log_msg(stdout, "%s\n", issuer_dn);
 			}
 		}
 	}
@@ -550,8 +550,8 @@ cert_callback(gnutls_session_t session,
 			if (x509_key != NULL) {
 				*pkey = x509_key;
 			} else {
-				printf
-				    ("- Could not find a suitable key to send to server\n");
+				log_msg
+				    (stdout, "- Could not find a suitable key to send to server\n");
 				return -1;
 			}
 
@@ -560,7 +560,7 @@ cert_callback(gnutls_session_t session,
 		}
 	}
 
-	printf("- Successfully sent %u certificate(s) to server.\n",
+	log_msg(stdout, "- Successfully sent %u certificate(s) to server.\n",
 	       *pcert_length);
 	return 0;
 
@@ -717,7 +717,7 @@ static int handle_error(socket_st * hd,
 		str = gnutls_alert_get_name(alert);
 		if (str == NULL)
 			str = str_unknown;
-		printf("*** Received alert [%d]: %s\n", alert, str);
+		log_msg(stdout, "*** Received alert [%d]: %s\n", alert, str);
 	}
 
 	check_server_cmd(hd, err);
@@ -813,7 +813,7 @@ static int try_rehandshake(socket_st * h
 		gnutls_perror(ret);
 		return ret;
 	} else {
-		printf("- ReHandshake was completed\n");
+		log_msg(stdout, "- ReHandshake was completed\n");
 		return 0;
 	}
 }
@@ -830,7 +830,7 @@ static int try_rekey(socket_st * hd, uns
 		fprintf(stderr, "*** Rekey has failed: %s\n", gnutls_strerror(ret));
 		return ret;
 	} else {
-		printf("- Rekey was completed\n");
+		log_msg(stdout, "- Rekey was completed\n");
 		return 0;
 	}
 }
@@ -854,13 +854,13 @@ static int try_resume(socket_st * hd)
 		hd->rdata.data = NULL;
 	}
 
-	printf("- Disconnecting\n");
+	log_msg(stdout, "- Disconnecting\n");
 	socket_bye(hd, 1);
 
 	canonicalize_host(hostname, service, sizeof(service));
 
-	printf
-	    ("\n\n- Connecting again- trying to resume previous session\n");
+	log_msg
+	    (stdout, "\n\n- Connecting again- trying to resume previous session\n");
 	if (HAVE_OPT(STARTTLS_PROTO))
 		socket_flags |= SOCKET_FLAG_STARTTLS;
 	else if (fastopen)
@@ -886,9 +886,9 @@ static int try_resume(socket_st * hd)
 	socket_open3(hd, hostname, service, OPT_ARG(STARTTLS_PROTO),
 		     socket_flags, CONNECT_MSG, &rdata, &edata);
 
-	printf("- Resume Handshake was completed\n");
+	log_msg(stdout, "- Resume Handshake was completed\n");
 	if (gnutls_session_is_resumed(hd->session) != 0)
-		printf("*** This is a resumed session\n");
+		log_msg(stdout, "*** This is a resumed session\n");
 
 	return 0;
 }
@@ -1128,12 +1128,22 @@ int main(int argc, char **argv)
 	int socket_flags = SOCKET_FLAG_DONT_PRINT_ERRORS;
 	FILE *server_fp = NULL;
 	FILE *client_fp = NULL;
+	FILE *logfile = NULL;
 #ifndef _WIN32
 	struct sigaction new_action;
 #endif
 
 	cmd_parser(argc, argv);
 
+	if (HAVE_OPT(LOGFILE)) {
+		logfile = fopen(OPT_ARG(LOGFILE), "w+");
+		if (!logfile) {
+			log_msg(stderr, "Unable to open '%s'!\n", OPT_ARG(LOGFILE));
+			exit(1);
+		}
+		log_set(logfile);
+	}
+
 	gnutls_global_set_log_function(tls_log_func);
 	gnutls_global_set_log_level(OPT_VALUE_DEBUG);
 
@@ -1178,7 +1188,7 @@ int main(int argc, char **argv)
 	hd.verbose = verbose;
 
 	if (hd.secure) {
-		printf("- Handshake was completed\n");
+		log_msg(stdout, "- Handshake was completed\n");
 
 		if (resume != 0)
 			if (try_resume(&hd)) {
@@ -1191,7 +1201,7 @@ int main(int argc, char **argv)
 
 	/* Warning!  Do not touch this text string, it is used by external
 	   programs to search for when gnutls-cli has reached this point. */
-	printf("\n- Simple Client Mode:\n\n");
+	log_msg(stdout, "\n- Simple Client Mode:\n\n");
 
 	if (rehandshake)
 		if (try_rehandshake(&hd)) {
@@ -1246,8 +1256,8 @@ int main(int argc, char **argv)
 			ret = socket_recv(&hd, buffer, MAX_BUF);
 
 			if (ret == 0 || (ret == GNUTLS_E_PREMATURE_TERMINATION && user_term)) {
-				printf
-				    ("- Peer has closed the GnuTLS connection\n");
+				log_msg
+				    (stdout, "- Peer has closed the GnuTLS connection\n");
 				break;
 			} else if (handle_error(&hd, ret) < 0) {
 				fprintf(stderr,
@@ -1256,7 +1266,7 @@ int main(int argc, char **argv)
 				break;
 			} else if (ret > 0) {
 				if (verbose != 0)
-					printf("- Received[%d]: ", ret);
+					log_msg(stdout, "- Received[%d]: ", ret);
 				for (ii = 0; ii < ret; ii++) {
 					fputc(buffer[ii], stdout);
 				}
@@ -1346,7 +1356,7 @@ int main(int argc, char **argv)
 
 			if (ret > 0) {
 				if (verbose != 0)
-					printf("- Sent: %d bytes\n", ret);
+					log_msg(stdout, "- Sent: %d bytes\n", ret);
 			} else
 				handle_error(&hd, ret);
 
@@ -1364,6 +1374,10 @@ int main(int argc, char **argv)
 
  cleanup:
 	socket_bye(&hd, 0);
+	if (logfile) {
+		fclose(logfile);
+		logfile = NULL;
+	}
 
 #ifdef ENABLE_SRP
 	if (srp_cred)
@@ -1392,21 +1406,21 @@ void print_priority_list(void)
 	const char *str;
 	unsigned int lineb = 0;
 
-	printf("Priority strings in GnuTLS %s:\n", gnutls_check_version(NULL));
+	log_msg(stdout, "Priority strings in GnuTLS %s:\n", gnutls_check_version(NULL));
 
 	fputs("\t", stdout);
 	for (idx=0;;idx++) {
 		str = gnutls_priority_string_list(idx, GNUTLS_PRIORITY_LIST_INIT_KEYWORDS);
 		if (str == NULL)
 			break;
-		lineb += printf("%s ", str);
+		lineb += log_msg(stdout, "%s ", str);
 		if (lineb > 64) {
 			lineb = 0;
-			printf("\n\t");
+			log_msg(stdout, "\n\t");
 		}
 	}
 
-	printf("\n\nSpecial strings:\n");
+	log_msg(stdout, "\n\nSpecial strings:\n");
 	lineb = 0;
 	fputs("\t", stdout);
 	for (idx=0;;idx++) {
@@ -1415,13 +1429,13 @@ void print_priority_list(void)
 			break;
 		if (str[0] == 0)
 			continue;
-		lineb += printf("%%%s ", str);
+		lineb += log_msg(stdout, "%%%s ", str);
 		if (lineb > 64) {
 			lineb = 0;
-			printf("\n\t");
+			log_msg(stdout, "\n\t");
 		}
 	}
-	printf("\n");
+	log_msg(stdout, "\n");
 
 	return;
 }
@@ -1593,15 +1607,15 @@ static void check_server_cmd(socket_st *
 			 * the server thinks we ignored his request.
 			 * This is a bad design of this client.
 			 */
-			printf("*** Received rehandshake request\n");
+			log_msg(stdout, "*** Received rehandshake request\n");
 			/* gnutls_alert_send( session, GNUTLS_AL_WARNING, GNUTLS_A_NO_RENEGOTIATION); */
 
 			ret = do_handshake(socket);
 
 			if (ret == 0) {
-				printf("*** Rehandshake was performed.\n");
+				log_msg(stdout, "*** Rehandshake was performed.\n");
 			} else {
-				printf("*** Rehandshake Failed: %s\n", gnutls_strerror(ret));
+				log_msg(stdout, "*** Rehandshake Failed: %s\n", gnutls_strerror(ret));
 			}
 		} else if (ret == GNUTLS_E_REAUTH_REQUEST) {
 			do {
@@ -1609,9 +1623,9 @@ static void check_server_cmd(socket_st *
 			} while (ret < 0 && gnutls_error_is_fatal(ret) == 0);
 
 			if (ret == 0) {
-				printf("*** Re-auth was performed.\n");
+				log_msg(stdout, "*** Re-auth was performed.\n");
 			} else {
-				printf("*** Re-auth failed: %s\n", gnutls_strerror(ret));
+				log_msg(stdout, "*** Re-auth failed: %s\n", gnutls_strerror(ret));
 			}
 		}
 	}
@@ -1678,11 +1692,11 @@ psk_callback(gnutls_session_t session, c
 	size_t res_size;
 	gnutls_datum_t tmp;
 
-	printf("- PSK client callback. ");
+	log_msg(stdout, "- PSK client callback. ");
 	if (hint)
-		printf("PSK hint '%s'\n", hint);
+		log_msg(stdout, "PSK hint '%s'\n", hint);
 	else
-		printf("No PSK hint\n");
+		log_msg(stdout, "No PSK hint\n");
 
 	if (HAVE_OPT(PSKUSERNAME))
 		*username = gnutls_strdup(OPT_ARG(PSKUSERNAME));
@@ -1690,7 +1704,7 @@ psk_callback(gnutls_session_t session, c
 		char *p = NULL;
 		size_t n;
 
-		printf("Enter PSK identity: ");
+		log_msg(stdout, "Enter PSK identity: ");
 		fflush(stdout);
 		ret = getline(&p, &n, stdin);
 
@@ -1805,7 +1819,7 @@ static void init_global_tls_stuff(void)
 		fprintf(stderr, "Error setting the x509 trust file: %s\n", gnutls_strerror(ret));
 		exit(1);
 	} else {
-		printf("Processed %d CA certificate(s).\n", ret);
+		log_msg(stdout, "Processed %d CA certificate(s).\n", ret);
 	}
 
 	if (x509_crlfile != NULL) {
@@ -1818,7 +1832,7 @@ static void init_global_tls_stuff(void)
 				"Error setting the x509 CRL file: %s\n", gnutls_strerror(ret));
 			exit(1);
 		} else {
-			printf("Processed %d CRL(s).\n", ret);
+			log_msg(stdout, "Processed %d CRL(s).\n", ret);
 		}
 	}
 
diff -NurBbp gnutls28-3.6.6/src/common.c gnutls28-3.6.7/src/common.c
--- gnutls28-3.6.6/src/common.c	2018-11-18 19:53:49.000000000 +0100
+++ gnutls28-3.6.7/src/common.c	2019-04-04 19:26:47.832143621 +0200
@@ -52,6 +52,7 @@
 
 const char str_unknown[] = "(unknown)";
 
+static FILE *logfile = NULL;
 /* Hex encodes the given data adding a semicolon between hex bytes.
  */
 const char *raw_to_string(const unsigned char *raw, size_t raw_size)
@@ -113,45 +114,6 @@ const char *raw_to_base64(const unsigned
 	return buf;
 }
 
-static void print_x509_info_compact(gnutls_session_t session, int print_crt_status)
-{
-	gnutls_x509_crt_t crt;
-	const gnutls_datum_t *cert_list;
-	unsigned int cert_list_size = 0;
-	int ret;
-	gnutls_datum_t cinfo;
-
-	cert_list = gnutls_certificate_get_peers(session, &cert_list_size);
-	if (cert_list_size == 0) {
-		if (print_crt_status)
-			fprintf(stderr, "No certificates found!\n");
-		return;
-	}
-
-	ret = gnutls_x509_crt_init(&crt);
-	if (ret < 0) {
-		fprintf(stderr, "Memory error\n");
-		return;
-	}
-
-	ret =
-	    gnutls_x509_crt_import(crt, &cert_list[0],
-				   GNUTLS_X509_FMT_DER);
-	if (ret < 0) {
-		fprintf(stderr, "Decoding error: %s\n",
-			gnutls_strerror(ret));
-		return;
-	}
-
-	ret = gnutls_x509_crt_print(crt, GNUTLS_CRT_PRINT_COMPACT, &cinfo);
-	if (ret == 0) {
-		printf("- X.509 cert: %s\n", cinfo.data);
-		gnutls_free(cinfo.data);
-	}
-
-	gnutls_x509_crt_deinit(crt);
-}
-
 static void
 print_x509_info(gnutls_session_t session, FILE *out, int flag, int print_cert, int print_crt_status)
 {
@@ -167,8 +129,8 @@ print_x509_info(gnutls_session_t session
 		return;
 	}
 
-	fprintf(out, "- Certificate type: X.509\n");
-	fprintf(out, "- Got a certificate list of %d certificates.\n",
+	log_msg(out, "- Certificate type: X.509\n");
+	log_msg(out, "- Got a certificate list of %d certificates.\n",
 	       cert_list_size);
 
 	for (j = 0; j < cert_list_size; j++) {
@@ -189,13 +151,13 @@ print_x509_info(gnutls_session_t session
 			return;
 		}
 
-		fprintf(out, "- Certificate[%d] info:\n - ", j);
+		log_msg(out, "- Certificate[%d] info:\n - ", j);
 		if (flag == GNUTLS_CRT_PRINT_COMPACT && j > 0)
 			flag = GNUTLS_CRT_PRINT_ONELINE;
 
 		ret = gnutls_x509_crt_print(crt, flag, &cinfo);
 		if (ret == 0) {
-			fprintf(out, "%s\n", cinfo.data);
+			log_msg(out, "%s\n", cinfo.data);
 			gnutls_free(cinfo.data);
 		}
 
@@ -211,9 +173,7 @@ print_x509_info(gnutls_session_t session
 				return;
 			}
 
-			fputs("\n", out);
-			fputs((char*)pem.data, out);
-			fputs("\n", out);
+			log_msg(out, "\n%s\n", (char*)pem.data);
 
 			gnutls_free(pem.data);
 		}
@@ -249,12 +209,12 @@ int cert_verify(gnutls_session_t session
 
 	rc = gnutls_certificate_verify_peers(session, data, elements, &status);
 	if (rc == GNUTLS_E_NO_CERTIFICATE_FOUND) {
-		printf("- Peer did not send any certificate.\n");
+		log_msg(stdout, "- Peer did not send any certificate.\n");
 		return 0;
 	}
 
 	if (rc < 0) {
-		printf("- Could not verify certificate (err: %s)\n",
+		log_msg(stdout, "- Could not verify certificate (err: %s)\n",
 		       gnutls_strerror(rc));
 		return 0;
 	}
@@ -263,12 +223,12 @@ int cert_verify(gnutls_session_t session
 	rc = gnutls_certificate_verification_status_print(status, type,
 							  &out, 0);
 	if (rc < 0) {
-		printf("- Could not print verification flags (err: %s)\n",
+		log_msg(stdout, "- Could not print verification flags (err: %s)\n",
 		       gnutls_strerror(rc));
 		return 0;
 	}
 
-	printf("- Status: %s\n", out.data);
+	log_msg(stdout, "- Status: %s\n", out.data);
 
 	gnutls_free(out.data);
 
@@ -298,12 +258,12 @@ print_dh_info(gnutls_session_t session,
 		return;
 	}
 
-	printf("- %sDiffie-Hellman parameters\n", str);
-	printf(" - Using prime: %d bits\n",
+	log_msg(stdout, "- %sDiffie-Hellman parameters\n", str);
+	log_msg(stdout, " - Using prime: %d bits\n",
 	       gnutls_dh_get_prime_bits(session));
-	printf(" - Secret key: %d bits\n",
+	log_msg(stdout, " - Secret key: %d bits\n",
 	       gnutls_dh_get_secret_bits(session));
-	printf(" - Peer's public key: %d bits\n",
+	log_msg(stdout, " - Peer's public key: %d bits\n",
 	       gnutls_dh_get_peers_public_bits(session));
 
 	ret = gnutls_dh_get_group(session, &raw_gen, &raw_prime);
@@ -354,7 +314,7 @@ print_dh_info(gnutls_session_t session,
 		goto out;
 	}
 
-	printf(" - PKCS#3 format:\n\n%.*s\n",
+	log_msg(stdout, " - PKCS#3 format:\n\n%.*s\n",
 	       (int) params_data_size, params_data);
 
       out:
@@ -372,12 +332,12 @@ static void print_ecdh_info(gnutls_sessi
 	if (!print)
 		return;
 
-	printf("- %sEC Diffie-Hellman parameters\n", str);
+	log_msg(stdout, "- %sEC Diffie-Hellman parameters\n", str);
 
 	curve = gnutls_ecc_curve_get(session);
 
-	printf(" - Using curve: %s\n", gnutls_ecc_curve_get_name(curve));
-	printf(" - Curve size: %d bits\n",
+	log_msg(stdout, " - Using curve: %s\n", gnutls_ecc_curve_get_name(curve));
+	log_msg(stdout, " - Curve size: %d bits\n",
 	       gnutls_ecc_curve_get_size(curve) * 8);
 
 }
@@ -396,13 +356,13 @@ int print_info(gnutls_session_t session,
 	int rc;
 
 	desc = gnutls_session_get_desc(session);
-	printf("- Description: %s\n", desc);
+	log_msg(stdout, "- Description: %s\n", desc);
 	gnutls_free(desc);
 
 	/* print session ID */
 	gnutls_session_get_id(session, session_id, &session_id_size);
 	if (session_id_size > 0) {
-		printf("- Session ID: %s\n",
+		log_msg(stdout, "- Session ID: %s\n",
 		       raw_to_string(session_id, session_id_size));
 	}
 
@@ -426,7 +386,7 @@ int print_info(gnutls_session_t session,
 		 * side.
 		 */
 		if (gnutls_srp_server_get_username(session) != NULL)
-			printf("- SRP authentication. Connected as '%s'\n",
+			log_msg(stdout, "- SRP authentication. Connected as '%s'\n",
 			       gnutls_srp_server_get_username(session));
 		break;
 #endif
@@ -435,12 +395,12 @@ int print_info(gnutls_session_t session,
 		/* This returns NULL in server side.
 		 */
 		if (gnutls_psk_client_get_hint(session) != NULL)
-			printf("- PSK authentication. PSK hint '%s'\n",
+			log_msg(stdout, "- PSK authentication. PSK hint '%s'\n",
 			       gnutls_psk_client_get_hint(session));
 		/* This returns NULL in client side.
 		 */
 		if (gnutls_psk_server_get_username(session) != NULL)
-			printf("- PSK authentication. Connected as '%s'\n",
+			log_msg(stdout, "- PSK authentication. Connected as '%s'\n",
 			       gnutls_psk_server_get_username(session));
 		if (kx == GNUTLS_KX_DHE_PSK)
 			print_dh_info(session, "Ephemeral ", verbose);
@@ -449,7 +409,7 @@ int print_info(gnutls_session_t session,
 		break;
 #endif
 	case GNUTLS_CRD_IA:
-		printf("- TLS/IA authentication\n");
+		log_msg(stdout, "- TLS/IA authentication\n");
 		break;
 	case GNUTLS_CRD_CERTIFICATE:
 		{
@@ -460,13 +420,13 @@ int print_info(gnutls_session_t session,
 			/* This fails in client side */
 			if (gnutls_server_name_get
 			    (session, dns, &dns_size, &type, 0) == 0) {
-				printf("- Given server name[%d]: %s\n",
+				log_msg(stdout, "- Given server name[%d]: %s\n",
 				       type, dns);
 			}
 		}
 
 		if ((flags & P_WAIT_FOR_CERT) && gnutls_certificate_get_ours(session) == 0)
-			printf("- No certificate was sent to peer\n");
+			log_msg(stdout, "- No certificate was sent to peer\n");
 
 		if (flags& P_PRINT_CERT)
 			print_cert_info(session, verbose, (flags&P_PRINT_CERT));
@@ -483,18 +443,18 @@ int print_info(gnutls_session_t session,
 		version = gnutls_protocol_get_version(session);
 		tmp =
 		    SU(gnutls_protocol_get_name(version));
-		printf("- Version: %s\n", tmp);
+		log_msg(stdout, "- Version: %s\n", tmp);
 
 		if (version < GNUTLS_TLS1_3) {
 			tmp = SU(gnutls_kx_get_name(kx));
-			printf("- Key Exchange: %s\n", tmp);
+			log_msg(stdout, "- Key Exchange: %s\n", tmp);
 		}
 
 		if (gnutls_sign_algorithm_get(session) != GNUTLS_SIGN_UNKNOWN) {
 			tmp =
 			    SU(gnutls_sign_get_name
 			       (gnutls_sign_algorithm_get(session)));
-			printf("- Server Signature: %s\n", tmp);
+			log_msg(stdout, "- Server Signature: %s\n", tmp);
 		}
 
 		if (gnutls_sign_algorithm_get_client(session) !=
@@ -502,41 +462,41 @@ int print_info(gnutls_session_t session,
 			tmp =
 			    SU(gnutls_sign_get_name
 			       (gnutls_sign_algorithm_get_client(session)));
-			printf("- Client Signature: %s\n", tmp);
+			log_msg(stdout, "- Client Signature: %s\n", tmp);
 		}
 
 		tmp = SU(gnutls_cipher_get_name(gnutls_cipher_get(session)));
-		printf("- Cipher: %s\n", tmp);
+		log_msg(stdout, "- Cipher: %s\n", tmp);
 
 		tmp = SU(gnutls_mac_get_name(gnutls_mac_get(session)));
-		printf("- MAC: %s\n", tmp);
+		log_msg(stdout, "- MAC: %s\n", tmp);
 	}
 
-	printf("- Options:");
+	log_msg(stdout, "- Options:");
 	if (gnutls_session_ext_master_secret_status(session)!=0)
-		printf(" extended master secret,");
+		log_msg(stdout, " extended master secret,");
 	if (gnutls_safe_renegotiation_status(session)!=0)
-		printf(" safe renegotiation,");
+		log_msg(stdout, " safe renegotiation,");
 	if (gnutls_session_etm_status(session)!=0)
-		printf(" EtM,");
+		log_msg(stdout, " EtM,");
 #ifdef ENABLE_OCSP
 	if (gnutls_ocsp_status_request_is_checked(session, GNUTLS_OCSP_SR_IS_AVAIL)!=0) {
-		printf(" OCSP status request%s,", gnutls_ocsp_status_request_is_checked(session,0)!=0?"":"[ignored]");
+		log_msg(stdout, " OCSP status request%s,", gnutls_ocsp_status_request_is_checked(session,0)!=0?"":"[ignored]");
 	}
 #endif
-	printf("\n");
+	log_msg(stdout, "\n");
 
 #ifdef ENABLE_DTLS_SRTP
 	rc = gnutls_srtp_get_selected_profile(session, &srtp_profile);
 	if (rc == 0)
-		printf("- SRTP profile: %s\n",
+		log_msg(stdout, "- SRTP profile: %s\n",
 		       gnutls_srtp_get_profile_name(srtp_profile));
 #endif
 
 #ifdef ENABLE_ALPN
 	rc = gnutls_alpn_get_selected_protocol(session, &p);
 	if (rc == 0)
-		printf("- Application protocol: %.*s\n", p.size, p.data);
+		log_msg(stdout, "- Application protocol: %.*s\n", p.size, p.data);
 #endif
 
 	if (verbose) {
@@ -551,10 +511,10 @@ int print_info(gnutls_session_t session,
 		else {
 			size_t i;
 
-			printf("- Channel binding 'tls-unique': ");
+			log_msg(stdout, "- Channel binding 'tls-unique': ");
 			for (i = 0; i < cb.size; i++)
-				printf("%02x", cb.data[i]);
-			printf("\n");
+				log_msg(stdout, "%02x", cb.data[i]);
+			log_msg(stdout, "\n");
 			gnutls_free(cb.data);
 		}
 	}
@@ -579,7 +539,7 @@ void print_cert_info2(gnutls_session_t s
 		flag = GNUTLS_CRT_PRINT_COMPACT;
 
 	if (gnutls_certificate_client_get_request_status(session) != 0) {
-		printf("- Server has requested a certificate.\n");
+		log_msg(stdout, "- Server has requested a certificate.\n");
 		print_crt_status = 1;
 	}
 
@@ -592,24 +552,6 @@ void print_cert_info2(gnutls_session_t s
 	}
 }
 
-void print_cert_info_compact(gnutls_session_t session)
-{
-	int verbose = 0;
-
-	if (gnutls_certificate_client_get_request_status(session) != 0) {
-		printf("- Server has requested a certificate.\n");
-		verbose = 1;
-	}
-
-	switch (gnutls_certificate_type_get(session)) {
-	case GNUTLS_CRT_X509:
-		print_x509_info_compact(session, verbose);
-		break;
-	default:
-		break;
-	}
-}
-
 void print_list(const char *priorities, int verbose)
 {
 	size_t i;
@@ -626,7 +568,7 @@ void print_list(const char *priorities,
 	const unsigned int *list;
 
 	if (priorities != NULL) {
-		printf("Cipher suites for %s\n", priorities);
+		log_msg(stdout, "Cipher suites for %s\n", priorities);
 
 		ret = gnutls_priority_init(&pcache, priorities, &err);
 		if (ret < 0) {
@@ -652,13 +594,13 @@ void print_list(const char *priorities,
 						     NULL, &version);
 
 			if (name != NULL)
-				printf("%-50s\t0x%02x, 0x%02x\t%s\n",
+				log_msg(stdout, "%-50s\t0x%02x, 0x%02x\t%s\n",
 				       name, (unsigned char) id[0],
 				       (unsigned char) id[1],
 				       gnutls_protocol_get_name(version));
 		}
 
-		printf("\n");
+		log_msg(stdout, "\n");
 #if 0
 		{
 			ret =
@@ -666,17 +608,17 @@ void print_list(const char *priorities,
 								  &list,
 								  GNUTLS_CTYPE_CLIENT);
 
-			printf("Certificate types: ");
+			log_msg(stdout, "Certificate types: ");
 			if (ret == 0)
-				printf("none\n");
+				log_msg(stdout, "none\n");
 			for (i = 0; i < (unsigned) ret; i++) {
-				printf("CTYPE-%s",
+				log_msg(stdout, "CTYPE-%s",
 				       gnutls_certificate_type_get_name
 				       (list[i]));
 				if (i + 1 != (unsigned) ret)
-					printf(", ");
+					log_msg(stdout, ", ");
 				else
-					printf("\n");
+					log_msg(stdout, "\n");
 			}
 		}
 #endif
@@ -684,64 +626,64 @@ void print_list(const char *priorities,
 		{
 			ret = gnutls_priority_protocol_list(pcache, &list);
 
-			printf("Protocols: ");
+			log_msg(stdout, "Protocols: ");
 			if (ret == 0)
-				printf("none\n");
+				log_msg(stdout, "none\n");
 			for (i = 0; i < (unsigned) ret; i++) {
-				printf("VERS-%s",
+				log_msg(stdout, "VERS-%s",
 				       gnutls_protocol_get_name(list[i]));
 				if (i + 1 != (unsigned) ret)
-					printf(", ");
+					log_msg(stdout, ", ");
 				else
-					printf("\n");
+					log_msg(stdout, "\n");
 			}
 		}
 
 		{
 			ret = gnutls_priority_cipher_list(pcache, &list);
 
-			printf("Ciphers: ");
+			log_msg(stdout, "Ciphers: ");
 			if (ret == 0)
-				printf("none\n");
+				log_msg(stdout, "none\n");
 			for (i = 0; i < (unsigned) ret; i++) {
-				printf("%s",
+				log_msg(stdout, "%s",
 				       gnutls_cipher_get_name(list[i]));
 				if (i + 1 != (unsigned) ret)
-					printf(", ");
+					log_msg(stdout, ", ");
 				else
-					printf("\n");
+					log_msg(stdout, "\n");
 			}
 		}
 
 		{
 			ret = gnutls_priority_mac_list(pcache, &list);
 
-			printf("MACs: ");
+			log_msg(stdout, "MACs: ");
 			if (ret == 0)
-				printf("none\n");
+				log_msg(stdout, "none\n");
 			for (i = 0; i < (unsigned) ret; i++) {
-				printf("%s",
+				log_msg(stdout, "%s",
 				       gnutls_mac_get_name(list[i]));
 				if (i + 1 != (unsigned) ret)
-					printf(", ");
+					log_msg(stdout, ", ");
 				else
-					printf("\n");
+					log_msg(stdout, "\n");
 			}
 		}
 
 		{
 			ret = gnutls_priority_kx_list(pcache, &list);
 
-			printf("Key Exchange Algorithms: ");
+			log_msg(stdout, "Key Exchange Algorithms: ");
 			if (ret == 0)
-				printf("none\n");
+				log_msg(stdout, "none\n");
 			for (i = 0; i < (unsigned) ret; i++) {
-				printf("%s",
+				log_msg(stdout, "%s",
 				       gnutls_kx_get_name(list[i]));
 				if (i + 1 != (unsigned) ret)
-					printf(", ");
+					log_msg(stdout, ", ");
 				else
-					printf("\n");
+					log_msg(stdout, "\n");
 			}
 		}
 
@@ -749,33 +691,33 @@ void print_list(const char *priorities,
 			ret =
 			    gnutls_priority_group_list(pcache, &list);
 
-			printf("Groups: ");
+			log_msg(stdout, "Groups: ");
 			if (ret == 0)
-				printf("none\n");
+				log_msg(stdout, "none\n");
 			for (i = 0; i < (unsigned) ret; i++) {
-				printf("GROUP-%s",
+				log_msg(stdout, "GROUP-%s",
 				       gnutls_group_get_name(list[i]));
 				if (i + 1 != (unsigned) ret)
-					printf(", ");
+					log_msg(stdout, ", ");
 				else
-					printf("\n");
+					log_msg(stdout, "\n");
 			}
 		}
 
 		{
 			ret = gnutls_priority_sign_list(pcache, &list);
 
-			printf("PK-signatures: ");
+			log_msg(stdout, "PK-signatures: ");
 			if (ret == 0)
-				printf("none\n");
+				log_msg(stdout, "none\n");
 			for (i = 0; i < (unsigned) ret; i++) {
-				printf("SIGN-%s",
+				log_msg(stdout, "SIGN-%s",
 				       gnutls_sign_algorithm_get_name(list
 								      [i]));
 				if (i + 1 != (unsigned) ret)
-					printf(", ");
+					log_msg(stdout, ", ");
 				else
-					printf("\n");
+					log_msg(stdout, "\n");
 			}
 		}
 
@@ -783,99 +725,99 @@ void print_list(const char *priorities,
 		return;
 	}
 
-	printf("Cipher suites:\n");
+	log_msg(stdout, "Cipher suites:\n");
 	for (i = 0; (name = gnutls_cipher_suite_info
 		     (i, id, &kx, &cipher, &mac, &version)); i++) {
-		printf("%-50s\t0x%02x, 0x%02x\t%s\n",
+		log_msg(stdout, "%-50s\t0x%02x, 0x%02x\t%s\n",
 		       name,
 		       (unsigned char) id[0], (unsigned char) id[1],
 		       gnutls_protocol_get_name(version));
 		if (verbose)
-			printf
-			    ("\tKey exchange: %s\n\tCipher: %s\n\tMAC: %s\n\n",
+			log_msg
+			    (stdout, "\tKey exchange: %s\n\tCipher: %s\n\tMAC: %s\n\n",
 			     gnutls_kx_get_name(kx),
 			     gnutls_cipher_get_name(cipher),
 			     gnutls_mac_get_name(mac));
 	}
 
-	printf("\n");
+	log_msg(stdout, "\n");
 	{
 		const gnutls_certificate_type_t *p =
 		    gnutls_certificate_type_list();
 
-		printf("Certificate types: ");
+		log_msg(stdout, "Certificate types: ");
 		for (; *p; p++) {
-			printf("CTYPE-%s",
+			log_msg(stdout, "CTYPE-%s",
 			       gnutls_certificate_type_get_name(*p));
 			if (*(p + 1))
-				printf(", ");
+				log_msg(stdout, ", ");
 			else
-				printf("\n");
+				log_msg(stdout, "\n");
 		}
 	}
 
 	{
 		const gnutls_protocol_t *p = gnutls_protocol_list();
 
-		printf("Protocols: ");
+		log_msg(stdout, "Protocols: ");
 		for (; *p; p++) {
-			printf("VERS-%s", gnutls_protocol_get_name(*p));
+			log_msg(stdout, "VERS-%s", gnutls_protocol_get_name(*p));
 			if (*(p + 1))
-				printf(", ");
+				log_msg(stdout, ", ");
 			else
-				printf("\n");
+				log_msg(stdout, "\n");
 		}
 	}
 
 	{
 		const gnutls_cipher_algorithm_t *p = gnutls_cipher_list();
 
-		printf("Ciphers: ");
+		log_msg(stdout, "Ciphers: ");
 		for (; *p; p++) {
-			printf("%s", gnutls_cipher_get_name(*p));
+			log_msg(stdout, "%s", gnutls_cipher_get_name(*p));
 			if (*(p + 1))
-				printf(", ");
+				log_msg(stdout, ", ");
 			else
-				printf("\n");
+				log_msg(stdout, "\n");
 		}
 	}
 
 	{
 		const gnutls_mac_algorithm_t *p = gnutls_mac_list();
 
-		printf("MACs: ");
+		log_msg(stdout, "MACs: ");
 		for (; *p; p++) {
-			printf("%s", gnutls_mac_get_name(*p));
+			log_msg(stdout, "%s", gnutls_mac_get_name(*p));
 			if (*(p + 1))
-				printf(", ");
+				log_msg(stdout, ", ");
 			else
-				printf("\n");
+				log_msg(stdout, "\n");
 		}
 	}
 
 	{
 		const gnutls_digest_algorithm_t *p = gnutls_digest_list();
 
-		printf("Digests: ");
+		log_msg(stdout, "Digests: ");
 		for (; *p; p++) {
-			printf("%s", gnutls_digest_get_name(*p));
+			log_msg(stdout, "%s", gnutls_digest_get_name(*p));
 			if (*(p + 1))
-				printf(", ");
+				log_msg(stdout, ", ");
 			else
-				printf("\n");
+				log_msg(stdout, "\n");
 		}
 	}
 
 	{
 		const gnutls_kx_algorithm_t *p = gnutls_kx_list();
 
-		printf("Key exchange algorithms: ");
+		log_msg(stdout, "Key exchange algorithms: ");
 		for (; *p; p++) {
-			printf("%s", gnutls_kx_get_name(*p));
+			log_msg(stdout, "%s", gnutls_kx_get_name(*p));
 			if (*(p + 1))
-				printf(", ");
+				log_msg(stdout, ", ");
 			else
-				printf("\n");
+				log_msg(stdout, "\n");
 		}
 	}
 
@@ -883,53 +825,53 @@ void print_list(const char *priorities,
 		const gnutls_compression_method_t *p =
 		    gnutls_compression_list();
 
-		printf("Compression: ");
+		log_msg(stdout, "Compression: ");
 		for (; *p; p++) {
-			printf("COMP-%s", gnutls_compression_get_name(*p));
+			log_msg(stdout, "COMP-%s", gnutls_compression_get_name(*p));
 			if (*(p + 1))
-				printf(", ");
+				log_msg(stdout, ", ");
 			else
-				printf("\n");
+				log_msg(stdout, "\n");
 		}
 	}
 
 	{
 		const gnutls_group_t *p = gnutls_group_list();
 
-		printf("Groups: ");
+		log_msg(stdout, "Groups: ");
 		for (; *p; p++) {
-			printf("GROUP-%s", gnutls_group_get_name(*p));
+			log_msg(stdout, "GROUP-%s", gnutls_group_get_name(*p));
 			if (*(p + 1))
-				printf(", ");
+				log_msg(stdout, ", ");
 			else
-				printf("\n");
+				log_msg(stdout, "\n");
 		}
 	}
 
 	{
 		const gnutls_pk_algorithm_t *p = gnutls_pk_list();
 
-		printf("Public Key Systems: ");
+		log_msg(stdout, "Public Key Systems: ");
 		for (; *p; p++) {
-			printf("%s", gnutls_pk_algorithm_get_name(*p));
+			log_msg(stdout, "%s", gnutls_pk_algorithm_get_name(*p));
 			if (*(p + 1))
-				printf(", ");
+				log_msg(stdout, ", ");
 			else
-				printf("\n");
+				log_msg(stdout, "\n");
 		}
 	}
 
 	{
 		const gnutls_sign_algorithm_t *p = gnutls_sign_list();
 
-		printf("PK-signatures: ");
+		log_msg(stdout, "PK-signatures: ");
 		for (; *p; p++) {
-			printf("SIGN-%s",
+			log_msg(stdout, "SIGN-%s",
 			       gnutls_sign_algorithm_get_name(*p));
 			if (*(p + 1))
-				printf(", ");
+				log_msg(stdout, ", ");
 			else
-				printf("\n");
+				log_msg(stdout, "\n");
 		}
 	}
 }
@@ -1069,16 +1011,16 @@ pin_callback(void *user, int attempt, co
 
 	if (flags & GNUTLS_PIN_FINAL_TRY) {
 		cache = 0;
-		printf("*** This is the final try before locking!\n");
+		log_msg(stdout, "*** This is the final try before locking!\n");
 	}
 	if (flags & GNUTLS_PIN_COUNT_LOW) {
 		cache = 0;
-		printf("*** Only few tries left before locking!\n");
+		log_msg(stdout, "*** Only few tries left before locking!\n");
 	}
 
 	if (flags & GNUTLS_PIN_WRONG) {
 		cache = 0;
-		printf("*** Wrong PIN has been provided!\n");
+		log_msg(stdout, "*** Wrong PIN has been provided!\n");
 	}
 
 	if (cache > 0 && cached_url != NULL) {
@@ -1166,7 +1108,7 @@ token_callback(void *user, const char *l
 		fprintf(stderr, "Could not find token %s\n", label);
 		return -1;
 	}
-	printf("Please insert token '%s' in slot and press enter\n",
+	log_msg(stdout, "Please insert token '%s' in slot and press enter\n",
 	       label);
 	if (fgets(buf, sizeof(buf), stdin) == NULL) {
 		fprintf(stderr, "error reading input\n");
@@ -1200,3 +1142,23 @@ void sockets_init(void)
 	signal(SIGPIPE, SIG_IGN);
 #endif
 }
+
+
+int log_msg(FILE *file, const char *message, ...)
+{
+	va_list args;
+	int rv;
+
+	va_start(args, message);
+
+	rv = vfprintf(logfile ? logfile : file, message, args);
+
+	va_end(args);
+
+	return rv;
+}
+
+void log_set(FILE *file)
+{
+	logfile = file;
+}
diff -NurBbp gnutls28-3.6.6/src/common.h gnutls28-3.6.7/src/common.h
--- gnutls28-3.6.6/src/common.h	2018-11-18 19:53:49.000000000 +0100
+++ gnutls28-3.6.7/src/common.h	2019-04-04 19:26:47.832143621 +0200
@@ -60,7 +60,9 @@ extern const char str_unknown[];
 #define P_WAIT_FOR_CERT (1<<1)
 int print_info(gnutls_session_t state, int verbose, int flags);
 void print_cert_info(gnutls_session_t, int flag, int print_cert);
-void print_cert_info_compact(gnutls_session_t session);
+
+int log_msg(FILE *file, const char *message, ...) __attribute__((format(printf, 2, 3)));
+void log_set(FILE *file);
 
 void print_cert_info2(gnutls_session_t, int flag, FILE *fp, int print_cert);
 
diff -NurBbp gnutls28-3.6.6/src/Makefile.am gnutls28-3.6.7/src/Makefile.am
--- gnutls28-3.6.6/src/Makefile.am	2019-01-25 08:26:17.000000000 +0100
+++ gnutls28-3.6.7/src/Makefile.am	2019-02-06 05:42:53.000000000 +0100
@@ -56,7 +56,7 @@ ARGS_STAMPS = \
 	systemkey-args.stamp srptool-args.stamp ocsptool-args.stamp p11tool-args.stamp \
 	danetool-args.stamp serv-args.stamp psktool-args.stamp
 
-BUILT_SOURCES = $(ARGS_BUILT) mech-list.h
+BUILT_SOURCES = $(ARGS_BUILT)
 
 DISTCLEANFILES = $(BUILT_SOURCES) $(ARGS_STAMPS)
 
@@ -226,8 +226,9 @@ libcmd_danetool_la_LIBADD += $(INET_PTON
 # p11 tool
 if ENABLE_PKCS11
 
+BUILT_SOURCES += mech-list.h
 p11tool_SOURCES = p11tool-args.def p11tool.c pkcs11.c certtool-common.c \
-	certtool-extras.c p11tool.h common.c
+	certtool-extras.c p11tool.h common.c mech-list.h
 p11tool_LDADD = ../lib/libgnutls.la
 p11tool_LDADD += libcmd-p11tool.la ../gl/libgnu.la gl/libgnu_gpl.la
 p11tool_LDADD += $(COMMON_LIBS)
diff -NurBbp gnutls28-3.6.6/src/mech-list.h gnutls28-3.6.7/src/mech-list.h
--- gnutls28-3.6.6/src/mech-list.h	1970-01-01 01:00:00.000000000 +0100
+++ gnutls28-3.6.7/src/mech-list.h	2019-03-24 08:30:24.000000000 +0100
@@ -0,0 +1,326 @@
+const char *mech_list[] = {
+	[(0UL)] = "CKM_RSA_PKCS_KEY_PAIR_GEN",
+	[(0x1000UL)] = "CKM_SKIPJACK_KEY_GEN",
+	[(0x1001UL)] = "CKM_SKIPJACK_ECB64",
+	[(0x1002UL)] = "CKM_SKIPJACK_CBC64",
+	[(0x1003UL)] = "CKM_SKIPJACK_OFB64",
+	[(0x1004UL)] = "CKM_SKIPJACK_CFB64",
+	[(0x1005UL)] = "CKM_SKIPJACK_CFB32",
+	[(0x1006UL)] = "CKM_SKIPJACK_CFB16",
+	[(0x1007UL)] = "CKM_SKIPJACK_CFB8",
+	[(0x1008UL)] = "CKM_SKIPJACK_WRAP",
+	[(0x1009UL)] = "CKM_SKIPJACK_PRIVATE_WRAP",
+	[(0x100UL)] = "CKM_RC2_KEY_GEN",
+	[(0x100aUL)] = "CKM_SKIPJACK_RELAYX",
+	[(0x1010UL)] = "CKM_KEA_KEY_PAIR_GEN",
+	[(0x1011UL)] = "CKM_KEA_KEY_DERIVE",
+	[(0x101UL)] = "CKM_RC2_ECB",
+	[(0x1020UL)] = "CKM_FORTEZZA_TIMESTAMP",
+	[(0x102UL)] = "CKM_RC2_CBC",
+	[(0x1030UL)] = "CKM_BATON_KEY_GEN",
+	[(0x1031UL)] = "CKM_BATON_ECB128",
+	[(0x1032UL)] = "CKM_BATON_ECB96",
+	[(0x1033UL)] = "CKM_BATON_CBC128",
+	[(0x1034UL)] = "CKM_BATON_COUNTER",
+	[(0x1035UL)] = "CKM_BATON_SHUFFLE",
+	[(0x1036UL)] = "CKM_BATON_WRAP",
+	[(0x103UL)] = "CKM_RC2_MAC",
+	[(0x1040UL)] = "CKM_ECDSA_KEY_PAIR_GEN",
+	[(0x1041UL)] = "CKM_ECDSA",
+	[(0x1042UL)] = "CKM_ECDSA_SHA1",
+	[(0x1043UL)] = "CKM_ECDSA_SHA224",
+	[(0x1044UL)] = "CKM_ECDSA_SHA256",
+	[(0x1045UL)] = "CKM_ECDSA_SHA384",
+	[(0x1046UL)] = "CKM_ECDSA_SHA512",
+	[(0x104UL)] = "CKM_RC2_MAC_GENERAL",
+	[(0x1050UL)] = "CKM_ECDH1_DERIVE",
+	[(0x1051UL)] = "CKM_ECDH1_COFACTOR_DERIVE",
+	[(0x1052UL)] = "CKM_ECMQV_DERIVE",
+	[(0x1053UL)] = "CKM_ECDH_AES_KEY_WRAP",
+	[(0x1054UL)] = "CKM_RSA_AES_KEY_WRAP",
+	[(0x1055UL)] = "CKM_EC_EDWARDS_KEY_PAIR_GEN",
+	[(0x1057UL)] = "CKM_EDDSA",
+	[(0x105UL)] = "CKM_RC2_CBC_PAD",
+	[(0x1060UL)] = "CKM_JUNIPER_KEY_GEN",
+	[(0x1061UL)] = "CKM_JUNIPER_ECB128",
+	[(0x1062UL)] = "CKM_JUNIPER_CBC128",
+	[(0x1063UL)] = "CKM_JUNIPER_COUNTER",
+	[(0x1064UL)] = "CKM_JUNIPER_SHUFFLE",
+	[(0x1065UL)] = "CKM_JUNIPER_WRAP",
+	[(0x1070UL)] = "CKM_FASTHASH",
+	[(0x1080UL)] = "CKM_AES_KEY_GEN",
+	[(0x1081UL)] = "CKM_AES_ECB",
+	[(0x1082UL)] = "CKM_AES_CBC",
+	[(0x1083UL)] = "CKM_AES_MAC",
+	[(0x1084UL)] = "CKM_AES_MAC_GENERAL",
+	[(0x1085UL)] = "CKM_AES_CBC_PAD",
+	[(0x1086UL)] = "CKM_AES_CTR",
+	[(0x1087UL)] = "CKM_AES_GCM",
+	[(0x1088UL)] = "CKM_AES_CCM",
+	[(0x1089UL)] = "CKM_AES_CTS",
+	[(0x108aUL)] = "CKM_AES_CMAC",
+	[(0x108bUL)] = "CKM_AES_CMAC_GENERAL",
+	[(0x108cUL)] = "CKM_AES_XCBC_MAC",
+	[(0x108dUL)] = "CKM_AES_XCBC_MAC_96",
+	[(0x108eUL)] = "CKM_AES_GMAC",
+	[(0x1090UL)] = "CKM_BLOWFISH_KEY_GEN",
+	[(0x1091UL)] = "CKM_BLOWFISH_CBC",
+	[(0x1092UL)] = "CKM_TWOFISH_KEY_GEN",
+	[(0x1093UL)] = "CKM_TWOFISH_CBC",
+	[(0x1094UL)] = "CKM_BLOWFISH_CBC_PAD",
+	[(0x1095UL)] = "CKM_TWOFISH_CBC_PAD",
+	[(0x10UL)] = "CKM_DSA_KEY_PAIR_GEN",
+	[(0x1100UL)] = "CKM_DES_ECB_ENCRYPT_DATA",
+	[(0x1101UL)] = "CKM_DES_CBC_ENCRYPT_DATA",
+	[(0x1102UL)] = "CKM_DES3_ECB_ENCRYPT_DATA",
+	[(0x1103UL)] = "CKM_DES3_CBC_ENCRYPT_DATA",
+	[(0x1104UL)] = "CKM_AES_ECB_ENCRYPT_DATA",
+	[(0x1105UL)] = "CKM_AES_CBC_ENCRYPT_DATA",
+	[(0x110UL)] = "CKM_RC4_KEY_GEN",
+	[(0x111UL)] = "CKM_RC4",
+	[(0x11UL)] = "CKM_DSA",
+	[(0x1200UL)] = "CKM_GOSTR3410_KEY_PAIR_GEN",
+	[(0x1201UL)] = "CKM_GOSTR3410",
+	[(0x1202UL)] = "CKM_GOSTR3410_WITH_GOSTR3411",
+	[(0x1203UL)] = "CKM_GOSTR3410_KEY_WRAP",
+	[(0x1204UL)] = "CKM_GOSTR3410_DERIVE",
+	[(0x120UL)] = "CKM_DES_KEY_GEN",
+	[(0x1210UL)] = "CKM_GOSTR3411",
+	[(0x1211UL)] = "CKM_GOSTR3411_HMAC",
+	[(0x121UL)] = "CKM_DES_ECB",
+	[(0x1220UL)] = "CKM_GOST28147_KEY_GEN",
+	[(0x1221UL)] = "CKM_GOST28147_ECB",
+	[(0x1222UL)] = "CKM_GOST28147",
+	[(0x1223UL)] = "CKM_GOST28147_MAC",
+	[(0x1224UL)] = "CKM_GOST28147_KEY_WRAP",
+	[(0x122UL)] = "CKM_DES_CBC",
+	[(0x123UL)] = "CKM_DES_MAC",
+	[(0x124UL)] = "CKM_DES_MAC_GENERAL",
+	[(0x125UL)] = "CKM_DES_CBC_PAD",
+	[(0x12UL)] = "CKM_DSA_SHA1",
+	[(0x130UL)] = "CKM_DES2_KEY_GEN",
+	[(0x131UL)] = "CKM_DES3_KEY_GEN",
+	[(0x132UL)] = "CKM_DES3_ECB",
+	[(0x133UL)] = "CKM_DES3_CBC",
+	[(0x134UL)] = "CKM_DES3_MAC",
+	[(0x135UL)] = "CKM_DES3_MAC_GENERAL",
+	[(0x136UL)] = "CKM_DES3_CBC_PAD",
+	[(0x137UL)] = "CKM_DES3_CMAC_GENERAL",
+	[(0x138UL)] = "CKM_DES3_CMAC",
+	[(0x13UL)] = "CKM_DSA_SHA224",
+	[(0x140UL)] = "CKM_CDMF_KEY_GEN",
+	[(0x141UL)] = "CKM_CDMF_ECB",
+	[(0x142UL)] = "CKM_CDMF_CBC",
+	[(0x143UL)] = "CKM_CDMF_MAC",
+	[(0x144UL)] = "CKM_CDMF_MAC_GENERAL",
+	[(0x145UL)] = "CKM_CDMF_CBC_PAD",
+	[(0x14UL)] = "CKM_DSA_SHA256",
+	[(0x150UL)] = "CKM_DES_OFB64",
+	[(0x151UL)] = "CKM_DES_OFB8",
+	[(0x152UL)] = "CKM_DES_CFB64",
+	[(0x153UL)] = "CKM_DES_CFB8",
+	[(0x15UL)] = "CKM_DSA_SHA384",
+	[(0x16UL)] = "CKM_DSA_SHA512",
+	[(0x2000UL)] = "CKM_DSA_PARAMETER_GEN",
+	[(0x2001UL)] = "CKM_DH_PKCS_PARAMETER_GEN",
+	[(0x2002UL)] = "CKM_X9_42_DH_PARAMETER_GEN",
+	[(0x2003UL)] = "CKM_DSA_PROBABLISTIC_PARAMETER_GEN",
+	[(0x2004UL)] = "CKM_DSA_SHAWE_TAYLOR_PARAMETER_GEN",
+	[(0x200UL)] = "CKM_MD2",
+	[(0x201UL)] = "CKM_MD2_HMAC",
+	[(0x202UL)] = "CKM_MD2_HMAC_GENERAL",
+	[(0x20UL)] = "CKM_DH_PKCS_KEY_PAIR_GEN",
+	[(0x2104UL)] = "CKM_AES_OFB",
+	[(0x2105UL)] = "CKM_AES_CFB64",
+	[(0x2106UL)] = "CKM_AES_CFB8",
+	[(0x2107UL)] = "CKM_AES_CFB128",
+	[(0x2108UL)] = "CKM_AES_CFB1",
+	[(0x2109UL)] = "CKM_AES_KEY_WRAP",
+	[(0x210UL)] = "CKM_MD5",
+	[(0x210aUL)] = "CKM_AES_KEY_WRAP_PAD",
+	[(0x211UL)] = "CKM_MD5_HMAC",
+	[(0x212UL)] = "CKM_MD5_HMAC_GENERAL",
+	[(0x21UL)] = "CKM_DH_PKCS_DERIVE",
+	[(0x220UL)] = "CKM_SHA_1",
+	[(0x221UL)] = "CKM_SHA_1_HMAC",
+	[(0x222UL)] = "CKM_SHA_1_HMAC_GENERAL",
+	[(0x230UL)] = "CKM_RIPEMD128",
+	[(0x231UL)] = "CKM_RIPEMD128_HMAC",
+	[(0x232UL)] = "CKM_RIPEMD128_HMAC_GENERAL",
+	[(0x240UL)] = "CKM_RIPEMD160",
+	[(0x241UL)] = "CKM_RIPEMD160_HMAC",
+	[(0x242UL)] = "CKM_RIPEMD160_HMAC_GENERAL",
+	[(0x250UL)] = "CKM_SHA256",
+	[(0x251UL)] = "CKM_SHA256_HMAC",
+	[(0x252UL)] = "CKM_SHA256_HMAC_GENERAL",
+	[(0x255UL)] = "CKM_SHA224",
+	[(0x256UL)] = "CKM_SHA224_HMAC",
+	[(0x257UL)] = "CKM_SHA224_HMAC_GENERAL",
+	[(0x260UL)] = "CKM_SHA384",
+	[(0x261UL)] = "CKM_SHA384_HMAC",
+	[(0x262UL)] = "CKM_SHA384_HMAC_GENERAL",
+	[(0x270UL)] = "CKM_SHA512",
+	[(0x271UL)] = "CKM_SHA512_HMAC",
+	[(0x272UL)] = "CKM_SHA512_HMAC_GENERAL",
+	[(0x280UL)] = "CKM_SECURID_KEY_GEN",
+	[(0x282UL)] = "CKM_SECURID",
+	[(0x290UL)] = "CKM_HOTP_KEY_GEN",
+	[(0x291UL)] = "CKM_HOTP",
+	[(0x2a0UL)] = "CKM_ACTI",
+	[(0x2a1UL)] = "CKM_ACTI_KEY_GEN",
+	[(0x300UL)] = "CKM_CAST_KEY_GEN",
+	[(0x301UL)] = "CKM_CAST_ECB",
+	[(0x302UL)] = "CKM_CAST_CBC",
+	[(0x303UL)] = "CKM_CAST_MAC",
+	[(0x304UL)] = "CKM_CAST_MAC_GENERAL",
+	[(0x305UL)] = "CKM_CAST_CBC_PAD",
+	[(0x30UL)] = "CKM_X9_42_DH_KEY_PAIR_GEN",
+	[(0x310UL)] = "CKM_CAST3_KEY_GEN",
+	[(0x311UL)] = "CKM_CAST3_ECB",
+	[(0x312UL)] = "CKM_CAST3_CBC",
+	[(0x313UL)] = "CKM_CAST3_MAC",
+	[(0x314UL)] = "CKM_CAST3_MAC_GENERAL",
+	[(0x315UL)] = "CKM_CAST3_CBC_PAD",
+	[(0x31UL)] = "CKM_X9_42_DH_DERIVE",
+	[(0x320UL)] = "CKM_CAST5_KEY_GEN",
+	[(0x321UL)] = "CKM_CAST5_ECB",
+	[(0x322UL)] = "CKM_CAST5_CBC",
+	[(0x323UL)] = "CKM_CAST5_MAC",
+	[(0x324UL)] = "CKM_CAST5_MAC_GENERAL",
+	[(0x325UL)] = "CKM_CAST5_CBC_PAD",
+	[(0x32UL)] = "CKM_X9_42_DH_HYBRID_DERIVE",
+	[(0x330UL)] = "CKM_RC5_KEY_GEN",
+	[(0x331UL)] = "CKM_RC5_ECB",
+	[(0x332UL)] = "CKM_RC5_CBC",
+	[(0x333UL)] = "CKM_RC5_MAC",
+	[(0x334UL)] = "CKM_RC5_MAC_GENERAL",
+	[(0x335UL)] = "CKM_RC5_CBC_PAD",
+	[(0x33UL)] = "CKM_X9_42_MQV_DERIVE",
+	[(0x340UL)] = "CKM_IDEA_KEY_GEN",
+	[(0x341UL)] = "CKM_IDEA_ECB",
+	[(0x342UL)] = "CKM_IDEA_CBC",
+	[(0x343UL)] = "CKM_IDEA_MAC",
+	[(0x344UL)] = "CKM_IDEA_MAC_GENERAL",
+	[(0x345UL)] = "CKM_IDEA_CBC_PAD",
+	[(0x350UL)] = "CKM_GENERIC_SECRET_KEY_GEN",
+	[(0x360UL)] = "CKM_CONCATENATE_BASE_AND_KEY",
+	[(0x362UL)] = "CKM_CONCATENATE_BASE_AND_DATA",
+	[(0x363UL)] = "CKM_CONCATENATE_DATA_AND_BASE",
+	[(0x364UL)] = "CKM_XOR_BASE_AND_DATA",
+	[(0x365UL)] = "CKM_EXTRACT_KEY_FROM_KEY",
+	[(0x370UL)] = "CKM_SSL3_PRE_MASTER_KEY_GEN",
+	[(0x371UL)] = "CKM_SSL3_MASTER_KEY_DERIVE",
+	[(0x372UL)] = "CKM_SSL3_KEY_AND_MAC_DERIVE",
+	[(0x373UL)] = "CKM_SSL3_MASTER_KEY_DERIVE_DH",
+	[(0x374UL)] = "CKM_TLS_PRE_MASTER_KEY_GEN",
+	[(0x375UL)] = "CKM_TLS_MASTER_KEY_DERIVE",
+	[(0x376UL)] = "CKM_TLS_KEY_AND_MAC_DERIVE",
+	[(0x377UL)] = "CKM_TLS_MASTER_KEY_DERIVE_DH",
+	[(0x378UL)] = "CKM_TLS_PRF",
+	[(0x380UL)] = "CKM_SSL3_MD5_MAC",
+	[(0x381UL)] = "CKM_SSL3_SHA1_MAC",
+	[(0x390UL)] = "CKM_MD5_KEY_DERIVATION",
+	[(0x391UL)] = "CKM_MD2_KEY_DERIVATION",
+	[(0x392UL)] = "CKM_SHA1_KEY_DERIVATION",
+	[(0x393UL)] = "CKM_SHA256_KEY_DERIVATION",
+	[(0x394UL)] = "CKM_SHA384_KEY_DERIVATION",
+	[(0x395UL)] = "CKM_SHA512_KEY_DERIVATION",
+	[(0x396UL)] = "CKM_SHA224_KEY_DERIVATION",
+	[(0x3a0UL)] = "CKM_PBE_MD2_DES_CBC",
+	[(0x3a1UL)] = "CKM_PBE_MD5_DES_CBC",
+	[(0x3a2UL)] = "CKM_PBE_MD5_CAST_CBC",
+	[(0x3a3UL)] = "CKM_PBE_MD5_CAST3_CBC",
+	[(0x3a4UL)] = "CKM_PBE_MD5_CAST5_CBC",
+	[(0x3a5UL)] = "CKM_PBE_SHA1_CAST5_CBC",
+	[(0x3a6UL)] = "CKM_PBE_SHA1_RC4_128",
+	[(0x3a7UL)] = "CKM_PBE_SHA1_RC4_40",
+	[(0x3a8UL)] = "CKM_PBE_SHA1_DES3_EDE_CBC",
+	[(0x3a9UL)] = "CKM_PBE_SHA1_DES2_EDE_CBC",
+	[(0x3aaUL)] = "CKM_PBE_SHA1_RC2_128_CBC",
+	[(0x3abUL)] = "CKM_PBE_SHA1_RC2_40_CBC",
+	[(0x3b0UL)] = "CKM_PKCS5_PBKD2",
+	[(0x3c0UL)] = "CKM_PBA_SHA1_WITH_SHA1_HMAC",
+	[(0x3d0UL)] = "CKM_WTLS_PRE_MASTER_KEY_GEN",
+	[(0x3d1UL)] = "CKM_WTLS_MASTER_KEY_DERIVE",
+	[(0x3d2UL)] = "CKM_WTLS_MASTER_KEY_DERIVE_DH_ECC",
+	[(0x3d3UL)] = "CKM_WTLS_PRF",
+	[(0x3d4UL)] = "CKM_WTLS_SERVER_KEY_AND_MAC_DERIVE",
+	[(0x3d5UL)] = "CKM_WTLS_CLIENT_KEY_AND_MAC_DERIVE",
+	[(0x3d6UL)] = "CKM_TLS10_MAC_SERVER",
+	[(0x3d7UL)] = "CKM_TLS10_MAC_CLIENT",
+	[(0x3d8UL)] = "CKM_TLS12_MAC",
+	[(0x3d9UL)] = "CKM_TLS12_KDF",
+	[(0x3e0UL)] = "CKM_TLS12_MASTER_KEY_DERIVE",
+	[(0x3e1UL)] = "CKM_TLS12_KEY_AND_MAC_DERIVE",
+	[(0x3e2UL)] = "CKM_TLS12_MASTER_KEY_DERIVE_DH",
+	[(0x3e3UL)] = "CKM_TLS12_KEY_SAFE_DERIVE",
+	[(0x3e4UL)] = "CKM_TLS_MAC",
+	[(0x3e5UL)] = "CKM_TLS_KDF",
+	[(0x4001UL)] = "CKM_RSA_PKCS_TPM_1_1",
+	[(0x4002UL)] = "CKM_RSA_PKCS_OAEP_TPM_1_1",
+	[(0x400UL)] = "CKM_KEY_WRAP_LYNKS",
+	[(0x401UL)] = "CKM_KEY_WRAP_SET_OAEP",
+	[(0x40UL)] = "CKM_SHA256_RSA_PKCS",
+	[(0x41UL)] = "CKM_SHA384_RSA_PKCS",
+	[(0x42UL)] = "CKM_SHA512_RSA_PKCS",
+	[(0x43UL)] = "CKM_SHA256_RSA_PKCS_PSS",
+	[(0x44UL)] = "CKM_SHA384_RSA_PKCS_PSS",
+	[(0x45UL)] = "CKM_SHA512_RSA_PKCS_PSS",
+	[(0x46UL)] = "CKM_SHA224_RSA_PKCS",
+	[(0x47UL)] = "CKM_SHA224_RSA_PKCS_PSS",
+	[(0x48UL)] = "CKM_SHA512_224",
+	[(0x49UL)] = "CKM_SHA512_224_HMAC",
+	[(0x4aUL)] = "CKM_SHA512_224_HMAC_GENERAL",
+	[(0x4bUL)] = "CKM_SHA512_224_KEY_DERIVATION",
+	[(0x4cUL)] = "CKM_SHA512_256",
+	[(0x4dUL)] = "CKM_SHA512_256_HMAC",
+	[(0x4eUL)] = "CKM_SHA512_256_HMAC_GENERAL",
+	[(0x4fUL)] = "CKM_SHA512_256_KEY_DERIVATION",
+	[(0x500UL)] = "CKM_CMS_SIG",
+	[(0x50UL)] = "CKM_SHA512_T",
+	[(0x510UL)] = "CKM_KIP_DERIVE",
+	[(0x511UL)] = "CKM_KIP_WRAP",
+	[(0x512UL)] = "CKM_KIP_MAC",
+	[(0x51UL)] = "CKM_SHA512_T_HMAC",
+	[(0x52UL)] = "CKM_SHA512_T_HMAC_GENERAL",
+	[(0x53UL)] = "CKM_SHA512_T_KEY_DERIVATION",
+	[(0x550UL)] = "CKM_CAMELLIA_KEY_GEN",
+	[(0x551UL)] = "CKM_CAMELLIA_ECB",
+	[(0x552UL)] = "CKM_CAMELLIA_CBC",
+	[(0x553UL)] = "CKM_CAMELLIA_MAC",
+	[(0x554UL)] = "CKM_CAMELLIA_MAC_GENERAL",
+	[(0x555UL)] = "CKM_CAMELLIA_CBC_PAD",
+	[(0x556UL)] = "CKM_CAMELLIA_ECB_ENCRYPT_DATA",
+	[(0x557UL)] = "CKM_CAMELLIA_CBC_ENCRYPT_DATA",
+	[(0x558UL)] = "CKM_CAMELLIA_CTR",
+	[(0x560UL)] = "CKM_ARIA_KEY_GEN",
+	[(0x561UL)] = "CKM_ARIA_ECB",
+	[(0x562UL)] = "CKM_ARIA_CBC",
+	[(0x563UL)] = "CKM_ARIA_MAC",
+	[(0x564UL)] = "CKM_ARIA_MAC_GENERAL",
+	[(0x565UL)] = "CKM_ARIA_CBC_PAD",
+	[(0x566UL)] = "CKM_ARIA_ECB_ENCRYPT_DATA",
+	[(0x567UL)] = "CKM_ARIA_CBC_ENCRYPT_DATA",
+	[(0x650UL)] = "CKM_SEED_KEY_GEN",
+	[(0x651UL)] = "CKM_SEED_ECB",
+	[(0x652UL)] = "CKM_SEED_CBC",
+	[(0x653UL)] = "CKM_SEED_MAC",
+	[(0x654UL)] = "CKM_SEED_MAC_GENERAL",
+	[(0x655UL)] = "CKM_SEED_CBC_PAD",
+	[(0x656UL)] = "CKM_SEED_ECB_ENCRYPT_DATA",
+	[(0x657UL)] = "CKM_SEED_CBC_ENCRYPT_DATA",
+	[(0xaUL)] = "CKM_RSA_X9_31_KEY_PAIR_GEN",
+	[(0xbUL)] = "CKM_RSA_X9_31",
+	[(0xcUL)] = "CKM_SHA1_RSA_X9_31",
+	[(0xdUL)] = "CKM_RSA_PKCS_PSS",
+	[(0xeUL)] = "CKM_SHA1_RSA_PKCS_PSS",
+	[(1UL)] = "CKM_RSA_PKCS",
+	[(2UL)] = "CKM_RSA_9796",
+	[(3UL)] = "CKM_RSA_X_509",
+	[(4UL)] = "CKM_MD2_RSA_PKCS",
+	[(5UL)] = "CKM_MD5_RSA_PKCS",
+	[(6UL)] = "CKM_SHA1_RSA_PKCS",
+	[(7UL)] = "CKM_RIPEMD128_RSA_PKCS",
+	[(8UL)] = "CKM_RIPEMD160_RSA_PKCS",
+	[(9UL)] = "CKM_RSA_PKCS_OAEP",
+};
diff -NurBbp gnutls28-3.6.6/src/serv-args.def gnutls28-3.6.7/src/serv-args.def
--- gnutls28-3.6.6/src/serv-args.def	2018-11-20 20:10:51.000000000 +0100
+++ gnutls28-3.6.7/src/serv-args.def	2019-02-13 19:45:23.000000000 +0100
@@ -51,7 +51,7 @@ flag = {
 flag = {
     name      = maxearlydata;
     arg-type  = number;
-    arg-range = "1->4294967296";
+    arg-range = "1->4294967295";
     descrip   = "The maximum early data size to accept";
     doc      = "";
 };
diff -NurBbp gnutls28-3.6.6/src/socket.c gnutls28-3.6.7/src/socket.c
--- gnutls28-3.6.6/src/socket.c	2018-11-18 19:53:49.000000000 +0100
+++ gnutls28-3.6.7/src/socket.c	2019-04-04 19:26:47.832143621 +0200
@@ -33,15 +33,16 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#ifndef _WIN32
-# include <arpa/inet.h>
-#else
-# undef endservent
-# define endservent()
-#endif
+#include <arpa/inet.h>
 #include <socket.h>
 #include <c-ctype.h>
 #include "sockets.h"
+#include "common.h"
+
+#ifdef _WIN32
+# undef endservent
+# define endservent()
+#endif
 
 #define MAX_BUF 4096
 
@@ -177,13 +178,13 @@ ssize_t wait_for_text(socket_st * socket
 		tv.tv_sec = 10;
 		tv.tv_usec = 0;
 		ret = select(socket->fd + 1, &read_fds, NULL, NULL, &tv);
-		if (ret <= 0)
-			ret = -1;
-		else
+		if (ret > 0)
 			ret = recv(socket->fd, pbuf, left, 0);
-		if (ret == -1 || ret == 0) {
-			int e = errno;
-			fprintf(stderr, "error receiving %s: %s\n", txt, strerror(e));
+		if (ret == -1) {
+			fprintf(stderr, "error receiving '%s': %s\n", txt, strerror(errno));
+			exit(2);
+		} else if (ret == 0) {
+			fprintf(stderr, "error receiving '%s': Timeout\n", txt);
 			exit(2);
 		}
 		pbuf[ret] = 0;
@@ -204,7 +205,7 @@ ssize_t wait_for_text(socket_st * socket
 			p = memmem(buf, got, txt, txt_size);
 			if (p != NULL && p != buf) {
 				p--;
-				if (*p == '\n' || *p == '\r')
+				if (*p == '\n' || *p == '\r' || (*txt == '<' && *p == '>')) // XMPP is not line oriented, uses XML format
 				break;
 			}
 		}
@@ -226,7 +227,7 @@ socket_starttls(socket_st * socket)
 
 	if (strcasecmp(socket->app_proto, "smtp") == 0 || strcasecmp(socket->app_proto, "submission") == 0) {
 		if (socket->verbose)
-			printf("Negotiating SMTP STARTTLS\n");
+			log_msg(stdout, "Negotiating SMTP STARTTLS\n");
 
 		wait_for_text(socket, "220 ", 4);
 		snprintf(buf, sizeof(buf), "EHLO %s\r\n", socket->hostname);
@@ -236,7 +237,7 @@ socket_starttls(socket_st * socket)
 		wait_for_text(socket, "220 ", 4);
 	} else if (strcasecmp(socket->app_proto, "imap") == 0 || strcasecmp(socket->app_proto, "imap2") == 0) {
 		if (socket->verbose)
-			printf("Negotiating IMAP STARTTLS\n");
+			log_msg(stdout, "Negotiating IMAP STARTTLS\n");
 
 		send_line(socket, "a CAPABILITY\r\n");
 		wait_for_text(socket, "a OK", 4);
@@ -244,7 +245,7 @@ socket_starttls(socket_st * socket)
 		wait_for_text(socket, "a OK", 4);
 	} else if (strcasecmp(socket->app_proto, "xmpp") == 0) {
 		if (socket->verbose)
-			printf("Negotiating XMPP STARTTLS\n");
+			log_msg(stdout, "Negotiating XMPP STARTTLS\n");
 
 		snprintf(buf, sizeof(buf), "<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' to='%s' version='1.0'>\n", socket->hostname);
 		send_line(socket, buf);
@@ -253,13 +254,13 @@ socket_starttls(socket_st * socket)
 		wait_for_text(socket, "<proceed", 8);
 	} else if (strcasecmp(socket->app_proto, "ldap") == 0) {
 		if (socket->verbose)
-			printf("Negotiating LDAP STARTTLS\n");
+			log_msg(stdout, "Negotiating LDAP STARTTLS\n");
 #define LDAP_STR "\x30\x1d\x02\x01\x01\x77\x18\x80\x16\x31\x2e\x33\x2e\x36\x2e\x31\x2e\x34\x2e\x31\x2e\x31\x34\x36\x36\x2e\x32\x30\x30\x33\x37"
 		send(socket->fd, LDAP_STR, sizeof(LDAP_STR)-1, 0);
 		wait_for_text(socket, NULL, 0);
 	} else if (strcasecmp(socket->app_proto, "ftp") == 0 || strcasecmp(socket->app_proto, "ftps") == 0) {
 		if (socket->verbose)
-			printf("Negotiating FTP STARTTLS\n");
+			log_msg(stdout, "Negotiating FTP STARTTLS\n");
 
 		send_line(socket, "FEAT\r\n");
 		wait_for_text(socket, "211 ", 4);
@@ -267,7 +268,7 @@ socket_starttls(socket_st * socket)
 		wait_for_text(socket, "234", 3);
 	} else if (strcasecmp(socket->app_proto, "lmtp") == 0) {
 		if (socket->verbose)
-			printf("Negotiating LMTP STARTTLS\n");
+			log_msg(stdout, "Negotiating LMTP STARTTLS\n");
 
 		wait_for_text(socket, "220 ", 4);
 		snprintf(buf, sizeof(buf), "LHLO %s\r\n", socket->hostname);
@@ -277,28 +278,28 @@ socket_starttls(socket_st * socket)
 		wait_for_text(socket, "220 ", 4);
 	} else if (strcasecmp(socket->app_proto, "pop3") == 0) {
 		if (socket->verbose)
-			printf("Negotiating POP3 STARTTLS\n");
+			log_msg(stdout, "Negotiating POP3 STARTTLS\n");
 
 		wait_for_text(socket, "+OK", 3);
 		send_line(socket, "STLS\r\n");
 		wait_for_text(socket, "+OK", 3);
 	} else if (strcasecmp(socket->app_proto, "nntp") == 0) {
 		if (socket->verbose)
-			printf("Negotiating NNTP STARTTLS\n");
+			log_msg(stdout, "Negotiating NNTP STARTTLS\n");
 
 		wait_for_text(socket, "200 ", 4);
 		send_line(socket, "STARTTLS\r\n");
 		wait_for_text(socket, "382 ", 4);
 	} else if (strcasecmp(socket->app_proto, "sieve") == 0) {
 		if (socket->verbose)
-			printf("Negotiating Sieve STARTTLS\n");
+			log_msg(stdout, "Negotiating Sieve STARTTLS\n");
 
 		wait_for_text(socket, "OK ", 3);
 		send_line(socket, "STARTTLS\r\n");
 		wait_for_text(socket, "OK ", 3);
 	} else if (strcasecmp(socket->app_proto, "postgres") == 0 || strcasecmp(socket->app_proto, "postgresql") == 0) {
 		if (socket->verbose)
-			printf("Negotiating PostgreSQL STARTTLS\n");
+			log_msg(stdout, "Negotiating PostgreSQL STARTTLS\n");
 
 #define POSTGRES_STR "\x00\x00\x00\x08\x04\xD2\x16\x2F"
 		send(socket->fd, POSTGRES_STR, sizeof(POSTGRES_STR)-1, 0);
@@ -494,7 +495,7 @@ socket_open2(socket_st * hd, const char
 	a_hostname = (char*)idna.data;
 
 	if (msg != NULL)
-		printf("Resolving '%s:%s'...\n", a_hostname, service);
+		log_msg(stdout, "Resolving '%s:%s'...\n", a_hostname, service);
 
 	/* get server name */
 	memset(&hints, 0, sizeof(hints));
@@ -543,11 +544,11 @@ socket_open2(socket_st * hd, const char
 			hd->connect_addrlen = ptr->ai_addrlen;
 
 			if (msg)
-				printf("%s '%s:%s' (TFO)...\n", msg, buffer, portname);
+				log_msg(stdout, "%s '%s:%s' (TFO)...\n", msg, buffer, portname);
 
 		} else {
 			if (msg)
-				printf("%s '%s:%s'...\n", msg, buffer, portname);
+				log_msg(stdout, "%s '%s:%s'...\n", msg, buffer, portname);
 
 			if ((err = connect(sd, ptr->ai_addr, ptr->ai_addrlen)) < 0)
 				continue;
diff -NurBbp gnutls28-3.6.6/tests/cert.c gnutls28-3.6.7/tests/cert.c
--- gnutls28-3.6.6/tests/cert.c	2017-04-19 21:49:27.000000000 +0200
+++ gnutls28-3.6.7/tests/cert.c	2019-02-25 19:14:55.000000000 +0100
@@ -89,7 +89,6 @@ static int getnextcert(DIR **dirp, gnutl
 				*exp_ret = atoi((char*)local.data);
 				success("expecting error code %d\n", *exp_ret);
 				gnutls_free(local.data);
-				local.data = NULL;
 			}
 
 			return 0;
@@ -135,7 +134,6 @@ void doit(void)
 
 		gnutls_x509_crt_deinit(cert);
 		gnutls_free(der.data);
-		der.data = NULL;
 		der.size = 0;
 		exp_ret = -1;
 	}
diff -NurBbp gnutls28-3.6.6/tests/cert-status.c gnutls28-3.6.7/tests/cert-status.c
--- gnutls28-3.6.6/tests/cert-status.c	2018-11-18 19:54:13.000000000 +0100
+++ gnutls28-3.6.7/tests/cert-status.c	2019-03-08 20:16:12.000000000 +0100
@@ -252,11 +252,11 @@ void doit(void)
 
 	start("NORMAL:-VERS-ALL:+VERS-TLS1.3", GNUTLS_CERT_IGNORE, 0);
 	start("NORMAL:-VERS-ALL:+VERS-TLS1.3", GNUTLS_CERT_REQUEST, 0);
-	start("NORMAL:-VERS-ALL:+VERS-TLS1.3", GNUTLS_CERT_REQUIRE, GNUTLS_E_NO_CERTIFICATE_FOUND);
+	start("NORMAL:-VERS-ALL:+VERS-TLS1.3", GNUTLS_CERT_REQUIRE, GNUTLS_E_CERTIFICATE_REQUIRED);
 
 	start("NORMAL", GNUTLS_CERT_IGNORE, 0);
 	start("NORMAL", GNUTLS_CERT_REQUEST, 0);
-	start("NORMAL", GNUTLS_CERT_REQUIRE, GNUTLS_E_NO_CERTIFICATE_FOUND);
+	start("NORMAL", GNUTLS_CERT_REQUIRE, GNUTLS_E_CERTIFICATE_REQUIRED);
 }
 
 #endif				/* _WIN32 */
diff -NurBbp gnutls28-3.6.6/tests/cert-tests/certtool gnutls28-3.6.7/tests/cert-tests/certtool
--- gnutls28-3.6.6/tests/cert-tests/certtool	2018-12-20 17:39:32.000000000 +0100
+++ gnutls28-3.6.7/tests/cert-tests/certtool	2019-04-04 19:26:47.832143621 +0200
@@ -132,6 +132,20 @@ if test "${id}" != "c4880390506a849cd2d8
 	exit 1
 fi
 
+# Test whether certtool --outder doesn't output the informational text data
+
+${VALGRIND} "${CERTTOOL}" -i --infile "${srcdir}/data/funny-spacing.pem" --outder --outfile ${TMPFILE1}
+if test $? != 0;then
+	echo "cert output to DER failed"
+	exit 1
+fi
+
+grep 'Version:' ${TMPFILE1}
+if test $? = 0;then
+	echo "found text info in DER certificate"
+	exit 1
+fi
+
 rm -f ${TMPFILE1} ${TMPFILE2}
 
 export TZ="UTC"
diff -NurBbp gnutls28-3.6.6/tests/cert-tests/data/cve-2019-3829.pem gnutls28-3.6.7/tests/cert-tests/data/cve-2019-3829.pem
--- gnutls28-3.6.6/tests/cert-tests/data/cve-2019-3829.pem	1970-01-01 01:00:00.000000000 +0100
+++ gnutls28-3.6.7/tests/cert-tests/data/cve-2019-3829.pem	2019-03-27 07:20:12.000000000 +0100
@@ -0,0 +1,66 @@
+-----BEGIN CERTIFICATE-----
+MIIFbjCCBFagAwIBAgIQPBKFvactgik351RXZ5opvTANBgkqhkiG9w0BAQUFADCB
+tDELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQL
+ExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTswOQYDVQQLEzJUZXJtcyBvZiB1c2Ug
+YXQgaHR0cHM6Ly93d3cudmVyaXNpZ24uY29tL3JwYSAoYykxMDEuMCwGA1UEAxMl
+VmVyaVNpZ24gQ2xhc3MgMyBDb2RlIFNpZ25pbmcgMjAxMCBDQTAeFw0xMjA4MTcw
+MDAwMDBaFw0xNTA5MDkyMzU5NTlaMIGxMQswCQYDVQQGEwJVUzETMBEGA1UECBMK
+Q2FsaWZvcm5pYTETMBEGA1UEBxMKTWVubG8gUGFyazEbMBkGA1UEChQSUk9CTE9Y
+IENvcnBvcmF0aW9uMT4wPAYDVQQLEzVEaWdpdGFsIElEIENsYXNzIDMgLSBNaWNy
+b3NvZnQgU29mdHdhcmUgVmFsaWRhdGlvbiB2MjEbMBkGA1UEAxQSUk9CTE9YIENv
+cnBvcmF0aW9uMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA9Vg9Z0ee
+4Tg3pwyw9CcQCINfJEWLhhvrB88pcnyMKxbB7v3qwwfi9VhL0fRM/AusgONWrQuW
+2gftlw9ZtQMAWRkLvPHM3hXz5ch1XpvTmNqPQrSGfn9te7T9018ORa+WVuUCKzhL
+xMSxG+VEpSRZsSdhq/chwA3fqhdUdq7fdxo6H3v/RV8bDUz1vRow+ygtAMneh8/x
+kvnnyGZrW7BzJH6odOq4ASbx08czrKzqxnnoiFDmPuBTjv5wCLz0yHboHRQ/aC25
+GKXNioEVAGY/nWxVetFgJG8SwiIBR9C4KHaUqLHpPDU40WW7jGvybDaEGWXBQfTr
+e1Dj/B3JY6SGhwIDAQABo4IBezCCAXcwCQYDVR0TBAIwADAOBgNVHQ8BAf8EBAMC
+B4AwQAYDVR0fBDkwNzA1oDOgMYYvaHR0cDovL2NzYzMtMjAxMC1jcmwudmVyaXNp
+Z24uY29tL0NTQzMtMjAxMC5jcmwwRAYDVR0gBD0wOzA5BgtghkgBhvhFAQcXAzAq
+MCgGCCsGAQUFBwIBFhybdHRwczovL3d3dy52ZXJpc2lnbi5jb20vcnBhMBMGA1Ud
+JQQMMAoGCCsGAQUFBwMDMHEGCCsGAQVLBwEBBGUwYzAkBggrBgEFBQcwAYYYaHR0
+cDovL29jc3AudmVyaXNpZ24uY29tMDsGCCsGAQUFBzAChi9odHRwOi8vY3NjMy0y
+MDEwLWFpYS52ZXJpc2lnbnhjb20vQ1NDMy0yMDEwLmNlcjAfBgNVHSMEGDAWgFBt
+48zqeyb0S8mOj9fwBSbv49KnnTARBglgIEgBhvhCAQEEBAMCBBAwFgYKKwYBBAGC
+NwIBGwQIMAYBAQABAf8wDQYJKoZIhvcNAQEFBQADggEBeCwxl3jzuZqItKl531TN
+TCCx3yoOfpZnGd7acfLyfeX8xDy7wakiOyC1nxv1FL7+H//Mku+F3Ne/A0HmnHx0
+sD9F1fYxweF8ubSoRqwUCXSMB4YZuwRAfUILon6YvyHU1kgPYwr0bsYu28l0liQY
+YC7ALFbwO2ecxOYgg38mho+XRRXPd/PtOfmZ23yeKvrD0Hm499jC1OloFX+8G4ly
+mz9Y8aoDBzkEYcXWn3Rz1p6EQJnWJzI/jSxMKIuI2/Ge+oIFZpEGK3Hec3sYqLs4
+EUOfWI4bNm1W+eU0E2bwuWmjddgTdOWHaYm7jMlCzkZw9qg2/IE2fTu7P7UuNOvw
+av0=
+-----END CERTIFICATE-----
+-----BEGIN CERTIFICATE-----
+MIIF4jCCBMqgAwIBAgIQJ1P4Bv6RNzIvW0CfHDGHXDANBgkqhkiG9w0BAQUFADCB
+yjELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQL
+ExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJp
+U2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxW
+ZXJpU2lnbiBDbGFzcyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0
+aG9yaXR5IC0gRzUwHhcNMTAwMjA4MDAwMDAwWhcNMjAwMjA3MjM1OTU5WjCBtDEL
+MAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQLExZW
+ZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTswOQYDVQQLEzJUZXJtcyBvZiB1c2UgYXQg
+aHR0cHM6Ly93d3cudmVyaXNpZ24uY29tL3JwYSAoYykxMDEuMCwGA1UEAxMlVmVy
+aVNpZ24gQ2xhc3MgMyBDb2RlIFNpZ25pbmcgMjAxMCBDQTCCASIwDQYJKoZIhvcN
+AQEBBQADggEPADCCAQoCggEBAPUjS16l14q7MunUV/fv5Mcmfq0ZmP6onX2U9jZr
+ENd1gTB/BGh/yyt1Hs0dCIzfaZSnN6Oce4DgmeHuN01fzjsU7obU0PUnNbwlCzin
+jGOdF6MIpauw+81qYoJM1SHaG9nx44Q7iipPhVuQAU/Jp3YQfycDfL6ufn3B3fkF
+vBtInGnnwKQ8PEEAPt+W5cXklHHWVQHHACZKQDy1oSapDKdtgI6QJXvPvz8c6y+W
++uWHd8a1VrJ6O1QwUxvfYjT/HtH0WpMoheVMF05+W/2kk5l/383vpHXv7xX2R+f4
+GXLYLjQaprSnTH69u08MPVfxMNamNo7WgHbXGS6lzX40LYkCAwEAAaOCAdYwggHS
+MBIGA1UdEwEB/wQIMAYBAf8CAQAwcAYDVR0gBGkwZzBlBgtghkgBhvhFAQcXAzBW
+MCgGCCsGAQUFBwIBFhxodHRwczovL3d3dy52ZXJpc2lnbi5jb20vY3BzMCoGCCsG
+AQUFBwICMB4aHGh0dHBzOi8vd3d3LnZlcmlzaWduLmNvbS9ycGEwDgYDVR0PAQH/
+BAQDAgEGMG0GCCsGAQUFBwEMBGEwX6FdoFswWTBXMFUWCWltYWdlL2dpZjAhMB8w
+BwYFKw4DAhoEFI/l0xqGrI2Oa8PPgGrUSBgsexkuMCUWI2h0dHA6Ly9sb2dvLnZl
+cmlzaWduLmNvbS92c2xvZ28uZ2lmMDQGA1UdHwQtMCswKaAnoCWGI2h0dHA6Ly9j
+cmwudmVyaXNpZ24uY29tL3BjYTMtZzUuY3JsMCgGA1UdEQQhMB+kHTAbMRkwFwYD
+VQQDExBWZXJpU2lnbk1QS0ktMi04MB0GA1UdDgQWBBTPmanqeyb0S8mOj9fwBSbv
+49KnnTArBgNVHSUEJDAiBggrBgEFBQcDAgYIKwYBBQUHAwMGDCqGOgABg4+JDQEB
+ATAfBgNVHSMEGDAWgBR/02Wnwt3su/AwCfNDOfoCrzMxMzANBgkqhkiG9w0BAQUF
+AAOCAQEAW46f07q+qa8aPmWBt8Fk9qJ460yABjqsIm6MK7xdhX/AjxAqysStliQB
+aP9ltdEULCql2kmWr+nU/3GckwlKamH0S9HLtl8p/GgR5XL/Rg82KZlDnrPZrEeT
+e+/E62aGp9aJVD6Umw2R8NIjasANN85G35WupGXGGL+kaXM/6IXQSH0o7/NfsAG0
+dbTRU0v0b/aki2a273g5xYgrZzIa70DAlPa30ouEoCZvikvF2NxU7uJKVqq8cuWT
+5j+23m1seyVbAexvKWS38y4j9h+uES3GurnrCGCxLRsrnr6FdAodLipSkRgg18my
+l4SPFiwyyhgSqsUgWcr7bTcy48WjhA==
+-----END CERTIFICATE-----
diff -NurBbp gnutls28-3.6.6/tests/cert-tests/data/invalid-sig4.pem gnutls28-3.6.7/tests/cert-tests/data/invalid-sig4.pem
--- gnutls28-3.6.6/tests/cert-tests/data/invalid-sig4.pem	1970-01-01 01:00:00.000000000 +0100
+++ gnutls28-3.6.7/tests/cert-tests/data/invalid-sig4.pem	2019-02-23 18:48:28.000000000 +0100
@@ -0,0 +1,23 @@
+-----BEGIN CERTIFICATE-----
+MIID1jCCAr2gAwIBAgIDAjbRMA0GCSqGSIb3DQEBBQUAMEIxCzAJBgNVBAYTAlVT
+MRYwFAYDVQQKEw1HZW9UcnVzdCBJbmMuMRswGQYDVQQDExJHZW9UcnVzdCBHbG9i
+YWwgQ0EwHhcNMTAwMjE5MjI0NTA1WhcNMjAwMjE4MjI0NTA1WjA8MQswCQYDVQQG
+EwJVUzEXMBUGA1UEChMOR2VvVHJ1c3QsIEluYy4xFDASBgNVBAMTC1JhcGlkU1NM
+IENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAx3H4Vsce2cy1rfa0
+l6P7oeYLUF9QqjraD/w9KSRDxhApwfxVQHLuverfn7ZB9EhLyG7+T1cSi1v6kt1e
+6K3z8Buxe037z/3R5fjj3Of1c3/fAUnPjFbBvTfjW761T4uL8NpPx+PdVUdp3/Jb
+ewdPPeWsIcHIHXro5/YPoar1b96oZU8QiZwD84l6pV4BcjPtqelaHnnzh8jfyMX8
+N8iamte4dsywPuf95lTq319SQXhZV63xEtZ/vNWfcNMFbPqjfWdY3SZiHTGSDHl5
+HI7PynvBZq+odEj7joLCniyZXHstXZu8W1eefDp6E63yoxhbK1kPzVw662gzxigd
+gtFQiwIDAQABo4HZMIHWMA4GA1UdDwEB/wQEAwIBBjAdBgNVHQ4EFgQUa2k9ahhC
+St2PAmU5/TUkhniRFjAwHwYDVR0jBBgwFoAUwHqYaI2J+6sFZAwRfap9ZbjKzE4w
+EgYDVR0TAQH/BAgwBgEB/wIBADA6BgNVHR8EMzAxMC+gLaArhilodHRwOi8vY3Js
+Lmdlb3RydXN0LmNvbS9jcmxzL2d0Z2xvYmFsLmNybDA0BggrBgEFBQcBAQQoMCYw
+JAYIKwYBBQUHMAGGGGh0dHA6Ly9vY3NwLmdlb3RydXN0LmNvbTAOBgkqhkiG9w0B
+AQUEAUEDggEBAKu8vApdGJTjwbHDqExV1r60mPHuPBzNz/MkJFyWAydY/Dauoi+P
+8f7aKwLDM73I3UgiK2APpQMQ/Xf40O2WZ0/96kcgcFTcqQxVfuGWJYrZtdpXSr6N
+jklDY6VsTieHJetbbf6ifzgo4DarrTmlpWLEt1xYLKpdAWCmYmejwMdiI/TnbEbu
+tdOAaiIT0i0/dE/qr4xftDic267Or4QepvY0UVl50+N13LzX83PfkuzSIFlvnPuV
++JJ2GAp8Dyymyt6KYnvY885faL2PPsF0uxVyOhaDqQvmTZmc2FfsqAFRx29XNF6r
+SixC9k8ciXjeJk71b5NMFWsnVk0AVGx6t7c=
+-----END CERTIFICATE-----
diff -NurBbp gnutls28-3.6.6/tests/cert-tests/data/invalid-sig4.pem~ gnutls28-3.6.7/tests/cert-tests/data/invalid-sig4.pem~
--- gnutls28-3.6.6/tests/cert-tests/data/invalid-sig4.pem~	1970-01-01 01:00:00.000000000 +0100
+++ gnutls28-3.6.7/tests/cert-tests/data/invalid-sig4.pem~	2019-02-12 05:51:52.000000000 +0100
@@ -0,0 +1,98 @@
+X.509 Certificate Information:
+	Version: 3
+	Serial Number (hex): 0236d1
+	Issuer: CN=GeoTrust Global CA,O=GeoTrust Inc.,C=US
+	Validity:
+		Not Before: Fri Feb 19 22:45:05 UTC 2010
+		Not After: Tue Feb 18 22:45:05 UTC 2020
+	Subject: CN=RapidSSL CA,O=GeoTrust\, Inc.,C=US
+	Subject Public Key Algorithm: RSA
+	Algorithm Security Level: Medium (2048 bits)
+		Modulus (bits 2048):
+			00:c7:71:f8:56:c7:1e:d9:cc:b5:ad:f6:b4:97:a3:fb
+			a1:e6:0b:50:5f:50:aa:3a:da:0f:fc:3d:29:24:43:c6
+			10:29:c1:fc:55:40:72:ee:bd:ea:df:9f:b6:41:f4:48
+			4b:c8:6e:fe:4f:57:12:8b:5b:fa:92:dd:5e:e8:ad:f3
+			f0:1b:b1:7b:4d:fb:cf:fd:d1:e5:f8:e3:dc:e7:f5:73
+			7f:df:01:49:cf:8c:56:c1:bd:37:e3:5b:be:b5:4f:8b
+			8b:f0:da:4f:c7:e3:dd:55:47:69:df:f2:5b:7b:07:4f
+			3d:e5:ac:21:c1:c8:1d:7a:e8:e7:f6:0f:a1:aa:f5:6f
+			de:a8:65:4f:10:89:9c:03:f3:89:7a:a5:5e:01:72:33
+			ed:a9:e9:5a:1e:79:f3:87:c8:df:c8:c5:fc:37:c8:9a
+			9a:d7:b8:76:cc:b0:3e:e7:fd:e6:54:ea:df:5f:52:41
+			78:59:57:ad:f1:12:d6:7f:bc:d5:9f:70:d3:05:6c:fa
+			a3:7d:67:58:dd:26:62:1d:31:92:0c:79:79:1c:8e:cf
+			ca:7b:c1:66:af:a8:74:48:fb:8e:82:c2:9e:2c:99:5c
+			7b:2d:5d:9b:bc:5b:57:9e:7c:3a:7a:13:ad:f2:a3:18
+			5b:2b:59:0f:cd:5c:3a:eb:68:33:c6:28:1d:82:d1:50
+			8b
+		Exponent (bits 24):
+			01:00:01
+	Extensions:
+		Key Usage (critical):
+			Certificate signing.
+			CRL signing.
+		Subject Key Identifier (not critical):
+			6b693d6a18424add8f026539fd35248678911630
+		Authority Key Identifier (not critical):
+			c07a98688d89fbab05640c117daa7d65b8cacc4e
+		Basic Constraints (critical):
+			Certificate Authority (CA): TRUE
+			Path Length Constraint: 0
+		CRL Distribution points (not critical):
+			URI: http://crl.geotrust.com/crls/gtglobal.crl
+		Authority Information Access (not critical):
+			Access Method: 1.3.6.1.5.5.7.48.1 (id-ad-ocsp)
+			Access Location URI: http://ocsp.geotrust.com
+	Signature Algorithm: RSA-SHA1
+warning: signed using a broken signature algorithm that can be forged.
+	Signature:
+		ab:bc:bc:0a:5d:18:94:e3:c1:b1:c3:a8:4c:55:d6:be
+		b4:98:f1:ee:3c:1c:cd:cf:f3:24:24:5c:96:03:27:58
+		fc:36:ae:a2:2f:8f:f1:fe:da:2b:02:c3:33:bd:c8:dd
+		48:22:2b:60:0f:a5:03:10:fd:77:f8:d0:ed:96:67:4f
+		fd:ea:47:20:70:54:dc:a9:0c:55:7e:e1:96:25:8a:d9
+		b5:da:57:4a:be:8d:8e:49:43:63:a5:6c:4e:27:87:25
+		eb:5b:6d:fe:a2:7f:38:28:e0:36:ab:ad:39:a5:a5:62
+		c4:b7:5c:58:2c:aa:5d:01:60:a6:62:67:a3:c0:c7:62
+		23:f4:e7:6c:46:ee:b5:d3:80:6a:22:13:d2:2d:3f:74
+		4f:ea:af:8c:5f:b4:38:9c:db:ae:ce:af:84:1e:a6:f6
+		34:51:59:79:d3:e3:75:dc:bc:d7:f3:73:df:92:ec:d2
+		20:59:6f:9c:fb:95:f8:92:76:18:0a:7c:0f:2c:a6:ca
+		de:8a:62:7b:d8:f3:ce:5f:68:bd:8f:3e:c1:74:bb:15
+		72:3a:16:83:a9:0b:e6:4d:99:9c:d8:57:ec:a8:01:51
+		c7:6f:57:34:5e:ab:4a:2c:42:f6:4f:1c:89:78:de:26
+		4e:f5:6f:93:4c:15:6b:27:56:4d:00:54:6c:7a:b7:b7
+Other Information:
+	Fingerprint:
+		sha1:871bbf3d924782aff672af8031d391e5b8aea17b
+		sha256:2cbe57c1cda1b0546bcb4b71836cca8e606aae2768944fe992eb3ccd7d6024d6
+	Public Key ID:
+		sha1:a39399c404c3b209b081c21f21622778c2748e4c
+		sha256:953d3d80f51e41f6d8ae5c51b69b07ae30db963f51a73faeeda8df0ab838a833
+	Public Key PIN:
+		pin-sha256:lT09gPUeQfbYrlxRtpsHrjDblj9Rpz+u7ajfCrg4qDM=
+
+-----BEGIN CERTIFICATE-----
+MIID1jCCAr2gAwIBAgIDAjbRMA0GCSqGSIb3DQEBBQUAMEIxCzAJBgNVBAYTAlVT
+MRYwFAYDVQQKEw1HZW9UcnVzdCBJbmMuMRswGQYDVQQDExJHZW9UcnVzdCBHbG9i
+YWwgQ0EwHhcNMTAwMjE5MjI0NTA1WhcNMjAwMjE4MjI0NTA1WjA8MQswCQYDVQQG
+EwJVUzEXMBUGA1UEChMOR2VvVHJ1c3QsIEluYy4xFDASBgNVBAMTC1JhcGlkU1NM
+IENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAx3H4Vsce2cy1rfa0
+l6P7oeYLUF9QqjraD/w9KSRDxhApwfxVQHLuverfn7ZB9EhLyG7+T1cSi1v6kt1e
+6K3z8Buxe037z/3R5fjj3Of1c3/fAUnPjFbBvTfjW761T4uL8NpPx+PdVUdp3/Jb
+ewdPPeWsIcHIHXro5/YPoar1b96oZU8QiZwD84l6pV4BcjPtqelaHnnzh8jfyMX8
+N8iamte4dsywPuf95lTq319SQXhZV63xEtZ/vNWfcNMFbPqjfWdY3SZiHTGSDHl5
+HI7PynvBZq+odEj7joLCniyZXHstXZu8W1eefDp6E63yoxhbK1kPzVw662gzxigd
+gtFQiwIDAQABo4HZMIHWMA4GA1UdDwEB/wQEAwIBBjAdBgNVHQ4EFgQUa2k9ahhC
+St2PAmU5/TUkhniRFjAwHwYDVR0jBBgwFoAUwHqYaI2J+6sFZAwRfap9ZbjKzE4w
+EgYDVR0TAQH/BAgwBgEB/wIBADA6BgNVHR8EMzAxMC+gLaArhilodHRwOi8vY3Js
+Lmdlb3RydXN0LmNvbS9jcmxzL2d0Z2xvYmFsLmNybDA0BggrBgEFBQcBAQQoMCYw
+JAYIKwYBBQUHMAGGGGh0dHA6Ly9vY3NwLmdlb3RydXN0LmNvbTAOBgkqhkiG9w0B
+AQUEAUEDggEBAKu8vApdGJTjwbHDqExV1r60mPHuPBzNz/MkJFyWAydY/Dauoi+P
+8f7aKwLDM73I3UgiK2APpQMQ/Xf40O2WZ0/96kcgcFTcqQxVfuGWJYrZtdpXSr6N
+jklDY6VsTieHJetbbf6ifzgo4DarrTmlpWLEt1xYLKpdAWCmYmejwMdiI/TnbEbu
+tdOAaiIT0i0/dE/qr4xftDic267Or4QepvY0UVl50+N13LzX83PfkuzSIFlvnPuV
++JJ2GAp8Dyymyt6KYnvY885faL2PPsF0uxVyOhaDqQvmTZmc2FfsqAFRx29XNF6r
+SixC9k8ciXjeJk71b5NMFWsnVk0AVGx6t7c=
+-----END CERTIFICATE-----
diff -NurBbp gnutls28-3.6.6/tests/cert-tests/data/invalid-sig5.pem gnutls28-3.6.7/tests/cert-tests/data/invalid-sig5.pem
--- gnutls28-3.6.6/tests/cert-tests/data/invalid-sig5.pem	1970-01-01 01:00:00.000000000 +0100
+++ gnutls28-3.6.7/tests/cert-tests/data/invalid-sig5.pem	2019-02-23 18:48:28.000000000 +0100
@@ -0,0 +1,22 @@
+-----BEGIN CERTIFICATE-----
+MIIDmjCCAlKgAwIBAgIMWXnRYyHbNWzuFxmzMD0GCSqGSIb3DQEBCjAwoA0wCwYJ
+YIZIAWUDBAIBoRowGAYJKoZIhvcNAQEIMAsGCWCGSAFlAwQCAaIDAgFAMA8xDTAL
+BgNVBAMTBENBLTAwIBcNMTcwNzI3MTE0MTIzWhgPOTk5OTEyMzEyMzU5NTlaMA8x
+DTALBgNVBAMTBENBLTEwggFSMD0GCSqGSIb3DQEBCjAwoA0wCwYJYIZIAWUDBAIB
+oRowGAYJKoZIhvcNAQEIMAsGCWCGSAFlAwQCAaIDAgEgA4IBDwAwggEKAoIBAQDB
+uQ2UwKWT1BfN6H2B3svKL34aPW/+MTfN8McvExZsZYuQyRxeG8SV4uJ+GAtJ/Ml/
+eaUqiKG0pNCna846FUtAax/0quuVSaZ2xOVA3lMKj2frtRLJ3W6ZaglCHkZUHhII
+JEtE1s0F8aaaZ6X4/57OAi6uyFNuBSBsp3giQS6SrtFMbhq7OuSSt2T14XlVGvAI
+TiO7t21+Eukq2jDGOerUax4Yxki4l8589uXu5IQzZalj42hr9YKbNb75RAICNnY8
+jxCezc0o8KNoDF0IAK7UERz6uUQElUh/bdm0k3UV+uVA6t0disZ4gdenPuLsGSVD
+9fcbh/zFlv2V3A9HLJB3AgMBAAGjZDBiMA8GA1UdEwEB/wQFMAMBAf8wDwYDVR0P
+AQH/BAUDAwcEADAdBgNVHQ4EFgQU6h4fxmpkIoNy/qx6u4Z13H7WN+QwHwYDVR0j
+BBgwFoAUZ97LfvATPRiWxwNOO+sxC5ig8VkwPQYJKoZIhvcNAQEKMDCgDTALBglg
+hkgBZQMEAgGhGjAYBgkqhkiG9w0BAQgwCwYJYIZIAWUDBAIBogMCASADggEBAFGH
+zxWW8R95wmmuDecuKf31LEKPubtaeqMRqt2Vk2mGCQOxcerl6MMGyl3w46hEkAjU
+jAPwmNnB9xyEyqR5w2TYrpzsrnUcZn+6HzSiPTEJ0jhY2S8N2V+Bch1QgMwlgeaD
+bZrY6qAG6PeqoQ8XhZ8+1sI/IpQKJHmmBN+qYbLFxEPjE4QnBahPbKfbpMY0MMX0
+uuI2nSBKcYmkYiWBYdydpP24VfeoUP0V6bXc5rrDdCNGp+AxUID51GT0AoMf2FGK
+LeOLJtPqH7raz44pa1qezHq4gPeXC0Ende9j7IimpsdB6eDVle8UZipfeASq9XVL
+F430KTcS7x42r71NZUU=
+-----END CERTIFICATE-----
diff -NurBbp gnutls28-3.6.6/tests/cert-tests/invalid-sig gnutls28-3.6.7/tests/cert-tests/invalid-sig
--- gnutls28-3.6.6/tests/cert-tests/invalid-sig	2016-07-09 10:37:35.000000000 +0200
+++ gnutls28-3.6.7/tests/cert-tests/invalid-sig	2019-03-27 07:20:12.000000000 +0100
@@ -29,6 +29,10 @@ if ! test -z "${VALGRIND}"; then
 	VALGRIND="${LIBTOOL:-libtool} --mode=execute ${VALGRIND}"
 fi
 
+if ! test -x "${CERTTOOL}"; then
+	exit 77
+fi
+
 #check whether a different PKCS #1 signature than the advertized in certificate is tolerated
 ${VALGRIND} "${CERTTOOL}" -e --infile "${srcdir}/data/invalid-sig.pem"
 rc=$?
@@ -59,4 +63,34 @@ if test "${rc}" = "0"; then
 	exit ${rc}
 fi
 
+#check whether different parameters in tbsCertificate than the outer signature is tolerated
+${VALGRIND} "${CERTTOOL}" -e --infile "${srcdir}/data/invalid-sig4.pem"
+rc=$?
+
+# We're done.
+if test "${rc}" = "0"; then
+	echo "Verification of invalid signature (4) failed"
+	exit ${rc}
+fi
+
+#check whether different RSA-PSS parameters in tbsCertificate than the outer signature is tolerated
+${VALGRIND} "${CERTTOOL}" --verify-chain --infile "${srcdir}/data/invalid-sig5.pem"
+rc=$?
+
+# We're done.
+if test "${rc}" = "0"; then
+	echo "Verification of invalid signature (5) failed"
+	exit ${rc}
+fi
+
+#this was causing a double free; verify that we receive the expected error code
+${VALGRIND} "${CERTTOOL}" --verify-chain --infile "${srcdir}/data/cve-2019-3829.pem"
+rc=$?
+
+# We're done.
+if test "${rc}" != "1"; then
+	echo "Verification of invalid signature (6) failed"
+	exit ${rc}
+fi
+
 exit 0
diff -NurBbp gnutls28-3.6.6/tests/cert-tests/Makefile.am gnutls28-3.6.7/tests/cert-tests/Makefile.am
--- gnutls28-3.6.6/tests/cert-tests/Makefile.am	2018-12-20 17:39:32.000000000 +0100
+++ gnutls28-3.6.7/tests/cert-tests/Makefile.am	2019-04-04 19:26:47.832143621 +0200
@@ -35,8 +35,8 @@ EXTRA_DIST = data/ca-no-pathlen.pem data
 	templates/template-generalized.tmpl data/privkey1.pem data/privkey2.pem data/privkey3.pem \
 	data/name-constraints-ip.pem data/cert-invalid-utf8.der data/very-long-dn.pem \
 	data/provable3072.pem data/provable2048.pem data/provable-dsa2048.pem \
-	data/provable-dsa2048-fips.pem templates/template-crq.tmpl \
-	templates/template-unique.tmpl data/template-unique.pem \
+	data/provable-dsa2048-fips.pem templates/template-crq.tmpl data/invalid-sig5.pem \
+	templates/template-unique.tmpl data/template-unique.pem data/invalid-sig4.pem \
 	templates/template-othername.tmpl data/template-othername.pem \
 	templates/template-othername-xmpp.tmpl data/template-othername-xmpp.pem \
 	templates/template-krb5name.tmpl data/crl-demo1.pem data/crl-demo2.pem data/crl-demo3.pem \
@@ -65,7 +65,7 @@ EXTRA_DIST = data/ca-no-pathlen.pem data
 	data/openssl-keyid.p7b data/openssl-keyid.p7b.out data/openssl.p12 \
 	data/x509-v1-with-sid.pem data/x509-v1-with-iid.pem data/x509-v3-with-fractional-time.pem \
 	templates/template-long-dns.tmpl templates/template-long-serial.tmpl \
-	data/key-rsa-pss-raw.pem data/key-rsa-pss.pem \
+	data/key-rsa-pss-raw.pem data/key-rsa-pss.pem data/cve-2019-3829.pem \
 	data/long-dns.pem data/template-long-dns-crq.pem data/chain-with-critical-on-root.pem \
 	data/chain-with-critical-on-intermediate.pem data/chain-with-critical-on-endcert.pem \
 	templates/crit-extensions.tmpl data/crit-extensions.pem data/x509-with-zero-version.pem \
diff -NurBbp gnutls28-3.6.6/tests/cert_verify_inv_utf8.c gnutls28-3.6.7/tests/cert_verify_inv_utf8.c
--- gnutls28-3.6.6/tests/cert_verify_inv_utf8.c	2017-12-14 11:00:19.000000000 +0100
+++ gnutls28-3.6.7/tests/cert_verify_inv_utf8.c	2019-02-04 19:07:18.000000000 +0100
@@ -137,7 +137,7 @@ static void auto_parse(void)
 	test_cli_serv_expect(x509_cred, clicred, "NORMAL", "NORMAL", "localhost", 0, 0);
 	test_cli_serv_vf(x509_cred, clicred, "NORMAL", "www.νίκοσ.com");
 	test_cli_serv_vf(x509_cred, clicred, "NORMAL", "www.νίκος.com");
-	test_cli_serv_expect(x509_cred, clicred, "NORMAL", "NORMAL", "raw:www.νίκος.com", GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER, GNUTLS_E_AGAIN);
+	test_cli_serv_expect(x509_cred, clicred, "NORMAL", "NORMAL", "raw:www.νίκος.com", GNUTLS_E_RECEIVED_DISALLOWED_NAME, GNUTLS_E_AGAIN);
 
 	gnutls_certificate_free_credentials(x509_cred);
 	gnutls_certificate_free_credentials(clicred);
diff -NurBbp gnutls28-3.6.6/tests/cipher-neg-common.c gnutls28-3.6.7/tests/cipher-neg-common.c
--- gnutls28-3.6.6/tests/cipher-neg-common.c	2018-11-28 19:56:17.000000000 +0100
+++ gnutls28-3.6.7/tests/cipher-neg-common.c	2019-04-04 19:26:47.884142070 +0200
@@ -54,8 +54,8 @@ static void try(test_case_st *test)
 	gnutls_certificate_set_known_dh_params(s_cert_cred, GNUTLS_SEC_PARAM_MEDIUM);
 
 	assert(gnutls_certificate_set_x509_key_mem(s_cert_cred, &server_ca3_localhost_rsa_decrypt_cert, &server_ca3_key, GNUTLS_X509_FMT_PEM) >= 0);
-	assert(gnutls_certificate_set_x509_key_mem(s_cert_cred, &server_ca3_localhost_ecc_cert, &server_ca3_ecc_key, GNUTLS_X509_FMT_PEM) >= 0);
 	assert(gnutls_certificate_set_x509_key_mem(s_cert_cred, &server_ca3_localhost_rsa_sign_cert, &server_ca3_key, GNUTLS_X509_FMT_PEM) >= 0);
+	assert(gnutls_certificate_set_x509_key_mem(s_cert_cred, &server_ca3_localhost_ecc_cert, &server_ca3_ecc_key, GNUTLS_X509_FMT_PEM) >= 0);
 
 	gnutls_credentials_set(client, GNUTLS_CRD_CERTIFICATE, c_cert_cred);
 
diff -NurBbp gnutls28-3.6.6/tests/common-cert-key-exchange.c gnutls28-3.6.7/tests/common-cert-key-exchange.c
--- gnutls28-3.6.6/tests/common-cert-key-exchange.c	2018-12-15 22:10:46.000000000 +0100
+++ gnutls28-3.6.7/tests/common-cert-key-exchange.c	2019-02-09 10:23:43.000000000 +0100
@@ -74,7 +74,7 @@ void try_with_key_fail(const char *name,
 
 	reset_buffers();
 	/* Init server */
-	gnutls_certificate_allocate_credentials(&serverx509cred);
+	assert(gnutls_certificate_allocate_credentials(&serverx509cred)>=0);
 
 	ret = gnutls_certificate_set_x509_key_mem(serverx509cred,
 						  serv_cert, serv_key,
@@ -82,16 +82,15 @@ void try_with_key_fail(const char *name,
 	if (ret < 0)
 		fail("Could not set key/cert: %s\n", gnutls_strerror(ret));
 
-	gnutls_init(&server, GNUTLS_SERVER);
-	gnutls_credentials_set(server, GNUTLS_CRD_CERTIFICATE,
-			       serverx509cred);
-
-
+	assert(gnutls_init(&server, GNUTLS_SERVER)>=0);
 	if (server_priority)
 		assert(gnutls_priority_set_direct(server, server_priority, NULL) >= 0);
 	else
 		assert(gnutls_priority_set_direct(server, client_prio, NULL) >= 0);
 
+	assert(gnutls_credentials_set(server, GNUTLS_CRD_CERTIFICATE,
+				      serverx509cred)>=0);
+
 	gnutls_transport_set_push_function(server, server_push);
 	gnutls_transport_set_pull_function(server, server_pull);
 	gnutls_transport_set_ptr(server, server);
@@ -112,11 +111,98 @@ void try_with_key_fail(const char *name,
 	if (ret < 0)
 		exit(1);
 
+	gnutls_transport_set_push_function(client, client_push);
+	gnutls_transport_set_pull_function(client, client_pull);
+	gnutls_transport_set_ptr(client, client);
+
+	ret = gnutls_priority_set_direct(client, client_prio, &err);
+	if (ret < 0) {
+		if (ret == GNUTLS_E_INVALID_REQUEST)
+			fprintf(stderr, "Error in %s\n", err);
+		exit(1);
+	}
+
 	ret = gnutls_credentials_set(client, GNUTLS_CRD_CERTIFICATE,
 				clientx509cred);
 	if (ret < 0)
 		exit(1);
 
+	success("negotiating %s\n", name);
+	HANDSHAKE_EXPECT(client, server, client_err, server_err);
+
+	gnutls_deinit(client);
+	gnutls_deinit(server);
+
+	gnutls_certificate_free_credentials(serverx509cred);
+	gnutls_certificate_free_credentials(clientx509cred);
+}
+
+void try_with_rawpk_key_fail(const char *name, const char *client_prio,
+			     int server_err, int client_err,
+			     const gnutls_datum_t *serv_cert,
+			     const gnutls_datum_t *serv_key,
+			     unsigned server_ku,
+			     const gnutls_datum_t *cli_cert,
+			     const gnutls_datum_t *cli_key,
+			     unsigned client_ku)
+{
+	int ret;
+	/* Server stuff. */
+	gnutls_certificate_credentials_t server_cred;
+	gnutls_session_t server;
+	int sret = GNUTLS_E_AGAIN;
+	/* Client stuff. */
+	gnutls_certificate_credentials_t client_cred;
+	gnutls_session_t client;
+	int cret = GNUTLS_E_AGAIN;
+	const char *err;
+
+	/* General init. */
+	gnutls_global_set_log_function(tls_log_func);
+	if (debug)
+		gnutls_global_set_log_level(6);
+
+	reset_buffers();
+	/* Init server */
+	gnutls_certificate_allocate_credentials(&server_cred);
+
+	ret = gnutls_certificate_set_rawpk_key_mem(server_cred,
+						   serv_cert, serv_key, GNUTLS_X509_FMT_PEM, NULL, server_ku,
+						   NULL, 0, 0);
+	if (ret < 0)
+		fail("Could not set key/cert: %s\n", gnutls_strerror(ret));
+
+	assert(gnutls_init(&server, GNUTLS_SERVER | GNUTLS_ENABLE_RAWPK) >= 0);
+	if (server_priority)
+		assert(gnutls_priority_set_direct(server, server_priority, NULL) >= 0);
+	else
+		assert(gnutls_priority_set_direct(server, client_prio, NULL) >= 0);
+
+	gnutls_credentials_set(server, GNUTLS_CRD_CERTIFICATE,
+			       server_cred);
+
+	gnutls_transport_set_push_function(server, server_push);
+	gnutls_transport_set_pull_function(server, server_pull);
+	gnutls_transport_set_ptr(server, server);
+
+	/* Init client */
+	ret = gnutls_certificate_allocate_credentials(&client_cred);
+	if (ret < 0)
+		exit(1);
+
+	if (cli_cert) {
+		ret = gnutls_certificate_set_rawpk_key_mem(client_cred,
+							   cli_cert, cli_key, GNUTLS_X509_FMT_PEM, NULL, client_ku,
+							   NULL, 0, 0);
+		if (ret < 0)
+			fail("Could not set key/cert: %s\n", gnutls_strerror(ret));
+		gnutls_certificate_server_set_request(server, GNUTLS_CERT_REQUIRE);
+	}
+
+	ret = gnutls_init(&client, GNUTLS_CLIENT|GNUTLS_ENABLE_RAWPK);
+	if (ret < 0)
+		exit(1);
+
 	gnutls_transport_set_push_function(client, client_push);
 	gnutls_transport_set_pull_function(client, client_pull);
 	gnutls_transport_set_ptr(client, client);
@@ -127,14 +213,20 @@ void try_with_key_fail(const char *name,
 			fprintf(stderr, "Error in %s\n", err);
 		exit(1);
 	}
+
+	ret = gnutls_credentials_set(client, GNUTLS_CRD_CERTIFICATE,
+				client_cred);
+	if (ret < 0)
+		exit(1);
+
 	success("negotiating %s\n", name);
 	HANDSHAKE_EXPECT(client, server, client_err, server_err);
 
 	gnutls_deinit(client);
 	gnutls_deinit(server);
 
-	gnutls_certificate_free_credentials(serverx509cred);
-	gnutls_certificate_free_credentials(clientx509cred);
+	gnutls_certificate_free_credentials(server_cred);
+	gnutls_certificate_free_credentials(client_cred);
 }
 
 void try_with_key_ks(const char *name, const char *client_prio, gnutls_kx_algorithm_t client_kx,
@@ -173,8 +265,8 @@ void try_with_key_ks(const char *name, c
 
 	reset_buffers();
 	/* Init server */
-	gnutls_anon_allocate_server_credentials(&s_anoncred);
-	gnutls_certificate_allocate_credentials(&server_cred);
+	assert(gnutls_anon_allocate_server_credentials(&s_anoncred)>=0);
+	assert(gnutls_certificate_allocate_credentials(&server_cred)>=0);
 
 	// Set server crt creds based on ctype
 	switch (server_ctype) {
@@ -201,11 +293,10 @@ void try_with_key_ks(const char *name, c
 	gnutls_certificate_set_dh_params(server_cred, dh_params);
 	gnutls_anon_set_server_dh_params(s_anoncred, dh_params);
 
-	gnutls_init(&server, GNUTLS_SERVER | GNUTLS_ENABLE_RAWPK);
-	gnutls_credentials_set(server, GNUTLS_CRD_CERTIFICATE,
-				server_cred);
-	gnutls_credentials_set(server, GNUTLS_CRD_ANON, s_anoncred);
-
+	assert(gnutls_init(&server, GNUTLS_SERVER | GNUTLS_ENABLE_RAWPK)>=0);
+	assert(gnutls_credentials_set(server, GNUTLS_CRD_CERTIFICATE,
+				      server_cred)>=0);
+	assert(gnutls_credentials_set(server, GNUTLS_CRD_ANON, s_anoncred)>=0);
 
 	if (server_priority)
 		assert(gnutls_priority_set_direct(server, server_priority, NULL) >= 0);
@@ -254,8 +345,8 @@ void try_with_key_ks(const char *name, c
 		exit(1);
 
 
-	gnutls_anon_allocate_client_credentials(&c_anoncred);
-	gnutls_credentials_set(client, GNUTLS_CRD_ANON, c_anoncred);
+	assert(gnutls_anon_allocate_client_credentials(&c_anoncred)>=0);
+	assert(gnutls_credentials_set(client, GNUTLS_CRD_ANON, c_anoncred)>=0);
 	ret = gnutls_credentials_set(client, GNUTLS_CRD_CERTIFICATE,
 				client_cred);
 	if (ret < 0)
@@ -397,14 +488,14 @@ void dtls_try_with_key_mtu(const char *n
 	gnutls_certificate_set_dh_params(serverx509cred, dh_params);
 	gnutls_anon_set_server_dh_params(s_anoncred, dh_params);
 
-	gnutls_init(&server, GNUTLS_SERVER|GNUTLS_DATAGRAM|GNUTLS_NONBLOCK);
-	gnutls_credentials_set(server, GNUTLS_CRD_CERTIFICATE,
-				serverx509cred);
-	gnutls_credentials_set(server, GNUTLS_CRD_ANON, s_anoncred);
+	assert(gnutls_init(&server, GNUTLS_SERVER|GNUTLS_DATAGRAM|GNUTLS_NONBLOCK)>=0);
+	assert(gnutls_credentials_set(server, GNUTLS_CRD_CERTIFICATE,
+				      serverx509cred)>=0);
+	assert(gnutls_credentials_set(server, GNUTLS_CRD_ANON, s_anoncred)>=0);
 
-	gnutls_priority_set_direct(server,
+	assert(gnutls_priority_set_direct(server,
 				   "NORMAL:+ANON-ECDH:+ANON-DH:+ECDHE-RSA:+DHE-RSA:+RSA:+ECDHE-ECDSA:+CURVE-X25519",
-				   NULL);
+					   NULL)>=0);
 	gnutls_transport_set_push_function(server, server_push);
 	gnutls_transport_set_pull_function(server, server_pull);
 	gnutls_transport_set_pull_timeout_function(server, server_pull_timeout_func);
@@ -440,8 +531,8 @@ void dtls_try_with_key_mtu(const char *n
 	if (ret < 0)
 		exit(1);
 
-	gnutls_anon_allocate_client_credentials(&c_anoncred);
-	gnutls_credentials_set(client, GNUTLS_CRD_ANON, c_anoncred);
+	assert(gnutls_anon_allocate_client_credentials(&c_anoncred)>=0);
+	assert(gnutls_credentials_set(client, GNUTLS_CRD_ANON, c_anoncred)>=0);
 	ret = gnutls_credentials_set(client, GNUTLS_CRD_CERTIFICATE,
 				clientx509cred);
 	if (ret < 0)
diff -NurBbp gnutls28-3.6.6/tests/common-cert-key-exchange.h gnutls28-3.6.7/tests/common-cert-key-exchange.h
--- gnutls28-3.6.6/tests/common-cert-key-exchange.h	2018-12-15 22:10:46.000000000 +0100
+++ gnutls28-3.6.7/tests/common-cert-key-exchange.h	2019-02-09 10:23:43.000000000 +0100
@@ -51,6 +51,14 @@ extern const char *server_priority;
 	try_with_key(name, client_prio, client_kx, server_sign_algo, client_sign_algo, \
 		&rawpk_public_key1, &rawpk_private_key1, &rawpk_public_key2, &rawpk_private_key2, client_cert, GNUTLS_CRT_RAWPK, GNUTLS_CRT_RAWPK)
 
+void try_with_rawpk_key_fail(const char *name, const char *client_prio,
+			     int server_err, int client_err,
+			     const gnutls_datum_t *serv_cert,
+			     const gnutls_datum_t *serv_key,
+			     unsigned server_ku,
+			     const gnutls_datum_t *cli_cert,
+			     const gnutls_datum_t *cli_key,
+			     unsigned client_ku);
 
 void try_with_key_ks(const char *name, const char *client_prio, gnutls_kx_algorithm_t client_kx,
 		gnutls_sign_algorithm_t server_sign_algo,
diff -NurBbp gnutls28-3.6.6/tests/conv-utf8.c gnutls28-3.6.7/tests/conv-utf8.c
--- gnutls28-3.6.6/tests/conv-utf8.c	2017-03-06 21:29:43.000000000 +0100
+++ gnutls28-3.6.7/tests/conv-utf8.c	2019-02-23 18:48:28.000000000 +0100
@@ -35,7 +35,7 @@
 #include <cmocka.h>
 
 int _gnutls_utf8_to_ucs2(const void *data, size_t size,
-			 gnutls_datum_t * output);
+			 gnutls_datum_t * output, unsigned be);
 
 int _gnutls_ucs2_to_utf8(const void *data, size_t size,
 			 gnutls_datum_t * output, unsigned be);
@@ -60,7 +60,7 @@ static void PRINT(const char *str, unsig
 static void fname(void **glob_state) \
 { \
 	gnutls_datum_t out; \
-	int ret = _gnutls_utf8_to_ucs2(utf8, strlen(utf8), &out); \
+	int ret = _gnutls_utf8_to_ucs2(utf8, strlen(utf8), &out, 1); \
 	assert_int_equal(ret, 0); \
 	if (out.size != sizeof(utf16)-1 || memcmp(utf16, out.data, out.size) != 0) { PRINT("got:      ", out.data, out.size); \
 	PRINT("expected: ", (unsigned char*)utf16, sizeof(utf16)-1); } \
@@ -86,7 +86,7 @@ static void fname(void **glob_state) \
 static void fname(void **glob_state) \
 { \
 	gnutls_datum_t out; \
-	int ret = _gnutls_utf8_to_ucs2(utf8, utf8_size, &out); \
+	int ret = _gnutls_utf8_to_ucs2(utf8, utf8_size, &out, 1); \
 	assert_int_not_equal(ret, 0); \
 }
 
diff -NurBbp gnutls28-3.6.6/tests/dtls-pthread.c gnutls28-3.6.7/tests/dtls-pthread.c
--- gnutls28-3.6.6/tests/dtls-pthread.c	1970-01-01 01:00:00.000000000 +0100
+++ gnutls28-3.6.7/tests/dtls-pthread.c	2019-03-08 20:15:32.000000000 +0100
@@ -0,0 +1,369 @@
+/*
+ * Copyright (C) 2015 Red Hat, Inc.
+ *
+ * Author: Nikos Mavrogiannopoulos
+ *
+ * This file is part of GnuTLS.
+ *
+ * GnuTLS is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuTLS is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GnuTLS; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <errno.h>
+#include <gnutls/gnutls.h>
+#include <gnutls/dtls.h>
+#include <signal.h>
+#include <unistd.h>
+#ifndef _WIN32
+# include <netinet/in.h>
+# include <sys/types.h>
+# include <sys/socket.h>
+# include <sys/wait.h>
+# include <pthread.h>
+#endif
+#include <assert.h>
+#include "utils.h"
+#include "cert-common.h"
+
+#ifdef _WIN32
+
+void doit(void)
+{
+	exit(77);
+}
+
+#else
+
+/* These are global */
+pid_t child;
+
+/* Tests whether we can send and receive from different threads
+ * using DTLS, either as server or client. DTLS is a superset of
+ * TLS, so correct behavior under fork means TLS would operate too.
+ */
+
+const char *side = "";
+
+static void tls_log_func(int level, const char *str)
+{
+	fprintf(stderr, "%s|<%d>| %s", side, level, str);
+}
+
+#define MSG "hello1111"
+#define MSG2 "xxxxxxxxxxxx"
+
+#define NO_MSGS 128
+
+static void *recv_thread(void *arg)
+{
+	gnutls_session_t session = arg;
+	int ret;
+	unsigned i;
+	char buf[64];
+
+	if (debug)
+		success("client: TLS version is: %s\n",
+			gnutls_protocol_get_name
+			(gnutls_protocol_get_version(session)));
+
+	for (i=0;i<NO_MSGS;i++) {
+		/* the peer should reflect our messages */
+		do {
+			ret = gnutls_record_recv(session, buf, sizeof(buf));
+		} while(ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
+		if (ret < 0)
+			fail("client: recv failed: %s\n", gnutls_strerror(ret));
+		if (ret != sizeof(MSG)-1 || memcmp(buf, MSG, sizeof(MSG)-1) != 0) {
+			fail("client: recv failed; not the expected values (got: %d, exp: %d)\n", ret, (int)sizeof(MSG)-1);
+		}
+
+		if (debug)
+			success("%d: client received: %.*s\n", i, ret, buf);
+	}
+
+	/* final MSG is MSG2 */
+	do {
+		ret = gnutls_record_recv(session, buf, sizeof(buf));
+	} while(ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
+	if (ret < 0)
+		fail("client: recv2 failed: %s\n", gnutls_strerror(ret));
+
+	if (ret != sizeof(MSG2)-1 || memcmp(buf, MSG2, sizeof(MSG2)-1) != 0) {
+		fail("client: recv2 failed; not the expected values\n");
+	}
+
+	if (debug) {
+		success("client received: %.*s\n", ret, buf);
+		success("closing recv thread\n");
+	}
+
+	pthread_exit(0);
+}
+
+static
+void do_thread_stuff(gnutls_session_t session)
+{
+	int ret;
+	unsigned i;
+	pthread_t id;
+	void *rval;
+
+	sec_sleep(1);
+	/* separate sending from receiving */
+	ret = pthread_create(&id, NULL, recv_thread, session);
+	if (ret != 0) {
+		fail("error in pthread_create\n");
+	}
+
+	for (i=0;i<NO_MSGS;i++) {
+		do {
+			ret = gnutls_record_send(session, MSG, sizeof(MSG)-1);
+		} while(ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
+		if (ret != sizeof(MSG)-1) {
+			fail("client: send failed: %s\n", gnutls_strerror(ret));
+		}
+	}
+
+	do {
+		ret = gnutls_record_send(session, MSG2, sizeof(MSG2)-1);
+	} while(ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
+	if (ret != sizeof(MSG2)-1) {
+		fail("client: send2 failed: %s\n", gnutls_strerror(ret));
+	}
+
+	if (debug)
+		success("closing sending thread\n");
+	assert(pthread_join(id, &rval)==0);
+	assert(rval == 0);
+
+	do {
+		ret = gnutls_bye(session, GNUTLS_SHUT_RDWR);
+	} while(ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
+}
+
+static void do_reflect_stuff(gnutls_session_t session)
+{
+	char buf[64];
+	unsigned buf_size;
+	int ret;
+
+	do {
+		do {
+			ret = gnutls_record_recv(session, buf, sizeof(buf));
+		} while(ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
+		if (ret < 0) {
+			fail("server: recv failed: %s\n", gnutls_strerror(ret));
+		}
+
+		if (ret == 0) {
+			break;
+		}
+
+		buf_size = ret;
+		if (debug) {
+			success("server received: %.*s\n", buf_size, buf);
+		}
+
+		do {
+			ret = gnutls_record_send(session, buf, buf_size);
+		} while(ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
+		if (ret < 0) {
+			fail("server: send failed: %s\n", gnutls_strerror(ret));
+		}
+		if (debug)
+			success("reflected %d\n", ret);
+	} while(1);
+
+	do {
+		gnutls_bye(session, GNUTLS_SHUT_WR);
+	} while(ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
+}
+
+static void client(int fd, const char *prio, unsigned do_thread, unsigned false_start)
+{
+	int ret;
+	gnutls_certificate_credentials_t x509_cred;
+	gnutls_session_t session;
+	unsigned flags = GNUTLS_CLIENT;
+
+	global_init();
+
+	if (debug) {
+		side = "client";
+		gnutls_global_set_log_function(tls_log_func);
+		gnutls_global_set_log_level(4711);
+	}
+
+	assert(gnutls_certificate_allocate_credentials(&x509_cred)>=0);
+
+	if (false_start)
+		flags |= GNUTLS_ENABLE_FALSE_START;
+
+	assert(gnutls_init(&session, flags|GNUTLS_DATAGRAM) >= 0);
+	gnutls_dtls_set_mtu(session, 1500);
+	gnutls_dtls_set_timeouts(session, 6 * 1000, 60 * 1000);
+
+	assert(gnutls_priority_set_direct(session, prio, NULL)>=0);
+
+	assert(gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, x509_cred)>=0);
+
+	gnutls_transport_set_int(session, fd);
+
+	do {
+		ret = gnutls_handshake(session);
+	}
+	while (ret < 0 && gnutls_error_is_fatal(ret) == 0);
+
+	if (ret < 0) {
+		fail("client: Handshake failed: %s\n", gnutls_strerror(ret));
+	} else {
+		if (debug)
+			success("client: Handshake was completed\n");
+	}
+
+	if (do_thread)
+		do_thread_stuff(session);
+	else
+		do_reflect_stuff(session);
+
+	close(fd);
+
+	gnutls_deinit(session);
+
+	gnutls_certificate_free_credentials(x509_cred);
+
+	gnutls_global_deinit();
+}
+
+static void server(int fd, const char *prio, unsigned do_thread)
+{
+	int ret;
+	gnutls_certificate_credentials_t x509_cred;
+	gnutls_session_t session;
+
+	global_init();
+
+#if 0
+	if (debug) {
+		side = "server";
+		gnutls_global_set_log_function(tls_log_func);
+		gnutls_global_set_log_level(4711);
+	}
+#endif
+
+	assert(gnutls_certificate_allocate_credentials(&x509_cred)>=0);
+	assert(gnutls_certificate_set_x509_key_mem(x509_cred, &server_cert,
+					    &server_key,
+					    GNUTLS_X509_FMT_PEM)>=0);
+
+	assert(gnutls_init(&session, GNUTLS_SERVER | GNUTLS_DATAGRAM)>=0);
+	gnutls_dtls_set_timeouts(session, 5 * 1000, 60 * 1000);
+	gnutls_dtls_set_mtu(session, 400);
+
+	assert(gnutls_priority_set_direct(session, prio, NULL)>=0);
+
+	gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, x509_cred);
+
+	gnutls_transport_set_int(session, fd);
+
+	do {
+		ret = gnutls_handshake(session);
+	} while (ret < 0 && gnutls_error_is_fatal(ret) == 0);
+	if (ret < 0) {
+		close(fd);
+		gnutls_deinit(session);
+		fail("server: Handshake has failed (%s)\n\n",
+		     gnutls_strerror(ret));
+	}
+	if (debug)
+		success("server: Handshake was completed\n");
+
+	if (debug)
+		success("server: TLS version is: %s\n",
+			gnutls_protocol_get_name
+			(gnutls_protocol_get_version(session)));
+
+	if (do_thread)
+		do_thread_stuff(session);
+	else
+		do_reflect_stuff(session);
+
+
+	close(fd);
+	gnutls_deinit(session);
+
+	gnutls_certificate_free_credentials(x509_cred);
+
+	gnutls_global_deinit();
+
+	if (debug)
+		success("server: finished\n");
+}
+
+static
+void run(const char *str, const char *prio, unsigned do_thread, unsigned false_start)
+{
+	int fd[2];
+	int ret;
+
+	if (str)
+		success("running %s\n", str);
+
+	ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fd);
+	if (ret < 0) {
+		perror("socketpair");
+		exit(1);
+	}
+
+	child = fork();
+	if (child < 0) {
+		perror("fork");
+		fail("fork");
+		exit(1);
+	}
+
+	if (child) {
+		int status;
+		/* parent */
+
+		close(fd[1]);
+		client(fd[0], prio, do_thread, false_start);
+		wait(&status);
+		check_wait_status(status);
+	} else {
+		close(fd[0]);
+		server(fd[1], prio, 1-do_thread);
+		exit(0);
+	}
+}
+
+void doit(void)
+{
+	signal(SIGPIPE, SIG_IGN);
+	run("default, threaded client", "NORMAL", 0, 0);
+	run("default, threaded server", "NORMAL", 1, 0);
+	run("dtls1.2, threaded client", "NORMAL:-VERS-ALL:+VERS-DTLS1.2", 0, 0);
+	run("dtls1.2, threaded server", "NORMAL:-VERS-ALL:+VERS-DTLS1.2", 1, 0);
+	run("dtls1.2 false start, threaded client", "NORMAL:-VERS-ALL:+VERS-DTLS1.2", 0, 1);
+	run("dtls1.2 false start, threaded server", "NORMAL:-VERS-ALL:+VERS-DTLS1.2", 1, 1);
+}
+#endif				/* _WIN32 */
diff -NurBbp gnutls28-3.6.6/tests/empty_retrieve_function.c gnutls28-3.6.7/tests/empty_retrieve_function.c
--- gnutls28-3.6.6/tests/empty_retrieve_function.c	2018-07-24 22:06:03.000000000 +0200
+++ gnutls28-3.6.7/tests/empty_retrieve_function.c	2019-04-04 19:26:47.968139565 +0200
@@ -110,17 +110,17 @@ void doit(void)
 
 	gnutls_certificate_allocate_credentials(&clicred);
 	gnutls_certificate_set_retrieve_function(clicred, cert_cb1);
-	_test_cli_serv(x509_cred, clicred, "NORMAL", "NORMAL", "localhost", NULL, NULL, NULL, 0, 1, GNUTLS_E_NO_CERTIFICATE_FOUND, -1);
+	_test_cli_serv(x509_cred, clicred, "NORMAL", "NORMAL", "localhost", NULL, NULL, NULL, 0, 1, GNUTLS_E_CERTIFICATE_REQUIRED, -1);
 	gnutls_certificate_free_credentials(clicred);
 
 	gnutls_certificate_allocate_credentials(&clicred);
 	gnutls_certificate_set_retrieve_function2(clicred, cert_cb2);
-	_test_cli_serv(x509_cred, clicred, "NORMAL", "NORMAL", "localhost", NULL, NULL, NULL, 0, 1, GNUTLS_E_NO_CERTIFICATE_FOUND, -1);
+	_test_cli_serv(x509_cred, clicred, "NORMAL", "NORMAL", "localhost", NULL, NULL, NULL, 0, 1, GNUTLS_E_CERTIFICATE_REQUIRED, -1);
 	gnutls_certificate_free_credentials(clicred);
 
 	gnutls_certificate_allocate_credentials(&clicred);
 	gnutls_certificate_set_retrieve_function3(clicred, cert_cb3);
-	_test_cli_serv(x509_cred, clicred, "NORMAL", "NORMAL", "localhost", NULL, NULL, NULL, 0, 1, GNUTLS_E_NO_CERTIFICATE_FOUND, -1);
+	_test_cli_serv(x509_cred, clicred, "NORMAL", "NORMAL", "localhost", NULL, NULL, NULL, 0, 1, GNUTLS_E_CERTIFICATE_REQUIRED, -1);
 	gnutls_certificate_free_credentials(clicred);
 
 	gnutls_certificate_free_credentials(x509_cred);
diff -NurBbp gnutls28-3.6.6/tests/gnutls-cli-resume.sh gnutls28-3.6.7/tests/gnutls-cli-resume.sh
--- gnutls28-3.6.6/tests/gnutls-cli-resume.sh	1970-01-01 01:00:00.000000000 +0100
+++ gnutls28-3.6.7/tests/gnutls-cli-resume.sh	2019-03-24 08:27:25.000000000 +0100
@@ -0,0 +1,104 @@
+#!/bin/sh
+
+# Copyright (C) 2019 Red Hat, Inc.
+#
+# Author: Nikos Mavrogiannopoulos
+#
+# This file is part of GnuTLS.
+#
+# GnuTLS is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 3 of the License, or (at
+# your option) any later version.
+#
+# GnuTLS is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>
+#
+
+srcdir="${srcdir:-.}"
+SERV="${SERV:-../src/gnutls-serv${EXEEXT}}"
+CLI="${CLI:-../src/gnutls-cli${EXEEXT}}"
+unset RETCODE
+
+if ! test -x "${SERV}"; then
+	exit 77
+fi
+
+if ! test -x "${CLI}"; then
+	exit 77
+fi
+
+if test "${WINDIR}" != ""; then
+	exit 77
+fi
+
+SERV="${SERV} -q"
+
+. "${srcdir}/scripts/common.sh"
+
+KEY1=${srcdir}/../doc/credentials/x509/key-rsa.pem
+CERT1=${srcdir}/../doc/credentials/x509/cert-rsa.pem
+
+eval "${GETPORT}"
+launch_server $$ --echo --x509keyfile ${KEY1} --x509certfile ${CERT1}
+PID=$!
+wait_server ${PID}
+
+run_server_test() {
+	local priority=$1
+	local id=$2
+	local TMPFILE=resume.$$-$i.tmp
+
+	"${CLI}" -p "${PORT}" 127.0.0.1 --logfile=${TMPFILE} --priority="${priority}" --resume --insecure </dev/null >/dev/null || \
+		exit 1
+	grep -H "* This is a resumed session" ${TMPFILE} ||
+		exit 1
+
+	rm -f ${TMPFILE}
+
+	exit 0
+}
+
+echo "Checking whether session resumption works reliably under TLS1.3"
+PRIORITY="NORMAL:-VERS-ALL:+VERS-TLS1.3"
+WAITPID=""
+
+i=0
+while [ $i -lt 10 ]
+do
+	run_server_test "${PRIORITY}" $i &
+	WAITPID="$WAITPID $!"
+	i=`expr $i + 1`
+done
+
+for i in "$WAITPID";do
+	wait $i
+	test $? != 0 && exit 1
+done
+
+echo "Checking whether session resumption works reliably under TLS1.2"
+PRIORITY="NORMAL:-VERS-ALL:+VERS-TLS1.2"
+WAITPID=""
+
+i=0
+while [ $i -lt 10 ]
+do
+	run_server_test "${PRIORITY}" $i &
+	WAITPID="$WAITPID $!"
+	i=`expr $i + 1`
+done
+
+for i in "$WAITPID";do
+	wait $i
+	test $? != 0 && exit 1
+done
+
+kill ${PID}
+wait
+
+exit 0
diff -NurBbp gnutls28-3.6.6/tests/gnutls_session_set_id.c gnutls28-3.6.7/tests/gnutls_session_set_id.c
--- gnutls28-3.6.6/tests/gnutls_session_set_id.c	2018-11-18 19:53:49.000000000 +0100
+++ gnutls28-3.6.7/tests/gnutls_session_set_id.c	2019-04-04 19:26:47.968139565 +0200
@@ -200,7 +200,6 @@ static void start(const char *test, unsi
 	gnutls_certificate_free_credentials(clientx509cred);
 
 	gnutls_free(dbdata.data);
-	dbdata.data = NULL;
 	dbdata.size = 0;
 }
 
diff -NurBbp gnutls28-3.6.6/tests/ip-utils.c gnutls28-3.6.7/tests/ip-utils.c
--- gnutls28-3.6.6/tests/ip-utils.c	2018-02-16 08:57:41.000000000 +0100
+++ gnutls28-3.6.7/tests/ip-utils.c	2019-02-12 05:51:35.000000000 +0100
@@ -28,13 +28,13 @@
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
+#include <arpa/inet.h>
 #include <gnutls/gnutls.h>
 #include <gnutls/x509.h>
 
 #ifndef _WIN32
 # include <cmocka.h>
 # include <sys/socket.h>
-# include <arpa/inet.h>
 
 #define BUILD_IN_TESTS
 #include "../lib/x509/ip-in-cidr.h"
diff -NurBbp gnutls28-3.6.6/tests/logfile-option.sh gnutls28-3.6.7/tests/logfile-option.sh
--- gnutls28-3.6.6/tests/logfile-option.sh	1970-01-01 01:00:00.000000000 +0100
+++ gnutls28-3.6.7/tests/logfile-option.sh	2019-03-24 08:27:43.000000000 +0100
@@ -0,0 +1,169 @@
+#!/bin/sh
+
+# Copyright (C) 2010-2016 Free Software Foundation, Inc.
+#
+# Author: Nikos Mavrogiannopoulos
+#
+# This file is part of GnuTLS.
+#
+# GnuTLS is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 3 of the License, or (at
+# your option) any later version.
+#
+# GnuTLS is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GnuTLS; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+srcdir="${srcdir:-.}"
+SERV="${SERV:-../src/gnutls-serv${EXEEXT}}"
+CLI="${CLI:-../src/gnutls-cli${EXEEXT}}"
+unset RETCODE
+
+if ! test -x "${SERV}"; then
+	exit 77
+fi
+
+if ! test -x "${CLI}"; then
+	exit 77
+fi
+
+if test "${WINDIR}" != ""; then
+	exit 77
+fi
+
+if ! test -z "${VALGRIND}"; then
+	VALGRIND="${LIBTOOL:-libtool} --mode=execute ${VALGRIND} --error-exitcode=15"
+fi
+
+
+SERV="${SERV} -q"
+
+. "${srcdir}/scripts/common.sh"
+
+echo "Checking whether logfile option works."
+
+KEY1=${srcdir}/../doc/credentials/x509/example.com-key.pem
+CERT1=${srcdir}/../doc/credentials/x509/example.com-cert.pem
+CA1=${srcdir}/../doc/credentials/x509/ca.pem
+PSK=${srcdir}/psk.passwd
+
+TMPFILE1=save-data1.$$.tmp
+TMPFILE2=save-data2.$$.tmp
+
+OPTS="--sni-hostname example.com --verify-hostname example.com"
+
+eval "${GETPORT}"
+launch_server $$ --echo --priority NORMAL:+ECDHE-PSK:+DHE-PSK:+PSK --pskpasswd=${PSK}
+PID=$!
+wait_server ${PID}
+
+${VALGRIND} "${CLI}" -p "${PORT}" 127.0.0.1 --priority NORMAL:+ECDHE-PSK:+DHE-PSK:+PSK --pskusername=jas --pskkey=9e32cf7786321a828ef7668f09fb35db </dev/null >${TMPFILE2}
+
+kill ${PID}
+wait
+
+if test -f ${TMPFILE1};then
+	echo "Logfile should not be created!"
+	exit 1
+fi
+if ! test -s ${TMPFILE2};then
+	echo "Stdout should not be empty!"
+	exit 1
+fi
+if grep -q "Handshake was completed" ${TMPFILE2};then
+	echo "Find the expected output!"
+else
+	echo "Cannot find the expected output!"
+	exit 1
+fi
+
+rm -f ${TMPFILE1} ${TMPFILE2}
+
+eval "${GETPORT}"
+launch_server $$ --echo --priority NORMAL:+ECDHE-PSK:+DHE-PSK:+PSK --pskpasswd=${PSK}
+PID=$!
+wait_server ${PID}
+
+${VALGRIND} "${CLI}" -p "${PORT}" 127.0.0.1 --logfile ${TMPFILE1} --priority NORMAL:+ECDHE-PSK:+DHE-PSK:+PSK --pskusername=jas --pskkey=9e32cf7786321a828ef7668f09fb35db </dev/null >${TMPFILE2}
+
+kill ${PID}
+wait
+
+if ! test -f ${TMPFILE1};then
+	echo "Logfile shoule be created!"
+	exit 1
+fi
+if test -s ${TMPFILE2};then
+	echo "Stdout should be empty!"
+	exit 1
+fi
+
+if grep -q "Handshake was completed" ${TMPFILE1}; then
+	echo "Found the expected output!"
+else
+	echo "Cannot find the expected output!"
+	exit 1
+fi
+rm -f ${TMPFILE1} ${TMPFILE2}
+
+
+echo "x509 functionality test"
+eval "${GETPORT}"
+launch_server $$ --echo --sni-hostname-fatal --sni-hostname example.com --x509keyfile ${KEY1} --x509certfile ${CERT1}
+PID=$!
+wait_server ${PID}
+
+${VALGRIND} "${CLI}" -p "${PORT}" 127.0.0.1 ${OPTS} --priority "NORMAL:-VERS-ALL:+VERS-TLS1.2" --x509cafile ${CA1}  </dev/null >${TMPFILE2}
+kill ${PID}
+wait
+
+if test -f ${TMPFILE1};then
+        echo "Logfile should not be created!"
+        exit 1
+fi
+if ! test -s ${TMPFILE2};then
+        echo "Stdout should not be empty!"
+        exit 1
+fi
+if grep -q "Handshake was completed" ${TMPFILE2};then
+        echo "Find the expected output!"
+else
+        echo "Cannot find the expected output!"
+        exit 1
+fi
+
+rm -f ${TMPFILE1} ${TMPFILE2}
+
+eval "${GETPORT}"
+launch_server $$ --echo --sni-hostname-fatal --sni-hostname example.com --x509keyfile ${KEY1} --x509certfile ${CERT1}
+PID=$!
+wait_server ${PID}
+
+${VALGRIND} "${CLI}" -p "${PORT}" 127.0.0.1 ${OPTS} --priority "NORMAL:-VERS-ALL:+VERS-TLS1.2" --x509cafile ${CA1} --logfile ${TMPFILE1} </dev/null >${TMPFILE2}
+kill ${PID}
+wait
+
+if ! test -f ${TMPFILE1};then
+       echo "Logfile shoule be created!"
+       exit 1
+fi
+if test -s ${TMPFILE2};then
+       echo "Stdout should be empty!"
+       exit 1
+fi
+
+if grep -q "Handshake was completed" ${TMPFILE1}; then
+       echo "Found the expected output!"
+else
+       echo "Cannot find the expected output!"
+       exit 1
+fi
+rm -f ${TMPFILE1} ${TMPFILE2}
+
+exit 0
diff -NurBbp gnutls28-3.6.6/tests/Makefile.am gnutls28-3.6.7/tests/Makefile.am
--- gnutls28-3.6.6/tests/Makefile.am	2019-01-24 20:15:38.000000000 +0100
+++ gnutls28-3.6.7/tests/Makefile.am	2019-04-04 19:26:47.832143621 +0200
@@ -41,7 +41,7 @@ EXTRA_DIST = suppressions.valgrind eagai
 	certs/ed25519.pem certs/cert-ed25519.pem \
 	system.prio pkcs11/softhsm.h pkcs11/pkcs11-pubkey-import.c gnutls-asan.supp \
 	rsa-md5-collision/README safe-renegotiation/README starttls-smtp.txt starttls-ftp.txt \
-	starttls-lmtp.txt starttls-pop3.txt starttls-nntp.txt starttls-sieve.txt \
+	starttls-lmtp.txt starttls-pop3.txt starttls-xmpp.txt starttls-nntp.txt starttls-sieve.txt \
 	rsa-md5-collision/colliding-chain-md5-2.pem rsa-md5-collision/colliding-chain-md5-1.pem \
 	ocsp-tests/certs/ocsp-amazon.com.der ocsp-tests/certs/chain-amazon.com.pem \
 	ocsp-tests/certs/chain-amazon.com-unsorted.pem cipher-neg-common.c \
@@ -147,7 +147,7 @@ ctests += mini-record-2 simple gnutls_hm
 	 tls13-rehandshake-cert gnutls_ext_raw_parse handshake-large-cert \
 	 x509cert x509cert-tl infoaccess mini-dtls-hello-verify sign-verify-ed25519-rfc8080 \
 	 trustdb-tofu dtls-rehandshake-anon mini-alpn mini-dtls-large \
-	 mini-termination mini-x509-cas mini-x509-2 pkcs12_simple \
+	 mini-termination mini-x509-cas mini-x509-2 pkcs12_simple tls-pthread \
 	 mini-emsgsize-dtls chainverify-unsorted mini-overhead tls12-ffdhe \
 	 mini-dtls-heartbeat mini-x509-callbacks key-openssl priorities priorities-groups	\
 	 gnutls_x509_privkey_import gnutls_x509_crt_list_import \
@@ -163,7 +163,7 @@ ctests += mini-record-2 simple gnutls_hm
 	 mini-chain-unsorted x509-verify-with-crl mini-dtls-mtu privkey-verify-broken \
 	 mini-dtls-record-asym key-import-export priority-set priority-set2 \
 	 pubkey-import-export sign-is-secure spki spki-abstract rsa-rsa-pss \
-	 mini-dtls-fork mini-dtls-pthread mini-key-material x509cert-invalid \
+	 mini-dtls-fork dtls-pthread mini-key-material x509cert-invalid \
 	 tls-ext-register tls-supplemental mini-dtls0-9 duplicate-extensions \
 	 record-retvals mini-server-name tls-etm tls-force-etm x509-cert-callback alerts \
 	 client-sign-md5-rep tls12-invalid-key-exchanges session-rdn-read \
@@ -238,10 +238,16 @@ gnutls_record_overhead_CPPFLAGS = $(AM_C
 	-I$(top_builddir)/gl	\
 	$(NETTLE_CFLAGS)
 
+ip_utils_CPPFLAGS = $(AM_CPPFLAGS) \
+	-I$(top_srcdir)/gl	\
+	-I$(top_builddir)/gl	\
+	$(NETTLE_CFLAGS)
+
 endif
 
+tls_pthread_LDADD = $(LDADD) -lpthread
 fips_mode_pthread_LDADD = $(LDADD) -lpthread
-mini_dtls_pthread_LDADD = $(LDADD) -lpthread
+dtls_pthread_LDADD = $(LDADD) -lpthread
 rng_pthread_LDADD = $(LDADD) -lpthread
 
 memset0_CFLAGS = -DCHAR=0x0
@@ -456,12 +462,12 @@ dtls_stress_LDADD = $(COMMON_GNUTLS_LDAD
 	$(COMMON_DEPS_LDADD)
 
 dist_check_SCRIPTS += fastopen.sh pkgconfig.sh starttls.sh starttls-ftp.sh starttls-smtp.sh \
-	starttls-lmtp.sh starttls-pop3.sh starttls-nntp.sh starttls-sieve.sh \
+	starttls-lmtp.sh starttls-pop3.sh starttls-xmpp.sh starttls-nntp.sh starttls-sieve.sh \
 	ocsp-tests/ocsp-tls-connection ocsp-tests/ocsp-must-staple-connection \
 	ocsp-tests/ocsp-test cipher-listings.sh sni-hostname.sh server-multi-keys.sh \
 	psktool.sh ocsp-tests/ocsp-load-chain gnutls-cli-save-data.sh gnutls-cli-debug.sh \
 	sni-resume.sh ocsp-tests/ocsptool cert-reencoding.sh pkcs7-cat.sh long-crl.sh \
-	serv-udp.sh
+	serv-udp.sh logfile-option.sh gnutls-cli-resume.sh
 
 dist_check_SCRIPTS += gnutls-cli-self-signed.sh gnutls-cli-invalid-crl.sh
 
diff -NurBbp gnutls28-3.6.6/tests/mini-dtls-pthread.c gnutls28-3.6.7/tests/mini-dtls-pthread.c
--- gnutls28-3.6.6/tests/mini-dtls-pthread.c	2016-10-09 14:29:09.000000000 +0200
+++ gnutls28-3.6.7/tests/mini-dtls-pthread.c	1970-01-01 01:00:00.000000000 +0100
@@ -1,393 +0,0 @@
-/*
- * Copyright (C) 2015 Red Hat, Inc.
- *
- * Author: Nikos Mavrogiannopoulos
- *
- * This file is part of GnuTLS.
- *
- * GnuTLS is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * GnuTLS is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GnuTLS; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-#include <errno.h>
-#include <gnutls/gnutls.h>
-#include <gnutls/dtls.h>
-#include <signal.h>
-#include <unistd.h>
-#ifndef _WIN32
-# include <netinet/in.h>
-# include <sys/types.h>
-# include <sys/socket.h>
-# include <sys/wait.h>
-# include <pthread.h>
-#endif
-#include "utils.h"
-
-#ifdef _WIN32
-
-void doit(void)
-{
-	exit(77);
-}
-
-#else
-
-/* These are global */
-pid_t child;
-
-static void terminate(void)
-{
-	int status;
-
-	kill(child, SIGTERM);
-	wait(&status);
-	exit(1);
-}
-
-/* Tests whether we can send and receive from different threads
- * using DTLS, either as server or client. DTLS is a superset of
- * TLS, so correct behavior under fork means TLS would operate too.
- */
-
-const char *side = "";
-
-static void tls_log_func(int level, const char *str)
-{
-	fprintf(stderr, "%s|<%d>| %s", side, level, str);
-}
-
-static unsigned char server_cert_pem[] =
-  "-----BEGIN CERTIFICATE-----\n"
-  "MIICHzCCAaWgAwIBAgIBCTAKBggqhkjOPQQDAjA+MQswCQYDVQQGEwJOTDERMA8G\n"
-  "A1UEChMIUG9sYXJTU0wxHDAaBgNVBAMTE1BvbGFyc3NsIFRlc3QgRUMgQ0EwHhcN\n"
-  "MTMwOTI0MTU1MjA0WhcNMjMwOTIyMTU1MjA0WjA0MQswCQYDVQQGEwJOTDERMA8G\n"
-  "A1UEChMIUG9sYXJTU0wxEjAQBgNVBAMTCWxvY2FsaG9zdDBZMBMGByqGSM49AgEG\n"
-  "CCqGSM49AwEHA0IABDfMVtl2CR5acj7HWS3/IG7ufPkGkXTQrRS192giWWKSTuUA\n"
-  "2CMR/+ov0jRdXRa9iojCa3cNVc2KKg76Aci07f+jgZ0wgZowCQYDVR0TBAIwADAd\n"
-  "BgNVHQ4EFgQUUGGlj9QH2deCAQzlZX+MY0anE74wbgYDVR0jBGcwZYAUnW0gJEkB\n"
-  "PyvLeLUZvH4kydv7NnyhQqRAMD4xCzAJBgNVBAYTAk5MMREwDwYDVQQKEwhQb2xh\n"
-  "clNTTDEcMBoGA1UEAxMTUG9sYXJzc2wgVGVzdCBFQyBDQYIJAMFD4n5iQ8zoMAoG\n"
-  "CCqGSM49BAMCA2gAMGUCMQCaLFzXptui5WQN8LlO3ddh1hMxx6tzgLvT03MTVK2S\n"
-  "C12r0Lz3ri/moSEpNZWqPjkCMCE2f53GXcYLqyfyJR078c/xNSUU5+Xxl7VZ414V\n"
-  "fGa5kHvHARBPc8YAIVIqDvHH1Q==\n"
-  "-----END CERTIFICATE-----\n";
-
-const gnutls_datum_t server_cert = { server_cert_pem,
-	sizeof(server_cert_pem)
-};
-
-static unsigned char server_key_pem[] =
-  "-----BEGIN EC PRIVATE KEY-----\n"
-  "MHcCAQEEIPEqEyB2AnCoPL/9U/YDHvdqXYbIogTywwyp6/UfDw6noAoGCCqGSM49\n"
-  "AwEHoUQDQgAEN8xW2XYJHlpyPsdZLf8gbu58+QaRdNCtFLX3aCJZYpJO5QDYIxH/\n"
-  "6i/SNF1dFr2KiMJrdw1VzYoqDvoByLTt/w==\n"
-  "-----END EC PRIVATE KEY-----\n";
-
-const gnutls_datum_t server_key = { server_key_pem,
-	sizeof(server_key_pem)
-};
-
-#define MSG "hello1111"
-#define MSG2 "xxxxxxxxxxxx"
-
-static void *start_thread(void *arg)
-{
-	gnutls_session_t session = arg;
-	int ret;
-	char buf[64];
-
-	if (debug)
-		success("client: TLS version is: %s\n",
-			gnutls_protocol_get_name
-			(gnutls_protocol_get_version(session)));
-	sec_sleep(1);
-	/* the server should reflect our messages */
-	ret = gnutls_record_recv(session, buf, sizeof(buf));
-	if (ret != sizeof(MSG)-1 || memcmp(buf, MSG, sizeof(MSG)-1) != 0) {
-		fail("client: recv failed: %s\n", gnutls_strerror(ret));
-		exit(1);
-	}
-
-	if (debug) {
-		fprintf(stderr, "client received: %.*s\n", ret, buf);
-	}
-
-	ret = gnutls_record_recv(session, buf, sizeof(buf));
-	if (ret != sizeof(MSG2)-1 || memcmp(buf, MSG2, sizeof(MSG2)-1) != 0) {
-		fail("client: recv2 failed: %s\n", gnutls_strerror(ret));
-		exit(1);
-	}
-
-	if (debug) {
-		fprintf(stderr, "client received: %.*s\n", ret, buf);
-	}
-
-	ret = gnutls_record_recv(session, buf, sizeof(buf));
-	if (ret != 0) {
-		fail("client: recv3 failed: %s\n", gnutls_strerror(ret));
-		exit(1);
-	}
-
-	pthread_exit(0);
-}
-
-static
-void do_thread_stuff(gnutls_session_t session)
-{
-	int ret;
-	pthread_t id;
-
-	/* separate sending from receiving */
-	ret = pthread_create(&id, NULL, start_thread, session);
-	if (ret != 0) {
-		exit(1);
-	}
-
-	ret = gnutls_record_send(session, MSG, sizeof(MSG)-1);
-	if (ret != sizeof(MSG)-1) {
-		fail("client: send failed: %s\n", gnutls_strerror(ret));
-		exit(1);
-	}
-
-	ret = gnutls_record_send(session, MSG2, sizeof(MSG2)-1);
-	if (ret != sizeof(MSG2)-1) {
-		fail("client: send2 failed: %s\n", gnutls_strerror(ret));
-		exit(1);
-	}
-	sec_sleep(2);
-	gnutls_bye(session, GNUTLS_SHUT_WR);
-}
-
-static void do_reflect_stuff(gnutls_session_t session)
-{
-	char buf[64];
-	unsigned buf_size;
-	int ret;
-
-	do {
-		ret = gnutls_record_recv(session, buf, sizeof(buf));
-		if (ret < 0) {
-			fail("server: recv failed: %s\n", gnutls_strerror(ret));
-			terminate();
-		}
-
-		if (ret == 0)
-			break;
-
-		buf_size = ret;
-		if (debug) {
-			fprintf(stderr, "server received: %.*s\n", buf_size, buf);
-		}
-
-		ret = gnutls_record_send(session, buf, buf_size);
-		if (ret < 0) {
-			fail("server: send failed: %s\n", gnutls_strerror(ret));
-			terminate();
-		}
-	} while(1);
-
-	/* do not wait for the peer to close the connection.
-	 */
-	gnutls_bye(session, GNUTLS_SHUT_WR);
-}
-
-static void client(int fd, unsigned do_thread)
-{
-	int ret;
-	gnutls_certificate_credentials_t x509_cred;
-	gnutls_session_t session;
-	/* Need to enable anonymous KX specifically. */
-
-	global_init();
-
-	if (debug) {
-		side = "client";
-		gnutls_global_set_log_function(tls_log_func);
-		gnutls_global_set_log_level(4711);
-	}
-
-	gnutls_certificate_allocate_credentials(&x509_cred);
-
-	/* Initialize TLS session
-	 */
-	gnutls_init(&session, GNUTLS_CLIENT | GNUTLS_DATAGRAM);
-	gnutls_dtls_set_mtu(session, 1500);
-	gnutls_dtls_set_timeouts(session, 6 * 1000, 60 * 1000);
-	//gnutls_transport_set_push_function(session, push);
-
-	/* Use default priorities */
-	gnutls_priority_set_direct(session,
-				   "NONE:+VERS-DTLS-ALL:+CIPHER-ALL:+MAC-ALL:+SIGN-ALL:+COMP-ALL:+ECDHE-ECDSA:+CURVE-ALL",
-				   NULL);
-
-	/* put the anonymous credentials to the current session
-	 */
-	gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, x509_cred);
-
-	gnutls_transport_set_int(session, fd);
-
-	/* Perform the TLS handshake
-	 */
-	do {
-		ret = gnutls_handshake(session);
-	}
-	while (ret < 0 && gnutls_error_is_fatal(ret) == 0);
-
-	if (ret < 0) {
-		fail("client: Handshake failed\n");
-		gnutls_perror(ret);
-		exit(1);
-	} else {
-		if (debug)
-			success("client: Handshake was completed\n");
-	}
-
-	if (do_thread)
-		do_thread_stuff(session);
-	else
-		do_reflect_stuff(session);
-
-	close(fd);
-
-	gnutls_deinit(session);
-
-	gnutls_certificate_free_credentials(x509_cred);
-
-	gnutls_global_deinit();
-	exit(0);
-}
-
-
-static void server(int fd, unsigned do_thread)
-{
-	int ret;
-	gnutls_certificate_credentials_t x509_cred;
-	gnutls_session_t session;
-
-	/* this must be called once in the program
-	 */
-	global_init();
-
-#if 0
-	if (debug) {
-		side = "server";
-		gnutls_global_set_log_function(tls_log_func);
-		gnutls_global_set_log_level(4711);
-	}
-#endif
-
-	gnutls_certificate_allocate_credentials(&x509_cred);
-	gnutls_certificate_set_x509_key_mem(x509_cred, &server_cert,
-					    &server_key,
-					    GNUTLS_X509_FMT_PEM);
-
-	gnutls_init(&session, GNUTLS_SERVER | GNUTLS_DATAGRAM);
-	gnutls_dtls_set_timeouts(session, 5 * 1000, 60 * 1000);
-	gnutls_dtls_set_mtu(session, 400);
-
-	/* avoid calling all the priority functions, since the defaults
-	 * are adequate.
-	 */
-	gnutls_priority_set_direct(session,
-				   "NONE:+VERS-DTLS1.2:+CIPHER-ALL:+MAC-ALL:+SIGN-ALL:+COMP-ALL:+ECDHE-ECDSA:+CURVE-ALL",
-				   NULL);
-
-	gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, x509_cred);
-
-	gnutls_transport_set_int(session, fd);
-
-	do {
-		ret = gnutls_handshake(session);
-	} while (ret < 0 && gnutls_error_is_fatal(ret) == 0);
-	if (ret < 0) {
-		close(fd);
-		gnutls_deinit(session);
-		fail("server: Handshake has failed (%s)\n\n",
-		     gnutls_strerror(ret));
-		terminate();
-	}
-	if (debug)
-		success("server: Handshake was completed\n");
-
-	if (debug)
-		success("server: TLS version is: %s\n",
-			gnutls_protocol_get_name
-			(gnutls_protocol_get_version(session)));
-
-	if (do_thread)
-		do_thread_stuff(session);
-	else
-		do_reflect_stuff(session);
-
-
-	close(fd);
-	gnutls_deinit(session);
-
-	gnutls_certificate_free_credentials(x509_cred);
-
-	gnutls_global_deinit();
-
-	if (debug)
-		success("server: finished\n");
-}
-
-static
-void run(unsigned do_thread)
-{
-	int fd[2];
-	int ret;
-
-	ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fd);
-	if (ret < 0) {
-		perror("socketpair");
-		exit(1);
-	}
-
-	child = fork();
-	if (child < 0) {
-		perror("fork");
-		fail("fork");
-		exit(1);
-	}
-
-	if (child) {
-		int status;
-		/* parent */
-
-		close(fd[1]);
-		client(fd[0], do_thread);
-		wait(&status);
-		check_wait_status(status);
-	} else {
-		close(fd[0]);
-		server(fd[1], 1-do_thread);
-		exit(0);
-	}
-}
-
-void doit(void)
-{
-	signal(SIGPIPE, SIG_IGN);
-	run(0);
-	run(1);
-}
-#endif				/* _WIN32 */
diff -NurBbp gnutls28-3.6.6/tests/mini-server-name.c gnutls28-3.6.7/tests/mini-server-name.c
--- gnutls28-3.6.6/tests/mini-server-name.c	2018-03-22 08:56:48.000000000 +0100
+++ gnutls28-3.6.7/tests/mini-server-name.c	2019-04-04 19:26:47.968139565 +0200
@@ -310,21 +310,21 @@ void doit(void)
 	start("tls1.2 test.example.com", PRIO_TLS12, 0, "test.example.com", strlen("test.example.com"), "test.example.com", strlen("test.example.com"), 0);
 	start("tls1.2 longtest.example.com", PRIO_TLS12, 0, "longtest.example.com.", strlen("longtest.example.com"), "longtest.example.com.", strlen("longtest.example.com"), 0);
 	/* test embedded NULL */
-	start("tls1.2 embedded-NULL", PRIO_TLS12, 1, "invalid\x00.example.com.", sizeof("invalid\x00.example.com")-1, NULL, 0, GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER);
+	start("tls1.2 embedded-NULL", PRIO_TLS12, 1, "invalid\x00.example.com.", sizeof("invalid\x00.example.com")-1, NULL, 0, GNUTLS_E_RECEIVED_DISALLOWED_NAME);
 
 	start("tls1.3 NULL", PRIO_TLS13, 0, NULL, 0, NULL, 0, 0);
 	start("tls1.3 empty", PRIO_TLS13, 0, "", 0, "", 0, 0);
 	start("tls1.3 test.example.com", PRIO_TLS13, 0, "test.example.com", strlen("test.example.com"), "test.example.com", strlen("test.example.com"), 0);
 	start("tls1.3 longtest.example.com", PRIO_TLS13, 0, "longtest.example.com.", strlen("longtest.example.com"), "longtest.example.com.", strlen("longtest.example.com"), 0);
 	/* test embedded NULL */
-	start("tls1.3 embedded-NULL", PRIO_TLS13, 1, "invalid\x00.example.com.", sizeof("invalid\x00.example.com")-1, NULL, 0, GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER);
+	start("tls1.3 embedded-NULL", PRIO_TLS13, 1, "invalid\x00.example.com.", sizeof("invalid\x00.example.com")-1, NULL, 0, GNUTLS_E_RECEIVED_DISALLOWED_NAME);
 
 	start("NULL", PRIO_NORMAL, 0, NULL, 0, NULL, 0, 0);
 	start("empty", PRIO_NORMAL, 0, "", 0, "", 0, 0);
 	start("test.example.com", PRIO_NORMAL, 0, "test.example.com", strlen("test.example.com"), "test.example.com", strlen("test.example.com"), 0);
 	start("longtest.example.com", PRIO_NORMAL, 0, "longtest.example.com.", strlen("longtest.example.com"), "longtest.example.com.", strlen("longtest.example.com"), 0);
 	/* test embedded NULL */
-	start("embedded-NULL", PRIO_NORMAL, 1, "invalid\x00.example.com.", sizeof("invalid\x00.example.com")-1, NULL, 0, GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER);
+	start("embedded-NULL", PRIO_NORMAL, 1, "invalid\x00.example.com.", sizeof("invalid\x00.example.com")-1, NULL, 0, GNUTLS_E_RECEIVED_DISALLOWED_NAME);
 }
 
 #endif				/* _WIN32 */
diff -NurBbp gnutls28-3.6.6/tests/name-constraints-ip.c gnutls28-3.6.7/tests/name-constraints-ip.c
--- gnutls28-3.6.6/tests/name-constraints-ip.c	2017-03-06 21:29:43.000000000 +0100
+++ gnutls28-3.6.7/tests/name-constraints-ip.c	2019-02-25 19:14:55.000000000 +0100
@@ -78,7 +78,6 @@ static void check_test_result(int ret, i
 static void parse_cidr(const char* cidr, gnutls_datum_t *datum) {
 	if (datum->data != NULL) {
 		gnutls_free(datum->data);
-		datum->data = NULL;
 	}
 	int ret = gnutls_x509_cidr_to_rfc5280(cidr, datum);
 	check_for_error(ret);
@@ -699,7 +698,7 @@ static int teardown(void **state) {
 	gnutls_free(test_vars->ip.data);
 	gnutls_x509_name_constraints_deinit(test_vars->nc);
 	gnutls_x509_name_constraints_deinit(test_vars->nc2);
-	gnutls_free(test_vars);
+	gnutls_free(*state);
 	return 0;
 }
 
diff -NurBbp gnutls28-3.6.6/tests/null_retrieve_function.c gnutls28-3.6.7/tests/null_retrieve_function.c
--- gnutls28-3.6.6/tests/null_retrieve_function.c	2018-07-24 22:06:03.000000000 +0200
+++ gnutls28-3.6.7/tests/null_retrieve_function.c	2019-04-04 19:26:48.048137180 +0200
@@ -102,19 +102,19 @@ void doit(void)
 	gnutls_certificate_allocate_credentials(&clicred);
 	gnutls_certificate_set_retrieve_function(clicred, cert_cb1);
 	gnutls_certificate_set_retrieve_function(clicred, NULL);
-	_test_cli_serv(x509_cred, clicred, "NORMAL", "NORMAL", "localhost", NULL, NULL, NULL, 0, 1, GNUTLS_E_NO_CERTIFICATE_FOUND, -1);
+	_test_cli_serv(x509_cred, clicred, "NORMAL", "NORMAL", "localhost", NULL, NULL, NULL, 0, 1, GNUTLS_E_CERTIFICATE_REQUIRED, -1);
 	gnutls_certificate_free_credentials(clicred);
 
 	gnutls_certificate_allocate_credentials(&clicred);
 	gnutls_certificate_set_retrieve_function2(clicred, cert_cb2);
 	gnutls_certificate_set_retrieve_function2(clicred, NULL);
-	_test_cli_serv(x509_cred, clicred, "NORMAL", "NORMAL", "localhost", NULL, NULL, NULL, 0, 1, GNUTLS_E_NO_CERTIFICATE_FOUND, -1);
+	_test_cli_serv(x509_cred, clicred, "NORMAL", "NORMAL", "localhost", NULL, NULL, NULL, 0, 1, GNUTLS_E_CERTIFICATE_REQUIRED, -1);
 	gnutls_certificate_free_credentials(clicred);
 
 	gnutls_certificate_allocate_credentials(&clicred);
 	gnutls_certificate_set_retrieve_function3(clicred, cert_cb3);
 	gnutls_certificate_set_retrieve_function3(clicred, NULL);
-	_test_cli_serv(x509_cred, clicred, "NORMAL", "NORMAL", "localhost", NULL, NULL, NULL, 0, 1, GNUTLS_E_NO_CERTIFICATE_FOUND, -1);
+	_test_cli_serv(x509_cred, clicred, "NORMAL", "NORMAL", "localhost", NULL, NULL, NULL, 0, 1, GNUTLS_E_CERTIFICATE_REQUIRED, -1);
 	gnutls_certificate_free_credentials(clicred);
 
 	gnutls_certificate_free_credentials(x509_cred);
diff -NurBbp gnutls28-3.6.6/tests/pkcs11/pkcs11-import-url-privkey.c gnutls28-3.6.7/tests/pkcs11/pkcs11-import-url-privkey.c
--- gnutls28-3.6.6/tests/pkcs11/pkcs11-import-url-privkey.c	2018-11-18 19:53:49.000000000 +0100
+++ gnutls28-3.6.7/tests/pkcs11/pkcs11-import-url-privkey.c	2019-02-25 19:14:55.000000000 +0100
@@ -91,7 +91,6 @@ void doit(void)
 	for (i=0;i<obj_list_size;i++)
 		gnutls_pkcs11_obj_deinit(obj_list[i]);
 	gnutls_free(obj_list);
-	obj_list = NULL;
 	obj_list_size = 0;
 
 #ifndef _WIN32
@@ -122,7 +121,6 @@ void doit(void)
 		for (i=0;i<obj_list_size;i++)
 			gnutls_pkcs11_obj_deinit(obj_list[i]);
 		gnutls_free(obj_list);
-		obj_list = NULL;
 		obj_list_size = 0;
 	}
 #endif
diff -NurBbp gnutls28-3.6.6/tests/pkcs11/pkcs11-privkey-always-auth.c gnutls28-3.6.7/tests/pkcs11/pkcs11-privkey-always-auth.c
--- gnutls28-3.6.6/tests/pkcs11/pkcs11-privkey-always-auth.c	2016-11-05 19:12:02.000000000 +0100
+++ gnutls28-3.6.7/tests/pkcs11/pkcs11-privkey-always-auth.c	2019-02-25 19:14:55.000000000 +0100
@@ -175,7 +175,6 @@ void doit(void)
 	pin_called = 0;
 
 	gnutls_free(sig.data);
-	sig.data = NULL;
 
 	/* call again - should re-authenticate */
 	ret = gnutls_privkey_sign_hash(key, GNUTLS_DIG_SHA1, 0, &data, &sig);
@@ -190,7 +189,6 @@ void doit(void)
 	pin_called = 0;
 
 	gnutls_free(sig.data);
-	sig.data = NULL;
 
 	if (debug)
 		printf("done\n\n\n");
diff -NurBbp gnutls28-3.6.6/tests/pkcs11/pkcs11-privkey-fork.c gnutls28-3.6.7/tests/pkcs11/pkcs11-privkey-fork.c
--- gnutls28-3.6.6/tests/pkcs11/pkcs11-privkey-fork.c	2016-09-11 11:55:02.000000000 +0200
+++ gnutls28-3.6.7/tests/pkcs11/pkcs11-privkey-fork.c	2019-02-25 19:14:55.000000000 +0100
@@ -123,7 +123,6 @@ void doit(void)
 	}
 
 	gnutls_free(sig.data);
-	sig.data = NULL;
 
 	pid = fork();
 	if (pid != 0) {
diff -NurBbp gnutls28-3.6.6/tests/pkcs11/pkcs11-privkey-fork-reinit.c gnutls28-3.6.7/tests/pkcs11/pkcs11-privkey-fork-reinit.c
--- gnutls28-3.6.6/tests/pkcs11/pkcs11-privkey-fork-reinit.c	2017-04-19 21:49:27.000000000 +0200
+++ gnutls28-3.6.7/tests/pkcs11/pkcs11-privkey-fork-reinit.c	2019-02-25 19:14:55.000000000 +0100
@@ -123,7 +123,6 @@ void doit(void)
 	}
 
 	gnutls_free(sig.data);
-	sig.data = NULL;
 
 	pid = fork();
 	if (pid != 0) {
diff -NurBbp gnutls28-3.6.6/tests/pkcs11/pkcs11-privkey-safenet-always-auth.c gnutls28-3.6.7/tests/pkcs11/pkcs11-privkey-safenet-always-auth.c
--- gnutls28-3.6.6/tests/pkcs11/pkcs11-privkey-safenet-always-auth.c	2017-12-14 11:00:19.000000000 +0100
+++ gnutls28-3.6.7/tests/pkcs11/pkcs11-privkey-safenet-always-auth.c	2019-02-25 19:14:55.000000000 +0100
@@ -157,7 +157,6 @@ void doit(void)
 	pin_called = 0;
 
 	gnutls_free(sig.data);
-	sig.data = NULL;
 
 	/* call again - should re-authenticate */
 	ret = gnutls_privkey_sign_hash(key, GNUTLS_DIG_SHA1, 0, &data, &sig);
@@ -172,7 +171,6 @@ void doit(void)
 	pin_called = 0;
 
 	gnutls_free(sig.data);
-	sig.data = NULL;
 
 	if (debug)
 		printf("done\n\n\n");
diff -NurBbp gnutls28-3.6.6/tests/pkcs11/pkcs11-token-raw.c gnutls28-3.6.7/tests/pkcs11/pkcs11-token-raw.c
--- gnutls28-3.6.6/tests/pkcs11/pkcs11-token-raw.c	2018-05-26 05:44:29.000000000 +0200
+++ gnutls28-3.6.7/tests/pkcs11/pkcs11-token-raw.c	2019-04-04 19:26:48.048137180 +0200
@@ -57,6 +57,7 @@ static void tls_log_func(int level, cons
 	fprintf(stderr, "|<%d>| %s", level, str);
 }
 
+#define TOKEN_NAME "whatever"
 void doit(void)
 {
 	int ret;
@@ -93,6 +94,42 @@ void doit(void)
 		exit(1);
 	}
 
+	{
+		static const char url[] = "pkcs11:token="TOKEN_NAME;
+
+		/* Testing a too small buffer */
+		size_t size = 1;
+		char *buf = gnutls_malloc(size);
+		assert(buf != NULL);
+		ret = gnutls_pkcs11_token_get_info(url,
+			GNUTLS_PKCS11_TOKEN_LABEL,
+			buf, &size);
+		assert(ret == GNUTLS_E_SHORT_MEMORY_BUFFER);
+		assert(size == strlen(TOKEN_NAME)+1);
+
+		/* Testing a too small buffer by one */
+		size -= 1;
+		buf = gnutls_realloc(buf, size);
+		assert(buf != NULL);
+		ret = gnutls_pkcs11_token_get_info(url,
+			GNUTLS_PKCS11_TOKEN_LABEL,
+			buf, &size);
+		assert(ret == GNUTLS_E_SHORT_MEMORY_BUFFER);
+		assert(size == strlen(TOKEN_NAME)+1);
+
+		/* Testing an exactly fitting buffer */
+		buf = gnutls_realloc(buf, size);
+		assert(buf != NULL);
+		ret = gnutls_pkcs11_token_get_info(url,
+			GNUTLS_PKCS11_TOKEN_LABEL,
+			buf, &size);
+		assert(ret == 0);
+		assert(strcmp(buf, TOKEN_NAME) == 0);
+		assert(size == strlen(TOKEN_NAME));
+
+		gnutls_free(buf);
+	}
+
 	ret = gnutls_pkcs11_token_get_ptr("pkcs11:token=invalid", (void**)&mod, &slot_id, 0);
 	assert(ret == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE);
 
diff -NurBbp gnutls28-3.6.6/tests/pkcs7.c gnutls28-3.6.7/tests/pkcs7.c
--- gnutls28-3.6.6/tests/pkcs7.c	2017-04-19 21:49:27.000000000 +0200
+++ gnutls28-3.6.7/tests/pkcs7.c	2019-02-25 19:14:55.000000000 +0100
@@ -90,7 +90,6 @@ static int getnextfile(DIR **dirp, gnutl
 				*exp_ret = atoi((char*)local.data);
 				success("expecting error code %d\n", *exp_ret);
 				gnutls_free(local.data);
-				local.data = NULL;
 			}
 
 			return 0;
@@ -134,7 +133,6 @@ void doit(void)
 
 		gnutls_pkcs7_deinit(cert);
 		gnutls_free(der.data);
-		der.data = NULL;
 		der.size = 0;
 		exp_ret = -1;
 	}
diff -NurBbp gnutls28-3.6.6/tests/resume.c gnutls28-3.6.7/tests/resume.c
--- gnutls28-3.6.6/tests/resume.c	2018-11-28 19:56:17.000000000 +0100
+++ gnutls28-3.6.7/tests/resume.c	2019-04-04 19:26:48.052137061 +0200
@@ -900,7 +900,6 @@ static void server(int sds[], struct par
 	}
 
 	gnutls_free(session_ticket_key.data);
-	session_ticket_key.data = NULL;
 
 	if (debug)
 		success("server: finished\n");
diff -NurBbp gnutls28-3.6.6/tests/resume-dtls.c gnutls28-3.6.7/tests/resume-dtls.c
--- gnutls28-3.6.6/tests/resume-dtls.c	2016-11-05 19:12:02.000000000 +0100
+++ gnutls28-3.6.7/tests/resume-dtls.c	2019-02-25 19:14:55.000000000 +0100
@@ -363,7 +363,6 @@ static void server(int sds[], struct par
 	}
 
 	gnutls_free(session_ticket_key.data);
-	session_ticket_key.data = NULL;
 	gnutls_anon_free_server_credentials(anoncred);
 
 	if (debug)
diff -NurBbp gnutls28-3.6.6/tests/seccomp.c gnutls28-3.6.7/tests/seccomp.c
--- gnutls28-3.6.6/tests/seccomp.c	2016-09-11 11:55:53.000000000 +0200
+++ gnutls28-3.6.7/tests/seccomp.c	2019-04-04 19:26:48.052137061 +0200
@@ -26,6 +26,9 @@
 #include <seccomp.h>
 #include <errno.h>
 #include <string.h>
+#if defined(__linux__)
+#  include <sys/syscall.h>
+#endif
 
 int disable_system_calls(void)
 {
@@ -70,7 +73,9 @@ int disable_system_calls(void)
 
 	/* to read from /dev/urandom */
 	ADD_SYSCALL(read, 0);
+#ifdef SYS_getrandom
 	ADD_SYSCALL(getrandom, 0);
+#endif
 
 	/* we use it in select */
 	ADD_SYSCALL(sigprocmask, 0);
diff -NurBbp gnutls28-3.6.6/tests/set_key_utf8.c gnutls28-3.6.7/tests/set_key_utf8.c
--- gnutls28-3.6.6/tests/set_key_utf8.c	2017-12-14 11:00:19.000000000 +0100
+++ gnutls28-3.6.7/tests/set_key_utf8.c	2019-02-04 19:07:18.000000000 +0100
@@ -140,7 +140,7 @@ static void auto_parse(void)
 
 	/* the raw DNS should result to verification failure as the advertized name should
 	 * not be considered and the first cert should be provided */
-	test_cli_serv_expect(x509_cred, clicred, "NORMAL", "NORMAL", "raw:简体中文.εξτρα.com", GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER, GNUTLS_E_AGAIN);
+	test_cli_serv_expect(x509_cred, clicred, "NORMAL", "NORMAL", "raw:简体中文.εξτρα.com", GNUTLS_E_RECEIVED_DISALLOWED_NAME, GNUTLS_E_AGAIN);
 
 	gnutls_certificate_free_credentials(x509_cred);
 	gnutls_certificate_free_credentials(clicred);
diff -NurBbp gnutls28-3.6.6/tests/set_x509_key_utf8.c gnutls28-3.6.7/tests/set_x509_key_utf8.c
--- gnutls28-3.6.6/tests/set_x509_key_utf8.c	2017-12-14 11:00:19.000000000 +0100
+++ gnutls28-3.6.7/tests/set_x509_key_utf8.c	2019-02-04 19:07:18.000000000 +0100
@@ -177,7 +177,7 @@ void doit(void)
 	test_cli_serv(x509_cred, clicred, "NORMAL", "简体中文.εξτρα.com", NULL, NULL, NULL); /* the second DNS name of cert */
 	test_cli_serv(x509_cred, clicred, "NORMAL", "xn--fiqu1az03c18t.xn--mxah1amo.com", NULL, NULL, NULL); /* its IDNA equivalent */
 
-	test_cli_serv_expect(x509_cred, clicred, "NORMAL", "NORMAL", "raw:简体中文.εξτρα.com", GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER, GNUTLS_E_AGAIN);
+	test_cli_serv_expect(x509_cred, clicred, "NORMAL", "NORMAL", "raw:简体中文.εξτρα.com", GNUTLS_E_RECEIVED_DISALLOWED_NAME, GNUTLS_E_AGAIN);
 
 	gnutls_certificate_free_credentials(x509_cred);
 	gnutls_certificate_free_credentials(clicred);
diff -NurBbp gnutls28-3.6.6/tests/sign-verify.c gnutls28-3.6.7/tests/sign-verify.c
--- gnutls28-3.6.6/tests/sign-verify.c	2018-02-19 20:07:27.000000000 +0100
+++ gnutls28-3.6.7/tests/sign-verify.c	2019-02-25 19:14:55.000000000 +0100
@@ -206,7 +206,6 @@ void doit(void)
 
 		/* test the raw interface */
 		gnutls_free(signature.data);
-		signature.data = NULL;
 
 		if (gnutls_pubkey_get_pk_algorithm(pubkey, NULL) ==
 		    GNUTLS_PK_RSA) {
diff -NurBbp gnutls28-3.6.6/tests/sign-verify-data.c gnutls28-3.6.7/tests/sign-verify-data.c
--- gnutls28-3.6.6/tests/sign-verify-data.c	2018-02-19 20:07:27.000000000 +0100
+++ gnutls28-3.6.7/tests/sign-verify-data.c	2019-02-25 19:14:55.000000000 +0100
@@ -153,7 +153,6 @@ void doit(void)
 
 		/* test the raw interface */
 		gnutls_free(signature.data);
-		signature.data = NULL;
 
 		gnutls_free(signature.data);
 		gnutls_x509_crt_deinit(crt);
diff -NurBbp gnutls28-3.6.6/tests/sign-verify-ext4.c gnutls28-3.6.7/tests/sign-verify-ext4.c
--- gnutls28-3.6.6/tests/sign-verify-ext4.c	2018-03-22 08:56:48.000000000 +0100
+++ gnutls28-3.6.7/tests/sign-verify-ext4.c	2019-04-04 19:26:48.056136943 +0200
@@ -227,7 +227,6 @@ void doit(void)
 			testfail("gnutls_pubkey_verify_data2\n");
 
 		gnutls_free(signature.data);
-		signature.data = NULL;
 
 
 		if (!tests[i].data_only) {
@@ -243,7 +242,6 @@ void doit(void)
 				testfail("gnutls_pubkey_verify_hash2-1 (hashed data)\n");
 
 			gnutls_free(signature2.data);
-			signature2.data = NULL;
 		}
 
 		if (gnutls_pubkey_get_pk_algorithm(pubkey, NULL) ==
diff -NurBbp gnutls28-3.6.6/tests/sign-verify-ext.c gnutls28-3.6.7/tests/sign-verify-ext.c
--- gnutls28-3.6.6/tests/sign-verify-ext.c	2018-02-19 20:07:27.000000000 +0100
+++ gnutls28-3.6.7/tests/sign-verify-ext.c	2019-02-25 19:14:55.000000000 +0100
@@ -186,9 +186,7 @@ void doit(void)
 
 		/* test the raw interface */
 		gnutls_free(signature.data);
-		signature.data = NULL;
 		gnutls_free(signature2.data);
-		signature2.data = NULL;
 
 		if (gnutls_pubkey_get_pk_algorithm(pubkey, NULL) ==
 		    GNUTLS_PK_RSA) {
diff -NurBbp gnutls28-3.6.6/tests/starttls-xmpp.sh gnutls28-3.6.7/tests/starttls-xmpp.sh
--- gnutls28-3.6.6/tests/starttls-xmpp.sh	1970-01-01 01:00:00.000000000 +0100
+++ gnutls28-3.6.7/tests/starttls-xmpp.sh	2019-03-08 20:16:12.000000000 +0100
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+# Copyright (C) 2010-2016 Free Software Foundation, Inc.
+#
+# Author: Nikos Mavrogiannopoulos
+#
+# This file is part of GnuTLS.
+#
+# GnuTLS is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 3 of the License, or (at
+# your option) any later version.
+#
+# GnuTLS is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GnuTLS; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+srcdir="${srcdir:-.}"
+SERV="${SERV:-../src/gnutls-serv${EXEEXT}}"
+CLI="${CLI:-../src/gnutls-cli${EXEEXT}}"
+unset RETCODE
+
+. "${srcdir}/scripts/common.sh"
+. "${srcdir}/scripts/starttls-common.sh"
+
+echo "Checking STARTTLS over XMPP"
+
+eval "${GETPORT}"
+socat TCP-LISTEN:${PORT} EXEC:"$CHAT -e -S -v -f ${srcdir}/starttls-xmpp.txt",pty &
+PID=$!
+wait_server ${PID}
+
+${VALGRIND} "${CLI}" -p "${PORT}" 127.0.0.1 --priority NORMAL:+ANON-ECDH --insecure --starttls-proto xmpp --verbose </dev/null >/dev/null
+if test $? != 1;then
+	fail ${PID} "connect should have failed with error code 1"
+fi
+
+kill ${PID}
+wait
+
+exit 0
diff -NurBbp gnutls28-3.6.6/tests/starttls-xmpp.txt gnutls28-3.6.7/tests/starttls-xmpp.txt
--- gnutls28-3.6.6/tests/starttls-xmpp.txt	1970-01-01 01:00:00.000000000 +0100
+++ gnutls28-3.6.7/tests/starttls-xmpp.txt	2019-03-08 20:16:12.000000000 +0100
@@ -0,0 +1,3 @@
+TIMEOUT 10
+'<stream:stream xmlns:stream' '<?xml version\=\'1.0\'?><stream:stream id\=\'16633990255660214772\' version\=\'1.0\' xml:lang\=\'en\' xmlns:stream\=\'http://etherx.jabber.org/streams\' from\=\'schokokeks.org\' xmlns\=\'jabber:client\'><stream:features><starttls xmlns\=\'urn:ietf:params:xml:ns:xmpp-tls\'><required/></starttls></stream:features>'
+'<starttls xmlns\=\'urn:ietf:params:xml:ns:xmpp-tls\'/>' '<proceed xmlns\=\'urn:ietf:params:xml:ns:xmpp-tls\'/>'
diff -NurBbp gnutls28-3.6.6/tests/test-chains.h gnutls28-3.6.7/tests/test-chains.h
--- gnutls28-3.6.6/tests/test-chains.h	2018-09-24 17:26:28.000000000 +0200
+++ gnutls28-3.6.7/tests/test-chains.h	2019-04-04 19:26:55.139926423 +0200
@@ -154,71 +154,76 @@ static const char *chain_with_no_subject
 	"-----END CERTIFICATE-----\n"
 };
 
+/* This chain was generated by a modified gnutls lib. The script tests/suite/certs/create-chain.sh
+ * was used after modifying it to generate RSA-PSS certificates and set 64 byte salt in intermediate
+ * CA, and 48-byte otherwise. Then _gnutls_x509_write_sign_params() was modified to set a 32-byte salt
+ * when it would have set a 64-byte one. That way signatures from the intermediate certificate restricted
+ * to 64-byte salts will be incorrectly set to 32-bytes. */
 static const char *rsa_pss_chain_smaller_salt_in_sig_fail[] = {
 	"-----BEGIN CERTIFICATE-----\n"
-	"MIIDfzCCAjegAwIBAgIMWXnRYyUPHcgwMUF2MD0GCSqGSIb3DQEBCjAwoA0wCwYJ\n"
-	"YIZIAWUDBAIBoRowGAYJKoZIhvcNAQEIMAsGCWCGSAFlAwQCAaIDAgEgMA8xDTAL\n"
-	"BgNVBAMTBENBLTEwIBcNMTcwNzI3MTE0MTIzWhgPOTk5OTEyMzEyMzU5NTlaMBMx\n"
-	"ETAPBgNVBAMTCHNlcnZlci0yMIIBIDALBgkqhkiG9w0BAQoDggEPADCCAQoCggEB\n"
-	"ALPUjrvjgPh9hv3gYDxu/Un28TzS3os+O1eAbVGuTeO0BX3u5D2ZtaVeB7gLwSku\n"
-	"YkDKLrXs+M5BsvpZOfKIyQjrLuc5U5ik8W7SsSH5MVliergMTz4Qi+DtXdsrIjpk\n"
-	"oTDxgUatrpYQSocPfqdMgma3DyW3jlZv4BoLZ95TsJi23qZxZI9fQeGG9DZ+x2h6\n"
-	"3QeW4OTpJB75O6ruas7KiId9RH6WHj/JvLF99RGhPHa7SUZstyvnDA80Igood6S6\n"
-	"J3GNs1RHnaHeOqcyfbdNzlyTaLK0Acos6AKlkm4OYABXRmfDSyjVPto7FTV4I9CV\n"
-	"jSRXOa5IK3kUvFApM6SvzQsCAwEAAaN3MHUwDAYDVR0TAQH/BAIwADAUBgNVHREE\n"
-	"DTALgglsb2NhbGhvc3QwDwYDVR0PAQH/BAUDAweAADAdBgNVHQ4EFgQUhAHLtEhd\n"
-	"NxMr6TQX5GB4a29ng4YwHwYDVR0jBBgwFoAU6h4fxmpkIoNy/qx6u4Z13H7WN+Qw\n"
-	"PQYJKoZIhvcNAQEKMDCgDTALBglghkgBZQMEAgGhGjAYBgkqhkiG9w0BAQgwCwYJ\n"
-	"YIZIAWUDBAIBogMCASADggEBAL5SQpMtcGQ4mNZaaW3SNB8EBPo4VZ1GXYsOd0ef\n"
-	"JmhNKKrw5Z2WHR8xDbP7cwq/X+U0M9TMhCWPaDgzt46TJu+ct43UqGt/bgz2Xt2R\n"
-	"xCvlhwGNM3A5c417jmNQiQvMyCiEZSPD7RLowoE34XyjaxydYoWGq9otNoIq0CX9\n"
-	"Q7GZudWfWvwDU3zM8gy6k8EPmOgG8PdvW6PjKyf5y/uSDHY7Dm8d9E/uybAbZUVo\n"
-	"WfdwhhP66EDmNozTNaBcfIkJTmuxq2oxnA8JS1V5hMccfZLIRh0hBkpdGXSAOMNV\n"
-	"qjqJUOWrbU5hbcZUk2UHK34rNvkX+rDmuKD2vAQ7MguzHfI=\n"
-	"-----END CERTIFICATE-----\n",
-	"-----BEGIN CERTIFICATE-----\n"
-	"MIIDmjCCAlKgAwIBAgIMWXnRYyHbNWzuFxmzMD0GCSqGSIb3DQEBCjAwoA0wCwYJ\n"
-	"YIZIAWUDBAIBoRowGAYJKoZIhvcNAQEIMAsGCWCGSAFlAwQCAaIDAgFAMA8xDTAL\n"
-	"BgNVBAMTBENBLTAwIBcNMTcwNzI3MTE0MTIzWhgPOTk5OTEyMzEyMzU5NTlaMA8x\n"
-	"DTALBgNVBAMTBENBLTEwggFSMD0GCSqGSIb3DQEBCjAwoA0wCwYJYIZIAWUDBAIB\n"
-	"oRowGAYJKoZIhvcNAQEIMAsGCWCGSAFlAwQCAaIDAgEgA4IBDwAwggEKAoIBAQDB\n"
-	"uQ2UwKWT1BfN6H2B3svKL34aPW/+MTfN8McvExZsZYuQyRxeG8SV4uJ+GAtJ/Ml/\n"
-	"eaUqiKG0pNCna846FUtAax/0quuVSaZ2xOVA3lMKj2frtRLJ3W6ZaglCHkZUHhII\n"
-	"JEtE1s0F8aaaZ6X4/57OAi6uyFNuBSBsp3giQS6SrtFMbhq7OuSSt2T14XlVGvAI\n"
-	"TiO7t21+Eukq2jDGOerUax4Yxki4l8589uXu5IQzZalj42hr9YKbNb75RAICNnY8\n"
-	"jxCezc0o8KNoDF0IAK7UERz6uUQElUh/bdm0k3UV+uVA6t0disZ4gdenPuLsGSVD\n"
-	"9fcbh/zFlv2V3A9HLJB3AgMBAAGjZDBiMA8GA1UdEwEB/wQFMAMBAf8wDwYDVR0P\n"
-	"AQH/BAUDAwcEADAdBgNVHQ4EFgQU6h4fxmpkIoNy/qx6u4Z13H7WN+QwHwYDVR0j\n"
-	"BBgwFoAUZ97LfvATPRiWxwNOO+sxC5ig8VkwPQYJKoZIhvcNAQEKMDCgDTALBglg\n"
-	"hkgBZQMEAgGhGjAYBgkqhkiG9w0BAQgwCwYJYIZIAWUDBAIBogMCASADggEBAFGH\n"
-	"zxWW8R95wmmuDecuKf31LEKPubtaeqMRqt2Vk2mGCQOxcerl6MMGyl3w46hEkAjU\n"
-	"jAPwmNnB9xyEyqR5w2TYrpzsrnUcZn+6HzSiPTEJ0jhY2S8N2V+Bch1QgMwlgeaD\n"
-	"bZrY6qAG6PeqoQ8XhZ8+1sI/IpQKJHmmBN+qYbLFxEPjE4QnBahPbKfbpMY0MMX0\n"
-	"uuI2nSBKcYmkYiWBYdydpP24VfeoUP0V6bXc5rrDdCNGp+AxUID51GT0AoMf2FGK\n"
-	"LeOLJtPqH7raz44pa1qezHq4gPeXC0Ende9j7IimpsdB6eDVle8UZipfeASq9XVL\n"
-	"F430KTcS7x42r71NZUU=\n"
+	"MIIDiTCCAkGgAwIBAgIUMquMu6/Azo9N40rNZ1z7hkotqC0wPQYJKoZIhvcNAQEK\n"
+	"MDCgDTALBglghkgBZQMEAgKhGjAYBgkqhkiG9w0BAQgwCwYJYIZIAWUDBAICogMC\n"
+	"ASAwDzENMAsGA1UEAxMEQ0EtMTAgFw0xOTAyMTIyMDU0NTlaGA85OTk5MTIzMTIz\n"
+	"NTk1OVowEzERMA8GA1UEAxMIc2VydmVyLTIwggEiMA0GCSqGSIb3DQEBAQUAA4IB\n"
+	"DwAwggEKAoIBAQDrEJ5ONj7OYNjDZ3johFKItvX6BFJ7ejLfNELvT7I9hsiGJBr5\n"
+	"Q/NgeQolSXLKHYG0L5Lxu1fbHINzC43NEivY3KMKKl0+MdXWwAr0yW/cTeuDc/+e\n"
+	"YqGT3TpCcxa/0dJ+Y3zAS1DqsHjNOxyYBvyKATyvFKo+oAwOqtR/OLflUvoXvYZV\n"
+	"YByseOLhE70Vfuk8yppRcKwokwk/3S6dZjoxK1K3PBQGARJNaUChtx5iM1qMrluK\n"
+	"uDj7yV9DYhtyhSmYvcZ1gb3t0aAxGoGbfdOHa7XMovzfRDUPbwvkKUJqcNfGkeGn\n"
+	"pZRzbA8D/YrjFtm7QVgf6yD20DbZChzoxRWzAgMBAAGjdzB1MAwGA1UdEwEB/wQC\n"
+	"MAAwFAYDVR0RBA0wC4IJbG9jYWxob3N0MA8GA1UdDwEB/wQFAwMHoAAwHQYDVR0O\n"
+	"BBYEFM/CHpfVzdNRBMYfqBXUieW9m9oFMB8GA1UdIwQYMBaAFDBBFsyy+oqRFlRx\n"
+	"MH5qlHt7guXUMD0GCSqGSIb3DQEBCjAwoA0wCwYJYIZIAWUDBAICoRowGAYJKoZI\n"
+	"hvcNAQEIMAsGCWCGSAFlAwQCAqIDAgEgA4IBAQADuShUlCXrs5K6Yu7mKvoyZztJ\n"
+	"dQFuxv4WDvbhoZ19GEEg6icRUoaA3tWKf7tNRnqQklMLhWIZParXtt+xz7q5K6ic\n"
+	"kX5oGzzUNryAx5DJkZCCffdA1FaQjCEI6Cy5cEnGifXyacwA7BViUwMnWvJRSKYi\n"
+	"gvBVKc1TBwA+vPIzlSb3COo1zhshxM+C7mhzspDFkceXV7qapFDMj7M/GbgqH7h0\n"
+	"yuJv2bymytjXadR43LuG6yqqsFvIPHYBcyPq3Uzu+57UJbHhAlkTXaAXfZkc1Ut7\n"
+	"Xz8pOEzcxZHl4SEgsO6KeT2uQUE1Zx5AgwaNfuMmg0aFJep8vKcQ1jvdzxS2\n"
+	"-----END CERTIFICATE-----\n",
+	"-----BEGIN CERTIFICATE-----\n"
+	"MIIDojCCAlqgAwIBAgIUYIZPL5Kf86B0XYSKAdI8dv4HJY8wPQYJKoZIhvcNAQEK\n"
+	"MDCgDTALBglghkgBZQMEAgGhGjAYBgkqhkiG9w0BAQgwCwYJYIZIAWUDBAIBogMC\n"
+	"ATAwDzENMAsGA1UEAxMEQ0EtMDAgFw0xOTAyMTIyMDU0NTlaGA85OTk5MTIzMTIz\n"
+	"NTk1OVowDzENMAsGA1UEAxMEQ0EtMTCCAVIwPQYJKoZIhvcNAQEKMDCgDTALBglg\n"
+	"hkgBZQMEAgKhGjAYBgkqhkiG9w0BAQgwCwYJYIZIAWUDBAICogMCAUADggEPADCC\n"
+	"AQoCggEBANCQ6fUJYYI3OTDYIcyshBdnVBQq0uGjHg/04niCpoAZi/nlfP3tCRZS\n"
+	"k44kMt6hla9cEkdj5mzeGFlG5AYG9C5MimyYwTJ5Sho6t8ct4wPESeypuDbcvMRX\n"
+	"MTLM/9+ZECkDgKA238z4sNX0T0ppsCXy8IK0Jmn7bky6lqNmaMTjYWy7Tu4kQOMX\n"
+	"7RE4tv/WlaH95d7zHYuaAf5dNY5GJ/cGrkYLrL1KpN/UU/4KKxvWs3EbsnDvrTcs\n"
+	"mzLrTOIaedrrNXY6FsGE3+XKDCo+Z80LsrySpCozAECrEFCENMfS3ptOwI+Vblb1\n"
+	"Kar8+4+7uMxbGY/RJ/gGIKGYibkpzicCAwEAAaNkMGIwDwYDVR0TAQH/BAUwAwEB\n"
+	"/zAPBgNVHQ8BAf8EBQMDBwQAMB0GA1UdDgQWBBQwQRbMsvqKkRZUcTB+apR7e4Ll\n"
+	"1DAfBgNVHSMEGDAWgBR1lWzS3rLSrmdPPgma8JL4j1PJgzA9BgkqhkiG9w0BAQow\n"
+	"MKANMAsGCWCGSAFlAwQCAaEaMBgGCSqGSIb3DQEBCDALBglghkgBZQMEAgGiAwIB\n"
+	"MAOCAQEAnYZf5bo7ZtysyLO/3QjAM+o1IWXinH97XANEbs5oZOK/rQNLBIpOLaYp\n"
+	"YcnziJTEIqvy+7/KNwdjLcKZ4f5PBlDHBsr70XeJmMc+9/ZadY14BHZUEWNfBPx5\n"
+	"dZR55/g62CdermdCJEoY6XdIMqdTHrdwmBIS/7g/dciQt0+lrjanX14VLAVRUAIu\n"
+	"HMn5C4ZGeBDd8av3P+VIqdkFfpAYlZ5BsYqshel4pnAyhpUO5wTmY7cm78fqctyX\n"
+	"qmQ0PRLQXmlqrL2oJtlGcSWlT0u1bS0gJPpvszataCZhnX/O9x6yzzgeUpP4I/AR\n"
+	"KS4ZXRehFmQH4xS1eq5fmWiTzbvWHA==\n"
 	"-----END CERTIFICATE-----\n",
 	NULL,
 	"-----BEGIN CERTIFICATE-----\n"
-	"MIIDeTCCAjGgAwIBAgIMWXnRYxvG34hjjASYMD0GCSqGSIb3DQEBCjAwoA0wCwYJ\n"
-	"YIZIAWUDBAIBoRowGAYJKoZIhvcNAQEIMAsGCWCGSAFlAwQCAaIDAgFAMA8xDTAL\n"
-	"BgNVBAMTBENBLTAwIBcNMTcwNzI3MTE0MTIzWhgPOTk5OTEyMzEyMzU5NTlaMA8x\n"
-	"DTALBgNVBAMTBENBLTAwggFSMD0GCSqGSIb3DQEBCjAwoA0wCwYJYIZIAWUDBAIB\n"
-	"oRowGAYJKoZIhvcNAQEIMAsGCWCGSAFlAwQCAaIDAgFAA4IBDwAwggEKAoIBAQCw\n"
-	"/vJ8ccKv5ptzLvQjduQJ67JMAsizWhdkOlEy1idzXo/qjtEw6eqUJdcraF5Nzhon\n"
-	"HnXtioIvV2C3cYtauKO2rCKjlChiK59YaaeIbl521sSLRpFYhYIKkjOLHJePxHny\n"
-	"FTQEuF8b8CvrM8GsxIVZ9U+DRnxJdzhUiqxadnPpiXG/IrQRBjm/Abb8s/CG+Ny6\n"
-	"sEJBt9gDYfIfgDfbzeLu5zaPibi4N/+fYfToA7I8LXn7/AmsWAIjrY9rSOxdKJKw\n"
-	"H5C0Yd7myhtJY0EeHDl3Y3L+lwO/JkqxhRzIiZnIbxFcgeb9lZjeU94z/oi3mI7H\n"
-	"xzOk+D7IGgCkEBhfY53RAgMBAAGjQzBBMA8GA1UdEwEB/wQFMAMBAf8wDwYDVR0P\n"
-	"AQH/BAUDAwcGADAdBgNVHQ4EFgQUZ97LfvATPRiWxwNOO+sxC5ig8VkwPQYJKoZI\n"
-	"hvcNAQEKMDCgDTALBglghkgBZQMEAgGhGjAYBgkqhkiG9w0BAQgwCwYJYIZIAWUD\n"
-	"BAIBogMCAUADggEBAH3ilegUORDk8WQ7sQWFsM1L3nnfGLlHAcac+P6vLnMCkkiD\n"
-	"bpzqKEfAvEnRnZhU9vMLJkv2vUNzqIaLalPveZx98yYAxDkjGbF3PU9Eesd+JYWd\n"
-	"aJQIqpFxMDgnAXhpny6JFnMS4PWqu8NDLukEXCeeC+asweChP4TubHTJYXVRlCPL\n"
-	"Xla2fDgaG3ZKAgoUo18Hmc+Ju/17jQxgVa+SUQW9AJL+87pUoaGP1lzwrRuZl4rr\n"
-	"kmuKVjoKukJ9BYIlz6RZ/8kZZtoCd7e84DJ+zEAd0/s9w5K6lzS0gpFDi/Yo23sr\n"
-	"6L6PwffJ42OdtgXobk6AlzKU5r3iQFdu4juNNQ0=\n"
+	"MIIDgTCCAjmgAwIBAgIUUVxp7I/ecuDCjWdn2Rng+TBNidUwPQYJKoZIhvcNAQEK\n"
+	"MDCgDTALBglghkgBZQMEAgGhGjAYBgkqhkiG9w0BAQgwCwYJYIZIAWUDBAIBogMC\n"
+	"ATAwDzENMAsGA1UEAxMEQ0EtMDAgFw0xOTAyMTIyMDU0NTlaGA85OTk5MTIzMTIz\n"
+	"NTk1OVowDzENMAsGA1UEAxMEQ0EtMDCCAVIwPQYJKoZIhvcNAQEKMDCgDTALBglg\n"
+	"hkgBZQMEAgGhGjAYBgkqhkiG9w0BAQgwCwYJYIZIAWUDBAIBogMCATADggEPADCC\n"
+	"AQoCggEBAMcPAwX89KK6Nz39xdQRbSy9Ax7XzKAqtmmIczRVTKqsdQh4bm/gDuD6\n"
+	"Edxjl02cISBLczWV13brINSBI+QX/eLPyBmGGzI4ryyJuP+1qc0NMjDAlfYw+kXF\n"
+	"NZz02W6svxvrrt26mKJ1F+K/bZE+s9XHN0DW+hifQBBr8HX3BWJ9g6yj6YPd55pm\n"
+	"kQQcVgRG3BG1EMkJGK4LNesGdJGTHy+uqgtcykrMjh25uhr0oTOG6UjVYjXalZ5o\n"
+	"rOqo6CV+uGPmJYW2pBOlAOmblMMXSHXhIAhRBY8+h01BCsCU5wlEfPIsvclP2gSG\n"
+	"RVbM/9XgS/+4yN0fD+oXgi5Jh6TCYz8CAwEAAaNDMEEwDwYDVR0TAQH/BAUwAwEB\n"
+	"/zAPBgNVHQ8BAf8EBQMDBwYAMB0GA1UdDgQWBBR1lWzS3rLSrmdPPgma8JL4j1PJ\n"
+	"gzA9BgkqhkiG9w0BAQowMKANMAsGCWCGSAFlAwQCAaEaMBgGCSqGSIb3DQEBCDAL\n"
+	"BglghkgBZQMEAgGiAwIBMAOCAQEAqudvb92hfo7iAS63u902onL2XwhfS9IZtu3D\n"
+	"Lum78Q8nzhWf+YSls4/o8ln/Erv8LfrrhxoPEVpxQTPCbj/mmHez3hh+xrb0ZUVQ\n"
+	"pi5gE6kkkzzvL1VEMce85RLbm4AyVDl4onU2gaFXTxpMpKwBTZoKRbLcG2TsQgyW\n"
+	"Kgq+XnyT/1AC2vp4Ou8G1MIh5bkfetTeo2KJ3lmEVGoUh0k0diayDwaBgBDeX7hl\n"
+	"XvKrG/hhhWPVWNDXdQsiYYKVty76yM3vJiK9No1+jPZzNTv+pZaRqJiQ/ZaCICvC\n"
+	"uK/63Yrle+W/W1Jdj23/kSSL94ugw7PFwbqo2gPkECbG2Mk8pw==\n"
 	"-----END CERTIFICATE-----\n"
 };
 
@@ -4120,7 +4125,7 @@ static struct
   { "rsa pss: invalid self sig - fail", rsa_pss_invalid_self_sig, &rsa_pss_invalid_self_sig[0], GNUTLS_VERIFY_DO_NOT_ALLOW_SAME, GNUTLS_CERT_INVALID | GNUTLS_CERT_SIGNER_CONSTRAINTS_FAILURE, 0, 1501138253},
   { "rsa pss: invalid chain with pkcs#1 1.5 sig - fail", rsa_pss_invalid_chain_with_pkcs1_sig, &rsa_pss_invalid_chain_with_pkcs1_sig[2], 0, GNUTLS_CERT_INVALID | GNUTLS_CERT_SIGNER_CONSTRAINTS_FAILURE, 0, 1501138253},
   { "rsa pss: invalid chain with wrong hash (sha384-sha256) - fail", rsa_pss_invalid_chain_with_wrong_hash, &rsa_pss_invalid_chain_with_wrong_hash[3], 0, GNUTLS_CERT_INVALID | GNUTLS_CERT_SIGNER_CONSTRAINTS_FAILURE, 0, 1501138253},
-  { "rsa pss: smaller salt in sig than spki - fail", rsa_pss_chain_smaller_salt_in_sig_fail, &rsa_pss_chain_smaller_salt_in_sig_fail[3], 0, GNUTLS_CERT_INVALID | GNUTLS_CERT_SIGNER_CONSTRAINTS_FAILURE, 0, 1501159136},
+  { "rsa pss: smaller salt in sig than spki - fail", rsa_pss_chain_smaller_salt_in_sig_fail, &rsa_pss_chain_smaller_salt_in_sig_fail[3], 0, GNUTLS_CERT_INVALID | GNUTLS_CERT_SIGNER_CONSTRAINTS_FAILURE, 0, 1550005473},
   { "rsa pss: chain with sha1 hash - fail", rsa_pss_chain_with_sha1_fail, &rsa_pss_chain_with_sha1_fail[3], 0, GNUTLS_CERT_INVALID, 0, 1501159136},
   { "rsa pss: chain with different mgf hash - fail", rsa_pss_chain_with_diff_mgf_oid_fail, &rsa_pss_chain_with_diff_mgf_oid_fail[3], 0, GNUTLS_CERT_INVALID, 0, 1501159136},
   { "rsa pss: chain with sha256 - ok", rsa_pss_chain_sha256_ok, &rsa_pss_chain_sha256_ok[3], 0, 0, 0, 1501138253},
diff -NurBbp gnutls28-3.6.6/tests/testpkcs11.sh gnutls28-3.6.7/tests/testpkcs11.sh
--- gnutls28-3.6.6/tests/testpkcs11.sh	2019-01-04 07:57:36.000000000 +0100
+++ gnutls28-3.6.7/tests/testpkcs11.sh	2019-03-24 08:27:25.000000000 +0100
@@ -341,6 +341,24 @@ export_pubkey_of_privkey () {
 }
 
 # $1: token
+# $2: SO PIN
+# $3: bits
+list_pubkey_as_so () {
+	export GNUTLS_SO_PIN="$2"
+	token="$1"
+	bits="$3"
+
+	echo -n "* Exporting public key as SO... "
+	${P11TOOL} ${ADDITIONAL_PARAM} --so-login --list-all "${token}" >>"${LOGFILE}" 2>&1
+	if test $? != 0; then
+		echo failed
+		exit 1
+	fi
+
+	echo ok
+}
+
+# $1: token
 # $2: PIN
 change_id_of_privkey () {
 	export GNUTLS_PIN="$2"
@@ -599,6 +617,7 @@ write_certificate_test () {
 		exit_error
 	fi
 
+	echo ok
 	rm -f ${TMPFILE}
 
 	echo -n "* Trying to obtain back the cert... "
@@ -1091,6 +1110,7 @@ generate_rsa_privkey "${TOKEN}" "${GNUTL
 change_id_of_privkey "${TOKEN}" "${GNUTLS_PIN}"
 export_pubkey_of_privkey "${TOKEN}" "${GNUTLS_PIN}"
 change_label_of_privkey "${TOKEN}" "${GNUTLS_PIN}"
+list_pubkey_as_so "${TOKEN}" "${GNUTLS_SO_PIN}"
 
 write_certificate_test "${TOKEN}" "${GNUTLS_PIN}" "${srcdir}/testpkcs11-certs/ca.key" "${srcdir}/testpkcs11-certs/ca.crt" tmp-client.pub
 write_serv_privkey "${TOKEN}" "${GNUTLS_PIN}" "${srcdir}/testpkcs11-certs/server.key"
diff -NurBbp gnutls28-3.6.6/tests/tls12-cert-key-exchange.c gnutls28-3.6.7/tests/tls12-cert-key-exchange.c
--- gnutls28-3.6.6/tests/tls12-cert-key-exchange.c	2018-12-15 22:10:46.000000000 +0100
+++ gnutls28-3.6.7/tests/tls12-cert-key-exchange.c	2019-02-09 10:23:43.000000000 +0100
@@ -120,5 +120,35 @@ void doit(void)
 			GNUTLS_E_AGAIN, GNUTLS_E_UNWANTED_ALGORITHM,
 			&server_ca3_rsa_pss_cert, &server_ca3_rsa_pss_key, &cli_ca3_cert, &cli_ca3_key);
 
+	try_with_key_fail("TLS 1.2 with rsa encryption cert without RSA",
+			"NORMAL:-VERS-ALL:+VERS-TLS1.2:-RSA",
+			GNUTLS_E_NO_CIPHER_SUITES, GNUTLS_E_AGAIN,
+			&server_ca3_localhost_rsa_decrypt_cert, &server_ca3_key, NULL, NULL);
+
+	try_with_key_fail("TLS 1.2 with (forced) rsa encryption cert and no RSA - client should detect",
+			"NORMAL:-VERS-ALL:+VERS-TLS1.2:-RSA:%DEBUG_ALLOW_KEY_USAGE_VIOLATIONS",
+			GNUTLS_E_AGAIN, GNUTLS_E_KEY_USAGE_VIOLATION,
+			&server_ca3_localhost_rsa_decrypt_cert, &server_ca3_key, NULL, NULL);
+
+	try_with_key_fail("TLS 1.2 with client rsa encryption cert",
+			"NORMAL:-VERS-ALL:+VERS-TLS1.2",
+			GNUTLS_E_AGAIN, GNUTLS_E_KEY_USAGE_VIOLATION,
+			&server_ca3_rsa_pss_cert, &server_ca3_rsa_pss_key, &server_ca3_localhost_rsa_decrypt_cert, &server_ca3_key);
+
+	try_with_key_fail("TLS 1.2 with (forced) client rsa encryption cert - server should detect",
+			"NORMAL:-VERS-ALL:+VERS-TLS1.2:%DEBUG_ALLOW_KEY_USAGE_VIOLATIONS",
+			GNUTLS_E_KEY_USAGE_VIOLATION, GNUTLS_E_AGAIN,
+			&server_ca3_rsa_pss_cert, &server_ca3_rsa_pss_key, &server_ca3_localhost_rsa_decrypt_cert, &server_ca3_key);
+
+	try_with_rawpk_key_fail("rawpk TLS 1.2 with rsa encryption cert without KX-RSA",
+			"NORMAL:-VERS-ALL:+VERS-TLS1.2:+CTYPE-RAWPK:-RSA",
+			GNUTLS_E_NO_CIPHER_SUITES, GNUTLS_E_AGAIN,
+			&rawpk_public_key1, &rawpk_private_key1, GNUTLS_KEY_KEY_ENCIPHERMENT, NULL, NULL, 0);
+
+	try_with_rawpk_key_fail("rawpk TLS 1.2 with client rsa encryption cert without KX-RSA",
+			"NORMAL:-VERS-ALL:+VERS-TLS1.2:+CTYPE-RAWPK:-RSA",
+			GNUTLS_E_AGAIN, GNUTLS_E_KEY_USAGE_VIOLATION,
+			&rawpk_public_key2, &rawpk_private_key2, 0, &rawpk_public_key1, &rawpk_private_key1, GNUTLS_KEY_KEY_ENCIPHERMENT);
+
 	gnutls_global_deinit();
 }
diff -NurBbp gnutls28-3.6.6/tests/tls13/post-handshake-with-cert-auto.c gnutls28-3.6.7/tests/tls13/post-handshake-with-cert-auto.c
--- gnutls28-3.6.6/tests/tls13/post-handshake-with-cert-auto.c	2018-11-18 19:53:49.000000000 +0100
+++ gnutls28-3.6.7/tests/tls13/post-handshake-with-cert-auto.c	2019-04-04 19:26:55.143926305 +0200
@@ -360,7 +360,7 @@ void start(const char *name, int err, in
 void doit(void)
 {
 	start("multi-reauth", 0, GNUTLS_CERT_REQUIRE, MAX_AUTHS, 1);
-	start("reauth-require with no-cert", GNUTLS_E_NO_CERTIFICATE_FOUND, GNUTLS_CERT_REQUIRE, 1, 0);
+	start("reauth-require with no-cert", GNUTLS_E_CERTIFICATE_REQUIRED, GNUTLS_CERT_REQUIRE, 1, 0);
 	start("reauth-request with no-cert", 0, GNUTLS_CERT_REQUEST, 1, 0);
 }
 #endif				/* _WIN32 */
diff -NurBbp gnutls28-3.6.6/tests/tls13/post-handshake-with-cert.c gnutls28-3.6.7/tests/tls13/post-handshake-with-cert.c
--- gnutls28-3.6.6/tests/tls13/post-handshake-with-cert.c	2018-07-02 20:00:33.000000000 +0200
+++ gnutls28-3.6.7/tests/tls13/post-handshake-with-cert.c	2019-04-04 19:26:55.143926305 +0200
@@ -377,7 +377,7 @@ void start(const char *name, int err, in
 void doit(void)
 {
 	start("multi-reauth", 0, GNUTLS_CERT_REQUIRE, MAX_AUTHS, 1);
-	start("reauth-require with no-cert", GNUTLS_E_NO_CERTIFICATE_FOUND, GNUTLS_CERT_REQUIRE, 1, 0);
+	start("reauth-require with no-cert", GNUTLS_E_CERTIFICATE_REQUIRED, GNUTLS_CERT_REQUIRE, 1, 0);
 	start("reauth-request with no-cert", 0, GNUTLS_CERT_REQUEST, 1, 0);
 }
 #endif				/* _WIN32 */
diff -NurBbp gnutls28-3.6.6/tests/tls13/post-handshake-with-cert-ticket.c gnutls28-3.6.7/tests/tls13/post-handshake-with-cert-ticket.c
--- gnutls28-3.6.6/tests/tls13/post-handshake-with-cert-ticket.c	2018-07-13 06:26:08.000000000 +0200
+++ gnutls28-3.6.7/tests/tls13/post-handshake-with-cert-ticket.c	2019-04-04 19:26:55.143926305 +0200
@@ -47,6 +47,7 @@ int main()
 #include <signal.h>
 #include <assert.h>
 
+#include "../lib/handshake-defs.h"
 #include "cert-common.h"
 #include "utils.h"
 
@@ -75,7 +76,7 @@ static int ticket_callback(gnutls_sessio
 	assert(htype == GNUTLS_HANDSHAKE_NEW_SESSION_TICKET);
 
 	counter++;
-	if (counter == 1) /* ignore the first ticket */
+	if (counter <= TLS13_TICKETS_TO_SEND) /* ignore the default tickets sent */
 		return 0;
 
 	d = gnutls_session_get_ptr(session);
diff -NurBbp gnutls28-3.6.6/tests/tls13/post-handshake-with-psk.c gnutls28-3.6.7/tests/tls13/post-handshake-with-psk.c
--- gnutls28-3.6.6/tests/tls13/post-handshake-with-psk.c	2018-07-02 20:00:33.000000000 +0200
+++ gnutls28-3.6.7/tests/tls13/post-handshake-with-psk.c	2019-04-04 19:26:55.143926305 +0200
@@ -361,7 +361,7 @@ void start(const char *name, int err, in
 void doit(void)
 {
 	start("multi-reauth", 0, GNUTLS_CERT_REQUIRE, MAX_AUTHS, 1);
-	start("reauth-require with no-cert", GNUTLS_E_NO_CERTIFICATE_FOUND, GNUTLS_CERT_REQUIRE, 1, 0);
+	start("reauth-require with no-cert", GNUTLS_E_CERTIFICATE_REQUIRED, GNUTLS_CERT_REQUIRE, 1, 0);
 	start("reauth-request with no-cert", 0, GNUTLS_CERT_REQUEST, 1, 0);
 }
 #endif				/* _WIN32 */
diff -NurBbp gnutls28-3.6.6/tests/tls13/prf.c gnutls28-3.6.7/tests/tls13/prf.c
--- gnutls28-3.6.6/tests/tls13/prf.c	2018-11-18 19:53:49.000000000 +0100
+++ gnutls28-3.6.7/tests/tls13/prf.c	2019-04-04 19:26:55.143926305 +0200
@@ -130,10 +130,10 @@ static void dump(const char *name, const
 	} \
 	}
 
-#define KEY_EXP_VALUE "\xfb\xcb\x96\x87\x8c\x64\x8b\x60\xef\xdc\x76\xb0\x7c\x3b\xd1\x50\x1e\xb1\x3f\x39\xb2\x20\x74\x2c\xb2\x76\x12\x9f\xfc\xad\xb9\xce\x1d\x9a"
-#define HELLO_VALUE "\x61\x32\x14\x81\x9b\xa0\x43\xcd\x39\xbf\x63\x18\x7c\xb7\xf3\x02\x65\xab\x2c\xa4\xaf\xbc\x1c\x7a\x1d\xa4\xc5\x28\x8f\x45\x68"
-#define CONTEXT_VALUE "\xa7\x3c\xa7\x59\x94\x33\xb4\x97\x90\x92\x8c\xe2\x39\xda\x56\x42\x4a\xeb\xeb\xab\x73\xc4\x20\xf0\x34\x4f\xda\xf8\x17\xf5\xbd"
-#define NULL_CONTEXT_VALUE "\x66\xa1\x0a\xcb\xfa\x28\x85\x79\xa3\x30\xeb\xc5\xd5\x50\x62\xdd\xb4\x9c\xa7\x0b\x0b\xe0\x28\x03\x18\xfb\x32\x3d\x37\xf2\xe5"
+#define KEY_EXP_VALUE "\xec\x26\x9e\x8c\x5f\xff\x5c\xb2\x60\x4f\x82\xe7\x6b\xb9\x70\x40\xb9\x2d\x2f\xe7\x41\xa8\xe7\xfa\x03\x7c\xe8\x6d\xfa\xda\xc2\xa9\x3f\x58"
+#define HELLO_VALUE "\xd4\x74\x4a\x09\x28\x0a\x99\xb9\xa4\x5b\x51\x5b\x80\xe7\x50\x1c\x16\xca\x57\x78\xf0\xe5\xa1\x94\x6b\x20\x2b\x14\xff\x2b\x53"
+#define CONTEXT_VALUE "\x8d\xde\xea\x58\xab\x90\xaf\x6c\x5c\x7a\x69\xbf\x8a\xd2\x16\xb4\x0f\x75\xb8\x63\xdb\x86\xe7\x66\x04\x59\xac\x57\xe0\x03\x37"
+#define NULL_CONTEXT_VALUE "\x6c\x1a\x10\x1f\xa9\x5a\xfd\xcd\xf4\xcf\x27\x09\x00\xa8\xca\x8e\x8a\x56\xfb\x80\xf0\x0d\xb3\xa6\xe9\x4a\x5f\xe0\x0c\x31\xd9"
 static void check_prfs(gnutls_session_t session)
 {
 	unsigned char key_material[512];
diff -NurBbp gnutls28-3.6.6/tests/tls13/rnd-check-rollback-val.c gnutls28-3.6.7/tests/tls13/rnd-check-rollback-val.c
--- gnutls28-3.6.6/tests/tls13/rnd-check-rollback-val.c	2018-07-02 20:00:33.000000000 +0200
+++ gnutls28-3.6.7/tests/tls13/rnd-check-rollback-val.c	2019-04-04 19:26:55.143926305 +0200
@@ -89,6 +89,8 @@ static void client(int fd)
 	gnutls_certificate_credentials_t x509_cred;
 	gnutls_session_t session;
 	gnutls_datum_t srandom;
+	unsigned try = 0;
+	gnutls_datum_t session_data = { NULL, 0 };
 
 	global_init();
 
@@ -102,6 +104,7 @@ static void client(int fd)
 					    &cli_ca3_key,
 					    GNUTLS_X509_FMT_PEM);
 
+ retry:
 	/* Initialize TLS session
 	 */
 	gnutls_init(&session, GNUTLS_CLIENT);
@@ -112,6 +115,9 @@ static void client(int fd)
 	if (ret < 0)
 		fail("cannot set TLS priorities\n");
 
+	if (try > 0)
+		gnutls_session_set_data(session, session_data.data, session_data.size);
+
 	/* put the anonymous credentials to the current session
 	 */
 	gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, x509_cred);
@@ -129,6 +135,9 @@ static void client(int fd)
 		fail("error in handshake: %s\n", gnutls_strerror(ret));
 	}
 
+	if (try > 0)
+		assert(gnutls_session_is_resumed(session));
+
 	gnutls_session_get_random(session, NULL, &srandom);
 
 	if (srandom.size != 32)
@@ -147,10 +156,28 @@ static void client(int fd)
 		fail("unexpected random data for %s\n", name);
 	}
 
-	close(fd);
+	do {
+		ret = gnutls_record_send(session, "\x00", 1);
+	} while (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
+
+	if (try == 0) {
+		ret = gnutls_session_get_data2(session, &session_data);
+		if (ret < 0)
+			fail("couldn't retrieve session data: %s\n",
+			     gnutls_strerror(ret));
+	}
 
 	gnutls_deinit(session);
 
+	if (try == 0) {
+		try++;
+		goto retry;
+	}
+
+	close(fd);
+
+	gnutls_free(session_data.data);
+
 	gnutls_certificate_free_credentials(x509_cred);
 
 	gnutls_global_deinit();
@@ -162,6 +189,9 @@ static void server(int fd)
 	int ret;
 	gnutls_session_t session;
 	gnutls_certificate_credentials_t x509_cred;
+	gnutls_datum_t skey;
+	unsigned try = 0;
+	unsigned char buf[16];
 
 	/* this must be called once in the program
 	 */
@@ -177,6 +207,9 @@ static void server(int fd)
 					    &server_key,
 					    GNUTLS_X509_FMT_PEM);
 
+	assert(gnutls_session_ticket_key_generate(&skey) >= 0);
+
+ retry:
 	gnutls_init(&session, GNUTLS_SERVER);
 
 	gnutls_handshake_set_timeout(session, 20 * 1000);
@@ -185,6 +218,8 @@ static void server(int fd)
 
 	gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, x509_cred);
 
+	assert(gnutls_session_ticket_enable_server(session, &skey) >= 0);
+
 	gnutls_transport_set_int(session, fd);
 
 	do {
@@ -197,9 +232,26 @@ static void server(int fd)
 	if (ret < 0)
 		fail("error in handshake: %s\n", gnutls_strerror(ret));
 
-	close(fd);
+	if (try > 0)
+		assert(gnutls_session_is_resumed(session));
+
+	do {
+		ret = gnutls_record_recv(session, buf, sizeof(buf));
+	} while (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
+
+	if (ret < 0)
+		fail("server: recv did not succeed as expected: %s\n", gnutls_strerror(ret));
+
 	gnutls_deinit(session);
 
+	if (try == 0) {
+		try++;
+		goto retry;
+	}
+
+	close(fd);
+
+	gnutls_free(skey.data);
 	gnutls_certificate_free_credentials(x509_cred);
 
 	gnutls_global_deinit();
diff -NurBbp gnutls28-3.6.6/tests/tls13-cert-key-exchange.c gnutls28-3.6.7/tests/tls13-cert-key-exchange.c
--- gnutls28-3.6.6/tests/tls13-cert-key-exchange.c	2018-12-15 22:10:46.000000000 +0100
+++ gnutls28-3.6.7/tests/tls13-cert-key-exchange.c	2019-04-04 19:26:55.143926305 +0200
@@ -138,5 +138,48 @@ void doit(void)
 			GNUTLS_E_AGAIN, GNUTLS_E_INCOMPATIBLE_SIG_WITH_KEY,
 			&server_ca3_rsa_pss_cert, &server_ca3_rsa_pss_key, &cli_ca3_cert, &cli_ca3_key);
 
+	try_with_key_fail("TLS 1.3 with rsa encryption cert",
+			"NORMAL:-VERS-ALL:+VERS-TLS1.3",
+			GNUTLS_E_NO_CIPHER_SUITES, GNUTLS_E_AGAIN,
+			&server_ca3_localhost_rsa_decrypt_cert, &server_ca3_key, NULL, NULL);
+
+	try_with_key_fail("TLS 1.3 and TLS 1.2 with rsa encryption cert",
+			"NORMAL:-VERS-ALL:+VERS-TLS1.3:+VERS-TLS1.2",
+			GNUTLS_E_SUCCESS, GNUTLS_E_SUCCESS,
+			&server_ca3_localhost_rsa_decrypt_cert, &server_ca3_key, NULL, NULL);
+
+	try_with_key_fail("TLS 1.3 with (forced) rsa encryption cert - client should detect",
+			"NORMAL:-VERS-ALL:+VERS-TLS1.3:%DEBUG_ALLOW_KEY_USAGE_VIOLATIONS",
+			GNUTLS_E_AGAIN, GNUTLS_E_KEY_USAGE_VIOLATION,
+			&server_ca3_localhost_rsa_decrypt_cert, &server_ca3_key, NULL, NULL);
+
+	try_with_key_fail("TLS 1.3 with client rsa encryption cert",
+			"NORMAL:-VERS-ALL:+VERS-TLS1.3",
+			GNUTLS_E_AGAIN, GNUTLS_E_INSUFFICIENT_CREDENTIALS,
+			&server_ca3_rsa_pss_cert, &server_ca3_rsa_pss_key, &server_ca3_localhost_rsa_decrypt_cert, &server_ca3_key);
+
+	try_with_key_fail("TLS 1.3 with (forced) client rsa encryption cert - server should detect",
+			"NORMAL:-VERS-ALL:+VERS-TLS1.3:%DEBUG_ALLOW_KEY_USAGE_VIOLATIONS",
+			GNUTLS_E_KEY_USAGE_VIOLATION, GNUTLS_E_SUCCESS,
+			&server_ca3_rsa_pss_cert, &server_ca3_rsa_pss_key, &server_ca3_localhost_rsa_decrypt_cert, &server_ca3_key);
+
+	try_with_rawpk_key_fail("rawpk TLS 1.3 with rsa encryption cert",
+			"NORMAL:-VERS-ALL:+VERS-TLS1.3:+CTYPE-RAWPK",
+			GNUTLS_E_NO_CIPHER_SUITES, GNUTLS_E_AGAIN,
+			&rawpk_public_key1, &rawpk_private_key1, GNUTLS_KEY_KEY_ENCIPHERMENT, NULL, NULL, 0);
+
+	try_with_rawpk_key_fail("rawpk TLS 1.3 and TLS 1.2 with rsa encryption cert",
+			"NORMAL:-VERS-ALL:+VERS-TLS1.3:+VERS-TLS1.2:+CTYPE-RAWPK",
+			GNUTLS_E_SUCCESS, GNUTLS_E_SUCCESS,
+			&rawpk_public_key1, &rawpk_private_key1, GNUTLS_KEY_KEY_ENCIPHERMENT, NULL, NULL, 0);
+
+	try_with_rawpk_key_fail("rawpk TLS 1.3 with client rsa encryption cert",
+			"NORMAL:-VERS-ALL:+VERS-TLS1.3:+CTYPE-RAWPK",
+			GNUTLS_E_AGAIN, GNUTLS_E_INSUFFICIENT_CREDENTIALS,
+			&rawpk_public_key2, &rawpk_private_key2, 0, &rawpk_public_key1, &rawpk_private_key1, GNUTLS_KEY_KEY_ENCIPHERMENT);
+
+	/* we do not test TLS 1.3 with (forced) rsa encryption cert - client should detect, because
+	 * there is no way under raw public keys for the client or server  to know the intended type. */
+
 	gnutls_global_deinit();
 }
diff -NurBbp gnutls28-3.6.6/tests/tls-pthread.c gnutls28-3.6.7/tests/tls-pthread.c
--- gnutls28-3.6.6/tests/tls-pthread.c	1970-01-01 01:00:00.000000000 +0100
+++ gnutls28-3.6.7/tests/tls-pthread.c	2019-03-08 20:15:32.000000000 +0100
@@ -0,0 +1,388 @@
+/*
+ * Copyright (C) 2019 Nikos Mavrogiannopoulos
+ *
+ * Author: Nikos Mavrogiannopoulos
+ *
+ * This file is part of GnuTLS.
+ *
+ * GnuTLS is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuTLS is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GnuTLS; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <errno.h>
+#include <gnutls/gnutls.h>
+#include <gnutls/dtls.h>
+#include <signal.h>
+#include <unistd.h>
+#ifndef _WIN32
+# include <netinet/in.h>
+# include <sys/types.h>
+# include <sys/socket.h>
+# include <sys/wait.h>
+# include <pthread.h>
+#endif
+#include <assert.h>
+#include "utils.h"
+#include "cert-common.h"
+
+#define FLAG_CLI_DO_THREADS 1
+#define FLAG_FALSE_START 2
+#define FLAG_EARLY_START 4
+
+#ifdef _WIN32
+
+void doit(void)
+{
+	exit(77);
+}
+
+#else
+
+/* Tests whether we can send and receive from different threads
+ * using DTLS, either as server or client. DTLS is a superset of
+ * TLS, so correct behavior under fork means TLS would operate too.
+ */
+
+const char *side = "";
+
+static void tls_log_func(int level, const char *str)
+{
+	fprintf(stderr, "%s|<%d>| %s", side, level, str);
+}
+
+#define MSG "hello1111"
+#define MSG2 "xxxxxxxxxxxx"
+
+#define NO_MSGS 128
+
+static void *recv_thread(void *arg)
+{
+	gnutls_session_t session = arg;
+	int ret;
+	unsigned i;
+	char buf[64];
+
+	if (debug)
+		success("client: TLS version is: %s\n",
+			gnutls_protocol_get_name
+			(gnutls_protocol_get_version(session)));
+
+	for (i=0;i<NO_MSGS;i++) {
+		/* the peer should reflect our messages */
+		do {
+			ret = gnutls_record_recv(session, buf, sizeof(buf));
+		} while(ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
+		if (ret < 0)
+			fail("client: recv failed: %s\n", gnutls_strerror(ret));
+		if (ret != sizeof(MSG)-1 || memcmp(buf, MSG, sizeof(MSG)-1) != 0) {
+			fail("client: recv failed; not the expected values (got: %d, exp: %d)\n", ret, (int)sizeof(MSG)-1);
+		}
+
+		if (debug)
+			success("%d: client received: %.*s\n", i, ret, buf);
+	}
+
+	/* final MSG is MSG2 */
+	do {
+		ret = gnutls_record_recv(session, buf, sizeof(buf));
+	} while(ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
+	if (ret < 0)
+		fail("client: recv2 failed: %s\n", gnutls_strerror(ret));
+
+	if (ret != sizeof(MSG2)-1 || memcmp(buf, MSG2, sizeof(MSG2)-1) != 0) {
+		fail("client: recv2 failed; not the expected values\n");
+	}
+
+	do {
+		ret = gnutls_record_recv(session, buf, sizeof(buf));
+	} while(ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
+	if (ret != 0)
+		fail("client: no EOF: %d\n", ret);
+
+	if (debug) {
+		success("client received: %.*s\n", ret, buf);
+		success("closing recv thread\n");
+	}
+
+	pthread_exit(0);
+}
+
+static
+void do_thread_stuff(gnutls_session_t session)
+{
+	int ret;
+	unsigned i;
+	pthread_t id;
+	void *rval;
+
+	sec_sleep(1);
+	/* separate sending from receiving */
+	ret = pthread_create(&id, NULL, recv_thread, session);
+	if (ret != 0) {
+		fail("error in pthread_create\n");
+	}
+
+	for (i=0;i<NO_MSGS;i++) {
+		do {
+			ret = gnutls_record_send(session, MSG, sizeof(MSG)-1);
+		} while(ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
+		if (ret != sizeof(MSG)-1) {
+			fail("client: send failed: %s\n", gnutls_strerror(ret));
+		}
+	}
+
+	do {
+		ret = gnutls_record_send(session, MSG2, sizeof(MSG2)-1);
+	} while(ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
+	if (ret != sizeof(MSG2)-1) {
+		fail("client: send2 failed: %s\n", gnutls_strerror(ret));
+	}
+
+	if (debug)
+		success("closing sending thread\n");
+
+	do {
+		ret = gnutls_bye(session, GNUTLS_SHUT_WR);
+	} while(ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
+
+	/* the receiving thread will receive the EOF and close */
+
+	assert(pthread_join(id, &rval)==0);
+	assert(rval == 0);
+
+}
+
+static void do_reflect_stuff(gnutls_session_t session)
+{
+	char buf[64];
+	unsigned buf_size;
+	int ret;
+
+	do {
+		do {
+			ret = gnutls_record_recv(session, buf, sizeof(buf));
+		} while(ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
+		if (ret < 0) {
+			fail("server: recv failed: %s\n", gnutls_strerror(ret));
+		}
+
+		if (ret == 0) {
+			break;
+		}
+
+		buf_size = ret;
+		if (debug) {
+			success("server received: %.*s\n", buf_size, buf);
+		}
+
+		do {
+			ret = gnutls_record_send(session, buf, buf_size);
+		} while(ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
+		if (ret < 0) {
+			fail("server: send failed: %s\n", gnutls_strerror(ret));
+		}
+		if (debug)
+			success("reflected %d\n", ret);
+	} while(1);
+
+	do {
+		gnutls_bye(session, GNUTLS_SHUT_WR);
+	} while(ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
+}
+
+static void client(int fd, const char *prio, unsigned flags)
+{
+	int ret;
+	gnutls_certificate_credentials_t x509_cred;
+	gnutls_session_t session;
+	unsigned init_flags = GNUTLS_CLIENT;
+
+	global_init();
+
+	if (debug) {
+		side = "client";
+		gnutls_global_set_log_function(tls_log_func);
+		gnutls_global_set_log_level(4711);
+	}
+
+	assert(gnutls_certificate_allocate_credentials(&x509_cred)>=0);
+
+	if (flags & FLAG_FALSE_START)
+		init_flags |= GNUTLS_ENABLE_FALSE_START;
+
+	assert(gnutls_init(&session, init_flags) >= 0);
+	gnutls_handshake_set_timeout(session, 60 * 1000);
+
+	assert(gnutls_priority_set_direct(session, prio, NULL)>=0);
+
+	assert(gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, x509_cred)>=0);
+
+	gnutls_transport_set_int(session, fd);
+
+	/* Perform the TLS handshake
+	 */
+	do {
+		ret = gnutls_handshake(session);
+	}
+	while (ret < 0 && gnutls_error_is_fatal(ret) == 0);
+
+	if (ret < 0) {
+		fail("client: Handshake failed: %s\n", gnutls_strerror(ret));
+	} else {
+		if (debug)
+			success("client: Handshake was completed\n");
+	}
+
+	if (flags & FLAG_CLI_DO_THREADS)
+		do_thread_stuff(session);
+	else
+		do_reflect_stuff(session);
+
+	close(fd);
+
+	gnutls_deinit(session);
+
+	gnutls_certificate_free_credentials(x509_cred);
+
+	gnutls_global_deinit();
+}
+
+static void server(int fd, const char *prio, unsigned flags)
+{
+	int ret;
+	gnutls_certificate_credentials_t x509_cred;
+	gnutls_session_t session;
+	unsigned init_flags = GNUTLS_SERVER;
+
+	/* this must be called once in the program
+	 */
+	global_init();
+
+#if 0
+	if (debug) {
+		side = "server";
+		gnutls_global_set_log_function(tls_log_func);
+		gnutls_global_set_log_level(4711);
+	}
+#endif
+
+	assert(gnutls_certificate_allocate_credentials(&x509_cred)>=0);
+	assert(gnutls_certificate_set_x509_key_mem(x509_cred, &server_cert,
+					    &server_key,
+					    GNUTLS_X509_FMT_PEM)>=0);
+
+	if (flags & FLAG_EARLY_START)
+		init_flags |= GNUTLS_ENABLE_EARLY_START;
+
+	assert(gnutls_init(&session, init_flags)>=0);
+	gnutls_handshake_set_timeout(session, 60 * 1000);
+
+	assert(gnutls_priority_set_direct(session, prio, NULL)>=0);
+
+	gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, x509_cred);
+
+	gnutls_transport_set_int(session, fd);
+
+	do {
+		ret = gnutls_handshake(session);
+	} while (ret < 0 && gnutls_error_is_fatal(ret) == 0);
+	if (ret < 0) {
+		close(fd);
+		gnutls_deinit(session);
+		fail("server: Handshake has failed (%s)\n\n",
+		     gnutls_strerror(ret));
+	}
+	if (debug)
+		success("server: Handshake was completed\n");
+
+	if (debug)
+		success("server: TLS version is: %s\n",
+			gnutls_protocol_get_name
+			(gnutls_protocol_get_version(session)));
+
+	if (flags & FLAG_CLI_DO_THREADS)
+		do_reflect_stuff(session);
+	else
+		do_thread_stuff(session);
+
+
+	close(fd);
+	gnutls_deinit(session);
+
+	gnutls_certificate_free_credentials(x509_cred);
+
+	gnutls_global_deinit();
+
+	if (debug)
+		success("server: finished\n");
+}
+
+static
+void run(const char *str, const char *prio, unsigned flags)
+{
+	int fd[2];
+	int ret;
+	pid_t child;
+
+	if (str)
+		success("running %s\n", str);
+
+	ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fd);
+	if (ret < 0) {
+		perror("socketpair");
+		exit(1);
+	}
+
+	child = fork();
+	if (child < 0) {
+		perror("fork");
+		fail("fork");
+	}
+
+	if (child) {
+		int status;
+		/* parent */
+
+		close(fd[1]);
+		client(fd[0], prio, flags);
+		wait(&status);
+		check_wait_status(status);
+	} else {
+		close(fd[0]);
+		server(fd[1], prio, flags);
+		exit(0);
+	}
+}
+
+void doit(void)
+{
+	signal(SIGPIPE, SIG_IGN);
+	run("default, threaded client", "NORMAL", FLAG_CLI_DO_THREADS);
+	run("default, threaded server", "NORMAL", 0);
+	run("tls1.2, threaded client", "NORMAL:-VERS-TLS-ALL:+VERS-TLS1.2", FLAG_CLI_DO_THREADS);
+	run("tls1.2, threaded server", "NORMAL:-VERS-TLS-ALL:+VERS-TLS1.2", 0);
+	run("tls1.2 false start, threaded client", "NORMAL:-VERS-TLS-ALL:+VERS-TLS1.2", FLAG_CLI_DO_THREADS|FLAG_FALSE_START);
+	run("tls1.2 false start, threaded server", "NORMAL:-VERS-TLS-ALL:+VERS-TLS1.2", FLAG_FALSE_START);
+	run("tls1.3 early start, threaded client", "NORMAL:-VERS-TLS-ALL:+VERS-TLS1.3", FLAG_CLI_DO_THREADS|FLAG_EARLY_START);
+	run("tls1.3 early start, threaded server", "NORMAL:-VERS-TLS-ALL:+VERS-TLS1.3", FLAG_EARLY_START);
+}
+#endif				/* _WIN32 */
diff -NurBbp gnutls28-3.6.6/tests/tls-record-size-limit.c gnutls28-3.6.7/tests/tls-record-size-limit.c
--- gnutls28-3.6.6/tests/tls-record-size-limit.c	2018-11-18 19:53:49.000000000 +0100
+++ gnutls28-3.6.7/tests/tls-record-size-limit.c	2019-02-23 18:48:28.000000000 +0100
@@ -52,9 +52,10 @@
 
 #define HANDSHAKE_SESSION_ID_POS 34
 
-static size_t max_record_size;
+static size_t server_max_send_size;
+static size_t client_max_send_size;
 
-#define SERVER_PUSH_ADD if (len > max_record_size + 5+32) fail("max record set to %d, len: %d\n", (int)max_record_size, (int)len);
+#define SERVER_PUSH_ADD if (len > server_max_send_size + 5+32) fail("max record set to %d, len: %d\n", (int)server_max_send_size, (int)len);
 #include "eagain-common.h"
 
 #include "cert-common.h"
@@ -136,22 +137,23 @@ static int handshake_callback(gnutls_ses
 #define MAX_BUF 16384
 static char buffer[MAX_BUF];
 
-struct test_ext_st {
+struct test_exp_st {
+	int error;
+	size_t size;
 	bool max_record_size;
 	bool record_size_limit;
 };
 
 struct test_st {
 	const char *prio;
-	size_t max_size;
+	size_t server_max_size;
+	size_t client_max_size;
 
-	int expect_error;
-	size_t expect_size;
-	struct test_ext_st expect_server_ext;
-	struct test_ext_st expect_client_ext;
+	struct test_exp_st server_exp;
+	struct test_exp_st client_exp;
 };
 
-static void check_exts(const struct test_ext_st *exp,
+static void check_exts(const struct test_exp_st *exp,
 		       struct handshake_cb_data_st *data)
 {
 	if (exp->max_record_size && !data->found_max_record_size)
@@ -198,6 +200,15 @@ static void start(const struct test_st *
 				serverx509cred);
 
 	gnutls_priority_set_direct(server, test->prio, NULL);
+
+	ret = gnutls_record_set_max_size(server, test->server_max_size);
+	if (ret != test->server_exp.error)
+		fail("server: unexpected error from gnutls_record_set_max_size()");
+	if (ret == 0)
+		server_max_send_size = test->server_max_size;
+	else
+		server_max_send_size = MAX_BUF;
+
 	gnutls_transport_set_push_function(server, server_push);
 	gnutls_transport_set_pull_function(server, server_pull);
 	gnutls_transport_set_pull_timeout_function(server,
@@ -233,13 +244,13 @@ static void start(const struct test_st *
 	if (ret < 0)
 		exit(1);
 
-	ret = gnutls_record_set_max_size(client, test->max_size);
-	if (ret != test->expect_error)
-		fail("unexpected error from gnutls_record_set_max_size()");
+	ret = gnutls_record_set_max_size(client, test->client_max_size);
+	if (ret != test->client_exp.error)
+		fail("client: unexpected error from gnutls_record_set_max_size()");
 	if (ret == 0)
-		max_record_size = test->max_size;
+		client_max_send_size = test->client_max_size;
 	else
-		max_record_size = MAX_BUF;
+		client_max_send_size = MAX_BUF;
 
 	gnutls_transport_set_push_function(client, client_push);
 	gnutls_transport_set_pull_function(client, client_pull);
@@ -256,22 +267,39 @@ static void start(const struct test_st *
 	HANDSHAKE(client, server);
 
 	memset(buffer, 1, sizeof(buffer));
-	ret = gnutls_record_send(server, buffer, max_record_size + 1);
+	ret = gnutls_record_send(server, buffer, server_max_send_size + 1);
+	if (ret < 0) {
+		gnutls_perror(ret);
+		exit(1);
+	}
+	if (ret != (int)test->server_exp.size)
+		fail("server: unexpected record size sent: %d (%d)\n",
+		     ret, (int)test->server_exp.size);
+	success("server: did not send a %d-byte packet\n", (int)server_max_send_size + 1);
+
+	ret = gnutls_record_send(server, buffer, server_max_send_size);
 	if (ret < 0) {
 		gnutls_perror(ret);
 		exit(1);
 	}
-	if (ret != (int)test->expect_size)
-		fail("unexpected record size sent: %d (%d)\n",
-		     ret, (int)test->expect_size);
-	success("did not send a %d-byte packet\n", (int)max_record_size + 1);
+	success("server: did send a %d-byte packet\n", (int)server_max_send_size);
 
-	ret = gnutls_record_send(server, buffer, max_record_size);
+	ret = gnutls_record_send(client, buffer, client_max_send_size + 1);
 	if (ret < 0) {
 		gnutls_perror(ret);
 		exit(1);
 	}
-	success("did send a %d-byte packet\n", (int)max_record_size);
+	if (ret != (int)test->client_exp.size)
+		fail("client: unexpected record size sent: %d (%d)\n",
+		     ret, (int)test->client_exp.size);
+	success("client: did not send a %d-byte packet\n", (int)client_max_send_size + 1);
+
+	ret = gnutls_record_send(client, buffer, client_max_send_size);
+	if (ret < 0) {
+		gnutls_perror(ret);
+		exit(1);
+	}
+	success("client: did send a %d-byte packet\n", (int)client_max_send_size);
 
 	gnutls_bye(client, GNUTLS_SHUT_RDWR);
 	gnutls_bye(server, GNUTLS_SHUT_RDWR);
@@ -286,79 +314,94 @@ static void start(const struct test_st *
 
 	reset_buffers();
 
-	check_exts(&test->expect_server_ext,
+	check_exts(&test->server_exp,
 		   &server_handshake_cb_data);
-	check_exts(&test->expect_client_ext,
+	check_exts(&test->client_exp,
 		   &client_handshake_cb_data);
 }
 
 static const struct test_st tests[] = {
 	{
 		.prio = "NORMAL:-VERS-ALL:+VERS-TLS1.2",
-		.max_size = 511,
-		.expect_error = GNUTLS_E_INVALID_REQUEST,
-		.expect_size = 16384,
-		.expect_server_ext = {
+		.server_max_size = 511,
+		.client_max_size = 511,
+		.server_exp = {
+			.error = GNUTLS_E_INVALID_REQUEST,
+			.size = 16384,
 			.max_record_size = 0,
 			.record_size_limit = 1
 		},
-		.expect_client_ext = {
+		.client_exp = {
+			.error = GNUTLS_E_INVALID_REQUEST,
+			.size = 16384,
 			.max_record_size = 0,
 			.record_size_limit = 1
 		}
 	},
 	{
 		.prio = "NORMAL:-VERS-ALL:+VERS-TLS1.2",
-		.max_size = 512,
-		.expect_error = 0,
-		.expect_size = 512,
-		.expect_server_ext = {
+		.server_max_size = 512,
+		.client_max_size = 512,
+		.server_exp = {
+			.error = 0,
+			.size = 512,
 			.max_record_size = 1,
 			.record_size_limit = 1
 		},
-		.expect_client_ext = {
+		.client_exp = {
+			.error = 0,
+			.size = 512,
 			.max_record_size = 0,
 			.record_size_limit = 1
 		}
 	},
 	{
 		.prio = "NORMAL:-VERS-ALL:+VERS-TLS1.2",
-		.max_size = 8192,
-		.expect_error = 0,
-		.expect_size = 8192,
-		.expect_server_ext = {
+		.server_max_size = 8192,
+		.client_max_size = 8192,
+		.server_exp = {
+			.error = 0,
+			.size = 8192,
 			.max_record_size = 0,
 			.record_size_limit = 1
 		},
-		.expect_client_ext = {
+		.client_exp = {
+			.error = 0,
+			.size = 8192,
 			.max_record_size = 0,
 			.record_size_limit = 1
 		}
 	},
 	{
 		.prio = "NORMAL:-VERS-ALL:+VERS-TLS1.2",
-		.max_size = 16384,
-		.expect_error = 0,
-		.expect_size = 16384,
-		.expect_server_ext = {
+		.server_max_size = 16384,
+		.client_max_size = 16384,
+		.server_exp = {
+			.error = 0,
+			.size = 16384,
 			.max_record_size = 0,
 			.record_size_limit = 1
 		},
-		.expect_client_ext = {
+		.client_exp = {
+			.error = 0,
+			.size = 16384,
 			.max_record_size = 0,
 			.record_size_limit = 1
 		}
 	},
 	{
 		.prio = "NORMAL:-VERS-ALL:+VERS-TLS1.2",
-		.max_size = 16385,
-		.expect_error = GNUTLS_E_INVALID_REQUEST,
-		.expect_size = 16384,
-		.expect_server_ext = {
+		.server_max_size = 16385,
+		.client_max_size = 16385,
+		.server_exp = {
+			.error = GNUTLS_E_INVALID_REQUEST,
+			.size = 16384,
 			.max_record_size = 0,
 			.record_size_limit = 1
 		},
-		.expect_client_ext = {
+		.client_exp = {
+			.error = GNUTLS_E_INVALID_REQUEST,
+			.size = 16384,
 			.max_record_size = 0,
 			.record_size_limit = 1
 		}
@@ -366,70 +409,102 @@ static const struct test_st tests[] = {
 
 	{
 		.prio = "NORMAL:-VERS-ALL:+VERS-TLS1.3",
-		.max_size = 511,
-		.expect_error = GNUTLS_E_INVALID_REQUEST,
-		.expect_size = 16384,
-		.expect_server_ext = {
+		.server_max_size = 511,
+		.client_max_size = 511,
+		.server_exp = {
+			.error = GNUTLS_E_INVALID_REQUEST,
+			.size = 16384,
 			.max_record_size = 0,
 			.record_size_limit = 1
 		},
-		.expect_client_ext = {
+		.client_exp = {
+			.error = GNUTLS_E_INVALID_REQUEST,
+			.size = 16384,
 			.max_record_size = 0,
 			.record_size_limit = 1
 		}
 		},
 	{
 		.prio = "NORMAL:-VERS-ALL:+VERS-TLS1.3",
-		.max_size = 512,
-		.expect_error = 0,
-		.expect_size = 512,
-		.expect_server_ext = {
+		.server_max_size = 512,
+		.client_max_size = 512,
+		.server_exp = {
+			.error = 0,
+			.size = 512,
 			.max_record_size = 1,
 			.record_size_limit = 1
 		},
-		.expect_client_ext = {
+		.client_exp = {
+			.error = 0,
+			.size = 512,
+			.max_record_size = 0,
+			.record_size_limit = 1
+		}
+	},
+	{
+		.prio = "NORMAL:-VERS-ALL:+VERS-TLS1.3",
+		.server_max_size = 8192,
+		.client_max_size = 8192,
+		.server_exp = {
+			.error = 0,
+			.size = 8192,
+			.max_record_size = 0,
+			.record_size_limit = 1
+		},
+		.client_exp = {
+			.error = 0,
+			.size = 8192,
 			.max_record_size = 0,
 			.record_size_limit = 1
 		}
 	},
 	{
 		.prio = "NORMAL:-VERS-ALL:+VERS-TLS1.3",
-		.max_size = 8192,
-		.expect_error = 0,
-		.expect_size = 8192,
-		.expect_server_ext = {
+		.server_max_size = 16384,
+		.client_max_size = 16384,
+		.server_exp = {
+			.error = 0,
+			.size = 16384,
 			.max_record_size = 0,
 			.record_size_limit = 1
 		},
-		.expect_client_ext = {
+		.client_exp = {
+			.error = 0,
+			.size = 16384,
 			.max_record_size = 0,
 			.record_size_limit = 1
 		}
 	},
 	{
 		.prio = "NORMAL:-VERS-ALL:+VERS-TLS1.3",
-		.max_size = 16384,
-		.expect_error = 0,
-		.expect_size = 16384,
-		.expect_server_ext = {
+		.server_max_size = 16383,
+		.client_max_size = 16384,
+		.server_exp = {
+			.error = 0,
+			.size = 16383,
 			.max_record_size = 0,
 			.record_size_limit = 1
 		},
-		.expect_client_ext = {
+		.client_exp = {
+			.error = 0,
+			.size = 16383,
 			.max_record_size = 0,
 			.record_size_limit = 1
 		}
 	},
 	{
 		.prio = "NORMAL:-VERS-ALL:+VERS-TLS1.3",
-		.max_size = 16385,
-		.expect_error = GNUTLS_E_INVALID_REQUEST,
-		.expect_size = 16384,
-		.expect_server_ext = {
+		.server_max_size = 16385,
+		.client_max_size = 16385,
+		.server_exp = {
+			.error = GNUTLS_E_INVALID_REQUEST,
+			.size = 16384,
 			.max_record_size = 0,
 			.record_size_limit = 1
 		},
-		.expect_client_ext = {
+		.client_exp = {
+			.error = GNUTLS_E_INVALID_REQUEST,
+			.size = 16384,
 			.max_record_size = 0,
 			.record_size_limit = 1
 		}
diff -NurBbp gnutls28-3.6.6/tests/x509-extensions.c gnutls28-3.6.7/tests/x509-extensions.c
--- gnutls28-3.6.6/tests/x509-extensions.c	2016-11-05 19:12:02.000000000 +0100
+++ gnutls28-3.6.7/tests/x509-extensions.c	2019-02-25 19:14:55.000000000 +0100
@@ -767,7 +767,6 @@ void doit(void)
 			}
 		}
 		gnutls_free(ext.data);
-		ext.data = NULL;
 	}
 
 	if (debug)
diff -NurBbp gnutls28-3.6.6/tests/x509sign-verify-error.c gnutls28-3.6.7/tests/x509sign-verify-error.c
--- gnutls28-3.6.6/tests/x509sign-verify-error.c	2017-04-19 21:49:27.000000000 +0200
+++ gnutls28-3.6.7/tests/x509sign-verify-error.c	2019-02-25 19:14:55.000000000 +0100
@@ -181,7 +181,6 @@ void doit(void)
 			fail("gnutls_privkey_sign_hash\n");
 
 		gnutls_free(signature2.data);
-		signature2.data = NULL;
 
 		_gnutls_lib_simulate_error();
 		ret = gnutls_privkey_sign_hash(privkey, GNUTLS_DIG_SHA1, 0,
