EldoS | Feel safer!

Software components for data protection, secure storage and transfer

C# to Delphi 7

Also by EldoS: RawDisk
Access locked and protected files in Windows, read and write disks and partitions and more.
Posted: 02/02/2014 09:29:32
by Timothy Vogel (Standard support level)
Joined: 01/28/2014
Posts: 8

I'm not sure if this is within the support guidelines but really need some help evaluating SSL Blackbox capabilities with Delphi 7.

I am using the SSL Simple Client example that ships with the evaluation product. I need to communicate to a proprietary (non-http) server. I have used the SSL simple client to establish a connection to the server and am sending data but the data is not properly received. The server is returning an unhelpful message. I was given sample C# code that works with exactly the same data.

Please review the two code sample below and tell me waht I'm doing wrong or if the SSL Simple Client is not suitable to perform this communication.

The specs for data sent / to the server require the data to be in UTF-16 and "little-endian".

C# code provided that works
// connect to server and establish SSL code removed

    string xml = File.ReadAllText(DataFile);
    byte[] messsage = System.Text.Encoding.Unicode.GetBytes(xml);
    int msgSize = messsage.Length;
    byte[] msgSizeByte = BitConverter.GetBytes(msgSize);

    setLabelmessage("Sending request to server...");

    sslStream.Write(msgSizeByte);  // size in bytes to write
    sslStream.Write(messsage);  // message
    setLabelmessage("Request Sent successfully");

    byte[] resultByteSize = new byte[4];
    sslStream.Read(resultByteSize, 0, 4);  // size in bytes to read
    int resultSize = BitConverter.ToInt32(resultByteSize, 0);
    byte[] resultMsg = new byte[resultSize];
    setLabelmessage("Receiving request from server...");

    sslStream.Read(resultMsg, 0, resultSize);

    setLabelmessage("Response : " + System.Text.Encoding.Unicode.GetString(resultMsg));

My Delphi 7 code that doesn't work
procedure TfrmMain.DoRequest;
  S: WideString;
  R : WideString;
  Write : Integer;
  Read, read1: integer;

  s:= '<?xml version="1.0" encoding="UTF-16"?><CommunicationCenter MessageCenter="123456" PacketId="F63B9BB2-DBB0-4473-8767-34DE30B44F11" Asynchronous="0"></CommunicationCenter>';   // same content as in the file read in C# program
  Write := length(s);

    memoOutput.Lines.Text:=memoOutput.Lines.Text+ 'sending [' + S + ']';
    Fclient.SendData(@Write, sizeof(Write));
    // TODO: log this and handle

  // read the size of the return message
    read1 := sizeof(Read);
    FClient.ReceiveData(@read, read1, false);
    SetLength(R, read);
    FClient.ReceiveData(@R[1], read);
    // TODO: log this and handle

Thanks for your input!
Posted: 02/02/2014 09:35:59
by Eugene Mayevski (EldoS Corp.)

Thank you for contacting us.

Try replacing SendText with SendData - that's the first thing to do.

Next, if the change doesn't help, please provide more details about actual server errors or other indication that something is wrong.

Sincerely yours
Eugene Mayevski
Posted: 02/02/2014 22:35:25
by Timothy Vogel (Standard support level)
Joined: 01/28/2014
Posts: 8

Thanks for the suggestion. A combination of changing to SendData and proper handling of Delphi strings / arrays worked. I have a working prototype.




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