Secure Tauri/Windows Code Signing with Certum HSM
One of our products — Defguard & WireGuard Desktop Client has multiple platform releases (Linux, MacOS, and Windows). We're building it with our beloved Rust and a great multi-platform desktop framework Tauri.
Defguard & WireGuard desktop client
While doing releases with Tauri is pretty straightforward and well-documented, the Code Signing for MacOS is spot-on, but the Windows Code Signing is not that straightforward. Tauri documentation assumes you have a certificate file (pfx - with certificate & key) - but most (if not all) Code Signing Certificates are sold on dedicated HSMs (Hardware Security Modules) that must be FIPS 140-2 compliant.
Thus to handle signing:
- One has to have a self-hosted GitLab/Github Runner - which just physically can have the HSM connected to the USB (and of course the runner needs to be in a secure network location and well as the system needs to be secured).
- There needs to be a solution & tools to handle this process automatically during the build & release.
Most certificate authorities have a dedicated solution for that (DigiCert, Sectigo) or solutions, examples, and a great documentation (SSL.com) but we have chosen Certum Code Signing certificate for two reasons, they operate as us in Szczecin Poland and they have a great Open Source Code Signing product - and defguard is an open-source project. The downside is that they do not have any CI/CD documentation or solutions, and weirdly (everything should be on the internet, right?) there are no docs, solutions, snippets, projects, or blogs (you name it), that could help us set up this process.
So after weeks of going back and forward with the Certum support and going nowhere (greeting for our colleagues), we took this project on our shoulders - and here are the recipes for building a Debian GNU/Linux CI/CD runner.
We assume you have:
- a configured GitHub/GitLab self-hosted runner based on Debian GNU/Linux (but Ubuntu should work as well)
- Bought an Open Source Code Signing Certificate set from Certum
- Have the certificate issued and the key is on the HSM shipped by Certum and it’s connected to the runner.
- You also have downloaded the certificate file in PEM format (from certum website), and placed it in /srv/codesign/certum/certificate.pem
Now we need to prepare the runner system to support the HSM. First let’s install all necessary system software:
Now, we need to install the Linux version of proCertumCardManager provided by Certum:
Now, we can check if the system sees the HSM and can show us the certificate & key details:
! As you can see, the key ID (this is important) is: 352c322687efb09df068a792c49cbac631d40cf0
Now the final, let’s check if the code signing works - for that we have a defguard.exe unsigned binary, which we will sign and check if it works:
And checking the signature:
Now what is left for you to do, is add the osslsigncode sign to your pipeline, and don’t forget to make the PIN a secret.
Robert Olejnik - Founder, Security and Open Source Advocate