EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Getting garbage results w/TElSimpleSSLClient

Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.
Posted: 08/15/2011 17:13:18
by Mike Torch (Basic support level)
Joined: 08/15/2011
Posts: 6

Using Delphi 2010 and the SocketDemo_CRS2010 demo under SecureBlackbox\Samples\Delphi\SSLBlackbox\Client\SimpleSSL I am able to connect with SSL to www.microsoft.com on port 443 and the correct results appear in the result memo. But when I try to use this component in my own project the results look like random garbage. Here is what some of the results look like when things don't work:

I tested many different options. Here's what I discovered. If I added new, completely fresh components to the sample application and used new methods, events, etc, it worked fine with the new components.

But here's what is really confusing me- I created a new project and simply added the forms from the sample project and then I got the garbage results once again, without changing ANY of the source code.

So one theory I came up with is that there might be some special project settings that I must configure for a new project. The only non-default I could see was the "SB_UNICODE_VCL" conditional directive. I tried adding that to my new project and it still gave me garbage.

I've tried solving this problem for the past 24 hours with no luck. I don't know what I'm doing wrong but hopefully someone knows why this is happening?

Posted: 08/15/2011 17:50:41
by Mike Torch (Basic support level)
Joined: 08/15/2011
Posts: 6

Somehow it all just started working. One of the test project's "Unit output directory" was set to ..\..\dcu and the "output directory" was ..\..
I cleared both of those values and recompiled and it worked. (I'm not positive if that's the only change I made). Not only that, but all of the other projects started working too. And now I can't even recreate the garbage output that was getting even if I try.

So maybe it was just some bad code of mine from earlier that was lingering? I can't explain it but I'm just glad it's working.

But I am curious if anyone knows what would have caused the garbage output in the first place?

Posted: 08/15/2011 20:32:59
by Mike Torch (Basic support level)
Joined: 08/15/2011
Posts: 6

So I did some more tests and apparently the problem was in fact caused by the missing SB_UNICODE_VCL definition. My question is this- how was I supposed to know to add that definition to make my code work? It was only through a very painful process of elimination that I found that. I didn't see that mentioned in any of the help files or FAQs. I would highly recommend documenting that requirement in an obvious place to prevent other programmers from losing a day or more like I did.
Posted: 08/16/2011 00:59:48
by Eugene Mayevski (EldoS Corp.)

As I understand, you are using Delphi 2010. Version-specific SecureBlackbox defines are set "automatically" via secbbox.inc file which is included by all source files of SecureBlackbox. You don't have to set any defines in your code or in project settings. I can only guess what was wrong initially.

Also, there are hundreds of developers using SecureBlackbox with unicode Delphi and this is the first time such problem was reported. If there was an issue with define, I think we'd have a report 2 years ago.

Sincerely yours
Eugene Mayevski
Posted: 08/16/2011 01:34:15
by Eugene Mayevski (EldoS Corp.)

Also, defines that you set in your project can't affect precompiled DCU files of evaluation version. So the glitch must be local. We will try to reproduce it on our side.

Sincerely yours
Eugene Mayevski
Posted: 08/16/2011 04:34:44
by Mike Torch (Basic support level)
Joined: 08/15/2011
Posts: 6

Thanks for the quick response! Yes, I am using Delphi 2010 (Embarcadero® RAD Studio 2010 Version 14.0.3615.26342). If this is just a local problem on my end then I'm happy to help try to pinpoint the cause if you're interested, in case other programmers are affected by this. Otherwise, maybe it was just something wrong on my end.

Out of curiosity I added the following code to my form's OnCreate event:
  ShowMessage('SB_UNICODE_VCL is defined');
  ShowMessage('SB_UNICODE_VCL is NOT defined');

'SB_UNICODE_VCL is NOT defined' appeared when I ran it, until I add SB_UNICODE_VCL to my project's Delphi Compiler | Conditional Defines, followed by Build. The status of the problem only changes if I click Build, not just Run. So that makes me think that somehow the SB_UNICODE_VCL directive was not successfully included in the precompiled DCU's in my evaluation version?

I don't know enough about the code since I just started using it this week. But I thought maybe sharing that would highlight the origin of the problem?

Also, here are the units that I'm using in my test project with the problem:
SBSimpleSSL, SBHTTPSClient, SBLicenseManager, SBConstants, SButils, SBX509, SBCustomCertStorage, SBCertValidator, SBWinCertStorage, SBHTTPCRL, SBHTTPOCSPClient, SBSSLConstants;

Please let me know if you want me to test anything out for you or provide you with more info. Otherwise the issue is resolved for me by just adding that one compiler directive.
Posted: 08/16/2011 05:06:54
by Eugene Mayevski (EldoS Corp.)

Compiler directive is used by source code parser. It can't be included in DCUs (which are blocks of executable code). Consequently when you set the directive in your project, - it's active. If you don't set it - it's inactive. If you include secbbox.inc file (I don't remember though if it goes to evaluation version) into your code, the directive will be set.

However, nothing in your code requires the directive. If you have copied some code from the sample project, and the copied code makes use of the directive, then you can assume that the directive is set and remove the directive and unused non-unicode code pieces from the code you've copied.

Sincerely yours
Eugene Mayevski
Posted: 08/16/2011 06:45:24
by Mike Torch (Basic support level)
Joined: 08/15/2011
Posts: 6

I'm not sure if this will add to the conversation, but I wanted to share the full results of connection attempts to www.microsoft.com on 443 with and without the SB_UNICODE_VCL compiler directive, using the TElSimpleSSLClient component. Here are the results with the compiler directive added to the Project | Options:
HTTP/1.1 200 OK
Cache-Control: no-cache
Content-Type: text/html
Last-Modified: Mon, 16 Mar 2009 20:35:26 GMT
Accept-Ranges: bytes
ETag: "67991fbd76a6c91:0"
Server: Microsoft-IIS/7.5
VTag: 791990642500000000
X-Powered-By: ASP.NET
Date: Tue, 16 Aug 2011 11:37:19 GMT
Connection: keep-alive
Content-Length: 1020

<html><head><title>Microsoft Corporation</title><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"></meta><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta><meta name="SearchTitle" content="Microsoft.com" scheme=""></meta><meta name="Description" content="Get product information, support, and news from Microsoft." scheme=""></meta><meta name="Title" content="Microsoft.com Home Page" scheme=""></meta><meta name="Keywords" content="Microsoft, product, support, help, training, Office, Windows, software, download, trial, preview, demo, business, security, update, free, computer, PC, server, search, download, install, news" scheme=""></meta><meta name="SearchDescription" content="Microsoft.com Homepage" scheme=""></meta></head><p>Your current User-Agent string appears to be from an automated process, if this is incorrect, please click this link:<a href="http://www.microsoft.com/en/us/default.aspx?redir=true">United States English Microsoft Homepage</a></p></html>

but when I remove that compiler directive I get the following results instead:

The only thing that changed between those two results was the removal of the compiler directive.

The code I used to retrieve the results is from the sample program (with renamed variables):
  S: {$IFNDEF SB_UNICODE_VCL}string{$ELSE} AnsiString {$ENDIF};
  while SSLClient.Active do
    Read := $FFFF;
    SetLength(S, Read);
      SSLClient.ReceiveData(@S[1], Read, true);
      SetLength(S, Read);
      MemoResults.Lines.text := MemoResults.Lines.text + S;
      // here we can catch disconnection or timeout event or something like this
Posted: 08/16/2011 07:56:57
by Eugene Mayevski (EldoS Corp.)

And this is correct. You need to declare S as AnsiString and that's all.

Can you please tell me where exactly have you taken this code from?

Sincerely yours
Eugene Mayevski
Posted: 08/16/2011 09:52:41
by Mike Torch (Basic support level)
Joined: 08/15/2011
Posts: 6

The String declaration (instead of AnsiString) seems to have been causing the problem. Mystery solved!
I got my code snippet from the sample project located at:
Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.



Topic viewed 3974 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!