This package includes the SharkSSL lite library and header files.
Dependents: WebSocket-Client-Example SharkMQ-LED-Demo
SharkSSL Socket Example Lib
[SharkExamples]
The SharkSSL Socket Example Lib (selib.h/selib.c) is a basic module that wraps the transport agnostic SharkSSL functions for encoding and decoding into functions that interface to TCP/IP socket calls. More...
Functions | |
int | seSec_handshake (SharkSslCon *s, SOCKET *sock, U32 timeout, const char *commonName) |
Performs the initial SSL handshaking using an asymmetric cipher in order to establish cipher settings and a shared key for the session. | |
int | seSec_read (SharkSslCon *s, SOCKET *sock, U8 **buf, U32 timeout) |
Read data from socket stream and decode the encrypted data. | |
int | seSec_write (SharkSslCon *s, SOCKET *sock, U8 *buf, int maxLen) |
Encrypts and sends encrypted data to the connected peer side. | |
int | se_connect (SOCKET *sock, const char *address, U16 port) |
Initializes a SOCKET object connected to a remote host/address at a given port. | |
int | se_bind (SOCKET *sock, U16 port) |
Initializes a SOCKET object bound to a local port, ready to accept client connections. | |
int | se_accept (SOCKET **listenSock, U32 timeout, SOCKET **outSock) |
Waits for remote connections on the server SOCKET object 'listenSock', initialized by function se_bind, and initializes socket object 'outSock' to represent the new connection. | |
void | se_close (SOCKET *sock) |
Close a connected socket connection. | |
int | se_sockValid (SOCKET *sock) |
Returns TRUE if socket is valid (connected). | |
S32 | se_send (SOCKET *sock, const void *buf, U32 len) |
Sends data to the connected peer. | |
S32 | se_recv (SOCKET *sock, void *buf, U32 len, U32 timeout) |
Waits for data sent by peer. | |
void | _xprintf (const char *fmt,...) |
The example code and macro xprintf requires this function when the code is compiled with macro XPRINTF set to 1. | |
void | mainTask (SeCtx *ctx) |
Main entry for all example programs. |
Detailed Description
The SharkSSL Socket Example Lib (selib.h/selib.c) is a basic module that wraps the transport agnostic SharkSSL functions for encoding and decoding into functions that interface to TCP/IP socket calls.
![Socket Example Lib](SharkSSL-selibjpg)
In addition, the file selib.c includes wrappers for standard BSD socket calls at the end of the file. TCP/IP stacks not using the BSD API must define NO_BSD_SOCK and implement the following functions in a separate file: se_bind, se_accept, se_connect, se_close, se_sockValid, se_send, and se_recv.
Function Documentation
void _xprintf | ( | const char * | fmt, |
... | |||
) |
The example code and macro xprintf requires this function when the code is compiled with macro XPRINTF set to 1.
- Parameters:
-
fmt the format string. ... variable arguments.
void mainTask | ( | SeCtx * | ctx ) |
Main entry for all example programs.
int se_accept | ( | SOCKET ** | listenSock, |
U32 | timeout, | ||
SOCKET ** | outSock | ||
) |
int se_bind | ( | SOCKET * | sock, |
U16 | port | ||
) |
void se_close | ( | SOCKET * | sock ) |
int se_connect | ( | SOCKET * | sock, |
const char * | address, | ||
U16 | port | ||
) |
S32 se_recv | ( | SOCKET * | sock, |
void * | buf, | ||
U32 | len, | ||
U32 | timeout | ||
) |
Waits for data sent by peer.
- Parameters:
-
sock the SOCKET object. buf is the data to send. len is the 'buf' length. timeout in milliseconds. The timeout can be set to INFINITE_TMO.
- Returns:
- the length of the data read, zero on timeout, or a negative value on error.
S32 se_send | ( | SOCKET * | sock, |
const void * | buf, | ||
U32 | len | ||
) |
int se_sockValid | ( | SOCKET * | sock ) |
int seSec_handshake | ( | SharkSslCon * | s, |
SOCKET * | sock, | ||
U32 | timeout, | ||
const char * | commonName | ||
) |
Performs the initial SSL handshaking using an asymmetric cipher in order to establish cipher settings and a shared key for the session.
The function also validates the server's certificate and compares the commonName provided in argument 3 with the common name in the certificate, if commonName is provided (not NULL). The domain name comparison works with and without the clone certificate API (SHARKSSL_ENABLE_CLONE_CERTINFO).
Note: the function only performs basic certificate domain name comparison and can only be used with server certificates that does not include Subject Alternative Names (SAN Certificate). Use the more advanced function SharkSslCon_trusted for certificate trust management if the server uses a SAN Certificate.
- Parameters:
-
s the SharkSslCon object. sock the SOCKET object. timeout in milliseconds. The timeout can be set to INFINITE_TMO. commonName is optional and is used for certificate domain name verification.
- Returns:
- A negative value on error. The negative value is an inverted SharkSslCon_RetVal value.
- Zero on timeout.
- The return value is SharkSslConTrust for any return value greater than zero.
int seSec_read | ( | SharkSslCon * | s, |
SOCKET * | sock, | ||
U8 ** | buf, | ||
U32 | timeout | ||
) |
Read data from socket stream and decode the encrypted data.
The buffer is managed by SharkSSL and the data returned is valid until the next SharkSSL call. This function blocks until data is available or until 'timeout' milliseconds.
- Parameters:
-
s the SharkSslCon object. sock the SOCKET object. buf is a pointer set to the SharkSSL receive buffer offset to the WebSocket payload data. timeout in milliseconds. The timeout can be set to INFINITE_TMO.
- Returns:
- The function returns the number of bytes available in 'buf' on success. The function returns 0 on timeout and a negative value on error.
int seSec_write | ( | SharkSslCon * | s, |
SOCKET * | sock, | ||
U8 * | buf, | ||
int | maxLen | ||
) |
Encrypts and sends encrypted data to the connected peer side.
- Returns:
- Zero on success or a negative value on error.
Generated on Wed Jul 13 2022 10:54:53 by 1.7.2