### Create AutoFirma Web Start Launch Button Source: https://github.com/ctt-gob-es/clienteafirma/blob/master/afirma-ui-miniapplet-deploy/src/main/webapp/afirma_jnlp_complete.html Generates a launch button for AutoFirma using Java Web Start. It constructs the URL with the OS name and specifies the required Java version. ```javascript var url = "http://localhost:8080/afirma-server-simpleafirma-webstart/autofirmajnlp?cp=true&os=" + getOSName(); deployJava.createWebStartLaunchButton(url, '1.8.0'); ``` -------------------------------- ### Example Configuration Parameter Source: https://github.com/ctt-gob-es/clienteafirma/blob/master/afirma-simple/src/main/resources/help/en_US/pgs/LineaComandos.html Demonstrates how to provide multiple configuration properties for a signature operation using the '-config' parameter. Properties are concatenated by '\n' and follow a key=value format. ```bash -config "format=XAdES Enveloping\nsignerEmbassyRoles=Director\nxadesNamespace=http://uri.etsi.org/01903/v1.4.1#" ``` -------------------------------- ### JavaScript: Initiate Signing Process Source: https://github.com/ctt-gob-es/clienteafirma/blob/master/afirma-ui-miniapplet-deploy/src/main/webapp/firma_masiva.html Starts the signing process for the current document in the queue. It retrieves the document data and calls the `MiniApplet.sign` method. ```javascript function doSign() { if (indiceN3 < docs.length) { try { var data = docs[in ``` -------------------------------- ### Perform Signing Operation Source: https://github.com/ctt-gob-es/clienteafirma/blob/master/afirma-ui-applet-deploy/src/main/webapp/demoKeyStores.html Executes the full signing process, including initialization, key store setup, file URI setting, and signing. Handles potential errors during the process. ```javascript function realizarOperacion() { clienteFirma.initialize(); establecerKeyStore(); clienteFirma.setFileuri(document.getElementById('ficheroDatos').value); clienteFirma.setSignatureMode("implicit"); if(clienteFirma.isError()) { document.getElementById('firma').value = clienteFirma.getErrorMessage(); return; } try { clienteFirma.sign(); } catch (e) { alert(e); } mostrarResultado(); } ``` -------------------------------- ### Configure Signing Operation with Properties Source: https://github.com/ctt-gob-es/clienteafirma/blob/master/afirma-simple/src/main/resources/help/es_ES/pgs/LineaComandos.html The -config parameter allows passing configuration properties as plain text, separated by '\n'. This example shows how to set the XAdES format, signer roles, and namespace. ```properties -config "format=XAdES Enveloping\nsignerClaimedRoles=Director\nxadesNamespace=http://uri.etsi.org/01903/v1.4.1#" ``` -------------------------------- ### OCSP Request via GET Method Source: https://github.com/ctt-gob-es/clienteafirma/blob/master/afirma-crypto-cms-enveloper/src/test/resources/safelayer/rfc2560.txt Constructs an OCSP request using the HTTP GET method. Suitable for small requests to enable HTTP caching. The URL includes the base64 encoded DER encoding of the OCSPRequest. ```http GET {url}/{url-encoding of base-64 encoding of the DER encoding of the OCSPRequest} ``` -------------------------------- ### Display Help for Autofirma Command Line Source: https://github.com/ctt-gob-es/clienteafirma/blob/master/afirma-simple/src/main/resources/help/es_ES/pgs/LineaComandos.html Use the -help flag to list all available commands and their syntax. The exact command varies by operating system. ```bash AutofirmaCommandLine –help ``` ```bash /usr/bin/Autofirma –help ``` ```bash /Applications/Autofirma.app/Contents/MacOS/AutofirmaCommandLine –help ``` -------------------------------- ### Initialize and Set Key Store Source: https://github.com/ctt-gob-es/clienteafirma/blob/master/afirma-ui-applet-deploy/src/main/webapp/demoKeyStores.html Initializes the client, sets the key store path, password, and type, and prepares for signing. Use this to configure the signing environment. ```javascript function establecerKeyStore() { var path = document.getElementById('ksPath').value; var pass = document.getElementById('ksPass').value; var ks = document.getElementById('keystores').value; clienteFirma.setKeyStore(path, pass, ks); /* Si conociesemos el alias del certificado, podriamos indicarlo directamente tal como sigue para firmar sin que el usuario indicase absolutamente nada. */ /* clienteFirma.setSelectedCertificateAlias("alias"); */ } ``` -------------------------------- ### JavaScript: Get Selected Target Element Source: https://github.com/ctt-gob-es/clienteafirma/blob/master/afirma-ui-miniapplet-deploy/src/main/webapp/demo.html Iterates through radio buttons with the name 'formTarget' to find and return the currently checked element. ```javascript function getSelectedTarget() { var selectedTarget = null; var targets = document.getElementsByName('formTarget'); for (var i = 0; i < targets.length && !selectedTarget; ++i){ if (targets[i].checked ``` -------------------------------- ### Build Basic Autofirma Modules with Maven Source: https://github.com/ctt-gob-es/clienteafirma/blob/master/README.md Use this command to build all basic modules included in the repository. Ensure you have Java 1.8 or higher configured. ```bash mvn clean install ``` -------------------------------- ### JavaScript: Get Document Title Source: https://github.com/ctt-gob-es/clienteafirma/blob/master/afirma-ui-miniapplet-deploy/src/main/webapp/firma_masiva.html Extracts the title from a Base64 encoded PDF string. It searches for the 'Title' keyword and returns the subsequent text as the title. ```javascript function getTitle(base64Pdf) { var creationTime = ""; var toSearch = "Title"; var atext = MiniApplet.getTextFromBase64(base64Pdf, "utf-8"); var pos = atext.search(toSearch); if (pos > -1) { //pos = pos.lenght; var trozo = atext.substring(pos, pos + 50); creationTime = trozo.substring(5, 40); } else { creationTime = base64Pdf; } return creationTime; } ``` -------------------------------- ### Build Deployable Artifacts and Applications with Maven Source: https://github.com/ctt-gob-es/clienteafirma/blob/master/README.md To build deployable artifacts like WAR services and executable JARs, activate the 'env-install' profile. This command builds the core Autofirma JAR and its associated services. ```bash mvn clean install -Denv=install ``` -------------------------------- ### Get Operating System Name Source: https://github.com/ctt-gob-es/clienteafirma/blob/master/afirma-ui-miniapplet-deploy/src/main/webapp/afirma_jnlp_complete.html Determines the user's operating system based on browser information. This is used to construct the correct download URL. ```javascript function getOSName() { var osName="unknown"; if (navigator.appVersion.indexOf("Win")!=-1) osName="windows"; if (navigator.appVersion.indexOf("Mac")!=-1) osName="mac"; if (navigator.appVersion.indexOf("Linux")!=-1) osName="linux"; return osName; } ``` -------------------------------- ### JavaScript: Get Document Creation Time Source: https://github.com/ctt-gob-es/clienteafirma/blob/master/afirma-ui-miniapplet-deploy/src/main/webapp/firma_masiva.html Extracts the creation date from a Base64 encoded PDF string. It searches for the 'CreationDate' keyword and returns the date string. ```javascript function getCreationTime(base64Pdf) { var creationTime = ""; var toSearch = "CreationDate"; var atext = MiniApplet.getTextFromBase64(base64Pdf, "utf-8"); var pos = atext.search(toSearch); if (pos > -1) { var trozo = atext.substring(pos, pos + 50); creationTime = trozo.substring(15, 29); } return creationTime; } ``` -------------------------------- ### Sign Command Options Reference Source: https://github.com/ctt-gob-es/clienteafirma/blob/master/afirma-simple/src/main/resources/help/en_US/pgs/LineaComandos.html Reference for the options available when using the 'sign' command. This includes parameters for GUI interaction, file paths, signature algorithm, format, key store, password, alias, and XML output. ```bash Syntax: Autofirma sign [options...] Options: -gui (Perform the operation with graphical environment. Has priority over -certgui) -certgui (Use a graphic dialogue to select the signing certificate) -i inputfile (Input file path) -o outputfile (Output file path) -algorithm something (signature algorithm) -format (Sets the signature format) auto (Format selection based on input file) cades (CAdES format) pades (PAdES format) xades (XAdES format) invoice (electronic invoice signature) -config extraParams (Flat text properties with operation configuration) -store (Sets the store of keys. By default, the system) auto (Store system keys) windows (Store Windows Keys) mac (Store macOS keys) mozilla (Store Mozilla Firefox Keys) dni (Electronic ID) pkcs12:p12file (Store PKCS#12. "p12file" is the store route) pkcs11:p11file (Store PKCS#11. "p11file" is the driver path) -password password (Sets the store counter) -alias (alias of signature certificate) -filter (Filter to select the certificate of signature) -xml (Format the answer as XML) ``` -------------------------------- ### Initialize and Run Miniapplet Tests Source: https://github.com/ctt-gob-es/clienteafirma/blob/master/afirma-ui-miniapplet-deploy/src/main/webapp/miniapplet-full_tests.html This function orchestrates the execution of various tests for the Afirma Miniapplet, including loading, signing, co-signing, and counter-signing. ```javascript function initTests() { testLoadApplet(); testSign(); testCoSign(); testCounterSign(); } ``` -------------------------------- ### Perform LDAP Operation and Get Certificate Source: https://github.com/ctt-gob-es/clienteafirma/blob/master/afirma-ui-applet-deploy/src/main/webapp/demoLdap.html Initializes the client, configures LDAP settings, retrieves a certificate, and displays it or an error message. Use this to fetch certificates from an LDAP server. ```javascript function realizarOperacion() { clienteFirma.initialize(); clienteFirma.setLdapConfiguration( document.getElementById('ldapAddress').value, document.getElementById('ldapPort').value, document.getElementById('ldapRoot').value); clienteFirma.setLdapCertificatePrincipal( document.getElementById('ldapPrincipal').value); var certB64 = clienteFirma.getLdapCertificate(); if(clienteFirma.isError()) { document.getElementById('certificadoB64').value = clienteFirma.getErrorMessage(); } else { document.getElementById('certificadoB64').value = certB64; } } ``` -------------------------------- ### Display Available Commands - Windows Source: https://github.com/ctt-gob-es/clienteafirma/blob/master/afirma-simple/src/main/resources/help/en_US/pgs/LineaComandos.html Use this command to list all available operations supported by Autofirma on the command line in Windows. ```bash Autofirma CommandLine – help ``` -------------------------------- ### Display Help for Sign Operation Source: https://github.com/ctt-gob-es/clienteafirma/blob/master/afirma-simple/src/main/resources/help/es_ES/pgs/LineaComandos.html To view specific options for an operation like 'sign', use the -help flag with the operation name. This shows available parameters for signing files. ```bash AutofirmaCommandLine sign –help ``` -------------------------------- ### Deploy Autofirma Modules to Artifact Repository with Maven Source: https://github.com/ctt-gob-es/clienteafirma/blob/master/README.md This command is used when deploying artifacts to a repository. It builds the artifacts, includes source code and JavaDoc, and signs the artifacts. Use the 'env-deploy' profile for this purpose. ```bash mvn clean deploy -Denv=deploy ``` -------------------------------- ### Display Available Commands - Linux Source: https://github.com/ctt-gob-es/clienteafirma/blob/master/afirma-simple/src/main/resources/help/en_US/pgs/LineaComandos.html Use this command to list all available operations supported by Autofirma on the command line in Linux. ```bash /usr/bin/Autofirma – help ```