2021-02-18 11:14:35 +01:00
|
|
|
// Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2018-04-16 16:34:39 +02:00
|
|
|
|
|
|
|
#ifndef WiFiClientSecure_h
|
|
|
|
#define WiFiClientSecure_h
|
|
|
|
#include "Arduino.h"
|
|
|
|
#include "IPAddress.h"
|
|
|
|
#include <WiFi.h>
|
|
|
|
#include "ssl_client.h"
|
|
|
|
|
|
|
|
class WiFiClientSecure : public WiFiClient
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
sslclient_context *sslclient;
|
|
|
|
|
|
|
|
int _lastError = 0;
|
|
|
|
int _peek = -1;
|
2019-04-15 17:19:49 +02:00
|
|
|
int _timeout = 0;
|
2020-12-21 00:09:37 +01:00
|
|
|
bool _use_insecure;
|
2018-04-16 16:34:39 +02:00
|
|
|
const char *_CA_cert;
|
|
|
|
const char *_cert;
|
|
|
|
const char *_private_key;
|
2018-12-03 16:17:55 +01:00
|
|
|
const char *_pskIdent; // identity for PSK cipher suites
|
|
|
|
const char *_psKey; // key in hex for PSK cipher suites
|
2018-04-16 16:34:39 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
WiFiClientSecure *next;
|
|
|
|
WiFiClientSecure();
|
|
|
|
WiFiClientSecure(int socket);
|
|
|
|
~WiFiClientSecure();
|
|
|
|
int connect(IPAddress ip, uint16_t port);
|
2019-04-15 17:19:49 +02:00
|
|
|
int connect(IPAddress ip, uint16_t port, int32_t timeout);
|
2018-04-16 16:34:39 +02:00
|
|
|
int connect(const char *host, uint16_t port);
|
2019-04-15 17:19:49 +02:00
|
|
|
int connect(const char *host, uint16_t port, int32_t timeout);
|
2018-04-16 16:34:39 +02:00
|
|
|
int connect(IPAddress ip, uint16_t port, const char *rootCABuff, const char *cli_cert, const char *cli_key);
|
|
|
|
int connect(const char *host, uint16_t port, const char *rootCABuff, const char *cli_cert, const char *cli_key);
|
2018-12-03 16:17:55 +01:00
|
|
|
int connect(IPAddress ip, uint16_t port, const char *pskIdent, const char *psKey);
|
|
|
|
int connect(const char *host, uint16_t port, const char *pskIdent, const char *psKey);
|
2018-04-16 16:34:39 +02:00
|
|
|
int peek();
|
|
|
|
size_t write(uint8_t data);
|
|
|
|
size_t write(const uint8_t *buf, size_t size);
|
|
|
|
int available();
|
|
|
|
int read();
|
|
|
|
int read(uint8_t *buf, size_t size);
|
|
|
|
void flush() {}
|
|
|
|
void stop();
|
|
|
|
uint8_t connected();
|
|
|
|
int lastError(char *buf, const size_t size);
|
2020-12-21 00:09:37 +01:00
|
|
|
void setInsecure(); // Don't validate the chain, just accept whatever is given. VERY INSECURE!
|
2018-12-03 16:17:55 +01:00
|
|
|
void setPreSharedKey(const char *pskIdent, const char *psKey); // psKey in Hex
|
2018-04-16 16:34:39 +02:00
|
|
|
void setCACert(const char *rootCA);
|
|
|
|
void setCertificate(const char *client_ca);
|
|
|
|
void setPrivateKey (const char *private_key);
|
2018-11-19 16:50:08 +01:00
|
|
|
bool loadCACert(Stream& stream, size_t size);
|
|
|
|
bool loadCertificate(Stream& stream, size_t size);
|
|
|
|
bool loadPrivateKey(Stream& stream, size_t size);
|
2018-05-14 13:00:40 +02:00
|
|
|
bool verify(const char* fingerprint, const char* domain_name);
|
2018-11-26 23:25:08 +01:00
|
|
|
void setHandshakeTimeout(unsigned long handshake_timeout);
|
2018-04-16 16:34:39 +02:00
|
|
|
|
2019-09-16 18:14:32 +02:00
|
|
|
int setTimeout(uint32_t seconds){ return 0; }
|
|
|
|
|
2018-04-16 16:34:39 +02:00
|
|
|
operator bool()
|
|
|
|
{
|
|
|
|
return connected();
|
|
|
|
}
|
|
|
|
WiFiClientSecure &operator=(const WiFiClientSecure &other);
|
|
|
|
bool operator==(const bool value)
|
|
|
|
{
|
|
|
|
return bool() == value;
|
|
|
|
}
|
|
|
|
bool operator!=(const bool value)
|
|
|
|
{
|
|
|
|
return bool() != value;
|
|
|
|
}
|
|
|
|
bool operator==(const WiFiClientSecure &);
|
|
|
|
bool operator!=(const WiFiClientSecure &rhs)
|
|
|
|
{
|
|
|
|
return !this->operator==(rhs);
|
|
|
|
};
|
|
|
|
|
|
|
|
int socket()
|
|
|
|
{
|
|
|
|
return sslclient->socket = -1;
|
|
|
|
}
|
|
|
|
|
2018-11-19 16:50:08 +01:00
|
|
|
private:
|
|
|
|
char *_streamLoad(Stream& stream, size_t size);
|
|
|
|
|
2018-04-16 16:34:39 +02:00
|
|
|
//friend class WiFiServer;
|
|
|
|
using Print::write;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _WIFICLIENT_H_ */
|