on 09-14-2015 5:38 PM
Alguém já implementou assinatura de NFSe para prefeitura de BH utilizando a classe cl_sec_sxml_dsignature?
Estou validando a assinatura gerada utilizando o site da receita, através do link abaixo, mas sem sucesso.
O detalhe é que estou utilizando o mesmo método para prefeitura do RJ e este retorna como válido (ainda não está em produção, mas pelo menos não retorna erro na assinatura).
Abaixo um trecho do código que faz a assinatura, depois disso não modifico mais o XML.
*----------------------------------------------------------------------------*
lo_sign = cl_sec_sxml_dsignature=>create_reader_instance( if_input = unsigned_xml ).
lo_sign->m_canonicalization = cl_sec_sxml_dsignature=>co_c14n_inclusive.
lo_sign->m_signature_ns_prefix = lc_signature_ns_prefix. " lc_signature_ns_prefix = "space"
lo_sign->set_attributes( if_attribute_name = lc_c14n_attribute ). " lc_c14n_attribute = "Id"
lo_sign->sign_xml(
EXPORTING if_ssf_app = ssfappl
if_add_keyinfo = abap_true
IMPORTING ef_signature_xml = lf_signature ). " xml node
lo_sign->embed_signature(
EXPORTING if_xml = unsigned_xml
if_signature = lf_signature
IMPORTING ef_result = signed_xml ).
Derik,
No primeiro momento, monte o XML com as informações apenas do RPS:
<GerarNfseEnvio xmlns="http://www.abrasf.org.br/nfse.xsd">
<Rps>
<InfRps Id="xxx">
.......
</InfRps>
</Rps>
</GerarNfseEnvio>
Assine o XML.
Insira as informações do lote no XML gerado (assinado).
Assine o novo XML.
Abraços,
Miguel Motta
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Boa tarde Derik, vc poderia mandar o restante do programa que vc fez pra assinar o xml? Estou precisando criar uma função que assine um xml para enviar para um transportador.
Desde já agradeço.
Bruno Barros
email: brunobarros.al@hotmail.com
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Olá Bruno.
No caso de BH o XML precisava ser assinado como um todo e cada tag RPS também. Então, na hora de assinar o XML o método que utilizei tinha um parâmetro para informar uma tag específica a ser assinada, bastou utilizá-lo.
" Important: IF_ATTRIBUTE must be present and initial | |
lo_sign = cl_sec_sxml_dsignature=>create_reader_instance( if_input = unsigned_xml if_attribute = lf_attribute ). " set attribtue for C14n | |
lo_sign->m_canonicalization = cl_sec_sxml_dsignature=>co_c14n_inclusive. " IN | |
lo_sign->m_signature_ns_prefix = lc_signature_ns_prefix. " lc_signature_ns_prefix = 'SPACE' |
" set attribute for C14n , means first element with Attribute. lc_c14n_attribute will be used to create a XML signature | ||
* | lo_sign->set_attributes( if_attribute_name = lc_c14n_attribute ). " lc_c14n_attribute = 'Id' | |
lo_sign->m_sign_attribute = lc_c14n_attribute. " lc_c14n_attribute = 'Id' | ||
lo_sign->m_sign_namespace = space. " SPACE | ||
lo_sign->m_pse_context | = lc_pse_context. " SSFA |
" Assina XML | |
lo_sign->sign_xml( | |
EXPORTING | |
if_ssf_app = ssfappl | |
if_add_keyinfo = abap_true | |
IMPORTING | |
ef_signature_xml = lf_signature | |
es_signer = ls_signer | |
). |
" Embed Signature at begin/end in unsigned xml
IF tag IS SUPPLIED. | ||
lo_sign->embed_signature( | ||
EXPORTING | ||
if_xml | = unsigned_xml | |
if_signature | = lf_signature | |
if_embed_into | = tag | |
if_embed_as_child = 'X' | ||
is_signer | = ls_signer | |
IMPORTING | ||
ef_result | = signed_xml ). | |
ELSE. | ||
lo_sign->embed_signature( | ||
EXPORTING | ||
if_xml | = unsigned_xml | |
if_signature | = lf_signature | |
if_embed_at_end = 'X' | ||
is_signer | = ls_signer | |
IMPORTING | ||
ef_result | = signed_xml ). | |
ENDIF. |
Olá Derik
Apesar de RJ e BH serem ambos baseados no padrão ABRASF, existem diferenças no processo de assinatura. RJ tem a assinatura de lote e de RPS, mas você pode assinar somente um deles, enquanto BH exige os dois. Pelo seu código, já vejo alguns parâmetros que estão faltando, como o "m_signature_reference_uri".
Sugiro que você use o programa SECXML_SIGN_SIGNED_XML como exemplo para testes e para analisar os parâmetros necessários.
Já há alguns tópicos no SCN também a respeito:
Abraços
Luis Becker
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Boa tarde Luís.
Obrigado pelo retorno. Já até consultei anteriormente os dois links sugeridos. Estou em contato com o Miguel Motta que no tópico Assinatura digital NFS-e disse que conseguiu gerar com sucesso pra BH. Vou testar as sua sugestão e as dicas dele e assim que conseguir alguma coisa volto aqui para dizer se funcionou.
User | Count |
---|---|
13 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.