winpr: start porting to non-OpenSSL
This commit is contained in:
parent
8e3baed882
commit
94a2f9533e
@ -640,6 +640,14 @@ if(TARGET_ARCH MATCHES "x86|x64")
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(OPENSSL_FOUND)
|
||||||
|
add_definitions("-DWITH_OPENSSL")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(MBEDTLS_FOUND)
|
||||||
|
add_definitions("-DWITH_MBEDTLS")
|
||||||
|
endif()
|
||||||
|
|
||||||
if (TARGET_ARCH MATCHES "sparc")
|
if (TARGET_ARCH MATCHES "sparc")
|
||||||
set(HAVE_ALIGNED_REQUIRED 1)
|
set(HAVE_ALIGNED_REQUIRED 1)
|
||||||
endif()
|
endif()
|
||||||
|
@ -103,13 +103,17 @@ winpr_module_add(${${MODULE_PREFIX}_SRCS}
|
|||||||
winpr_include_directory_add(
|
winpr_include_directory_add(
|
||||||
"lodepng"
|
"lodepng"
|
||||||
"trio"
|
"trio"
|
||||||
"."
|
".")
|
||||||
${ZLIB_INCLUDE_DIRS}
|
|
||||||
${OPENSSL_INCLUDE_DIR})
|
|
||||||
|
|
||||||
winpr_library_add(
|
if(OPENSSL_FOUND)
|
||||||
${ZLIB_LIBRARIES}
|
winpr_include_directory_add(${OPENSSL_INCLUDE_DIR})
|
||||||
${OPENSSL_LIBRARIES})
|
winpr_library_add(${OPENSSL_LIBRARIES})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(MBEDTLS_FOUND)
|
||||||
|
winpr_include_directory_add(${MBEDTLS_INCLUDE_DIR})
|
||||||
|
winpr_library_add(${MBEDTLS_LIBRARIES})
|
||||||
|
endif()
|
||||||
|
|
||||||
if(UNIX)
|
if(UNIX)
|
||||||
winpr_library_add(m)
|
winpr_library_add(m)
|
||||||
|
@ -25,8 +25,10 @@
|
|||||||
|
|
||||||
#include <winpr/crt.h>
|
#include <winpr/crt.h>
|
||||||
|
|
||||||
|
#ifdef WITH_OPENSSL
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
#include <openssl/md4.h>
|
#include <openssl/md4.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define NTOWFv1(Password, User, Domain) as
|
* Define NTOWFv1(Password, User, Domain) as
|
||||||
@ -36,17 +38,20 @@
|
|||||||
|
|
||||||
BYTE* NTOWFv1W(LPWSTR Password, UINT32 PasswordLength, BYTE* NtHash)
|
BYTE* NTOWFv1W(LPWSTR Password, UINT32 PasswordLength, BYTE* NtHash)
|
||||||
{
|
{
|
||||||
MD4_CTX md4_ctx;
|
|
||||||
|
|
||||||
if (!Password)
|
if (!Password)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!NtHash && !(NtHash = malloc(16)))
|
if (!NtHash && !(NtHash = malloc(16)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
#ifdef WITH_OPENSSL
|
||||||
|
{
|
||||||
|
MD4_CTX md4_ctx;
|
||||||
MD4_Init(&md4_ctx);
|
MD4_Init(&md4_ctx);
|
||||||
MD4_Update(&md4_ctx, Password, PasswordLength);
|
MD4_Update(&md4_ctx, Password, PasswordLength);
|
||||||
MD4_Final((void*) NtHash, &md4_ctx);
|
MD4_Final((void*) NtHash, &md4_ctx);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return NtHash;
|
return NtHash;
|
||||||
}
|
}
|
||||||
@ -105,7 +110,9 @@ BYTE* NTOWFv2W(LPWSTR Password, UINT32 PasswordLength, LPWSTR User,
|
|||||||
CopyMemory(&buffer[UserLength], Domain, DomainLength);
|
CopyMemory(&buffer[UserLength], Domain, DomainLength);
|
||||||
|
|
||||||
/* Compute the HMAC-MD5 hash of the above value using the NTLMv1 hash as the key, the result is the NTLMv2 hash */
|
/* Compute the HMAC-MD5 hash of the above value using the NTLMv1 hash as the key, the result is the NTLMv2 hash */
|
||||||
|
#ifdef WITH_OPENSSL
|
||||||
HMAC(EVP_md5(), (void*) NtHashV1, 16, buffer, UserLength + DomainLength, (void*) NtHash, NULL);
|
HMAC(EVP_md5(), (void*) NtHashV1, 16, buffer, UserLength + DomainLength, (void*) NtHash, NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
|
||||||
@ -167,7 +174,9 @@ BYTE* NTOWFv2FromHashW(BYTE* NtHashV1, LPWSTR User, UINT32 UserLength, LPWSTR Do
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Compute the HMAC-MD5 hash of the above value using the NTLMv1 hash as the key, the result is the NTLMv2 hash */
|
/* Compute the HMAC-MD5 hash of the above value using the NTLMv1 hash as the key, the result is the NTLMv2 hash */
|
||||||
|
#ifdef WITH_OPENSSL
|
||||||
HMAC(EVP_md5(), (void*) NtHashV1, 16, buffer, UserLength + DomainLength, (void*) NtHash, NULL);
|
HMAC(EVP_md5(), (void*) NtHashV1, 16, buffer, UserLength + DomainLength, (void*) NtHash, NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
|
||||||
|
@ -18,11 +18,17 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <winpr/crt.h>
|
#include <winpr/crt.h>
|
||||||
#include <winpr/synch.h>
|
#include <winpr/synch.h>
|
||||||
#include <winpr/ssl.h>
|
#include <winpr/ssl.h>
|
||||||
#include <winpr/thread.h>
|
#include <winpr/thread.h>
|
||||||
|
|
||||||
|
#ifdef WITH_OPENSSL
|
||||||
|
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
|
|
||||||
@ -277,3 +283,17 @@ BOOL winpr_CleanupSSL(DWORD flags)
|
|||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
BOOL winpr_InitializeSSL(DWORD flags)
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL winpr_CleanupSSL(DWORD flags)
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@ -18,9 +18,6 @@
|
|||||||
set(MODULE_NAME "winpr-hash")
|
set(MODULE_NAME "winpr-hash")
|
||||||
set(MODULE_PREFIX "WINPR_TOOLS_HASH")
|
set(MODULE_PREFIX "WINPR_TOOLS_HASH")
|
||||||
|
|
||||||
include_directories(${ZLIB_INCLUDE_DIRS})
|
|
||||||
include_directories(${OPENSSL_INCLUDE_DIR})
|
|
||||||
|
|
||||||
set(${MODULE_PREFIX}_SRCS
|
set(${MODULE_PREFIX}_SRCS
|
||||||
hash.c)
|
hash.c)
|
||||||
|
|
||||||
@ -42,10 +39,7 @@ endif()
|
|||||||
|
|
||||||
add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
|
add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
|
||||||
|
|
||||||
set(${MODULE_PREFIX}_LIBS
|
set(${MODULE_PREFIX}_LIBS winpr)
|
||||||
${ZLIB_LIBRARIES}
|
|
||||||
${OPENSSL_LIBRARIES}
|
|
||||||
winpr)
|
|
||||||
|
|
||||||
target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
|
target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
|
||||||
|
|
||||||
|
@ -20,15 +20,25 @@ set(MODULE_PREFIX "WINPR_MAKECERT_TOOL")
|
|||||||
|
|
||||||
set(${MODULE_PREFIX}_SRCS makecert.c)
|
set(${MODULE_PREFIX}_SRCS makecert.c)
|
||||||
|
|
||||||
include_directories(${ZLIB_INCLUDE_DIRS})
|
if(OPENSSL_FOUND)
|
||||||
include_directories(${OPENSSL_INCLUDE_DIR})
|
include_directories(${OPENSSL_INCLUDE_DIR})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(MBEDTLS_FOUND)
|
||||||
|
include_directories(${MBEDTLS_INCLUDE_DIR})
|
||||||
|
endif()
|
||||||
|
|
||||||
add_library(${MODULE_NAME} STATIC ${${MODULE_PREFIX}_SRCS})
|
add_library(${MODULE_NAME} STATIC ${${MODULE_PREFIX}_SRCS})
|
||||||
|
|
||||||
set(${MODULE_PREFIX}_LIBS
|
set(${MODULE_PREFIX}_LIBS winpr)
|
||||||
${ZLIB_LIBRARIES}
|
|
||||||
${OPENSSL_LIBRARIES}
|
if(OPENSSL_FOUND)
|
||||||
winpr)
|
list(APPEND ${MODULE_PREFIX}_LIBS ${OPENSSL_LIBRARIES})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(MBEDTLS_FOUND)
|
||||||
|
list(APPEND ${MODULE_PREFIX}_LIBS ${MBEDTLS_LIBRARIES})
|
||||||
|
endif()
|
||||||
|
|
||||||
target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
|
target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
|
||||||
|
|
||||||
|
@ -17,19 +17,17 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include <winpr/crt.h>
|
#include <winpr/crt.h>
|
||||||
#include <winpr/path.h>
|
#include <winpr/path.h>
|
||||||
#include <winpr/cmdline.h>
|
#include <winpr/cmdline.h>
|
||||||
#include <winpr/sysinfo.h>
|
#include <winpr/sysinfo.h>
|
||||||
|
|
||||||
|
#ifdef WITH_OPENSSL
|
||||||
#include <openssl/conf.h>
|
#include <openssl/conf.h>
|
||||||
#include <openssl/pem.h>
|
#include <openssl/pem.h>
|
||||||
#include <openssl/pkcs12.h>
|
#include <openssl/pkcs12.h>
|
||||||
#include <openssl/x509v3.h>
|
#include <openssl/x509v3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <winpr/tools/makecert.h>
|
#include <winpr/tools/makecert.h>
|
||||||
|
|
||||||
@ -38,10 +36,12 @@ struct _MAKECERT_CONTEXT
|
|||||||
int argc;
|
int argc;
|
||||||
char** argv;
|
char** argv;
|
||||||
|
|
||||||
|
#ifdef WITH_OPENSSL
|
||||||
RSA* rsa;
|
RSA* rsa;
|
||||||
X509* x509;
|
X509* x509;
|
||||||
EVP_PKEY* pkey;
|
EVP_PKEY* pkey;
|
||||||
PKCS12* pkcs12;
|
PKCS12* pkcs12;
|
||||||
|
#endif
|
||||||
|
|
||||||
BOOL live;
|
BOOL live;
|
||||||
BOOL silent;
|
BOOL silent;
|
||||||
@ -265,6 +265,7 @@ int makecert_print_command_line_help(int argc, char** argv)
|
|||||||
|
|
||||||
int x509_add_ext(X509* cert, int nid, char* value)
|
int x509_add_ext(X509* cert, int nid, char* value)
|
||||||
{
|
{
|
||||||
|
#ifdef WITH_OPENSSL
|
||||||
X509V3_CTX ctx;
|
X509V3_CTX ctx;
|
||||||
X509_EXTENSION* ext;
|
X509_EXTENSION* ext;
|
||||||
|
|
||||||
@ -278,6 +279,7 @@ int x509_add_ext(X509* cert, int nid, char* value)
|
|||||||
|
|
||||||
X509_add_ext(cert, ext, -1);
|
X509_add_ext(cert, ext, -1);
|
||||||
X509_EXTENSION_free(ext);
|
X509_EXTENSION_free(ext);
|
||||||
|
#endif
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -493,6 +495,7 @@ int makecert_context_set_output_file_name(MAKECERT_CONTEXT* context, char* name)
|
|||||||
|
|
||||||
int makecert_context_output_certificate_file(MAKECERT_CONTEXT* context, char* path)
|
int makecert_context_output_certificate_file(MAKECERT_CONTEXT* context, char* path)
|
||||||
{
|
{
|
||||||
|
#ifdef WITH_OPENSSL
|
||||||
FILE* fp = NULL;
|
FILE* fp = NULL;
|
||||||
int status;
|
int status;
|
||||||
int length;
|
int length;
|
||||||
@ -741,10 +744,14 @@ out_fail:
|
|||||||
free(fullpath);
|
free(fullpath);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
#else
|
||||||
|
return 1;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int makecert_context_output_private_key_file(MAKECERT_CONTEXT* context, char* path)
|
int makecert_context_output_private_key_file(MAKECERT_CONTEXT* context, char* path)
|
||||||
{
|
{
|
||||||
|
#ifdef WITH_OPENSSL
|
||||||
FILE* fp = NULL;
|
FILE* fp = NULL;
|
||||||
int status;
|
int status;
|
||||||
int length;
|
int length;
|
||||||
@ -853,10 +860,14 @@ out_fail:
|
|||||||
free(fullpath);
|
free(fullpath);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
#else
|
||||||
|
return 1;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int makecert_context_process(MAKECERT_CONTEXT* context, int argc, char** argv)
|
int makecert_context_process(MAKECERT_CONTEXT* context, int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
#ifdef WITH_OPENSSL
|
||||||
int length;
|
int length;
|
||||||
char* entry;
|
char* entry;
|
||||||
int key_length;
|
int key_length;
|
||||||
@ -1100,7 +1111,7 @@ int makecert_context_process(MAKECERT_CONTEXT* context, int argc, char** argv)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1125,15 +1136,16 @@ void makecert_context_free(MAKECERT_CONTEXT* context)
|
|||||||
{
|
{
|
||||||
free(context->password);
|
free(context->password);
|
||||||
|
|
||||||
X509_free(context->x509);
|
|
||||||
EVP_PKEY_free(context->pkey);
|
|
||||||
|
|
||||||
free(context->default_name);
|
free(context->default_name);
|
||||||
free(context->common_name);
|
free(context->common_name);
|
||||||
free(context->output_file);
|
free(context->output_file);
|
||||||
free(context->output_path);
|
free(context->output_path);
|
||||||
|
|
||||||
|
#ifdef WITH_OPENSSL
|
||||||
|
X509_free(context->x509);
|
||||||
|
EVP_PKEY_free(context->pkey);
|
||||||
CRYPTO_cleanup_all_ex_data();
|
CRYPTO_cleanup_all_ex_data();
|
||||||
|
#endif
|
||||||
|
|
||||||
free(context);
|
free(context);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user