CSecureSocket Recv/RecvOneOrMore gives no data.

Login to reply to this topic.
Thu, 2007-08-16 09:16
Joined: 2007-02-27
Forum posts: 6

I'm in the process of implementing a solution which requires SSL. CSecureSocket is the way to go, but I have one major issue; Recv and RecvOneOrMore fails to deliver data to the application.
If I instead use the same function on the CSocket, I get the data immediately, but encrypted.
I've seen this issue listed numerous times, but never a solution to it.

I've tested against an HTTPS server, and the request is received by the server, and a response is returned; I just cannot access it.

...
iError = aSocket.Open( m_iSocketServer, KAfInet, KSockStream, KProtocolInetTcp, aConnection );
...
_LIT(KTLS1,"TLS1.0");
m_iSocket.Connect( aAddr, m_iSocketStatus );
User::WaitForRequest( m_iSocketStatus );
...
m_iSecureSocket = CSecureSocket::NewL( m_iSocket, KTLS1 );
m_iSecureSocket->FlushSessionCache();
m_iSecureSocket->SetOpt(KSoSSLDomainName,KSolInetSSL, iAddress );       
m_iSecureSocket->SetDialogMode(EDialogModeAttended);
m_iSecureSocket->StartClientHandshake( iStatus );
SetActive();

On completion, it calls RunL, like it should, and an async. request is sent:

m_iSecureSocket->CancelAll();
m_iBytesSentPkg() = 0;
m_iSecureSocket->Send( *m_iSendBuf, iStatus, m_iBytesSentPkg );
SetActive();

This also calls RunL on completion. I now start to listen for the server's response:

m_iInputBuf.SetMax();
m_iInputBuf.FillZ();
m_iInputBuf.Zero();
m_iBytesReadPkg() = 0;
m_iSecureSocket->RecvOneOrMore( m_iInputBuf, iStatus, m_iBytesReadPkg );
SetActive();

RunL is never called if using RecvOneOrMore, or if using Recv, called when the server closes the socket 10 minutes later, and nothing has passed through the CSecureSocket to the receiving buffer.
I do know that data is available on the socket, because at regular intervals I have a look at the pending data.

iError = m_iSocket.GetOpt( KSOReadBytesPending, KSOLSocket, iPendingData );

The question is, how can I get this data, when Recv and RecvOneOrMore never yield anything?


Sat, 2007-08-18 19:47
Joined: 2006-05-08
Forum posts: 162
Re: CSecureSocket Recv/RecvOneOrMore gives no data.

Hi JensJ,

Very strange... Couple of points:

m_iSecureSocket->SetOpt(KSoSSLDomainName,KSolInetSSL, iAddress ); seems to me an unnecessary call.
Why are you calling m_iSecureSocket->CancelAll();? Seems redundant.

RecvOneOrMore should just work! However, you need to be careful about using Recv. The legendary problem with Recv is, it only completes when the amount of data received is equal to the MaxLength of the descriptor passed in, so if your server returned 10 bytes of data, but the max length of the descriptor passed in is 20, Recv will hang.

Apart from that, I've got nothing for you, yet. Also I hope the code you posted was some sort of psudo code, because its missing error checking Eye-wink


Mon, 2007-08-20 08:32
Joined: 2007-02-27
Forum posts: 6
Re: CSecureSocket Recv/RecvOneOrMore gives no data.

Hi maxxxpayne,

Thanks for your reply, the posted code is partial grabs from the source.
m_iSecureSocket->SetOpt(KSoSSLDomainName,KSolInetSSL, iAddress ); is needed for S60 3rd, to validate the host you're connecting against. If omitted, it will fail handshake with error code -7547 (read about it here)

CancelAll() I've found to be a rather useful, when making tests with RSocket, besides, at the times it's called the socket is idle, i.e. immediately after negotiating security, and when responding to received data, which ofcourse never happens on my CSecureSocket, but did on my RSocket tests.

I'm well aware of the pitfalls of Recv. When attempting with this, my receive buffer is a fraction of the amount pending in my RSocket. Both work with RSocket, but neither with CSecureSocket.

