Error signing xml nfse Curitba

Asked

Viewed 345 times

0

Guys I’m making the following mistake :

Grave:   javax.faces.el.EvaluationException: javax.xml.crypto.dsig.XMLSignatureException: javax.xml.crypto.URIReferenceException: com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException: Cannot resolve element with ID 2
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:745)
 Caused by: javax.xml.crypto.dsig.XMLSignatureException: javax.xml.crypto.URIReferenceException: com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException: Cannot resolve element with ID 2
at org.jcp.xml.dsig.internal.dom.DOMReference.dereference(DOMReference.java:436)
at org.jcp.xml.dsig.internal.dom.DOMReference.digest(DOMReference.java:364)
at org.jcp.xml.dsig.internal.dom.DOMXMLSignature.digestReference(DOMXMLSignature.java:496)
at org.jcp.xml.dsig.internal.dom.DOMXMLSignature.sign(DOMXMLSignature.java:379)
at Controller.Assinador.assinaLoteRpsNFSe(Assinador.java:161)
at Controller.Assinador.assinaNFSe(Assinador.java:205)
at Controller.Assinador.assinaXML(Assinador.java:193)
at Controller.solicitacaoBean.xml(solicitacaoBean.java:686)
at Controller.solicitacaoBean.gravaFaturamento(solicitacaoBean.java:366)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at javax.el.ELUtil.invokeMethod(ELUtil.java:332)
at javax.el.BeanELResolver.invoke(BeanELResolver.java:537)
at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:256)
at com.sun.el.parser.AstValue.invoke(AstValue.java:283)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
... 36 more
Caused by: javax.xml.crypto.URIReferenceException: com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException: Cannot resolve element with ID 2
at org.jcp.xml.dsig.internal.dom.DOMURIDereferencer.dereference(DOMURIDereferencer.java:121)
at org.jcp.xml.dsig.internal.dom.DOMReference.dereference(DOMReference.java:430)
... 55 more
Caused by: com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException: Cannot resolve element with ID 2
at com.sun.org.apache.xml.internal.security.utils.resolver.implementations.ResolverFragment.engineResolveURI(ResolverFragment.java:89)
at com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolver.resolve(ResourceResolver.java:313)
at com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolver.resolve(ResourceResolver.java:298)
at org.jcp.xml.dsig.internal.dom.DOMURIDereferencer.dereference(DOMURIDereferencer.java:114)
... 56 more

Follow my xml where you are trying to assimilate

