diff --git a/main.c b/main.c index 510f309..6b7f44e 100644 --- a/main.c +++ b/main.c @@ -53,8 +53,7 @@ #include "as.h" #ifndef DISABLE_CHANGE_PASSWORD -#include -#include +#include #endif #define OVPN_EXITCODE_ERROR 1 @@ -287,9 +286,9 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance, #ifndef DISABLE_CHANGE_PASSWORD /* Initialize OpenSSL */ - OpenSSL_add_all_algorithms(); - ERR_load_crypto_strings(); -#endif + set_openssl_env_vars(); + OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL); +#endif /* DISABLE_CHANGE_PASSWORD */ /* The Window structure */ wincl.hInstance = hThisInstance; diff --git a/misc.c b/misc.c index 861163f..782ed4c 100644 --- a/misc.c +++ b/misc.c @@ -713,3 +713,28 @@ ImportConfigFile(const TCHAR* source, bool prompt_user) /* destroy popup menus, based on existing num_configs, rescan file list and recreate menus */ RecreatePopupMenus(); } + +void +set_openssl_env_vars() +{ + struct { + WCHAR *name; + WCHAR *value; + } ossl_env[] = { + {L"OPENSSL_CONF", L"ssl\\openssl.cnf"}, + {L"OPENSSL_ENGINES", L"ssl\\engines"}, + {L"OPENSSL_MODULES", L"ssl\\modules"} + }; + for (size_t i = 0; i < _countof(ossl_env); i++) + { + size_t size = 0; + + _wgetenv_s(&size, NULL, 0, ossl_env[i].name); + if (size == 0) + { + WCHAR val[MAX_PATH] = {0}; + _sntprintf_0(val, L"%ls%ls", o.install_path, ossl_env[i].value); + _wputenv_s(ossl_env[i].name, val); + } + } +} diff --git a/misc.h b/misc.h index 79f3762..e1b5833 100644 --- a/misc.h +++ b/misc.h @@ -81,4 +81,9 @@ void ImportConfigFile(const TCHAR* path, bool prompt_user); BOOL GetDlgItemTextUtf8(HWND hDlg, int id, LPSTR* str, int* len); +/* + * Set env vars used by OpenSSL to sane values. + */ +void set_openssl_env_vars(void); + #endif diff --git a/options.c b/options.c index fc609c8..41af25c 100644 --- a/options.c +++ b/options.c @@ -78,6 +78,7 @@ ExpandOptions (void) ExpandString (o.log_dir, _countof(o.log_dir)); ExpandString (o.editor, _countof(o.editor)); ExpandString (o.log_viewer, _countof(o.log_viewer)); + ExpandString (o.install_path, _countof(o.install_path)); } static int diff --git a/options.h b/options.h index fb56569..5166d12 100644 --- a/options.h +++ b/options.h @@ -185,6 +185,7 @@ typedef struct { /* HKLM Registry values */ TCHAR exe_path[MAX_PATH]; + TCHAR install_path[MAX_PATH]; TCHAR global_config_dir[MAX_PATH]; TCHAR priority_string[64]; TCHAR ovpn_admin_group[MAX_NAME]; diff --git a/registry.c b/registry.c index 3c35c6b..3853eca 100644 --- a/registry.c +++ b/registry.c @@ -78,7 +78,6 @@ static int GetGlobalRegistryKeys() { TCHAR windows_dir[MAX_PATH]; - TCHAR openvpn_path[MAX_PATH]; HKEY regkey; if (!GetWindowsDirectory(windows_dir, _countof(windows_dir))) { @@ -100,23 +99,23 @@ GetGlobalRegistryKeys() regkey = NULL; ShowLocalizedMsg(IDS_ERR_OPEN_REGISTRY); } - if (!regkey || !GetRegistryValue(regkey, _T(""), openvpn_path, _countof(openvpn_path)) - || _tcslen(openvpn_path) == 0) + if (!regkey || !GetRegistryValue(regkey, _T(""), o.install_path, _countof(o.install_path)) + || _tcslen(o.install_path) == 0) { /* error reading registry value */ if (regkey) ShowLocalizedMsg(IDS_ERR_READING_REGISTRY); /* Use a sane default value */ - _sntprintf_0(openvpn_path, _T("%ls"), _T("C:\\Program Files\\OpenVPN\\")); + _sntprintf_0(o.install_path, _T("%ls"), _T("C:\\Program Files\\OpenVPN\\")); } - if (openvpn_path[_tcslen(openvpn_path) - 1] != _T('\\')) - _tcscat(openvpn_path, _T("\\")); + if (o.install_path[_tcslen(o.install_path) - 1] != _T('\\')) + _tcscat(o.install_path, _T("\\")); /* an admin-defined global config dir defined in HKLM\OpenVPN\config_dir */ if (!regkey || !GetRegistryValue(regkey, _T("config_dir"), o.global_config_dir, _countof(o.global_config_dir))) { /* use default = openvpnpath\config */ - _sntprintf_0(o.global_config_dir, _T("%lsconfig"), openvpn_path); + _sntprintf_0(o.global_config_dir, _T("%lsconfig"), o.install_path); } if (!regkey || !GetRegistryValue(regkey, _T("ovpn_admin_group"), o.ovpn_admin_group, _countof(o.ovpn_admin_group))) @@ -126,7 +125,7 @@ GetGlobalRegistryKeys() if (!regkey || !GetRegistryValue(regkey, _T("exe_path"), o.exe_path, _countof(o.exe_path))) { - _sntprintf_0(o.exe_path, _T("%lsbin\\openvpn.exe"), openvpn_path); + _sntprintf_0(o.exe_path, _T("%lsbin\\openvpn.exe"), o.install_path); } if (!regkey || !GetRegistryValue(regkey, _T("priority"), o.priority_string, _countof(o.priority_string)))