|
|
@ -30,11 +30,15 @@ class AssinaturaA1(Assinatura): |
|
|
def assinar(self, xml, retorna_string=False): |
|
|
def assinar(self, xml, retorna_string=False): |
|
|
try: |
|
|
try: |
|
|
# No raiz do XML de saida |
|
|
# No raiz do XML de saida |
|
|
|
|
|
tag = 'infNFe'; # tag que será assinada |
|
|
raiz = etree.Element('Signature', xmlns='http://www.w3.org/2000/09/xmldsig#') |
|
|
raiz = etree.Element('Signature', xmlns='http://www.w3.org/2000/09/xmldsig#') |
|
|
siginfo = etree.SubElement(raiz, 'SignedInfo') |
|
|
siginfo = etree.SubElement(raiz, 'SignedInfo') |
|
|
etree.SubElement(siginfo, 'CanonicalizationMethod', Algorithm='http://www.w3.org/TR/2001/REC-xml-c14n-20010315') |
|
|
etree.SubElement(siginfo, 'CanonicalizationMethod', Algorithm='http://www.w3.org/TR/2001/REC-xml-c14n-20010315') |
|
|
etree.SubElement(siginfo, 'SignatureMethod', Algorithm='http://www.w3.org/2000/09/xmldsig#rsa-sha1') |
|
|
etree.SubElement(siginfo, 'SignatureMethod', Algorithm='http://www.w3.org/2000/09/xmldsig#rsa-sha1') |
|
|
#ref = etree.SubElement(siginfo, 'Reference', URI='#'+xml.findall('infNFe')[0].attrib['Id']) |
|
|
|
|
|
|
|
|
if xml.findall('infNFe')[0].attrib['Id']: |
|
|
|
|
|
ref = etree.SubElement(siginfo, 'Reference', URI='#'+xml.findall('infNFe')[0].attrib['Id']) |
|
|
|
|
|
elif xml.findall('infEvento')[0].attrib['Id']: |
|
|
|
|
|
tag = 'infEvento' |
|
|
ref = etree.SubElement(siginfo, 'Reference', URI='#'+xml.findall('infEvento')[0].attrib['Id']) |
|
|
ref = etree.SubElement(siginfo, 'Reference', URI='#'+xml.findall('infEvento')[0].attrib['Id']) |
|
|
trans = etree.SubElement(ref, 'Transforms') |
|
|
trans = etree.SubElement(ref, 'Transforms') |
|
|
etree.SubElement(trans, 'Transform', Algorithm='http://www.w3.org/2000/09/xmldsig#enveloped-signature') |
|
|
etree.SubElement(trans, 'Transform', Algorithm='http://www.w3.org/2000/09/xmldsig#enveloped-signature') |
|
|
@ -50,8 +54,7 @@ class AssinaturaA1(Assinatura): |
|
|
with open('testes.xml', 'w') as arquivo: |
|
|
with open('testes.xml', 'w') as arquivo: |
|
|
arquivo.write(etree.tostring(xml, encoding="unicode", pretty_print=False)) |
|
|
arquivo.write(etree.tostring(xml, encoding="unicode", pretty_print=False)) |
|
|
|
|
|
|
|
|
#subprocess.call(['xmlsec1', '--sign', '--pkcs12', self.certificado, '--pwd', self.senha, '--crypto', 'openssl', '--output', 'funfa.xml', '--id-attr:Id', 'infNFe', 'testes.xml']) |
|
|
|
|
|
subprocess.call(['xmlsec1', '--sign', '--pkcs12', self.certificado, '--pwd', self.senha, '--crypto', 'openssl', '--output', 'funfa.xml', '--id-attr:Id', 'infEvento', 'testes.xml']) |
|
|
|
|
|
|
|
|
subprocess.call(['xmlsec1', '--sign', '--pkcs12', self.certificado, '--pwd', self.senha, '--crypto', 'openssl', '--output', 'funfa.xml', '--id-attr:Id', tag, 'testes.xml']) |
|
|
xml = etree.parse('funfa.xml').getroot() |
|
|
xml = etree.parse('funfa.xml').getroot() |
|
|
|
|
|
|
|
|
if retorna_string: |
|
|
if retorna_string: |
|
|
|