diff --git a/Makefile b/Makefile index 1da0ce7..0f97693 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,13 @@ OPTFLAGS += -DSETPROCTITLE -DSPT_TYPE=2 # System dependant blocks... if your system is listed below, uncomment # the relevant lines +# MSYS +# The current version of gcc from MSYS defines __MSYS__ and __CYGWIN__. +# To avoid to change the code, simply define CYGWIN additionally. +ifneq ($(filter $(MSYSTEM),MSYS MINGW32 MINGW64 UCRT64),) +CFLAGS += -DCYGWIN +endif + # OpenBSD #OPTFLAGS += -DHAVE_SYS_PSTAT_H diff --git a/buildwin.sh b/buildwin.sh index 52d8b59..5e1165c 100644 --- a/buildwin.sh +++ b/buildwin.sh @@ -4,13 +4,13 @@ echo "Build docs..." make -C docs echo "Build proxytunnel..." -make -f Makefile.ssl11 - -echo "Copy msys/openssl dll to build dir..." -cp /usr/bin/msys-2.0.dll /usr/bin/msys-crypto-1.1.dll /usr/bin/msys-ssl-1.1.dll /usr/bin/msys-z.dll . +make -f Makefile +strip -s proxytunnel.exe echo "Generate proxytunnel.zip with docs, exe and msys/openssl dll..." -zip proxytunnel.zip proxytunnel.exe *.dll docs/proxytunnel.1 docs/proxytunnel.1.html docs/proxytunnel-paper.html +zip proxytunnel.zip proxytunnel.exe docs/proxytunnel.1 docs/proxytunnel.1.html docs/proxytunnel-paper.html +DLLS="$(ldd proxytunnel.exe | grep msys.*\.dll | awk '{print $3}' | xargs) /usr/lib/ossl-modules/legacy.dll" +zip proxytunnel.zip -j $DLLS if [ ! -z "${TRAVIS_TAG}" ]; then echo "Deploy proxytunnel.zip to github release tag:${TRAVIS_TAG}..." diff --git a/ntlm.c b/ntlm.c index 54761f5..5159202 100644 --- a/ntlm.c +++ b/ntlm.c @@ -29,6 +29,9 @@ #include #include #if OPENSSL_VERSION_NUMBER >= 0x30000000L + #ifdef CYGWIN + #include + #endif #include #include #else @@ -71,8 +74,55 @@ unsigned char lm2digest[LM2_DIGEST_LEN]; void init_ntlm() { #if OPENSSL_VERSION_NUMBER >= 0x30000000L - OSSL_PROVIDER_load(NULL, "default"); - OSSL_PROVIDER_load(NULL, "legacy"); + OSSL_PROVIDER *provider; + provider = OSSL_PROVIDER_load(NULL, "default"); + if (!provider) { + my_perror("Loading default provider failed"); + exit(1); + } + provider = OSSL_PROVIDER_load(NULL, "legacy"); +#ifdef CYGWIN + if (!provider) { + // available at msys and git for windows + // the msys version has an additional dependency on libcrypto-3-x64.dll + provider = OSSL_PROVIDER_load(NULL, "/mingw64/lib/ossl-modules/legacy.dll"); + } + if (!provider) { + // available at msys (without dependency on libcrypto-3-x64.dll) + provider = OSSL_PROVIDER_load(NULL, "/usr/lib/ossl-modules/legacy.dll"); + } + if (!provider) { + // default installation path for additional tools + provider = OSSL_PROVIDER_load(NULL, "/usr/local/bin/legacy.dll"); + } + if (!provider) { + // directory of proxytunnel itself + const char *p = strrchr(program_name, '/'); + if (p) { + const int len = p - program_name; + char *tmp = (char*)alloca(len + sizeof("/legacy.dll")); + memcpy(tmp, program_name, len); + strcpy(tmp + len, "/legacy.dll"); + provider = OSSL_PROVIDER_load(NULL, tmp); + } + } + if (!provider) { + // current working directory + char *cwd = getcwd(NULL, 0); + if (cwd) { + const int len = strlen(cwd); + char *tmp = (char*)alloca(len + sizeof("/legacy.dll")); + memcpy(tmp, cwd, len); + free(cwd); + strcpy(tmp + len, "/legacy.dll"); + provider = OSSL_PROVIDER_load(NULL, tmp); + } + } +#endif + if (!provider) { + my_perror("Loading legacy provider failed"); + exit(1); + } md4alg = EVP_md4(); md5alg = EVP_md5(); mdctx = EVP_MD_CTX_new();