|
| 1 | +/* |
| 2 | + EthernetSSLClient.h |
| 3 | + Copyright (c) 2021 Arduino SA. All right reserved. |
| 4 | +
|
| 5 | + This library is free software; you can redistribute it and/or |
| 6 | + modify it under the terms of the GNU Lesser General Public |
| 7 | + License as published by the Free Software Foundation; either |
| 8 | + version 2.1 of the License, or (at your option) any later version. |
| 9 | +
|
| 10 | + This library is distributed in the hope that it will be useful, |
| 11 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | + Lesser General Public License for more details. |
| 14 | +
|
| 15 | + You should have received a copy of the GNU Lesser General Public |
| 16 | + License along with this library; if not, write to the Free Software |
| 17 | + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | +*/ |
| 19 | + |
| 20 | +#ifndef ETHERNETSSLCLIENT_H |
| 21 | +#define ETHERNETSSLCLIENT_H |
| 22 | + |
| 23 | +#include "EthernetClient.h" |
| 24 | + |
| 25 | +#include <FATFileSystem.h> |
| 26 | +#include <MBRBlockDevice.h> |
| 27 | +#include <QSPIFBlockDevice.h> |
| 28 | + |
| 29 | +extern const char CA_CERTIFICATES[]; |
| 30 | + |
| 31 | +namespace arduino { |
| 32 | + |
| 33 | +class EthernetSSLClient : public arduino::EthernetClient { |
| 34 | + |
| 35 | +public: |
| 36 | + EthernetSSLClient(); |
| 37 | + virtual ~EthernetSSLClient() { |
| 38 | + stop(); |
| 39 | + } |
| 40 | + |
| 41 | + int connect(IPAddress ip, uint16_t port) { |
| 42 | + return connectSSL(ip, port); |
| 43 | + } |
| 44 | + int connect(const char* host, uint16_t port) { |
| 45 | + return connectSSL(host, port, _disableSNI); |
| 46 | + } |
| 47 | + void disableSNI(bool statusSNI) { |
| 48 | + _disableSNI = statusSNI; |
| 49 | + } |
| 50 | + |
| 51 | +private: |
| 52 | + int setRootCA() { |
| 53 | + |
| 54 | + QSPIFBlockDevice root; |
| 55 | + mbed::MBRBlockDevice wifi_data(&root, 1); |
| 56 | + mbed::FATFileSystem wifi("wlan"); |
| 57 | + |
| 58 | + int err = wifi.mount(&wifi_data); |
| 59 | + if (err) |
| 60 | + return err; |
| 61 | + |
| 62 | + return ((TLSSocket*)sock)->set_root_ca_cert_path("/wlan/"); |
| 63 | + } |
| 64 | + |
| 65 | + bool _disableSNI; |
| 66 | +}; |
| 67 | + |
| 68 | +} |
| 69 | + |
| 70 | +#endif /* EthernetSSLCLIENT_H */ |
0 commit comments