xmlsig

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package xmlsig builds the WS-Security signed SOAP envelopes required by the SAT "Descarga Masiva" web service.

The SAT authentication endpoint expects a SOAP 1.1 envelope whose <Timestamp> element is signed with the FIEL using an enveloped XML-DSig: exclusive canonicalization (xml-exc-c14n), SHA-1 digests and an RSA-SHA1 signature, with the certificate carried in a <BinarySecurityToken>.

Rather than run a general-purpose C14N engine over parsed XML (fragile and error-prone), we emit the signed fragments (Timestamp and SignedInfo) directly in their canonical form and sign those exact bytes. Because we control the XML generation, the emitted form already matches exclusive-C14N output. This is the same strategy used by the reference phpcfdi implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthEnvelope

func AuthEnvelope(s Signer, created time.Time, ttl time.Duration, timestampID, tokenID string) (string, error)

AuthEnvelope builds a signed SOAP envelope for the SAT Autenticacion operation. created is the moment the timestamp opens; the timestamp is valid for ttl (the SAT uses 5 minutes). tokenID and timestampID must be unique per request.

func NoSpaces

func NoSpaces(s string) string

NoSpaces removes insignificant whitespace between XML tags, matching the simplified canonicalization the SAT expects (phpcfdi's Helpers::nospaces).

func SignEnveloped

func SignEnveloped(s Signer, toDigest, uri, keyInfoXML string) (string, error)

SignEnveloped builds an enveloped <Signature> that signs toDigest (the element to be digested, in its canonical form) with the given Reference URI (empty for the SAT SolicitaDescarga signature). keyInfoXML is the <KeyInfo> block.

The digest is SHA-1 over NoSpaces(toDigest); the SignedInfo is signed with RSA-SHA1. The emitted SignedInfo omits its redundant xmlns (inherited from the enclosing Signature), while the signed bytes include it — exclusive C14N makes the two equivalent, which is what the SAT verifies.

Types

type Signer

type Signer interface {
	// SignSHA1 signs data with RSA PKCS#1 v1.5 / SHA-1 using the FIEL private key.
	SignSHA1(data []byte) ([]byte, error)
	// CertificateBase64 returns the base64 DER certificate for the token.
	CertificateBase64() string
}

Signer holds the material needed to produce a signature.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL