@@ -48,19 +48,48 @@ class MbedSSLClient : public arduino::MbedClient {
4848 _disableSNI = statusSNI;
4949 }
5050
51- void appendCustomCACert (const char * ca_cert) {
52- _ca_cert_custom = ca_cert;
51+ void appendCustomCACert (const char * rootCA) {
52+ _rootCA = rootCA;
53+ _appendCA = true ;
54+ }
55+ void setCACert (const char * rootCA) {
56+ _rootCA = 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
55- protected :
56- const char * _ca_cert_custom ;
66+ private :
67+ const char * _rootCA ;
5768 const char * _hostname;
69+ const char * _clientCert;
70+ const char * _privateKey;
5871 bool _disableSNI;
72+ bool _appendCA;
5973
60- private :
74+ protected :
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 && _rootCA) {
90+ return ((TLSSocket*)sock)->set_root_ca_cert (_rootCA);
91+ }
92+
6493#if defined(MBEDTLS_FS_IO)
6594 mbed::BlockDevice* root = mbed::BlockDevice::get_default_instance ();
6695 err = root->init ();
@@ -82,12 +111,8 @@ class MbedSSLClient : public arduino::MbedClient {
82111 }
83112#endif
84113
85- if (_hostname && !_disableSNI) {
86- ((TLSSocket*)sock)->set_hostname (_hostname);
87- }
88-
89- if (_ca_cert_custom != NULL ) {
90- err = ((TLSSocket*)sock)->append_root_ca_cert (_ca_cert_custom);
114+ if (_rootCA != NULL ) {
115+ err = ((TLSSocket*)sock)->append_root_ca_cert (_rootCA);
91116 }
92117 return err;
93118 }
0 commit comments