Re: TcpIPServer and SSL

Giganews Newsgroups
Subject: Re: TcpIPServer and SSL
Posted by:  Ioan Ghip (delphi…@hotmail.com)
Date: Thu, 26 May 2005

Mustafa Shabib wrote:
> Hello All,
>
> I've written my client side component in C++ and it is cross platform;
> this is due to our client's requirements. I use OpenSSL for SSL security
> on the client side and, via some tests, have been able to make encrypted
> connections to https websites, etc so I believe it to be working. The
> server is written using Indy.net and this is where I need help... can
> anyone post a tutorial or some kind of step-by-step on how to set up a
> TCP/IP server with SSL via Indy.net?
>
> Thank you in advance and I await your response.
>
> Mustafa

Hi Mustafa,
I don't use indy.net but here it's how I do it in indy.9 :-)

when I create the server:

    Server := TIDTCPServer.create(nil);
    ThreadMgr := TIdThreadMgrDefault.Create(nil);
    {Set Indy TCP server Properties}
    Server.ThreadMgr := ThreadMgr;

    Server.OnExecute := OnExecute;
    Server.OnConnect := OnConnect;
    Server.OnDisconnect := OnDisconnect;
    Server.TerminateWaitTime := 5000;
    Server.DefaultPort := DEFAULT_FAX_SERVER_PORT;
    {SSL Stuff begin}
    SSL := TIdServerIOHandlerSSL.Create(nil);
    SSLPassword := GlobalVar.SSLPassword;
    with SSL do
    begin
      SSLOptions.Method := sslvSSLv23;
      SSLOptions.RootCertFile := GlobalVar.RootCertFile;
      SSLOptions.CertFile := GlobalVar.CertFile;
      SSLOptions.KeyFile := GlobalVar.KeyFile;
      OnGetPassword := SSLOnGetPassword; <--- see below
    end;
    Server.IOHandler := SSL;

procedure TFaxTCPServer.SSLOnGetPassword(var Password: string);
begin
  Password := SSLPassword;
end;

and the client:

    ReadTimeout := avglobal.GlobalVar.ReadFromConnectionTimeOut;
    Client.Port := DEFAULT_FAX_SERVER_PORT;
    Client.Host := GlobalVar.LocalIP
    {SSL begin}
    SSL := TIdSSLIOHandlerSocket.Create(nil);
    with SSL.SSLOptions do
    begin
      Method := sslvSSLv23;
      Mode := sslmClient;
    end;
    Client.IOHandler := SSL;

of course, you need the ssl dlls.
libeay32.dll and ssleay32.dll

-ioan

Replies

In response to

TcpIPServer and SSL posted by Mustafa Shabib on Fri, 20 May 2005