Skip to content
Closed
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d52925a
feat: get all required dependencies in setup.py from issue #105
HanslettTheDev Mar 27, 2023
2e7a007
feat: get all required dependencies in setup.py from issue #105
HanslettTheDev Mar 27, 2023
27ef0bb
fix: improved the get_dependencies function to grab all dependency mo…
HanslettTheDev Apr 7, 2023
d966227
fix: improved the get_dependencies function to grab all dependency mo…
HanslettTheDev Apr 7, 2023
dbe2317
fix: fixed the issue with pip not detecting links
HanslettTheDev Apr 10, 2023
e365ff1
fix: removed the python version number in the requirements.txt file
HanslettTheDev Apr 11, 2023
1fbaa0e
bump: pull request clone to fix pull #113. current commit is just the…
HanslettTheDev May 10, 2023
c1fa3b5
fix: changed version number
HanslettTheDev May 22, 2023
e7375ab
fix(tests): fixed 4 broken tests and still one pending
HanslettTheDev Jun 8, 2023
147a4b9
fix: broken cryptography tests ressolved
HanslettTheDev Jun 10, 2023
25f7bcd
fix: fixes the tests for python 2.7
HanslettTheDev Jun 10, 2023
dbf6465
still ressolving python2.7 build error
HanslettTheDev Jun 10, 2023
7cd097f
still ressolving python2.7 build error part2
HanslettTheDev Jun 10, 2023
f1d312d
still ressolving python2.7 build error part3
HanslettTheDev Jun 10, 2023
148671f
fix: removed accidentally pushed conf files
HanslettTheDev Jun 10, 2023
ade95f4
fix: changed the requirements.txt file to show version number
HanslettTheDev Jun 10, 2023
f4d20e7
fix: changed the requirements.txt file to show version number
HanslettTheDev Jun 10, 2023
507cd2c
bump: crytography downgrade to 3.4.7
HanslettTheDev Jun 12, 2023
e5e9db1
bump: crytography downgrade to 3.4.7
HanslettTheDev Jun 12, 2023
ed17a5b
bump: crytography upgrade 3.4.7 -> 39.0.2
HanslettTheDev Jun 12, 2023
b8d1d72
feat: backward compatible code for python 2.7 to sign transactions
HanslettTheDev Jun 12, 2023
d180d05
feat: backward compatible code for python 2.7 to sign transactions
HanslettTheDev Jun 12, 2023
5144484
Testing support for python2.7
HanslettTheDev Jun 13, 2023
33bb3ab
modified the make file to add new test commands
HanslettTheDev Jun 15, 2023
80a1a41
Update wsaa.py
HanslettTheDev Jun 15, 2023
d7fe387
fix(bump): upgraded cryptography library to work on python3+ for new …
HanslettTheDev Jun 15, 2023
d9f8da5
bump: cryptopgraphy upgrade from 39.0.2 -> 41.0.1
HanslettTheDev Jun 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ nosetests.xml
.mr.developer.cfg
.project
.pydevproject

# vscode settings
.vscode
20 changes: 19 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ test:
.venv/bin/py.test tests

clean:
rm -Rf .venv
rm -Rf .venv

