Delphi: idHttp+SSL
Asked Answered
F

3

15

Explain me please how to download a file from a server using SSL (https://). I have not found an appropriate answer in the Internet.

Everybody says about TIdSSLIOHandlerSocket, but I have only TIdSSLIOHandlerSocketOpenSSL. I have an error 'could not load SSL library' if I use TIdSSLIOHandlerSocketOpenSSL. Some people say it needs a library, but the most even do not mention about it. Do I need to use libraries from here http://www.indyproject.org/sockets/SSL.EN.aspx ?

I have those DLLs in program's folder. According to: http://edn.embarcadero.com/article/31279 "At runtime, Indy attempts to load libeay32.dll and ssleay32.dll." I do not know from where Indy tries to load the DDLs -> I have an error: 'Could not load SSL library.'

procedure TForm1.FormCreate(Sender: TObject);
    var  UpdateMemoryStream:tmemorystream;
    begin
    try
    UpdateMemoryStream:=TMemoryStream.Create;
                try
                idhttp2.Get('https://example.com/list.rar',UpdateMemoryStream); //I have: Exception class EIdOSSLCouldNotLoadSSLLibrary with message 'Could not load SSL library.'
                except
                    on E : Exception do 
                    begin showmessage('Error: '+E.Message); 
                    end;
                end;
    UpdateMemoryStream.SaveToFile('d:\1.rar');
    finally
    UpdateMemoryStream.Free;
    end;
    end;

Why do I have this error? I have Delphi 2010.

Fetlock answered 13/7, 2011 at 17:36 Comment(1)
TIdSSLIOHandlerSocket is the class name in Indy 9. TIdSSLIOHandlerSocketOpenSSL is the new class name in Indy 10.Justis
A
9

To use Indy's OpenSSL class, you need ssleay32.dll and libeay32.dll. That probably should have been apparent from the source of the exception in the Indy code you tried to execute.

The libraries are linked to from the Indy page mentioned in the question. If you're legally allowed to do so, you can distribute them with your application. Put them wherever DLLs go (usually your application directory).

TIdSSLIOHandlerSocketOpenSSL is an OpenSSL-specific descendant of the abstract TIdSSLIOHandlerSocket class. If you were using some other SSL library instead of OpenSSL, you'd use a different descendant class.

Alliteration answered 13/7, 2011 at 18:12 Comment(8)
It is not important what and how to use. I need only to download a file using idHTTP+SSL.Can you provide an example of using? I would appreciate it. Thanks.Fetlock
@Fetlock The exception that was raised "could not load SSL library" is solved by using these DLL's.Axenic
I have them in program's folder! How to link them to TIdSSLIOHandlerSocketOpenSSL?Fetlock
You don't need to link the DLLs to the class. They are loaded automatically at runtime.Justis
You don't have to link them to anything. They're loaded automatically with plain old LoadLibrary when they're needed. Maxfax, you need to do some troubleshooting of your own. You're getting an exception, and you have the source code, so look at the code to discover what condition caused the exception to be raised. If the condition was a failed function call, then follow the code to that function and see what condition made it fail. Keep following it until you can't go any farther. Document your steps and recount them when you ask for help.Alliteration
Maxfax, you don't call LoadLibrary. I told you before that Indy calls it when it needs the DLL. It apparently doesn't get loaded properly, which is why you get an exception. When you get an exception, use the debugger to investigate what happened. The debugger will show you which line of code raised the exception. Read the code backward to find out why. If it's not immediately apparent, set breakpoints earlier in the code and re-run your code to see exactly how it reaches the exception point. If you want, go ahead an call LoadLibrary yourself, wherever you want, just to see if it works.Alliteration
Please see my code where the error rises. I have DLLs in program's folder. According to: edn.embarcadero.com/article/31279 "At runtime, Indy attempts to load libeay32.dll and ssleay32.dll." I do not know from where Indy tries to load the DDLsFetlock
Thanks guys! I have used win64 DLL, not win32 :)Fetlock
F
7

Download openssl-1.0.0d-i386-win32-rev2.zip , not openssl-1.0.0d-x64_86-win64-rev2.zip from http://indy.fulgan.com/SSL/

Read here too: https://forums.embarcadero.com/thread.jspa?threadID=15569

Fetlock answered 13/7, 2011 at 21:15 Comment(1)
Right. You're writing 32-bit programs, so you need 32-bit DLLs.Alliteration
M
3

It is essential to get the correct DLLs as some are compiled with links to M$ Studio and therefore do not work in Delphi. Try https://indy.fulgan.com/SSL/ Latest versions are at the bottom of the page.

Morelos answered 3/11, 2017 at 7:0 Comment(1)
These are dlls not work for me on delphi 7.Kennith

© 2022 - 2024 — McMap. All rights reserved.