This document describes the infrastructure and configuration needed for live SDI (Sistema di Interscambio) and PEC (Posta Elettronica Certificata) transmission of FatturaPA invoices.
This implementation includes XML generation and validation only. Live SDI/PEC transmission is NOT implemented and requires additional security, legal, and infrastructure setup.
FatturaPA XML must be digitally signed before transmission to SDI.
Certificate Directory Structure:
data/
└── certs/
├── signing/
│ ├── certificate.pem # Your digital signature certificate
│ ├── private_key.pem # Private key (KEEP SECURE!)
│ └── ca_chain.pem # Certificate authority chain
└── ssl/
├── client.crt # SSL client certificate (for HTTPS)
└── client.key # SSL client key
Certificate Requirements:
Security Notes:
chmod 600 private_key.pemFor clients without a Codice Destinatario (using 0000000), invoices are sent via PEC.
SMTP Configuration (Environment Variables):
# PEC SMTP Server
export OPENFATTURE_PEC_SMTP_SERVER="smtps.pec.aruba.it"
export OPENFATTURE_PEC_SMTP_PORT="465"
export OPENFATTURE_PEC_USERNAME="your-pec@pec.it"
export OPENFATTURE_PEC_PASSWORD="your-secure-password"
# Enable TLS/SSL
export OPENFATTURE_PEC_USE_TLS="true"
# Sender email (your PEC address)
export OPENFATTURE_PEC_FROM_ADDRESS="your-pec@pec.it"
PEC Provider Examples:
smtps.pec.aruba.it465 (SSL/TLS)smtps.aruba.it465 (SSL/TLS)smtp.pec.aruba.it465 (SSL/TLS)There are three ways to transmit to SDI:
https://sdi.fatturapa.gov.it or FTP serverConfiguration:
export OPENFATTURE_SDI_CHANNEL="direct"
export OPENFATTURE_SDI_USERNAME="your-sdi-username"
export OPENFATTURE_SDI_PASSWORD="your-sdi-password"
export OPENFATTURE_SDI_ENDPOINT="https://sdi.fatturapa.gov.it/SdiRiceviFile"
Example Configuration (Aruba):
export OPENFATTURE_SDI_CHANNEL="aruba"
export OPENFATTURE_SDI_API_USERNAME="your-aruba-username"
export OPENFATTURE_SDI_API_PASSWORD="your-aruba-password"
export OPENFATTURE_SDI_API_ENDPOINT="https://ws.fatturapa.aruba.it/services"
sdi01@pec.fatturapa.itConfiguration:
export OPENFATTURE_SDI_CHANNEL="pec"
export OPENFATTURE_SDI_PEC_ADDRESS="sdi01@pec.fatturapa.it"
Before enabling live transmission, ensure:
xmlsec)The following are HARD REQUIREMENTS before any live transmission:
When implementing transmission, these areas need attention:
# Example integration point (NOT IMPLEMENTED)
from openfatture.sdi.signature import sign_xml
def prepare_for_sdi(fattura: Fattura) -> Path:
"""Prepare invoice for SDI transmission."""
# 1. Generate XML
xml_content = builder.build(fattura)
# 2. Validate against XSD
is_valid, error = validator.validate(xml_content)
if not is_valid:
raise ValueError(f"Invalid XML: {error}")
# 3. Sign XML (REQUIRES IMPLEMENTATION)
signed_xml = sign_xml(
xml_content=xml_content,
certificate_path=settings.cert_path,
private_key_path=settings.key_path,
)
# 4. Save signed XML
signed_path = settings.invoices_dir / f"{fattura.numero}_signed.xml"
signed_path.write_text(signed_xml)
return signed_path
# Example integration point (NOT IMPLEMENTED)
from openfatture.sdi.transport import send_via_pec
def send_to_pec(fattura: Fattura, signed_xml_path: Path):
"""Send invoice via PEC."""
# Requires PEC SMTP configuration
send_via_pec(
recipient=fattura.cliente.pec or settings.sdi_pec_address,
subject=f"Fattura {fattura.numero}/{fattura.anno}",
attachment=signed_xml_path,
smtp_config=settings.pec_smtp_config,
)
# Example integration point (NOT IMPLEMENTED)
from openfatture.sdi.notifications import process_sdi_notification
def handle_sdi_response(notification_xml: str):
"""Process SDI notification (RC, NS, MC, etc.)."""
notification = process_sdi_notification(notification_xml)
# Update invoice status based on notification type
if notification.tipo == "NS": # Notifica Scarto
# Invoice rejected
update_invoice_status(notification.fattura_id, StatoFattura.SCARTATA)
elif notification.tipo == "RC": # Ricevuta Consegna
# Invoice delivered
update_invoice_status(notification.fattura_id, StatoFattura.CONSEGNATA)
openfatture/sdi/schemas/ (FatturaPA v1.2.2 + W3C xmldsig) - no download requiredRemember: This is infrastructure documentation only. Implementation requires qualified professionals familiar with Italian fiscal law, digital signatures, and secure system design.