Merge pull request #1971 from awakecoding/master

Win32 Visual Studio Version + Toolset Fixes, makecert improvements
This commit is contained in:
Marc-André Moreau 2014-07-17 17:46:15 -04:00
commit 128a21a273
23 changed files with 243 additions and 32 deletions

View File

@ -233,9 +233,23 @@ endif()
if(WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUNICODE -D_UNICODE")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_WIN32_WINNT=0x0501")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWIN32_LEAN_AND_MEAN")
if(NOT DEFINED CMAKE_WINDOWS_VERSION)
set(CMAKE_WINDOWS_VERSION "WINXP")
endif()
if(CMAKE_WINDOWS_VERSION STREQUAL "WINXP")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWINVER=0x0501 -DWIN32_WINNT=0x0501")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWINVER=0x0501 -DWIN32_WINNT=0x0501")
elseif(CMAKE_WINDOWS_VERSION STREQUAL "WIN7")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWINVER=0x0601 -DWIN32_WINNT=0x0601")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWINVER=0x0601 -DWIN32_WINNT=0x0601")
elseif(CMAKE_WINDOWS_VERSION STREQUAL "WIN8")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWINVER=0x0602 -DWIN32_WINNT=0x0602")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWINVER=0x0602 -DWIN32_WINNT=0x0602")
endif()
endif()
if(IOS)

View File

@ -212,12 +212,14 @@ enum RDPDR_PRINTER_ANNOUNCE_FLAG
/* [MS-FSCC] FSCTL Structures */
#if !defined(_WIN32) || (defined(_WIN32) && (_WIN32_WINNT < 0x0600))
#define FSCTL_LMR_SET_LINK_TRACKING_INFORMATION 0x1400ec
#define FSCTL_PIPE_PEEK 0x11400c
#define FSCTL_PIPE_TRANSCEIVE 0x11c017
#define FSCTL_PIPE_WAIT 0x110018
#define FSCTL_QUERY_ON_DISK_VOLUME_INFO 0x9013c
#define FSCTL_QUERY_SPARING_INFO 0x90138
#endif
#ifndef _WIN32
#define FSCTL_CREATE_OR_GET_OBJECT_ID 0x900c0
@ -239,8 +241,10 @@ enum RDPDR_PRINTER_ANNOUNCE_FLAG
#define FSCTL_WRITE_USN_CLOSE_RECORD 0x900ef
#endif
#if !defined(_WIN32) || (defined(_WIN32) && (_WIN32_WINNT < 0x0600))
#define FSCTL_SET_DEFECT_MANAGEMENT 0x98134
#define FSCTL_SET_ZERO_ON_DEALLOCATION 0x90194
#endif
/* [MS-FSCC] FileFsAttributeInformation.FileSystemAttributes */

View File

