ThingWorx C SDK
|
ThingWorx TLS client abstraction layer. More...
Go to the source code of this file.
Classes | |
struct | twTlsClient |
TLS client structure definition. More... | |
Macros | |
#define | TW_SUBJECT_CN 0 |
#define | TW_SUBJECT_O 1 |
#define | TW_SUBJECT_OU 2 |
#define | TW_ISSUER_CN 3 |
#define | TW_ISSUER_O 4 |
#define | TW_ISSUER_OU 5 |
#define | TW_READ_TIMEOUT -333 |
#define | TW_SHA1_CTX hash_state |
#define | TW_SHA1_INIT(a) sha1_init(a) |
#define | TW_SHA1_UPDATE(a, b, c) sha1_process(a,b,c) |
#define | TW_SHA1_FINAL(a, b) sha1_done(b,a) |
#define | TW_MD5_CTX hash_state |
#define | TW_MD5_INIT(a) md5_init(a) |
#define | TW_MD5_UPDATE(a, b, c) md5_process(a,b,c) |
#define | TW_MD5_FINAL(a, b) md5_done(b,a) |
Typedefs | |
typedef struct twTlsClient | twTlsClient |
TLS client structure definition. | |
Functions | |
int | twTlsClient_Create (const char *host, int16_t port, uint32_t options, twTlsClient **client) |
Creates a new twTlsClient structure with the specified settings. More... | |
int | twTlsClient_Connect (twTlsClient *t) |
Connects a twTlsClient::connection (see twSocket_Connect()). More... | |
int | twTlsClient_ConnectSession (twTlsClient *t, void *sessionId, int sessionLength) |
Connects a twTlsClient::connection (see twSocket_Connect()) with some additional session options. More... | |
int | twTlsClient_Reconnect (twTlsClient *t, const char *host, int16_t port) |
Reconnects a twTlsClient::connection (see twSocket_Reconnect()). More... | |
int | twTlsClient_Close (twTlsClient *t) |
Closes a twTlsClient::connection (see twSocket_Close()). More... | |
int | twTlsClient_Read (twTlsClient *t, char *buf, int len, int timeout) |
Reads len bytes of data from a twTlsClient::connection into buf (see twSocket_Read()). More... | |
int | twTlsClient_Write (twTlsClient *t, char *buf, int len, int timeout) |
Writes len bytes of data from buf to a twTlsClient::connection (see twSocket_Write()). More... | |
int | twTlsClient_Delete (twTlsClient *t) |
Frees all memory associated with a twTlsClient and all of its owned substructures. More... | |
int | twTlsClient_IsEncrypted (twTlsClient *t) |
Checks to see if a twTlsClient is encrypted by getting the value of twTlsClient::isEncrypted. More... | |
void * | twTlsClient_GetSessionId (twTlsClient *t) |
Gets the session ID of a twTlsClient. More... | |
void | twTlsClient_SetSelfSignedOk (twTlsClient *t) |
Sets the twTlsClient to accept self signed certificates (see twSocket_SetSelfSignedOk()). More... | |
void | twTlsClient_DisableCertValidation (twTlsClient *t) |
Sets the twTlsClient to disable certificate validation (see twSocket_DisableCertValidation()). More... | |
void | twTlsClient_DisableEncryption (twTlsClient *t) |
Sets the twTlsClient to disable encryption (see twSocket_DisableEncryption()). More... | |
int | twTlsClient_ValidateCert (twTlsClient *t) |
Tells the twTlsClient to validate its twTlsClient::ssl certificate (see TW_VALIDATE_CERT()). More... | |
int | twTlsClient_UseCertificateFile (twTlsClient *t, const char *file, int type) |
Loads the first certificate stored in file into twTlsClient::ctx. More... | |
int | twTlsClient_UsePrivateKeyFile (twTlsClient *t, const char *file, int type) |
Loads the first private key stored in file into twTlsClient::ctx. More... | |
int | twTlsClient_UseCertificateChainFile (twTlsClient *t, const char *file, int type) |
Loads the certificate authority cert chain used to validate the server's certificate in file into twTlsClient::ctx (see TW_USE_KEY_FILE(). More... | |
int | twTlsClient_SetClientCaList (twTlsClient *t, char *caFile) |
Loads a client certificate authority cert chain in file into twTlsClient::ctx. More... | |
void | twTlsClient_SetDefaultPasswdCbUserdata (twTlsClient *t, void *u) |
Sets the twTlsClient::keypasswd of a twTlsClient to u . More... | |
int | twTlsClient_EnableFipsMode (twTlsClient *t) |
Enables FIPS mode for a twTlsClient. Wrapper function for TW_ENABLE_FIPS_MODE(). More... | |
int | twTlsClient_SetX509Fields (twTlsClient *t, char *subject_cn, char *subject_o, char *subject_ou, char *issuer_cn, char *issuer_o, char *issuer_ou) |
Sets the X509 fields of a twTlsClient. More... | |
int | twTlsServer_Create (twTlsClient *t) |
Creates a new #TW_TLS server and associates it with a twTlsClient::ssl. More... | |
int | twTlsServer_Accept (twTlsClient *t) |
Waits for a twTlsClient::ssl to initiate a handshake with the server (see TW_SSL_ACCEPT()). More... | |
void | twSHA1_Init (TW_SHA1_CTX *ctx) |
Initializes an SHA1 context. More... | |
void | twSHA1_Update (TW_SHA1_CTX *ctx, const uint8_t *msg, int len) |
Add a new entry to an SHA1 hash. More... | |
void | twSHA1_Final (uint8_t *digest, TW_SHA1_CTX *ctx) |
Finalize and get the calculated SHA1 digest. More... | |
void | twMD5_Init (TW_MD5_CTX *) |
Initializes an MD5 context. More... | |
void | twMD5_Update (TW_MD5_CTX *, const uint8_t *msg, int len) |
Add a new entry to an MD5 hash. More... | |
void | twMD5_Final (uint8_t *digest, TW_MD5_CTX *) |
Finalize and get the calculated MD5 digest. More... | |
ThingWorx TLS client abstraction layer.
#define TW_MD5_CTX hash_state |
#define TW_SHA1_CTX hash_state |
void twMD5_Final | ( | uint8_t * | digest, |
TW_MD5_CTX * | |||
) |
Finalize and get the calculated MD5 digest.
[in,out] | digest | A pointer to the buffer to receive the digest. |
[in] | ctx | A pointer to the ctx structure. |
void twMD5_Init | ( | TW_MD5_CTX * | ) |
Initializes an MD5 context.
[in] | ctx | A pointer to the ctx structure to initialize. |
void twMD5_Update | ( | TW_MD5_CTX * | , |
const uint8_t * | msg, | ||
int | len | ||
) |
Add a new entry to an MD5 hash.
[in] | ctx | A pointer to the ctx structure. |
[in] | msg | A pointer to the message to add. |
[in] | len | The length of the message. |
void twSHA1_Final | ( | uint8_t * | digest, |
TW_SHA1_CTX * | ctx | ||
) |
Finalize and get the calculated SHA1 digest.
[in,out] | digest | A pointer to the buffer to receive the digest. |
[in] | ctx | A pointer to the ctx structure. |
void twSHA1_Init | ( | TW_SHA1_CTX * | ctx | ) |
Initializes an SHA1 context.
[in] | ctx | A pointer to the ctx structure to initialize. |
void twSHA1_Update | ( | TW_SHA1_CTX * | ctx, |
const uint8_t * | msg, | ||
int | len | ||
) |
Add a new entry to an SHA1 hash.
[in] | ctx | A pointer to the ctx structure. |
[in] | msg | A pointer to the message to add. |
[in] | len | The length of the message. |
int twTlsClient_Close | ( | twTlsClient * | t | ) |
Closes a twTlsClient::connection (see twSocket_Close()).
[in] | t | A pointer to the twTlsClient to close. |
int twTlsClient_Connect | ( | twTlsClient * | t | ) |
Connects a twTlsClient::connection (see twSocket_Connect()).
[in] | t | A pointer to the twTlsClient to connect. |
int twTlsClient_ConnectSession | ( | twTlsClient * | t, |
void * | sessionId, | ||
int | sessionLength | ||
) |
Connects a twTlsClient::connection (see twSocket_Connect()) with some additional session options.
[in] | t | A pointer to the twTlsClient to connect. |
[in] | sessionId | The session ID to assign to the connection. |
[in] | sessionLength | The length of the session. |
int twTlsClient_Create | ( | const char * | host, |
int16_t | port, | ||
uint32_t | options, | ||
twTlsClient ** | client | ||
) |
Creates a new twTlsClient structure with the specified settings.
[in] | host | The host name of the server (twSocket::host). |
[in] | port | The port the server is listening on (twSocket::port). |
[in] | options | The TLS options of the twTlsClient. |
[out] | client | A pointer to a pointer to store the newly allocated twTlsClient at. |
client
and is responsible for freeing it via twTlsClient_Delete(). int cert_index = 0, ca_cert_index = 0; int cert_size, ca_cert_size; char **ca_cert, **cert; const char *password = NULL;
int twTlsClient_Delete | ( | twTlsClient * | t | ) |
Frees all memory associated with a twTlsClient and all of its owned substructures.
[in] | t | A pointer to the twTlsClient to delete. |
void twTlsClient_DisableCertValidation | ( | twTlsClient * | t | ) |
Sets the twTlsClient to disable certificate validation (see twSocket_DisableCertValidation()).
[in] | t | A pointer to the twTlsClient to modify. |
void twTlsClient_DisableEncryption | ( | twTlsClient * | t | ) |
Sets the twTlsClient to disable encryption (see twSocket_DisableEncryption()).
[in] | t | A pointer to the twTlsClient to modify. |
int twTlsClient_EnableFipsMode | ( | twTlsClient * | t | ) |
Enables FIPS mode for a twTlsClient. Wrapper function for TW_ENABLE_FIPS_MODE().
[in] | t | A pointer to the twTlsClient to modify. |
void* twTlsClient_GetSessionId | ( | twTlsClient * | t | ) |
Gets the session ID of a twTlsClient.
[in] | t | A pointer to the twTlsClient to get the session ID of. |
int twTlsClient_IsEncrypted | ( | twTlsClient * | t | ) |
Checks to see if a twTlsClient is encrypted by getting the value of twTlsClient::isEncrypted.
[in] | t | A pointer to the twTlsClient to inspect. |
t
is encrypted, #FALSE otherwise. int twTlsClient_Read | ( | twTlsClient * | t, |
char * | buf, | ||
int | len, | ||
int | timeout | ||
) |
Reads len
bytes of data from a twTlsClient::connection into buf
(see twSocket_Read()).
[in] | t | A pointer to the twTlsClient to read from. |
[out] | buf | A buffer to store the read data. |
[in] | len | The length of data to read. |
[in] | timeout | The amount of time (in milliseconds) to wait for I/O before timing out. |
buf
and is responsible for freeing it. int twTlsClient_Reconnect | ( | twTlsClient * | t, |
const char * | host, | ||
int16_t | port | ||
) |
Reconnects a twTlsClient::connection (see twSocket_Reconnect()).
[in,out] | t | A pointer to the twTlsClient to reconnect. |
[in] | host | The host name of the server (twSocket::host). |
[in] | port | The port the server is listening on (twSocket::port). |
int twTlsClient_SetClientCaList | ( | twTlsClient * | t, |
char * | caFile | ||
) |
Loads a client certificate authority cert chain in file
into twTlsClient::ctx.
[in] | t | A pointer to the twTlsClient to modify. |
[in] | file | The certificate chain file to use. |
[in] | type | The container format of file . |
void twTlsClient_SetDefaultPasswdCbUserdata | ( | twTlsClient * | t, |
void * | u | ||
) |
Sets the twTlsClient::keypasswd of a twTlsClient to u
.
[in] | t | A pointer to the twTlsClient to modify. |
[in] | u | A pointer to the data to use as they password. |
void twTlsClient_SetSelfSignedOk | ( | twTlsClient * | t | ) |
Sets the twTlsClient to accept self signed certificates (see twSocket_SetSelfSignedOk()).
[in] | t | A pointer to the twTlsClient to modify. |
int twTlsClient_SetX509Fields | ( | twTlsClient * | t, |
char * | subject_cn, | ||
char * | subject_o, | ||
char * | subject_ou, | ||
char * | issuer_cn, | ||
char * | issuer_o, | ||
char * | issuer_ou | ||
) |
Sets the X509 fields of a twTlsClient.
[in,out] | t | A pointer to the twTlsClient to modify. |
[in] | subject_cn | The common name of the subject. |
[in] | subject_o | The organization of the subject. |
[in] | subject_ou | The organizational unit of the subject. |
[in] | issuer_cn | The common name of the issuer. |
[in] | issuer_o | The organization of the issuer. |
[in] | issuer_ou | The organizational unit of the issuer. |
int twTlsClient_UseCertificateChainFile | ( | twTlsClient * | t, |
const char * | file, | ||
int | type | ||
) |
Loads the certificate authority cert chain used to validate the server's certificate in file
into twTlsClient::ctx (see TW_USE_KEY_FILE().
[in] | t | A pointer to the twTlsClient to modify. |
[in] | file | The certificate chain file to use. |
[in] | type | The container format of file . |
int twTlsClient_UseCertificateFile | ( | twTlsClient * | t, |
const char * | file, | ||
int | type | ||
) |
Loads the first certificate stored in file
into twTlsClient::ctx.
[in] | t | A pointer to the twTlsClient to modify. |
[in] | file | The certificate file to use. |
[in] | type | The container format of file . |
int twTlsClient_UsePrivateKeyFile | ( | twTlsClient * | t, |
const char * | file, | ||
int | type | ||
) |
Loads the first private key stored in file
into twTlsClient::ctx.
[in] | t | A pointer to the twTlsClient to modify. |
[in] | file | The private key file to use. |
[in] | type | The container format of file . |
int twTlsClient_ValidateCert | ( | twTlsClient * | t | ) |
Tells the twTlsClient to validate its twTlsClient::ssl certificate (see TW_VALIDATE_CERT()).
[in] | t | A pointer to the twTlsClient to validate the certificate of. |
int twTlsClient_Write | ( | twTlsClient * | t, |
char * | buf, | ||
int | len, | ||
int | timeout | ||
) |
Writes len
bytes of data from buf
to a twTlsClient::connection (see twSocket_Write()).
[in] | t | A pointer to the twTlsClient to write to. |
[out] | buf | A buffer containing the data to be written. |
[in] | len | The length of data to write. |
[in] | timeout | The amount of time (in milliseconds) to wait for I/O before timing out. |
buf
and is responsible for freeing it. int twTlsServer_Accept | ( | twTlsClient * | t | ) |
Waits for a twTlsClient::ssl to initiate a handshake with the server (see TW_SSL_ACCEPT()).
[in] | t | A pointer to the twTlsClient to utilize. |
int twTlsServer_Create | ( | twTlsClient * | t | ) |
Creates a new #TW_TLS server and associates it with a twTlsClient::ssl.
[in,out] | t | A pointer to the twTlsClient to modify. |