Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/configs/os-check-linux.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
{"name": "all-static", "minutes": 8,
"comment": "Static-only build, so configure defines WOLFSSL_TEST_STATIC_BUILD and the tests that call WOLFSSL_LOCAL functions directly are compiled and run.",
"configure": ["--enable-all", "--enable-static", "--disable-shared"]},
{"name": "record-size-limit",
"comment": "RFC 8449 on its own. --enable-all covers it alongside everything else; this is the minimal build, which is where the extension's own guards get exercised.",
"configure": ["--enable-recordsizelimit"]},
{"name": "record-size-limit-tls12",
"comment": "RFC 8449 defines the extension for TLS 1.2 too, where the server answers in the ServerHello. Guards the parse dispatch staying outside the WOLFSSL_TLS13 block.",
"configure": ["--enable-recordsizelimit", "--disable-tls13"]},
{"name": "record-size-limit-libz",
"comment": "RFC 8449 alongside TLS record layer compression. Both are built, and each connection uses at most one: wolfSSL_set_compression() and wolfSSL_UseRecordSizeLimit() refuse each other, so this is where that pairing gets exercised.",
"configure": ["--enable-recordsizelimit", "--with-libz"]},
{"name": "user-settings-all-compat", "minutes": 9.5,
"comment": "user_settings_all.h with the compatibility layer enabled by flipping its \"#if 0\" block, as a build-dir copy.",
"user_settings": "examples/configs/user_settings_all.h",
Expand Down
20 changes: 18 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ if(WOLFSSL_ALL)
WOLFSSL_OCSPSTAPLING WOLFSSL_OCSPSTAPLING_V2 WOLFSSL_OPENSSLALL
WOLFSSL_OPENSSLEXTRA WOLFSSL_POSTAUTH WOLFSSL_QUIC WOLFSSL_SAVECERT
WOLFSSL_SAVESESSION WOLFSSL_SCEP WOLFSSL_SESSION_TICKET WOLFSSL_SNI
WOLFSSL_SRTP WOLFSSL_TLS13)
WOLFSSL_SRTP WOLFSSL_TLS13 WOLFSSL_RECORDSIZELIMIT)
default_option(${_o} "yes")
endforeach()

Expand Down Expand Up @@ -857,7 +857,7 @@ if(WOLFSSL_CRYPT_ONLY)
WOLFSSL_PKCALLBACKS WOLFSSL_QUIC
WOLFSSL_RENEGOTIATION_INDICATION WOLFSSL_SECURE_RENEGOTIATION
WOLFSSL_SECURE_RENEGOTIATION_INFO
WOLFSSL_SNI WOLFSSL_SRTP WOLFSSL_TLSX)
WOLFSSL_SNI WOLFSSL_SRTP WOLFSSL_TLSX WOLFSSL_RECORDSIZELIMIT)
force_option(${_o} "no")
endforeach()
message(STATUS "WOLFSSL_CRYPT_ONLY: TLS layer off, including its options")
Expand Down Expand Up @@ -2234,6 +2234,9 @@ add_option("WOLFSSL_TLS" "Enable TLS (default: enabled)" "yes" "yes;no")
if(NOT WOLFSSL_TLS)
list(APPEND WOLFSSL_DEFINITIONS "-DNO_TLS")
default_option(WOLFSSL_SECURE_RENEGOTIATION_INFO "no")
# record_size_limit needs the TLS layer, and its API is compiled only with it, so
# an explicit -DWOLFSSL_RECORDSIZELIMIT=yes is overridden here, as --disable-tls does.
force_option(WOLFSSL_RECORDSIZELIMIT "no")
endif()

# TLSv1.2
Expand Down Expand Up @@ -3066,6 +3069,8 @@ endif()

if(WOLFSSL_TLSX)
override_cache(WOLFSSL_ENC_THEN_MAC "yes")
# A pure extension, which is what --enable-tlsx means in configure.ac.
default_option(WOLFSSL_RECORDSIZELIMIT "yes")
endif()

if(WOLFSSL_SNIFFER)
Expand Down Expand Up @@ -4750,6 +4755,17 @@ if(WOLFSSL_LIBZ)
list(APPEND WOLFSSL_INCLUDE_DIRS ${ZLIB_INCLUDE_DIRS})
endif()

# Record size limit (RFC 8449). Applies to TLS 1.2 as well as TLS 1.3, where
# the server answers in the ServerHello rather than EncryptedExtensions, so
# it imposes no TLS 1.3 requirement.
add_option("WOLFSSL_RECORDSIZELIMIT"
"Enable RFC 8449 record_size_limit, for TLS 1.2 and TLS 1.3 (default: disabled)"
"no" "yes;no")
if(WOLFSSL_RECORDSIZELIMIT)
list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_TLS_EXTENSIONS")
list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_RECORD_SIZE_LIMIT")
endif()


####################################################
# Maximum key size options (parity with configure.ac)
Expand Down
20 changes: 20 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
Both macros are documented in
`wolfcrypt/src/port/nxp/README_SE050.md` and `IDE/CRYPTOCELL/README.md`. by @SparkiDev

* Added the RFC 8449 record_size_limit TLS extension for TLS 1.2 and TLS 1.3
(`--enable-recordsizelimit`, CMake `WOLFSSL_RECORDSIZELIMIT`, macro
`HAVE_RECORD_SIZE_LIMIT`), the byte-exact replacement for
max_fragment_length. `wolfSSL_CTX_UseRecordSizeLimit()` and
`wolfSSL_UseRecordSizeLimit()` set the largest record this end accepts, and
the records sent are sized to the limit the peer advertised. Record layer
compression and a record size limit cannot share a connection, so each is
refused while the other is in use. by @SparkiDev (PR 12258)

## Behavioral Changes
* **Behavioral change (DSA now uses the leftmost |q| bytes of the digest)**:
`wc_DsaSign_ex()`/`wc_DsaVerify_ex()` read the whole digest, and the EVP DSA
Expand Down Expand Up @@ -125,6 +134,17 @@
because callers fold the result into constant-time masks that read a
negative value as a match.

* **Behavioral change (`--enable-all` and `--enable-tlsx` advertise a record
size limit)**: both options now enable record_size_limit, and a build with
it advertises the protocol maximum by default, adding 6 bytes to every
ClientHello. When both peers send it, RFC 8449 has record_size_limit
override max_fragment_length. Session export is refused for a connection
that negotiated a limit below the maximum, as the export format does not
carry it. Pass `WOLFSSL_RECORD_SIZE_LIMIT_OFF` to
`wolfSSL_UseRecordSizeLimit()` to stop advertising one, or build with
`--disable-recordsizelimit` (CMake `-DWOLFSSL_RECORDSIZELIMIT=no`).
by @SparkiDev (PR 12258)

## Post-Quantum Cryptography (PQC)

