简体   繁体   English

Delphi 6和Indy SSL连接不起作用

[英]Delphi 6 and Indy SSL connection not working

I need to consume a Web Service via SSL. 我需要通过SSL使用Web服务。 In order to accomplish that I have built a web client in Delphi 6 that uses Indy to read the client certificates and write the soap request via https. 为了实现这一点,我在Delphi 6中构建了一个Web客户端,该客户端使用Indy读取客户端证书并通过https编写soap请求。 The compilated version of the code is a DLL that runs in IIS 5.0. 该代码的编译版本是在IIS 5.0中运行的DLL。 After tested the code in my local machine it works fine (I'm behind a proxy). 在本地计算机上测试代码后,它可以正常工作(我在代理后面)。 But after the code is deployed to prod servers (not proxy) the SSL connection fails saying "Error connecting with SSL". 但是,将代码部署到产品服务器(而非代理)后,SSL连接失败,提示“连接SSL出错”。

Here is my code: 这是我的代码:

var
  Response: TStringStream;
  IdHttp: TIdHTTP;
  IdCnxSLL: TIdConnectionInterceptOpenSSL;
  XmlSoapDoc: IXMLDocument;
begin
  Response := TStringStream.Create('');
  IdHttp := TIdHTTP.Create(nil);
  IdCnxSLL := TIdConnectionInterceptOpenSSL.Create(nil);
  XmlSoapDoc := TXMLDocument.Create(nil);
  with IdCnxSLL do
   begin
    IdCnxSLL.SSLOptions.Method := sslvSSLv23;
    IdCnxSLL.SSLOptions.RootCertFile := IniHttpConnectionData.Values['RootCertFile'];
    IdCnxSLL.SSLOptions.CertFile := IniHttpConnectionData.Values['CertFile'];
    IdCnxSLL.SSLOptions.KeyFile := IniHttpConnectionData.Values['KeyFile'];
    IdCnxSLL.OnGetPassword :=  IdConInterceptOpenSSLGetPassword;
  end;
  with IdHttp do
  begin
    if bUseProxy then
    begin
       Request.ProxyServer := IniHttpConnectionData.Values['ProxyServer'];
       Request.ProxyPort := StrToIntDef(IniHttpConnectionData.Values['ProxyPort'], 0);
    end
    else
    begin
       Host := IniHttpConnectionData.Values['HTTPHost'];
       Port := StrToIntDef(IniHttpConnectionData.Values['HTTPPort'], 443);
    end;
    Request.ContentType := 'text/xml';
    Intercept := IdCnxSLL;
    InterceptEnabled := True;
  end;

  try
    IdHttp.Post(ServiceURL, SoapEnv, Response);
  except
    on E:EIdOSSLConnectError do
       LogError('SSL Connect Error: ' + E.Message);
    on E:Exception do
      LogError('Error' + E.ClassName + ' - ' + E.Message);
  end;

I also try this code compiling into an exe program and it works. 我也尝试将此代码编译为exe程序,并且可以正常工作。 Is there something else I need to configure/add? 我还需要配置/添加其他内容吗?

Thanks. 谢谢。

The fact that you are using TIdConnectionInterceptOpenSSL tells me that you are using a VERY old version of Indy. 您正在使用TIdConnectionInterceptOpenSSL的事实告诉我您正在使用非常旧的Indy版本。 I am guessing Indy 8, which shipped with D6. 我猜是D6随附的Indy 8。 Indy 8 and earlier are no longer officially supported by the Indy development team (which I am a member of). Indy 8及更早版本不再由Indy开发团队(我是其成员)正式支持。 You really should upgrade to Indy 9, if not to Indy 10. In Indy 9, TIdConnectionInterceptOpenSSL was replaced with a new TIdSSLIOHandlerSocket component. 您确实应该升级到Indy 9,如果没有升级到Indy 10,则在Indy 9中,TIdConnectionInterceptOpenSSL被替换为新的TIdSSLIOHandlerSocket组件。 Also, Indy 9 and earlier required custom-made OpenSSL DLLs, which may be contributing to your error as well, if you are using the wrong DLLs for your version of Indy. 另外,Indy 9和更早版本需要定制的OpenSSL DLL,如果您为Indy版本使用了错误的DLL,这也可能导致您的错误。 Indy 10, on the other hand, uses the standard DLLs from OpenSSL's website now. 另一方面,Indy 10现在使用OpenSSL网站上的标准DLL。

Finnally It worked. 最后,它奏效了。 Although I strongly encourage you to use a newer version of Indy as Remy suggests. 尽管我极力鼓励您使用Remy建议的较新版本的Indy。 I will post the steps that did the trick for me since there should be other people with the same problem. 我将发布对我有用的步骤,因为应该有其他人遇到相同的问题。

The original code I posted is functional, it works when we need to post information via secured http (https) but the remote server requires prior authentification using a client certificate. 我发布的原始代码是有效的,当我们需要通过安全的http(https)发布信息但远程服务器需要使用客户端证书进行预先身份验证时,它可以工作。

In order to make it work, it is necessary to verify the following: 为了使其正常工作,必须验证以下内容:

  1. TIdHttp and TIdConnectionInterceptOpenSSL configuration TIdHttp和TIdConnectionInterceptOpenSSL配置
  2. Certificates 证明书

For the first 2 steps follow the steps mentioned here link text or (in case link is expired) Google "IndySSL - using certificate authentication". 对于前两个步骤,请遵循此处提到的步骤, 链接文本或(如果链接已过期)Google“ IndySSL-使用证书身份验证”。 It worked for me. 它为我工作。

  1. Indy SSL DLLs. Indy SSL DLL。 (For D6/Indy 8 download indy_openssl096g.zip from Indy SSL or Intelicom ) This DLLs where the only ones that worked for this version of Indy. (对于来自D6 /印8下载indy_openssl096g.zip 印SSLIntelicom )这个DLL文件,其中只有这个版本印的工作的人。

Hope this will help. 希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM