mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-10-19 19:27:45 -04:00
Update WolfSSL library to the latest version.
This commit is contained in:
parent
8af1ad9bac
commit
5a6242fbd0
443 changed files with 70230 additions and 45414 deletions
|
@ -1,15 +1,15 @@
|
|||
/* crl.c
|
||||
*
|
||||
* Copyright (C) 2006-2014 wolfSSL Inc.
|
||||
* Copyright (C) 2006-2015 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of CyaSSL.
|
||||
* This file is part of wolfSSL. (formerly known as CyaSSL)
|
||||
*
|
||||
* CyaSSL is free software; you can redistribute it and/or modify
|
||||
* wolfSSL is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* CyaSSL is distributed in the hope that it will be useful,
|
||||
* wolfSSL is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
@ -19,16 +19,18 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
/* Name change compatibility layer no longer needs included here */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <cyassl/ctaocrypt/settings.h>
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
|
||||
#ifdef HAVE_CRL
|
||||
|
||||
#include <cyassl/internal.h>
|
||||
#include <cyassl/error-ssl.h>
|
||||
#include <wolfssl/internal.h>
|
||||
#include <wolfssl/error-ssl.h>
|
||||
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -40,9 +42,9 @@
|
|||
|
||||
|
||||
/* Initialze CRL members */
|
||||
int InitCRL(CYASSL_CRL* crl, CYASSL_CERT_MANAGER* cm)
|
||||
int InitCRL(WOLFSSL_CRL* crl, WOLFSSL_CERT_MANAGER* cm)
|
||||
{
|
||||
CYASSL_ENTER("InitCRL");
|
||||
WOLFSSL_ENTER("InitCRL");
|
||||
|
||||
crl->cm = cm;
|
||||
crl->crlList = NULL;
|
||||
|
@ -62,10 +64,10 @@ int InitCRL(CYASSL_CRL* crl, CYASSL_CERT_MANAGER* cm)
|
|||
/* Initialze CRL Entry */
|
||||
static int InitCRL_Entry(CRL_Entry* crle, DecodedCRL* dcrl)
|
||||
{
|
||||
CYASSL_ENTER("InitCRL_Entry");
|
||||
WOLFSSL_ENTER("InitCRL_Entry");
|
||||
|
||||
XMEMCPY(crle->issuerHash, dcrl->issuerHash, SHA_DIGEST_SIZE);
|
||||
/* XMEMCPY(crle->crlHash, dcrl->crlHash, SHA_DIGEST_SIZE);
|
||||
XMEMCPY(crle->issuerHash, dcrl->issuerHash, CRL_DIGEST_SIZE);
|
||||
/* XMEMCPY(crle->crlHash, dcrl->crlHash, CRL_DIGEST_SIZE);
|
||||
* copy the hash here if needed for optimized comparisons */
|
||||
XMEMCPY(crle->lastDate, dcrl->lastDate, MAX_DATE_SIZE);
|
||||
XMEMCPY(crle->nextDate, dcrl->nextDate, MAX_DATE_SIZE);
|
||||
|
@ -85,7 +87,7 @@ static void FreeCRL_Entry(CRL_Entry* crle)
|
|||
{
|
||||
RevokedCert* tmp = crle->certs;
|
||||
|
||||
CYASSL_ENTER("FreeCRL_Entry");
|
||||
WOLFSSL_ENTER("FreeCRL_Entry");
|
||||
|
||||
while(tmp) {
|
||||
RevokedCert* next = tmp->next;
|
||||
|
@ -97,11 +99,11 @@ static void FreeCRL_Entry(CRL_Entry* crle)
|
|||
|
||||
|
||||
/* Free all CRL resources */
|
||||
void FreeCRL(CYASSL_CRL* crl, int dynamic)
|
||||
void FreeCRL(WOLFSSL_CRL* crl, int dynamic)
|
||||
{
|
||||
CRL_Entry* tmp = crl->crlList;
|
||||
|
||||
CYASSL_ENTER("FreeCRL");
|
||||
WOLFSSL_ENTER("FreeCRL");
|
||||
|
||||
if (crl->monitors[0].path)
|
||||
XFREE(crl->monitors[0].path, NULL, DYNAMIC_TYPE_CRL_MONITOR);
|
||||
|
@ -118,11 +120,11 @@ void FreeCRL(CYASSL_CRL* crl, int dynamic)
|
|||
|
||||
#ifdef HAVE_CRL_MONITOR
|
||||
if (crl->tid != 0) {
|
||||
CYASSL_MSG("stopping monitor thread");
|
||||
WOLFSSL_MSG("stopping monitor thread");
|
||||
if (StopMonitor(crl->mfd) == 0)
|
||||
pthread_join(crl->tid, NULL);
|
||||
else {
|
||||
CYASSL_MSG("stop monitor failed, cancel instead");
|
||||
WOLFSSL_MSG("stop monitor failed, cancel instead");
|
||||
pthread_cancel(crl->tid);
|
||||
}
|
||||
}
|
||||
|
@ -134,28 +136,28 @@ void FreeCRL(CYASSL_CRL* crl, int dynamic)
|
|||
|
||||
|
||||
/* Is the cert ok with CRL, return 0 on success */
|
||||
int CheckCertCRL(CYASSL_CRL* crl, DecodedCert* cert)
|
||||
int CheckCertCRL(WOLFSSL_CRL* crl, DecodedCert* cert)
|
||||
{
|
||||
CRL_Entry* crle;
|
||||
int foundEntry = 0;
|
||||
int ret = 0;
|
||||
|
||||
CYASSL_ENTER("CheckCertCRL");
|
||||
WOLFSSL_ENTER("CheckCertCRL");
|
||||
|
||||
if (LockMutex(&crl->crlLock) != 0) {
|
||||
CYASSL_MSG("LockMutex failed");
|
||||
WOLFSSL_MSG("LockMutex failed");
|
||||
return BAD_MUTEX_E;
|
||||
}
|
||||
|
||||
crle = crl->crlList;
|
||||
|
||||
while (crle) {
|
||||
if (XMEMCMP(crle->issuerHash, cert->issuerHash, SHA_DIGEST_SIZE) == 0) {
|
||||
CYASSL_MSG("Found CRL Entry on list");
|
||||
CYASSL_MSG("Checking next date validity");
|
||||
if (XMEMCMP(crle->issuerHash, cert->issuerHash, CRL_DIGEST_SIZE) == 0) {
|
||||
WOLFSSL_MSG("Found CRL Entry on list");
|
||||
WOLFSSL_MSG("Checking next date validity");
|
||||
|
||||
if (!ValidateDate(crle->nextDate, crle->nextDateFormat, AFTER)) {
|
||||
CYASSL_MSG("CRL next date is no longer valid");
|
||||
WOLFSSL_MSG("CRL next date is no longer valid");
|
||||
ret = ASN_AFTER_DATE_E;
|
||||
}
|
||||
else
|
||||
|
@ -170,7 +172,7 @@ int CheckCertCRL(CYASSL_CRL* crl, DecodedCert* cert)
|
|||
|
||||
while (rc) {
|
||||
if (XMEMCMP(rc->serialNumber, cert->serial, rc->serialSz) == 0) {
|
||||
CYASSL_MSG("Cert revoked");
|
||||
WOLFSSL_MSG("Cert revoked");
|
||||
ret = CRL_CERT_REVOKED;
|
||||
break;
|
||||
}
|
||||
|
@ -181,19 +183,19 @@ int CheckCertCRL(CYASSL_CRL* crl, DecodedCert* cert)
|
|||
UnLockMutex(&crl->crlLock);
|
||||
|
||||
if (foundEntry == 0) {
|
||||
CYASSL_MSG("Couldn't find CRL for status check");
|
||||
WOLFSSL_MSG("Couldn't find CRL for status check");
|
||||
ret = CRL_MISSING;
|
||||
if (crl->cm->cbMissingCRL) {
|
||||
char url[256];
|
||||
|
||||
CYASSL_MSG("Issuing missing CRL callback");
|
||||
WOLFSSL_MSG("Issuing missing CRL callback");
|
||||
url[0] = '\0';
|
||||
if (cert->extCrlInfoSz < (int)sizeof(url) -1 ) {
|
||||
XMEMCPY(url, cert->extCrlInfo, cert->extCrlInfoSz);
|
||||
url[cert->extCrlInfoSz] = '\0';
|
||||
}
|
||||
else {
|
||||
CYASSL_MSG("CRL url too long");
|
||||
WOLFSSL_MSG("CRL url too long");
|
||||
}
|
||||
crl->cm->cbMissingCRL(url);
|
||||
}
|
||||
|
@ -205,26 +207,26 @@ int CheckCertCRL(CYASSL_CRL* crl, DecodedCert* cert)
|
|||
|
||||
|
||||
/* Add Decoded CRL, 0 on success */
|
||||
static int AddCRL(CYASSL_CRL* crl, DecodedCRL* dcrl)
|
||||
static int AddCRL(WOLFSSL_CRL* crl, DecodedCRL* dcrl)
|
||||
{
|
||||
CRL_Entry* crle;
|
||||
|
||||
CYASSL_ENTER("AddCRL");
|
||||
WOLFSSL_ENTER("AddCRL");
|
||||
|
||||
crle = (CRL_Entry*)XMALLOC(sizeof(CRL_Entry), NULL, DYNAMIC_TYPE_CRL_ENTRY);
|
||||
if (crle == NULL) {
|
||||
CYASSL_MSG("alloc CRL Entry failed");
|
||||
WOLFSSL_MSG("alloc CRL Entry failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (InitCRL_Entry(crle, dcrl) < 0) {
|
||||
CYASSL_MSG("Init CRL Entry failed");
|
||||
WOLFSSL_MSG("Init CRL Entry failed");
|
||||
XFREE(crle, NULL, DYNAMIC_TYPE_CRL_ENTRY);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (LockMutex(&crl->crlLock) != 0) {
|
||||
CYASSL_MSG("LockMutex failed");
|
||||
WOLFSSL_MSG("LockMutex failed");
|
||||
FreeCRL_Entry(crle);
|
||||
XFREE(crle, NULL, DYNAMIC_TYPE_CRL_ENTRY);
|
||||
return BAD_MUTEX_E;
|
||||
|
@ -238,16 +240,20 @@ static int AddCRL(CYASSL_CRL* crl, DecodedCRL* dcrl)
|
|||
|
||||
|
||||
/* Load CRL File of type, SSL_SUCCESS on ok */
|
||||
int BufferLoadCRL(CYASSL_CRL* crl, const byte* buff, long sz, int type)
|
||||
int BufferLoadCRL(WOLFSSL_CRL* crl, const byte* buff, long sz, int type)
|
||||
{
|
||||
int ret = SSL_SUCCESS;
|
||||
const byte* myBuffer = buff; /* if DER ok, otherwise switch */
|
||||
buffer der;
|
||||
DecodedCRL dcrl;
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
DecodedCRL* dcrl;
|
||||
#else
|
||||
DecodedCRL dcrl[1];
|
||||
#endif
|
||||
|
||||
der.buffer = NULL;
|
||||
|
||||
CYASSL_ENTER("BufferLoadCRL");
|
||||
WOLFSSL_ENTER("BufferLoadCRL");
|
||||
|
||||
if (crl == NULL || buff == NULL || sz == 0)
|
||||
return BAD_FUNC_ARG;
|
||||
|
@ -263,30 +269,43 @@ int BufferLoadCRL(CYASSL_CRL* crl, const byte* buff, long sz, int type)
|
|||
sz = der.length;
|
||||
}
|
||||
else {
|
||||
CYASSL_MSG("Pem to Der failed");
|
||||
WOLFSSL_MSG("Pem to Der failed");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
InitDecodedCRL(&dcrl);
|
||||
ret = ParseCRL(&dcrl, myBuffer, (word32)sz, crl->cm);
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
dcrl = (DecodedCRL*)XMALLOC(sizeof(DecodedCRL), NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (dcrl == NULL) {
|
||||
if (der.buffer)
|
||||
XFREE(der.buffer, NULL, DYNAMIC_TYPE_CRL);
|
||||
|
||||
return MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
InitDecodedCRL(dcrl);
|
||||
ret = ParseCRL(dcrl, myBuffer, (word32)sz, crl->cm);
|
||||
if (ret != 0) {
|
||||
CYASSL_MSG("ParseCRL error");
|
||||
WOLFSSL_MSG("ParseCRL error");
|
||||
}
|
||||
else {
|
||||
ret = AddCRL(crl, &dcrl);
|
||||
ret = AddCRL(crl, dcrl);
|
||||
if (ret != 0) {
|
||||
CYASSL_MSG("AddCRL error");
|
||||
WOLFSSL_MSG("AddCRL error");
|
||||
}
|
||||
}
|
||||
FreeDecodedCRL(&dcrl);
|
||||
|
||||
FreeDecodedCRL(dcrl);
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(dcrl, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
|
||||
if (der.buffer)
|
||||
XFREE(der.buffer, NULL, DYNAMIC_TYPE_CRL);
|
||||
|
||||
if (ret == 0)
|
||||
return SSL_SUCCESS; /* convert */
|
||||
return ret;
|
||||
return ret ? ret : SSL_SUCCESS; /* convert 0 to SSL_SUCCESS */
|
||||
}
|
||||
|
||||
|
||||
|
@ -294,50 +313,76 @@ int BufferLoadCRL(CYASSL_CRL* crl, const byte* buff, long sz, int type)
|
|||
|
||||
|
||||
/* read in new CRL entries and save new list */
|
||||
static int SwapLists(CYASSL_CRL* crl)
|
||||
static int SwapLists(WOLFSSL_CRL* crl)
|
||||
{
|
||||
int ret;
|
||||
CYASSL_CRL tmp;
|
||||
CRL_Entry* newList;
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
WOLFSSL_CRL* tmp;
|
||||
#else
|
||||
WOLFSSL_CRL tmp[1];
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
tmp = (WOLFSSL_CRL*)XMALLOC(sizeof(WOLFSSL_CRL), NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (tmp == NULL)
|
||||
return MEMORY_E;
|
||||
#endif
|
||||
|
||||
if (InitCRL(&tmp, crl->cm) < 0) {
|
||||
CYASSL_MSG("Init tmp CRL failed");
|
||||
if (InitCRL(tmp, crl->cm) < 0) {
|
||||
WOLFSSL_MSG("Init tmp CRL failed");
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (crl->monitors[0].path) {
|
||||
ret = LoadCRL(&tmp, crl->monitors[0].path, SSL_FILETYPE_PEM, 0);
|
||||
ret = LoadCRL(tmp, crl->monitors[0].path, SSL_FILETYPE_PEM, 0);
|
||||
if (ret != SSL_SUCCESS) {
|
||||
CYASSL_MSG("PEM LoadCRL on dir change failed");
|
||||
FreeCRL(&tmp, 0);
|
||||
WOLFSSL_MSG("PEM LoadCRL on dir change failed");
|
||||
FreeCRL(tmp, 0);
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (crl->monitors[1].path) {
|
||||
ret = LoadCRL(&tmp, crl->monitors[1].path, SSL_FILETYPE_ASN1, 0);
|
||||
ret = LoadCRL(tmp, crl->monitors[1].path, SSL_FILETYPE_ASN1, 0);
|
||||
if (ret != SSL_SUCCESS) {
|
||||
CYASSL_MSG("DER LoadCRL on dir change failed");
|
||||
FreeCRL(&tmp, 0);
|
||||
WOLFSSL_MSG("DER LoadCRL on dir change failed");
|
||||
FreeCRL(tmp, 0);
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (LockMutex(&crl->crlLock) != 0) {
|
||||
CYASSL_MSG("LockMutex failed");
|
||||
FreeCRL(&tmp, 0);
|
||||
WOLFSSL_MSG("LockMutex failed");
|
||||
FreeCRL(tmp, 0);
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
newList = tmp.crlList;
|
||||
newList = tmp->crlList;
|
||||
|
||||
/* swap lists */
|
||||
tmp.crlList = crl->crlList;
|
||||
tmp->crlList = crl->crlList;
|
||||
crl->crlList = newList;
|
||||
|
||||
UnLockMutex(&crl->crlLock);
|
||||
|
||||
FreeCRL(&tmp, 0);
|
||||
FreeCRL(tmp, 0);
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -373,7 +418,7 @@ static int StopMonitor(int mfd)
|
|||
/* trigger custom shutdown */
|
||||
EV_SET(&change, CRL_CUSTOM_FD, EVFILT_USER, 0, NOTE_TRIGGER, 0, NULL);
|
||||
if (kevent(mfd, &change, 1, NULL, 0, NULL) < 0) {
|
||||
CYASSL_MSG("kevent trigger customer event failed");
|
||||
WOLFSSL_MSG("kevent trigger customer event failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -387,20 +432,20 @@ static void* DoMonitor(void* arg)
|
|||
int fPEM, fDER;
|
||||
struct kevent change;
|
||||
|
||||
CYASSL_CRL* crl = (CYASSL_CRL*)arg;
|
||||
WOLFSSL_CRL* crl = (WOLFSSL_CRL*)arg;
|
||||
|
||||
CYASSL_ENTER("DoMonitor");
|
||||
WOLFSSL_ENTER("DoMonitor");
|
||||
|
||||
crl->mfd = kqueue();
|
||||
if (crl->mfd == -1) {
|
||||
CYASSL_MSG("kqueue failed");
|
||||
WOLFSSL_MSG("kqueue failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* listen for custom shutdown event */
|
||||
EV_SET(&change, CRL_CUSTOM_FD, EVFILT_USER, EV_ADD, 0, 0, NULL);
|
||||
if (kevent(crl->mfd, &change, 1, NULL, 0, NULL) < 0) {
|
||||
CYASSL_MSG("kevent monitor customer event failed");
|
||||
WOLFSSL_MSG("kevent monitor customer event failed");
|
||||
close(crl->mfd);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -411,7 +456,7 @@ static void* DoMonitor(void* arg)
|
|||
if (crl->monitors[0].path) {
|
||||
fPEM = open(crl->monitors[0].path, XEVENT_MODE);
|
||||
if (fPEM == -1) {
|
||||
CYASSL_MSG("PEM event dir open failed");
|
||||
WOLFSSL_MSG("PEM event dir open failed");
|
||||
close(crl->mfd);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -420,7 +465,7 @@ static void* DoMonitor(void* arg)
|
|||
if (crl->monitors[1].path) {
|
||||
fDER = open(crl->monitors[1].path, XEVENT_MODE);
|
||||
if (fDER == -1) {
|
||||
CYASSL_MSG("DER event dir open failed");
|
||||
WOLFSSL_MSG("DER event dir open failed");
|
||||
close(crl->mfd);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -438,20 +483,20 @@ static void* DoMonitor(void* arg)
|
|||
struct kevent event;
|
||||
int numEvents = kevent(crl->mfd, &change, 1, &event, 1, NULL);
|
||||
|
||||
CYASSL_MSG("Got kevent");
|
||||
WOLFSSL_MSG("Got kevent");
|
||||
|
||||
if (numEvents == -1) {
|
||||
CYASSL_MSG("kevent problem, continue");
|
||||
WOLFSSL_MSG("kevent problem, continue");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (event.filter == EVFILT_USER) {
|
||||
CYASSL_MSG("Got user shutdown event, breaking out");
|
||||
WOLFSSL_MSG("Got user shutdown event, breaking out");
|
||||
break;
|
||||
}
|
||||
|
||||
if (SwapLists(crl) < 0) {
|
||||
CYASSL_MSG("SwapLists problem, continue");
|
||||
WOLFSSL_MSG("SwapLists problem, continue");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -489,7 +534,7 @@ static int StopMonitor(int mfd)
|
|||
|
||||
/* write to our custom event */
|
||||
if (write(mfd, &w64, sizeof(w64)) < 0) {
|
||||
CYASSL_MSG("StopMonitor write failed");
|
||||
WOLFSSL_MSG("StopMonitor write failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -502,19 +547,24 @@ static void* DoMonitor(void* arg)
|
|||
{
|
||||
int notifyFd;
|
||||
int wd = -1;
|
||||
CYASSL_CRL* crl = (CYASSL_CRL*)arg;
|
||||
WOLFSSL_CRL* crl = (WOLFSSL_CRL*)arg;
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
char* buff;
|
||||
#else
|
||||
char buff[8192];
|
||||
#endif
|
||||
|
||||
CYASSL_ENTER("DoMonitor");
|
||||
WOLFSSL_ENTER("DoMonitor");
|
||||
|
||||
crl->mfd = eventfd(0, 0); /* our custom shutdown event */
|
||||
if (crl->mfd < 0) {
|
||||
CYASSL_MSG("eventfd failed");
|
||||
WOLFSSL_MSG("eventfd failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
notifyFd = inotify_init();
|
||||
if (notifyFd < 0) {
|
||||
CYASSL_MSG("inotify failed");
|
||||
WOLFSSL_MSG("inotify failed");
|
||||
close(crl->mfd);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -523,7 +573,7 @@ static void* DoMonitor(void* arg)
|
|||
wd = inotify_add_watch(notifyFd, crl->monitors[0].path, IN_CLOSE_WRITE |
|
||||
IN_DELETE);
|
||||
if (wd < 0) {
|
||||
CYASSL_MSG("PEM notify add watch failed");
|
||||
WOLFSSL_MSG("PEM notify add watch failed");
|
||||
close(crl->mfd);
|
||||
close(notifyFd);
|
||||
return NULL;
|
||||
|
@ -534,17 +584,23 @@ static void* DoMonitor(void* arg)
|
|||
wd = inotify_add_watch(notifyFd, crl->monitors[1].path, IN_CLOSE_WRITE |
|
||||
IN_DELETE);
|
||||
if (wd < 0) {
|
||||
CYASSL_MSG("DER notify add watch failed");
|
||||
WOLFSSL_MSG("DER notify add watch failed");
|
||||
close(crl->mfd);
|
||||
close(notifyFd);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
buff = (char*)XMALLOC(8192, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (buff == NULL)
|
||||
return NULL;
|
||||
#endif
|
||||
|
||||
for (;;) {
|
||||
fd_set readfds;
|
||||
char buff[8192];
|
||||
int result, length;
|
||||
fd_set readfds;
|
||||
int result;
|
||||
int length;
|
||||
|
||||
FD_ZERO(&readfds);
|
||||
FD_SET(notifyFd, &readfds);
|
||||
|
@ -552,29 +608,33 @@ static void* DoMonitor(void* arg)
|
|||
|
||||
result = select(max(notifyFd, crl->mfd) + 1, &readfds, NULL, NULL,NULL);
|
||||
|
||||
CYASSL_MSG("Got notify event");
|
||||
WOLFSSL_MSG("Got notify event");
|
||||
|
||||
if (result < 0) {
|
||||
CYASSL_MSG("select problem, continue");
|
||||
WOLFSSL_MSG("select problem, continue");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (FD_ISSET(crl->mfd, &readfds)) {
|
||||
CYASSL_MSG("got custom shutdown event, breaking out");
|
||||
WOLFSSL_MSG("got custom shutdown event, breaking out");
|
||||
break;
|
||||
}
|
||||
|
||||
length = read(notifyFd, buff, sizeof(buff));
|
||||
length = read(notifyFd, buff, 8192);
|
||||
if (length < 0) {
|
||||
CYASSL_MSG("notify read problem, continue");
|
||||
WOLFSSL_MSG("notify read problem, continue");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (SwapLists(crl) < 0) {
|
||||
CYASSL_MSG("SwapLists problem, continue");
|
||||
WOLFSSL_MSG("SwapLists problem, continue");
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(buff, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
|
||||
if (wd > 0)
|
||||
inotify_rm_watch(notifyFd, wd);
|
||||
close(crl->mfd);
|
||||
|
@ -592,24 +652,24 @@ static void* DoMonitor(void* arg)
|
|||
|
||||
|
||||
/* Start Monitoring the CRL path(s) in a thread */
|
||||
static int StartMonitorCRL(CYASSL_CRL* crl)
|
||||
static int StartMonitorCRL(WOLFSSL_CRL* crl)
|
||||
{
|
||||
pthread_attr_t attr;
|
||||
|
||||
CYASSL_ENTER("StartMonitorCRL");
|
||||
WOLFSSL_ENTER("StartMonitorCRL");
|
||||
|
||||
if (crl == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
if (crl->tid != 0) {
|
||||
CYASSL_MSG("Monitor thread already running");
|
||||
WOLFSSL_MSG("Monitor thread already running");
|
||||
return MONITOR_RUNNING_E;
|
||||
}
|
||||
|
||||
pthread_attr_init(&attr);
|
||||
|
||||
if (pthread_create(&crl->tid, &attr, DoMonitor, crl) != 0) {
|
||||
CYASSL_MSG("Thread creation error");
|
||||
WOLFSSL_MSG("Thread creation error");
|
||||
return THREAD_CREATE_E;
|
||||
}
|
||||
|
||||
|
@ -619,12 +679,12 @@ static int StartMonitorCRL(CYASSL_CRL* crl)
|
|||
|
||||
#else /* HAVE_CRL_MONITOR */
|
||||
|
||||
static int StartMonitorCRL(CYASSL_CRL* crl)
|
||||
static int StartMonitorCRL(WOLFSSL_CRL* crl)
|
||||
{
|
||||
(void)crl;
|
||||
|
||||
CYASSL_ENTER("StartMonitorCRL");
|
||||
CYASSL_MSG("Not compiled in");
|
||||
WOLFSSL_ENTER("StartMonitorCRL");
|
||||
WOLFSSL_MSG("Not compiled in");
|
||||
|
||||
return NOT_COMPILED_IN;
|
||||
}
|
||||
|
@ -633,39 +693,50 @@ static int StartMonitorCRL(CYASSL_CRL* crl)
|
|||
|
||||
|
||||
/* Load CRL path files of type, SSL_SUCCESS on ok */
|
||||
int LoadCRL(CYASSL_CRL* crl, const char* path, int type, int monitor)
|
||||
int LoadCRL(WOLFSSL_CRL* crl, const char* path, int type, int monitor)
|
||||
{
|
||||
struct dirent* entry;
|
||||
DIR* dir;
|
||||
int ret = SSL_SUCCESS;
|
||||
DIR* dir;
|
||||
int ret = SSL_SUCCESS;
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
char* name;
|
||||
#else
|
||||
char name[MAX_FILENAME_SZ];
|
||||
#endif
|
||||
|
||||
CYASSL_ENTER("LoadCRL");
|
||||
WOLFSSL_ENTER("LoadCRL");
|
||||
if (crl == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
dir = opendir(path);
|
||||
if (dir == NULL) {
|
||||
CYASSL_MSG("opendir path crl load failed");
|
||||
WOLFSSL_MSG("opendir path crl load failed");
|
||||
return BAD_PATH_ERROR;
|
||||
}
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
name = (char*)XMALLOC(MAX_FILENAME_SZ, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (name == NULL)
|
||||
return MEMORY_E;
|
||||
#endif
|
||||
|
||||
while ( (entry = readdir(dir)) != NULL) {
|
||||
char name[MAX_FILENAME_SZ];
|
||||
struct stat s;
|
||||
|
||||
XMEMSET(name, 0, sizeof(name));
|
||||
XMEMSET(name, 0, MAX_FILENAME_SZ);
|
||||
XSTRNCPY(name, path, MAX_FILENAME_SZ/2 - 2);
|
||||
XSTRNCAT(name, "/", 1);
|
||||
XSTRNCAT(name, entry->d_name, MAX_FILENAME_SZ/2);
|
||||
|
||||
if (stat(name, &s) != 0) {
|
||||
CYASSL_MSG("stat on name failed");
|
||||
WOLFSSL_MSG("stat on name failed");
|
||||
continue;
|
||||
}
|
||||
if (s.st_mode & S_IFREG) {
|
||||
|
||||
if (type == SSL_FILETYPE_PEM) {
|
||||
if (strstr(entry->d_name, ".pem") == NULL) {
|
||||
CYASSL_MSG("not .pem file, skipping");
|
||||
WOLFSSL_MSG("not .pem file, skipping");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -673,20 +744,24 @@ int LoadCRL(CYASSL_CRL* crl, const char* path, int type, int monitor)
|
|||
if (strstr(entry->d_name, ".der") == NULL &&
|
||||
strstr(entry->d_name, ".crl") == NULL) {
|
||||
|
||||
CYASSL_MSG("not .der or .crl file, skipping");
|
||||
WOLFSSL_MSG("not .der or .crl file, skipping");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (ProcessFile(NULL, name, type, CRL_TYPE, NULL, 0, crl)
|
||||
!= SSL_SUCCESS) {
|
||||
CYASSL_MSG("CRL file load failed, continuing");
|
||||
WOLFSSL_MSG("CRL file load failed, continuing");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (monitor & CYASSL_CRL_MONITOR) {
|
||||
CYASSL_MSG("monitor path requested");
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
|
||||
if (monitor & WOLFSSL_CRL_MONITOR) {
|
||||
WOLFSSL_MSG("monitor path requested");
|
||||
|
||||
if (type == SSL_FILETYPE_PEM) {
|
||||
crl->monitors[0].path = strdup(path);
|
||||
|
@ -700,8 +775,8 @@ int LoadCRL(CYASSL_CRL* crl, const char* path, int type, int monitor)
|
|||
ret = MEMORY_E;
|
||||
}
|
||||
|
||||
if (monitor & CYASSL_CRL_START_MON) {
|
||||
CYASSL_MSG("start monitoring requested");
|
||||
if (monitor & WOLFSSL_CRL_START_MON) {
|
||||
WOLFSSL_MSG("start monitoring requested");
|
||||
|
||||
ret = StartMonitorCRL(crl);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue