This is a discussion on CSecureSocket::NewL Error within the Mobile Software Development forums, part of the Software Development category; hi everybody, I'm testing SSL on Symbian (3rd)... I have a problem with NewL method of CSecureSocket class....When ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| hi everybody, I'm testing SSL on Symbian (3rd)... I have a problem with NewL method of CSecureSocket class....When my script calls this method the emulator crashes and dont't return anything...this is a piece of my code: Code: CX509Certificate* cert;
Rsocket socket;
TRequestStatus ssl_status;
CSecureSocket* secSock;
_LIT(KServerTlsProtocol, "TLS1.0");
secSock = CSecureSocket::NewL(socket, KServerTlsProtocol); // here crash
secSock->FlushSessionCache();
TInt errSsc = secSock->SetServerCert(*cert);
// chech if the certificate is set correctly
if(errSsc == KErrNone){
_LIT(mess91,"SetServerCert failed...\n");
console->Printf(mess91);
}
else {
_LIT(mess101,"SetServerCert done...\n");
console->Printf(mess101);
}
secSock->StartClientHandshake(ssl_status);
// check if handshake fails or not
if(ssl_status!=KErrNone){
_LIT(mess51,"Handshake failed...\n");
console->Printf(mess51);
}
else {
_LIT(mess61,"Handshake done...\n");
console->Printf(mess61);
} I find some examples that do the same thinghs....Can anyone help me? thanks in advance |
| Sponsored Links |
| |||
| Your socket isn't connected to anything, so I guess your code is panicing with KERN-EXEC 0. You need to establish a connection first, and then open a secure socket with that connection. Also, it looks like you're attempting to use CSecureSocket as a server socket. If that's the case, you'll be disappointed. CSecureSocket is client only. |
| |||
| My socket is a client and is connected to a server....I didn't quote entire code...the entire code is: Code: RSocketServ sockServ;
User::LeaveIfError(sockServ.Connect());
// posto --> 1 FRODO
// --> 0 CASA
TInt posto = 1;
TInetAddr s_addr;
TInetAddr c_addr;
TInt s_porta;
TInt c_porta;
TUint32 KInetAddrS;
TUint32 KInetAddrC;
// FRODO
if(posto == 1){
KInetAddrS = INET_ADDR(10,20,10,22);
s_porta = 10000;
KInetAddrC = INET_ADDR(10,20,179,155);
c_porta = 6680;
}
// CASA
else{
KInetAddrS = INET_ADDR(192,168,1,2);
s_porta = 10000;
KInetAddrC = INET_ADDR(192,168,1,44);
c_porta = 6680;
}
s_addr.SetAddress(KInetAddrS);
s_addr.SetPort(s_porta);
c_addr.SetAddress(KInetAddrC);
c_addr.SetPort(c_porta);
RSocket socket;
TInt errno;
errno=socket.Open(sockServ,KAfInet,KSockStream, KProtocolInetTcp);
if(errno!=KErrNone){
_LIT(mess1,"Error opening socket...\n");
console->Printf(mess1);
}
else {
_LIT(mess2,"Socket opened...\n");
console->Printf(mess2);
}
TInt errBin;
errBin=socket.Bind(c_addr);
if(errBin!=KErrNone){
_LIT(mess5,"Error binding CLIENT...\n");
console->Printf(mess5);
}
else {
_LIT(mess6,"Socket binded...\n");
console->Printf(mess6);
}
TRequestStatus status;
socket.Connect(s_addr, status);
if(status!=KErrNone){
_LIT(mess3,"Error connecting SERVER...\n");
console->Printf(mess3);
}
else {
_LIT(mess4,"Socket connected...\n");
console->Printf(mess4);
}
// apro certificato e lo salvo in un buffer
TBuf8<500000> certBuf;
RFs fsSession;
_LIT(KFileName,"C:\\serverCert.cer");
RFileReadStream fileStream;
User::LeaveIfError(fsSession.Connect());
TInt errOp = fileStream.Open(fsSession,KFileName,EFileStream);
_LIT(retr,"errOp value: %d\n");
console->Printf(retr, errOp);
// ottengo la dimensione del file
TEntry entry;
User::LeaveIfError(fsSession.Entry(KFileName, entry));
TInt fileSize = entry.iSize;
// leggo lo stream e lo salvo nel buffer
fileStream.ReadL(certBuf, fileSize);
_LIT(testRead,"dimensione file: %d\n");
console->Printf(testRead, fileSize);
// chiudo la sessione
fsSession.Close();
CX509Certificate* cert;
cert = CX509Certificate::NewL(certBuf);
TRequestStatus ssl_status;
CSecureSocket* secSock; // socket protetto con ssl
_LIT(KServerTlsProtocol, "TLS1.0");
secSock = CSecureSocket::NewL(socket, KServerTlsProtocol);
secSock->FlushSessionCache();
TInt errSsc = secSock->SetServerCert(*cert);
if(errSsc == KErrNone){
_LIT(mess91,"SetServerCert failed...\n");
console->Printf(mess91);
}
else {
_LIT(mess101,"SetServerCert done...\n");
console->Printf(mess101);
}
secSock->StartClientHandshake(ssl_status);
if(ssl_status!=KErrNone){
_LIT(mess51,"Handshake failed...\n");
console->Printf(mess51);
}
else {
_LIT(mess61,"Handshake done...\n");
console->Printf(mess61);
}
secSock->Recv(recBuff, ssl_status);
socket.CancelAll();
secSock->CancelAll();
//chiudo il secure socket
secSock->Close();
delete secSock;
// chiudo il socket sockServ e socket
socket.Close();
sockServ.Close();
} |
| |||
| I don't know where to start really. The biggest problem is that you're calling asynchronous functions and charging on without waiting for them to complete. RSocket::Connect, for instance. I suggest you start by reading about active objects. Then, you're mixing things that a server should do (binding a socket, selecting a certificate) with things a client should do (connecting to a remote host, handshaking.) There is no need to select a port for client sockets, it'll automatically select a high numbered port for you. Ditto with certificates if you're using client auth, the server will send you a list of of CAs it supports, and the framework will select an installed client certificate to use for the transaction if it has one. Then there is things like "TBuf8<500000> certBuf;", that's a 500 kilobyte buffer. On the stack. The stack is by default 8Kbs. |
| |||
| hi i tried to use active objects, but I still have some problem... After connecting to the server with RSocket::Connect, my program crashes....(this happens when I put SetActive() command after RSocket::Connect). The same problem happens when I use CSecureSocket::StartClientHandshake... I paste my .h and .cpp files....I only try to setup a SSL connection without sending/receiving file... sslEngine.h: Code: //sslEngine.h
#ifndef __SSLENGINE_H__
#define __SSLENGINE_H__
// Include Files
#include <e32base.h>
#include <in_sock.h>
#include <e32def.h>
#include <es_sock.h>
#include <e32std.h>
#include <e32cons.h>
#include <x509cert.h>
#include <securesocket.h>
//#include <>
// Function Prototypes
GLDEF_C TInt E32Main();
class CSslEngine : public CActive {
public:
//Costruttore
static CSslEngine *NewL();
//Distruttore
~CSslEngine();
// ConnectL
void ConnectL(TUint32 anAddress, TInt aPort);
// setConsole
void setConsole(CConsoleBase* aConsole);
private:
//costruttore
CSslEngine();
//ConstructL
void ConstructL();
// RunL
void RunL();
// DoCancel
void DoCancel();
// makeSecureConL
void makeSecureConL();
// CloseCoL()
void CloseConL();
// RunError
TInt RunError(TInt aError);
private:
// oggetti della classe
RSocket sockEng;
RSocketServ sockServEng;
TInetAddr servAddr;
TRequestStatus iStatus;
CConsoleBase* iConsole;
CSecureSocket* iTlsSock;
// engine state
enum eSslState
{
eNotCon, // non connesso
eConnected, // connesso al Rsocket
eSecConnected, // socket protetto con ssl
eDataTransfered, // invio/Ricezione dati terminato
};
// variabile indicante lo stato dell' engine
TInt iSslState;
};
#endif // __SSLENGINE_H__ Code: // sslEngine.cpp
// Include Files
#include "sslEngine.h"
// COSTANTI
_LIT(KErrOpen,"Error opening socket...\n");
_LIT(KNerrOpen,"Socket opened...\n");
_LIT(KErrCon,"Error connecting to the server...\n");
_LIT(KNerrCon,"Socket Connected...\n");
_LIT(KErrHand,"Handshake Failed...\n");
_LIT(KNerrHand,"Handshake Done...\n");
_LIT(KErrRecv,"Error receiving data...\n");
_LIT(KNerrRecv,"Data Received");
_LIT(KErrSend,"Error sending data...\n");
_LIT(KNerrSend,"Data Sent...\n");
_LIT(KCloseConn,"Connection Closed...\n");
// CLASS CSSLENGINE
// costruttore pubblico
CSslEngine* CSslEngine::NewL()
{
CSslEngine* me = new(ELeave) CSslEngine;
CleanupStack::PushL(me);
me->ConstructL();
CleanupStack::Pop();
return me;
}
// costruttore privato
CSslEngine::CSslEngine()
: CActive(0)
{
//CActiveScheduler::Add( this );
}
// distruttore
CSslEngine::~CSslEngine()
{
sockServEng.Close();
}
// ConstructL
void CSslEngine::ConstructL()
{
User::LeaveIfError(sockServEng.Connect());
CActiveScheduler::Add( this );
}
// RunL
void CSslEngine::RunL()
{
switch(iSslState)
{
case eConnected:
makeSecureConL();
break;
//case eSecConnected:
// invio-ricezione
//break;
//case eDataTransfered:
//closeConL();
//break;
}
}
//DoCancel
void CSslEngine::DoCancel()
{
}
// ConnectL
void CSslEngine::ConnectL(TUint32 anAddress, TInt aPort)
{
TInt errorCode;
servAddr.SetAddress(anAddress);
servAddr.SetPort(aPort);
errorCode = sockEng.Open(sockServEng, KAfInet, KSockStream,KProtocolInetTcp);
if(errorCode != KErrNone)
{
iConsole->Write(KErrOpen);
}
else
{
iConsole->Write(KNerrOpen);
}
//SetActive();
sockEng.Connect(servAddr, iStatus);
if(iStatus != KErrNone)
{
iConsole->Write(KErrCon);
iSslState = eConnected;
}
else
{
iConsole->Write(KNerrCon);
}
SetActive();
}
void CSslEngine::setConsole(CConsoleBase* aConsole)
{
iConsole = aConsole;
}
void CSslEngine::makeSecureConL()
{
_LIT(KSerTls, "TLS1.0");
iTlsSock = CSecureSocket::NewL(sockEng, KSerTls);
iTlsSock->FlushSessionCache();
//SetActive();
iTlsSock->StartClientHandshake(iStatus);
iSslState = eSecConnected;
SetActive();
}
void CSslEngine::CloseConL()
{
iTlsSock->CancelAll();
iTlsSock->Close();
delete iTlsSock;
sockEng.CancelAll();
sockEng.Close();
}
TInt CSslEngine::RunError(TInt aError)
{
TInt y = aError;
return KErrNone;
}
//==============================================================
//==============================================================
//==============================================================
// Constants
_LIT(KTextConsoleTitle, "Console");
_LIT(KTextFailed, " failed, leave code = %d");
_LIT(KTextPressAnyKey, " [press any key]\n");
// Global Variables
LOCAL_D CConsoleBase* console;
// Local Functions
//LOCAL_C void MainL()
// {
// console->Write(_L("Hello, world!\n"));
// }
LOCAL_C void DoStartL()
{
// Create active scheduler (to run active objects)
CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
CleanupStack::PushL(scheduler);
CActiveScheduler::Install(scheduler);
//CActiveScheduler::Start();
TInt tipo = 1;
TUint32 serv;
//porta
TInt port = 10000;
//indirizzo ip
if(tipo == 1){
serv = INET_ADDR(10,20,10,22);
}
else{
serv = INET_ADDR(192,168,1,2);
}
CSslEngine* pippo;
pippo = CSslEngine::NewL();
pippo->setConsole(console);
pippo->ConnectL(serv, port);
pippo->~CSslEngine();
//CActiveScheduler::Stop();
// Delete active scheduler
CleanupStack::PopAndDestroy(scheduler);
}
// Global Functions
GLDEF_C TInt E32Main()
{
// Create cleanup stack
__UHEAP_MARK;
CTrapCleanup* cleanup = CTrapCleanup::New();
// Create output console
TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(KConsFullScreen,KConsFullScreen)));
if (createError)
return createError;
// Run application code inside TRAP harness, wait keypress when terminated
TRAPD(mainError, DoStartL());
if (mainError)
console->Printf(KTextFailed, mainError);
console->Printf(KTextPressAnyKey);
console->Getch();
delete console;
delete cleanup;
__UHEAP_MARKEND;
return KErrNone;
} |
| |||
| You still aren't checking the error code returned by RSocket::Connect. Checking what it is immediately after the call isn't helpful, you have to wait until after it has completed, in RunL. Also, as I said earlier, get rid of the call to FlushSessionCache. At best it's totally redundant. It would also help if you told us what the panic code was, rather than saying "it crashes".
__________________ Venkat knowledge is Power |
| |||
| RSocket::Connect works well. The socket is connected to server, but as soon as it is connected, my script exits not correctly closing emulator window... how can i check the return code? thanks in advance |
| |||
| hi, the error is a connection failed error, 10061. server spec: openssl version 0.9.71 on mac os X 10..4.9 (kernel Darwin 8.9.1) |
| |||
| checking the epocwind.out file, the only error that I've found is: [DOSSERVER] RDosServer::Connect()-CreateSession err: -1 But this method is called again in the file, returning no error. Also I checked the messages exchange with wireshark (i tried to send a simple string to the server). After been connected to the server, my socket sends the string (the server gives errors because it expects SSL parameters) and then the emulator window shuts. |
| |||
| anybody can help me? Is my code correct? I did some tests and I found that the problem is the SetActive call after RSocket::Connect. Commenting this method, script doesn't crash and the socket connects to the server....Perhaps my AO implementation is not correct... thanks in advance |
| |||
| There are examples of using the secure socket API in the 2nd FP2 Codewarrior SDK in Examples\networking\securesockets and also in the 3.1 UIQ SDK Examples\SymbianNotCompatible\Networking\SecureSoc kets Email me if you want the example code for this example and don't want to download the entire SDK. |
| |||
| Hi, I tried to use SecureSockets example (SecEngine.ccp/.h), but i still have problems.... My application doesn't called The RunL method and exits with "Console Panic KERN-EXEC 3" I try to comment RunL except the part that does handshake... My main32 code is paste below: Code: // Create active scheduler (to run active objects)
CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
CleanupStack::PushL(scheduler);
CActiveScheduler::Install(scheduler);
//CActiveScheduler::Start();
//SISTEMARE LE VARIE VARIABILI
TConnectSettings settings;
settings.iPortNum = 10000;
settings.iAddress = _L("10.20.10.22");
//settings.iAddress = _L("192.168.1.2");
settings.iPage = _L8("");
CSecEngine* pippo;
pippo = CSecEngine::NewL();
pippo->SetConsole(console);
pippo->ConnectL(settings);
pippo->~CSecEngine();
//CActiveScheduler::Stop();
//Delete active scheduler
CleanupStack::PopAndDestroy(scheduler); |
| |||
| There might be... For example this is a really nice method invocation indeed: Code: pippo->~CSecEngine(); |
| |||
| Now I'm testing if ssl-Handshake works well....then I will implement a secure data exchange between a cell phone and a server if I start the scheduler, my code does nothing, emulator'windows doesn't print anything, only a blinking underscore |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Error: command line error MIDL1001 : cannot open input file wincodec.idl midl | Mramesh | C# Programming | 0 | 02-18-2008 11:07 PM |
| Why do I get Error message "Unable to Start Debugging" Error Message? | a.deeban | ASP and ASP.NET Programming | 5 | 09-25-2007 12:22 AM |
| .Debugging php ..What does this mean " Parse error: parse error, unexpected....... | oxygen | PHP Programming | 1 | 07-26-2007 03:41 AM |
| error | nssukumar | Flash Actionscript Programming | 1 | 07-25-2007 04:51 AM |
| I get the error "The page cannot be displayed" and an HTTP 502 Proxy Error. Why? | kingmaker | ASP and ASP.NET Programming | 1 | 07-20-2007 04:43 AM |