mirror of https://github.com/ARMmbed/mbed-os.git
Doxygen corrections to DTLSSocket.h, TLSSocket.h, TLSSocketWrapper.h and DTLSSocketWrapper.h
parent
c2718e3666
commit
02e2704db0
|
@ -29,11 +29,16 @@
|
||||||
// This class requires Mbed TLS SSL/TLS client code
|
// This class requires Mbed TLS SSL/TLS client code
|
||||||
#if defined(MBEDTLS_SSL_CLI_C) || defined(DOXYGEN_ONLY)
|
#if defined(MBEDTLS_SSL_CLI_C) || defined(DOXYGEN_ONLY)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief DTLSSocket implement DTLS stream over the existing Socket transport
|
||||||
|
*/
|
||||||
|
|
||||||
class DTLSSocket : public DTLSSocketWrapper {
|
class DTLSSocket : public DTLSSocketWrapper {
|
||||||
public:
|
public:
|
||||||
/** Create an uninitialized DTLS socket
|
/** Create an uninitialized DTLS socket.
|
||||||
*
|
*
|
||||||
* Must call open to initialize the socket on a network stack.
|
* Must call open to initialize the socket on a network stack.
|
||||||
|
* @param _udp_socket Underlying transport socket.
|
||||||
*/
|
*/
|
||||||
DTLSSocket() : DTLSSocketWrapper(&_udp_socket) {}
|
DTLSSocket() : DTLSSocketWrapper(&_udp_socket) {}
|
||||||
|
|
||||||
|
@ -41,14 +46,14 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual ~DTLSSocket();
|
virtual ~DTLSSocket();
|
||||||
|
|
||||||
/** Create a socket on a network interface
|
/** Create a socket on a network interface.
|
||||||
*
|
*
|
||||||
* Creates and opens a socket on the network stack of the given
|
* Creates and opens a socket on the network stack of the given
|
||||||
* network interface.
|
* network interface.
|
||||||
* If hostname is also given, user is not required to call set_hostname() later.
|
* If hostname is also given, user is not required to call set_hostname() later.
|
||||||
*
|
*
|
||||||
* @param stack Network stack as target for socket
|
* @param stack Network stack as target for socket.
|
||||||
* @param hostname Hostname used for certificate verification
|
* @param hostname Hostname used for certificate verification.
|
||||||
*/
|
*/
|
||||||
template <typename S>
|
template <typename S>
|
||||||
DTLSSocket(S *stack, const char *hostname = NULL) : DTLSSocketWrapper(&_udp_socket, hostname)
|
DTLSSocket(S *stack, const char *hostname = NULL) : DTLSSocketWrapper(&_udp_socket, hostname)
|
||||||
|
@ -57,14 +62,14 @@ public:
|
||||||
MBED_ASSERT(ret == NSAPI_ERROR_OK);
|
MBED_ASSERT(ret == NSAPI_ERROR_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Opens a socket
|
/** Opens a socket.
|
||||||
*
|
*
|
||||||
* Creates a network socket on the network stack of the given
|
* Creates a network socket on the network stack of the given
|
||||||
* network interface. Not needed if stack is passed to the
|
* network interface. Not needed if stack is passed to the
|
||||||
* socket's constructor.
|
* socket's constructor.
|
||||||
*
|
*
|
||||||
* @param stack Network stack as target for socket
|
* @param stack Network stack as target for socket.
|
||||||
* @return 0 on success, negative error code on failure
|
* @return 0 on success, negative error code on failure.
|
||||||
*/
|
*/
|
||||||
virtual nsapi_error_t open(NetworkStack *stack)
|
virtual nsapi_error_t open(NetworkStack *stack)
|
||||||
{
|
{
|
||||||
|
@ -79,14 +84,14 @@ public:
|
||||||
|
|
||||||
using DTLSSocketWrapper::connect;
|
using DTLSSocketWrapper::connect;
|
||||||
|
|
||||||
/** Connects TCP socket to a remote host
|
/** Connects TCP socket to a remote host.
|
||||||
*
|
*
|
||||||
* Initiates a connection to a remote server specified by either
|
* Initiates a connection to a remote server specified by either
|
||||||
* a domain name or an IP address and a port.
|
* a domain name or an IP address and a port.
|
||||||
*
|
*
|
||||||
* @param host Hostname of the remote host
|
* @param host Hostname of the remote host.
|
||||||
* @param port Port of the remote host
|
* @param port Port of the remote host.
|
||||||
* @return 0 on success, negative error code on failure
|
* @return 0 on success, negative error code on failure.
|
||||||
*/
|
*/
|
||||||
nsapi_error_t connect(const char *host, uint16_t port);
|
nsapi_error_t connect(const char *host, uint16_t port);
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/** @file DTLSSocketWrapper.h DTLSSocketWrapper */
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 ARM Limited
|
* Copyright (c) 2018 ARM Limited
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
@ -14,6 +15,9 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
/** @addtogroup netsocket
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef DTLSSOCKETWRAPPER_H
|
#ifndef DTLSSOCKETWRAPPER_H
|
||||||
#define DTLSSOCKETWRAPPER_H
|
#define DTLSSOCKETWRAPPER_H
|
||||||
|
@ -23,8 +27,17 @@
|
||||||
// This class requires Mbed TLS SSL/TLS client code
|
// This class requires Mbed TLS SSL/TLS client code
|
||||||
#if defined(MBEDTLS_SSL_CLI_C) || defined(DOXYGEN_ONLY)
|
#if defined(MBEDTLS_SSL_CLI_C) || defined(DOXYGEN_ONLY)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief DTLSSocketWrapper implement DTLS stream over the existing Socket transport
|
||||||
|
*/
|
||||||
class DTLSSocketWrapper : public TLSSocketWrapper {
|
class DTLSSocketWrapper : public TLSSocketWrapper {
|
||||||
public:
|
public:
|
||||||
|
/** Create a DTLSSocketWrapper.
|
||||||
|
*
|
||||||
|
* @param transport Underlying transport socket to wrap.
|
||||||
|
* @param hostname Hostname of the remote host, used for certificate checking.
|
||||||
|
* @param control Transport control mode. See @ref control_transport.
|
||||||
|
*/
|
||||||
DTLSSocketWrapper(Socket *transport, const char *hostname = NULL, control_transport control = TRANSPORT_CONNECT_AND_CLOSE);
|
DTLSSocketWrapper(Socket *transport, const char *hostname = NULL, control_transport control = TRANSPORT_CONNECT_AND_CLOSE);
|
||||||
private:
|
private:
|
||||||
static void timing_set_delay(void *ctx, uint32_t int_ms, uint32_t fin_ms);
|
static void timing_set_delay(void *ctx, uint32_t int_ms, uint32_t fin_ms);
|
||||||
|
@ -37,3 +50,4 @@ private:
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
/** @} */
|
|
@ -35,13 +35,14 @@
|
||||||
#if defined(MBEDTLS_SSL_CLI_C) || defined(DOXYGEN_ONLY)
|
#if defined(MBEDTLS_SSL_CLI_C) || defined(DOXYGEN_ONLY)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief TLSSocket a wrapper around TCPSocket for interacting with TLS servers
|
* \brief TLSSocket a wrapper around TCPSocket for interacting with TLS servers.
|
||||||
*/
|
*/
|
||||||
class TLSSocket : public TLSSocketWrapper {
|
class TLSSocket : public TLSSocketWrapper {
|
||||||
public:
|
public:
|
||||||
/** Create an uninitialized socket
|
/** Create an uninitialized socket.
|
||||||
*
|
*
|
||||||
* Must call open to initialize the socket on a network stack.
|
* Must call open to initialize the socket on a network stack.
|
||||||
|
* @param tcp_socket Underlying transport socket.
|
||||||
*/
|
*/
|
||||||
TLSSocket() : TLSSocketWrapper(&tcp_socket) {}
|
TLSSocket() : TLSSocketWrapper(&tcp_socket) {}
|
||||||
|
|
||||||
|
@ -49,17 +50,16 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual ~TLSSocket();
|
virtual ~TLSSocket();
|
||||||
|
|
||||||
/** Opens a socket
|
/** Opens a socket.
|
||||||
*
|
*
|
||||||
* Creates a network socket on the network stack of the given
|
* Creates a network socket on the network stack of the given
|
||||||
* network interface. Not needed if stack is passed to the
|
* network interface.
|
||||||
* socket's constructor.
|
|
||||||
*
|
*
|
||||||
* @note TLSSocket cannot be reopened after closing. It should be destructed to
|
* @note TLSSocket cannot be reopened after closing. It should be destructed to
|
||||||
* clear internal TLS memory structures.
|
* clear internal TLS memory structures.
|
||||||
*
|
*
|
||||||
* @param stack Network stack as target for socket
|
* @param stack Network stack as target for socket.
|
||||||
* @return 0 on success, negative error code on failure
|
* @return 0 on success, negative error code on failure.
|
||||||
*/
|
*/
|
||||||
virtual nsapi_error_t open(NetworkStack *stack)
|
virtual nsapi_error_t open(NetworkStack *stack)
|
||||||
{
|
{
|
||||||
|
@ -74,14 +74,14 @@ public:
|
||||||
|
|
||||||
using TLSSocketWrapper::connect;
|
using TLSSocketWrapper::connect;
|
||||||
|
|
||||||
/** Connects TCP socket to a remote host
|
/** Connects TCP socket to a remote host.
|
||||||
*
|
*
|
||||||
* Initiates a connection to a remote server specified by either
|
* Initiates a connection to a remote server specified by either
|
||||||
* a domain name or an IP address and a port.
|
* a domain name or an IP address and a port.
|
||||||
*
|
*
|
||||||
* @param host Hostname of the remote host
|
* @param host Hostname of the remote host.
|
||||||
* @param port Port of the remote host
|
* @param port Port of the remote host.
|
||||||
* @return 0 on success, negative error code on failure
|
* @return 0 on success, negative error code on failure.
|
||||||
*/
|
*/
|
||||||
nsapi_error_t connect(const char *host, uint16_t port);
|
nsapi_error_t connect(const char *host, uint16_t port);
|
||||||
|
|
||||||
|
|
|
@ -39,23 +39,25 @@
|
||||||
*/
|
*/
|
||||||
class TLSSocketWrapper : public Socket {
|
class TLSSocketWrapper : public Socket {
|
||||||
public:
|
public:
|
||||||
|
/** Transport modes */
|
||||||
enum control_transport {
|
enum control_transport {
|
||||||
TRANSPORT_KEEP,
|
TRANSPORT_KEEP, /**< Doesn't call connect() or close() on transport socket */
|
||||||
TRANSPORT_CONNECT_AND_CLOSE,
|
TRANSPORT_CONNECT_AND_CLOSE, /**< Does call connect() and close() on transport socket */
|
||||||
TRANSPORT_CONNECT,
|
TRANSPORT_CONNECT, /**< Does call only connect() on transport socket */
|
||||||
TRANSPORT_CLOSE,
|
TRANSPORT_CLOSE, /**< Does call close() on transport socket */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Create a TLSSocketWrapper
|
/** Create a TLSSocketWrapper.
|
||||||
*
|
*
|
||||||
* @param transport Underlying transport socket to wrap
|
* @param transport Underlying transport socket to wrap.
|
||||||
* @param hostname Hostname of the remote host, used for certificate checking
|
* @param hostname Hostname of the remote host, used for certificate checking.
|
||||||
|
* @param control Transport control mode. See @ref control_transport.
|
||||||
*/
|
*/
|
||||||
TLSSocketWrapper(Socket *transport, const char *hostname = NULL, control_transport control = TRANSPORT_CONNECT_AND_CLOSE);
|
TLSSocketWrapper(Socket *transport, const char *hostname = NULL, control_transport control = TRANSPORT_CONNECT_AND_CLOSE);
|
||||||
|
|
||||||
/** Destroy a socket wrapper
|
/** Destroy a socket wrapper.
|
||||||
*
|
*
|
||||||
* Closes socket wrapper if the socket wrapper is still open
|
* Closes socket wrapper if the socket wrapper is still open.
|
||||||
*/
|
*/
|
||||||
virtual ~TLSSocketWrapper();
|
virtual ~TLSSocketWrapper();
|
||||||
|
|
||||||
|
@ -64,6 +66,8 @@ public:
|
||||||
* TLSSocket requires hostname that is used to verify the certificate.
|
* TLSSocket requires hostname that is used to verify the certificate.
|
||||||
* If hostname is not given in constructor, this function must be used before
|
* If hostname is not given in constructor, this function must be used before
|
||||||
* starting the TLS handshake.
|
* starting the TLS handshake.
|
||||||
|
*
|
||||||
|
* @param hostname Hostname of the remote host, used for certificate checking.
|
||||||
*/
|
*/
|
||||||
void set_hostname(const char *hostname);
|
void set_hostname(const char *hostname);
|
||||||
|
|
||||||
|
@ -71,12 +75,14 @@ public:
|
||||||
*
|
*
|
||||||
* @param root_ca Root CA Certificate in any mbed-TLS supported format.
|
* @param root_ca Root CA Certificate in any mbed-TLS supported format.
|
||||||
* @param len Length of certificate (including terminating 0 for PEM).
|
* @param len Length of certificate (including terminating 0 for PEM).
|
||||||
|
* @return 0 on success, negative error code on failure.
|
||||||
*/
|
*/
|
||||||
nsapi_error_t set_root_ca_cert(const void *root_ca, size_t len);
|
nsapi_error_t set_root_ca_cert(const void *root_ca, size_t len);
|
||||||
|
|
||||||
/** Sets the certification of Root CA.
|
/** Sets the certification of Root CA.
|
||||||
*
|
*
|
||||||
* @param root_ca_pem Root CA Certificate in PEM format
|
* @param root_ca_pem Root CA Certificate in PEM format.
|
||||||
|
* @return 0 on success, negative error code on failure.
|
||||||
*/
|
*/
|
||||||
nsapi_error_t set_root_ca_cert(const char *root_ca_pem);
|
nsapi_error_t set_root_ca_cert(const char *root_ca_pem);
|
||||||
|
|
||||||
|
@ -84,8 +90,9 @@ public:
|
||||||
*
|
*
|
||||||
* @param client_cert client certification in PEM or DER format.
|
* @param client_cert client certification in PEM or DER format.
|
||||||
* @param client_cert_len certificate size including the terminating null byte for PEM data.
|
* @param client_cert_len certificate size including the terminating null byte for PEM data.
|
||||||
* @param client_private_key_pem client private key in PEM or DER format
|
* @param client_private_key_pem client private key in PEM or DER format.
|
||||||
* @param client_private_key_len key size including the terminating null byte for PEM data
|
* @param client_private_key_len key size including the terminating null byte for PEM data
|
||||||
|
* @return 0 on success, negative error code on failure.
|
||||||
*/
|
*/
|
||||||
nsapi_error_t set_client_cert_key(const void *client_cert, size_t client_cert_len,
|
nsapi_error_t set_client_cert_key(const void *client_cert, size_t client_cert_len,
|
||||||
const void *client_private_key_pem, size_t client_private_key_len);
|
const void *client_private_key_pem, size_t client_private_key_len);
|
||||||
|
@ -94,6 +101,7 @@ public:
|
||||||
*
|
*
|
||||||
* @param client_cert_pem Client certification in PEM format.
|
* @param client_cert_pem Client certification in PEM format.
|
||||||
* @param client_private_key_pem Client private key in PEM format.
|
* @param client_private_key_pem Client private key in PEM format.
|
||||||
|
* @return 0 on success, negative error code on failure.
|
||||||
*/
|
*/
|
||||||
nsapi_error_t set_client_cert_key(const char *client_cert_pem, const char *client_private_key_pem);
|
nsapi_error_t set_client_cert_key(const char *client_cert_pem, const char *client_private_key_pem);
|
||||||
|
|
||||||
|
@ -102,20 +110,19 @@ public:
|
||||||
* The socket must be connected to a remote host. Returns the number of
|
* The socket must be connected to a remote host. Returns the number of
|
||||||
* bytes sent from the buffer.
|
* bytes sent from the buffer.
|
||||||
*
|
*
|
||||||
* @param data Buffer of data to send to the host
|
* @param data Buffer of data to send to the host.
|
||||||
* @param size Size of the buffer in bytes
|
* @param size Size of the buffer in bytes.
|
||||||
* @return Number of sent bytes on success, negative error
|
* @return Number of sent bytes on success, negative error code on failure.
|
||||||
* code on failure
|
|
||||||
*/
|
*/
|
||||||
virtual nsapi_error_t send(const void *data, nsapi_size_t size);
|
virtual nsapi_error_t send(const void *data, nsapi_size_t size);
|
||||||
|
|
||||||
/** Receive data over a TLS socket
|
/** Receive data over a TLS socket.
|
||||||
*
|
*
|
||||||
* The socket must be connected to a remote host. Returns the number of
|
* The socket must be connected to a remote host. Returns the number of
|
||||||
* bytes received into the buffer.
|
* bytes received into the buffer.
|
||||||
*
|
*
|
||||||
* @param data Destination buffer for data received from the host
|
* @param data Destination buffer for data received from the host.
|
||||||
* @param size Size of the buffer in bytes
|
* @param size Size of the buffer in bytes.
|
||||||
* @return Number of received bytes on success, negative error
|
* @return Number of received bytes on success, negative error
|
||||||
* code on failure. If no data is available to be received
|
* code on failure. If no data is available to be received
|
||||||
* and the peer has performed an orderly shutdown,
|
* and the peer has performed an orderly shutdown,
|
||||||
|
@ -140,48 +147,55 @@ public:
|
||||||
virtual nsapi_error_t getpeername(SocketAddress *address);
|
virtual nsapi_error_t getpeername(SocketAddress *address);
|
||||||
|
|
||||||
#if defined(MBEDTLS_X509_CRT_PARSE_C) || defined(DOXYGEN_ONLY)
|
#if defined(MBEDTLS_X509_CRT_PARSE_C) || defined(DOXYGEN_ONLY)
|
||||||
/** Get own certificate directly from Mbed TLS
|
/** Get own certificate directly from Mbed TLS.
|
||||||
* @return internal Mbed TLS X509 structure
|
*
|
||||||
|
* @return internal Mbed TLS X509 structure.
|
||||||
*/
|
*/
|
||||||
mbedtls_x509_crt *get_own_cert();
|
mbedtls_x509_crt *get_own_cert();
|
||||||
|
|
||||||
/** Set own certificate directly to Mbed TLS
|
/** Set own certificate directly to Mbed TLS.
|
||||||
|
*
|
||||||
* @param crt Mbed TLS X509 certificate chain.
|
* @param crt Mbed TLS X509 certificate chain.
|
||||||
* @return error code from mbedtls_ssl_conf_own_cert()
|
* @return error code from mbedtls_ssl_conf_own_cert().
|
||||||
*/
|
*/
|
||||||
int set_own_cert(mbedtls_x509_crt *crt);
|
int set_own_cert(mbedtls_x509_crt *crt);
|
||||||
|
|
||||||
/** Get CA chain structure.
|
/** Get CA chain structure.
|
||||||
|
*
|
||||||
* @return Mbed TLS X509 certificate chain.
|
* @return Mbed TLS X509 certificate chain.
|
||||||
*/
|
*/
|
||||||
mbedtls_x509_crt *get_ca_chain();
|
mbedtls_x509_crt *get_ca_chain();
|
||||||
|
|
||||||
/** Set CA chain directly to Mbed TLS
|
/** Set CA chain directly to Mbed TLS.
|
||||||
|
*
|
||||||
* @param crt Mbed TLS X509 certificate chain.
|
* @param crt Mbed TLS X509 certificate chain.
|
||||||
*/
|
*/
|
||||||
void set_ca_chain(mbedtls_x509_crt *crt);
|
void set_ca_chain(mbedtls_x509_crt *crt);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** Get internal Mbed TLS configuration structure
|
/** Get internal Mbed TLS configuration structure.
|
||||||
* @return Mbed TLS SSL config
|
*
|
||||||
|
* @return Mbed TLS SSL config.
|
||||||
*/
|
*/
|
||||||
mbedtls_ssl_config *get_ssl_config();
|
mbedtls_ssl_config *get_ssl_config();
|
||||||
|
|
||||||
/** Override Mbed TLS configuration.
|
/** Override Mbed TLS configuration.
|
||||||
* @param conf Mbed TLS SSL configuration structure
|
*
|
||||||
|
* @param conf Mbed TLS SSL configuration structure.
|
||||||
*/
|
*/
|
||||||
void set_ssl_config(mbedtls_ssl_config *conf);
|
void set_ssl_config(mbedtls_ssl_config *conf);
|
||||||
|
|
||||||
/** Get internal Mbed TLS context structure.
|
/** Get internal Mbed TLS context structure.
|
||||||
* @return SSL context
|
*
|
||||||
|
* @return SSL context.
|
||||||
*/
|
*/
|
||||||
mbedtls_ssl_context *get_ssl_context();
|
mbedtls_ssl_context *get_ssl_context();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** Initiates TLS Handshake
|
/** Initiates TLS Handshake.
|
||||||
*
|
*
|
||||||
* Initiates a TLS handshake to a remote peer
|
* Initiates a TLS handshake to a remote peer.
|
||||||
* Underlying transport socket should already be connected
|
* Underlying transport socket should already be connected.
|
||||||
*
|
*
|
||||||
* Root CA certification must be set by set_ssl_ca_pem() before
|
* Root CA certification must be set by set_ssl_ca_pem() before
|
||||||
* call this function.
|
* call this function.
|
||||||
|
|
Loading…
Reference in New Issue