Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8038184

XMLSignature throws StringIndexOutOfBoundsException if ID attribute value is empty String

XMLWordPrintable

    • b10
    • generic
    • generic
    • Verified

        FULL PRODUCT VERSION :
        java version "1.8.0"
        Java(TM) SE Runtime Environment (build 1.8.0-b132)
        Java HotSpot(TM) Client VM (build 25.0-b70, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows [Version 6.2.9200]

        A DESCRIPTION OF THE PROBLEM :
        I'm trying to sign the "InfRps" tag on the following XML file:

        <?xml version="1.0" encoding="UTF-8"?>
        <EnviarLoteRpsEnvio xmlns="http://www.abrasf.org.br/nfse.xsd">
          <LoteRps Id="" versao="1.00">
            <NumeroLote>100</NumeroLote>
            <Cnpj>01339695000101</Cnpj>
            <InscricaoMunicipal>01323820024</InscricaoMunicipal>
            <QuantidadeRps>1</QuantidadeRps>
            <ListaRps>
              <Rps>
                <InfRps Id="1">
                  <IdentificacaoRps>
                    <Numero>500122</Numero>
                    <Serie>900</Serie>
                    <Tipo>1</Tipo>
                  </IdentificacaoRps>
                  <DataEmissao>2014-03-21T00:00:00.000-03:00</DataEmissao>
                  <NaturezaOperacao>1</NaturezaOperacao>
                  <OptanteSimplesNacional>2</OptanteSimplesNacional>
                  <IncentivadorCultural>2</IncentivadorCultural>
                  <Status>1</Status>
                  <Servico>
                    <Valores>
                      <ValorServicos>98.01</ValorServicos>
                      <ValorPis>0.00</ValorPis>
                      <ValorCofins>0.00</ValorCofins>
                      <ValorInss>0.00</ValorInss>
                      <ValorIr>0.00</ValorIr>
                      <IssRetido>2</IssRetido>
                      <ValorIss>0.00</ValorIss>
                      <Aliquota>0.00</Aliquota>
                    </Valores>
                    <ItemListaServico>1</ItemListaServico>
                    <CodigoCnae>6201500</CodigoCnae>
                    <Discriminacao>1 null - R$ 98,01</Discriminacao>
                    <CodigoMunicipio>3106200</CodigoMunicipio>
                  </Servico>
                  <Prestador>
                    <Cnpj>01339695000101</Cnpj>
                    <InscricaoMunicipal>01323820024</InscricaoMunicipal>
                  </Prestador>
                  <Tomador>
                    <IdentificacaoTomador>
                      <CpfCnpj>
                        <Cpf>01234567890</Cpf>
                      </CpfCnpj>
                    </IdentificacaoTomador>
                    <RazaoSocial>CLIENTE AVULSO</RazaoSocial>
                    <Endereco>
                      <Endereco>RUA CATETE</Endereco>
                      <Numero>999</Numero>
                      <Complemento>601/701</Complemento>
                      <Bairro>ALTO BARROCA</Bairro>
                      <CodigoMunicipio>3106200</CodigoMunicipio>
                      <Uf>MG</Uf>
                      <Cep>30431016</Cep>
                    </Endereco>
                  </Tomador>
                </InfRps>
              </Rps>
            </ListaRps>
          </LoteRps>
        </EnviarLoteRpsEnvio>


        And I'm getting the following error message:

        2014-03-21 09:27:17,747 ERROR [Tarefa NFe 34.034.264.168] ComandoAppletNFeQueueImpl.enviaComando(60) | Stack trace remoto referente a taskId 34034264168: com.ats.jnfe.exception.NfeConfigurationException: erros: [Erro ao realizar a assinatura. Favor, verificar se o certificado está configurado corretamente nas configurações.] alertas: []
        at com.ats.jnfe.service.comunicacao.impl.MscapiSecurityHandlerBean.handle(MscapiSecurityHandlerBean.java:88)
        at com.ats.jnfe.applet.security.ConfigurableSecurityHandlerBean.handle(ConfigurableSecurityHandlerBean.java:42)
        at br.com.jnfe.base.service.DOMNFeSignatureHandler.sign(DOMNFeSignatureHandler.java:57)
        at com.ats.jnfe.applet.client.impl.ClientComandoAppletNFeServiceImpl.newSignature(ClientComandoAppletNFeServiceImpl.java:130)
        at com.ats.jnfe.applet.client.impl.ClientComandoAppletNFeHandlerImpl.trataComando(ClientComandoAppletNFeHandlerImpl.java:63)
        at com.ats.jnfe.applet.client.impl.ComandoAppletNFeExecutorImpl$1.run(ComandoAppletNFeExecutorImpl.java:64)
        at java.lang.Thread.run(Unknown Source)
        Caused by: java.lang.IllegalArgumentException: Impossível construir assinatura,
        at br.com.jnfe.base.service.DOMNFeSignatureBuilder.build(DOMNFeSignatureBuilder.java:207)
        at br.com.jnfe.base.service.DOMNFeSignatureBuilder.build(DOMNFeSignatureBuilder.java:1)
        at br.com.jnfe.base.service.DOMNFeSignatureHandler$1.doInSecurityContext(DOMNFeSignatureHandler.java:59)
        at com.ats.jnfe.service.comunicacao.impl.MscapiSecurityHandlerBean.handle(MscapiSecurityHandlerBean.java:86)
        ... 6 more
        Caused by: javax.xml.crypto.dsig.XMLSignatureException: javax.xml.crypto.URIReferenceException: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
        at org.jcp.xml.dsig.internal.dom.DOMReference.dereference(Unknown Source)
        at org.jcp.xml.dsig.internal.dom.DOMReference.digest(Unknown Source)
        at org.jcp.xml.dsig.internal.dom.DOMXMLSignature.digestReference(Unknown Source)
        at org.jcp.xml.dsig.internal.dom.DOMXMLSignature.sign(Unknown Source)
        at br.com.jnfe.base.service.DOMNFeSignatureBuilder.build(DOMNFeSignatureBuilder.java:195)
        ... 9 more
        Caused by: javax.xml.crypto.URIReferenceException: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
        at org.jcp.xml.dsig.internal.dom.DOMURIDereferencer.dereference(Unknown Source)
        ... 14 more
        Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
        at java.lang.String.charAt(Unknown Source)
        at com.sun.org.apache.xml.internal.security.utils.XMLUtils.protectAgainstWrappingAttack(Unknown Source)
        at com.sun.org.apache.xml.internal.security.utils.resolver.implementations.ResolverFragment.engineResolveURI(Unknown Source)
        at com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolver.resolve(Unknown Source)
        at com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolver.resolve(Unknown Source)
        ... 15 more

        I'm still not sure whether there's an error on the XML or not, but the error message definitely doesn't point me towards any useful direction.


        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        2014-03-21 09:27:17,747 ERROR [Tarefa NFe 34.034.264.168] ComandoAppletNFeQueueImpl.enviaComando(60) | Stack trace remoto referente a taskId 34034264168: com.ats.jnfe.exception.NfeConfigurationException: erros: [Erro ao realizar a assinatura. Favor, verificar se o certificado está configurado corretamente nas configurações.] alertas: []
        at com.ats.jnfe.service.comunicacao.impl.MscapiSecurityHandlerBean.handle(MscapiSecurityHandlerBean.java:88)
        at com.ats.jnfe.applet.security.ConfigurableSecurityHandlerBean.handle(ConfigurableSecurityHandlerBean.java:42)
        at br.com.jnfe.base.service.DOMNFeSignatureHandler.sign(DOMNFeSignatureHandler.java:57)
        at com.ats.jnfe.applet.client.impl.ClientComandoAppletNFeServiceImpl.newSignature(ClientComandoAppletNFeServiceImpl.java:130)
        at com.ats.jnfe.applet.client.impl.ClientComandoAppletNFeHandlerImpl.trataComando(ClientComandoAppletNFeHandlerImpl.java:63)
        at com.ats.jnfe.applet.client.impl.ComandoAppletNFeExecutorImpl$1.run(ComandoAppletNFeExecutorImpl.java:64)
        at java.lang.Thread.run(Unknown Source)
        Caused by: java.lang.IllegalArgumentException: Impossível construir assinatura,
        at br.com.jnfe.base.service.DOMNFeSignatureBuilder.build(DOMNFeSignatureBuilder.java:207)
        at br.com.jnfe.base.service.DOMNFeSignatureBuilder.build(DOMNFeSignatureBuilder.java:1)
        at br.com.jnfe.base.service.DOMNFeSignatureHandler$1.doInSecurityContext(DOMNFeSignatureHandler.java:59)
        at com.ats.jnfe.service.comunicacao.impl.MscapiSecurityHandlerBean.handle(MscapiSecurityHandlerBean.java:86)
        ... 6 more
        Caused by: javax.xml.crypto.dsig.XMLSignatureException: javax.xml.crypto.URIReferenceException: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
        at org.jcp.xml.dsig.internal.dom.DOMReference.dereference(Unknown Source)
        at org.jcp.xml.dsig.internal.dom.DOMReference.digest(Unknown Source)
        at org.jcp.xml.dsig.internal.dom.DOMXMLSignature.digestReference(Unknown Source)
        at org.jcp.xml.dsig.internal.dom.DOMXMLSignature.sign(Unknown Source)
        at br.com.jnfe.base.service.DOMNFeSignatureBuilder.build(DOMNFeSignatureBuilder.java:195)
        ... 9 more
        Caused by: javax.xml.crypto.URIReferenceException: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
        at org.jcp.xml.dsig.internal.dom.DOMURIDereferencer.dereference(Unknown Source)
        ... 14 more
        Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
        at java.lang.String.charAt(Unknown Source)
        at com.sun.org.apache.xml.internal.security.utils.XMLUtils.protectAgainstWrappingAttack(Unknown Source)
        at com.sun.org.apache.xml.internal.security.utils.resolver.implementations.ResolverFragment.engineResolveURI(Unknown Source)
        at com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolver.resolve(Unknown Source)
        at com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolver.resolve(Unknown Source)
        ... 15 more

        REPRODUCIBILITY :
        This bug can be reproduced always.

              mullan Sean Mullan
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: