SharkSSL C/C++ Reference
TLS, cryptography, certificates, and PSA integration
SharkSSL Examples

Detailed Description

Client and server SSL/TLS examples.

See the examples getting started guide for an introduction to the examples.

Client Example Programs

A client program is a network program that opens and establishes a connection to a server.

WebSocket Client Library

We include a generic WebSocket client library and an example program that demonstrates use of the library:

Initialize the cryptographic RNG before sending frames, even without TLS. WsEchoClient.c uses the same demonstration seed as the other examples. Replace it with proper platform entropy in a product. A nonzero initialization result stops the example before connecting. The client rejects TinyMT and stops sending if it cannot obtain a masking key. See wscProtocolHandshake for the client's remaining protocol limits.

SMTP (Simple Mail Transfer Protocol)

A generic secure SMTP library. SMTP is a common method for sending notifications from devices.

Server Example Programs

A server program is a network program that waits for and responds to requests from client network programs.

WebSocket Server Library

The MinnowServer is a secure WebSocket server library. The two demo programs WsChatServer.c and WsLedServer.c show how to use the APIs in the WebSocket server library.

Certificate Management Example Programs

The source file (CertCheck.c) shows how to implement a full server certificate check. The code includes most common root certificates, so it should technically be able to certify any server on the internet with a valid certificate.

SharkSSL Socket Library

The source file selib.c includes a generic TCP/IP socket wrapper around the transport agnostic SharkSSL API. All SharkSSL socket examples/demos use this library.

Example Makefiles

Makefiles and project files can be found in ../build

Modules

 Minnow Server
 Compact HTTPS and WebSocket Server.
 
 SharkMQ
 A secure SimpleMQ client designed for SharkSSL.
 
 SharkMQTT
 A secure MQTT client designed for SharkSSL.
 
 WebSocket Client Lib
 A compact WebSocket client library.
 
 SharkSSL Socket Example Lib
 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.
 
 Simple Mail Transfer Protocol
 A minimal secure SMTP client library (SMTPS and STARTTLS).
 
 SharkMQ proxy connections
 Define ENABLE_PROXY when compiling both SharkMQ.c and its callers to include HTTP CONNECT and SOCKS5.
 

Functions

U8 * msstrstrn (U8 *str, int slen, const U8 *substr)
 Find a case-insensitive substring in a bounded text buffer. More...
 
int MS_send (MS *o, U8 opCode, int len)
 Send a WebSocket frame from the prepared Minnow send buffer. More...
 
void SeCtx_save (SeCtx *o)
 Suspend the active bare-metal socket context and save its stack. More...
 
void SeCtx_restore (SeCtx *o)
 Restore a previously saved bare-metal socket context. More...
 

Function Documentation

◆ MS_send()

int MS_send ( MS *  o,
U8  opCode,
int  len 
)

Send a WebSocket frame from the prepared Minnow send buffer.

Fill only the returned payload space before calling. This helper does not allocate or copy the payload.

Parameters
oMS *; Required active Minnow WebSocket object whose send buffer was prepared with MS_prepSend.
opCodeU8; WebSocket opcode and FIN flags for the frame.
lenint; Nonnegative payload length in bytes, within the prepared buffer and at most 65535; must agree with its short/extended header form.
Returns
int: Underlying transport write result, or a negative MS_ERR_BUF_* error for a header/length mismatch.

◆ msstrstrn()

U8 * msstrstrn ( U8 *  str,
int  slen,
const U8 *  substr 
)

Find a case-insensitive substring in a bounded text buffer.

Parameters
strU8 *; Required borrowed input text; search also stops at its first NUL.
slenint; Nonnegative maximum number of input bytes to inspect.
substrconst U8 *; Required NUL-terminated search text, borrowed for the call.
Returns
U8 *: Borrowed pointer to the first match, or NULL when no match is found.

◆ SeCtx_restore()

void SeCtx_restore ( SeCtx *  o)

Restore a previously saved bare-metal socket context.

Clears the saved/ready flags and transfers control to the saved execution point. Does not return normally to its caller; use only with the matching SeCtx port and scheduler.

Parameters
oSeCtx *; Required context with a saved stack; its original stack environment must still be valid.

◆ SeCtx_save()

void SeCtx_save ( SeCtx *  o)

Suspend the active bare-metal socket context and save its stack.

For the supported bare-metal selib port only. Transfers control to the scheduler and resumes here after SeCtx_restore; do not use as a portable thread primitive.

Parameters
oSeCtx *; Required initialized active context with no saved context and ready cleared.