# Works with bash and linux
load-tests:
cp conf/*.ini .
curl -o reingart.zip https://www.sistemasagiles.com.ar/soft/pyafipws/reingart.zip
python -m zipfile -e reingart.zip .

sign-tra:
python -m pyafipws.wsaa

sign-cert:
python -m pyafipws.wsfev1 --prueba

# Use this command wisely as it might wipe out some files
# Use "git clean -n" to see the files to be cleaned
# Use only when only the config files are untracked
clean-tests:
git clean -f

.PHONY: install test
24 changes: 24 additions & 0 deletions get_dep.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os


def get_dependecies():
blob = "git+https://github.com"
requirements_path = os.path.join(
os.path.abspath(os.getcwd()),
"requirements.txt"
)
if os.path.isfile(requirements_path):
with open(requirements_path) as f:
dependencies = [
">=".join(x.split("==")) for x in f.read().splitlines()
]
for x in dependencies:
if x.startswith(blob):
# split the text and join them with the @ command
# index 3 holds the name of the module
chunks = x.split("/")
dependencies[dependencies.index(x)] = x.replace(
blob, chunks[3] + " @ " + blob
)
break
return dependencies
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
httplib2==0.9.2; python_version <= '2.7'
httplib2==0.20.4; python_version > '3'
pysimplesoap==1.08.14; python_version <= '2.7'
git+https://github.com/pysimplesoap/pysimplesoap.git@py311#pysimplesoap; python_version > '3'
git+https://github.com/pysimplesoap/pysimplesoap.git@py311#pysimplesoap ; python_version > '3'
cryptography==3.3.2; python_version <= '2.7'
cryptography==3.4.7; python_version > '3'
cryptography==39.0.2; python_version > '3'
fpdf>=1.7.2
dbf>=0.88.019
Pillow>=2.0.0
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
__copyright__ = "Copyright (C) 2008-2021 Mariano Reingart"

from distutils.core import setup
from get_dep import get_dependecies
import glob
import os
import subprocess
Expand Down Expand Up @@ -70,6 +71,7 @@
author_email="[email protected]",
url="https://github.com/reingart/pyafipws",
license="LGPL-3.0-or-later",
install_requires=get_dependecies(),
options=opts,
data_files=data_files,
classifiers=[
Expand Down
780 changes: 780 additions & 0 deletions tests/cassettes/test_wsmtx_recem/test_main_formato.yaml

Large diffs are not rendered by default.

72 changes: 46 additions & 26 deletions wsaa.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.bindings.openssl.binding import Binding
from cryptography.hazmat.primitives.serialization import pkcs7

except ImportError:
ex = exception_info()
Expand Down Expand Up @@ -116,6 +117,7 @@ def sign_tra(tra, cert=CERT, privatekey=PRIVATEKEY, passphrase=""):
_lib = Binding.lib
_ffi = Binding.ffi
# Crear un buffer desde el texto
# Se crea un buffer nuevo porque la firma lo consume
bio_in = _lib.BIO_new_mem_buf(tra, len(tra))

# Leer privatekey y cert
Expand All @@ -136,42 +138,60 @@ def sign_tra(tra, cert=CERT, privatekey=PRIVATEKEY, passphrase=""):
cert = open(cert).read()
if isinstance(cert, str):
cert = cert.encode("utf-8")
cert = x509.load_pem_x509_certificate(cert, default_backend())
cert = x509.load_pem_x509_certificate(cert)

try:
# Firmar el texto (tra) usando cryptography (openssl bindings para python)
p7 = _lib.PKCS7_sign(
cert._x509, private_key._evp_pkey, _ffi.NULL, bio_in, 0
)
finally:
# Liberar memoria asignada
_lib.BIO_free(bio_in)
# Se crea un buffer nuevo porque la firma lo consume
bio_in = _lib.BIO_new_mem_buf(tra, len(tra))
try:
# Crear buffer de salida
bio_out = _lib.BIO_new(_lib.BIO_s_mem())
if sys.version.split(" ")[0][0:3] == "2.7":
try:
# Instanciar un SMIME
_lib.SMIME_write_PKCS7(bio_out, p7, bio_in, 0)

# Tomar datos para la salida
result_buffer = _ffi.new("char**")
buffer_length = _lib.BIO_get_mem_data(bio_out, result_buffer)
output = _ffi.buffer(result_buffer[0], buffer_length)[:]
# Firmar el texto (tra) usando cryptography (openssl bindings para python)
p7 = _lib.PKCS7_sign(
cert._x509, private_key._evp_pkey, _ffi.NULL, bio_in, 0
)
finally:
# Liberar memoria asignada
_lib.BIO_free(bio_in)
try:
# Crear buffer de salida
bio_out = _lib.BIO_new(_lib.BIO_s_mem())
try:
# Instanciar un SMIME
_lib.SMIME_write_PKCS7(bio_out, p7, bio_in, 0)

# Tomar datos para la salida
result_buffer = _ffi.new("char**")
buffer_length = _lib.BIO_get_mem_data(bio_out, result_buffer)
output = _ffi.buffer(result_buffer[0], buffer_length)[:]
finally:
_lib.BIO_free(bio_out)
finally:
_lib.BIO_free(bio_out)
finally:
_lib.BIO_free(bio_in)
_lib.BIO_free(bio_in)

# Generar p7 en formato mail y recortar headers
msg = email.message_from_string(output.decode("utf8"))
for part in msg.walk():
filename = part.get_filename()
if filename == "smime.p7m":
# Es la parte firmada?
# Devolver CMS
return part.get_payload(decode=False)

p7 = pkcs7.PKCS7SignatureBuilder().set_data(
tra
).add_signer(
cert, private_key, hashes.SHA256()
).sign(
serialization.Encoding.SMIME, [pkcs7.PKCS7Options.Binary]
)

# Generar p7 en formato mail y recortar headers
msg = email.message_from_string(output.decode("utf8"))
msg = email.message_from_string(p7.decode("utf8"))
for part in msg.walk():
filename = part.get_filename()
if filename == "smime.p7m":
if filename == "smime.p7s":
# Es la parte firmada?
# Devolver CMS
return part.get_payload(decode=False)
else:
raise RuntimeError("Part not found")
else:
# Firmar el texto (tra) usando OPENSSL directamente
try:
Expand Down