Tfd class

A Python interface to FirmaSAT <http://www.cryptosys.net/firmasat/>.

class firmasat.Tfd

Operates on the Timbre Fiscal Digital (TFD) element, if present.

static add_signed_tfd(newFile, inputFile, keyFile, password, certFile)

Add a signed Timbre Fiscal Digital (TFD) element to a CFDI document.

Parameters:
  • newFile – Name of new file to be created.

  • inputFile – Name of existing CFDI file.

  • keyFile – Name of PAC’s private key file.

  • password – Password for private key.

  • certFile – Name of PAC’s X.509 certificate that matches the keyFile.

Returns:

0 if successful, otherwise a nonzero error code – see Err.error_lookup().

Return type:

int

Note

The inputFile must be a version 3.2 CFDI document already signed with a sello field and no existing TFD element. The TFD will be timestamped using the system clock and a fresh UUID will be generated. No other XML processing is carried out except inserting the TFD element.

static extract_digest_from_sig(xmlfile, certfile)

Extracts the message digest from the selloSAT node in Timbre Fiscal Digital of CFDI document.

Parameters:
  • xmlfile – Full path to XML file

  • certfile – X.509 certificate file of PAC who signed the TFD (required)

Returns:

Message digest in hex format or empty string on error

static make_digest(xmlfile, hashalg=0)

Form the message digest of cadena original del Timbre Fiscal Digital del SAT (TFD piped String) from CFDI document.

static make_pipestring(xmlfile)

Create the cadena original del Timbre Fiscal Digital del SAT (TFD piped string) from CFDI document.

static make_sig(xmlfile, keyfile, password, hashalg=0)

Create the selloSAT signature as a base64 String from TFD data in CFDI document.

Parameters:
  • xmlfile – Full path to XML file

  • keyfile – Name of private key file

  • password – Password

  • hashalg – Message digest algorithm to use in signature (optional).

Returns:

Signature in base64 format or empty string on error.

Note

Assumes you are a PAC with a valid SAT signing key.

static verify_sig(xmlfile, certfile)

Verify the selloSAT signature in TFD node of CFDI document.

Parameters:
  • xmlfile – Full path to XML file

  • certfile – X.509 certificate file of PAC who signed the TFD (required)

Returns:

0 if match is OK, otherwise a nonzero error code – see Err.error_lookup()

Return type:

int