1 (edited by mr_d 2019-10-01 17:40:48)

Topic: Problem With SSL When Using HTTPGetFile Function

Hi Dmitri and MVD users,


I've run into a problem that I hope someone can help to resolve.
I am using the HTTPGetFile() function to try to download a file from a website.
I have added the latest OpenSSL DLL file to my application folder as required to connect to an HTTPS URL, but I am getting the following error message:


Error conecting with SSL
error:1408F10B:SSL
routines:SSL3_GET_RECORD:wrong version number


From searching on the web, it seems that this is caused by the client not using the correct version of SSL as the server, and the suggested solution is apparently to set the correct version manually by setting the relevant properties of the library to:


SSLOptions.Method := sslvSSLv3;
SSLOptions.SSLVersions := [sslvSSLv3];


However, this assumes that we are directly using the relevant libraries/objects in the DLL files from our code, but in this case I am using the provided function which I assume wraps the protocol version stuff already which doesn't seem to be able to be changed manually.


How can I overcome or work around this problem?



EDIT: I have just double checked the site info and found that apparently the encryption being used is stated as:
(TLS_AES_128_GCM_SHA256, 128 bit keys, TLS 1.3).
So it may be that it is reversed of what I have above in that MVD is using SSLv3, but the site does not support this so I may have to use TLS instead somehow, Not sure if this helps or makes the problem more confusing...
Again, any help would be great.  Cheers.

Dennis

Re: Problem With SSL When Using HTTPGetFile Function

я использую эту библиотеку SSL ...
поместите файлы в папку вашего проекта..

Post's attachments

Attachment icon libssl.7z 477.74 kb, 380 downloads since 2019-10-01 

3 (edited by mr_d 2019-10-01 18:32:53)

Re: Problem With SSL When Using HTTPGetFile Function

Thanks for the suggestion, but it didn't fix the problem (although a different error is now displayed - please refer to attached pic of error).


I noticed that your library files are from 2008; this looks to be a bit old and there have been many issues with SSL that have been identified and fixed since then, so I would sugget that you use a newer version.
I have been using the OpenSSL version 1.0.2o with success previous to my latest problem and have tried 1.0.2t as well to see if that improved matters (...it didn't).

Post's attachments

Attachment icon pic.png 9.01 kb, 164 downloads since 2019-10-01 

Dennis

Re: Problem With SSL When Using HTTPGetFile Function

Вы используете proxy ?

The https:// is wrong, it should be http://. The proxy itself should be accessed by HTTP and not HTTPS even though the target URL is HTTPS. The proxy will nevertheless properly handle HTTPS connection and keep the end-to-end encryption.

Re: Problem With SSL When Using HTTPGetFile Function

I'm not using a proxy per se, but I am using a VPN service.
I have tried just now with just HTTP instead of HTTPS to check, but am still getting the exact same error message so this wasn't the cause of the problem.

Thanks for giving me more ideas to try out though; if you have any more, please keep them coming smile

Dennis

Re: Problem With SSL When Using HTTPGetFile Function

попробуйте скачать файл с моего адреса

https://service-vv.ru/demo_php.zip

У меня работает..

7 (edited by mr_d 2019-10-02 07:20:37)

Re: Problem With SSL When Using HTTPGetFile Function

Yep. This works for me as well. I think that the difference may be that your site does not have a certificate installed, so even though it says it is using https, there is not the same level of validation as there would be for a certified site (one that has the green padlock) - this is just my guess as there is no problem with downloading the sample file you put up.

EDIT: or maybe not...I just checked with the following, and that worked as well:
https://www.google.com/images/branding/ … 2x92dp.png
maybe it's just the other site I'm trying to get the file from that has this problem...

Dennis

Re: Problem With SSL When Using HTTPGetFile Function

возможно проблема в уровне безопастности на Вашем VPN

Re: Problem With SSL When Using HTTPGetFile Function

maybe, but this shouldn't be as the test with google file worked.

Anyway, I have used an alternate method to download the files from the site (spawning wget from MVD with OpenFile), so I am sort of happy enough for now.

Thanks for your time in trying to help with this. Cheers.

Dennis

Re: Problem With SSL When Using HTTPGetFile Function

mr_d wrote:

maybe, but this shouldn't be as the test with google file worked.

Anyway, I have used an alternate method to download the files from the site (spawning wget from MVD with OpenFile), so I am sort of happy enough for now.

Thanks for your time in trying to help with this. Cheers.

Please provide the link which you use, I'll test it.

Dmitry.

11 (edited by mr_d 2019-10-11 10:04:58)

Re: Problem With SSL When Using HTTPGetFile Function

Hi Dimitry,
Hope you've seen my PM to you about the above problem. Any luck in finding the problem and a suitable solution or work around?

Anyway, while working more with the HTTPGetFile() function, I've run into another issue that I hope you can help me solve.
The problem is that no matter what value I use for the EnableException parameter, whenever this is used to try to get a file that does not exist, it results in a pop-up window to be displayed with an error message (please see attached pic). This is very anoying and impacts the running of a program that will try to download multiple files (both those that exist and those that don't).
Here is some example code for you to use to see the problem for yourself:

begin
    ShowMessage('First Test');
    try
        HTTPGetFile('https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', ExtractFilePath(Application.ExeName) + 'test.png', False); // Default EnableException value
        HTTPGetFile('https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', ExtractFilePath(Application.ExeName) + 'test.png', True); // EnableException value set to True
    except
        ShowMessage('With file that exists, this pop-up is not displayed as expected and wanted');
    end;

    ShowMessage('Second Test');
    try
        HTTPGetFile('https://www.google.com/file/that/does/not/exist/example.txt', ExtractFilePath(Application.ExeName) + 'test.txt', False); // Default EnableException value
        HTTPGetFile('https://www.google.com/file/that/does/not/exist/example.txt', ExtractFilePath(Application.ExeName) + 'test.txt', True); // EnableException value set to True
    except
        ShowMessage('This should be the only pop-up window to be shown');
    end;
end.

Note: you need to have the SSL library files in the same directory for the above to work.


Can you please look into this as a higher priority than my last raised problem?
Cheers, D.

EDIT: Been looking furthe\r into this and my new tests seem to work better and sort of more expected to wnat I want, so please stop looking into this for now unless you want to sort out the pop-up anyway (which I don't think should show up either way without explicitly telling it to). Thanks.

Post's attachments

Attachment icon pic.png 5.49 kb, 149 downloads since 2019-10-11 

Dennis

Re: Problem With SSL When Using HTTPGetFile Function

May be I can't understand you correctly, but the pop-up window don't show if you set second parameter to True


Here you will see only ShowMessage, if exception will be raised.

    try
        HTTPGetFile('https://www.google.com/file/that/does/not/exist/example.txt', ExtractFilePath(Application.ExeName) + 'test.txt', True); // EnableException value set to True
    except
        ShowMessage('This should be the only pop-up window to be shown');
    end;
Dmitry.

Re: Problem With SSL When Using HTTPGetFile Function

Hi. Yes, the pop-up doesn't show up if the second parameter is set to True which will handle the File Not Found as an exception and be handles in the except block of the try statement; this is ok (but not optimal as it shouldn't really be an exception, but rather a valid failure condition - that was why I thought you would have this be a actual function that is supposed to return a boolean result).
What is the use of this result if it is handled by the exception handling method?
Here is some more code to check out:

    ShowMessage('Test5 - Try..Except - EnableException=False');
    try
        bResult := HTTPGetFile('https://www.google.com/file/that/does/not/exist/example.txt', ExtractFilePath(Application.ExeName) + 'test.txt', False); // Default EnableException value
        // HTTP1.1/404 Not Found Error Message Popup Is Shown
    finally
        ShowMessage('Test5 - Message Popup'); // With file that does not exist, this pop-up is shown as unexpected and not wanted, instead this should be a False result of the function call.
    end;
 {
    ShowMessage('Test6 - Try..Except - EnableException=True');
    try
        bResult := HTTPGetFile('https://www.google.com/file/that/does/not/exist/example.txt', ExtractFilePath(Application.ExeName) + 'test.txt', True); // EnableException value set to True
        // Exception Error Message Popup Is Shown & Program Crashes
    finally
        ShowMessage('Test6 - Message Popup'); // With file that does not exist, this pop-up is not displayed as expected and wanted as this raises an exception that crashes the program if not handled.
    end;
 }

Does this make sense, or have I completely got this totally fuzzed up?

Dennis

Re: Problem With SSL When Using HTTPGetFile Function

Please download latest beta version
https://www.dropbox.com/s/6n60thhfaszoj … a.zip?dl=0


Message will no longer show if second parameter = False

Dmitry.

15 (edited by mr_d 2019-10-11 12:46:33)

Re: Problem With SSL When Using HTTPGetFile Function

Thanks Dimiry.
I won't be able to test this to test, as I only install final versions to my PC. But I have confidence that you have fixed this as stated. Thanks.
On a side note, have you had a chance to look into the first problem I raised initially with HTTPGetFile in this thread?
Please check it out for a bit to see if there is any solution or if you have any ideas. Cheers. D.

Dennis

Re: Problem With SSL When Using HTTPGetFile Function

About the first problem, unfortunately I can't solve this problem now, because I must update some components in MVD to fix it.

Dmitry.

17

Re: Problem With SSL When Using HTTPGetFile Function

anyone with a solution here ?

I have the same problem but non of the files in this thread work



thx !

Re: Problem With SSL When Using HTTPGetFile Function

OLE + WinHttpRequest

19

Re: Problem With SSL When Using HTTPGetFile Function

vovka3003 wrote:

OLE + WinHttpRequest


thank you for that very short answer but I don't understand


here is my code:



procedure Form1_Button1_OnClick (Sender: TObject; var Cancel: boolean);
var
    res: String;
    ts : Array of String;
begin
    res := HTTPGet('**********.org/ninfo.htm', True);
    ts := SplitString(res, '|');
    if (length(ts) = 3) then begin
        Form2.ver.Text := ts[0];
        Form2.msg.Text := ts[2];
    end else
        errorMsg('Invalid Data!!!');
end;


and here is the error



so what should it be ?

thank you !

Post's attachments

Attachment icon pict (1).PNG 7.9 kb, 132 downloads since 2020-09-19