Skip to main content

Python interface to CryptoSys FirmaSAT

Project description

This is a Python interface to the core FirmaSAT library, which must be installed on your system. FirmaSAT is available from http://www.cryptosys.net/firmasat/.

Classes

Sello

Operates on the sello (signature) node in a SAT XML document.

Tfd

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

Pkix

PKI X.509 security utilities. Operates on private keys and X.509 certificates.

Xmlu

XML utilities. Operates on SAT-specific XML documents.

Gen

General info about the core library DLL, e.g. version number, compile date.

Err

Details of errors returned by the core library DLL.

All code in is one module firmasat.py for simplicity of distribution. All methods are static methods.

Errors

Most errors (missing files, invalid format) will result in a firmasat.Error exception, although some methods are more forgiving and will return a negative error code instead. Passing a bad argument type will result in an ArgumentError exception

We’re not entirely sure about being this brutal with exceptions. We’d appreciate comments.

We may refine the method names and the exception behaviour in a future release. If you have feedback or suggestions, please contact us at http://www.cryptosys.net/contact/.

Examples

To use in Python’s REPL:

>>> from firmasat import *
>>> Gen.version()
70310

If you don’t like import * and find firmasat a bit long to type each time, try

>>> import firmasat as fs
>>> fs.Gen.version()
70310

To sign a CFDI document, create the base XML file with all the required data except the following nodes

sello=""
certificado=""
noCertificado="00000000000000000000"

Then run the Sello.sign_xml() method with full paths to your key and cer files.

n = Sello.sign_xml('new.xml', 'base.xml', "emisor.key", password, "emisor.cer")

This creates a new file new.xml with the sello and certificado nodes completed.

Tests

There is a series of tests in test/test_firmasat.py. This requires a subdirectory work in the same folder as the test_firmasat.py module which must contain all the required test files (available in firmasatPyTestFiles.zip). The test function then creates a temporary subdirectory which is deleted automatically (add the argument nodelete on the command line to keep this temp directory).

test/
    test_firmasat.py  # this module
    work/        # this _must_ exist
        <all required test files>
        tmp.XXXXXXXX/    # created by `setup_temp_dir()`
            <copy of all required test files>
            <files created by tests>

This structure is already set up in the distribution file, so unzip the file firmasat-x.x.x.zip and open a command-line prompt in the test subdirectory. You can do any of the following.

  1. python test_firmasat.py

  2. py.test -v

  3. Open the file test_firmasat.py using IDLE and select Run > Run Module (F5).

We’ve tested this using the Python 2.7.12 interpreter and IDLE, the PyDev environment in Eclipse, and using py.test.

System requirements

Windows platforms only. Python 2 must be installed on your system (at least 2.6). Python 3 is not supported. FirmaSAT v7.3 or above must also be installed.

Contact

For more information or to make suggestions, please contact us at http://www.cryptosys.net/contact/.

David Ireland
DI Management Services Pty Ltd
Australia
28 August 2016

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

firmasatpy-0.1.1.zip (114.2 kB view details)

Uploaded Source

File details

Details for the file firmasatpy-0.1.1.zip.

File metadata

  • Download URL: firmasatpy-0.1.1.zip
  • Upload date:
  • Size: 114.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for firmasatpy-0.1.1.zip
Algorithm Hash digest
SHA256 b27fbb93ae111651a821e7877e36702529562302f43fa1bbc57af802fe5c64ff
MD5 88d41f0543cee35204b5a53b96ca0b24
BLAKE2b-256 f437c4f808e101d431afe23640684e1d63d5d4b397cf27858f1adafd6a7242d0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page