@@ -46,6 +46,9 @@ BearSSLClient::BearSSLClient(Client* client, const br_x509_trust_anchor* myTAs,
46
46
_numTAs(myNumTAs),
47
47
_noSNI(false )
48
48
{
49
+ _ecVrfy = br_ecdsa_vrfy_asn1_get_default ();
50
+ _ecSign = br_ecdsa_sign_asn1_get_default ();
51
+
49
52
_ecKey.curve = 0 ;
50
53
_ecKey.x = NULL ;
51
54
_ecKey.xlen = 0 ;
@@ -192,6 +195,16 @@ void BearSSLClient::setInsecure(SNI insecure)
192
195
}
193
196
}
194
197
198
+ void BearSSLClient::setEccVrfy (br_ecdsa_vrfy vrfy)
199
+ {
200
+ _ecVrfy = vrfy;
201
+ }
202
+
203
+ void BearSSLClient::setEccSign (br_ecdsa_sign sign)
204
+ {
205
+ _ecSign = sign;
206
+ }
207
+
195
208
void BearSSLClient::setEccSlot (int ecc508KeySlot, const byte cert[], int certLength)
196
209
{
197
210
// HACK: put the key slot info. in the br_ec_private_key structure
@@ -202,6 +215,9 @@ void BearSSLClient::setEccSlot(int ecc508KeySlot, const byte cert[], int certLen
202
215
_ecCert.data = (unsigned char *)cert;
203
216
_ecCert.data_len = certLength;
204
217
_ecCertDynamic = false ;
218
+
219
+ _ecVrfy = eccX08_vrfy_asn1;
220
+ _ecSign = eccX08_sign_asn1;
205
221
}
206
222
207
223
void BearSSLClient::setEccSlot (int ecc508KeySlot, const char cert[])
@@ -267,23 +283,23 @@ int BearSSLClient::connectSSL(const char* host)
267
283
// inject entropy in engine
268
284
unsigned char entropy[32 ];
269
285
270
- if (ECCX08.begin () && ECCX08.locked () && ECCX08.random (entropy, sizeof (entropy))) {
271
- // ECC508 random success, add custom ECDSA vfry and EC sign
272
- br_ssl_engine_set_ecdsa (&_sc.eng , eccX08_vrfy_asn1);
273
- br_x509_minimal_set_ecdsa (&_xc, br_ssl_engine_get_ec (&_sc.eng ), br_ssl_engine_get_ecdsa (&_sc.eng ));
274
-
275
- // enable client auth using the ECCX08
276
- if (_ecCert.data_len && _ecKey.xlen ) {
277
- 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);
278
- }
279
- } else {
286
+ if (!ECCX08.begin () || !ECCX08.locked () || !ECCX08.random (entropy, sizeof (entropy))) {
280
287
// no ECCX08 or random failed, fallback to pseudo random
281
288
for (size_t i = 0 ; i < sizeof (entropy); i++) {
282
289
entropy[i] = random (0 , 255 );
283
290
}
284
291
}
285
292
br_ssl_engine_inject_entropy (&_sc.eng , entropy, sizeof (entropy));
286
293
294
+ // add custom ECDSA vfry and EC sign
295
+ br_ssl_engine_set_ecdsa (&_sc.eng , _ecVrfy);
296
+ br_x509_minimal_set_ecdsa (&_xc, br_ssl_engine_get_ec (&_sc.eng ), br_ssl_engine_get_ecdsa (&_sc.eng ));
297
+
298
+ // enable client auth
299
+ if (_ecCert.data_len && _ecKey.xlen ) {
300
+ br_ssl_client_set_single_ec (&_sc, &_ecCert, 1 , &_ecKey, BR_KEYTYPE_KEYX | BR_KEYTYPE_SIGN, BR_KEYTYPE_EC, br_ec_get_default (), _ecSign);
301
+ }
302
+
287
303
// set the hostname used for SNI
288
304
br_ssl_client_reset (&_sc, host, 0 );
289
305
0 commit comments