@@ -44,7 +44,8 @@ BearSSLClient::BearSSLClient(Client* client, const br_x509_trust_anchor* myTAs,
44
44
_client(client),
45
45
_TAs(myTAs),
46
46
_numTAs(myNumTAs),
47
- _noSNI(false )
47
+ _noSNI(false ),
48
+ _ecChainLen(0 )
48
49
{
49
50
_ecVrfy = br_ecdsa_vrfy_asn1_get_default ();
50
51
_ecSign = br_ecdsa_sign_asn1_get_default ();
@@ -53,16 +54,18 @@ BearSSLClient::BearSSLClient(Client* client, const br_x509_trust_anchor* myTAs,
53
54
_ecKey.x = NULL ;
54
55
_ecKey.xlen = 0 ;
55
56
56
- _ecCert.data = NULL ;
57
- _ecCert.data_len = 0 ;
57
+ for (size_t i = 0 ; i < BEAR_SSL_CLIENT_CHAIN_SIZE; i++) {
58
+ _ecCert[i].data = NULL ;
59
+ _ecCert[i].data_len = 0 ;
60
+ }
58
61
_ecCertDynamic = false ;
59
62
}
60
63
61
64
BearSSLClient::~BearSSLClient ()
62
65
{
63
- if (_ecCertDynamic && _ecCert.data ) {
64
- free (_ecCert.data );
65
- _ecCert.data = NULL ;
66
+ if (_ecCertDynamic && _ecCert[ 0 ] .data ) {
67
+ free (_ecCert[ 0 ] .data );
68
+ _ecCert[ 0 ] .data = NULL ;
66
69
}
67
70
}
68
71
@@ -207,7 +210,19 @@ void BearSSLClient::setEccSign(br_ecdsa_sign sign)
207
210
208
211
void BearSSLClient::setEccCert (br_x509_certificate cert)
209
212
{
210
- _ecCert = cert;
213
+ _ecCert[0 ] = cert;
214
+ _ecChainLen = 1 ;
215
+ }
216
+
217
+ void BearSSLClient::setEccChain (br_x509_certificate* chain, size_t chainLen)
218
+ {
219
+ if (chainLen > BEAR_SSL_CLIENT_CHAIN_SIZE)
220
+ return ;
221
+
222
+ for (size_t i = 0 ; i < chainLen; i++) {
223
+ _ecCert[i] = chain[i];
224
+ }
225
+ _ecChainLen = chainLen;
211
226
}
212
227
213
228
void BearSSLClient::setEccSlot (int ecc508KeySlot, const byte cert[], int certLength)
@@ -217,8 +232,9 @@ void BearSSLClient::setEccSlot(int ecc508KeySlot, const byte cert[], int certLen
217
232
_ecKey.x = (unsigned char *)ecc508KeySlot;
218
233
_ecKey.xlen = 32 ;
219
234
220
- _ecCert.data = (unsigned char *)cert;
221
- _ecCert.data_len = certLength;
235
+ _ecCert[0 ].data = (unsigned char *)cert;
236
+ _ecCert[0 ].data_len = certLength;
237
+ _ecChainLen = 1 ;
222
238
_ecCertDynamic = false ;
223
239
224
240
_ecVrfy = eccX08_vrfy_asn1;
@@ -233,14 +249,15 @@ void BearSSLClient::setEccSlot(int ecc508KeySlot, const char cert[])
233
249
size_t certLen = strlen (cert);
234
250
235
251
// free old data
236
- if (_ecCertDynamic && _ecCert.data ) {
237
- free (_ecCert.data );
238
- _ecCert.data = NULL ;
252
+ if (_ecCertDynamic && _ecCert[ 0 ] .data ) {
253
+ free (_ecCert[ 0 ] .data );
254
+ _ecCert[ 0 ] .data = NULL ;
239
255
}
240
256
241
257
// assume the decoded cert is 3/4 the length of the input
242
- _ecCert.data = (unsigned char *)malloc (((certLen * 3 ) + 3 ) / 4 );
243
- _ecCert.data_len = 0 ;
258
+ _ecCert[0 ].data = (unsigned char *)malloc (((certLen * 3 ) + 3 ) / 4 );
259
+ _ecCert[0 ].data_len = 0 ;
260
+ _ecChainLen = 1 ;
244
261
245
262
br_pem_decoder_init (&pemDecoder);
246
263
@@ -256,17 +273,17 @@ void BearSSLClient::setEccSlot(int ecc508KeySlot, const char cert[])
256
273
break ;
257
274
258
275
case BR_PEM_END_OBJ:
259
- if (_ecCert.data_len ) {
276
+ if (_ecCert[ 0 ] .data_len ) {
260
277
// done
261
- setEccSlot (ecc508KeySlot, _ecCert.data , _ecCert.data_len );
278
+ setEccSlot (ecc508KeySlot, _ecCert[ 0 ] .data , _ecCert[ 0 ] .data_len );
262
279
_ecCertDynamic = true ;
263
280
return ;
264
281
}
265
282
break ;
266
283
267
284
case BR_PEM_ERROR:
268
285
// failure
269
- free (_ecCert.data );
286
+ free (_ecCert[ 0 ] .data );
270
287
setEccSlot (ecc508KeySlot, NULL , 0 );
271
288
return ;
272
289
}
@@ -301,8 +318,8 @@ int BearSSLClient::connectSSL(const char* host)
301
318
br_x509_minimal_set_ecdsa (&_xc, br_ssl_engine_get_ec (&_sc.eng ), br_ssl_engine_get_ecdsa (&_sc.eng ));
302
319
303
320
// enable client auth
304
- if (_ecCert.data_len ) {
305
- br_ssl_client_set_single_ec (&_sc, & _ecCert, 1 , &_ecKey, BR_KEYTYPE_KEYX | BR_KEYTYPE_SIGN, BR_KEYTYPE_EC, br_ec_get_default (), _ecSign);
321
+ if (_ecCert[ 0 ] .data_len ) {
322
+ br_ssl_client_set_single_ec (&_sc, _ecCert, _ecChainLen , &_ecKey, BR_KEYTYPE_KEYX | BR_KEYTYPE_SIGN, BR_KEYTYPE_EC, br_ec_get_default (), _ecSign);
306
323
}
307
324
308
325
// set the hostname used for SNI
@@ -401,6 +418,6 @@ void BearSSLClient::clientAppendCert(void *ctx, const void *data, size_t len)
401
418
{
402
419
BearSSLClient* c = (BearSSLClient*)ctx;
403
420
404
- memcpy (&c->_ecCert .data [c->_ecCert .data_len ], data, len);
405
- c->_ecCert .data_len += len;
421
+ memcpy (&c->_ecCert [ 0 ] .data [c->_ecCert [ 0 ] .data_len ], data, len);
422
+ c->_ecCert [ 0 ] .data_len += len;
406
423
}
0 commit comments