1.1 --- a/epoc32/include/securesocket.h Tue Nov 24 13:55:44 2009 +0000
1.2 +++ b/epoc32/include/securesocket.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -1,1 +1,197 @@
1.4 -securesocket.h
1.5 +// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +// All rights reserved.
1.7 +// This component and the accompanying materials are made available
1.8 +// 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
1.9 +// which accompanies this distribution, and is available
1.10 +// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
1.11 +//
1.12 +// Initial Contributors:
1.13 +// Nokia Corporation - initial contribution.
1.14 +//
1.15 +// Contributors:
1.16 +//
1.17 +// Description:
1.18 +// Secure Sockets
1.19 +//
1.20 +//
1.21 +
1.22 +
1.23 +
1.24 +/**
1.25 + @file
1.26 +*/
1.27 +
1.28 +#ifndef __SECURESOCKET_H__
1.29 +#define __SECURESOCKET_H__
1.30 +
1.31 +#include <e32base.h>
1.32 +#include <e32cons.h>
1.33 +#include <c32comm.h>
1.34 +#include <es_sock.h>
1.35 +#include <ssl.h>
1.36 +
1.37 +#include <sslerr.h>
1.38 +#include <x509cert.h>
1.39 +
1.40 +#include <securesocketinterface.h>
1.41 +//Secure Socket specific panic
1.42 +_LIT(KSecureSocketPanic,"SecureSocket Panic");
1.43 +
1.44 +/**
1.45 + * Maximum length of the protocol name.
1.46 + *
1.47 + * @internalComponent
1.48 + */
1.49 +const TInt KMaxProtocolName = 32;
1.50 +
1.51 +class TSecSocketProtocol
1.52 +/**
1.53 + * The secure socket protocol class.
1.54 + *
1.55 + * @internalComponent
1.56 + *
1.57 + * @since v7.0
1.58 + */
1.59 + {
1.60 +public:
1.61 + /** Protocol name. */
1.62 + TBuf<KMaxProtocolName> iName;
1.63 + /** Handle to the DLL. */
1.64 + RLibrary iLibrary;
1.65 + static inline TInt Offset()
1.66 + /**
1.67 + * Gets the offset to the iSlink member.
1.68 + *
1.69 + * @return The offset to the iSlink member. */
1.70 + {return _FOFF(TSecSocketProtocol,iSlink);}
1.71 + // Moved the implementation to the cpp file
1.72 + virtual ~TSecSocketProtocol();
1.73 +private:
1.74 + TSglQueLink iSlink;
1.75 + };
1.76 +
1.77 +
1.78 +class TSecureSocketGlobals
1.79 +/**
1.80 + * Class to store the Secure Sockets Globals.
1.81 + *
1.82 + * @internalComponent
1.83 + *
1.84 + * @since v7.0
1.85 + */
1.86 + {
1.87 +public:
1.88 + inline TSecureSocketGlobals():
1.89 + iSecureSocketProtocols(TSecSocketProtocol::Offset()),
1.90 + /** Constructor. */
1.91 + iSecureSocketProtocolsIter(iSecureSocketProtocols),
1.92 + iUseCount(0){};
1.93 + /** List of supported protocols. */
1.94 + TSglQue<TSecSocketProtocol> iSecureSocketProtocols;
1.95 + /** A templated class that provides for iterating through the list of supported
1.96 + * protocols. */
1.97 + TSglQueIter<TSecSocketProtocol> iSecureSocketProtocolsIter;
1.98 + /** Use counter. */
1.99 + TInt iUseCount;
1.100 + };
1.101 +
1.102 +class MGenericSecureSocket;
1.103 +
1.104 +/**
1.105 + * Definition for the entry point function exported by Secure Socket modules.
1.106 + *
1.107 + * @internalComponent
1.108 + */
1.109 +typedef TInt (*TSecSockDllLibraryFunction)( RSocket& aSocket, const TDesC& aProtocol );
1.110 +typedef TInt (*TSecSockDllLibraryGenericFunction)(MGenericSecureSocket& aSocket, const TDesC& aProtocol);
1.111 +
1.112 +/**
1.113 + * Definition for the entry point for the cleanup function exported by secureSocket modules
1.114 + *
1.115 + * @internalComponent
1.116 + */
1.117 +typedef void (*TSecSockDllUnloadFunction)( TAny* );
1.118 +
1.119 +class CSecureSocketLibraryLoader : public CBase
1.120 +/**
1.121 + * Factory class for creating secure sockets.
1.122 + *
1.123 + * @internalAll
1.124 + *
1.125 + * @since v6.2 */
1.126 + // Create and reference Secure Sockets
1.127 + {
1.128 +public:
1.129 + static TInt OpenL(const TDesC& aProtocolName,TSecSockDllLibraryFunction& anEntryPoint);
1.130 + static TInt OpenL(const TDesC& aProtocolName, TSecSockDllLibraryGenericFunction& aEntryPoint);
1.131 + static void FindItemInDbL(const TDesC& aProtocolName, TDes& aLibraryName);
1.132 + IMPORT_C static void Unload();
1.133 +
1.134 +private:
1.135 + static void OpenWithIdL(TInt aId, const TDesC& aProtocolName, TLibraryFunction& aEntryPoint);
1.136 + };
1.137 +
1.138 +
1.139 +class CSecureSocket : public CBase
1.140 +/**
1.141 + * Secure sockets class.
1.142 + *
1.143 + * @publishedAll
1.144 + * @released
1.145 + *
1.146 + * @since v6.2 */
1.147 + // New secure sockets can be created through the static CSecureSocket::NewL method.
1.148 + // @public
1.149 + {
1.150 +public:
1.151 + IMPORT_C static CSecureSocket* NewL(RSocket& aSocket,const TDesC& aProtocol);
1.152 + IMPORT_C static CSecureSocket* NewL(MGenericSecureSocket& aSocket,const TDesC& aProtocol);
1.153 +
1.154 + /** Standard destructor. */
1.155 + ~CSecureSocket();
1.156 +
1.157 + // export CSecureSocket methods
1.158 + IMPORT_C TInt AvailableCipherSuites( TDes8& aCiphers );
1.159 + IMPORT_C void CancelAll();
1.160 + IMPORT_C void CancelHandshake();
1.161 + IMPORT_C void CancelRecv();
1.162 + IMPORT_C void CancelSend();
1.163 + IMPORT_C const CX509Certificate* ClientCert();
1.164 + IMPORT_C TClientCertMode ClientCertMode();
1.165 + IMPORT_C TDialogMode DialogMode();
1.166 + IMPORT_C void Close();
1.167 + IMPORT_C TInt CurrentCipherSuite( TDes8& aCipherSuite );
1.168 + IMPORT_C void FlushSessionCache();
1.169 + IMPORT_C TInt GetOpt(TUint aOptionName, TUint aOptionLevel, TDes8& aOption);
1.170 + IMPORT_C TInt GetOpt(TUint aOptionName, TUint aOptionLevel, TInt& aOption);
1.171 + IMPORT_C TInt Protocol(TDes& aProtocol);
1.172 + IMPORT_C void Recv (TDes8& aDesc, TRequestStatus& aStatus );
1.173 + IMPORT_C void RecvOneOrMore( TDes8& aDesc, TRequestStatus& aStatus, TSockXfrLength& aLen );
1.174 + IMPORT_C void RenegotiateHandshake(TRequestStatus& aStatus );
1.175 + IMPORT_C void Send( const TDesC8& aDesc, TRequestStatus& aStatus, TSockXfrLength& aLen );
1.176 + IMPORT_C void Send( const TDesC8& aDesc, TRequestStatus& aStatus );
1.177 + IMPORT_C const CX509Certificate* ServerCert();
1.178 + IMPORT_C TInt SetAvailableCipherSuites(const TDesC8& aCiphers);
1.179 + IMPORT_C TInt SetClientCert(const CX509Certificate& aCert);
1.180 + IMPORT_C TInt SetClientCertMode(const TClientCertMode aClientCertMode);
1.181 + IMPORT_C TInt SetDialogMode(const TDialogMode aDialogMode);
1.182 + IMPORT_C TInt SetProtocol(const TDesC& aProtocol);
1.183 + IMPORT_C TInt SetOpt(TUint aOptionName, TUint aOptionLevel, const TDesC8& aOption=TPtrC8(NULL,0));
1.184 + IMPORT_C TInt SetOpt(TUint aOptionName, TUint aOptionLevel, TInt aOption);
1.185 + IMPORT_C TInt SetServerCert(const CX509Certificate& aCert);
1.186 + IMPORT_C void StartClientHandshake(TRequestStatus& aStatus);
1.187 + IMPORT_C void StartServerHandshake(TRequestStatus& aStatus);
1.188 +
1.189 +private:
1.190 + void ConstructL(RSocket& aSocket,const TDesC& aProtocol);
1.191 + void ConstructL(MGenericSecureSocket& aSocket,const TDesC& aProtocol);
1.192 +
1.193 + enum {ESecureSocketStateOpen, ESecureSocketStateClosed};
1.194 +
1.195 + TUint iSecureSocketState;
1.196 +
1.197 + TSecSockDllLibraryFunction iUNUSED;
1.198 + MSecureSocket* iSecureImplementation;
1.199 + };
1.200 +
1.201 +#endif // __SECURESOCKET_H__