Basically the code is the same as in the Symbian example, with a few extra lines, like "KSoSSLDomainName" and resetting buffers and counters. Compinling the Symbian
example has the exact same result; receives but never delivers.

Wed, 2008-05-21 16:58
Joined: 2007-05-31
Forum posts: 1
Re: CSecureSocket Recv/RecvOneOrMore gives no data.

Have you sorted it out?

When I issue RecvOneOrMore() and then CancelRecv and then another RecvOneOrMore the 2nd RecvOneOrMore never returns (even when I know the data is sent to the device) and I cannot even cancel it.

This does not happen when I use RSocket.

Cheers!

Mon, 2008-06-02 09:08
Joined: 2007-02-27
Forum posts: 6
Re: CSecureSocket Recv/RecvOneOrMore gives no data.

Hi tymi,

No, I never got CSecureSocket to work so I had to abandon that approach.
I'm fairly certain that there must be some undocumented call to get the async SSL to work correctly. I believe this is what's used in the HTTP classes.
An alternative could be to make a from scratch implementation of the newest TLS/SSL protocols.
Due to time constraints, we had to switch to a HTTPS solution.
I think I read about an OpenSSL implementation for Symbian, but with some limitations on licensing that makes it less viable for comercial applications.

Kindly,
Jens

Thu, 2008-08-07 10:20
Joined: 2008-03-18
Forum posts: 45
Re: CSecureSocket Recv/RecvOneOrMore gives no data.

Hi JensJ,

we are aslo facing the same issue on Recv/RecvOneOrMore,but ours is bit different case.
we are using SSL for downloading two or more files,so we are able to download first one
succefully but when we try to download second file we are getting the above mentined problem,
That we are not receiving anything in the buffer after Recv() call.

did you get any solution for the same.

Thanks in advance.
Satya


NEWBIE OF SYMBIAN

Thu, 2008-08-07 10:51
Joined: 2007-02-27
Forum posts: 6
Re: CSecureSocket Recv/RecvOneOrMore gives no data.

Hi tiger4mobile,

I never got mine to work, as stated above, and it's about a year ago so the exact details are a little hazy.

If you're managing to get the first file streamed down, but not the second, I'll assume that you issue a request for the second file after having received the first.
Perhaps you're missing a cancellation in order to get it to reset its receive data state.
You could try to omit the SSL/TLS on both server and client to see if it's an issue with your code or the CSecureSocket component. The regular CSocket seemed to work just fine for me, doing 2-way communications.

Kindly,
Jens

Fri, 2008-08-08 04:29
Joined: 2008-03-18
Forum posts: 45
Re: CSecureSocket Recv/RecvOneOrMore gives no data.

Hi JansJ,
Thanks for your early reply.
we are calling cancelall on CSecuresocket after streaming first file but still we are not getting the data on Recv() for second file streaming.

what may be the reason..??
Thanks in advance.

Regards
Satya


NEWBIE OF SYMBIAN

Fri, 2008-08-08 06:21
Joined: 2008-03-18
Forum posts: 45
Re: CSecureSocket Recv/RecvOneOrMore gives no data.

Hi jansJ,

When we call Recv() second file streaming its returning -36(KErrDisconneted),
i tried with RenegotiateHandshake() to get connected again but its not returning anything.

Do You have any idea how to get connection again??

Regards
Satya


NEWBIE OF SYMBIAN

Fri, 2008-08-08 08:32
Joined: 2007-02-27
Forum posts: 6
Re: CSecureSocket Recv/RecvOneOrMore gives no data.

Hi,

That sounds like a HTTP server. The server closes the socket after it has sent its payload; that's the standard HTTP way of doing a transaction. One request&response per connection, and then discard it.

You'll need to make a new connection afterwards to get the next file.

Kindly,
Jens

Tue, 2008-08-19 10:26
Joined: 2007-01-17
Forum posts: 99
Re: CSecureSocket Recv/RecvOneOrMore gives no data.

I agree with JensJ . If thats a HTTP Server make a fresh request again for the second download.


Shashi Kiran G M

  • Login to reply to this topic.