Flujo de Firma Digital
Diagrama del Flujo Completo
sequenceDiagram
participant C as Cliente
participant A as API REST
participant M as Motor SSigner
participant F as Filesystem
Note over C,A: 1. Autenticacion
C->>A: POST /auth/acceder
A-->>C: {jwtToken, refreshToken}
Note over C,A: 2. Iniciar Grupo
C->>A: POST /grupo-proceso-firma/iniciar-grupo
A->>F: Guarda docs en {basePath}/{idFirmante}/entrada/
A-->>C: {codigoOperacion, propiedades}
Note over C,A: 3. Generar Hash
C->>A: POST /ssigner/generar-hash
A->>M: SSigner.iniciar(--operacion=fb)
M->>F: Crea .prefirma y .sha256 en entrada/
A-->>C: {hashes[], algoritmo}
Note over C: 4. Firma Local
Note over C: Cliente firma hash con certificado
Note over C,A: 5. Insertar Hash Firmado
C->>A: POST /ssigner/insertar-hash-firmado
A->>M: SSigner.iniciar(--operacion=ihf)
M->>F: Inserta firma en salida/
A-->>C: {estado: true}
Note over C,A: 6. Verificar y Descargar
C->>A: GET /grupo-proceso-firma/verificar/{idGP}
A->>F: Lee documentos de salida/
A-->>C: {documentos[], firmado: true}
Estados del Grupo de Firma
| Estado | Valor | Nombre | Descripcion |
| CANCELLED | 0 | Cancelado | Grupo cancelado |
| INITIATED | 1 | Iniciado | Grupo creado |
| DICHARGED | 2 | Descargado | Hash generado |
| CONFIGGETTER | 3 | Config Obtenida | Config recuperada |
| UPLOADED | 4 | Cargado | Hash firmado recibido |
| FINALIZED | 5 | Finalizado | Documentos descargados |
Transiciones de Estado
stateDiagram-v2
[*] --> INITIATED: iniciar-grupo
INITIATED --> DICHARGED: generar-hash
DICHARGED --> CONFIGGETTER: obtener-config
CONFIGGETTER --> UPLOADED: insertar-hash
UPLOADED --> FINALIZED: verificar-descarga
INITIATED --> CANCELLED: cancelar
DICHARGED --> CANCELLED: cancelar
CONFIGGETTER --> CANCELLED: cancelar
Ejemplo Completo con cURL
#!/bin/bash
# Firmar un documento PDF
API="<API_HOST>:<API_PORT>"
EMAIL="user@test.com"
PASS="pass123"
# 1. Autenticarse
TOKEN=$(curl -s -X POST $API/auth/acceder \
-H "Content-Type: application/json" \
-d "{\"email\":\"$EMAIL\",\"password\":\"$PASS\"}" \
| jq -r '.jwtToken')
# 2. Iniciar grupo
GRP=$(curl -s -X POST $API/api/v2/grupo-proceso-firma/iniciar-grupo \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"idFirmante": "DNI123456",
"idProceso": 1,
"documentos": [{"nombre": "doc.pdf", "codigo": "D1", "contenido": "'$(base64 doc.pdf)'"}]
}')
GRP_ID=$(echo $GRP | jq -r '.gruProFirId')
# 3. Generar hash
HASH_RESP=$(curl -s -X POST $API/api/v2/ssigner/generar-hash \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"idGP": "'$GRP_ID'", "idFirmante": "DNI123456", "certifcadoPublicoFirmante": "'$(base64 cert.pem)'"}')
HASH=$(echo $HASH_RESP | jq -r '.hashes[0]')
# 4. Cliente firma el hash localmente...
# HASH_FIRMADO=$(firmar_hash $HASH $CLAVE_PRIVADA)
# 5. Insertar hash firmado
curl -s -X POST $API/api/v2/ssigner/insertar-hash-firmado \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"idpg": '$GRP_ID', "hashesFirmados": ["'$HASH_FIRMADO'"]}'
# 6. Verificar y descargar
curl -s -X GET $API/api/v2/grupo-proceso-firma/verificar-grupo-firmado/$GRP_ID \
-H "Authorization: Bearer $TOKEN" \
-o documento_firmado.pdf