Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d4a65ea

Browse files
pennamandreagilardoni
authored andcommittedApr 17, 2024
BearSSLClient: allow configuration after object creation
1 parent bc68ef1 commit d4a65ea

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed
 

‎src/tls/BearSSLClient.cpp

+15-6
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,20 @@
3434

3535
#include "BearSSLClient.h"
3636

37-
extern "C" void aiotc_client_profile_init(br_ssl_client_context *cc, br_x509_minimal_context *xc, const br_x509_trust_anchor *trust_anchors, size_t trust_anchors_num);
38-
39-
4037
bool BearSSLClient::_sslio_closing = false;
4138

39+
BearSSLClient::BearSSLClient() :
40+
_noSNI(false),
41+
_get_time_func(nullptr)
42+
{
43+
_ecKey.curve = 0;
44+
_ecKey.x = NULL;
45+
_ecKey.xlen = 0;
46+
47+
_ecCert.data = NULL;
48+
_ecCert.data_len = 0;
49+
_ecCertDynamic = false;
50+
}
4251

4352
BearSSLClient::BearSSLClient(Client* client, const br_x509_trust_anchor* myTAs, int myNumTAs, GetTimeCallbackFunc func) :
4453
_client(client),
@@ -266,8 +275,8 @@ int BearSSLClient::connectSSL(const char* host)
266275
/* Ensure this flag is cleared so we don't terminate a just starting connection. */
267276
_sslio_closing = false;
268277

269-
// initialize client context with all necessary algorithms and hardcoded trust anchors.
270-
aiotc_client_profile_init(&_sc, &_xc, _TAs, _numTAs);
278+
// initialize client context with enabled algorithms and trust anchors
279+
_br_ssl_client_init_function(&_sc, &_xc, _TAs, _numTAs);
271280

272281
br_ssl_engine_set_buffers_bidi(&_sc.eng, _ibuf, sizeof(_ibuf), _obuf, sizeof(_obuf));
273282

@@ -278,7 +287,7 @@ int BearSSLClient::connectSSL(const char* host)
278287
// ECC508 random success, add custom ECDSA vfry and EC sign
279288
br_ssl_engine_set_ecdsa(&_sc.eng, eccX08_vrfy_asn1);
280289
br_x509_minimal_set_ecdsa(&_xc, br_ssl_engine_get_ec(&_sc.eng), br_ssl_engine_get_ecdsa(&_sc.eng));
281-
290+
282291
// enable client auth using the ECCX08
283292
if (_ecCert.data_len && _ecKey.xlen) {
284293
br_ssl_client_set_single_ec(&_sc, &_ecCert, 1, &_ecKey, BR_KEYTYPE_KEYX | BR_KEYTYPE_SIGN, BR_KEYTYPE_EC, br_ec_get_default(), eccX08_sign_asn1);

‎src/tls/BearSSLClient.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,14 @@ class BearSSLClient : public Client {
4848
public:
4949

5050
BearSSLClient(Client* client, const br_x509_trust_anchor* myTAs, int myNumTAs, GetTimeCallbackFunc func);
51+
BearSSLClient();
5152
virtual ~BearSSLClient();
5253

5354

5455
inline void setClient(Client& client) { _client = &client; }
55-
56+
inline void setProfile(void(*client_init_function)(br_ssl_client_context *cc, br_x509_minimal_context *xc, const br_x509_trust_anchor *trust_anchors, size_t trustrust_anchorst_anchors_num)) { _br_ssl_client_init_function = client_init_function; }
57+
inline void setTrustAnchors(const br_x509_trust_anchor* myTAs, int myNumTAs) { _TAs = myTAs; _numTAs = myNumTAs; }
58+
inline void onGetTime(GetTimeCallbackFunc callback) { _get_time_func = callback;}
5659

5760
virtual int connect(IPAddress ip, uint16_t port);
5861
virtual int connect(const char* host, uint16_t port);
@@ -103,6 +106,8 @@ class BearSSLClient : public Client {
103106
unsigned char _ibuf[BEAR_SSL_CLIENT_IBUF_SIZE];
104107
unsigned char _obuf[BEAR_SSL_CLIENT_OBUF_SIZE];
105108
br_sslio_context _ioc;
109+
110+
void (*_br_ssl_client_init_function)(br_ssl_client_context *cc, br_x509_minimal_context *xc, const br_x509_trust_anchor *trust_anchors, size_t trust_anchors_num);
106111
};
107112

108113
#endif /* #ifdef BOARD_HAS_ECCX08 */

0 commit comments

Comments
 (0)
Please sign in to comment.