indy - 在 Delphi 中关闭 SSL 证书验证
问题描述
我有一个使用 sTunnel 在 Windows Server 2012R2 上运行的 Web 服务。使用 Postman 时,我必须关闭 SSL 验证才能使其工作,否则我会收到:没有连接错误。
我的一些客户端使用我们的 Delphi Windows 应用程序得到错误 HTTP 1.1 500 和消息 Reject 由于策略限制。
sTunnel 日志中显示以下内容: SSL 例程:ssl3_read_bytes: sslv3 alert certificate unknow
我在 System32 文件夹中有最新的打开的 Ssl dll。
我不知道我是否可以在 Delphi 或 sTunnel 中打开/关闭某些东西。
这是发送 SMS 并将结果发送到我的网络服务器的代码。
procedure SendSMS.Execute;
var
JsonToSend: TStringStream;
url, SMSText, Rtext, AppId, Json: String;
IdHTTP1: TIdHTTP;
IdSSLIOHandlerSocketOpenSSL2: TIdSSLIOHandlerSocketOpenSSL;
jsonRecived: TJSONObject;
begin
AppId := 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx';
mySMSSent := False;
if (Length(DataM1.ComTbl.FieldByName('SMSToken').AsString) > 10) and (Length(SMSMessageText) > 3) then
begin
SMSText := StringReplace(SMSMessageText,#$A,'\n',[rfReplaceAll, rfIgnoreCase]);
SMSText := StringReplace(SMSText,#$D,'',[rfReplaceAll, rfIgnoreCase]);
Try
IdSSLIOHandlerSocketOpenSSL2 := TIdSSLIOHandlerSocketOpenSSL.Create;
IdHTTP1 := TIdHTTP.Create;
IdHTTP1.Request.UserAgent := 'Mozilla/3.0 (compatible; Indy Library)';
IdHTTP1.Request.ContentType := 'application/json';
IdHTTP1.Request.BasicAuthentication := true;
IdHTTP1.Request.Username := SMSPass;
IdHTTP1.Request.Password := SMSToken;
IdSSLIOHandlerSocketOpenSSL2.SSLOptions.Method := sslvTLSv1_2;
IdHTTP1.IOHandler := IdSSLIOHandlerSocketOpenSSL2;
IdHTTP1.HandleRedirects := False;
if Length(SMSMedia) > 5 then
Json := '{"from": "+1' + SMSPhone + '","to": "+1' + ToPhone + '","text": "' + SMSText + '","applicationId": "' + AppId + '","media": "' + SMSMedia + '","tag": "' + NameID + '"}'
else
Json := '{"from": "+1' + SMSPhone + '","to": "+1' + ToPhone + '","text": "' + SMSText + '","applicationId": "' + AppId + '","tag": "' + NameID + '"}';
url:='https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx?';
JsonToSend := TStringStream.Create(Json);
try
Rtext:=IdHTTP1.Post(url, JsonToSend);
except
on E:Exception do
begin
SMSText := E.Classname + ': ' + E.Message;
mySMSSent := True;
end;
end;
if Pos('owner',Rtext) > 0 then // Send to web service //
begin
jsonRecived := TJSONObject.create(rtext);
if jsonRecived <> nil then
begin
Json := '{"id": "';
Json := Json + jsonRecived.optString('id') + '","from": "+1';
Json := Json + SMSPhone + '","time": "';
Json := Json + jsonRecived.optString('time') + '","direction": "';
Json := Json + jsonRecived.optString('direction') + '","text": "';
Json := Json + SMSText + '","to": "+1' + ToPhone + '"}';
Try
if Assigned(JsonToSend) then
FreeAndNil(JsonToSend);
JsonToSend := TStringStream.Create(Json);
url:='https://mywebservice';
IdHTTP1.Post(url, JsonToSend);
Except
End;
end;
end;
Finally
IdHTTP1.Disconnect;
IdSSLIOHandlerSocketOpenSSL2.Free;
IdHTTP1.Free;
JsonToSend.Free;
End;
end;
end;
解决方案
推荐阅读
- python - 在while循环中同时给出1000个答案
- c - FTDI。需要了解有关 FT_Write() 函数的更多详细信息
- asp.net - 使用 XSLT 将 XML 节点组合成单个节点
- java - 使用 ResultSet 的子集填充 RowSet
- go - 如何在 Go 中检测操作系统版本
- list - Power Query检查字符串是否包含列表中的字符串
- postgresql - 是否可以执行需要在 Postgres 中过滤的 upsert?
- sonarqube - 如何在项目级别使用 UI 排除代码覆盖率?
- bluetooth - 如何在 Mac App 处于非活动状态时捕获蓝牙控制器?
- java - 我应该担心我的网站性能,因为 tomcat 9 没有使用阻塞 io