Skip to content

Commit

Permalink
Add env vars during install
Browse files Browse the repository at this point in the history
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 <levitte@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #6)
  • Loading branch information
nhorman committed May 21, 2024
1 parent 24c4670 commit 372a731
Showing 1 changed file with 45 additions and 8 deletions.
53 changes: 45 additions & 8 deletions windows-installer/openssl.nsi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,6 +11,7 @@
# ####################################################

!include "MUI.nsh"
!include "winmessages.nsh"

!define PRODUCT_NAME "OpenSSL"

Expand All @@ -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"
Expand All @@ -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
Expand All @@ -69,30 +76,60 @@ 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

!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

!define MUI_PAGE_CUSTOMFUNCTION_LEAVE CheckRunUninstaller
!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
Expand Down

0 comments on commit 372a731

Please sign in to comment.