mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-04 13:14:45 +02:00
add path handling (basic) for load_verify_locations()
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
AC_INIT([cyassl],[2.0.6],[http://www.yassl.com])
|
AC_INIT([cyassl],[2.0.6b],[http://www.yassl.com])
|
||||||
|
|
||||||
AC_CONFIG_AUX_DIR(config)
|
AC_CONFIG_AUX_DIR(config)
|
||||||
|
|
||||||
|
@@ -164,10 +164,11 @@ enum {
|
|||||||
|
|
||||||
#define XSTRLEN(s1) strlen((s1))
|
#define XSTRLEN(s1) strlen((s1))
|
||||||
#define XSTRNCPY(s1,s2,n) strncpy((s1),(s2),(n))
|
#define XSTRNCPY(s1,s2,n) strncpy((s1),(s2),(n))
|
||||||
/* strstr and strncmp only used by CyaSSL proper, not required for
|
/* strstr, strncmp, and strncat only used by CyaSSL proper, not required for
|
||||||
CTaoCrypt only */
|
CTaoCrypt only */
|
||||||
#define XSTRSTR(s1,s2) strstr((s1),(s2))
|
#define XSTRSTR(s1,s2) strstr((s1),(s2))
|
||||||
#define XSTRNCMP(s1,s2,n) strncmp((s1),(s2),(n))
|
#define XSTRNCMP(s1,s2,n) strncmp((s1),(s2),(n))
|
||||||
|
#define XSTRNCAT(s1,s2,n) strncat((s1),(s2),(n))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_ECC
|
#ifdef HAVE_ECC
|
||||||
|
@@ -90,6 +90,7 @@ enum CyaSSL_ErrorCodes {
|
|||||||
ECC_SHARED_ERROR = -255, /* Bad ECC Shared Secret */
|
ECC_SHARED_ERROR = -255, /* Bad ECC Shared Secret */
|
||||||
BAD_MUTEX_ERROR = -256, /* Bad mutex */
|
BAD_MUTEX_ERROR = -256, /* Bad mutex */
|
||||||
NOT_CA_ERROR = -257, /* Not a CA cert error */
|
NOT_CA_ERROR = -257, /* Not a CA cert error */
|
||||||
|
BAD_PATH_ERROR = -258, /* Bad path for opendir */
|
||||||
/* add strings to SetErrorString !!!!! */
|
/* add strings to SetErrorString !!!!! */
|
||||||
|
|
||||||
/* begin negotiation parameter errors */
|
/* begin negotiation parameter errors */
|
||||||
|
@@ -359,6 +359,7 @@ enum Misc {
|
|||||||
MAX_CHAIN_DEPTH = 4, /* max cert chain peer depth */
|
MAX_CHAIN_DEPTH = 4, /* max cert chain peer depth */
|
||||||
MAX_X509_SIZE = 2048, /* max static x509 buffer size */
|
MAX_X509_SIZE = 2048, /* max static x509 buffer size */
|
||||||
CERT_MIN_SIZE = 256, /* min PEM cert size with header/footer */
|
CERT_MIN_SIZE = 256, /* min PEM cert size with header/footer */
|
||||||
|
MAX_FILENAME_SZ = 256, /* max file name length */
|
||||||
FILE_BUFFER_SIZE = 1024, /* default static file buffer size for input,
|
FILE_BUFFER_SIZE = 1024, /* default static file buffer size for input,
|
||||||
will use dynamic buffer if not big enough */
|
will use dynamic buffer if not big enough */
|
||||||
|
|
||||||
|
@@ -3351,6 +3351,10 @@ void SetErrorString(int error, char* str)
|
|||||||
XSTRNCPY(str, "Not a CA by basic constraint error", max);
|
XSTRNCPY(str, "Not a CA by basic constraint error", max);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case BAD_PATH_ERROR:
|
||||||
|
XSTRNCPY(str, "Bad path for opendir error", max);
|
||||||
|
break;
|
||||||
|
|
||||||
default :
|
default :
|
||||||
XSTRNCPY(str, "unknown error number", max);
|
XSTRNCPY(str, "unknown error number", max);
|
||||||
}
|
}
|
||||||
|
66
src/ssl.c
66
src/ssl.c
@@ -52,6 +52,14 @@
|
|||||||
#include <cyassl/ctaocrypt/md5.h>
|
#include <cyassl/ctaocrypt/md5.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef NO_FILESYSTEM
|
||||||
|
#ifdef USE_WINDOWS_API
|
||||||
|
|
||||||
|
#else
|
||||||
|
#include <dirent.h>
|
||||||
|
#endif /* USE_WINDOWS_API */
|
||||||
|
#endif /* NO_FILESYSTEM */
|
||||||
|
|
||||||
|
|
||||||
#ifndef min
|
#ifndef min
|
||||||
|
|
||||||
@@ -1085,17 +1093,71 @@ static int ProcessFile(CYASSL_CTX* ctx, const char* fname, int format, int type,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* just one for now TODO: add dir support from path */
|
/* loads each file in path, no c_rehash */
|
||||||
int CyaSSL_CTX_load_verify_locations(CYASSL_CTX* ctx, const char* file,
|
int CyaSSL_CTX_load_verify_locations(CYASSL_CTX* ctx, const char* file,
|
||||||
const char* path)
|
const char* path)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
CYASSL_ENTER("SSL_CTX_load_verify_locations");
|
CYASSL_ENTER("SSL_CTX_load_verify_locations");
|
||||||
(void)path;
|
(void)path;
|
||||||
|
|
||||||
if (ctx == NULL || file == NULL)
|
if (ctx == NULL || file == NULL)
|
||||||
return SSL_FAILURE;
|
return SSL_FAILURE;
|
||||||
|
|
||||||
return ProcessFile(ctx, file, SSL_FILETYPE_PEM, CA_TYPE, NULL, 0);
|
ret = ProcessFile(ctx, file, SSL_FILETYPE_PEM, CA_TYPE, NULL, 0);
|
||||||
|
|
||||||
|
if (ret == SSL_SUCCESS && path) {
|
||||||
|
/* try to load each regular file in path */
|
||||||
|
#ifdef USE_WINDOWS_API
|
||||||
|
WIN32_FIND_DATAA FindFileData;
|
||||||
|
HANDLE hFind;
|
||||||
|
|
||||||
|
char name[MAX_FILENAME_SZ];
|
||||||
|
XSTRNCPY(name, path, MAX_FILENAME_SZ - 4);
|
||||||
|
XSTRNCAT(name, "\\*", 3);
|
||||||
|
|
||||||
|
hFind = FindFirstFileA(name, &FindFileData);
|
||||||
|
if (hFind == INVALID_HANDLE_VALUE) {
|
||||||
|
CYASSL_MSG("FindFirstFile for path verify locations failed");
|
||||||
|
return BAD_PATH_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (FindFileData.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY) {
|
||||||
|
XSTRNCPY(name, path, MAX_FILENAME_SZ/2 - 3);
|
||||||
|
XSTRNCAT(name, "\\", 2);
|
||||||
|
XSTRNCAT(name, FindFileData.cFileName, MAX_FILENAME_SZ/2);
|
||||||
|
|
||||||
|
ret = ProcessFile(ctx, name, SSL_FILETYPE_PEM, CA_TYPE, NULL,0);
|
||||||
|
}
|
||||||
|
} while (ret == SSL_SUCCESS && FindNextFileA(hFind, &FindFileData));
|
||||||
|
|
||||||
|
FindClose(hFind);
|
||||||
|
#else
|
||||||
|
struct dirent* entry;
|
||||||
|
DIR* dir = opendir(path);
|
||||||
|
|
||||||
|
if (dir == NULL) {
|
||||||
|
CYASSL_MSG("opendir path verify locations failed");
|
||||||
|
return BAD_PATH_ERROR;
|
||||||
|
}
|
||||||
|
while ( ret == SSL_SUCCESS && (entry = readdir(dir)) != NULL) {
|
||||||
|
if (entry->d_type & DT_REG) {
|
||||||
|
char name[MAX_FILENAME_SZ];
|
||||||
|
|
||||||
|
XSTRNCPY(name, path, MAX_FILENAME_SZ/2 - 2);
|
||||||
|
XSTRNCAT(name, "/", 1);
|
||||||
|
XSTRNCAT(name, entry->d_name, MAX_FILENAME_SZ/2);
|
||||||
|
|
||||||
|
ret = ProcessFile(ctx, name, SSL_FILETYPE_PEM, CA_TYPE, NULL,0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir(dir);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user