1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
24 #ifndef __SECURESOCKET_H__
25 #define __SECURESOCKET_H__
36 #include <securesocketinterface.h>
37 //Secure Socket specific panic
38 _LIT(KSecureSocketPanic,"SecureSocket Panic");
41 * Maximum length of the protocol name.
45 const TInt KMaxProtocolName = 32;
47 class TSecSocketProtocol
49 * The secure socket protocol class.
58 TBuf<KMaxProtocolName> iName;
59 /** Handle to the DLL. */
61 static inline TInt Offset()
63 * Gets the offset to the iSlink member.
65 * @return The offset to the iSlink member. */
66 {return _FOFF(TSecSocketProtocol,iSlink);}
67 // Moved the implementation to the cpp file
68 virtual ~TSecSocketProtocol();
74 class TSecureSocketGlobals
76 * Class to store the Secure Sockets Globals.
84 inline TSecureSocketGlobals():
85 iSecureSocketProtocols(TSecSocketProtocol::Offset()),
87 iSecureSocketProtocolsIter(iSecureSocketProtocols),
89 /** List of supported protocols. */
90 TSglQue<TSecSocketProtocol> iSecureSocketProtocols;
91 /** A templated class that provides for iterating through the list of supported
93 TSglQueIter<TSecSocketProtocol> iSecureSocketProtocolsIter;
98 class MGenericSecureSocket;
101 * Definition for the entry point function exported by Secure Socket modules.
105 typedef TInt (*TSecSockDllLibraryFunction)( RSocket& aSocket, const TDesC& aProtocol );
106 typedef TInt (*TSecSockDllLibraryGenericFunction)(MGenericSecureSocket& aSocket, const TDesC& aProtocol);
109 * Definition for the entry point for the cleanup function exported by secureSocket modules
113 typedef void (*TSecSockDllUnloadFunction)( TAny* );
115 class CSecureSocketLibraryLoader : public CBase
117 * Factory class for creating secure sockets.
122 // Create and reference Secure Sockets
125 static TInt OpenL(const TDesC& aProtocolName,TSecSockDllLibraryFunction& anEntryPoint);
126 static TInt OpenL(const TDesC& aProtocolName, TSecSockDllLibraryGenericFunction& aEntryPoint);
127 static void FindItemInDbL(const TDesC& aProtocolName, TDes& aLibraryName);
128 IMPORT_C static void Unload();
131 static void OpenWithIdL(TInt aId, const TDesC& aProtocolName, TLibraryFunction& aEntryPoint);
135 class CSecureSocket : public CBase
137 * Secure sockets class.
143 // New secure sockets can be created through the static CSecureSocket::NewL method.
147 IMPORT_C static CSecureSocket* NewL(RSocket& aSocket,const TDesC& aProtocol);
148 IMPORT_C static CSecureSocket* NewL(MGenericSecureSocket& aSocket,const TDesC& aProtocol);
150 /** Standard destructor. */
153 // export CSecureSocket methods
154 IMPORT_C TInt AvailableCipherSuites( TDes8& aCiphers );
155 IMPORT_C void CancelAll();
156 IMPORT_C void CancelHandshake();
157 IMPORT_C void CancelRecv();
158 IMPORT_C void CancelSend();
159 IMPORT_C const CX509Certificate* ClientCert();
160 IMPORT_C TClientCertMode ClientCertMode();
161 IMPORT_C TDialogMode DialogMode();
162 IMPORT_C void Close();
163 IMPORT_C TInt CurrentCipherSuite( TDes8& aCipherSuite );
164 IMPORT_C void FlushSessionCache();
165 IMPORT_C TInt GetOpt(TUint aOptionName, TUint aOptionLevel, TDes8& aOption);
166 IMPORT_C TInt GetOpt(TUint aOptionName, TUint aOptionLevel, TInt& aOption);
167 IMPORT_C TInt Protocol(TDes& aProtocol);
168 IMPORT_C void Recv (TDes8& aDesc, TRequestStatus& aStatus );
169 IMPORT_C void RecvOneOrMore( TDes8& aDesc, TRequestStatus& aStatus, TSockXfrLength& aLen );
170 IMPORT_C void RenegotiateHandshake(TRequestStatus& aStatus );
171 IMPORT_C void Send( const TDesC8& aDesc, TRequestStatus& aStatus, TSockXfrLength& aLen );
172 IMPORT_C void Send( const TDesC8& aDesc, TRequestStatus& aStatus );
173 IMPORT_C const CX509Certificate* ServerCert();
174 IMPORT_C TInt SetAvailableCipherSuites(const TDesC8& aCiphers);
175 IMPORT_C TInt SetClientCert(const CX509Certificate& aCert);
176 IMPORT_C TInt SetClientCertMode(const TClientCertMode aClientCertMode);
177 IMPORT_C TInt SetDialogMode(const TDialogMode aDialogMode);
178 IMPORT_C TInt SetProtocol(const TDesC& aProtocol);
179 IMPORT_C TInt SetOpt(TUint aOptionName, TUint aOptionLevel, const TDesC8& aOption=TPtrC8(NULL,0));
180 IMPORT_C TInt SetOpt(TUint aOptionName, TUint aOptionLevel, TInt aOption);
181 IMPORT_C TInt SetServerCert(const CX509Certificate& aCert);
182 IMPORT_C void StartClientHandshake(TRequestStatus& aStatus);
183 IMPORT_C void StartServerHandshake(TRequestStatus& aStatus);
186 void ConstructL(RSocket& aSocket,const TDesC& aProtocol);
187 void ConstructL(MGenericSecureSocket& aSocket,const TDesC& aProtocol);
189 enum {ESecureSocketStateOpen, ESecureSocketStateClosed};
191 TUint iSecureSocketState;
193 TSecSockDllLibraryFunction iUNUSED;
194 MSecureSocket* iSecureImplementation;
197 #endif // __SECURESOCKET_H__