vendredi 8 août 2014

Web services - désactiver la validation de certificat - Stack Overflow


I need to consume a WCF, but it has a certificate and I need to disable its authentication. Does anyone know how can I do this in Delphi XE2?


I've already tried the codes below:


First attempt :


Rio.HTTPWebNode.InvokeOptions:= [soIgnoreInvalidCerts,soAutoCheckAccessPointViaUDDI];


Where Rio is a THTTPRIO.


Second attempt:


    class procedure ClasseTeste.OnBeforePost(const HTTPReqResp: THTTPReqResp;
Data: Pointer);
var
SecurityFlags: DWord;
SecurityFlagsLen: DWord;
Request: HINTERNET;
begin
Request := Data;
if soIgnoreInvalidCerts in Rio.HTTPWebNode.InvokeOptions then
begin
SecurityFlagsLen := SizeOf(SecurityFlags);
InternetQueryOption(Request, INTERNET_OPTION_SECURITY_FLAGS,
Pointer(@SecurityFlags), SecurityFlagsLen);
SecurityFlags := SecurityFlags or INTERNET_FLAG_IGNORE_CERT_CN_INVALID;
InternetSetOption(Request, INTERNET_OPTION_SECURITY_FLAGS,
Pointer(@SecurityFlags), SecurityFlagsLen);
end;
end;

rio.HTTPWebNode.OnBeforePost:= ClasseTeste.OnBeforePost;

I can do this using c#, with the code below:


channel = new ChannelFactory<WsMain.IWsInterface>("****");
channel.Credentials.UserName.UserName = "*****";
channel.Credentials.UserName.Password = "*****";
channel.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None;


I need to consume a WCF, but it has a certificate and I need to disable its authentication. Does anyone know how can I do this in Delphi XE2?


I've already tried the codes below:


First attempt :


Rio.HTTPWebNode.InvokeOptions:= [soIgnoreInvalidCerts,soAutoCheckAccessPointViaUDDI];


Where Rio is a THTTPRIO.


Second attempt:


    class procedure ClasseTeste.OnBeforePost(const HTTPReqResp: THTTPReqResp;
Data: Pointer);
var
SecurityFlags: DWord;
SecurityFlagsLen: DWord;
Request: HINTERNET;
begin
Request := Data;
if soIgnoreInvalidCerts in Rio.HTTPWebNode.InvokeOptions then
begin
SecurityFlagsLen := SizeOf(SecurityFlags);
InternetQueryOption(Request, INTERNET_OPTION_SECURITY_FLAGS,
Pointer(@SecurityFlags), SecurityFlagsLen);
SecurityFlags := SecurityFlags or INTERNET_FLAG_IGNORE_CERT_CN_INVALID;
InternetSetOption(Request, INTERNET_OPTION_SECURITY_FLAGS,
Pointer(@SecurityFlags), SecurityFlagsLen);
end;
end;

rio.HTTPWebNode.OnBeforePost:= ClasseTeste.OnBeforePost;

I can do this using c#, with the code below:


channel = new ChannelFactory<WsMain.IWsInterface>("****");
channel.Credentials.UserName.UserName = "*****";
channel.Credentials.UserName.Password = "*****";
channel.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None;

0 commentaires:

Enregistrer un commentaire