Delphi 迁移到 10.4 Sydney 后出现 Indy SSL 错误

Delphi Indy SSL Error after migrating to 10.4 Sydney

在使用 Delphi 10.4 编译我的 win32 client/server 应用程序(使用 INDY 和 TMS Sparkle)后,我收到一个 ssl 错误。我在服务器端使用 Indy 和自签名证书,在客户端使用 Indy。错误信息是 (t运行slated from german):

与 SSL 的连接错误。 EOF 遇到违反协议的情况。

我没有从 10.3 完美地更改任何代码或环境 运行。我可以将其分解为服务器端,因为旧服务器(在 10.3 中编译)与新客户端(在 10.4 中编译)一起运行,但旧客户端在尝试连接到新服务器时也会中断。

这是我初始化 SSL 的方式:

    SecureServer := TIndySparkleHTTPServer.create(nil);
    SecureServer.DefaultPort := SecurePort;
    // Initialize SSL with self signed certificate
    SSLHandler := TIdServerIOHandlerSSLOpenSSL.create(SecureServer);
    SSLHandler.SSLOptions.CertFile := SharedVals.ServerPath + 'appcert.pem';
    SSLHandler.SSLOptions.RootCertFile := SharedVals.ServerPath + 'approot.pem';
    SSLHandler.SSLOptions.KeyFile := SharedVals.ServerPath + 'appkey.pem';
    SSLHandler.SSLOptions.Method := sslvSSLv23;
    SecureServer.IOHandler := SSLHandler;

Emba 在 10.3 中成功打破了 Indy,也许这是另一个类似的案例?

归功于 Remy Lebau,他为我指明了正确的方向。但我想通过提供使其在 Delphi 10.4 中再次运行的代码来回答我的问题。由于 Indy 的更改已于 2018 年完成(!),我仍然不知道为什么它在升级到 10.4 之前在 10.3 中完美运行。

因为我在 service/daemon 项目中直接使用 Indy 的 TMS Sparke 服务器,所以我提供了一个小 class 来连接需要对象方法的 OnQuerySSLPort 方法。

type
  TSSLHelper = class
  // This helper class is neccessary to set ssl true
  // as it defaults to false on non standard ssl ports
    procedure QuerySSLPort(APort: Word; var VUseSSL: boolean);
  end;

...

procedure TSSLHelper.QuerySSLPort(APort: Word; var VUseSSL: boolean);
begin
  VUseSSL := true;
end;

...

SecureServer := TIndySparkleHTTPServer.create(nil);
SecureServer.DefaultPort := SecurePort;
// Initialize SSL with self signed certificate
SSLHandler := TIdServerIOHandlerSSLOpenSSL.create(SecureServer);
SSLHandler.SSLOptions.CertFile := SharedVals.ServerPath + 'appcert.pem';
SSLHandler.SSLOptions.RootCertFile := SharedVals.ServerPath + 'approot.pem';
SSLHandler.SSLOptions.KeyFile := SharedVals.ServerPath + 'appkey.pem';
SSLHandler.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];
SecureServer.IOHandler := SSLHandler;
SSLHelper := TSSLHelper.Create;
SecureServer.OnQuerySSLPort := SSLHelper.QuerySSLPort;
...

现在它像以前一样工作了。