Handshake failure IdHTTP - Encapsulate digital certificate

0

Reformulating the question ...

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

I need to encapsulate a digital certificate next to the request and I do not know how to do this, so I researched I need to do something with the properties of the TIdSSLIOHandlerSocketOpenSSL class, but I do not know how to do it.

Here are the properties I searched for:

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

Wall I need to put the path of some file in them, I do not know.

Here is 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;
    
asked by anonymous 28.02.2018 / 15:16

1 answer

0

I had the .p12 certificate, so I converted it to .pem with the 'openssl pkcs12 -in command ARCHIVING.p12 -out OUTPUT_RECORD.pem -nodes' running OpenSSL from the 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;
    
02.03.2018 / 18:13