Skip to content

Commit 8561ef6

Browse files
committed
Read and pass cacert buffer to lws_config instead of path
- Avoids libwebsockets taking control over using raw fread/nvs APIs - The SDK, hence, do not need to rely on libwebsockets method
1 parent 0854986 commit 8561ef6

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

src/source/Signaling/Signaling.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,34 @@
66
extern StateMachineState SIGNALING_STATE_MACHINE_STATES[];
77
extern UINT32 SIGNALING_STATE_MACHINE_STATE_COUNT;
88

9+
// allocate memory and read the CA certificate from the path
10+
PRIVATE_API STATUS readCACertificate(PCHAR pCaCertPath, PBYTE* pCaCertBuf, UINT32* pCaCertBufLen)
11+
{
12+
ENTERS();
13+
STATUS retStatus = STATUS_SUCCESS;
14+
UINT64 cert_len = 0;
15+
PBYTE cert_buf = NULL;
16+
17+
CHK(pCaCertPath != NULL, STATUS_NULL_ARG);
18+
19+
CHK_STATUS(readFile(pCaCertPath, FALSE, NULL, &cert_len));
20+
CHK(cert_len > 0, STATUS_INVALID_CERT_PATH_LENGTH);
21+
cert_buf = (PBYTE) MEMCALLOC(1, cert_len + 1); // +1 for the null terminator
22+
CHK(cert_buf != NULL, STATUS_NOT_ENOUGH_MEMORY);
23+
CHK_STATUS(readFile(pCaCertPath, FALSE, cert_buf, &cert_len));
24+
25+
*pCaCertBuf = cert_buf;
26+
*pCaCertBufLen = (UINT32) cert_len;
27+
cert_buf = NULL; // So that it is not freed by SAFE_MEMFREE
28+
29+
CleanUp:
30+
CHK_LOG_ERR(retStatus);
31+
SAFE_MEMFREE(cert_buf);
32+
33+
LEAVES();
34+
return retStatus;
35+
}
36+
937
STATUS createSignalingSync(PSignalingClientInfoInternal pClientInfo, PChannelInfo pChannelInfo, PSignalingClientCallbacks pCallbacks,
1038
PAwsCredentialProvider pCredentialProvider, PSignalingClient* ppSignalingClient)
1139
{
@@ -14,6 +42,8 @@ STATUS createSignalingSync(PSignalingClientInfoInternal pClientInfo, PChannelInf
1442
PSignalingClient pSignalingClient = NULL;
1543
PCHAR userLogLevelStr = NULL;
1644
UINT32 userLogLevel;
45+
PCHAR caCertBuf = NULL;
46+
UINT32 caCertBufLen = 0;
1747
struct lws_context_creation_info creationInfo;
1848
const lws_retry_bo_t retryPolicy = {
1949
.secs_since_valid_ping = SIGNALING_SERVICE_WSS_PING_PONG_INTERVAL_IN_SECONDS,
@@ -121,7 +151,9 @@ STATUS createSignalingSync(PSignalingClientInfoInternal pClientInfo, PChannelInf
121151
creationInfo.timeout_secs = SIGNALING_SERVICE_API_CALL_TIMEOUT_IN_SECONDS;
122152
creationInfo.gid = -1;
123153
creationInfo.uid = -1;
124-
creationInfo.client_ssl_ca_filepath = pChannelInfo->pCertPath;
154+
CHK_STATUS(readCACertificate(pChannelInfo->pCertPath, &caCertBuf, &caCertBufLen));
155+
creationInfo.client_ssl_ca_mem = caCertBuf;
156+
creationInfo.client_ssl_ca_mem_len = caCertBufLen;
125157
creationInfo.client_ssl_cipher_list = "HIGH:!PSK:!RSP:!eNULL:!aNULL:!RC4:!MD5:!DES:!3DES:!aDH:!kDH:!DSS";
126158
creationInfo.ka_time = SIGNALING_SERVICE_TCP_KEEPALIVE_IN_SECONDS;
127159
creationInfo.ka_probes = SIGNALING_SERVICE_TCP_KEEPALIVE_PROBE_COUNT;
@@ -204,6 +236,7 @@ STATUS createSignalingSync(PSignalingClientInfoInternal pClientInfo, PChannelInf
204236
SIGNALING_STATE_GET_TOKEN));
205237

206238
CleanUp:
239+
SAFE_MEMFREE(caCertBuf);
207240
if (pClientInfo != NULL && pSignalingClient != NULL) {
208241
pClientInfo->signalingClientInfo.stateMachineRetryCountReadOnly = pSignalingClient->diagnostics.stateMachineRetryCount;
209242
}

0 commit comments

Comments
 (0)