Verificar cancelación con certificados en CD
This commit is contained in:
parent
d237b33020
commit
0adcd7f30f
|
@ -28,7 +28,6 @@ class SATCertificate(object):
|
||||||
self._init_values()
|
self._init_values()
|
||||||
self._get_data_cer(cer)
|
self._get_data_cer(cer)
|
||||||
self._get_data_key(key, password)
|
self._get_data_key(key, password)
|
||||||
self._p = self._get_hash()
|
|
||||||
|
|
||||||
def _init_values(self):
|
def _init_values(self):
|
||||||
self._rfc = ''
|
self._rfc = ''
|
||||||
|
@ -167,8 +166,10 @@ class SATCertificate(object):
|
||||||
# ~ node.text = self.issuer
|
# ~ node.text = self.issuer
|
||||||
node = xmlsec.tree.find_node(tree, 'X509SerialNumber')
|
node = xmlsec.tree.find_node(tree, 'X509SerialNumber')
|
||||||
node.text = self.serial_number
|
node.text = self.serial_number
|
||||||
# ~ node = xmlsec.tree.find_node(tree, 'SignatureValue')
|
node = xmlsec.tree.find_node(tree, 'SignatureValue')
|
||||||
# ~ node.text = node.text.replace('\n', '')
|
node.text = node.text.replace('\n', '')
|
||||||
|
node = xmlsec.tree.find_node(tree, 'Modulus')
|
||||||
|
node.text = node.text.replace('\n', '')
|
||||||
|
|
||||||
xml_signed = ET.tostring(tree,
|
xml_signed = ET.tostring(tree,
|
||||||
xml_declaration=True, encoding='UTF-8').decode()
|
xml_declaration=True, encoding='UTF-8').decode()
|
||||||
|
|
|
@ -765,8 +765,7 @@ def get_pac_by_rfc(cfdi):
|
||||||
def _cancel_with_cert(invoice, args, auth, certificado):
|
def _cancel_with_cert(invoice, args, auth, certificado):
|
||||||
cert = SATCertificate(certificado.cer, certificado.key_enc.encode())
|
cert = SATCertificate(certificado.cer, certificado.key_enc.encode())
|
||||||
pac = PACS[auth['pac']]()
|
pac = PACS[auth['pac']]()
|
||||||
info = {'cer': cert.cer_pem, 'key': cert.key_pem, 'pass': cert._p, 'args': args}
|
info = {'cer': cert.cer_pem, 'key': cert.key_pem, 'pass': '', 'args': args}
|
||||||
# ~ print(info['pass'])
|
|
||||||
|
|
||||||
result = pac.cancel(invoice.xml, info, auth)
|
result = pac.cancel(invoice.xml, info, auth)
|
||||||
if pac.error:
|
if pac.error:
|
||||||
|
@ -780,8 +779,8 @@ def _cancel_with_cert(invoice, args, auth, certificado):
|
||||||
|
|
||||||
|
|
||||||
def cancel_xml_sign(invoice, args, auth, certificado):
|
def cancel_xml_sign(invoice, args, auth, certificado):
|
||||||
# ~ if auth['pac'] == 'finkok':
|
if auth['pac'] == 'finkok':
|
||||||
return _cancel_with_cert(invoice, args, auth, certificado)
|
return _cancel_with_cert(invoice, args, auth, certificado)
|
||||||
|
|
||||||
cert = SATCertificate(certificado.cer, certificado.key_enc.encode())
|
cert = SATCertificate(certificado.cer, certificado.key_enc.encode())
|
||||||
pac = PACS[auth['pac']]()
|
pac = PACS[auth['pac']]()
|
||||||
|
@ -798,6 +797,7 @@ def cancel_xml_sign(invoice, args, auth, certificado):
|
||||||
template = TEMPLATE_CANCEL.format(**data)
|
template = TEMPLATE_CANCEL.format(**data)
|
||||||
tree = ET.fromstring(template.encode())
|
tree = ET.fromstring(template.encode())
|
||||||
sign_xml = cert.sign_xml(tree)
|
sign_xml = cert.sign_xml(tree)
|
||||||
|
print(sign_xml)
|
||||||
|
|
||||||
result = pac.cancel_xml(sign_xml, auth, invoice.xml)
|
result = pac.cancel_xml(sign_xml, auth, invoice.xml)
|
||||||
|
|
||||||
|
|
|
@ -256,37 +256,38 @@ DEFAULT_GLOBAL = {
|
||||||
'clave_sat': '01010101',
|
'clave_sat': '01010101',
|
||||||
}
|
}
|
||||||
|
|
||||||
TEMPLATE_CANCEL = """<Cancelacion xmlns="http://cancelacfd.sat.gob.mx" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" RfcEmisor="{rfc}" Fecha="{fecha}">
|
# ~ TEMPLATE_CANCEL = """<Cancelacion xmlns="http://cancelacfd.sat.gob.mx" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" RfcEmisor="{rfc}" Fecha="{fecha}">
|
||||||
<Folios>
|
# ~ <Folios>
|
||||||
<Folio UUID="{uuid}" Motivo="{motivo}"{folio}/>
|
# ~ <Folio UUID="{uuid}" Motivo="{motivo}"{folio}/>
|
||||||
</Folios>
|
# ~ </Folios>
|
||||||
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
|
# ~ <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
|
||||||
<SignedInfo>
|
# ~ <SignedInfo>
|
||||||
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
|
# ~ <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
|
||||||
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
|
# ~ <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
|
||||||
<Reference URI="">
|
# ~ <Reference URI="">
|
||||||
<Transforms>
|
# ~ <Transforms>
|
||||||
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
|
# ~ <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
|
||||||
</Transforms>
|
# ~ </Transforms>
|
||||||
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
|
# ~ <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
|
||||||
<DigestValue/>
|
# ~ <DigestValue/>
|
||||||
</Reference>
|
# ~ </Reference>
|
||||||
</SignedInfo>
|
# ~ </SignedInfo>
|
||||||
<SignatureValue/>
|
# ~ <SignatureValue/>
|
||||||
<KeyInfo>
|
# ~ <KeyInfo>
|
||||||
<X509Data>
|
# ~ <X509Data>
|
||||||
<X509IssuerSerial>
|
# ~ <X509IssuerSerial>
|
||||||
<X509IssuerName/>
|
# ~ <X509IssuerName/>
|
||||||
<X509SerialNumber/>
|
# ~ <X509SerialNumber/>
|
||||||
</X509IssuerSerial>
|
# ~ </X509IssuerSerial>
|
||||||
<X509Certificate/>
|
# ~ <X509Certificate/>
|
||||||
</X509Data>
|
# ~ </X509Data>
|
||||||
<KeyValue>
|
# ~ <KeyValue>
|
||||||
<RSAKeyValue>
|
# ~ <RSAKeyValue>
|
||||||
<Modulus/>
|
# ~ <Modulus/>
|
||||||
<Exponent/>
|
# ~ <Exponent/>
|
||||||
</RSAKeyValue>
|
# ~ </RSAKeyValue>
|
||||||
</KeyValue>
|
# ~ </KeyValue>
|
||||||
</KeyInfo>
|
# ~ </KeyInfo>
|
||||||
</Signature>
|
# ~ </Signature>
|
||||||
</Cancelacion>"""
|
# ~ </Cancelacion>"""
|
||||||
|
TEMPLATE_CANCEL = """<Cancelacion xmlns="http://cancelacfd.sat.gob.mx" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" RfcEmisor="{rfc}" Fecha="{fecha}"><Folios><Folio UUID="{uuid}" Motivo="{motivo}"{folio}/></Folios><Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" /><Reference URI=""><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /><DigestValue/></Reference></SignedInfo><SignatureValue/><KeyInfo><X509Data><X509IssuerSerial><X509IssuerName/><X509SerialNumber/></X509IssuerSerial><X509Certificate/></X509Data><KeyValue><RSAKeyValue><Modulus/><Exponent/></RSAKeyValue></KeyValue></KeyInfo></Signature></Cancelacion>"""
|
||||||
|
|
Loading…
Reference in New Issue