Delphi 6 和 Indy SSL 连接不工作

标签 delphi ssl indy

我需要通过 SSL 使用 Web 服务。为了实现这一点,我在 Delphi 6 中构建了一个 Web 客户端,它使用 Indy 读取客户端证书并通过 https 编写 soap 请求。代码的编译版本是在 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 程序并且它可以工作。我还需要配置/添加其他东西吗?

谢谢。

最佳答案

您使用 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。

关于Delphi 6 和 Indy SSL 连接不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1422586/

相关文章:

google-chrome - 浏览器是否支持证书透明度?

web-services - 使用 TidHTTPServer 以安全的方式处理 GET 请求

delphi - 使用 Delphi-7 的 Indy10 无法下载某些 SSL 页面,即使使用 2019 年 5 月的 DLL

image - 使用 firebird 从 delphi 中的 blob 字段加载和保存图像

c# - 适用于 .NET 或 Delphi 的 ODETTE FTP (OFTP)

delphi - VerQueryValue 在中文操作系统中不返回版权符号?

php - 如何禁用 fsockopen 中的 ssl 检查? (PHP 5.6)

Google App Engine(Java) 上的安全性 - Servlet SSL?

ios - iOS 的 FIONBIO 值是多少,以阻止/取消阻止套接字?

delphi - 如何将 TDBGrid 记录 View 恢复到刷新之前的状态?