Skip to content

Commit 73f4763

Browse files
authored
Use two buffers instead of split mode (arduino-libraries#18)
Use two dedicated buffers for input and output instead of split mode. Indeed some MQTT server (especially with TLS) needs a full 8k buffer as they send their Certificate. On the other hand, on output, a smaller buffer is needed. Clients will be able to finely tune those values by defining BEAR_SSL_CLIENT_{I,O}BUF_SIZE before including ArduinoBearSSL.h, the default default values have been chosen to keep current behavior as requested during review. Signed-off-by: Fabrice Fontaine <[email protected]>
1 parent ecdc2c9 commit 73f4763

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/BearSSLClient.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,7 @@ int BearSSLClient::connectSSL(const char* host)
259259
// initialize client context with all algorithms and hardcoded trust anchors
260260
br_ssl_client_init_full(&_sc, &_xc, _TAs, _numTAs);
261261

262-
// set the buffer in split mode
263-
br_ssl_engine_set_buffer(&_sc.eng, _iobuf, sizeof(_iobuf), 1);
262+
br_ssl_engine_set_buffers_bidi(&_sc.eng, _ibuf, sizeof(_ibuf), _obuf, sizeof(_obuf));
264263

265264
// inject entropy in engine
266265
unsigned char entropy[32];

src/BearSSLClient.h

+8-3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@
2525
#ifndef _BEAR_SSL_CLIENT_H_
2626
#define _BEAR_SSL_CLIENT_H_
2727

28-
#ifndef BEAR_SSL_CLIENT_IOBUF_SIZE
29-
#define BEAR_SSL_CLIENT_IOBUF_SIZE 8192 + 85 + 325
28+
#ifndef BEAR_SSL_CLIENT_OBUF_SIZE
29+
#define BEAR_SSL_CLIENT_OBUF_SIZE 512 + 85
30+
#endif
31+
32+
#ifndef BEAR_SSL_CLIENT_IBUF_SIZE
33+
#define BEAR_SSL_CLIENT_IBUF_SIZE 8192 + 85 + 325 - BEAR_SSL_CLIENT_OBUF_SIZE
3034
#endif
3135

3236
#include <Arduino.h>
@@ -82,7 +86,8 @@ class BearSSLClient : public Client {
8286

8387
br_ssl_client_context _sc;
8488
br_x509_minimal_context _xc;
85-
unsigned char _iobuf[BEAR_SSL_CLIENT_IOBUF_SIZE];
89+
unsigned char _ibuf[BEAR_SSL_CLIENT_IBUF_SIZE];
90+
unsigned char _obuf[BEAR_SSL_CLIENT_OBUF_SIZE];
8691
br_sslio_context _ioc;
8792
};
8893

0 commit comments

Comments
 (0)