0

With Delphi XE8 I imported a WSDL and use the HTTPRIO component For use authentication:

property HTTPRIO:
  HTTPWebNode ->
    ClientCertificate ->  CertName = ServiceSSL.cer
    InvokeOptions [soIgnoreInvalidCerts,soPickFirstClientCertificate]
 Event HTTPRIO
    HTTPWebNode -> OnBeforePost = HTTPRIO1HTTPWebNode1BeforePost


procedure HTTPRIO1HTTPWebNode1BeforePost(const HTTPReqResp: THTTPReqResp;
  Data: Pointer);
var
 auth: String;
 FUserName, FPassword : string;
begin
 FUserName:=UtenteTS;
 FPassword:=PassTS;
 auth := 'Authorization: Basic ' + TNetEncoding.Base64.Encode(FUserName + ':' + FPassword);
 HttpAddRequestHeaders(Data, PChar(auth), Length(auth), HTTP_ADDREQ_FLAG_ADD);
end;

Works well.

The problem is: when a Smart Card Reader with a digital signature card is inserted in the PC, during authentication it communicates with the smart card, opening a PIN request window.

enter image description here

I don't want this, i want to prioritize authentication through HTTPRIO1HTTPWebNode1BeforePost !

Note:

Run debug, HTTPRIO1HTTPWebNode1BeforePost, it is processed and then communication with the smart card is started. How can I disable Smart Card Reader reading?

The card with the digital signature I need connected to the PC because my program has to digitally sign documents.

I add details.

I noticed that after the call HTTPRIO1HTTPWebNode1BeforePost

this code is executed twice

 { line 1151 of soap.SOAPHTTPtrans.pas  Posting Data Event }
      if Assigned(FOnPostingData) then
        FOnPostingData(DatStr.Size, BuffSize);

      RetVal := ERROR_SUCCESS;
{$IFDEF UNICODE}
      HttpSendRequest(Request, nil, 0,
                      DatStr.Bytes, DatStr.Size);
{$ELSE}
      HttpSendRequest(Request, nil, 0,
                      @DatStr.DataString[1],
                      Length(DatStr.DataString));
{$ENDIF}
      RetVal := HandleWinInetError(GetLastError, Request, True);

      case RetVal of
        ERROR_SUCCESS: break;
        ERROR_CANCELLED: System.SysUtils.Abort;
        ERROR_INTERNET_FORCE_RETRY: {Retry the operation};
      end;

The first RetVal pass has value 12032 = ERROR_INTERNET_FORCE_RETRY: {Retry the operation};

the second step HttpSendRequest(Request, nil, 0, DatStr.Bytes, DatStr.Size); starts the smart card reader and opens the message login window which requests the PIN of the digit signature entered in the reader. RetVal = 0

I tried to use InternetSetOption(Data, INTERNET_FLAG_NO_AUTH, ????, ????) but I do not know how I can do it.

I don't want the login message box to open, request smart card PIN. How can I do?


update to my request

after reading this: I tried this:post "Replace WinINet by WinHTTP component. Both have very close APIs, and the 2nd does not create any UI interaction, but will return error codes, just like any other API. The UI part of WinINet may be a good idea for some software, but it sounds like if does not fit your needs."

How can I use winHttp with HttpRio? I tried:

uses winHTTP;
...
procedure HTTPRIOHTTPWebNode1BeforePost(const HTTPReqResp: THTTPReqResp; Data: Pointer);

auth := 'Authorization: Basic ' + TNetEncoding.Base64.Encode(FUserName + ':' + FPassword);

if not WinHttpAddRequestHeaders(Data, PChar(auth), Length(auth), WinHTTP_ADDREQ_FLAG_ADD) then ShowMessage('demat WinHttpAddRequestHeaders:  ' + SysErrorMessage(GetLastError()));

if I use HttpAddRequestHeaders (in winInet.dll) it works:

HttpAddRequestHeaders(Data, PChar(auth), Length(auth), HTTP_ADDREQ_FLAG_ADD)

if I use WinHttpAddRequestHeaders (in winhttp.dll) it NOT works, and I receive error: invalid handle.:

Handle is Data type Point.

in post About HINTERNET Handles "Microsoft Win32 Internet (WinInet) functions also use HINTERNET handles. However, the handles used in WinInet functions cannot be interchanged with the handles used in WinHTTP functions. For more information about WinInet, see About WinINet."

So I can't use WinHttpAddRequestHeaders with Httprio. I am sorry.

" WinHttpAddRequestHeaders(Data, PChar(auth), Length(auth), WinHTTP_ADDREQ_FLAG_ADD) I want to try using winHttp with HttpRio instead of winInet. As I read, using winHttp, I will not receive the windows security window (PIN request). I don't know how to use winHttp with HttpRio. " You can help me?

  • after reading this: I tried this:[post](https://stackoverflow.com/questions/8185923/delphi-soap-https-authentication-failure-pops-up-a-dialog-box) I consulted: [link microsoft](https://learn.microsoft.com/it-it/windows/win32/winhttp/porting-wininet-applications-to-winhttp?redirectedfrom=MSDN#_auth) No useful results. – carmelocony Oct 16 '19 at 08:45
  • Is there a function within WinInet to disable the certificates present in the system for the HTTPRio call? Perhaps, CertCloseStore ...? – carmelocony Oct 19 '19 at 12:18
  • I have verified that this problem occurs with all those who use HTTPrio and authentication "Authentication base = 'User: Password". It's not just my situation. Delphi + HTTPRio + Authentication Base + SmartCard or KeyUSB with certificate = PIN request message. The WS accepts basic Authentication not certified by smartcard – carmelocony Oct 21 '19 at 06:54
  • I solved it by calling the onWinInetError event of the HttpRio component. Thanks to all, maybe the solution can serve others. – carmelocony Dec 12 '19 at 08:34

0 Answers0