Well
There are two things you can do:
1: Show the certificate error to the user and allow him to decide whether or not to continue.
2: Ignore any certificate errors you receive.
I will show you how to make the second option:
When you get ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED or any other certificate error, you need to call InternetSetOptions to tell wininet that it should ignore the error and continue. After that you need to resend the request.
function SetToIgnoreCerticateErrors(var aErrorMsg: string): Boolean; var vDWFlags: DWord; vDWFlagsLen: DWord; begin Result := False; try vDWFlagsLen := SizeOf(vDWFlags); if not InternetQueryOptionA(oRequestHandle, INTERNET_OPTION_SECURITY_FLAGS, @vDWFlags, vDWFlagsLen) then begin aErrorMsg := 'Internal error in SetToIgnoreCerticateErrors when trying to get wininet flags.' + GetWininetError; Exit; end; vDWFlags := vDWFlags or SECURITY_FLAG_IGNORE_UNKNOWN_CA or SECURITY_FLAG_IGNORE_CERT_DATE_INVALID or SECURITY_FLAG_IGNORE_CERT_CN_INVALID or SECURITY_FLAG_IGNORE_REVOCATION; if not InternetSetOptionA(oRequestHandle, INTERNET_OPTION_SECURITY_FLAGS, @vDWFlags, vDWFlagsLen) then begin aErrorMsg := 'Internal error in SetToIgnoreCerticateErrors when trying to set wininet INTERNET_OPTION_SECURITY_FLAGS flag .' + GetWininetError; Exit; end; Result := True; except on E: Exception do begin aErrorMsg := 'Unknown error in SetToIgnoreCerticateErrors.' + E.Message; end; end; end; vErrorNone := HttpSendRequest(HttpOpen_Request, nil, 0, nil, 0); if vErrorNone = False then begin vErrorID := GetLastError; if (vErrorID = ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED) then begin //call SetToIgnoreCerticateErrors //re-send the request end end end;
I extracted SetToIgnoreCerticateErrors from my wininet API and cannot compile it accurately.
These are the following steps:
1 - Get an error
2 - Check if the error is a certificate error
3 - If this is a certificate error, they call InternetSetOption, just like me.
4 - Resubmit the request.
I donβt know how to implement the first option "Show the certificate error to the user and let him decide whether or not to continue." because I never had to do this.
Also check this out: How to handle a certificate authority error using WinInet
Hope this helps you.
source share