Use self-built openssl for Windows

This commit is contained in:
z3apa3a 2021-07-01 19:55:20 +03:00
parent d7eb9fb82f
commit 1fca6ada82
5 changed files with 52 additions and 36 deletions

View File

@ -8,13 +8,13 @@
BUILDDIR = ../bin/ BUILDDIR = ../bin/
CC = cl CC = cl
CFLAGS = /nologo /MT /W3 /Ox /GS /EHs- /GA /GF /D "MSVC" /D "WITH_STD_MALLOC" /D "WITH_WSAPOLL" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_WIN32" /D "PRINTF_INT64_MODIFIER=\"I64\"" /Fp"proxy.pch" /FD /c $(VERSION) $(BUILDDATE) CFLAGS = /nologo /MT /W3 /Ox /GS /EHs- /GA /GF /D "MSVC" /D "WITH_STD_MALLOC" /D "WITH_WSAPOLL" /D "NDEBUG" /D "WIN32" /D "WITH_SSL" /D "_CONSOLE" /D "_MBCS" /D "_WIN32" /D "PRINTF_INT64_MODIFIER=\"I64\"" /Fp"proxy.pch" /FD /c $(VERSION) $(BUILDDATE)
COUT = /Fo COUT = /Fo
LN = link LN = link
LDFLAGS = /nologo /subsystem:console /incremental:no /machine:I386 LDFLAGS = /nologo /subsystem:console /incremental:no /machine:I386
DLFLAGS = /DLL DLFLAGS = /DLL
DLSUFFICS = .dll DLSUFFICS = .dll
LIBS = ws2_32.lib advapi32.lib odbc32.lib user32.lib kernel32.lib Gdi32.lib libeay32.lib ssleay32.lib LIBS = ws2_32.lib advapi32.lib odbc32.lib user32.lib kernel32.lib Gdi32.lib libcrypto_static.lib libssl_static.lib
LIBSOLD = libeay32MT.lib ssleay32MT.lib LIBSOLD = libeay32MT.lib ssleay32MT.lib
LIBSPREFIX = LIBSPREFIX =
LIBSSUFFIX = .lib LIBSSUFFIX = .lib

View File

@ -8,13 +8,13 @@
BUILDDIR = ../bin64/ BUILDDIR = ../bin64/
CC = cl CC = cl
CFLAGS = /nologo /MT /W3 /Ox /EHs- /GS /GA /GF /D "MSVC" /D "WITH_STD_MALLOC" /D "WITH_WSAPOLL" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_WIN32" /D "PRINTF_INT64_MODIFIER=\"I64\"" /Fp"proxy.pch" /FD /c $(VERSION) $(BUILDDATE) CFLAGS = /nologo /MT /W3 /Ox /EHs- /GS /GA /GF /D "MSVC" /D "WITH_STD_MALLOC" /D "WITH_SSL" /D "WITH_WSAPOLL" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_WIN32" /D "PRINTF_INT64_MODIFIER=\"I64\"" /Fp"proxy.pch" /FD /c $(VERSION) $(BUILDDATE)
COUT = /Fo COUT = /Fo
LN = link LN = link
LDFLAGS = /nologo /subsystem:console /incremental:no /machine:x64 LDFLAGS = /nologo /subsystem:console /incremental:no /machine:x64
DLFLAGS = /DLL DLFLAGS = /DLL
DLSUFFICS = .dll DLSUFFICS = .dll
LIBS = ws2_32.lib advapi32.lib odbc32.lib user32.lib kernel32.lib Gdi32.lib libeay32.lib ssleay32.lib LIBS = ws2_32.lib advapi32.lib odbc32.lib user32.lib kernel32.lib Gdi32.lib libcrypto_static.lib libssl_static.lib
LIBSOLD = libeay32.lib ssleay32.lib LIBSOLD = libeay32.lib ssleay32.lib
LIBSPREFIX = LIBSPREFIX =
LIBSSUFFIX = .lib LIBSSUFFIX = .lib

View File

