@@ -50,17 +50,46 @@ class MbedSSLClient : public arduino::MbedClient {
5050
5151 void appendCustomCACert (const char * ca_cert) {
5252 _ca_cert_custom = ca_cert;
53+ _appendCA = true ;
54+ }
55+ void setCACert (const char * rootCA) {
56+ _ca_cert_custom = rootCA;
57+ _appendCA = false ;
58+ }
59+ void setCertificate (const char * clientCert) {
60+ _clientCert = clientCert;
61+ }
62+ void setPrivateKey (const char * privateKey) {
63+ _privateKey = privateKey;
5364 }
5465
5566protected:
5667 const char * _ca_cert_custom;
5768 const char * _hostname;
69+ const char * _clientCert;
70+ const char * _privateKey;
5871 bool _disableSNI;
72+ bool _appendCA;
5973
6074private:
6175 int setRootCA () {
6276 int err = 0 ;
6377
78+ if (_hostname && !_disableSNI) {
79+ ((TLSSocket*)sock)->set_hostname (_hostname);
80+ }
81+
82+ if (_clientCert && _privateKey) {
83+ err = ((TLSSocket*)sock)->set_client_cert_key (_clientCert, _privateKey);
84+ if ( err != NSAPI_ERROR_OK) {
85+ return err;
86+ }
87+ }
88+
89+ if (!_appendCA && _ca_cert_custom) {
90+ return ((TLSSocket*)sock)->set_root_ca_cert (_ca_cert_custom);
91+ }
92+
6493#if defined(MBEDTLS_FS_IO)
6594 mbed::BlockDevice* root = mbed::BlockDevice::get_default_instance ();
6695 err = root->init ();
@@ -82,10 +111,6 @@ class MbedSSLClient : public arduino::MbedClient {
82111 }
83112#endif
84113
85- if (_hostname && !_disableSNI) {
86- ((TLSSocket*)sock)->set_hostname (_hostname);
87- }
88-
89114 if (_ca_cert_custom != NULL ) {
90115 err = ((TLSSocket*)sock)->append_root_ca_cert (_ca_cert_custom);
91116 }
0 commit comments