Delphi 6 和 Indy SSL 连接无法正常工作

发布于 2024-08-04 21:43:56 字数 1715 浏览 1 评论 0原文

我需要通过 SSL 使用 Web 服务。为了实现这一目标,我在 Delphi 6 中构建了一个 Web 客户端,它使用 Indy 读取客户端证书并通过 https 写入肥皂请求。代码的编译版本是在 IIS 5.0 中运行的 DLL。在我的本地计算机中测试代码后,它工作正常(我在代理后面)。但是,将代码部署到产品服务器(而非代理)后,SSL 连接失败,并显示“使用 SSL 连接时出错”。

这是我的代码:

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;

我还尝试将此代码编译成 exe 程序,它可以工作。我还需要配置/添加其他内容吗?

谢谢。

I need to consume a Web Service via SSL. 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. The compilated version of the code is a DLL that runs in IIS 5.0. 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".

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. Is there something else I need to configure/add?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

做个少女永远怀春 2024-08-11 21:43:56

您使用 TIdConnectionInterceptOpenSSL 的事实告诉我您正在使用非常旧版本的 Indy。我猜测 Indy 8 是随 D6 一起提供的。 Indy 8 及更早版本不再受到 Indy 开发团队(我是该团队的成员)的正式支持。如果不是 Indy 10,您确实应该升级到 Indy 9。在 Indy 9 中,TIdConnectionInterceptOpenSSL 被新的 TIdSSLIOHandlerSocket 组件替换。此外,Indy 9 及更早版本需要定制 OpenSSL DLL,如果您为您的 Indy 版本使用了错误的 DLL,这也可能会导致您的错误。另一方面,Indy 10 现在使用 OpenSSL 网站上的标准 DLL。

The fact that you are using TIdConnectionInterceptOpenSSL tells me that you are using a VERY old version of Indy. I am guessing Indy 8, which shipped with D6. Indy 8 and earlier are no longer officially supported by the Indy development team (which I am a member of). You really should upgrade to Indy 9, if not to Indy 10. In Indy 9, TIdConnectionInterceptOpenSSL was replaced with a new TIdSSLIOHandlerSocket component. 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 10, on the other hand, uses the standard DLLs from OpenSSL's website now.

み零 2024-08-11 21:43:56

终于成功了。尽管我强烈建议您按照雷米的建议使用较新版本的 Indy。我将发布对我有用的步骤,因为应该有其他人遇到同样的问题。

我发布的原始代码是有效的,当我们需要通过安全的 http (https) 发布信息但远程服务器需要使用客户端证书进行事先身份验证时,它可以工作。

为了使其工作,需要验证以下内容:

  1. TIdHttp 和 TIdConnectionInterceptOpenSSL 配置
  2. 证书

对于前 2 个步骤,请按照此处提到的步骤 链接文本 或(如果链接已过期)Google“IndySSL - 使用证书身份验证”。这对我有用。

  1. Indy SSL DLL。 (对于 D6/Indy 8,请从 Indy SSL 下载 indy_openssl096g.zip 或 Intelicom) 这个 DLL 是唯一可以工作的对于这个版本的印地。

希望这会有所帮助。

Finnally It worked. Although I strongly encourage you to use a newer version of Indy as Remy suggests. 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.

In order to make it work, it is necessary to verify the following:

  1. TIdHttp and TIdConnectionInterceptOpenSSL configuration
  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". It worked for me.

  1. Indy SSL DLLs. (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.

Hope this will help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文