首页 > 解决方案 > 在 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;

标签: indydelphi-2007delphi-xe6stunnel

解决方案


推荐阅读