Open modal with Javascript to select certificate and send to server

Asked

Viewed 4,499 times

4

When we enter the page eCAC - Virtual Call Center and we click on Digital Certificate on the right side of the screen a modal is opened to select certain certificate that we configure in the system (this if there is certificate(s) in the configured system). Follow the image of the modal with the deleted modal description:

inserir a descrição da imagem aqui

I would like to know how I can implement a similar feature in a particular system application using Javascript to load the customer’s NF-e certificate and use it in order to send the bills to the government and carry out other operations with them. I haven’t figured out where to start yet and few materials were found.

  • Sending the file is even possible, but this is not how the certificate is validated. First because only type A1 would be possible to read and it needs to be computer-based, which requires typing the password. Type A3 cannot read without a specific reader, as it is of the type A3 inviolable.

  • And this certificate needs to be made available on the server or is only on the client side?

  • It needs to be installed on the system that will issue the NF, IE, Voce need to pass your certificate and enter your password. All systems I’ve seen that do what Voce wants to do require Voce to make your certificate available to the issuing system. It’s kind of sharing your certificate.

  • Any example of code that allows this sharing? The certificate is already installed correctly on the machine, a file with extension . pfx has been installed

  • 1

    Since your system is for Java, I believe this project can help you. https://github.com/wmixvideo/nfe

  • I’m already using it, the question now is, do the same as eCAC does or will have to store the client certificate in a directory on the server?

  • 1

    You will need to create a form where the customer places the certificate (file upload) and password of the A1 certificate. Then just use the class to consume the Sefaz Webservice referring to the correct federation unit. Understand that this model is different from what eCac does where it already reads the certificate directly from the browser that in turn reads from the S.O. To avoid doing this every time you work with this Certificate, you can store the information on the server. In the case of A3 you would need an applet to communicate with the reader EVERY time you use it. You can’t store.

  • 1

    And how do you do it the way eCac does it? In this case I am using ASP.NET MVC, but I believe that if the language used to do this is web, such as javascript, I can implement in ASP.NET as well. How to read the certificate through the browser?

  • I still have this doubt friend and I have not found the solution so far

  • Giancarlo all right? Well, I’m having the same doubt, managed to find some solution?

  • Unfortunately not yet, if you find an answer here (;

  • The process that opens this "modal" is a negotiation in connection time (network layer) called TSL Handshake, I explained a little of how it works, and how I implemented in my own system the flow with PHP(https://answall.com/a/195838/7130) similar

Show 7 more comments

1 answer

3


Well, after a long time, I managed to find a solution, today Certisign has an API that validates digital certificates.

If I’m not mistaken a GET with javascript is blocked by the CORS of their application,

<form action=" https://autenticador.certisign.com.br/CertisignLogin/certificado/login?id={idDaChave}&nome={nomeDaChave}&retorno={urlDeRetorno}"
  method="get">
   <input type="submit" value="enviar" />
</form>

Using a form, when you send it, it will automatically prompt you to choose the certificate, and open the modal.

In this return URL, it will send you an encrypted token if authenticated, and you will have access to the data, for example:

CertificadoBean:
{
  emissor: Certisign Autoridade Certificadora TESTE,
  nome: "PROPRIETARIO DO CERTIFICADO DE TESTE",
  cpf: "001.002.003-44",
  cnpj: "",
  OAB: "",
  validade: "2015-05-27 20:59:59",
  emissao: "2014-05-27 21:00:00",
  email: "[email protected]",
  certificadoBase64: "MIIFmDCCBICgAwI...... BAQUFADCCARAx"
}

If you have any further questions, https://www.certisign.com.br/solucoes-corporativas/seguranca-e-gerenciamento/certisignlogin/desenvolvedores

Here on my team, we had some questions, so we called them on the phone that’s on the site. They treated us super well and answered all our questions.

  • Good afternoon, did you manage to sort it out? I tried to do, opened the screen to select the certificate and clicked, but keeps looping the page, know tell me why?

Browser other questions tagged

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