使用 Delphi 10.4 编译我的 win32 客户端/服务器应用程序(使用 INDY 和 TMS Sparkle)后,出现 ssl 错误。我在服务器端使用 Indy 并使用自签名证书,在客户端使用 Indy。错误消息是(翻译自德语):
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;
Run Code Online (Sandbox Code Playgroud)
Emba 在 10.3 中成功打破了 Indy,也许这是另一个类似的案例?
这要归功于 Remy Lebau,他为我指明了正确的方向。但我想通过提供使其在 Delphi 10.4 中再次工作的代码来回答我的问题。由于 Indy 的更改是在 2018 年完成的(!),我仍然不知道为什么它在 10.3 中完美运行,直到升级到 10.4。
由于我直接在服务/守护程序项目中使用 TMS Sparke Server for Indy,因此我提供了一个小类来连接需要对象方法的 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;
...
Run Code Online (Sandbox Code Playgroud)
现在它像以前一样工作。
| 归档时间: |
|
| 查看次数: |
2878 次 |
| 最近记录: |