@ -156,8 +156,16 @@ WINPR_API LONG InterlockedCompareExchange(LONG volatile *Destination, LONG Excha
#endif /* _WIN32 */
#if (!defined(_WIN32) || (defined(_WIN32) && (_WIN32_WINNT < 0x0502)))
#define WINPR_INTERLOCKED_COMPARE_EXCHANGE64 1
#endif
#ifdef WINPR_INTERLOCKED_COMPARE_EXCHANGE64
WINPR_API LONGLONG InterlockedCompareExchange64(LONGLONG volatile *Destination, LONGLONG Exchange, LONGLONG Comperand);
#endif
/* Doubly-Linked List */
WINPR_API VOID InitializeListHead(PLIST_ENTRY ListHead);

View File

@ -81,7 +81,6 @@ typedef struct _TP_CALLBACK_ENVIRON_V1
/* Non-Windows and pre Windows 7 */
#if ((!defined(_WIN32)) || (defined(_WIN32) && (_WIN32_WINNT < 0x0601)))
//#if !defined(_WIN32_WINNT_VISTA)
typedef struct _TP_CALLBACK_ENVIRON_V3
{
@ -121,7 +120,9 @@ typedef struct _TP_WAIT TP_WAIT, *PTP_WAIT;
typedef struct _TP_IO TP_IO, *PTP_IO;
#if !defined(_WIN32) || (defined(_WIN32) && (_WIN32_WINNT < 0x0601))
typedef TP_CALLBACK_ENVIRON_V1 TP_CALLBACK_ENVIRON, *PTP_CALLBACK_ENVIRON;
#endif
#ifndef _WIN32
@ -152,13 +153,18 @@ typedef VOID (*PTP_WIN32_IO_CALLBACK)(PTP_CALLBACK_INSTANCE Instance, PVOID Cont
#endif
#if (!defined(_WIN32) || ((defined(_WIN32) && (_WIN32_WINNT < 0x0601))))
#define WINPR_THREAD_POOL 1
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* Synch */
#ifdef WINPR_THREAD_POOL
WINPR_API PTP_WAIT CreateThreadpoolWait(PTP_WAIT_CALLBACK pfnwa, PVOID pv, PTP_CALLBACK_ENVIRON pcbe);
WINPR_API VOID CloseThreadpoolWait(PTP_WAIT pwa);
WINPR_API VOID SetThreadpoolWait(PTP_WAIT pwa, HANDLE h, PFILETIME pftTimeout);
@ -225,6 +231,8 @@ WINPR_API VOID LeaveCriticalSectionWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci
WINPR_API VOID FreeLibraryWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, HMODULE mod);
WINPR_API VOID DisassociateCurrentThreadFromCallback(PTP_CALLBACK_INSTANCE pci);
#endif
/* Dummy */
WINPR_API void winpr_pool_dummy(void);

View File

@ -297,7 +297,7 @@ WINPR_API BOOL DeleteTimerQueueTimer(HANDLE TimerQueue, HANDLE Timer, HANDLE Com
#endif
#if ((defined _WIN32) && (_WIN32_WINNT < 0x0403))
#if (defined(_WIN32) && (_WIN32_WINNT < 0x0600))
WINPR_API BOOL InitializeCriticalSectionEx(LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount, DWORD Flags);

View File

@ -33,6 +33,6 @@ set(${MODULE_PREFIX}_SRCS
winpr_module_add(${${MODULE_PREFIX}_SRCS})
if(BUILD_TESTING)
if(BUILD_TESTING AND UNIX AND NOT WIN32)
add_subdirectory(test)
endif()

View File

@ -90,9 +90,10 @@ int TestGetCommState(int argc, char* argv[])
return EXIT_FAILURE;
}
hComm = CreateFile("COM1",
hComm = CreateFileA("COM1",
GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING, 0, NULL);
if (hComm == INVALID_HANDLE_VALUE)
{
printf("CreateFileA failure: 0x%x\n", GetLastError());

View File

@ -19,7 +19,10 @@
#include <stdio.h>
#include <sys/stat.h>
#ifndef _WIN32
#include <termios.h>
#endif
#include <winpr/comm.h>
#include <winpr/crt.h>

View File

@ -19,7 +19,10 @@
#include <stdio.h>
#include <sys/stat.h>
#ifndef _WIN32
#include <termios.h>
#endif
#include <winpr/comm.h>
#include <winpr/crt.h>

View File

@ -19,7 +19,10 @@
#include <stdio.h>
#include <sys/stat.h>
#ifndef _WIN32
#include <termios.h>
#endif
#include <winpr/comm.h>
#include <winpr/crt.h>

View File

@ -20,6 +20,10 @@ winpr_module_add(
crypto.h
cert.c)
if(WIN32)
winpr_library_add(crypt32)
endif()
if(BUILD_TESTING)
add_subdirectory(test)
endif()

View File

@ -236,11 +236,11 @@ LONG InterlockedCompareExchange(LONG volatile *Destination, LONG Exchange, LONG
#endif /* _WIN32 */
#if defined(_WIN64)
#if defined(_WIN32) && !defined(WINPR_INTERLOCKED_COMPARE_EXCHANGE64)
/* InterlockedCompareExchange64 already defined */
#elif (_WIN32 && (_WIN32_WINNT < 0x0502))
#elif defined(_WIN32) && defined(WINPR_INTERLOCKED_COMPARE_EXCHANGE64)
static volatile HANDLE mutex = NULL;
@ -257,8 +257,6 @@ int static_mutex_lock(volatile HANDLE* static_mutex)
return (WaitForSingleObject(*static_mutex, INFINITE) == WAIT_FAILED);
}
/* Not available in XP */
LONGLONG InterlockedCompareExchange64(LONGLONG volatile *Destination, LONGLONG Exchange, LONGLONG Comperand)
{
LONGLONG previousValue = 0;

View File

@ -50,6 +50,8 @@ static void module_init()
#endif
#ifdef WINPR_THREAD_POOL
BOOL CallbackMayRunLong(PTP_CALLBACK_INSTANCE pci)
{
#ifdef _WIN32
@ -61,3 +63,5 @@ BOOL CallbackMayRunLong(PTP_CALLBACK_INSTANCE pci)
#endif
return FALSE;
}
#endif

View File

@ -62,6 +62,8 @@ static void module_init()
#endif
#ifdef WINPR_THREAD_POOL
VOID SetEventWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, HANDLE evt)
{
#ifdef _WIN32
@ -128,5 +130,5 @@ VOID DisassociateCurrentThreadFromCallback(PTP_CALLBACK_INSTANCE pci)
#endif
}
#endif

View File

@ -26,6 +26,8 @@
#include "pool.h"
#ifdef WINPR_THREAD_POOL
VOID InitializeCallbackEnvironment_V1(TP_CALLBACK_ENVIRON_V1* pcbe)
{
pcbe->Version = 1;
@ -55,6 +57,8 @@ VOID InitializeCallbackEnvironment_V3(TP_CALLBACK_ENVIRON_V3* pcbe)
pcbe->Size = sizeof(TP_CALLBACK_ENVIRON);
}
#endif
#ifdef _WIN32
static BOOL module_initialized = FALSE;
@ -116,6 +120,8 @@ PTP_CALLBACK_ENVIRON GetDefaultThreadpoolEnvironment()
#endif
#ifdef WINPR_THREAD_POOL
VOID InitializeThreadpoolEnvironment(PTP_CALLBACK_ENVIRON pcbe)
{
if (pcbe->Version == 3)
@ -193,3 +199,5 @@ VOID SetThreadpoolCallbackPriority(PTP_CALLBACK_ENVIRON pcbe, TP_CALLBACK_PRIORI
#else
#endif
}
#endif

View File

@ -56,6 +56,8 @@ static void module_init()
#endif
#if WINPR_THREAD_POOL
PTP_CLEANUP_GROUP CreateThreadpoolCleanupGroup()
{
PTP_CLEANUP_GROUP cleanupGroup = NULL;
@ -94,4 +96,5 @@ VOID CloseThreadpoolCleanupGroup(PTP_CLEANUP_GROUP ptpcg)
#endif
}
#endif

View File

@ -24,6 +24,8 @@
#include <winpr/crt.h>
#include <winpr/pool.h>
#ifdef WINPR_THREAD_POOL
PTP_IO CreateThreadpoolIo(HANDLE fl, PTP_WIN32_IO_CALLBACK pfnio, PVOID pv, PTP_CALLBACK_ENVIRON pcbe)
{
return NULL;
@ -49,3 +51,4 @@ VOID WaitForThreadpoolIoCallbacks(PTP_IO pio, BOOL fCancelPendingCallbacks)
}
#endif

View File

@ -150,6 +150,8 @@ PTP_POOL GetDefaultThreadpool()
#endif
#ifdef WINPR_THREAD_POOL
PTP_POOL CreateThreadpool(PVOID reserved)
{
PTP_POOL pool = NULL;
@ -236,6 +238,8 @@ VOID SetThreadpoolThreadMaximum(PTP_POOL ptpp, DWORD cthrdMost)
#endif
}
#endif
/* dummy */
void winpr_pool_dummy()

View File

@ -24,6 +24,8 @@
#include <winpr/crt.h>
#include <winpr/pool.h>
#ifdef WINPR_THREAD_POOL
PTP_WAIT CreateThreadpoolWait(PTP_WAIT_CALLBACK pfnwa, PVOID pv, PTP_CALLBACK_ENVIRON pcbe)
{
return NULL;
@ -44,4 +46,4 @@ VOID WaitForThreadpoolWaitCallbacks(PTP_WAIT pwa, BOOL fCancelPendingCallbacks)
}
#endif

View File

@ -24,6 +24,8 @@
#include <winpr/crt.h>
#include <winpr/pool.h>
#ifdef WINPR_THREAD_POOL
PTP_TIMER CreateThreadpoolTimer(PTP_TIMER_CALLBACK pfnti, PVOID pv, PTP_CALLBACK_ENVIRON pcbe)
{
return NULL;
@ -49,4 +51,4 @@ VOID WaitForThreadpoolTimerCallbacks(PTP_TIMER pti, BOOL fCancelPendingCallbacks
}
#endif

View File

@ -60,6 +60,8 @@ static void module_init()
#endif
#ifdef WINPR_THREAD_POOL
PTP_WORK CreateThreadpoolWork(PTP_WORK_CALLBACK pfnwk, PVOID pv, PTP_CALLBACK_ENVIRON pcbe)
{
PTP_WORK work = NULL;
@ -153,3 +155,5 @@ VOID WaitForThreadpoolWorkCallbacks(PTP_WORK pwk, BOOL fCancelPendingCallbacks)
printf("WaitForThreadpoolWorkCallbacks: error waiting on work completion\n");
#endif
}
#endif

View File

@ -235,7 +235,7 @@ VOID DeleteCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
#endif
#if ((_WIN32) && (_WIN32_WINNT < 0x0403))
#if (defined(_WIN32) && (_WIN32_WINNT < 0x0600))
typedef BOOL (WINAPI * PINITIALIZE_CRITICAL_SECTION_EX_FN)(LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount, DWORD Flags);

View File

@ -27,8 +27,10 @@
#include <winpr/cmdline.h>
#include <winpr/sysinfo.h>
#include <openssl/pem.h>
#include <openssl/conf.h>
#include <openssl/pem.h>
#include <openssl/err.h>
#include <openssl/pkcs12.h>
#include <openssl/x509v3.h>
#include <winpr/tools/makecert.h>
@ -42,12 +44,24 @@ struct _MAKECERT_CONTEXT
RSA* rsa;
X509* x509;
EVP_PKEY* pkey;
PKCS12* pkcs12;
BOOL live;
BOOL silent;
BOOL crtFormat;
BOOL pemFormat;
BOOL pfxFormat;
char* password;
char* output_file;
char* output_path;
char* default_name;
char* common_name;
int duration_years;
int duration_months;
};
COMMAND_LINE_ARGUMENT_A args[] =
@ -63,6 +77,15 @@ COMMAND_LINE_ARGUMENT_A args[] =
{ "live", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, NULL,
"Generate certificate live in memory when used as a library."
},
{ "format", COMMAND_LINE_VALUE_REQUIRED, "<crt|pem|pfx>", NULL, NULL, -1, NULL,
"Specify certificate file format"
},
{ "path", COMMAND_LINE_VALUE_REQUIRED, "<path>", NULL, NULL, -1, NULL,
"Specify certificate file output path"
},
{ "p", COMMAND_LINE_VALUE_REQUIRED, "<password>", NULL, NULL, -1, NULL,
"Specify certificate export password"
},
/* Basic Options */
@ -154,6 +177,9 @@ COMMAND_LINE_ARGUMENT_A args[] =
{ "m", COMMAND_LINE_VALUE_REQUIRED, "<number>", NULL, NULL, -1, NULL,
"Specifies the duration, in months, of the certificate validity period."
},
{ "y", COMMAND_LINE_VALUE_REQUIRED, "<number>", NULL, NULL, -1, NULL,
"Specifies the duration, in years, of the certificate validity period."
},
{ "nscp", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, NULL,
"Includes the Netscape client-authorization extension."
},
@ -346,6 +372,65 @@ int makecert_context_parse_arguments(MAKECERT_CONTEXT* context, int argc, char**
{
context->live = TRUE;
}
CommandLineSwitchCase(arg, "format")
{
if (!(arg->Flags & COMMAND_LINE_ARGUMENT_PRESENT))
continue;
if (strcmp(arg->Value, "crt") == 0)
{
context->crtFormat = TRUE;
context->pemFormat = FALSE;
context->pfxFormat = FALSE;
}
else if (strcmp(arg->Value, "pem") == 0)
{
context->crtFormat = FALSE;
context->pemFormat = TRUE;
context->pfxFormat = FALSE;
}
else if (strcmp(arg->Value, "pfx") == 0)
{
context->crtFormat = FALSE;
context->pemFormat = FALSE;
context->pfxFormat = TRUE;
}
}
CommandLineSwitchCase(arg, "path")
{
if (!(arg->Flags & COMMAND_LINE_ARGUMENT_PRESENT))
continue;
context->output_path = _strdup(arg->Value);
}
CommandLineSwitchCase(arg, "p")
{
if (!(arg->Flags & COMMAND_LINE_ARGUMENT_PRESENT))
continue;
context->password = _strdup(arg->Value);
}
CommandLineSwitchCase(arg, "n")
{
if (!(arg->Flags & COMMAND_LINE_ARGUMENT_PRESENT))
continue;
context->common_name = _strdup(arg->Value);
}
CommandLineSwitchCase(arg, "y")
{
if (!(arg->Flags & COMMAND_LINE_ARGUMENT_PRESENT))
continue;
context->duration_years = atoi(arg->Value);
}
CommandLineSwitchCase(arg, "m")
{
if (!(arg->Flags & COMMAND_LINE_ARGUMENT_PRESENT))
continue;
context->duration_months = atoi(arg->Value);
}
CommandLineSwitchDefault(arg)
{
@ -374,7 +459,7 @@ int makecert_context_output_certificate_file(MAKECERT_CONTEXT* context, char* pa
char* fullpath;
if (!context->output_file)
context->output_file = context->default_name;
context->output_file = _strdup(context->default_name);
/*
* Output Certificate File
@ -383,7 +468,13 @@ int makecert_context_output_certificate_file(MAKECERT_CONTEXT* context, char* pa
length = strlen(context->output_file);
filename = malloc(length + 8);
strcpy(filename, context->output_file);
strcpy(&filename[length], ".crt");
if (context->crtFormat)
strcpy(&filename[length], ".crt");
else if (context->pemFormat)
strcpy(&filename[length], ".pem");
else if (context->pfxFormat)
strcpy(&filename[length], ".pfx");
if (path)
fullpath = GetCombinedPath(path, filename);
@ -394,7 +485,31 @@ int makecert_context_output_certificate_file(MAKECERT_CONTEXT* context, char* pa
if (fp)
{
PEM_write_X509(fp, context->x509);
if (context->pfxFormat)
{
if (!context->password)
{
context->password = _strdup("password");
printf("Using default export password \"password\"\n");
}
OpenSSL_add_all_algorithms();
OpenSSL_add_all_ciphers();
OpenSSL_add_all_digests();
context->pkcs12 = PKCS12_create(context->password, context->default_name, context->pkey,
context->x509, NULL, 0, 0, 0, 0, 0);
i2d_PKCS12_fp(fp, context->pkcs12);
}
else
{
PEM_write_X509(fp, context->x509);
if (context->pemFormat)
PEM_write_PrivateKey(fp, context->pkey, NULL, NULL, 0, NULL, NULL);
}
fclose(fp);
}
@ -411,6 +526,9 @@ int makecert_context_output_private_key_file(MAKECERT_CONTEXT* context, char* pa
char* filename;
char* fullpath;
if (!context->crtFormat)
return 1;
if (!context->output_file)
context->output_file = context->default_name;
@ -456,7 +574,13 @@ int makecert_context_process(MAKECERT_CONTEXT* context, int argc, char** argv)
if (makecert_context_parse_arguments(context, argc, argv) < 1)
return 0;
context->default_name = x509_get_default_name();
if (!context->default_name && !context->common_name)
context->default_name = x509_get_default_name();
else
context->default_name = _strdup(context->common_name);
if (!context->common_name)
context->common_name = _strdup(context->default_name);
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
context->bio = BIO_new_fp(stderr, BIO_NOCLOSE);
@ -501,7 +625,16 @@ int makecert_context_process(MAKECERT_CONTEXT* context, int argc, char** argv)
ASN1_INTEGER_set(X509_get_serialNumber(context->x509), serial);
X509_gmtime_adj(X509_get_notBefore(context->x509), 0);
X509_gmtime_adj(X509_get_notAfter(context->x509), (long) 60 * 60 * 24 * 365);
if (context->duration_months)
{
X509_gmtime_adj(X509_get_notAfter(context->x509), (long) (60 * 60 * 24 * 31 * context->duration_months));
}
else if (context->duration_years)
{
X509_gmtime_adj(X509_get_notAfter(context->x509), (long) (60 * 60 * 24 * 365 * context->duration_years));
}
X509_set_pubkey(context->x509, context->pkey);
name = X509_get_subject_name(context->x509);
@ -535,19 +668,14 @@ int makecert_context_process(MAKECERT_CONTEXT* context, int argc, char** argv)
if (entry)
X509_NAME_add_entry_by_txt(name, "OU", MBSTRING_UTF8, (const unsigned char*) entry, length, -1, 0);
entry = x509_name_parse(arg->Value, "CN", &length);
if (!entry)
{
entry = context->default_name;
length = strlen(entry);
}
entry = context->common_name;
length = strlen(entry);
X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_UTF8, (const unsigned char*) entry, length, -1, 0);
}
else
{
entry = context->default_name;
entry = context->common_name;
length = strlen(entry);
X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_UTF8, (const unsigned char*) entry, length, -1, 0);
@ -592,8 +720,10 @@ int makecert_context_process(MAKECERT_CONTEXT* context, int argc, char** argv)
if (!context->live)
{
makecert_context_output_certificate_file(context, NULL);
makecert_context_output_private_key_file(context, NULL);
makecert_context_output_certificate_file(context, context->output_path);
if (context->crtFormat)
makecert_context_output_private_key_file(context, context->output_path);
}
return 0;
@ -603,11 +733,12 @@ MAKECERT_CONTEXT* makecert_context_new()
{
MAKECERT_CONTEXT* context = NULL;
context = (MAKECERT_CONTEXT*) malloc(sizeof(MAKECERT_CONTEXT));
context = (MAKECERT_CONTEXT*) calloc(1, sizeof(MAKECERT_CONTEXT));
if (context)
{
ZeroMemory(context, sizeof(MAKECERT_CONTEXT));
context->crtFormat = TRUE;
context->duration_years = 1;
}
return context;
@ -617,6 +748,8 @@ void makecert_context_free(MAKECERT_CONTEXT* context)
{
if (context)
{
free(context->password);
X509_free(context->x509);
EVP_PKEY_free(context->pkey);