希望有人可以为我提供一个支持 SSL的简单TIdHttpServer示例。使用 Delphi2007 和 Indy10。我有以下内容来创建/设置服务器和 ioHandler:
ServerIOHandler := TIdServerIOHandlerSSLOpenSSL.Create(self);
ServerIOHandler.SSLOptions.CertFile := 'mycert.pem';
ServerIOHandler.SSLOptions.KeyFile := 'mycert.pem';
ServerIOHandler.SSLOptions.RootCertFile := 'mycert.pem';
ServerIOHandler.SSLOptions.Method := sslvSSLv23;
ServerIOHandler.SSLOptions.Mode := sslmServer;
ServerIOHandler.SSLOptions.VerifyDepth := 1;
ServerIOHandler.SSLOptions.VerifyMode := [sslvrfPeer,sslvrfFailIfNoPeerCert,sslvrfClientOnce];
IdHTTPServer1 := TIdHTTPServer.Create;
IdHTTPServer1.AutoStartSession := True;
IdHTTPServer1.SessionState := True;
IdHTTPServer1.OnCommandGet := IdHTTPServer1CommandGet;
idHttpServer1.ParseParams := True;
idHttpServer1.DefaultPort := 80;
idHttpServer1.IOHandler := ServerIOHandler;
IdHTTPServer1.Active := True;
mycert.pem是使用 openssl 和以下命令创建的:
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem
我马上认为有问题,因为我对CertFile, KeyFile, RootCertFile使用相同的文件。
我为提示输入了空格,但通用名称除外。我确定设置为我正在使用的域名(假设它是myexample.com)。
在浏览器中,如果我点击http://myexample.com会导致异常:Error accepting connection with SSL。点击https://myexample.com永远不会进入我的代码。
1 月 30 日注意 - 我使用 sslbuddy 生成密钥。这仍然没有奏效。然后我注释掉了以下几行,它起作用了:
ServerIOHandler.SSLOptions.VerifyDepth := 1;
ServerIOHandler.SSLOptions.VerifyMode := [sslvrfPeer,sslvrfFailIfNoPeerCert,sslvrfClientOnce];