XML signature error for EFD-Reinf in Elixir

0

I followed the instructions posted in this link:

This was very enlightening, but I'm still having trouble signing the REINF XML using Elixir as a language.

In the example I put below, I'm trying to sign the event "evtInfoContri", the format I'm using to sign is this way:

<Reinf xmlns="http://www.reinf.esocial.gov.br/schemas/evtInfoContribuinte/v1_03_02"><evtInfoContri id="ID1142933600000002018051414491100281"><ideEvento><tpAmb>2</tpAmb><procEmi>1</procEmi><verProc>V2R010</verProc></ideEvento><ideContri><tpInsc>1</tpInsc><nrInsc>14293360</nrInsc></ideContri><infoContri><inclusao><idePeriodo><iniValid>2018-01</iniValid></idePeriodo><infoCadastro><classTrib>99</classTrib><indEscrituracao>1</indEscrituracao><indDesoneracao>1</indDesoneracao><indAcordoIsenMulta>0</indAcordoIsenMulta><indSitPJ>0</indSitPJ><contato><nmCtt>CARLOS DOMIENIKAN</nmCtt><cpfCtt>18293491809</cpfCtt><foneFixo>1149021845</foneFixo><email>[email protected]</email></contato></infoCadastro></inclusao></infoContri></evtInfoContri></Reinf>

As I try to show, this XML is on a single line. For signing and creating the digest, I'm using the ExCrypto module, performing the following statements:

rsa_priv_key     = ExPublicKey.load!("priv/cert/private_rsa.key")
{:ok, hash}      = ExCrypto.Hash.sha256(evento())
digest           = "#{Base.encode64 hash}"
{:ok, signature} = ExPublicKey.sign(eventoXML(), :sha256, rsa_priv_key)
base64           = "#{Base.encode64 signature}"

Once this has been accomplished, my signed XML stays this way (Addendum: For security reasons because it is my client's private information, the data has been modified here, so it was not necessarily set up like this)

<Reinf xmlns="http://www.reinf.esocial.gov.br/schemas/evtInfoContribuinte/v1_03_02"><evtInfoContri id="ID1142933600000002018051414491100281"><ideEvento><tpAmb>2</tpAmb><procEmi>1</procEmi><verProc>V2R010</verProc></ideEvento><ideContri><tpInsc>1</tpInsc><nrInsc>12345678</nrInsc></ideContri><infoContri><inclusao><idePeriodo><iniValid>2018-01</iniValid></idePeriodo><infoCadastro><classTrib>99</classTrib><indEscrituracao>1</indEscrituracao><indDesoneracao>1</indDesoneracao><indAcordoIsenMulta>0</indAcordoIsenMulta><indSitPJ>0</indSitPJ><contato><nmCtt>Empresa XPTO</nmCtt><cpfCtt>12345678999</cpfCtt><foneFixo>1123456789</foneFixo><email>[email protected]</email></contato></infoCadastro></inclusao></infoContri></evtInfoContri><Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/><SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/><Reference URI="#ID1142933600000002018051414491100281"><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/2001/04/xmlenc#sha256"/><DigestValue>Valor do digest em Base64</DigestValue></Reference></SignedInfo><SignatureValue>Valor da assinatura em Base64</SignatureValue><KeyInfo><X509Data><X509Certificate>Valor do certificado</X509Data></KeyInfo></Signature></Reinf>

and after enveloping it looks like this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sped="http://sped.fazenda.gov.br/"><soapenv:Header/><soapenv:Body><sped:ReceberLoteEventos><sped:loteEventos><Reinf xmlns="http://www.reinf.esocial.gov.br/schemas/envioLoteEventos/v1_03_02"><loteEventos><evento id="ID1142933600000002018051414491100281"><Reinf xmlns="http://www.reinf.esocial.gov.br/schemas/evtInfoContribuinte/v1_03_02"><evtInfoContri id="ID1142933600000002018051414491100281"><ideEvento><tpAmb>2</tpAmb><procEmi>1</procEmi><verProc>V2R010</verProc></ideEvento><ideContri><tpInsc>1</tpInsc><nrInsc>12345678</nrInsc></ideContri><infoContri><inclusao><idePeriodo><iniValid>2018-01</iniValid></idePeriodo><infoCadastro><classTrib>99</classTrib><indEscrituracao>1</indEscrituracao><indDesoneracao>1</indDesoneracao><indAcordoIsenMulta>0</indAcordoIsenMulta><indSitPJ>0</indSitPJ><contato><nmCtt>Empresa XPTO</nmCtt><cpfCtt>12345678999</cpfCtt><foneFixo>1123456789</foneFixo><email>[email protected]</email></contato></infoCadastro></inclusao></infoContri></evtInfoContri><Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/><SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/><Reference URI="#ID1142933600000002018051414491100281"><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/2001/04/xmlenc#sha256"/><DigestValue>Valor do digest em Base64</DigestValue></Reference></SignedInfo><SignatureValue>Valor da assinatura em Base64</SignatureValue><KeyInfo><X509Data><X509Certificate>Valor do certificado</X509Data></KeyInfo></Signature></Reinf></evento></loteEventos></Reinf></sped:loteEventos></sped:ReceberLoteEventos></soapenv:Body></soapenv:Envelope>

Even doing this, I get the message MS0017 as a result.

What could be wrong?

Thank you very much for your attention,

    
asked by anonymous 29.05.2018 / 16:24

0 answers