* Added opt-in per-key Falcon signing caches (`--enable-falcon=cache-key`, `cache-basis`), roughly doubling signing speed with the default integer fpr backend. by @Frauschi
Expand Down
2 changes: 2 additions & 0 deletions cmake/options.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ extern "C" {
#cmakedefine HAVE_PTHREAD 1
#undef HAVE_REPRODUCIBLE_BUILD
#cmakedefine HAVE_REPRODUCIBLE_BUILD
#undef HAVE_RECORD_SIZE_LIMIT
#cmakedefine HAVE_RECORD_SIZE_LIMIT
#undef HAVE_SESSION_TICKET
#cmakedefine HAVE_SESSION_TICKET
#undef HAVE_SNI
Expand Down
28 changes: 28 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,7 @@ then
test "$enable_srtp" = "" && enable_srtp=no
test "$enable_ocsp" = "" && enable_ocsp=no
test "$enable_tlsx" = "" && enable_tlsx=no
test "$enable_recordsizelimit" = "" && enable_recordsizelimit=no
test "$enable_sni" = "" && enable_sni=no
test "$enable_crl_monitor" = "" && enable_crl_monitor=no
test "$enable_alpn" = "" && enable_alpn=no
Expand Down Expand Up @@ -1583,6 +1584,7 @@ then
test "$enable_earlydata" = "" && enable_earlydata=yes
test "$enable_rpk" = "" && enable_rpk=yes

test "$enable_recordsizelimit" = "" && enable_recordsizelimit=yes
if test "$KERNEL_MODE_DEFAULTS" != "yes"
then
# Disable QUIC with JNI since incompatible with client-side
Expand Down Expand Up @@ -10228,6 +10230,10 @@ then
ENABLED_ALPN=yes
ENABLED_TRUSTED_CA=yes
ENABLED_ENCRYPT_THEN_MAC=yes
dnl A seed rather than an ENABLED_ var: this block runs before that option
dnl is declared, and AC_ARG_ENABLE keys off ${enable_X+set}. It is a pure
dnl extension, which is what --enable-tlsx means.
test "$enable_recordsizelimit" = "" && enable_recordsizelimit=yes
AM_CFLAGS="$AM_CFLAGS -DHAVE_TLS_EXTENSIONS -DHAVE_SNI -DHAVE_MAX_FRAGMENT -DHAVE_TRUNCATED_HMAC -DHAVE_ALPN -DHAVE_TRUSTED_CA"
# Check the ECC supported curves prereq
AS_IF([test "x$ENABLED_ECC" != "xno" || test "$ENABLED_CURVE25519" != "no" || test "x$ENABLED_CURVE448" = "xyes" || test "x$ENABLED_TLS13" = "xyes"],
Expand Down Expand Up @@ -11663,6 +11669,27 @@ AC_ARG_WITH([libz],
]
)

# Record Size Limit (RFC 8449)
AC_ARG_ENABLE([recordsizelimit],
[AS_HELP_STRING([--enable-recordsizelimit],[Enable RFC 8449 record_size_limit, the byte-exact replacement for max_fragment_length. Applies to TLS 1.2 and TLS 1.3. A connection cannot both use it and compress its records, so wolfSSL_set_compression() and wolfSSL_UseRecordSizeLimit() refuse each other (default: disabled)])],
[ ENABLED_RECORD_SIZE_LIMIT=$enableval ],
[ ENABLED_RECORD_SIZE_LIMIT=no ]
)
dnl RFC 8449 defines the extension for TLS 1.2 as well as TLS 1.3, where the
dnl server answers in the ServerHello rather than EncryptedExtensions, so no
dnl TLS 1.3 dependency is imposed here. It does need TLS: the no-TLS defaults
dnl above only cover an unset option, so an explicit --enable-recordsizelimit
dnl is overridden here in a crypto-only or no-TLS build, as CMake does.
if test "$ENABLED_RECORD_SIZE_LIMIT" = "yes" && test "$ENABLED_TLS" = "no"
then
AC_MSG_WARN([--enable-recordsizelimit needs TLS; disabled in this no-TLS build])
ENABLED_RECORD_SIZE_LIMIT=no
fi
if test "$ENABLED_RECORD_SIZE_LIMIT" = "yes"
then
AM_CFLAGS="$AM_CFLAGS -DHAVE_TLS_EXTENSIONS -DHAVE_RECORD_SIZE_LIMIT"
fi


# PKCS#11
AC_ARG_ENABLE([pkcs11],
Expand Down Expand Up @@ -15505,6 +15532,7 @@ echo " * Falcon: $ENABLED_FALCON"
echo " * Server Name Indication: $ENABLED_SNI"
echo " * ALPN: $ENABLED_ALPN"
echo " * Maximum Fragment Length: $ENABLED_MAX_FRAGMENT"
echo " * Record Size Limit: $ENABLED_RECORD_SIZE_LIMIT"
echo " * Trusted CA Indication: $ENABLED_TRUSTED_CA"
echo " * Truncated HMAC: $ENABLED_TRUNCATED_HMAC"
echo " * Supported Elliptic Curves: $ENABLED_SUPPORTED_CURVES"
Expand Down
125 changes: 118 additions & 7 deletions doc/dox_comments/header_files/ssl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8770,10 +8770,22 @@ int wolfSSL_negotiate(WOLFSSL* ssl);
transport is known when the WOLFSSL object is created, this is reported
rather than dropped.

A connection cannot both compress its records and use the RFC 8449
record_size_limit extension: the limit bounds the plaintext, which deflate
may expand past it. A limit the application set with
wolfSSL_UseRecordSizeLimit() or wolfSSL_CTX_UseRecordSizeLimit() is its
request, so this call is refused; the advertisement that is on by default
gives way instead, and such a connection offers no limit. It can give way
only before it is sent or answered, so call this before the handshake
starts: from a server's SNI callback, for one, it is refused whenever the
client offered record_size_limit.

\return SSL_SUCCESS upon success.
\return NOT_COMPILED_IN will be returned if compression support wasn’t
built into the library.
\return BAD_FUNC_ARG will be returned if ssl is NULL or is a DTLS session.
\return BAD_FUNC_ARG will be returned if ssl is NULL, is a DTLS session,
was given a record size limit, or has already advertised, sent or
received one.

\param ssl pointer to the SSL session, created with wolfSSL_new().

Expand Down Expand Up @@ -11171,12 +11183,13 @@ int wolfSSL_GetOutputSize(WOLFSSL* ssl, int inSz);

/*!
\brief Returns the maximum record layer size for plaintext data. This
will correspond to either the maximum SSL/TLS record size as specified
by the protocol standard, the maximum TLS fragment size as set by the
TLS Max Fragment Length extension. This function is helpful when the
application has called wolfSSL_GetOutputSize() and received a INPUT_SIZE_E
error. This function must be called after the SSL/TLS handshake has been
completed.
will correspond to the smallest of the maximum SSL/TLS record size as
specified by the protocol standard, the maximum TLS fragment size as set
by the TLS Max Fragment Length extension, and the limit the peer
advertised with the RFC 8449 record_size_limit extension. This function is
helpful when the application has called wolfSSL_GetOutputSize() and
received a INPUT_SIZE_E error. This function must be called after the
SSL/TLS handshake has been completed.

\return size Upon success, the maximum output size will be returned
\return BAD_FUNC_ARG will be returned upon invalid function argument,
Expand All @@ -11190,6 +11203,8 @@ int wolfSSL_GetOutputSize(WOLFSSL* ssl, int inSz);
\endcode

\sa wolfSSL_GetOutputSize
\sa wolfSSL_UseRecordSizeLimit
\sa wolfSSL_UseMaxFragment
*/
int wolfSSL_GetMaxOutputSize(WOLFSSL* ssl);

Expand Down Expand Up @@ -14100,9 +14115,105 @@ int wolfSSL_ALPN_GetPeerProtocol(WOLFSSL* ssl, char **list,

\sa wolfSSL_new
\sa wolfSSL_CTX_UseMaxFragment
\sa wolfSSL_UseRecordSizeLimit
*/
int wolfSSL_UseMaxFragment(WOLFSSL* ssl, unsigned char mfl);

/*!
\brief Sets the largest record payload this end will accept, advertised as
the RFC 8449 record_size_limit extension. A client sends it in the
ClientHello; a server that received one answers in EncryptedExtensions
under TLS 1.3 or in the ServerHello under TLS 1.2. The extension only
takes effect when both ends send it, so the peer's records are capped only
once it has answered. It supersedes max_fragment_length, which offers four
fixed sizes rather than an exact byte count; where a peer sends both, RFC
8449 Sect. 5 says record_size_limit governs.

The count is payload. RFC 8449's field on the wire covers the whole TLS
1.3 TLSInnerPlaintext, so a request for n goes out as n+1 under TLS 1.3
and as n under TLS 1.2; the conversion is internal.

A limit is advertised by default. Pass WOLFSSL_RECORD_SIZE_LIMIT_OFF to
stop advertising one. Must be called before the handshake starts, since
the value is both advertised to the peer and enforced on arrival: on the
context, or on the object before wolfSSL_connect() or wolfSSL_accept().
A server callback is too late. A certificate setup callback and an SNI
callback both run after the ClientHello's extensions have been parsed, so
either is refused whenever the client sent record_size_limit - and a
client that sent the extension is the only case in which a server's limit
would be answered at all.

Record layer compression is refused on a connection that was given a
limit, and a limit is refused on one that compresses: RFC 8449 Sect. 4
measures the limit against the plaintext, which deflate may expand past
it. A limit set here is the application's request and wins, so
wolfSSL_set_compression() then fails; the advertisement that is on by
default gives way instead, and such a connection offers no limit.

The default limit stands aside for an application that asked for
max_fragment_length with wolfSSL_UseMaxFragment(), so a client that set
one keeps offering it alone. Calling this function explicitly overrides
that: the application has then asked for both, and RFC 8449 Sect. 5 says
record_size_limit governs.

\return WOLFSSL_SUCCESS upon success.
\return BAD_FUNC_ARG for any of four distinct causes: ssl is NULL, limit
is outside WOLFSSL_RECORD_SIZE_LIMIT_MIN..WOLFSSL_RECORD_SIZE_LIMIT_MAX
(and not WOLFSSL_RECORD_SIZE_LIMIT_OFF), the handshake has already begun,
or wolfSSL_set_compression() was called on this object. The last two are
state errors rather than bad arguments; they share the code so that
existing callers testing for failure are unaffected.

\param ssl pointer to a SSL object, created with wolfSSL_new().
\param limit largest record payload accepted, from
WOLFSSL_RECORD_SIZE_LIMIT_MIN (64) to WOLFSSL_RECORD_SIZE_LIMIT_MAX
(16384), or WOLFSSL_RECORD_SIZE_LIMIT_OFF (0) to advertise nothing.
Defaults to WOLFSSL_RECORD_SIZE_LIMIT_DEFAULT.

_Example_
\code
int ret = 0;
WOLFSSL* ssl = wolfSSL_new(ctx);
if (ssl == NULL) {
// ssl creation failed
}
ret = wolfSSL_UseRecordSizeLimit(ssl, 1024);
if (ret != WOLFSSL_SUCCESS) {
// limit rejected
}
\endcode

\sa wolfSSL_CTX_UseRecordSizeLimit
\sa wolfSSL_UseMaxFragment
\sa wolfSSL_GetMaxOutputSize
*/
int wolfSSL_UseRecordSizeLimit(WOLFSSL* ssl, unsigned short limit);

/*!
\brief Sets the record_size_limit inherited by every WOLFSSL object
created from this context afterwards. See wolfSSL_UseRecordSizeLimit() for
what the value means and how the extension is negotiated.

\return WOLFSSL_SUCCESS upon success.
\return BAD_FUNC_ARG when ctx is NULL or limit is out of range.

\param ctx pointer to a SSL context, created with wolfSSL_CTX_new().
\param limit largest record payload accepted, from
WOLFSSL_RECORD_SIZE_LIMIT_MIN (64) to WOLFSSL_RECORD_SIZE_LIMIT_MAX
(16384), or WOLFSSL_RECORD_SIZE_LIMIT_OFF (0) to advertise nothing.

_Example_
\code
int ret = wolfSSL_CTX_UseRecordSizeLimit(ctx, 512);
if (ret != WOLFSSL_SUCCESS) {
// limit rejected
}
\endcode

\sa wolfSSL_UseRecordSizeLimit
*/
int wolfSSL_CTX_UseRecordSizeLimit(WOLFSSL_CTX* ctx, unsigned short limit);

/*!
\brief This function is called on the client side to enable the use
of Maximum Fragment Length for SSL objects created from the SSL context
Expand Down
Loading
Loading