How to sign documents with the unattended agent using AutoFirma
Overview
This guide explains how to sign documents using the unattended agent and AutoFirma. It is useful to admins and developers looking for a way to enhance signature operations.
Background
Unattended or massive signing refers to automated signature operations performed without user interaction. In this mode, documents are signed by services that access the necessary signing keys securely and automatically. This approach is used to sign PDF documents, XML files (such as electronic invoices), or other binary files, when signatures must be applied on a server.
The unattended signing requires the installation of the Redtrust Linux agent.
Redtrust is only compatible with AutoFirma 1.8.4 or higher.
Before you start
Before proceeding with this guide, you must have:
- Ubuntu environment.
- Redtrust's Linux agent.
- AutoFirma in your Ubuntu instance.
- A service user with access to the certificate you want to use and to a policy that allows all apps and sites or the Java app specifically.
When installing AutoFirma, you will need to install java and the libnss3-tools using these commands:
apt-cache search java | more
sudo apt install openjdk-11-jre
sudo apt install libnss3-tools
Be aware that the sudo apt –fix-broken install documented in the AutoFirma link above may not work.
Steps
-
Access your Linux machine where the unattended agent is installed.
-
Check that the agent is running.
systemctl status KeyfactorService.service -
Configure the agent with the credentials of the service user that will sign the documents..
keyfactor-setup hostname=IP_OR_HOSTNAME clientid=CLIENT_ID username=USERNAME password=PASSWORD loglevel=LOGLEVELFor example, the command for a user
cris@local.usersinagent01.example.comis:keyfactor-setup hostname=agent01.example.com clientid=T4N3r2WBbvKfyYe8/z+SVW5N= username=cris@local.users password=ChangeMe123 loglevel=LOWnoteloglevelrepresents the amount of detail to include in logs. Valid values:NONE,LOW,HIGH. -
Sign the documents with the following command. This command calls AutoFirma and instructs it to use the Redtrust PKCS#11 module as the certificate store.
autofirma sign -store pkcs11://usr/lib/libkeyfactorpkcs11.so -i ORIGINAL_FILE_NAME_WITH_EXTENSION -o NAME_OF_THE_SIGNED_FILE -filter subject.contains:USER_DNI
If you don't know the DNI associated with the certificate, run the following command to see the subject of the certificate and add any part of the it that is unique to that certificate.
pkcs11-tool --module /usr/lib/libkeyfactorpkcs11.so --list-objects --type cert
Alternatively, use the GUI to select the certificate you need.
autofirma sign -store pkcs11://usr/lib/libkeyfactorpkcs11.so -i ORIGINAL_FILE_NAME_WITH_EXTENSION -o NAME_OF_THE_SIGNED_FILE -certgui