MQTT Vuser Functions > mqtt_set_tls_certificate

mqtt_set_tls_certificate

Sets the TLS private key file, certificate file, and the private key password.

C Language

int mqtt_set_tls_certificate( MQTT handle, const char* certificatePath, const char* pkeyPath, const char* pkeyPassword);

Example MQTT Vuser Functions

Arguments

Name Comments
handle The MQTT client handle returned by mqtt_create.
certificatePath The path of the certificate file. The path can be absolute or relative to the script directory.
pkeyPassword The private key password. Pass MQTT_NONE if the private key is not encrypted.
pkeyPath The path of the private key file. MQTT_NONE if certificate and private key are in the same file.

General

mqtt_set_tls_certificate sets the TLS private key file, certificate file, and the private key password. The files must be in PEM format. Call this function before mqtt_connect.

If invalid arguments are passed, the Vuser aborts, even if Continue on error is set.

Return Values

MQTT_SUCCESS or MQTT_FAIL

Parameterization

Standard parameterization is available for this function.

Exception: pkeyPassword cannot be parametrized (to avoid exposing in the output log)

Example

MQTT client = mqtt_create();

/* Set TLS certificate for secured connection:

- client certificate file

- client private key file

- client private key password (encrypted in this case)

As file paths are relative, they are expected to be placed in the script directory and added as Extra Files

*/

mqtt_set_tls_certificate(client, "client.crt", "client.key", lr_unmask("582c4f507db5f3df86f88518"));

mqtt_connect(client, "ssl://test.broker.com:8883");