Added support for plain (not signed) invoice files.

This commit is contained in:
Franco Masotti 2019-10-12 12:14:45 +02:00
parent 383d5c3a3a
commit abb8aec6cb
Signed by: frnmst
GPG Key ID: 24116ED85666780A
2 changed files with 31 additions and 15 deletions

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,17 @@ 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'
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:
shutil.copyfile(invoice_original_file, str(pathlib.Path(tmpdirname, invoice_original_file)))
else:
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',