Difference between revisions of "Documentation/Nightly/Developers/Windows Code Signing"
Max.smolens (talk | contribs) |
Max.smolens (talk | contribs) |
||
Line 29: | Line 29: | ||
* other .exe files outside bin/, such as CLI modules | * other .exe files outside bin/, such as CLI modules | ||
* .dll files in bin/ and for modules | * .dll files in bin/ and for modules | ||
+ | |||
+ | ===Examples=== | ||
+ | |||
+ | ====Sign using SHA-2==== | ||
+ | Sign using a DigiCert code signing certificate, following their [https://www.digicert.com/code-signing/signcode-signtool-command-line.htm examples]: | ||
+ | <pre> | ||
+ | signtool.exe sign /f "C:\path\to\cert.pfx" /p <password> /fd sha256 /tr http://timestamp.digicert.com /td sha256 /v setup.exe | ||
+ | </pre> | ||
+ | * <tt>/f</tt> specifies the path to the code signing certificate | ||
+ | * <tt>/p</tt> specifies the password for the code signing certificate | ||
+ | * <tt>/fd</tt> specifies the file digest algorithm | ||
+ | * <tt>/tr</tt> specifies the URL of the RFC-3161 timestamp server | ||
+ | * <tt>/td</tt> specifies the digest algorithm to be used by the timestamp server | ||
+ | * <tt>/v</tt> displays verbose output | ||
+ | |||
+ | ====Dual sign with SHA-1 and SHA-2==== | ||
+ | Dual singing should be necessary only when targeting Windows XP SP3/Vista: | ||
+ | <pre> | ||
+ | signtool.exe sign /f "C:\path\to\cert.pfx" /p <password> /t http://timestamp.digicert.com /v setup.exe | ||
+ | signtool.exe sign /f "C:\path\to\cert.pfx" /p <password> /fd sha256 /tr http://timestamp.digicert.com /td sha256 /as /v foo.exe | ||
+ | </pre> | ||
+ | * <tt>/as</tt> appends the SHA-2 signature to the primary signature | ||
+ | |||
+ | ====Verify the signature==== | ||
+ | <pre> | ||
+ | signtool.exe verify /pa /v setup.exe | ||
+ | </pre> | ||
+ | * <tt>/pa</tt> specifies that the Default Authenticode Verification Policy should be used instead of the Windows Driver Verification Policy | ||
+ | |||
+ | ===Notes=== | ||
+ | |||
+ | The Windows 10 SDK installs the 64-bit SignTool.exe to <tt>C:\Program Files (x86)\Windows Kits\10\bin\x64\signtool.exe</tt>. | ||
==CMake integration== | ==CMake integration== |
Revision as of 17:26, 10 October 2016
Home < Documentation < Nightly < Developers < Windows Code SigningContents
Overview
This page contains information on code signing on Windows and on integrating code signing into the Slicer packaging process.
Prerequisites
- Install Windows 10 SDK to get latest SignTool.exe.
Acquire and install a code signing certificate
Follow the procedure described in Acquire a Code Signing Certificate to acquire a code signing certificate from a commercial vendor recognized by Microsoft. Some example vendor links include:
It may be necessary to install the code signing certificate on the machine that will be used to sign the code. Regardless, it is necessary to export the certificate to a .pfx file to be used by SignTool.exe.
Sign files using SignTool.exe
SignTool.exe digitally signs files, verifies signatures in files, and time-stamps files. See SignTool.exe documentation.
At a minimum, the final installer .exe should be signed.
It's recommend to also sign executables inside the installer, including at least:
- Slicer.exe (launcher)
- bin/SlicerApp-real.exe (application)
Other candidate files to sign include:
- other .exe files in bin/
- other .exe files outside bin/, such as CLI modules
- .dll files in bin/ and for modules
Examples
Sign using SHA-2
Sign using a DigiCert code signing certificate, following their examples:
signtool.exe sign /f "C:\path\to\cert.pfx" /p <password> /fd sha256 /tr http://timestamp.digicert.com /td sha256 /v setup.exe
- /f specifies the path to the code signing certificate
- /p specifies the password for the code signing certificate
- /fd specifies the file digest algorithm
- /tr specifies the URL of the RFC-3161 timestamp server
- /td specifies the digest algorithm to be used by the timestamp server
- /v displays verbose output
Dual sign with SHA-1 and SHA-2
Dual singing should be necessary only when targeting Windows XP SP3/Vista:
signtool.exe sign /f "C:\path\to\cert.pfx" /p <password> /t http://timestamp.digicert.com /v setup.exe signtool.exe sign /f "C:\path\to\cert.pfx" /p <password> /fd sha256 /tr http://timestamp.digicert.com /td sha256 /as /v foo.exe
- /as appends the SHA-2 signature to the primary signature
Verify the signature
signtool.exe verify /pa /v setup.exe
- /pa specifies that the Default Authenticode Verification Policy should be used instead of the Windows Driver Verification Policy
Notes
The Windows 10 SDK installs the 64-bit SignTool.exe to C:\Program Files (x86)\Windows Kits\10\bin\x64\signtool.exe.
CMake integration
Currently, CMake/CPack doesn't include any built-in functionality to automatically call SignTool.exe to digitally sign files or installers. Therefore, integrating code signing into Slicer requires adding custom steps for the targets chosen to be signed.
MySQL's implementation could be a useful example; see https://github.com/mysql/mysql-server/blob/67d52e7c7a1a23424e39273cbb6f5f9d56fda8d1/cmake/install_macros.cmake#L155.
Additional references
Introduction to Code Signing (MSDN)
Windows Enforcement of Authenticode Code Signing and Timestamping (Microsoft TechNet)