3 votesby askubuntu.com/users/385945written 2022-06-16
Here's how you can generate your own certificate for signing documents within libreoffice on (eg Debian), and get yourself set up to do so:
Prep
Install necessary tools:
sudo apt-get update && sudo apt-get install openssl libnss3-tools
Making the certificate
First, generate an x509 certificate:
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes \
-keyout signing.key -out signing.crt -subj "/CN=John T Doe" \
-addext "subjectAltName=email:you@example.com"
...
..+......+..+....+........+.+.........+...........+.+.....+.+.....+...+.+....
+.....+.+.....+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++*.........+..+.........+....+.........+...............+......+......
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-----
...
Note that subjectAltName can contain email: instead of DNS entries
Next, convert the certificate to a p12 format key:
openssl pkcs12 -export -in signing.cert -inkey signing.key \
-out signing-certificate.p12 -name "John T Doe"
...
Enter Export Password:
Verifying - Enter Export Password:
...
Making the NSS Database
Next, we need to prepare a database path for NSS and generate the database:
mkdir -p ~/.pki/nssdb
certutil -d ~/.pki/nssdb -N
...
Enter Password or Pin for "NSS Certificate DB":
Enter a password which will be used to encrypt your keys.
The password should be at least 8 characters long,
and should contain at least one non-alphabetic character.
Enter new password:
Re-enter password:
Password changed successfully.
...
Note that the password in question is your default master firefox password (on Debian/Ubuntu). So if you haven't set one up, its an empty string - once you do it will prompt you to enter a new one and change it
Or, do so without adding a password (Reference 4):
certutil -d ~/.pki/nssdb -N --empty-password
Finally, import the p12 certificate into the database:
pk12util -d ~/.pki/nssdb -i signing-certificate.p12
...
Enter Password or Pin for "NSS Certificate DB":
Enter password for PKCS12 file:
pk12util: PKCS12 IMPORT SUCCESSFUL
...
Note that you can use -k ${database.password.file} -w ${certificate.password.file} to flag in the passwords programatically if you want to get fancy
Configuring LibreOffice
Open LibreOffice
Select Window
Select Options
Select Security on the left
On the right, select Certificate by Certificate Path
Select Select NSS Path at the bottom of the resulting dialog, select the proper path (i.e. ~/.pki/nssdb), select Ok (ensuring the new Manual path is selected), and finally Restart Now.
After reboot, open a document, select File, select Export as, select Export as PDF.
Navigate to the Digital Signatures tab, and you should see things working:
Then select the certificate in question to use it to sign:
Enter your certificate password
Enter your location and reason (if so desired)
Select Export and save your document
You can lastly go into File ⨠Digital Signatures... ⨠Sign Existing PDF, and open your signed PDF to verify that a signature exists (and you could also sign in this fashion too):
References: