1
I would like to know how I can achieve the integration of a digital certificate of the kind A3 to the component Tidssliohandlersocketopenssl. I already managed to perform the search part and choose which digital certificate to use, but now I’m having difficulty associating the chosen certificate to the component Tidssliohandlersocketopenssl, because I need to make the access to the site GNRE - https://www.testegnre.pe.gov.br/gnreWS/services/GnreLoteReception which requires that the connection to that webservice be made through a certificate.
Function that obtains the certificate settings
This function uses the Microsoft Capicom component.
function TForm1.GetCertificado: Boolean;
var
Store: IStore3;
CertsLista, CertsSelecionado: ICertificates2;
CertDados: ICertificate;
lSigner: TSigner;
lSignedData: TSignedData;
begin
Result := False;
Store := CoStore.Create;
Store.Open(CAPICOM_CURRENT_USER_STORE, 'My',CAPICOM_STORE_OPEN_MAXIMUM_ALLOWED);
CertsLista := Store.Certificates as ICertificates2;
CertsSelecionado := CertsLista.Select('Certificado(s) Digital(is) disponível(is)',
'Selecione o Certificado Digital para uso no aplicativo', False);
if not(CertsSelecionado.Count = 0) then
begin
CertDados := IInterface(CertsSelecionado.Item[1]) as ICertificate2;
{ Configura o objeto responsável por fazer a assinatura, informando qual é o certificado a ser usado e o conteúdo a ser assinado }
lSigner := TSigner.Create(self);
lSigner.Certificate := CertDados;
lSignedData := TSignedData.Create(self);
lSignedData.Content := ' ';
if CertDados.ValidFromDate > Now then
begin
showmessage('Certificado não liberado. aguardar ' + datetostr(CertDados.ValidFromDate));
exit;
end;
if CertDados.ValidToDate < Now then
begin
showmessage('Certificado expirado');
exit;
end;
{ Solicita a senha }
lSignedData.Sign(lSigner.DefaultInterface, False, CAPICOM_ENCODE_BASE64);
Result := True;
lSignedData.Free;
lSigner.Free;
end;
end;
Access to the Webservice
function EnvioWS(XML:String):String;
var
SSLIOHandlerSocketOpenSSL: TIdSSLIOHandlerSocketOpenSSL;
IdHTTP: TIdHTTP;
Retorno, Envio: TStringStream;
begin
try //Instancia e configuração
IdHTTP := TIdHTTP.Create(nil);
IdHTTP.HTTPOptions := [hoKeepOrigProtocol];
SSLIOHandlerSocketOpenSSL := TIdSSLIOHandlerSocketOpenSSL.Create(IdHTTP);
IdHTTP.IOHandler := SSLIOHandlerSocketOpenSSL;
IdHTTP.Request.CharSet := 'UTF-8';
IdHTTP.Request.ContentType := 'application/soap+xml; charset=utf-8';
if GetCertificado then
begin
//Envio ao WS
Envio := TStringStream.Create(XML);
Retorno := TStringStream.Create(EmptyStr);
IdHTTP.CustomHeaders.Add(Format('SOAPAction: "%s"', ['http://www.gnre.pe.gov.br/webservice/GnreResultadoLote/GnreConfigUF']));
IdHTTP.post(Envio, Retorno);
Result := Retorno.DataString;
end;
finally
if assigned(IdHTTP) then
FreeAndNil(IdHTTP);
if assigned(Retorno) then
FreeAndNil(Retorno);
if assigned(Envio) then
FreeAndNil(Envio);
end;
end;
how do you access this web service ? can pass the code ?
– Passella
@Passella ready, I put the code I use for sending
– Jhonny Rm