diff --git a/docs/html/_s_s_l_client_8cpp.html b/docs/html/_s_s_l_client_8cpp.html new file mode 100644 index 0000000..2717c69 --- /dev/null +++ b/docs/html/_s_s_l_client_8cpp.html @@ -0,0 +1,130 @@ + + +
+ + + + +
+ SSLClient
+ v1.3.0
+
+ Add TLS 1.2 functionality to any network library.
+ |
+
#include "SSLClient.h"
+Variables | |
char * | __brkval |
char* __brkval | +
#include "Client.h"
#include "SSLClientImpl.h"
#include "SSLSession.h"
#include "SSLClientParameters.h"
#include "SSLObj.h"
#include <vector>
Go to the source code of this file.
Classes | |
class | SSLClient< C, SessionCache > |
class | SSLClient |
The main SSLClient class. Check out README.md for more info. More... | |
-Macros | |
#define | SSLClient_H_ |
#define SSLClient_H_ | -
#include "bearssl.h"
#include "Arduino.h"
#include "IPAddress.h"
Go to the source code of this file.
Cssl_pem_decode_state | |
CSSLClient | The main SSLClient class. Check out README.md for more info |
CSSLClientImpl | Implementation code to be inherited by SSLClient |
CSSLClientParameters | This struct stores data required for SSLClient to use mutual authentication |
CSSLSession | This class stores values which allow SSLClient to save and resume SSL sessions |
CSSLClientParameters | This struct stores data required for SSLClient to use mutual authentication |
CSSLSession | This class stores values which allow SSLClient to save and resume SSL sessions |
This is the complete list of members for SSLClient< C, SessionCache >, including all inherited members.
+This is the complete list of members for SSLClient, including all inherited members.
available() override | SSLClient< C, SessionCache > | inline |
available_impl() | SSLClientImpl | |
connect(IPAddress ip, uint16_t port) override | SSLClient< C, SessionCache > | inline |
connect(const char *host, uint16_t port) override | SSLClient< C, SessionCache > | inline |
connect_impl(IPAddress ip, uint16_t port) | SSLClientImpl | |
connect_impl(const char *host, uint16_t port) | SSLClientImpl | |
connected() override | SSLClient< C, SessionCache > | inline |
connected_impl() | SSLClientImpl | |
flush() override | SSLClient< C, SessionCache > | inline |
flush_impl() | SSLClientImpl | |
get_arduino_client() override | SSLClient< C, SessionCache > | inlineprotectedvirtual |
get_arduino_client() const override | SSLClient< C, SessionCache > | inlineprotectedvirtual |
get_session_array() override | SSLClient< C, SessionCache > | inlineprotectedvirtual |
get_session_array() const override | SSLClient< C, SessionCache > | inlineprotectedvirtual |
get_session_impl(const char *host, const IPAddress &addr) | SSLClientImpl | |
getClient() | SSLClient< C, SessionCache > | inline |
getSession(const char *host, const IPAddress &addr) | SSLClient< C, SessionCache > | inline |
getSessionCount() const override | SSLClient< C, SessionCache > | inlinevirtual |
localPort() override | SSLClient< C, SessionCache > | inlinevirtual |
m_error(const T str, const char *func_name) const | SSLClientImpl | inlineprotected |
m_info(const T str, const char *func_name) const | SSLClientImpl | inlineprotected |
m_print(const T str, const char *func_name, const DebugLevel level) const | SSLClientImpl | inlineprotected |
m_print_br_error(const unsigned br_error_code, const DebugLevel level) const | SSLClientImpl | protected |
m_print_prefix(const char *func_name, const DebugLevel level) const | SSLClientImpl | protected |
m_print_ssl_error(const int ssl_error, const DebugLevel level) const | SSLClientImpl | protected |
m_warn(const T str, const char *func_name) const | SSLClientImpl | inlineprotected |
operator bool() | SSLClient< C, SessionCache > | inline |
operator!=(const bool value) | SSLClient< C, SessionCache > | inline |
operator!=(const C &rhs) | SSLClient< C, SessionCache > | inline |
operator==(const bool value) | SSLClient< C, SessionCache > | inline |
operator==(const C &rhs) | SSLClient< C, SessionCache > | inline |
peek() override | SSLClient< C, SessionCache > | inline |
peek_impl() | SSLClientImpl | |
read() override | SSLClient< C, SessionCache > | inline |
read(uint8_t *buf, size_t size) override | SSLClient< C, SessionCache > | inline |
read_impl(uint8_t *buf, size_t size) | SSLClientImpl | |
remoteIP() override | SSLClient< C, SessionCache > | inlinevirtual |
remotePort() override | SSLClient< C, SessionCache > | inlinevirtual |
remove_session_impl(const char *host, const IPAddress &addr) | SSLClientImpl | |
removeSession(const char *host, const IPAddress &addr) | SSLClient< C, SessionCache > | inline |
set_mutual_impl(const SSLClientParameters *params) | SSLClientImpl | |
setMutualAuthParams(const SSLClientParameters *params) | SSLClient< C, SessionCache > | inline |
SSLClient(const C &client, const br_x509_trust_anchor *trust_anchors, const size_t trust_anchors_num, const int analog_pin, const DebugLevel debug=SSL_WARN) | SSLClient< C, SessionCache > | inlineexplicit |
SSLClientImpl(const br_x509_trust_anchor *trust_anchors, const size_t trust_anchors_num, const int analog_pin, const DebugLevel debug) | SSLClientImpl | explicit |
SSLClientImpl(const br_x509_trust_anchor *trust_anchors, const size_t trust_anchors_num, const int analog_pin, const DebugLevel debug, const SSLClientParameters *mutual_auth_params) | SSLClientImpl | explicit |
stop() override | SSLClient< C, SessionCache > | inline |
stop_impl() | SSLClientImpl | |
write(uint8_t b) override | SSLClient< C, SessionCache > | inline |
write(const uint8_t *buf, size_t size) override | SSLClient< C, SessionCache > | inline |
write_impl(const uint8_t *buf, size_t size) | SSLClientImpl | |
available() override | SSLClient | |
connect(IPAddress ip, uint16_t port) override | SSLClient | |
connect(const char *host, uint16_t port) override | SSLClient | |
connected() override | SSLClient | |
DebugLevel enum name | SSLClient | |
Error enum name | SSLClient | |
flush() override | SSLClient | |
getClient() | SSLClient | inline |
getSession(const char *host) | SSLClient | |
getSessionCount() const | SSLClient | inline |
operator bool() | SSLClient | inline |
peek() override | SSLClient | |
read(uint8_t *buf, size_t size) override | SSLClient | |
read() override | SSLClient | inline |
removeSession(const char *host) | SSLClient | |
setMutualAuthParams(const SSLClientParameters *params) | SSLClient | |
SSL_BR_CONNECT_FAIL enum value | SSLClient | |
SSL_BR_WRITE_ERROR enum value | SSLClient | |
SSL_CLIENT_CONNECT_FAIL enum value | SSLClient | |
SSL_CLIENT_WRTIE_ERROR enum value | SSLClient | |
SSL_ERROR enum value | SSLClient | |
SSL_INFO enum value | SSLClient | |
SSL_INTERNAL_ERROR enum value | SSLClient | |
SSL_NONE enum value | SSLClient | |
SSL_OK enum value | SSLClient | |
SSL_OUT_OF_MEMORY enum value | SSLClient | |
SSL_WARN enum value | SSLClient | |
SSLClient(Client &client, const br_x509_trust_anchor *trust_anchors, const size_t trust_anchors_num, const int analog_pin, const size_t max_sessions=1, const DebugLevel debug=SSL_WARN) | SSLClient | explicit |
stop() override | SSLClient | |
write(const uint8_t *buf, size_t size) override | SSLClient | |
write(uint8_t b) override | SSLClient | inline |
#include <SSLClient.h>
+Public Types | |
enum | Error { + SSL_OK = 0, +SSL_CLIENT_CONNECT_FAIL, +SSL_BR_CONNECT_FAIL, +SSL_CLIENT_WRTIE_ERROR, + + SSL_BR_WRITE_ERROR, +SSL_INTERNAL_ERROR, +SSL_OUT_OF_MEMORY + + } |
Static constants defining the possible errors encountered. More... | |
enum | DebugLevel { SSL_NONE = 0, +SSL_ERROR = 1, +SSL_WARN = 2, +SSL_INFO = 3 + } |
Level of verbosity used in logging for SSLClient. More... | |
Public Member Functions | |
SSLClient (const C &client, const br_x509_trust_anchor *trust_anchors, const size_t trust_anchors_num, const int analog_pin, const DebugLevel debug=SSL_WARN) | |
Initialize SSLClient with all of the prerequisites needed. More... | |
int | connect (IPAddress ip, uint16_t port) override |
Connect over SSL to a host specified by an IP address. More... | |
int | connect (const char *host, uint16_t port) override |
Connect over SSL to a host specified by a hostname. More... | |
size_t | write (uint8_t b) override |
size_t | write (const uint8_t *buf, size_t size) override |
Write some bytes to the SSL connection. More... | |
int | available () override |
Returns the number of bytes available to read from the data that has been received and decrypted. More... | |
int | read () override |
Read a single byte, or -1 if none is available. More... | |
int | read (uint8_t *buf, size_t size) override |
Read size bytes from the SSL client buffer, copying them into *buf, and return the number of bytes read. More... | |
int | peek () override |
View the first byte of the buffer, without removing it from the SSLClient Buffer. More... | |
void | flush () override |
Force writing the buffered bytes from SSLClient::write to the network. More... | |
void | stop () override |
Close the connection. More... | |
uint8_t | connected () override |
Check if the device is connected. More... | |
void | setMutualAuthParams (const SSLClientParameters *params) |
Add a client certificate and enable support for mutual auth. More... | |
SSLSession & | getSession (const char *host, const IPAddress &addr) |
Gets a session reference corresponding to a host and IP, or a reference to a empty session if none exist. More... | |
void | removeSession (const char *host, const IPAddress &addr) |
Clear the session corresponding to a host and IP. More... | |
size_t | getSessionCount () const override |
Get the maximum number of SSL sessions that can be stored at once. More... | |
operator bool () | |
Equivalent to SSLClient::connected() > 0. More... | |
bool | operator== (const bool value) |
bool | operator!= (const bool value) |
bool | operator== (const C &rhs) |
Returns whether or not two SSLClient objects have the same underlying client object. More... | |
bool | operator!= (const C &rhs) |
Returns whether or not two SSLClient objects do not have the same underlying client object. More... | |
uint16_t | localPort () override |
Returns the local port, if C::localPort exists. More... | |
IPAddress | remoteIP () override |
Returns the remote IP, if C::remoteIP exists. More... | |
uint16_t | remotePort () override |
Returns the remote port, if C::remotePort exists. Else return 0. More... | |
C & | getClient () |
Returns a reference to the client object stored in this class. Take care not to break it. More... | |
Public Member Functions inherited from SSLClientImpl | |
SSLClientImpl (const br_x509_trust_anchor *trust_anchors, const size_t trust_anchors_num, const int analog_pin, const DebugLevel debug) | |
SSLClientImpl (const br_x509_trust_anchor *trust_anchors, const size_t trust_anchors_num, const int analog_pin, const DebugLevel debug, const SSLClientParameters *mutual_auth_params) | |
int | connect_impl (IPAddress ip, uint16_t port) |
int | connect_impl (const char *host, uint16_t port) |
size_t | write_impl (const uint8_t *buf, size_t size) |
int | available_impl () |
int | read_impl (uint8_t *buf, size_t size) |
int | peek_impl () |
void | flush_impl () |
void | stop_impl () |
uint8_t | connected_impl () |
SSLSession & | get_session_impl (const char *host, const IPAddress &addr) |
void | remove_session_impl (const char *host, const IPAddress &addr) |
void | set_mutual_impl (const SSLClientParameters *params) |
-Protected Member Functions | |
Client & | get_arduino_client () override |
Returns an instance of m_client that is polymorphic and can be used by SSLClientImpl. More... | |
const Client & | get_arduino_client () const override |
SSLSession * | get_session_array () override |
Returns an instance of the session array that is on the stack. More... | |
const SSLSession * | get_session_array () const override |
Protected Member Functions inherited from SSLClientImpl | |
void | m_print_prefix (const char *func_name, const DebugLevel level) const |
Prints a debugging prefix to all logs, so we can attatch them to useful information. More... | |
void | m_print_ssl_error (const int ssl_error, const DebugLevel level) const |
Prints the string associated with a write error. More... | |
void | m_print_br_error (const unsigned br_error_code, const DebugLevel level) const |
Print the text string associated with a BearSSL error code. More... | |
template<typename T > | |
void | m_print (const T str, const char *func_name, const DebugLevel level) const |
debugging print function, only prints if m_debug is true More... | |
template<typename T > | |
void | m_info (const T str, const char *func_name) const |
Prints a info message to serial, if info messages are enabled. More... | |
template<typename T > | |
void | m_warn (const T str, const char *func_name) const |
template<typename T > | |
void | m_error (const T str, const char *func_name) const |
SSLClient (Client &client, const br_x509_trust_anchor *trust_anchors, const size_t trust_anchors_num, const int analog_pin, const size_t max_sessions=1, const DebugLevel debug=SSL_WARN) | |
Initialize SSLClient with all of the prerequisites needed. More... | |
int | connect (IPAddress ip, uint16_t port) override |
Connect over SSL to a host specified by an IP address. More... | |
int | connect (const char *host, uint16_t port) override |
Connect over SSL to a host specified by a hostname. More... | |
size_t | write (const uint8_t *buf, size_t size) override |
Write some bytes to the SSL connection. More... | |
size_t | write (uint8_t b) override |
int | available () override |
Returns the number of bytes available to read from the data that has been received and decrypted. More... | |
int | read (uint8_t *buf, size_t size) override |
Read size bytes from the SSL client buffer, copying them into *buf, and return the number of bytes read. More... | |
int | read () override |
Read a single byte, or -1 if none is available. More... | |
int | peek () override |
View the first byte of the buffer, without removing it from the SSLClient Buffer. More... | |
void | flush () override |
Force writing the buffered bytes from SSLClient::write to the network. More... | |
void | stop () override |
Close the connection. More... | |
uint8_t | connected () override |
Check if the device is connected. More... | |
void | setMutualAuthParams (const SSLClientParameters *params) |
Add a client certificate and enable support for mutual auth. More... | |
SSLSession * | getSession (const char *host) |
Gets a session reference corresponding to a host and IP, or a reference to a empty session if none exist. More... | |
void | removeSession (const char *host) |
Clear the session corresponding to a host and IP. More... | |
size_t | getSessionCount () const |
Get the maximum number of SSL sessions that can be stored at once. More... | |
operator bool () | |
Equivalent to SSLClient::connected() > 0. More... | |
Client & | getClient () |
Returns a reference to the client object stored in this class. Take care not to break it. More... | |
The main SSLClient class. Check out README.md for more info.
-enum SSLClient::DebugLevel | +
Level of verbosity used in logging for SSLClient.
+Use these values when initializing SSLClient to set how many logs you would like to see in the Serial monitor.
+enum SSLClient::Error | +
Static constants defining the possible errors encountered.
+If SSLClient encounters an error, it will generally output logs into the serial monitor. If you need a way of programmatically checking the errors, you can do so with SSLClient::getWriteError(), which will return one of these values.
+Enumerator | |
---|---|
SSL_OK | |
SSL_CLIENT_CONNECT_FAIL | The underlying client failed to connect, probably not an issue with SSL + |
SSL_BR_CONNECT_FAIL | BearSSL failed to complete the SSL handshake, check logs for bear ssl error output + |
SSL_CLIENT_WRTIE_ERROR | The underlying client failed to write a payload, probably not an issue with SSL + |
SSL_BR_WRITE_ERROR | An internal error occurred with BearSSL, check logs for diagnosis. + |
SSL_INTERNAL_ERROR | An internal error occurred with SSLClient, and you probably need to submit an issue on Github. + |
SSL_OUT_OF_MEMORY | SSLClient detected that there was not enough memory (>8000 bytes) to continue. + |
|
-inlineexplicit | +explicit
|
-inlineoverride | +override
Returns the number of bytes available to read from the data that has been received and decrypted.
-This function updates the state of the SSL engine (including writing any data, see SSLClient::write) and as a result should be called periodically when expecting data. Additionally, since if there are no bytes and if SSLClient::connected is false this function returns zero (this same behavior is found in EthernetClient), it is prudent to ensure in your own code that the preconditions are met before checking this function to prevent an ambiguous result.
+This function updates the state of the SSL engine (including writing any data, see SSLClient::write) and as a result should be called periodically when expecting data. Additionally, since if there are no bytes and if SSLClient::connected is false this function returns zero (this same behavior is found in EthernetClient), it is prudent to ensure in your own code that the preconditions are met before checking this function to prevent an ambiguous result.
The implementation for this function can be found in SSLClientImpl::available
-
|
-inlineoverride | +override
SSLClient::connect(host, port) should be preferred over this function, as verifying the domain name is a step in ensuring the certificate is legitimate, which is important to the security of the device. Additionally, SSL sessions cannot be resumed when using this function, which can drastically increase initial connect time.
This function initializes the socket by calling m_client::connect(IPAddress, uint16_t) with the parameters supplied, then once the socket is open, uses BearSSL to to complete a SSL handshake. Due to the design of the SSL standard, this function will probably take an extended period (1-4sec) to negotiate the handshake and finish the connection. This function runs until the SSL handshake succeeds or fails.
SSL requires the client to generate some random bits (to be later combined with some random bits from the server), so SSLClient uses the least significant bits from the analog pin supplied in the constructor. The random bits are generated from 16 consecutive analogReads, and given to BearSSL before the handshake starts.
-The implementation for this function can be found in SSLClientImpl::connect_impl(IPAddress, uint16_t).
+The implementation for this function can be found in SSLClientImpl::connect_impl(IPAddress, uint16_t).
|
-inlineoverride | +override
This function initializes the socket by calling m_client::connect(const char*, uint16_t) with the parameters supplied, then once the socket is open, uses BearSSL to complete a SSL handshake. This function runs until the SSL handshake succeeds or fails.
SSL requires the client to generate some random bits (to be later combined with some random bits from the server), so SSLClient uses the least significant bits from the analog pin supplied in the constructor. The random bits are generated from 16 consecutive analogReads, and given to BearSSL before the handshake starts.
This function will usually take around 4-10 seconds. If possible, this function also attempts to resume the SSL session if one is present matching the hostname string, which will reduce connection time to 100-500ms. To read more about this functionality, check out Session Caching in the README.
-The implementation for this function can be found in SSLClientImpl::connect_impl(const char*, uint16_t)
+The implementation for this function can be found in SSLClientImpl::connect_impl(const char*, uint16_t)
|
-inlineoverride | +override
Check if the device is connected.
-Use this function to determine if SSLClient is still connected and a SSL connection is active. It should be noted that this function should be called before SSLClient::available– both functions send and receive data with the SSLClient::m_client device, however SSLClient::available has some delays built in to protect SSLClient::m_client from being polled too frequently, and SSLClient::connected contains logic to ensure that if the socket is dropped SSLClient will react accordingly.
-The implementation for this function can be found in SSLClientImpl::connected_impl.
+Use this function to determine if SSLClient is still connected and a SSL connection is active. It should be noted that this function should be called before SSLClient::available– both functions send and receive data with the SSLClient::m_client device, however SSLClient::available has some delays built in to protect SSLClient::m_client from being polled too frequently, and SSLClient::connected contains logic to ensure that if the socket is dropped SSLClient will react accordingly.
+The implementation for this function can be found in SSLClientImpl::connected_impl.
|
-inlineoverride | +override
Force writing the buffered bytes from SSLClient::write to the network.
-This function is blocking until all bytes from the buffer are written. For an explanation of how writing with SSLClient works, please see SSLClient::write. The implementation for this function can be found in SSLClientImpl::flush.
+Force writing the buffered bytes from SSLClient::write to the network.
+This function is blocking until all bytes from the buffer are written. For an explanation of how writing with SSLClient works, please see SSLClient::write. The implementation for this function can be found in SSLClientImpl::flush.
|
- -inlineoverrideprotectedvirtual | -
Returns an instance of m_client that is polymorphic and can be used by SSLClientImpl.
- -Implements SSLClientImpl.
- -
-
|
- -inlineoverrideprotectedvirtual | -
Implements SSLClientImpl.
- -
-
|
- -inlineoverrideprotectedvirtual | -
Returns an instance of the session array that is on the stack.
- -Implements SSLClientImpl.
- -
-
|
- -inlineoverrideprotectedvirtual | -
Implements SSLClientImpl.
- -
-
Gets a session reference corresponding to a host and IP, or a reference to a empty session if none exist. If no session corresponding to the host and IP exist, then this function will cycle through sessions in a rotating order. This allows the session cache to continually store sessions, however it will also result in old sessions being cleared and returned. In general, it is a good idea to use a SessionCache size equal to the number of domains you plan on connecting to. -The implementation for this function can be found at SSLClientImpl::get_session_impl. +The implementation for this function can be found at SSLClientImpl::get_session_impl.
◆ getSessionCount()+ +◆ getSessionCount()
-
-template<class C , size_t SessionCache = 1>
@@ -770,54 +612,19 @@ template<class C , size_t SessionCache = 1>
Get the maximum number of SSL sessions that can be stored at once.
Implements SSLClientImpl. -◆ localPort()+ +◆ operator bool()
-
-template<class C , size_t SessionCache = 1>
-
-
-Returns the local port, if C::localPort exists. - -Implements SSLClientImpl. - -◆ operator bool()- -
-
-
-template<class C , size_t SessionCache = 1>
-
|