|
|
@ -6,25 +6,25 @@ except ImportError: |
|
|
from StringIO import StringIO |
|
|
from StringIO import StringIO |
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
|
from lxml import etree |
|
|
|
|
|
|
|
|
from lxml import etree |
|
|
except ImportError: |
|
|
except ImportError: |
|
|
try: |
|
|
|
|
|
# Python 2.5 - cElementTree |
|
|
|
|
|
import xml.etree.cElementTree as etree |
|
|
|
|
|
except ImportError: |
|
|
|
|
|
try: |
|
|
try: |
|
|
# Python 2.5 - ElementTree |
|
|
|
|
|
import xml.etree.ElementTree as etree |
|
|
|
|
|
|
|
|
# Python 2.5 - cElementTree |
|
|
|
|
|
import xml.etree.cElementTree as etree |
|
|
except ImportError: |
|
|
except ImportError: |
|
|
try: |
|
|
|
|
|
# Instalacao normal do cElementTree |
|
|
|
|
|
import cElementTree as etree |
|
|
|
|
|
except ImportError: |
|
|
|
|
|
try: |
|
|
try: |
|
|
# Instalacao normal do ElementTree |
|
|
|
|
|
import elementtree.ElementTree as etree |
|
|
|
|
|
|
|
|
# Python 2.5 - ElementTree |
|
|
|
|
|
import xml.etree.ElementTree as etree |
|
|
except ImportError: |
|
|
except ImportError: |
|
|
raise Exception('Falhou ao importar lxml/ElementTree') |
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
# Instalacao normal do cElementTree |
|
|
|
|
|
import cElementTree as etree |
|
|
|
|
|
except ImportError: |
|
|
|
|
|
try: |
|
|
|
|
|
# Instalacao normal do ElementTree |
|
|
|
|
|
import elementtree.ElementTree as etree |
|
|
|
|
|
except ImportError: |
|
|
|
|
|
raise Exception('Falhou ao importar lxml/ElementTree') |
|
|
|
|
|
|
|
|
import xmlsec, libxml2 # FIXME: verificar ambiguidade de dependencias: lxml e libxml2 |
|
|
import xmlsec, libxml2 # FIXME: verificar ambiguidade de dependencias: lxml e libxml2 |
|
|
|
|
|
|
|
|
@ -113,10 +113,10 @@ class AssinaturaA1(Assinatura): |
|
|
# Tag de assinatura |
|
|
# Tag de assinatura |
|
|
if raiz.getroot().find('Signature') is None: |
|
|
if raiz.getroot().find('Signature') is None: |
|
|
signature = etree.Element( |
|
|
signature = etree.Element( |
|
|
'Signature', |
|
|
|
|
|
URI=raiz.getroot().getchildren()[0].attrib['Id'], |
|
|
|
|
|
xmlns=NAMESPACE_SIG, |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
'Signature', |
|
|
|
|
|
URI=raiz.getroot().getchildren()[0].attrib['Id'], |
|
|
|
|
|
xmlns=NAMESPACE_SIG, |
|
|
|
|
|
) |
|
|
signature.text = '' |
|
|
signature.text = '' |
|
|
raiz.getroot().insert(0, signature) |
|
|
raiz.getroot().insert(0, signature) |
|
|
|
|
|
|
|
|
@ -142,12 +142,12 @@ class AssinaturaA1(Assinatura): |
|
|
|
|
|
|
|
|
# Buscamos a chave no arquivo do certificado |
|
|
# Buscamos a chave no arquivo do certificado |
|
|
chave = xmlsec.cryptoAppKeyLoad( |
|
|
chave = xmlsec.cryptoAppKeyLoad( |
|
|
filename=str(self.certificado.caminho_arquivo), |
|
|
|
|
|
format=xmlsec.KeyDataFormatPkcs12, |
|
|
|
|
|
pwd=str(self.senha), |
|
|
|
|
|
pwdCallback=None, |
|
|
|
|
|
pwdCallbackCtx=None, |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
filename=str(self.certificado.caminho_arquivo), |
|
|
|
|
|
format=xmlsec.KeyDataFormatPkcs12, |
|
|
|
|
|
pwd=str(self.senha), |
|
|
|
|
|
pwdCallback=None, |
|
|
|
|
|
pwdCallbackCtx=None, |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
# Cria a variável de chamada (callable) da função de assinatura |
|
|
# Cria a variável de chamada (callable) da função de assinatura |
|
|
assinador = xmlsec.DSigCtx() |
|
|
assinador = xmlsec.DSigCtx() |
|
|
|