We are living in 2022. And it is now possible to digitally sign a PDF document using libre software. This is a love letter to libre software projects, and also a manual.
For a long time, one of the challenges in using libre software in ‘enterprise’ environments or working with Government documents is that one will eventually be forced to use a proprietary software that isn’t even available for a libre platform like GNU/Linux. A notorious use-case is digitally signing PDF documents.
Recently, Poppler (the free software library for rendering PDF; used by Evince and Okular) and Okular in particular has gained a lot of improvements in displaying digital signature and actually signing a PDF document digitally (see this, this, this, this, this and this). When the main developer Albert asked for feedback on what important functionality would the community like to see incorporated as part this effort; I had asked if it would be possible to use hardware tokens for digital signature. Turns out,
nss (Network Security Services, a Mozilla project) for managing the certificates, and if the token is enrolled in NSS database, Okular should be able to just use it.
This blog post written a couple of years ago about using hardware token in GNU/Linux is still actively referred by many users. Trying to make the hardware token work with Okular gave me some more insights. With all the other prerequisites (token driver installation etc.) in place, follow these steps to get everything working nicely.
- There are 2 options to manage NSSDB: (i) manually by setting up
$HOME/.pki/nssdb, or (ii) use the one automatically created by Firefox if you already use it. Assuming the latter, the nssdb would be located in the default profile directory
$HOME/.mozilla/firefox/<random.dirname>/(check for existence of the file
pkcs11.txtin that directory to be sure).
- Open Okular and go to
- Start the smart card service (usually auto-started, you won’t have to do this): either
pcsc_wd.service(for WatchData keys) or
- Plug in the hardware token.
- Open a PDF in Okular. Add digitial signature using menu
- This should prompt for the hardware token password.
- Click & drag a square area where you need to place the signature and choose the certificate. Note that, since Poppler 22.03, it is also possible to insert signature in a designated field.
- Signature will be placed on a new PDF file (with suffix
-signed) and it will open automatically.
- You can also see the details of the hardware token in PDF backend settings.
Thanks to the free software projects & developers who made this possible.