@ -8,13 +8,13 @@
BUILDDIR = ../bin64/ BUILDDIR = ../bin64/
CC = cl CC = cl
CFLAGS = /nologo /MT /W3 /Ox /EHs- /GS /GA /GF /D "MSVC" /D "WITH_STD_MALLOC" /D "WITH_WSAPOLL" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_WIN32" /D "PRINTF_INT64_MODIFIER=\"I64\"" /Fp"proxy.pch" /FD /c $(VERSION) $(BUILDDATE) CFLAGS = /nologo /MT /W3 /Ox /EHs- /GS /GA /GF /D "MSVC" /D "WITH_STD_MALLOC" /D "WITH_WSAPOLL" /D "WITH_SSL" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_WIN32" /D "PRINTF_INT64_MODIFIER=\"I64\"" /Fp"proxy.pch" /FD /c $(VERSION) $(BUILDDATE)
COUT = /Fo COUT = /Fo
LN = link LN = link
LDFLAGS = /nologo /subsystem:console /incremental:no /machine:arm64 LDFLAGS = /nologo /subsystem:console /incremental:no /machine:arm64
DLFLAGS = /DLL DLFLAGS = /DLL
DLSUFFICS = .dll DLSUFFICS = .dll
LIBS = ws2_32.lib advapi32.lib odbc32.lib user32.lib kernel32.lib Gdi32.lib LIBS = ws2_32.lib advapi32.lib odbc32.lib user32.lib kernel32.lib Gdi32.lib libcrypto_static.lib libssl_static.lib
LIBSOLD = LIBSOLD =
LIBSPREFIX = LIBSPREFIX =
LIBSSUFFIX = .lib LIBSSUFFIX = .lib
@ -28,7 +28,7 @@ REMOVECOMMAND = del 2>NUL >NUL
TYPECOMMAND = type TYPECOMMAND = type
COMPATLIBS = COMPATLIBS =
MAKEFILE = Makefile.msvcARM64 MAKEFILE = Makefile.msvcARM64
PLUGINS = utf8tocp1251 WindowsAuthentication TrafficPlugin StringsPlugin PCREPlugin FilePlugin PLUGINS = utf8tocp1251 WindowsAuthentication TrafficPlugin StringsPlugin PCREPlugin FilePlugin SSLPlugin
VERFILE = 3proxy.res $(VERFILE) VERFILE = 3proxy.res $(VERFILE)
VERSIONDEP = 3proxy.res $(VERSIONDEP) VERSIONDEP = 3proxy.res $(VERSIONDEP)
AFTERCLEAN = del src\*.res AFTERCLEAN = del src\*.res

View File

@ -12,6 +12,11 @@
#ifndef NOPLUGINS #ifndef NOPLUGINS
#include <dlfcn.h> #include <dlfcn.h>
#endif #endif
#else
#ifdef WITH_SSL
#include <openssl/applink.c>
#endif
#endif #endif
#ifndef DEFAULTCONFIG #ifndef DEFAULTCONFIG

View File

