gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 22:36:25 25 4
gpt4 key购买 nike

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

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

我没有更改 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 中完美运行。

由于我在服务/守护程序项目中直接使用 Indy 的 TMS Sparke 服务器,所以我提供了一个小类来连接需要对象方法的 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;
...

现在它像以前一样工作。

关于迁移到 10.4 Sydney 后出现 Delphi Indy SSL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62068537/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com