Skip to content

Commit 9c21762

Browse files
committed
Add support for passing ECC508 key slot and cert. byte array + length in constructor
1 parent 7b50ad3 commit 9c21762

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/BearSSLClient.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,24 @@
99
BearSSLClient::BearSSLClient(Client& client) :
1010
_client(&client)
1111
{
12+
_ecKey.curve = 0;
13+
_ecKey.x = NULL;
14+
_ecKey.xlen = 0;
15+
16+
_ecCert.data = NULL;
17+
_ecCert.data_len = 0;
18+
}
19+
20+
BearSSLClient::BearSSLClient(Client& client, int ecc508KeySlot, const byte cert[], int certLength) :
21+
BearSSLClient(client)
22+
{
23+
// HACK: put the key slot info. in the br_ec_private_key structure
24+
_ecKey.curve = 23;
25+
_ecKey.x = (unsigned char*)ecc508KeySlot;
26+
_ecKey.xlen = 32;
27+
28+
_ecCert.data = (unsigned char*)cert;
29+
_ecCert.data_len = certLength;
1230
}
1331

1432
BearSSLClient::~BearSSLClient()
@@ -166,7 +184,10 @@ int BearSSLClient::connectSSL(const char* host)
166184
br_ssl_engine_set_ecdsa(&_sc.eng, ecc508_vrfy_asn1);
167185
br_x509_minimal_set_ecdsa(&_xc, br_ssl_engine_get_ec(&_sc.eng), br_ssl_engine_get_ecdsa(&_sc.eng));
168186

169-
// br_ssl_client_set_single_ec(&_sc, CHAIN, CHAIN_LEN, &EC, BR_KEYTYPE_KEYX | BR_KEYTYPE_SIGN, BR_KEYTYPE_EC, br_ec_get_default(), ecc508_sign_asn1);
187+
// enable client auth using the ECC508
188+
if (_ecCert.data_len && _ecKey.xlen) {
189+
br_ssl_client_set_single_ec(&_sc, &_ecCert, 1, &_ecKey, BR_KEYTYPE_KEYX | BR_KEYTYPE_SIGN, BR_KEYTYPE_EC, br_ec_get_default(), ecc508_sign_asn1);
190+
}
170191
} else {
171192
// no ECC508 or random failed, fallback to pseudo random
172193
for (size_t i = 0; i < sizeof(entropy); i++) {

src/BearSSLClient.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class BearSSLClient : public Client {
1010

1111
public:
1212
BearSSLClient(Client& client);
13+
BearSSLClient(Client& client, int ecc508KeySlot, const byte cert[], int certLength);
1314
virtual ~BearSSLClient();
1415

1516
virtual int connect(IPAddress ip, uint16_t port);
@@ -34,6 +35,8 @@ class BearSSLClient : public Client {
3435

3536
private:
3637
Client* _client;
38+
br_ec_private_key _ecKey;
39+
br_x509_certificate _ecCert;
3740

3841
br_ssl_client_context _sc;
3942
br_x509_minimal_context _xc;

src/utility/ecc508_sign_asn1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ecc508_sign_asn1(const br_ec_impl * /*impl*/,
1717
return 0;
1818
}
1919

20-
if (!ECC508.ecSign(0, (const uint8_t*)hash_value, (uint8_t*)rsig)) {
20+
if (!ECC508.ecSign((int)(sk->x), (const uint8_t*)hash_value, (uint8_t*)rsig)) {
2121
return 0;
2222
}
2323
sig_len = 64;

0 commit comments

Comments
 (0)