VerifactuMidAPI/documentacion/PREREQUISITES.md

2.7 KiB

Prerequisites

System Requirements

Go

No se requieren Python, OpenSSL ni scripts externos. Todo el procesamiento de certificados (.p12/.pfx) es nativo en Go.


Project Setup

1. Clone the repository

git clone <repository-url>
cd VerifactuMidAPI

2. Install Go dependencies

go mod download

3. Create required directories

mkdir -p data/certs data keys
Directory Purpose
data/certs/ Stored .p12 certificates
data/ Hash chain records (JSON files per emitter)
keys/ Auto-generated RSA key pair for password encryption

4. Configure the application

Copy or edit config.yml:

server:
  port: 6789

verifactu:
  production: false

certificates:
  storage_path: ./data/certs/
  cert_file: ./data/certs/personal.p12
  cert_password: YOUR_PASSWORD

crypto:
  keys_path: ./keys/
  name: "VeriFactu API"
  email: "admin@example.com"

Important: Change cert_password and email to your own values.

5. Obtain a digital certificate

VeriFactu requires a qualified electronic certificate (eIDAS compliant) in .p12 or .pfx format.

  • FNMT Persona Fisica (free): https://www.fnmt.es
  • Must be valid and registered with AEAT for the testing environment
  • Place it at ./data/certs/personal.p12 (or update cert_file in config)

Build & Run

Development (auto-reload with source)

go run .

Production build

go build -o verifactu-api .
./verifactu-api

The server starts on http://localhost:6789 (or the port configured in config.yml).


Verify the installation

1. Health check

curl http://localhost:6789/api/v1/health
# Expected: {"status":"ok"}

2. Get public key

curl http://localhost:6789/api/v1/auth/public-key
# Expected: {"public_key":"<base64>"}

Troubleshooting

go: command not found

Go is not installed or not in your PATH. Add it:

# Linux/macOS
export PATH=$PATH:/usr/local/go/bin

# Windows: add C:\Program Files\Go\bin to system PATH

config.yml not found

The API falls back to defaults but logs a warning. Create the file as described in step 4.

certificate expired / invalid_password_or_format

  • Verify the certificate dates with:
    openssl pkcs12 -in ./data/certs/personal.p12 -info -nokeys
    
  • Ensure the password in config.yml matches the certificate.

403 Forbidden from AEAT

The certificate is not authorized in the AEAT testing environment. Contact AEAT or verify your FNMT certificate is enabled for VeriFactu.