38 #define TLS_CERT_TIMEOUT (24 * 60 * 60 * 1000) 39 #define MAX_TLS_CERT_NAME (22) 40 #define MAX_CALLBACKS (5) 44 #ifdef TLS_DEBUG_PRINT 45 #define PRINT(x) DBG_PRINTF x 58 TLS_CERT_STATE_INVALID
59 } TlsCertRefreshState;
62 static void(*tlsCallback[MAX_CALLBACKS]) (void);
63 static U16BIT callbackCount = 0;
64 static U32BIT lastCertStoreUpdate = 0;
65 static MHEG5Int lastRequestNumber = 0;
66 static MHEG5Bool lastRequestFailed = MHEG5FALSE;
67 static TlsCertRefreshState certRequestState = TLS_CERT_STATE_VALID;
71 static MHEG5Bool IsTimeToUpdate(
void);
72 static void ClearTlsCertStore(
void);
73 static void TlsCertRetrieved(
void *userData,
S_CONTENT *content );
74 static void AddCertificates( U8BIT *certData, U32BIT certLen );
75 static void TlsCertRetrievalFailed(
void *userData );
76 static void NotifyTlsReady(
void);
99 if (certRequestState == TLS_CERT_STATE_ASYNC)
104 certRequestState = TLS_CERT_STATE_INVALID;
128 MHEG5TlsCertRequestStatus status;
129 MHEG5Int currentRequestNumber;
130 char name[MAX_TLS_CERT_NAME];
133 status = MHEG5_TLS_CERT_REQUEST_PENDING;
135 if (lastRequestFailed)
138 status = MHEG5_TLS_CERT_REQUEST_FAILURE;
141 if (certRequestState == TLS_CERT_STATE_VALID)
143 if (IsTimeToUpdate())
148 if (!lastRequestFailed)
150 certRequestState = TLS_CERT_STATE_SYNC;
152 currentRequestNumber = lastRequestNumber;
153 sprintf(name,
"DSM://auth.tls.%ld", lastRequestNumber + 1);
154 requestName.data = (U8BIT *)name;
155 requestName.len = strlen(name);
156 (void)
MHEG5FileOrmGet( requestName, FRP_CERT | FRP_CACHE_DEFAULT, NULL,
157 TlsCertRetrieved, TlsCertRetrievalFailed);
159 if (certRequestState == TLS_CERT_STATE_VALID)
161 if (currentRequestNumber == lastRequestNumber)
164 status = MHEG5_TLS_CERT_REQUEST_FAILURE;
169 status = MHEG5_TLS_CERT_REQUEST_SUCCESS;
175 certRequestState = TLS_CERT_STATE_ASYNC;
191 if (callbackCount < MAX_CALLBACKS)
193 tlsCallback[callbackCount] = loadCallback;
205 static MHEG5Bool IsTimeToUpdate(
void)
207 MHEG5Bool timeToUpdate;
210 timeToUpdate = FALSE;
214 if (lastCertStoreUpdate == 0)
218 else if ((currentTime > lastCertStoreUpdate) &&
219 (currentTime - lastCertStoreUpdate) > TLS_CERT_TIMEOUT)
223 else if (currentTime < lastCertStoreUpdate)
236 static void ClearTlsCertStore(
void)
239 lastCertStoreUpdate = 0;
240 lastRequestNumber = 0;
241 lastRequestFailed = MHEG5FALSE;
254 static void TlsCertRetrieved(
void *userData,
S_CONTENT *content )
256 USE_UNWANTED_PARAM(userData);
258 if (certRequestState == TLS_CERT_STATE_INVALID)
263 certRequestState = TLS_CERT_STATE_VALID;
266 else if (certRequestState != TLS_CERT_STATE_VALID)
269 AddCertificates( content->data, content->size );
275 if (certRequestState == TLS_CERT_STATE_ASYNC)
280 certRequestState = TLS_CERT_STATE_VALID;
290 static void AddCertificates(U8BIT *certData, U32BIT certLen)
298 count = certData[0] << 8 | certData[1];
306 size = (certData[2] << 16 | certData[3] << 8 | certData[4]);
307 if (size + 5 == certLen)
315 DBG_PRINTF(
"Invalid certificate size\n");
323 DBG_PRINTF(
"Invalid certificate file length\n");
328 if (lastRequestNumber == 0)
342 void TlsCertRetrievalFailed(
void *userData)
344 USE_UNWANTED_PARAM(userData);
346 if (certRequestState == TLS_CERT_STATE_INVALID)
351 certRequestState = TLS_CERT_STATE_VALID;
356 lastRequestFailed = MHEG5TRUE;
357 if (lastCertStoreUpdate == 0)
364 if (certRequestState == TLS_CERT_STATE_ASYNC)
370 certRequestState = TLS_CERT_STATE_VALID;
377 static void NotifyTlsReady(
void)
381 for (i = 0; i < callbackCount; i++)
383 if (tlsCallback[i] != NULL)
U32BIT STB_OSGetClockMilliseconds(void)
Get Current Computer Clock Time.
Manages the interface between MHEG5 Engine and the HTTP component.
MHEG5TlsCertRequestStatus MHEG5GetNextTlsCertificate(void)
Issues a request to load the next TLS certificate from the DSM-CC object carousel.
void MHEG5InvalidateTlsCertStore(void)
Invalidate the TLS certificate store.
void MHEG5AddTlsCertificateCallback(void(*loadCallback)(void))
Add a callback function to be called when pending requests are resolved.
void * MHEG5FileOrmGet(MHEG5String name, U16BIT priority, void *userData, F_CB_Good cbGood, F_CB_Fail cbFail)
Get a file. The file will be loaded and one of the callback functions called when request is resolved...
void MHEG5ClearTlsCertStore(void)
Clear the TLS certificate store.
This file defines the profile for the MHEG engine.
void httpClearTlsCertStore(void)
Clear TLS certificate store.
File interface functions to DSMCC component.
Functions relating to TLS certificate store.
void httpAddTlsCertToStore(U8BIT *certData, U32BIT certLen)
Add TLS certificate to store.
U32BIT MHEG5GetTlsCertStoreCount(void)
Return number of TLS certificates in the TLS certificate store.
U32BIT httpGetTlsCertStoreCount(void)
Return number of TLS certificate in the certificate store.
Header file - Function prototypes for operating system.