@@ -46,6 +46,9 @@ BearSSLClient::BearSSLClient(Client* client, const br_x509_trust_anchor* myTAs,
4646 _numTAs(myNumTAs),
4747 _noSNI(false )
4848{
49+ _ecVrfy = br_ecdsa_vrfy_asn1_get_default ();
50+ _ecSign = br_ecdsa_sign_asn1_get_default ();
51+
4952 _ecKey.curve = 0 ;
5053 _ecKey.x = NULL ;
5154 _ecKey.xlen = 0 ;
@@ -192,6 +195,16 @@ void BearSSLClient::setInsecure(SNI insecure)
192195 }
193196}
194197
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+
195208void BearSSLClient::setEccSlot (int ecc508KeySlot, const byte cert[], int certLength)
196209{
197210 // 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
202215 _ecCert.data = (unsigned char *)cert;
203216 _ecCert.data_len = certLength;
204217 _ecCertDynamic = false ;
218+
219+ _ecVrfy = eccX08_vrfy_asn1;
220+ _ecSign = eccX08_sign_asn1;
205221}
206222
207223void BearSSLClient::setEccSlot (int ecc508KeySlot, const char cert[])
@@ -267,23 +283,23 @@ int BearSSLClient::connectSSL(const char* host)
267283 // inject entropy in engine
268284 unsigned char entropy[32 ];
269285
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))) {
280287 // no ECCX08 or random failed, fallback to pseudo random
281288 for (size_t i = 0 ; i < sizeof (entropy); i++) {
282289 entropy[i] = random (0 , 255 );
283290 }
284291 }
285292 br_ssl_engine_inject_entropy (&_sc.eng , entropy, sizeof (entropy));
286293
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+
287303 // set the hostname used for SNI
288304 br_ssl_client_reset (&_sc, host, 0 );
289305
0 commit comments