From 372a7313f8e74190eb74e16a20e33f2a21fefc5b Mon Sep 17 00:00:00 2001 From: Neil Horman Date: Tue, 14 May 2024 08:17:18 -0400 Subject: [PATCH] Add env vars during install Set the OPENSSL_CONF/CTLOG_FILE/SSL_CERT_FILE env vars during install to point to the proper installation directory also set a global OPENSSLDIR registry key in the non-user writeable keyspace to allow for a runtime defined fallback location that openssl can query at run time Reviewed-by: Richard Levitte Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/installer/pull/6) --- windows-installer/openssl.nsi | 53 +++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/windows-installer/openssl.nsi b/windows-installer/openssl.nsi index 2b7576e..59663fc 100644 --- a/windows-installer/openssl.nsi +++ b/windows-installer/openssl.nsi @@ -1,6 +1,7 @@ ###################################################### # NSIS windows installer script file +# # Requirements: NSIS 3.0 must be installed with the MUI plugin # Usage notes: # This script expects to be executed from the directory it is @@ -10,6 +11,7 @@ # #################################################### !include "MUI.nsh" +!include "winmessages.nsh" !define PRODUCT_NAME "OpenSSL" @@ -22,10 +24,15 @@ NAME "${PRODUCT_NAME} ${VERSION}" ShowInstDetails show +Var DataDir +Var ModDir + Function .onInit StrCpy $INSTDIR "C:\Program Files\openssl-${VERSION}" FunctionEnd +# This section is run if installation of 32 bit binaries are selected + !ifdef BUILD64 # This section is run if installation of the 64 bit binaries are selectd SectionGroup "64 Bit Installation" @@ -45,19 +52,19 @@ SectionGroupEnd !endif !ifdef BUILD32 -# This section is run if installation of the 32 bit binaries are selectd +# This section is run if installation of the 64 bit binaries are selectd SectionGroup "32 Bit Installation" Section "32 Bit Binaries" SetOutPath $INSTDIR\x32\lib - File /r "${BUILD32}\Program Files\OpenSSL\lib\" + File /r "${BUILD32}\Program Files (x86)\OpenSSL\lib\" SetOutPath $INSTDIR\x32\bin - File /r "${BUILD32}\Program Files\OpenSSL\bin\" + File /r "${BUILD32}\Program Files(x86)\OpenSSL\bin\" SetOutPath "$INSTDIR\x64\Common Files" - File /r "${BUILD32}\Program Files\Common Files\" + File /r "${BUILD32}\Program Files (x86)\Common Files\" SectionEnd Section "x32 Development Headers" - SetOutPath $INSTDIR\x324\include - File /r "${BUILD32}\Program Files\OpenSSL\include\" + SetOutPath $INSTDIR\x32\include + File /r "${BUILD32}\Program Files (x86)\OpenSSL\include\" SectionEnd SectionGroupEnd !endif @@ -69,14 +76,24 @@ Section "Documentation" SectionEnd !endif -# Always install the uninstaller -Section +# Always install the uninstaller and set a registry key +Section WriteUninstaller $INSTDIR\uninstall.exe SectionEnd +!define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' +!define openssl_hklm 'HKLM "SOFTWARE\OpenSSL"' + # This is run on uninstall Section "Uninstall" RMDIR /r $INSTDIR + DeleteRegValue ${env_hklm} OPENSSL_CONF + DeleteRegValue ${env_hklm} SSL_CERT_FILE + DeleteRegValue ${env_hklm} CTLOG_FILE + DeleteRegValue ${env_hklm} OPENSSL_MODULES + DeleteRegValue ${env_hklm} OPENSSL_ENGINES + DeleteRegValue ${openssl_hklm} OPENSSLDIR + SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000 SectionEnd !insertmacro MUI_PAGE_WELCOME @@ -84,8 +101,23 @@ SectionEnd !insertmacro MUI_PAGE_LICENSE ${LICENSE_FILE} Function CheckRunUninstaller +!ifdef BUILD64 + StrCpy $DataDir "$INSTDIR\x64\Common Files\SSL" + StrCpy $ModDir "$INSTDIR\x64\lib\ossl-modules" +!else + StrCpy $DataDir "$INSTDIR\x32\Common Files\SSL" + StrCpy $ModDir "$INSTDIR\x32\lib\ossl-modules" +!endif ifFileExists $INSTDIR\uninstall.exe 0 +2 ExecWait "$INSTDIR\uninstall.exe /S _?=$INSTDIR" + + WriteRegExpandStr ${env_hklm} OPENSSL_CONF "$DataDir\openssl.cnf" + WriteRegExpandStr ${env_hklm} SSL_CERT_FILE "$DataDir\cert.pem" + WriteRegExpandStr ${env_hklm} CTLOG_FILE "$DataDir\ct_log_list.cnf" + WriteRegExpandStr ${env_hklm} OPENSSL_MODULES "$ModDir" + WriteRegExpandStr ${env_hklm} OPENSSL_ENGINES "$ModDir" + WriteRegExpandStr ${openssl_hklm} OPENSSLDIR "$DataDir" + SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000 FunctionEnd !insertmacro MUI_PAGE_COMPONENTS @@ -93,6 +125,11 @@ FunctionEnd !define MUI_DIRECTORYPAGE_TEXT_DESTINATION "Installation Directory" !insertmacro MUI_PAGE_DIRECTORY +!define MUI_DIRECTORYPAGE_VARIABLE $DataDir +!define MUI_DIRECTORYPAGE_TEXT_TOP "Select Configuration/Data Directory" +!define MUI_DIRECTORYPAGE_TEXT_DESTINATION "Configuration/Data Directory" +!insertmacro MUI_PAGE_DIRECTORY + !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_UNPAGE_WELCOME