EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Getting garbage results w/TElSimpleSSLClient

Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages
#17285
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?

Thanks,
Mike
#17286
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?

Thanks!
Mike
#17288
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.
#17291
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
#17295
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
#17296
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:
Code
{$IFDEF SB_UNICODE_VCL}
  ShowMessage('SB_UNICODE_VCL is defined');
{$ELSE}
  ShowMessage('SB_UNICODE_VCL is NOT defined');
{$ENDIF}

'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:
Code
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.
#17298
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
#17299
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:
Quote
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
P3P: CP="ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI"
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:
Quote
呈偔ㄯㄮ㈠〰传ോ䌊捡敨䌭湯牴汯›潮挭捡敨਍潃瑮湥⵴祔数›整瑸栯浴൬䰊獡⵴潍楤楦摥›潍Ɱㄠ‶慍⁲〲㤰㈠㨰㔳㈺‶䵇ൔ䄊捣灥⵴慒杮獥›祢整൳䔊慔㩧∠㜶㤹昱摢㘷㙡㥣㨱∰਍敓癲牥›楍牣獯景⵴䥉⽓⸷വ嘊慔㩧㜠ㄹ〶㈳〰〷〰〰〰ര倊倳›偃∽䱁⁌义⁄卄⁐佃⁒䑁⁍佃潎䌠剕䌠单噉潁䤠䑖卐⁁卐⁄䅔⁉䕔潌传剕匠䵁乃⁔佃⁍义⁔䅎⁖乏⁌䡐⁙剐⁅啐⁒乕≉਍ⵘ潐敷敲ⵤ祂›十⹐䕎ൔ䐊瑡㩥吠敵‬㘱䄠杵㈠㄰‱ㄱ㌺㨸㔲䜠呍਍潃湮捥楴湯›敫灥愭楬敶਍潃瑮湥⵴敌杮桴›〱〲਍਍格浴㹬格慥㹤琼瑩敬䴾捩潲潳瑦䌠牯潰慲楴湯⼼楴汴㹥洼瑥⁡瑨灴攭畱癩∽ⵘ䅕䌭浯慰楴汢≥挠湯整瑮∽䕉䔽畭慬整䕉∷㰾洯瑥㹡洼瑥⁡瑨灴攭畱癩∽潃瑮湥⵴祔数•潣瑮湥㵴琢硥⽴瑨汭※档牡敳㵴瑵ⵦ∸㰾洯瑥㹡洼瑥⁡慮敭∽敓牡档楔汴≥挠湯整瑮∽楍牣獯景⹴潣≭猠档浥㵥∢㰾洯瑥㹡洼瑥⁡慮敭∽敄捳楲瑰潩≮挠湯整瑮∽敇⁴牰摯捵⁴湩潦浲瑡潩Ɱ猠灵潰瑲‬湡⁤敮獷映潲楍牣獯景⹴•捳敨敭∽㸢⼼敭慴㰾敭慴渠浡㵥吢瑩敬•潣瑮湥㵴䴢捩潲潳瑦挮浯䠠浯⁥慐敧•捳敨敭∽㸢⼼敭慴㰾敭慴渠浡㵥䬢祥潷摲≳挠湯整瑮∽楍牣獯景ⱴ瀠潲畤瑣‬畳灰牯ⱴ栠汥Ɒ琠慲湩湩Ⱨ传晦捩ⱥ圠湩潤獷‬潳瑦慷敲‬潤湷潬摡‬牴慩ⱬ瀠敲楶睥‬敤潭‬戠獵湩獥ⱳ猠捥牵瑩ⱹ甠摰瑡ⱥ映敲ⱥ挠浯異整Ⱳ倠ⱃ猠牥敶Ⱳ猠慥捲ⱨ搠睯汮慯Ɽ椠獮慴汬‬敮獷•捳敨敭∽㸢⼼敭慴㰾敭慴渠浡㵥匢慥捲䑨獥牣灩楴湯•潣瑮湥㵴䴢捩潲潳瑦挮浯䠠浯灥条≥猠档浥㵥∢㰾洯瑥㹡⼼敨摡㰾潢祤㰾㹰潙牵挠牵敲瑮唠敳⵲杁湥⁴瑳楲杮愠灰慥獲琠敢映潲湡愠瑵浯瑡摥瀠潲散獳‬晩琠楨⁳獩椠据牯敲瑣‬汰慥敳挠楬正琠楨⁳楬歮㰺⁡牨晥∽瑨灴⼺眯睷洮捩潲潳瑦挮浯支⽮獵搯晥畡瑬愮灳㽸敲楤㵲牴敵㸢湕瑩摥匠慴整⁳湅汧獩⁨楍牣獯景⁴潈敭慰敧⼼㹡⼼㹰⼼潢祤㰾栯浴㹬਍


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):
Code
var
  S: {$IFNDEF SB_UNICODE_VCL}string{$ELSE} AnsiString {$ENDIF};
...
  while SSLClient.Active do
  begin
    Read := $FFFF;
    SetLength(S, Read);
    try
      SSLClient.ReceiveData(@S[1], Read, true);
      SetLength(S, Read);
      MemoResults.Lines.text := MemoResults.Lines.text + S;
    except
      // here we can catch disconnection or timeout event or something like this
      break;
    end;
    Application.ProcessMessages;
  end;
#17300
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
#17305
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:
C:\Users\Public\Documents\EldoS\SecureBlackbox\Samples\Delphi\SSLBlackbox\Client\SimpleSSL\SocketDemo_CRS2010
Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.

Reply

Statistics

Topic viewed 4019 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!