Handshake Failure Idhttp - Packaged digital certificate

Asked

Viewed 574 times

0

Rephrasing the question...

I was able to get an answer from the webserve, but it is returning the following error:

inserir a descrição da imagem aqui

I need to encapsulate a digital Ceritificado together with the requisition and do not know how to do it, so I researched I need to do something with the properties of the class Tidssliohandlersocketopenssl, but I do not know how to proceed.

It follows the properties I researched:

IdSSLIOHandlerSocketOpenSSL.SSLOptions.CertFile IdSSLIOHandlerSocketOpenSSL.SSLOptions.KeyFile IdSSLIOHandlerSocketOpenSSL.SSLOptions.RootCertFile

Wall I need to put the path of some file on them, I don’t know.

Follow the code I’m using:

procedure TForm2.Button2Click(Sender: TObject);
var
   str: TStringList;
   strResp : TStringStream;
   IdHTTP: TIdHTTP;
   IdSSLIOHandlerSocketOpenSSL: TIdSSLIOHandlerSocketOpenSSL;
begin
  str := TStringList.Create;
  strResp := TStringStream.Create('');
  IdHTTP := TIdHTTP.Create(nil);
  IdSSLIOHandlerSocketOpenSSL := TIdSSLIOHandlerSocketOpenSSL.Create(IdHTTP);
  IdSSLIOHandlerSocketOpenSSL.SSLOptions.Method := sslvTLSv1_2;
  IdHTTP.IOHandler := IdSSLIOHandlerSocketOpenSSL;
  IdHTTP.Request.CustomHeaders.Clear;
  IdHTTP.Request.CustomHeaders.AddValue('Role-Type','IMPEXP');
  IdHTTP.Post('https://val.portalunico.siscomex.gov.br/portal/api/autenticar',str, strResp);
  Memo1.Lines.Text := strResp.ToString;
end;
  • 2

    You should leave a comment on the questions indicated or offer a reward for your answers. And don’t open a new question with their link. If so, you could create your own question including your specific code and scenario.

1 answer

0

I owned the certificate . P12, so I converted it to . pem with the command 'openssl pkcs12 -in FILE.P12 -out SAIDA_ARQUIVO.pem -nodes' running Openssl by command prompt.

I used the following code:

procedure TForm1.BitBtnClick(Sender: TObject);
var
  URL: String;
  URLNFe: String;
  str: TStringList;
  strResp : TStringStream;
  IdHTTP: TIdHTTP;
  IdSSLIOHandlerSocketOpenSSL: TIdSSLIOHandlerSocketOpenSSL;
begin
   try
      URL := 'https://val.portalunico.siscomex.gov.br/portal/api/autenticar';
      URLNFe:= 'https://val.portalunico.siscomex.gov.br/cct/api/ext/carga/recepcao-nfe';

      str := TStringList.Create;
      strResp := TStringStream.Create(Memo1.Lines.Text);
      IdHTTP := TIdHTTP.Create(Self);
      IdSSLIOHandlerSocketOpenSSL := TIdSSLIOHandlerSocketOpenSSL.Create(IdHTTP);
      IdSSLIOHandlerSocketOpenSSL.SSLOptions.Method := sslvTLSv1_2;
      IdSSLIOHandlerSocketOpenSSL.SSLOptions.CertFile := 'dir\cert.pem';
      IdSSLIOHandlerSocketOpenSSL.SSLOptions.KeyFile := 'dir\cert.pem';
      IdHTTP.IOHandler := IdSSLIOHandlerSocketOpenSSL;
      IdHTTP.Request.CustomHeaders.Clear;
      IdHTTP.Request.CustomHeaders.AddValue('Role-Type','IMPEXP');
      IdHTTP.Post(URL,str, strResp);
      Memo1.Lines.Text := strResp.DataString;
   finally
      strResp.Free;
   end;
end;

Browser other questions tagged

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