Skip to content

Commit 7558ce8

Browse files
pfalconAnas Nashif
authored andcommitted
mbedtls: Add CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN
This value allows to set max payload length of a TLS protocol message, and passed thru to mbedTLS as MBEDTLS_SSL_MAX_CONTENT_LEN setting. The only safe value is 16384, which translates to 32KB of RAM required just for mbedTLS input/output buffers. Any other value can be configured *only* per a particular application (e.g. knowing that it won't pass more than spefific amount of data at once and/or won't connect to a server with a long cert chain). Previosuly, we had quite an adhoc and inflexible config with random values for that setting, based on protocol. Note that while the safe value is 16384, "backward compatible" default of 1500 is used (good for DTLS on the other hand). Signed-off-by: Paul Sokolovsky <[email protected]>
1 parent bdfa021 commit 7558ce8

File tree

7 files changed

+25
-10
lines changed

7 files changed

+25
-10
lines changed

ext/lib/crypto/mbedtls/Kconfig

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ config MBEDTLS_CFG_FILE
5252
relatively many features enabled. To optimize resources for special
5353
TLS usage, an alternative config may be selected.
5454

55+
config MBEDTLS_SSL_MAX_CONTENT_LEN
56+
int "Max payload size for TLS protocol message"
57+
default 1500
58+
depends on MBEDTLS_BUILTIN
59+
help
60+
The TLS standards mandate max payload size of 16384 bytes. So, for
61+
maximum operability and for general-purpose usage, that value must
62+
be used. For specific usages, that value can be largely decreased.
63+
E.g. for DTLS, payload size is limited by UDP datagram size, and
64+
even for HTTPS REST API, the payload can be limited to max size of
65+
(REST request, REST response, server certificate(s)).
66+
mbedTLS uses this value separate for input and output buffers, so
67+
twice this value will be allocated (on mbedTLS own heap, so the
68+
value of MBEDTLS_HEAP_SIZE should accommodate that).
69+
5570
config MBEDTLS_DEBUG
5671
bool "mbed TLS debug activation"
5772
depends on MBEDTLS_BUILTIN
@@ -116,9 +131,10 @@ config MBEDTLS_HEAP_SIZE
116131
MBEDTLS_MEMORY_BUFFER_ALLOC_C option for details. That option is not
117132
enabled by default.
118133
Default value for the heap size is not set as it depends on the
119-
application. For server application 15000 bytes should be enough.
120-
For some dedicated and specific usage of mbedtls API, the 1000 bytes
121-
might be ok.
134+
application. For streaming communication with arbitrary (HTTPS)
135+
servers on the Internet, 32KB + overheads (up to another 20KB) may
136+
be needed. For some dedicated and specific usage of mbedtls API, the
137+
1000 bytes might be ok.
122138

123139
config APP_LINK_WITH_MBEDTLS
124140
bool "Link 'app' with MBEDTLS"

ext/lib/crypto/mbedtls/configs/config-mini-tls1_2.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,7 @@
7272
#define MBEDTLS_SSL_ALL_ALERT_MESSAGES
7373
#endif
7474

75-
#if defined(CONFIG_MQTT_LIB_TLS)
76-
#define MBEDTLS_SSL_MAX_CONTENT_LEN 2500
77-
#elif defined(CONFIG_HTTPS)
78-
#define MBEDTLS_SSL_MAX_CONTENT_LEN 2500
79-
#else
80-
#define MBEDTLS_SSL_MAX_CONTENT_LEN 1500
81-
#endif
75+
#define MBEDTLS_SSL_MAX_CONTENT_LEN CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN
8276

8377
#include "mbedtls/check_config.h"
8478

samples/net/http_client/prj_bt.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ CONFIG_HTTPS=n
3131
CONFIG_MBEDTLS=y
3232
CONFIG_MBEDTLS_BUILTIN=y
3333
CONFIG_MBEDTLS_CFG_FILE="config-mini-tls1_2.h"
34+
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=2500
3435
CONFIG_MBEDTLS_ENABLE_HEAP=y
3536
CONFIG_MBEDTLS_HEAP_SIZE=12000
3637

samples/net/http_client/prj_tls.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ CONFIG_HTTPS=y
3737
CONFIG_MBEDTLS=y
3838
CONFIG_MBEDTLS_BUILTIN=y
3939
CONFIG_MBEDTLS_CFG_FILE="config-mini-tls1_2.h"
40+
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=2500
4041
CONFIG_MBEDTLS_ENABLE_HEAP=y
4142
CONFIG_MBEDTLS_HEAP_SIZE=30000
4243

samples/net/http_server/prj_bt.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ CONFIG_HTTPS=y
2828
CONFIG_MBEDTLS=y
2929
CONFIG_MBEDTLS_BUILTIN=y
3030
CONFIG_MBEDTLS_CFG_FILE="config-mini-tls1_2.h"
31+
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=2500
3132
CONFIG_MBEDTLS_ENABLE_HEAP=y
3233
CONFIG_MBEDTLS_HEAP_SIZE=12000
3334

samples/net/http_server/prj_tls.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ CONFIG_HTTPS=y
3535
CONFIG_MBEDTLS=y
3636
CONFIG_MBEDTLS_BUILTIN=y
3737
CONFIG_MBEDTLS_CFG_FILE="config-mini-tls1_2.h"
38+
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=2500
3839
CONFIG_MBEDTLS_ENABLE_HEAP=y
3940
CONFIG_MBEDTLS_HEAP_SIZE=30000
4041

samples/net/mqtt_publisher/prj_frdm_k64f_tls.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ CONFIG_NET_BUF_DATA_SIZE=256
3939

4040
CONFIG_MBEDTLS=y
4141
CONFIG_MBEDTLS_BUILTIN=y
42+
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=2500
4243
CONFIG_MBEDTLS_ENABLE_HEAP=y
4344
CONFIG_MBEDTLS_HEAP_SIZE=30000
4445
CONFIG_MBEDTLS_CFG_FILE="config-mini-tls1_2.h"

0 commit comments

Comments
 (0)