<?xml version="1.0" encoding="UTF-8"?>
<EnviarLoteRpsEnvio xsi:schemaLocation="http://isscuritiba.curitiba.pr.gov.br/iss/nfse.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://isscuritiba.curitiba.pr.gov.br/iss/nfse.xsd">
<LoteRps id="2" xmlns="">
<NumeroLote>2</NumeroLote>
<Cnpj>06994660000111</Cnpj>
<InscricaoMunicipal>04890151</InscricaoMunicipal>
<QuantidadeRps>1</QuantidadeRps>
<ListaRps>
<Rps>
<InfRps>
<IdentificacaoRps>
<Numero>201612051</Numero>
<Serie>F</Serie>
<Tipo>1</Tipo>
</IdentificacaoRps>
<DataEmissao>2016-12-05T10:46:21</DataEmissao>
<NaturezaOperacao>1</NaturezaOperacao>
<RegimeEspecialTributacao>1</RegimeEspecialTributacao>
<OpitanteSimplesNacional>1</OpitanteSimplesNacional>
<IncentivadorCultural>2</IncentivadorCultural>
<Status>1</Status>
<Servico>
<Valores>
<ValorServicos>250.0</ValorServicos>
<ValorDeducoes>0.0</ValorDeducoes>
<ValorPis>25.0</ValorPis>
<ValorCofins>25.0</ValorCofins>
<ValorInss>0.0</ValorInss>
<ValorIr>25.0</ValorIr>
<ValorCsll>25.0</ValorCsll>
<IssRetido>2</IssRetido>
<ValorIss>25.0</ValorIss>
<ValorIssRetido>0.0</ValorIssRetido>
<OutrasRetencoes>0.0</OutrasRetencoes>
<BaseCalculo>250.0</BaseCalculo>
<Aliquota>0.0</Aliquota>
<ValorLiquidoNfse>0.0</ValorLiquidoNfse>
<DescontoIncondicionado>0.0</DescontoIncondicionado>
<DescontoCondicionado>0.0</DescontoCondicionado>
</Valores>
<ItemListaServico>0.0</ItemListaServico>
<Descriminacao>MANUTENCAOO VEICULAR - TOTAL 250.0 SOLICITACAO null BANCO DO BRASIL AGENCIA 0756-0CONTACORRENTE :54582-1 </Descriminacao>
<CodigoMunicipio>4106902</CodigoMunicipio>
</Servico>
<Prestador>
<Cnpj>06994660000111</Cnpj>
<InscricaoMunicipal>04890151</InscricaoMunicipal>
</Prestador>
<Tomador>
<IdentificacaoTomador>
<CpfCnpj>
<Cnpj>03141166000116</Cnpj>
</CpfCnpj>
</IdentificacaoTomador>
<RazaoSocial>Tribunal Regional do Trabalho da 9ª Região</RazaoSocial>
<Endereco>
<Entedeco>Al. Dr. Carlos de Carvalho</Entedeco>
<Numero>528</Numero>
<Bairro>Centro</Bairro>
<CodigoMuniciopio>4106902</CodigoMuniciopio>
<Uf>PR</Uf>
<Cep>80430180</Cep>
</Endereco>
<Contato>
<Telefone>4133107770</Telefone>
<Email>[email protected]</Email>
</Contato>
</Tomador>
</InfRps>
</Rps>
</ListaRps>
</LoteRps>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo xmlns="">
<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="#2">
<Transforms>
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<DigestValue/>
</Reference>
</SignedInfo>
<SignatureValue xmlns=""/>
<KeyInfo xmlns="">
<X509Data>
<X509Certificate/>
</X509Data>
</KeyInfo>
</Signature>
</EnviarLoteRpsEnvio>

Follow my signature class:

    public void assinaLoteRpsNFSe(String tipo, XMLSignatureFactory fac,
        ArrayList<Transform> transformList, PrivateKey privateKey,
        KeyInfo ki, Document document, int indexNFe) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, MarshalException, XMLSignatureException, javax.xml.crypto.MarshalException {
    if (tipo.equals(Assinador.EnviarLoteRpsEnvio)) {
        this.elements = this.document.getDocumentElement().getElementsByTagName("LoteRps");
    }
    if (tipo.equals(Assinador.RPS)) {
        this.elements = this.document.getElementsByTagName("InfRps");
    }

    this.el = (org.w3c.dom.Element) this.elements.item(indexNFe);

    String id = el.getAttribute("id");
    this.ref = fac.newReference("#" + id,
            fac.newDigestMethod(DigestMethod.SHA1, null), transformList,
            null, null);
    this.si = fac.newSignedInfo(fac.newCanonicalizationMethod(
            CanonicalizationMethod.INCLUSIVE,
            (C14NMethodParameterSpec) null), fac
            .newSignatureMethod(SignatureMethod.RSA_SHA1, null),
            Collections.singletonList(ref));
    this.signature = fac.newXMLSignature(si, ki);
    this.dsc = new DOMSignContext(privateKey,
            document.getDocumentElement().getElementsByTagName(tipo).item(indexNFe));
    this.signature.sign(this.dsc);
}

by which I saw this giving error in the last line this.signature.sign(this.dsc);

1 answer

1

  • Friend the signature I managed to solve , now the problem is Enviar Loterpsenvio , vc has some example of how to do?

  • In the user manual there is a link to download a . zip file, as mentioned above, with examples of all the cases you will need. But if the error still persists, I ask you to ask a new question since the context is different, so we respect the rules of the stack.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.