messagingfw/wappushfw/plugins/PushSecurity/CGTPushSecurityPolicy.cpp
changeset 62 db3f5fa34ec7
parent 0 8e480a14352b
equal deleted inserted replaced
60:9f5ae1728557 62:db3f5fa34ec7
       
     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 "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Implements all the WapPushSecurity plugin classes contained within
       
    15 // this plugin DLL
       
    16 // // DISCLAIMER - THIS SOURCE FILE CONTAINS DUMMY POLICIES FOR TESTING PURPOSES //
       
    17 // //              ONLY.  IT SHOULD NOT FORM PART OF FINAL DELIVERABLE SOFTWARE. //
       
    18 // //              IN REALITY, DELIVERABLE SOFTWARE SHOULD REFLECT ACTUAL        //
       
    19 // //              LICENSEE OR NETWORK PROVIDER SECURITY POLICY.                 //
       
    20 // 
       
    21 //
       
    22 
       
    23 // Local includes
       
    24 #include "CGTPushSecurityPolicy.h"
       
    25 
       
    26 // Constants
       
    27 _LIT(KReserved, "Reserved");
       
    28 
       
    29 TAny* CGTPushSecurityPolicy::Extend_CPushSecurityPolicy1(TAny* aArg)
       
    30 	{
       
    31 	User::Panic(KReserved, KErrNotSupported);
       
    32 	return aArg;
       
    33 	}
       
    34 
       
    35 TAny* CGTPushSecurityPolicy::Extend_CPushSecurityPolicy2(TAny* aArg)
       
    36 	{
       
    37 	User::Panic(KReserved, KErrNotSupported);
       
    38 	return aArg;
       
    39 	}
       
    40 
       
    41 /**
       
    42  * Implementation of class CGTPushSecurityPolicy
       
    43  */
       
    44 
       
    45 /**
       
    46  * Standard plugin constructor
       
    47  * Return				: nothing
       
    48  * Error Behaviour		: none, cannot fail.
       
    49  * Post Conditions		: constructed class with partial initialisation.
       
    50 */
       
    51 CGTPushSecurityPolicy::CGTPushSecurityPolicy()
       
    52 : CPushSecurityPolicy()
       
    53 	{
       
    54 	}
       
    55 
       
    56 /**
       
    57  * Complete the initialisation of the plugin
       
    58  * May leave if any part of initialisation fails
       
    59  * Post-Condition : Fully initialised class when successful.
       
    60  */
       
    61 void CGTPushSecurityPolicy::ConstructL()
       
    62 	{
       
    63 	}
       
    64 
       
    65 /**
       
    66  * Create an instance of a CGTPushSecurityPolicy on the heap
       
    67  * Leaving if the instance cannot be fully initialised.
       
    68  * Nothing is left on the cleanup stack
       
    69  *
       
    70  * Rtn: a new CHTTPManager object, by ptr. Ownership is transferred to the
       
    71  *      caller.
       
    72  */
       
    73 CGTPushSecurityPolicy* CGTPushSecurityPolicy::NewL()
       
    74 	{
       
    75 	CGTPushSecurityPolicy* self = new (ELeave) CGTPushSecurityPolicy;
       
    76 	CleanupStack::PushL(self);
       
    77 	self->ConstructL();
       
    78 	CleanupStack::Pop(self);
       
    79 	return self;
       
    80 	}
       
    81 
       
    82 // Default d'tor. Removes this object and releases memory held by it
       
    83 CGTPushSecurityPolicy::~CGTPushSecurityPolicy()
       
    84 	{
       
    85 	}
       
    86 
       
    87 
       
    88 /**
       
    89  * Methods inherited from CSecurityPolicy
       
    90  */
       
    91 
       
    92 /**
       
    93  * Is anonymous authentication allowed?
       
    94  *
       
    95  * Rtn: ETrue if anonymous authentication can be allowed
       
    96  */
       
    97 TBool CGTPushSecurityPolicy::AnonymousAuthenticationAllowed()
       
    98 	{
       
    99 	// This GT Plug-in doesn't allow anonymous authentication.
       
   100 	//__LOG_ENTER(_L("CGTPushSecurityPolicy::AnonymousAuthenticationAllowed"));
       
   101 	return ETrue;
       
   102 	}
       
   103 
       
   104 /**
       
   105  * Obtain the key exchange suite for WTLS, for a non-anonymous session (ie.
       
   106  * on in which the server-certificate is obtained and authenticated)
       
   107  *
       
   108  * Out:
       
   109  *  aSuite	- the key exchange suite desired for WTLS
       
   110  *  aIdType	- the ID type desired for WTLS
       
   111  *  aKeyId	- the key ID desired for WTLS
       
   112  *
       
   113  * Rtn: ETrue if the default is to be overridden
       
   114  */
       
   115 TBool CGTPushSecurityPolicy::GetKeyExchangeSuiteNormal(
       
   116 								RWTLS::TKeyExchangeSuite& aSuite,
       
   117 								RWTLS::TIdType& aIdType,
       
   118 								TDes8& aKeyId
       
   119 								)
       
   120 	{
       
   121 	//
       
   122 	// NB DISCLAIMER - THIS IS A DUMMY POLICY FOR TESTING PURPOSES ONLY.   //
       
   123 	//                 IN REALITY, DELIVERABLE SOFTWARE SHOULD REFLECT     //
       
   124 	//                 ACTUAL LICENSEE/NETWORK PROVIDER POLICY.            //
       
   125 	//
       
   126 	//__LOG_ENTER(_L("CGTPushSecurityPolicy::GetKeyExchangeSuiteNormal"));
       
   127 	TBool retVal = EFalse;
       
   128 	switch (iKeyExchangeSuitesSet)
       
   129 		{
       
   130 		case 0:
       
   131 			{
       
   132 			aSuite = RWTLS::ERsa512;
       
   133 			aIdType = RWTLS::EIdNull;
       
   134 			aKeyId.Copy(KNullDesC8);
       
   135 			retVal = ETrue;
       
   136 			iKeyExchangeSuitesSet++;
       
   137 			} break;
       
   138 		case 1:
       
   139 			{
       
   140 			aSuite = RWTLS::ERsa768;
       
   141 			aIdType = RWTLS::EIdNull;
       
   142 			aKeyId.Copy(KNullDesC8);
       
   143 			retVal = ETrue;
       
   144 			iKeyExchangeSuitesSet++;
       
   145 			} break;
       
   146 		case 2:
       
   147 			{
       
   148 			// No more key exchange suites to be set...
       
   149 			retVal = EFalse;
       
   150 			}
       
   151 		}
       
   152 	//__LOG_RETURN;
       
   153 	return retVal;
       
   154 	}
       
   155 
       
   156 /**
       
   157  * Obtain the key exchange suite for WTLS, for an anonymous session (ie.
       
   158  * on in which no server-certificate is obtained)
       
   159  *
       
   160  * Out:
       
   161  *  aSuite	- the key exchange suite desired for WTLS
       
   162  *  aIdType	- the ID type desired for WTLS
       
   163  *  aKeyId	- the key ID desired for WTLS
       
   164  *
       
   165  * Rtn: ETrue if the default is to be overridden
       
   166  */
       
   167 TBool CGTPushSecurityPolicy::GetKeyExchangeSuiteAnon(
       
   168 								RWTLS::TKeyExchangeSuite& aSuite,
       
   169 								RWTLS::TIdType& aIdType,
       
   170 								TDes8& aKeyId
       
   171 								)
       
   172 	{
       
   173 	//
       
   174 	// NB DISCLAIMER - THIS IS A DUMMY POLICY FOR TESTING PURPOSES ONLY.   //
       
   175 	//                 IN REALITY, DELIVERABLE SOFTWARE SHOULD REFLECT     //
       
   176 	//                 ACTUAL LICENSEE/NETWORK PROVIDER POLICY.            //
       
   177 	//
       
   178 	//__LOG_ENTER(_L("CGTPushSecurityPolicy::GetKeyExchangeSuiteAnon"));
       
   179 	TBool retVal = EFalse;
       
   180 	switch (iKeyExchangeSuitesSet)
       
   181 		{
       
   182 		case 0:
       
   183 			{
       
   184 			aSuite = RWTLS::ERsaAnon512;
       
   185 			aIdType = RWTLS::EIdNull;
       
   186 			aKeyId.Copy(KNullDesC8);
       
   187 			retVal = ETrue;
       
   188 			iKeyExchangeSuitesSet++;
       
   189 			} break;
       
   190 		case 1:
       
   191 			{
       
   192 			aSuite = RWTLS::ERsaAnon768;
       
   193 			aIdType = RWTLS::EIdNull;
       
   194 			aKeyId.Copy(KNullDesC8);
       
   195 			retVal = ETrue;
       
   196 			iKeyExchangeSuitesSet++;
       
   197 			} break;
       
   198 		case 2:
       
   199 			{
       
   200 			// No more key exchange suites to be set...
       
   201 			retVal = EFalse;
       
   202 			}
       
   203 		}
       
   204 	//__LOG_RETURN;
       
   205 	return retVal;
       
   206 	}
       
   207 
       
   208 /**
       
   209  * Obtain the number of cipher suites desired for WTLS
       
   210  *
       
   211  * Out:
       
   212  *  aNumCipherSuites - the number of cipher suites to be requested
       
   213  *
       
   214  * Rtn: ETrue if the default is to be overridden
       
   215  */
       
   216 TBool CGTPushSecurityPolicy::GetNumCipherSuites(TInt& aNumCipherSuites)
       
   217 	{
       
   218 	//
       
   219 	// NB DISCLAIMER - THIS IS A DUMMY POLICY FOR TESTING PURPOSES ONLY.   //
       
   220 	//                 IN REALITY, DELIVERABLE SOFTWARE SHOULD REFLECT     //
       
   221 	//                 ACTUAL LICENSEE/NETWORK PROVIDER POLICY.            //
       
   222 	//
       
   223 	//__LOG_ENTER(_L("CGTPushSecurityPolicy::GetNumCipherSuites"));
       
   224 	// We support four different suites (see next method)
       
   225 	aNumCipherSuites = 4;
       
   226 	//__LOG_RETURN;
       
   227 	return ETrue;
       
   228 	}
       
   229 
       
   230 /**
       
   231  * Obtain the cipher suites desired for WTLS - an array of TCipherSuite
       
   232  *
       
   233  * Out:
       
   234  *  aCipherSuites - the cipher suites to be requested
       
   235  *
       
   236  * Rtn: ETrue if the default is to be overridden
       
   237  */
       
   238 TBool CGTPushSecurityPolicy::GetCipherSuitesL(RWTLS::CipherSuiteArray& aCipherSuites)
       
   239 	{
       
   240 	//
       
   241 	// NB DISCLAIMER - THIS IS A DUMMY POLICY FOR TESTING PURPOSES ONLY.   //
       
   242 	//                 IN REALITY, DELIVERABLE SOFTWARE SHOULD REFLECT     //
       
   243 	//                 ACTUAL LICENSEE/NETWORK PROVIDER POLICY.            //
       
   244 	//
       
   245 	//__LOG_ENTER(_L("CGTPushSecurityPolicy::GetCipherSuitesL"));
       
   246 	// Add the four suites we support to the supplied array
       
   247 	RWTLS::TCipherSuite suite1 = {RWTLS::ERc5_cbc_56, RWTLS::ESha};
       
   248 	aCipherSuites.AppendL(suite1);
       
   249 	RWTLS::TCipherSuite suite2 = {RWTLS::ERc5_cbc_56, RWTLS::ESha_80};
       
   250 	aCipherSuites.AppendL(suite2);
       
   251 	RWTLS::TCipherSuite suite3 = {RWTLS::ERc5_cbc_56, RWTLS::ESha_40};
       
   252 	aCipherSuites.AppendL(suite3);
       
   253 	RWTLS::TCipherSuite suite4 = {RWTLS::ERc5_cbc_40, RWTLS::ESha};
       
   254 	aCipherSuites.AppendL(suite4);
       
   255 	//__LOG_RETURN;
       
   256 	return ETrue;
       
   257 	}
       
   258 
       
   259 /**
       
   260  * Obtain the key refresh rate for WTLS
       
   261  *
       
   262  * Out:
       
   263  *  aRate - the rate value desired. Refreshing occurs every 2^aRate msgs
       
   264  *
       
   265  * Rtn: ETrue if the default is to be overridden
       
   266  */
       
   267 TBool CGTPushSecurityPolicy::GetKeyRefreshRate(TUint8& aRate)
       
   268 	{
       
   269 	//
       
   270 	// NB DISCLAIMER - THIS IS A DUMMY POLICY FOR TESTING PURPOSES ONLY.   //
       
   271 	//                 IN REALITY, DELIVERABLE SOFTWARE SHOULD REFLECT     //
       
   272 	//                 ACTUAL LICENSEE/NETWORK PROVIDER POLICY.            //
       
   273 	//
       
   274 	//__LOG_ENTER(_L("CGTPushSecurityPolicy::GetKeyRefreshRate"));
       
   275 	// Set a rate of 3 - ie. keys are refreshed after every 2^3 messages
       
   276 	aRate = 3;
       
   277 	//__LOG_RETURN;
       
   278 	return ETrue;
       
   279 	}
       
   280 
       
   281 /**
       
   282  * Obtain the sequence number mode desired for WTLS
       
   283  *
       
   284  * Out:
       
   285  *  aMode - the desired mode
       
   286  *
       
   287  * Rtn: ETrue if the default is to be overridden
       
   288  */
       
   289 TBool CGTPushSecurityPolicy::GetSequenceNumberMode(RWTLS::TSequenceNumberMode& aMode)
       
   290 	{
       
   291 	//
       
   292 	// NB DISCLAIMER - THIS IS A DUMMY POLICY FOR TESTING PURPOSES ONLY.   //
       
   293 	//                 IN REALITY, DELIVERABLE SOFTWARE SHOULD REFLECT     //
       
   294 	//                 ACTUAL LICENSEE/NETWORK PROVIDER POLICY.            //
       
   295 	//
       
   296 	//__LOG_ENTER(_L("CGTPushSecurityPolicy::GetSequenceNumberMode"));
       
   297 	// Sequence number mode is not used
       
   298 	aMode = RWTLS::ENotUsed;
       
   299 	//__LOG_RETURN;
       
   300 	return ETrue;
       
   301 	}
       
   302 /**
       
   303  * Obtain the record length usage flag for WTLS
       
   304  *
       
   305  * Out:
       
   306  *  aUseRecordLengthFlag : ETrue if record length usage is desired for WTLS
       
   307  *
       
   308  * Rtn: ETrue if the default is to be overridden
       
   309  */
       
   310 TBool CGTPushSecurityPolicy::GetRecordLengthUsage(TBool& aUseRecordLengthFlag)
       
   311 	{
       
   312 	//
       
   313 	// NB DISCLAIMER - THIS IS A DUMMY POLICY FOR TESTING PURPOSES ONLY.   //
       
   314 	//                 IN REALITY, DELIVERABLE SOFTWARE SHOULD REFLECT     //
       
   315 	//                 ACTUAL LICENSEE/NETWORK PROVIDER POLICY.            //
       
   316 	//
       
   317 	//__LOG_ENTER(_L("CGTPushSecurityPolicy::GetRecordLengthUsage"));
       
   318 	// Record length is not used
       
   319 	aUseRecordLengthFlag = EFalse;
       
   320 	//__LOG_RETURN;
       
   321 	return ETrue;
       
   322 	}
       
   323 
       
   324 /**
       
   325  * Obtain the shared secret used for WTLS
       
   326  *
       
   327  * Out:
       
   328  *  aSharedSecret - the shared secret data
       
   329  *
       
   330  * Rtn: ETrue if the default is to be overridden
       
   331  */
       
   332 TBool CGTPushSecurityPolicy::GetSharedSecretLC(HBufC8*& aSharedSecret)
       
   333 	{
       
   334 	//
       
   335 	// NB DISCLAIMER - THIS IS A DUMMY POLICY FOR TESTING PURPOSES ONLY.   //
       
   336 	//                 IN REALITY, DELIVERABLE SOFTWARE SHOULD REFLECT     //
       
   337 	//                 ACTUAL LICENSEE/NETWORK PROVIDER POLICY.            //
       
   338 	//
       
   339 	//__LOG_ENTER(_L("CGTPushSecurityPolicy::GetSharedSecretLC"));
       
   340 	// Shared secret is not used
       
   341 	aSharedSecret = NULL;
       
   342 	//__LOG_RETURN;
       
   343 	return EFalse;
       
   344 	}
       
   345 /**
       
   346  * Find out what action to take with the actual ciphers negotiated with
       
   347  * the stack
       
   348  *
       
   349  * In:
       
   350  *  aSuite	- the negotiated cipher suite, or NULL if none was reported by
       
   351  *            the stack
       
   352  *  aMode	- the negotiated mode, or NULL if none was reported by the stack
       
   353  *
       
   354  * Rtn: TCipherResponse enumerates the response to be taken
       
   355  */
       
   356 CPushSecurityPolicy::TCipherResponse
       
   357 CGTPushSecurityPolicy::GetNegotiatedCipherAction(
       
   358 									RWTLS::TCipherSuite* aSuite,
       
   359 									RWTLS::TSequenceNumberMode* aMode
       
   360 									)
       
   361 	{
       
   362 	//
       
   363 	// NB DISCLAIMER - THIS IS A DUMMY POLICY FOR TESTING PURPOSES ONLY.   //
       
   364 	//                 IN REALITY IT SHOULD CHECK THE ACTUAL CIPHER VALUES //
       
   365 	//                 AGAINST THOSE REQUESTED TO DETERMINE THEIR          //
       
   366 	//                 ACCEPTABILITY.                                      //
       
   367 	//
       
   368 
       
   369 	// Check the values negotiated with the stack. Check for the worst case
       
   370 	// first
       
   371 	if ((aSuite == NULL) && (aMode == NULL))
       
   372 		{
       
   373 		// Nothing negotiated at all - never complete the connection
       
   374 		return CPushSecurityPolicy::ENeverConnect;
       
   375 		}
       
   376 	else if ((aSuite == NULL) || (aMode == NULL))
       
   377 		{
       
   378 		// One thing was negotiated out of two - ask the user
       
   379 		return CPushSecurityPolicy::EAskToConnect;
       
   380 		}
       
   381 	else
       
   382 		{
       
   383 		// Both things negotiated ok - connect unconditionally
       
   384 		return CPushSecurityPolicy::EAlwaysConnect;
       
   385 		}
       
   386 	}