ZE02 LISTO PAPA
se adicionaron parametros encontrados en https://github.com/jaullo/l10n_cr/blob/12.0/cr_electronic_invoice/xades/context2.py#L62 FossilOrigin-Name: 4767eb72711b7c05d7515da7570f5a020080e48b951abe00b9932e4271bfc69e
This commit is contained in:
parent
5479adbaca
commit
e0e53d61ad
17
facho/cli.py
17
facho/cli.py
@ -216,7 +216,8 @@ def validate_invoice(invoice_path):
|
|||||||
@click.option('--ssl/--no-ssl', default=False)
|
@click.option('--ssl/--no-ssl', default=False)
|
||||||
@click.option('--use-cache-policy/--no-use-cache-policy', default=False)
|
@click.option('--use-cache-policy/--no-use-cache-policy', default=False)
|
||||||
@click.argument('xmlfile', type=click.Path(exists=True), required=True)
|
@click.argument('xmlfile', type=click.Path(exists=True), required=True)
|
||||||
def sign_xml(private_key, passphrase, xmlfile, ssl=True, use_cache_policy=False):
|
@click.argument('output', required=True)
|
||||||
|
def sign_xml(private_key, passphrase, xmlfile, ssl=True, use_cache_policy=False, output=None):
|
||||||
if not ssl:
|
if not ssl:
|
||||||
disable_ssl()
|
disable_ssl()
|
||||||
|
|
||||||
@ -226,7 +227,8 @@ def sign_xml(private_key, passphrase, xmlfile, ssl=True, use_cache_policy=False)
|
|||||||
|
|
||||||
signer = fe.DianXMLExtensionSigner(private_key, passphrase=passphrase, mockpolicy=use_cache_policy)
|
signer = fe.DianXMLExtensionSigner(private_key, passphrase=passphrase, mockpolicy=use_cache_policy)
|
||||||
document = open(xmlfile, 'r').read().encode('utf-8')
|
document = open(xmlfile, 'r').read().encode('utf-8')
|
||||||
print(signer.sign_xml_string(document))
|
with open(output, 'w') as f:
|
||||||
|
f.write(signer.sign_xml_string(document))
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option('--private-key', type=click.Path(exists=True))
|
@click.option('--private-key', type=click.Path(exists=True))
|
||||||
@ -236,7 +238,8 @@ def sign_xml(private_key, passphrase, xmlfile, ssl=True, use_cache_policy=False)
|
|||||||
@click.option('--sign/--no-sign', default=False)
|
@click.option('--sign/--no-sign', default=False)
|
||||||
@click.option('--use-cache-policy/--no-use-cache-policy', default=False)
|
@click.option('--use-cache-policy/--no-use-cache-policy', default=False)
|
||||||
@click.argument('scriptname', type=click.Path(exists=True), required=True)
|
@click.argument('scriptname', type=click.Path(exists=True), required=True)
|
||||||
def generate_invoice(private_key, passphrase, scriptname, generate=False, ssl=True, sign=False, use_cache_policy=False):
|
@click.argument('output', required=True)
|
||||||
|
def generate_invoice(private_key, passphrase, scriptname, generate=False, ssl=True, sign=False, use_cache_policy=False, output=None):
|
||||||
"""
|
"""
|
||||||
imprime xml en pantalla.
|
imprime xml en pantalla.
|
||||||
SCRIPTNAME espera
|
SCRIPTNAME espera
|
||||||
@ -270,12 +273,14 @@ def generate_invoice(private_key, passphrase, scriptname, generate=False, ssl=Tr
|
|||||||
for extension in extensions:
|
for extension in extensions:
|
||||||
xml.add_extension(extension)
|
xml.add_extension(extension)
|
||||||
|
|
||||||
xmlstring = xml.tostringMACHETE(xml_declaration=True)
|
xmlstring = xml.tostringMACHETE(xml_declaration=True, encoding='UTF-8')
|
||||||
if sign:
|
if sign:
|
||||||
signer = fe.DianXMLExtensionSigner(private_key, passphrase=passphrase, mockpolicy=use_cache_policy)
|
signer = fe.DianXMLExtensionSigner(private_key, passphrase=passphrase, mockpolicy=use_cache_policy)
|
||||||
print(signer.sign_xml_string(xmlstring.encode('utf-8')))
|
with open(output, 'w') as f:
|
||||||
|
f.write(signer.sign_xml_string(xmlstring.encode('utf-8')))
|
||||||
else:
|
else:
|
||||||
print(xmlstring)
|
with open(output, 'w') as f:
|
||||||
|
f.write(xmlstring)
|
||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
def main():
|
def main():
|
||||||
|
@ -202,7 +202,7 @@ class DianXMLExtensionSigner(FachoXMLExtension):
|
|||||||
extcontent = fachoxml.builder.xpath(fachoxml.root, '/fe:Invoice/ext:UBLExtensions/ext:UBLExtension[2]/ext:ExtensionContent')
|
extcontent = fachoxml.builder.xpath(fachoxml.root, '/fe:Invoice/ext:UBLExtensions/ext:UBLExtension[2]/ext:ExtensionContent')
|
||||||
fachoxml.append_element(extcontent, signature)
|
fachoxml.append_element(extcontent, signature)
|
||||||
|
|
||||||
return fachoxml.tostring(xml_declaration=True)
|
return fachoxml.tostring(xml_declaration=True, encoding='UTF-8')
|
||||||
|
|
||||||
def sign_xml_element(self, xml):
|
def sign_xml_element(self, xml):
|
||||||
id_uuid = str(uuid.uuid4())
|
id_uuid = str(uuid.uuid4())
|
||||||
@ -226,23 +226,17 @@ class DianXMLExtensionSigner(FachoXMLExtension):
|
|||||||
ki = xmlsig.template.ensure_key_info(signature, name=id_keyinfo)
|
ki = xmlsig.template.ensure_key_info(signature, name=id_keyinfo)
|
||||||
data = xmlsig.template.add_x509_data(ki)
|
data = xmlsig.template.add_x509_data(ki)
|
||||||
xmlsig.template.x509_data_add_certificate(data)
|
xmlsig.template.x509_data_add_certificate(data)
|
||||||
|
|
||||||
|
|
||||||
xmlsig.template.add_key_value(ki)
|
xmlsig.template.add_key_value(ki)
|
||||||
qualifying = xades.template.create_qualifying_properties(signature)
|
|
||||||
|
qualifying = xades.template.create_qualifying_properties(signature, 'XadesObjects', 'xades')
|
||||||
xades.utils.ensure_id(qualifying)
|
xades.utils.ensure_id(qualifying)
|
||||||
|
|
||||||
|
|
||||||
id_props = "xmldsig-%s-signedprops" % (id_uuid)
|
id_props = "xmldsig-%s-signedprops" % (id_uuid)
|
||||||
# MACHETE si no lo envio la dian no lo valida y pasa
|
props_ref = xmlsig.template.add_reference(
|
||||||
# si lo adiciono https://tools.chilkat.io/xmlDsigVerify.cshtml
|
signature, xmlsig.constants.TransformSha256, uri="#%s" % (id_props),
|
||||||
# falla en validar este reference..
|
uri_type="http://uri.etsi.org/01903#SignedProperties"
|
||||||
|
)
|
||||||
#props_ref = xmlsig.template.add_reference(
|
xmlsig.template.add_transform(props_ref, xmlsig.constants.TransformInclC14N)
|
||||||
# signature, xmlsig.constants.TransformSha256, uri="#%s" % (id_props),
|
|
||||||
# uri_type="http://uri.etsi.org/01903#SignedProperties"
|
|
||||||
#)
|
|
||||||
#xmlsig.template.add_transform(props_ref, xmlsig.constants.TransformInclC14N)
|
|
||||||
|
|
||||||
# TODO assert with http://www.sic.gov.co/hora-legal-colombiana
|
# TODO assert with http://www.sic.gov.co/hora-legal-colombiana
|
||||||
props = xades.template.create_signed_properties(qualifying, name=id_props, datetime=datetime.now())
|
props = xades.template.create_signed_properties(qualifying, name=id_props, datetime=datetime.now())
|
||||||
|
Loading…
Reference in New Issue
Block a user