@ -14,9 +14,6 @@
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/ssl.h> #include <openssl/ssl.h>
#include <openssl/err.h> #include <openssl/err.h>
#ifdef WIN32
#include <openssl/applink.c>
#endif
#include "../../proxy.h" #include "../../proxy.h"
#include "my_ssl.h" #include "my_ssl.h"
@ -104,7 +101,7 @@ void del_ext(X509 *dst_cert, int nid, int where){
SSL_CERT ssl_copy_cert(SSL_CERT cert) SSL_CERT ssl_copy_cert(SSL_CERT cert)
{ {
int err = -1; int err = -1;
FILE *fcache; BIO *fcache;
X509 *src_cert = (X509 *) cert; X509 *src_cert = (X509 *) cert;
X509 *dst_cert = NULL; X509 *dst_cert = NULL;
@ -129,16 +126,16 @@ SSL_CERT ssl_copy_cert(SSL_CERT cert)
bin2hex(hash_sha1, 20, hash_name_sha1, sizeof(hash_name_sha1)); bin2hex(hash_sha1, 20, hash_name_sha1, sizeof(hash_name_sha1));
sprintf(cache_name, "%s%s.pem", cert_path, hash_name_sha1); sprintf(cache_name, "%s%s.pem", cert_path, hash_name_sha1);
/* check if certificate is already cached */ /* check if certificate is already cached */
fcache = fopen(cache_name, "rb"); fcache = BIO_new_file(cache_name, "rb");
if ( fcache != NULL ) { if ( fcache != NULL ) {
#ifndef _WIN32 #ifndef _WIN32
flock(fileno(fcache), LOCK_SH); flock(BIO_get_fd(fcache, NULL), LOCK_SH);
#endif #endif
dst_cert = PEM_read_X509(fcache, &dst_cert, NULL, NULL); dst_cert = PEM_read_bio_X509(fcache, &dst_cert, NULL, NULL);
#ifndef _WIN32 #ifndef _WIN32
flock(fileno(fcache), LOCK_UN); flock(BIO_get_fd(fcache, NULL), LOCK_UN);
#endif #endif
fclose(fcache); BIO_free(fcache);
if ( dst_cert != NULL ){ if ( dst_cert != NULL ){
return dst_cert; return dst_cert;
} }
@ -174,16 +171,16 @@ SSL_CERT ssl_copy_cert(SSL_CERT cert)
/* write to cache */ /* write to cache */
fcache = fopen(cache_name, "wb"); fcache = BIO_new_file(cache_name, "wb");
if ( fcache != NULL ) { if ( fcache != NULL ) {
#ifndef _WIN32 #ifndef _WIN32
flock(fileno(fcache), LOCK_EX); flock(BIO_get_fd(fcache, NULL), LOCK_EX);
#endif #endif
PEM_write_X509(fcache, dst_cert); PEM_write_bio_X509(fcache, dst_cert);
#ifndef _WIN32 #ifndef _WIN32
flock(fileno(fcache), LOCK_UN); flock(BIO_get_fd(fcache, NULL), LOCK_UN);
#endif #endif
fclose(fcache); BIO_free(fcache);
} }
return dst_cert; return dst_cert;
} }
@ -414,50 +411,64 @@ int ssl_file_init = 0;
void ssl_init(void) void ssl_init(void)
{ {
FILE *f; BIO *f;
static char fname[200]; static char fname[200];
if(!ssl_file_init++)pthread_mutex_init(&ssl_file_mutex, NULL); if(!ssl_file_init++)pthread_mutex_init(&ssl_file_mutex, NULL);
pthread_mutex_lock(&ssl_file_mutex); pthread_mutex_lock(&ssl_file_mutex);
thread_setup(); thread_setup();
SSLeay_add_ssl_algorithms(); SSLeay_add_ssl_algorithms();
SSL_load_error_strings(); SSL_load_error_strings();
sprintf(fname, "%.128s3proxy.pem", cert_path); sprintf(fname, "%.128s3proxy.pem", cert_path);
f = fopen(fname, "r"); f = BIO_new_file(fname, "r");
if ( f != NULL ) { if ( f != NULL ) {
PEM_read_X509(f, &CA_cert, NULL, NULL); if(!(CA_cert=PEM_read_bio_X509(f, NULL, NULL, NULL))){
fclose(f); unsigned long err;
err=ERR_get_error();
fprintf(stderr, "failed to read: %s: [%lu] %s\n", fname, err, ERR_error_string(err, NULL));
return;
}
BIO_free(f);
} }
else { else {
fprintf(stderr, "failed to open: %s\n", fname); fprintf(stderr, "failed to open: %s\n", fname);
return;
} }
name = X509_get_subject_name(CA_cert); name = X509_get_subject_name(CA_cert);
sprintf(fname, "%.128s3proxy.key", cert_path); sprintf(fname, "%.128s3proxy.key", cert_path);
f = fopen(fname, "rb"); f = BIO_new_file(fname, "rb");
if ( f != NULL ) { if ( f != NULL ) {
CA_key = PEM_read_PrivateKey(f, &CA_key, NULL, NULL); CA_key = PEM_read_bio_PrivateKey(f, NULL, NULL, NULL);
fclose(f); if(!CA_key){
unsigned long err;
err=ERR_get_error();
fprintf(stderr, "failed to read: %s: [%lu] %s\n", fname, err, ERR_error_string(err, NULL));
return;
}
BIO_free(f);
} }
else { else {
fprintf(stderr, "failed to open: %s\n", fname); fprintf(stderr, "failed to open: %s\n", fname);
return;
} }
sprintf(fname, "%.128sserver.key", cert_path); sprintf(fname, "%.128sserver.key", cert_path);
f = fopen(fname, "rb"); f = BIO_new_file(fname, "rb");
if ( f != NULL ) { if ( f != NULL ) {
server_key = PEM_read_PrivateKey(f, &server_key, NULL, NULL); server_key = PEM_read_bio_PrivateKey(f, &server_key, NULL, NULL);
fclose(f); if(!server_key){
unsigned long err;
err=ERR_get_error();
fprintf(stderr, "failed to read: %s: [%lu] %s\n", fname, err, ERR_error_string(err, NULL));
return;
}
BIO_free(f);
} }
else { else {
fprintf(stderr, "failed to open: %s\n", fname); fprintf(stderr, "failed to open: %s\n", fname);
} }
if(!CA_cert || !CA_key || !server_key){
fprintf(stderr, "failed to init SSL certificate / keys\n");
}
bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
pthread_mutex_unlock(&ssl_file_mutex); pthread_mutex_unlock(&ssl_file_mutex);