🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.web
Article #715

Re: SSL and Indy

#715
From: Lesley Anne
Date: Tue, 24 Oct 2006 19:34
120 lines
6302 bytes
Remy Lebeau (TeamB) wrote:
> Lesley Anne wrote:
>
> > Does anyone have an example of how to add SSL when using IdHTTP->Post?
>
> This has been asked and answered many times before.  Please search
> through the Borland newsgroup archives at http://www.deja.com, and
> also browse through the old messages on the news.atozed.com server.

I've spent a full day reading through lots of messages, and the only useful 
thing I've found is where to download the necessary library files from. 
There have been many mentions of SSL in Indy, sometimes using Intercepts and 
sometimes using IO Handlers.  (I did find a couple messages that mentioned 
Intercepts being the older version, so I think the choice to use the IO 
Handler is correct.)  Of those using the TIdSSLIOHandlerSocket and who even 
mention any of its properties (which most of the messages don't), there's 
apparently some people who just set things like Method and Mode, while other 
people set the various certificate and key files, but I didn't find any 
messages that indicated when one approach or the other is needed.  Nor could 
I find any explanations of what the different options are (beyond just their 
names).  Similarly, some examples set handlers for events such as 
OnGetPassword and OnVerifyPeer, while others didn't.  (And none of the 
examples I found showed what was actually done in those event handlers, 
making it harder to determine whether they were necessary.  I still don't 
know what they're supposed to be for).  I've seen a lot of responses that 
end with "and configure it as needed", but none that provide any clues for 
how to determine what's needed.

In the Indy Knowledge Base, the topic "I need SSL help, where can I find 
answers?" just gives a single line directing the reader to a page that 
doesn't exist (404).  The demos for Indy 9 don't include any projects that 
use SSL.  The help file doesn't contain descriptions on /any/ of the 
TIdSSLIOHandlerSocket members (and even the root TIdSSLIOHandlerSocket page 
of the help file has only two sentences of description).

Questions on this may have been asked many times before, but answers are a 
lot harder to come by.

> > Indy has two SSL components: TIdServerIOHandlerSSL and
> > TIdSSLIOHandlerSocket.  I'm assuming that since I'm on the client
> > side of the connection that I would just use TIdSSLIOHandlerSocket.
> > Is that right?
>
> Yes.
>
> > And then sometime before the call to Post() I would set:
> >    IdHTTP1->IOHandler = IdSSLIOHandlerSocket1;
>
> Yes.
>
> > what functions (if any) do I need to call?
>
> There are no function calls needed.

What about properties or events?  Are any of them needed?  I still haven't 
figured out what any of them really mean.  The machine must have whatever 
certificates and keys any Windows machine normally has, but how do I tell 
the IOHandler that?  And do I need to tell it that, or does it pick those up 
by default, or does it even need them on the client side?  (We're using SSL 
for its encryption rather than its authentication capabilities, but I don't 
know how much those can be separated.)

The following is all I have so far for posting to the server:


// XMLQuery and HTTPAddress are thread-global input variables.
// XMLResponse and Success  are thread-global output variables
// ReturnResult() is a thread function for responding to the main thread
// ------------------------------------------------------------------------
void __fastcall TUDPPostThread::Execute()
{
   TStringList           *RequestData  = new TStringList;
   TStringStream         *Output       = new TStringStream("");
   TIdHTTP               *IdHTTP1      = new TIdHTTP(NULL);
   TIdSSLIOHandlerSocket *SSLIOHandler = new TIdSSLIOHandlerSocket(NULL);

   Success = true;

   SSLIOHandler->SSLOptions->Method = sslvSSLv23;
   SSLIOHandler->SSLOptions->Mode = sslmClient;
   SSLIOHandler->SSLOptions->VerifyDepth = 0;
   IdHTTP1->IOHandler = SSLIOHandler;
   IdHTTP1->ProtocolVersion = pv1_0;
   IdHTTP1->Request->Accept = "text/html, */*";
   IdHTTP1->Request->ContentLength = 0;
   IdHTTP1->Request->ContentRangeEnd = 0;
   IdHTTP1->Request->ContentRangeStart = 0;
   IdHTTP1->Request->ContentType = "application/x-www-form-urlencoded";
   IdHTTP1->Request->UserAgent = "Mozilla/3.0 (compatible; Indy Library)";

   RequestData->Add(XMLQuery);

   try {
      IdHTTP1->Post(HTTPAddress, RequestData, Output);
   } catch (EIdHTTPProtocolException &E) {
      Success = false;
      XMLResponse = "EIdHTTPProtocolException: " + E.ErrorMessage;
   } catch (EIdException &E) {
      Success = false;
      XMLResponse = "EIdException: " + E.Message;
   }

   if (Success)
        XMLResponse = Output->DataString;

   Synchronize(ReturnResult);

   delete RequestData;
   delete Output;
   delete IdHTTP1;
   delete SSLIOHandler;
}
// ------------------------------------------------------------------------


Even the few properties I did set here involved some guesswork, and I don't 
know whether I guessed correctly.  For instance, several of the code 
snippets I've seen in other messages set Mode to sslmUnassigned, but I set 
mine to sslmClient simply because I couldn't think of what "unassigned" 
could mean here.  Which is the right one to use?
Technical Details
Message-ID: <453e6ae5$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <453d224b$1@newsgroups.borland.com> <453d24d2$3@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,f658a3cbb24f5b31
X-Google-Attributes: gidfeeec,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Lesley Anne" <mspfila-ng@yahoo.com>
Newsgroups: borland.public.cppbuilder.internet.web
References: <453d224b$1@newsgroups.borland.com> <453d24d2$3@newsgroups.borland.com>
Subject: Re: SSL and Indy
Date: Tue, 24 Oct 2006 15:34:58 -0400
Lines: 122
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2869
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2962
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 144.160.5.25
Message-ID: <453e6ae5$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1161718501 144.160.5.25 (24 Oct 2006 12:35:01 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail