Merge branch 'newfeature-non-signed-invoice-files' into dev

This commit is contained in:
Franco Masotti 2019-10-12 12:34:01 +02:00
commit a0eb0ed393
Signed by: frnmst
GPG Key ID: 24116ED85666780A
4 changed files with 49 additions and 15 deletions

View File

@ -169,6 +169,9 @@ in other cases it is not.
If you find any official source please let me know and/or open a pull request.
Support for non-signed invoice files has been added because of at least one
reported case.
Closing note
------------

View File

@ -41,3 +41,12 @@ which is the same as
$ fattura_elettronica_reader -H -a -o -S -s -w -W ${metadata_file}
You need to extract a plain (non-signed) invoice file
`````````````````````````````````````````````````````
::
$ fattura_elettronica_reader -b -H ${metadata_file}

View File

@ -519,7 +519,8 @@ def pipeline(metadata_file: str,
invoice_xslt_type: str = 'ordinaria',
ignore_attachment_extension_whitelist: bool = False,
ignore_attachment_filetype_whitelist: bool = False,
write_default_configuration_file: bool = False):
write_default_configuration_file: bool = False,
invoice_file_is_not_p7m: bool = False):
r"""Run the pipeline."""
project_name = 'fattura_elettronica_reader'
create_appdirs(project_name)
@ -566,10 +567,10 @@ def pipeline(metadata_file: str,
# Apparently, invoices must be signed for 'PA' and not necessarly for
# 'B2B' and other cases. I could not find official documentation
# corroborating this. For the moment we will assume that all invoices
# need to be signed.
if not is_invoice_file_signed(invoice_filename):
raise InvoiceFileDoesNotHaveACoherentCryptographicalSignature
# corroborating this but it happened at least one.
if not invoice_file_is_not_p7m:
if not is_invoice_file_signed(invoice_filename):
raise InvoiceFileDoesNotHaveACoherentCryptographicalSignature
if force_trusted_list_file_download or not pathlib.Path(
trusted_list_file).exists():
@ -582,11 +583,11 @@ def pipeline(metadata_file: str,
config['trusted list file']['XML namespace'],
config['trusted list file']['XML certificate tag'])
if not is_invoice_file_authentic(invoice_filename, ca_certificate_pem_file,
ignore_signature_check,
ignore_signers_certificate_check):
raise InvoiceFileNotAuthentic
if not invoice_file_is_not_p7m:
if not is_invoice_file_authentic(invoice_filename, ca_certificate_pem_file,
ignore_signature_check,
ignore_signers_certificate_check):
raise InvoiceFileNotAuthentic
if not no_invoice_xml_validation:
@ -602,11 +603,23 @@ def pipeline(metadata_file: str,
# Create a temporary directory to store the original XML invoice file.
with tempfile.TemporaryDirectory() as tmpdirname:
invoice_original_file = invoice_filename + '.xml'
# invoice_original_file is the path of the non-signed invoice file. If an invoice file is signed,
# the filename usually ends in '.p7m' so the destination file must end with '.xml'
# to be transformed into an xml file. On the contrary, the filename of non-signed invoice files
# already ends in '.xml'.
if invoice_file_is_not_p7m:
invoice_original_file = invoice_filename
else:
invoice_original_file = invoice_filename + '.xml'
if not remove_signature_from_invoice_file(invoice_filename,
str(pathlib.Path(tmpdirname, invoice_original_file))):
raise CannotExtractOriginalInvoiceFile
if invoice_file_is_not_p7m:
# There is no signature to extract but we need to copy the file in the temporary store.
shutil.copyfile(invoice_original_file, str(pathlib.Path(tmpdirname, invoice_original_file)))
else:
# Extract the original invoice and copy it in the temporary store.
if not remove_signature_from_invoice_file(invoice_filename,
str(pathlib.Path(tmpdirname, invoice_original_file))):
raise CannotExtractOriginalInvoiceFile
if not no_invoice_xml_validation:
if not is_xml_file_conforming_to_schema(str(pathlib.Path(tmpdirname, invoice_original_file)), invoice_schema_file):

View File

@ -66,7 +66,9 @@ class CliToApi():
invoice_xslt_type=args.invoice_xslt_type,
ignore_attachment_extension_whitelist=args.ignore_attachment_extension_whitelist,
ignore_attachment_filetype_whitelist=args.ignore_attachment_filetype_whitelist,
write_default_configuration_file=args.write_default_configuration_file)
write_default_configuration_file=args.write_default_configuration_file,
invoice_file_is_not_p7m=args.invoice_file_is_not_p7m)
class CliInterface():
"""The interface exposed to the final user."""
@ -146,6 +148,13 @@ class CliInterface():
action='store_true',
help='force download of the XML schema necessary for the validation of the invoice file')
parser.add_argument(
'-b',
'--invoice-file-is-not-p7m',
default=False,
action='store_true',
help='avoids running any type of cryptographical signature and certificate checks. This is useful for certain B2B invoice files.')
parser.add_argument(
'-s',
'--ignore-signature-check',