Skip to content

Commit bcc67ce

Browse files
committed
Allow enabling or disabling key decoder via config file
1 parent a9ed8b5 commit bcc67ce

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/BearSSLClient.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ BearSSLClient::BearSSLClient(Client* client, const br_x509_trust_anchor* myTAs,
5252
_TAs(myTAs),
5353
_numTAs(myNumTAs),
5454
_noSNI(false),
55+
#ifndef ARDUINO_BEARSSL_DISABLE_KEY_DECODER
5556
_skeyDecoder(NULL),
57+
#endif
5658
_ecChainLen(0),
5759
#ifndef ARDUINO_BEARSSL_DISABLE_FULL_CLIENT_PROFILE
5860
_br_ssl_client_init_function(br_ssl_client_init_full)
@@ -86,10 +88,12 @@ BearSSLClient::~BearSSLClient()
8688
_ecCert[0].data = NULL;
8789
}
8890

91+
#ifndef ARDUINO_BEARSSL_DISABLE_KEY_DECODER
8992
if (_skeyDecoder) {
9093
free(_skeyDecoder);
9194
_skeyDecoder = NULL;
9295
}
96+
#endif
9397
}
9498

9599
int BearSSLClient::connect(IPAddress ip, uint16_t port)
@@ -318,6 +322,7 @@ void BearSSLClient::setEccSlot(int ecc508KeySlot, const char cert[])
318322
}
319323
}
320324

325+
#ifndef ARDUINO_BEARSSL_DISABLE_KEY_DECODER
321326
void BearSSLClient::setKey(const char key[], const char cert[])
322327
{
323328
// try to decode the key and cert
@@ -390,6 +395,7 @@ void BearSSLClient::setKey(const char key[], const char cert[])
390395
}
391396
}
392397
}
398+
#endif
393399

394400
void BearSSLClient::setEccCertParent(const char cert[])
395401
{
@@ -475,6 +481,7 @@ int BearSSLClient::connectSSL(const char* host)
475481

476482
// enable client auth
477483
if (_ecCert[0].data_len) {
484+
#ifndef ARDUINO_BEARSSL_DISABLE_KEY_DECODER
478485
if (_skeyDecoder) {
479486
int skeyType = br_skey_decoder_key_type(_skeyDecoder);
480487

@@ -484,8 +491,11 @@ int BearSSLClient::connectSSL(const char* host)
484491
br_ssl_client_set_single_rsa(&_sc, _ecCert, _ecChainLen, br_skey_decoder_get_rsa(_skeyDecoder), br_rsa_pkcs1_sign_get_default());
485492
}
486493
} else {
494+
#endif
487495
br_ssl_client_set_single_ec(&_sc, _ecCert, _ecChainLen, &_ecKey, BR_KEYTYPE_KEYX | BR_KEYTYPE_SIGN, BR_KEYTYPE_EC, br_ec_get_default(), _ecSign);
496+
#ifndef ARDUINO_BEARSSL_DISABLE_KEY_DECODER
488497
}
498+
#endif
489499
}
490500

491501
// set the hostname used for SNI
@@ -588,12 +598,14 @@ void BearSSLClient::clientAppendCert(void *ctx, const void *data, size_t len)
588598
c->_ecCert[0].data_len += len;
589599
}
590600

601+
#ifndef ARDUINO_BEARSSL_DISABLE_KEY_DECODER
591602
void BearSSLClient::clientAppendKey(void *ctx, const void *data, size_t len)
592603
{
593604
BearSSLClient* c = (BearSSLClient*)ctx;
594605

595606
br_skey_decoder_push(c->_skeyDecoder, data, len);
596607
}
608+
#endif
597609

598610
void BearSSLClient::parentAppendCert(void *ctx, const void *data, size_t len)
599611
{

src/BearSSLClient.h

+6
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ class BearSSLClient : public Client {
9696

9797
void setEccSlot(int ecc508KeySlot, const byte cert[], int certLength);
9898
void setEccSlot(int ecc508KeySlot, const char cert[]);
99+
#ifndef ARDUINO_BEARSSL_DISABLE_KEY_DECODER
99100
void setKey(const char key[], const char cert[]);
101+
#endif
100102
void setEccCertParent(const char cert[]);
101103

102104
int errorCode();
@@ -106,7 +108,9 @@ class BearSSLClient : public Client {
106108
static int clientRead(void *ctx, unsigned char *buf, size_t len);
107109
static int clientWrite(void *ctx, const unsigned char *buf, size_t len);
108110
static void clientAppendCert(void *ctx, const void *data, size_t len);
111+
#ifndef ARDUINO_BEARSSL_DISABLE_KEY_DECODER
109112
static void clientAppendKey(void *ctx, const void *data, size_t len);
113+
#endif
110114
static void parentAppendCert(void *ctx, const void *data, size_t len);
111115

112116
private:
@@ -120,7 +124,9 @@ class BearSSLClient : public Client {
120124
br_ecdsa_sign _ecSign;
121125

122126
br_ec_private_key _ecKey;
127+
#ifndef ARDUINO_BEARSSL_DISABLE_KEY_DECODER
123128
br_skey_decoder_context* _skeyDecoder;
129+
#endif
124130
br_x509_certificate _ecCert[BEAR_SSL_CLIENT_CHAIN_SIZE];
125131
int _ecChainLen;
126132
bool _ecCertDynamic;

0 commit comments

Comments
 (0)