policymanagement/dmutilserver/src/DMUtilServer.cpp
changeset 0 b497e44ab2fc
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2000 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Implementation of policymanagement components
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDES
       
    21 
       
    22 #include <e32svr.h>
       
    23 #include <centralrepository.h>
       
    24 
       
    25 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
    26 const TUid KUidSmlSyncAgentCategory = { 0x10009F46 }; // temporary
       
    27 const TUint KHttpsServerCertificateKey = 1234; // temporary
       
    28 #else
       
    29 // nothing
       
    30 #endif
       
    31 
       
    32 #include <SyncMLClient.h>
       
    33 #include <SyncMLClientDM.h>
       
    34  
       
    35 #include "ACLStorage.h"
       
    36 #include "DMUtilServer.h"
       
    37 #include "DMUtilSession.h"
       
    38 #include "debug.h"
       
    39 
       
    40 
       
    41 // CONSTANTS
       
    42 
       
    43 /**
       
    44     Ranges of policies
       
    45 */
       
    46 const TInt   CDMUtilServer::tcRanges[DMUTILSERVER_NUMBER_OF_POLICIES] = {0, EPerformDMUtilRFS, ERemoveACL};
       
    47 
       
    48 /**
       
    49     Number of elements
       
    50 */
       
    51 const TUint8 CDMUtilServer::tcElementsIndex[DMUTILSERVER_NUMBER_OF_POLICIES] = {0, 1, 2};
       
    52 
       
    53 /**
       
    54     Elements for each range
       
    55 */    
       
    56 const CPolicyServer::TPolicyElement CDMUtilServer::tcElements[DMUTILSERVER_NUMBER_OF_POLICIES] =
       
    57 	    {
       
    58         { _INIT_SECURITY_POLICY_PASS },
       
    59         { _INIT_SECURITY_POLICY_S0(0x102073EA) },	// RFs SID
       
    60         { _INIT_SECURITY_POLICY_S0(0x10207814) }
       
    61 	    };
       
    62 
       
    63 /**
       
    64     The policy 
       
    65 */
       
    66 CPolicyServer::TPolicy CDMUtilServer::iTcConnectionPolicy =
       
    67     {
       
    68         CPolicyServer::ECustomCheck, // On connection, check for policies
       
    69         1,
       
    70         tcRanges,
       
    71         tcElementsIndex,
       
    72         tcElements
       
    73     };
       
    74 
       
    75 
       
    76 // MACROS
       
    77 
       
    78 #define __INCLUDE_CAPABILITY_NAMES__
       
    79 
       
    80 // DATA TYPES
       
    81 // FUNCTION PROTOTYPES
       
    82 // FORWARD DECLARATIONS
       
    83 
       
    84 CACLStorage* CDMUtilServer::iACLs = 0;
       
    85 TBool CDMUtilServer::iManagementActive = EFalse;
       
    86 
       
    87 
       
    88 
       
    89 
       
    90 // ----------------------------------------------------------------------------------------
       
    91 // Server startup code
       
    92 // ----------------------------------------------------------------------------------------
       
    93 static void RunServerL()
       
    94 	{
       
    95 	// naming the server thread after the server helps to debug panics
       
    96 	//User::LeaveIfError(RThread().Rename(KDMUtilServerName));   //Deprecated! Replace this with the line below as soon as possible
       
    97 	User::LeaveIfError(User::RenameThread(KDMUtilServerName)); //Correct PlatSec function, not available until week 2004_32
       
    98 
       
    99 	// create and install the active scheduler
       
   100 
       
   101 	CActiveScheduler* s=new(ELeave) CActiveScheduler;
       
   102 	CleanupStack::PushL(s);
       
   103 	CActiveScheduler::Install(s);
       
   104 
       
   105 	// create the server (leave it on the cleanup stack)
       
   106 	CDMUtilServer::NewLC();
       
   107 	// Initialisation complete, now signal the client
       
   108 
       
   109 	RProcess::Rendezvous(KErrNone);
       
   110 
       
   111 	// Ready to run
       
   112 	RDEBUG("DMUtilServer is running");
       
   113 	CActiveScheduler::Start();
       
   114 	RDEBUG("DMUtilServer has stopped");
       
   115 
       
   116 	// Cleanup the server and scheduler
       
   117 	CleanupStack::PopAndDestroy(2);
       
   118 	}
       
   119 
       
   120 // Server process entry-point
       
   121 TInt E32Main()
       
   122 	{
       
   123 	__UHEAP_MARK;
       
   124 	RDEBUG("DMUtilServer: E32Main");
       
   125 	CTrapCleanup* cleanup=CTrapCleanup::New();
       
   126 	TInt r=KErrNoMemory;
       
   127 	if (cleanup)
       
   128 		{
       
   129 		TRAP(r,RunServerL());
       
   130 		RDEBUG_2("DMUtilServer closed with code: %d", r);
       
   131 		delete cleanup;
       
   132 		}
       
   133 	__UHEAP_MARKEND;
       
   134 	return r;
       
   135 	}
       
   136     
       
   137 // RMessagePtr2::Panic() also completes the message. This is:
       
   138 // (a) important for efficient cleanup within the kernel
       
   139 // (b) a problem if the message is completed a second time
       
   140 void PanicClient(const RMessagePtr2& aMessage,TDMUtilPanic aPanic)
       
   141 	{
       
   142 	_LIT(KPanic,"DMUtilServer");
       
   143 	aMessage.Panic(KPanic,aPanic);
       
   144 	}
       
   145 
       
   146 // ----------------------------------------------------------------------------------------
       
   147 // CDMUtilServer
       
   148 // ----------------------------------------------------------------------------------------
       
   149 CDMUtilServer::CDMUtilServer()
       
   150 	:CPolicyServer(0, 
       
   151     iTcConnectionPolicy,
       
   152 	ESharableSessions),
       
   153 	iServerID(0)
       
   154 	{
       
   155 	}
       
   156 
       
   157 // ----------------------------------------------------------------------------------------
       
   158 // CDMUtilServer::CertificateChangedL
       
   159 // ----------------------------------------------------------------------------------------
       
   160 void CDMUtilServer::CertificateChangedL()
       
   161     {
       
   162     RDEBUG("DMUtilServer: CDMUtilServer::CertificateChangedL");
       
   163     TRAPD( reason, UpdateSessionInfoL() );
       
   164     if( KErrNone != reason )
       
   165         {
       
   166         RDEBUG("DMUtilServer: ERROR Failed to update certificate!");
       
   167         iACLs->CloseSession();
       
   168 		iManagementActive = EFalse;
       
   169         CDMUtilSession::SetIndicatorStateL( 0 );
       
   170         }
       
   171     else
       
   172         {
       
   173         RDEBUG("DMUtilServer: Starting new session, updating ACLs");
       
   174         UpdateACLsL();
       
   175         }
       
   176     }
       
   177 
       
   178 // ----------------------------------------------------------------------------------------
       
   179 // CDMUtilServer::NotifierErrorL
       
   180 // ----------------------------------------------------------------------------------------
       
   181 void CDMUtilServer::NotifierErrorL( TInt aCode )
       
   182     {
       
   183     RDEBUG_2("CDMUtilServer::NotifierErrorL Certificate notifier error %d", aCode);
       
   184 
       
   185     if( KErrAbort == aCode )
       
   186         {
       
   187         RDEBUG("**** DMUtilServer::NotifierErrorL KErrAbort == aCode");
       
   188         iNotifier.StartL( this );
       
   189         }
       
   190     }
       
   191 
       
   192 // ----------------------------------------------------------------------------------------
       
   193 // CDMUtilServer::NewLC
       
   194 // ----------------------------------------------------------------------------------------
       
   195 CServer2* CDMUtilServer::NewLC()
       
   196 	{    
       
   197 	RDEBUG("CDMUtilServer::NewLC - start");
       
   198 	
       
   199 	CDMUtilServer* self=new(ELeave) CDMUtilServer;
       
   200 	CleanupStack::PushL(self);
       
   201 	self->ConstructL();
       
   202 	RDEBUG("CDMUtilServer::NewLC - end");
       
   203 	return self;
       
   204 	}
       
   205 
       
   206 // ----------------------------------------------------------------------------------------
       
   207 // CDMUtilServer::~CDMUtilServer
       
   208 // ----------------------------------------------------------------------------------------
       
   209 CDMUtilServer::~CDMUtilServer()
       
   210 	{
       
   211 	RDEBUG("CDMUtilServer::~CDMUtilServer()");
       
   212     delete iServerID; iServerID=0;
       
   213     delete iACLs;
       
   214 	}
       
   215 
       
   216 // ----------------------------------------------------------------------------------------
       
   217 // CDMUtilServer::ConstructL
       
   218 // 2nd phase construction - ensure the timer and server objects are running
       
   219 // ----------------------------------------------------------------------------------------
       
   220 void CDMUtilServer::ConstructL()
       
   221 	{
       
   222 	RDEBUG("CDMUtilServer::ConstructL");
       
   223 	StartL(KDMUtilServerName);
       
   224 	
       
   225 	CDMUtilSession::DefinePropertiesL();
       
   226 
       
   227     iACLs = CACLStorage::NewL();
       
   228 
       
   229     TRAPD( reason, UpdateSessionInfoL() );
       
   230     if( KErrNone != reason )
       
   231         {
       
   232         RDEBUG("DMUtilServer: Failed to update certificate");
       
   233         }
       
   234     else
       
   235         {
       
   236         RDEBUG("	CDMUtilServer::ConstructL	UPDATING ACLs ....");
       
   237         UpdateACLsL();
       
   238         RDEBUG("	CDMUtilServer::ConstructL	UPDATING ACLs ....DONE!");
       
   239         }
       
   240             
       
   241     iNotifier.StartL( this );
       
   242     }
       
   243 
       
   244 // ----------------------------------------------------------------------------------------
       
   245 // CDMUtilServer::UpdateSessionInfoL
       
   246 // ----------------------------------------------------------------------------------------
       
   247 void CDMUtilServer::UpdateSessionInfoL()
       
   248     {
       
   249 	RDEBUG("CDMUtilServer::UpdateSessionInfoL");
       
   250     TPckg<TCertInfo> certp( iCertInfo );
       
   251     certp.Fill( TChar(0) );
       
   252     delete iServerID; iServerID=0;
       
   253 
       
   254     iServerID = GetServerIDL();
       
   255     if( iServerID != 0 )
       
   256         {
       
   257         if( KErrNone != GetCertFromCentRep() )
       
   258             {
       
   259             RDEBUG("**** CDMUtilServer::UpdateSessionInfoL - unable to get certificate from cenrep");
       
   260             delete iServerID; iServerID=0;
       
   261             }
       
   262         else
       
   263         	{
       
   264         	if ( IsSilentModeAllowed() )
       
   265             	{
       
   266             	iManagementActive = ETrue;
       
   267             	}
       
   268 			CDMUtilSession::SetIndicatorStateL(0);
       
   269             }
       
   270             
       
   271         }
       
   272     }
       
   273 
       
   274 
       
   275 
       
   276 CACLStorage * CDMUtilServer::ACLStorage()
       
   277 	{
       
   278 	return iACLs;
       
   279 	}
       
   280 
       
   281 
       
   282 // ----------------------------------------------------------------------------------------
       
   283 // CDMUtilServer::GetServerIDL
       
   284 // ----------------------------------------------------------------------------------------
       
   285 HBufC8* CDMUtilServer::GetServerIDL()
       
   286     {
       
   287     HBufC8* serverId = NULL;
       
   288     
       
   289 	TRAPD( err, serverId = GetServerIDFromSyncMLSessionL() );
       
   290 	if( err == KErrNone )
       
   291 		{
       
   292 		return serverId;
       
   293 		}
       
   294 		
       
   295 	serverId = GetServerIDFromLocalCacheL();
       
   296 	if( serverId == NULL )
       
   297 		{
       
   298 		User::Leave( KErrNotFound );
       
   299 		}
       
   300 	
       
   301 	return serverId;
       
   302     }
       
   303 
       
   304 HBufC8* CDMUtilServer::GetServerIDFromSyncMLSessionL()
       
   305 	{
       
   306 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
   307 	RDEBUG("CDMUtilServer::GetServerIDFromSyncMLSessionL() ......");
       
   308     HBufC8* serverIdStr = 0;
       
   309 
       
   310 	RSyncMLSession ses;
       
   311 	ses.OpenL();
       
   312 	CleanupClosePushL( ses );
       
   313 
       
   314 	TSmlJobId jid;
       
   315 	TSmlUsageType jtype;
       
   316     ses.CurrentJobL( jid, jtype );
       
   317     RSyncMLDevManJob job;
       
   318     job.OpenL( ses, jid );
       
   319     CleanupClosePushL( job );
       
   320 
       
   321 	TSmlProfileId pid( job.Profile() );
       
   322 
       
   323 	RSyncMLDevManProfile profile;
       
   324 	profile.OpenL( ses, pid );
       
   325 	CleanupClosePushL( profile );
       
   326 
       
   327 	serverIdStr = profile.ServerId().AllocL();
       
   328 
       
   329 	CleanupStack::PopAndDestroy( &profile );
       
   330 	CleanupStack::PopAndDestroy( &job );
       
   331 	CleanupStack::PopAndDestroy( &ses );
       
   332 
       
   333 	RDEBUG("CDMUtilServer::GetServerIDFromSyncMLSessionL ......DONE!");
       
   334 	return serverIdStr;
       
   335 #else
       
   336 RDEBUG("CDMUtilServer::GetServerIDFromSyncMLSessionL ......");
       
   337     HBufC8* serverIdStr = 0;
       
   338 
       
   339 	RSyncMLSession ses;
       
   340 	ses.OpenL();
       
   341 	CleanupClosePushL( ses );
       
   342 
       
   343 	TSmlJobId jid;
       
   344 	TSmlUsageType jtype;
       
   345     ses.CurrentJobL(jid, jtype );
       
   346     RSyncMLDevManJob job;
       
   347     job.OpenL( ses, jid );
       
   348     CleanupClosePushL( job );
       
   349 
       
   350     TSmlProfileId pid( job.Profile() );
       
   351     RSyncMLDevManProfile prof;
       
   352     prof.OpenL( ses, pid, ESmlOpenRead );
       
   353     CleanupClosePushL( prof );
       
   354 
       
   355 	serverIdStr = prof.ServerId().AllocL();
       
   356 
       
   357 	CleanupStack::PopAndDestroy( &prof );
       
   358 	CleanupStack::PopAndDestroy( &job );
       
   359 	CleanupStack::PopAndDestroy( &ses );
       
   360 
       
   361 	RDEBUG("CDMUtilServer::GetServerIDFromSyncMLSessionL ......DONE!");
       
   362 	return serverIdStr;
       
   363 #endif
       
   364 	}
       
   365 
       
   366 HBufC8* CDMUtilServer::GetServerIDFromLocalCacheL()
       
   367 	{
       
   368 	RDEBUG("CDMUtilServer::GetServerIDFromLocalCacheL ......");
       
   369 	if( iServerID )
       
   370 		{
       
   371 		RDEBUG("CDMUtilServer::GetServerIDFromLocalCacheL ......DONE!");
       
   372 		return iServerID->AllocL();
       
   373 		}
       
   374 	
       
   375 	RDEBUG("CDMUtilServer::GetServerIDFromLocalCacheL ...... **** NOT FOUND!");
       
   376 	return NULL;
       
   377 	}
       
   378 
       
   379 // ----------------------------------------------------------------------------------------
       
   380 // CDMUtilServer::GetCertFromCentRep
       
   381 // ----------------------------------------------------------------------------------------
       
   382 TInt CDMUtilServer::GetCertFromCentRep()
       
   383     {
       
   384 	RDEBUG("CDMUtilServer::GetCertFromCentRep");
       
   385 	TInt result = KErrNone;
       
   386 	
       
   387 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
   388 	result = iNotifier.GetCert( iCertInfo );
       
   389 	if ( result != KErrNone ) 
       
   390 		{
       
   391 		RDEBUG_2("**** CDMUtilServer::GetCertFromCentRep ... NOT FOUND: %d", result );
       
   392 		result = KErrNotFound;
       
   393 		}
       
   394 #else	
       
   395     TCertInfo info;
       
   396 	CRepository *rep = NULL;
       
   397 	TRAP( result, rep = CRepository::NewL ( KCRUidPolicyManagementUtilInternalKeys ) );
       
   398 	if (result == KErrNone )
       
   399 		{
       
   400 		TPckg<TCertInfo> pcert( iCertInfo );
       
   401 		TInt len( 0 );
       
   402 		result = rep->Get( KSyncMLSessionCertificate, pcert, len );
       
   403 		delete rep;
       
   404 		if ( len == 0 ) 
       
   405 			{
       
   406 			RDEBUG("**** CDMUtilServer::GetCertFromCentRep ... NOT FOUND");
       
   407 			result = KErrNotFound;
       
   408 			}
       
   409 		}
       
   410 #endif	
       
   411 
       
   412 	return result;
       
   413     }
       
   414 
       
   415 
       
   416 // ----------------------------------------------------------------------------------------
       
   417 // CDMUtilServer::IsSilentModeAllowed
       
   418 // ----------------------------------------------------------------------------------------
       
   419 TBool CDMUtilServer::IsSilentModeAllowed()
       
   420     {
       
   421 	RDEBUG("CDMUtilServer::IsSilentModeAllowed()");
       
   422 	CRepository *rep = NULL;
       
   423     TInt result = KErrNone;
       
   424 	TRAP( result, rep = CRepository::NewL ( KCRUidPolicyManagementUtilInternalKeys ) );
       
   425 	if (result == KErrNone )
       
   426 		{
       
   427 		TInt state( 0 );
       
   428 		result = rep->Get( KSyncMLForcedCertificateCheckKey, state );
       
   429 		delete rep;
       
   430 		if ( state == 1 ) 
       
   431 			{
       
   432 			RDEBUG("CDMUtilServer::IsSilentModeAllowed ... allowed");
       
   433 			return ETrue;
       
   434 			}
       
   435 		else
       
   436 			{
       
   437 			RDEBUG("CDMUtilServer::IsSilentModeAllowed ... NOT allowed");
       
   438 			}
       
   439 		}
       
   440 	return EFalse;
       
   441     }
       
   442 
       
   443 
       
   444 // ----------------------------------------------------------------------------------------
       
   445 // CDMUtilServer::UpdateACLs
       
   446 // ----------------------------------------------------------------------------------------
       
   447 TInt CDMUtilServer::UpdateACLsL()
       
   448     {
       
   449     RDEBUG("CDMUtilServer::UpdateACLsL()");
       
   450     
       
   451     if( NULL != iServerID )
       
   452         {
       
   453         TRAPD( reason, iACLs->NewSessionL( iCertInfo, *iServerID ) );
       
   454         RDEBUG8_3("CDMUtilServer::UpdateACLs() ... iACLs->NewSessionL = %S with error: %d", &iServerID, reason);
       
   455         return reason;
       
   456         }
       
   457     else
       
   458         {
       
   459        	iACLs->CloseSession();
       
   460 	   	iManagementActive = EFalse;
       
   461        	CDMUtilSession::SetIndicatorStateL( 0 );
       
   462         }
       
   463         
       
   464     return KErrNone;
       
   465     }
       
   466 
       
   467 // ----------------------------------------------------------------------------------------
       
   468 // CDMUtilServer::NewSessionL
       
   469 // Create a new client session. This should really check the version number.
       
   470 // ----------------------------------------------------------------------------------------
       
   471 CSession2* CDMUtilServer::NewSessionL(const TVersion&,const RMessage2&) const
       
   472 	{
       
   473 	RDEBUG("CDMUtilServer::NewSessionL");
       
   474 	return new (ELeave) CDMUtilSession();
       
   475 	}
       
   476 
       
   477 // ----------------------------------------------------------------------------------------
       
   478 // CDMUtilServer::CustomSecurityCheckL
       
   479 // ----------------------------------------------------------------------------------------
       
   480 CPolicyServer::TCustomResult CDMUtilServer::CustomSecurityCheckL(const RMessage2& /*aMsg*/, TInt& /*aAction*/, TSecurityInfo& /*aMissing*/)
       
   481 	{
       
   482 	RDEBUG("CDMUtilServer::CustomSecurityCheckL");
       
   483 	return EPass;
       
   484 	}
       
   485 	
       
   486 
       
   487 
       
   488 
       
   489 // ----------------------------------------------------------------------------------------
       
   490 // ----------------------------------------------------------------------------------------
       
   491 // ----------------------------------------------------------------------------------------
       
   492 
       
   493 
       
   494 // ----------------------------------------------------------------------------------------
       
   495 // CDMCertNotifier::CDMCertNotifier
       
   496 // ----------------------------------------------------------------------------------------
       
   497 CDMCertNotifier::CDMCertNotifier()
       
   498     : CActive( EPriorityStandard )
       
   499     , iCallback( 0 )
       
   500 #ifdef __TARM_SYMBIAN_CONVERGENCY  
       
   501 // nothing
       
   502 #else    
       
   503     , iRepository(0)
       
   504 #endif    
       
   505     {
       
   506 	RDEBUG("CDMCertNotifier::CDMCertNotifier - start");
       
   507     CActiveScheduler::Add( this );
       
   508     
       
   509 #ifdef __TARM_SYMBIAN_CONVERGENCY //  
       
   510     TInt err = iCertificateProperty.Attach( KUidSmlSyncAgentCategory, KHttpsServerCertificateKey );
       
   511     RDEBUG_2("CDMCertNotifier::CDMCertNotifier() - Attached to P&S key with code: %d", err );
       
   512     __ASSERT_ALWAYS( err == KErrNone, User::Panic( _L("DMUtilServer P&S attach"), err ) );
       
   513 #else
       
   514 // nothing
       
   515 #endif    
       
   516 	RDEBUG("CDMCertNotifier::CDMCertNotifier - end");
       
   517     }
       
   518 
       
   519 // ----------------------------------------------------------------------------------------
       
   520 // CDMCertNotifier::~CDMCertNotifier
       
   521 // ----------------------------------------------------------------------------------------
       
   522 CDMCertNotifier::~CDMCertNotifier()
       
   523     {
       
   524 	RDEBUG("CDMCertNotifier::~CDMCertNotifier");
       
   525 #ifdef __TARM_SYMBIAN_CONVERGENCY  
       
   526 	iCertificateProperty.Close();
       
   527 #else
       
   528 	delete iRepository; 
       
   529     iRepository = 0;
       
   530 #endif	
       
   531     }
       
   532 
       
   533 // ----------------------------------------------------------------------------------------
       
   534 // CDMCertNotifier::Start
       
   535 // ----------------------------------------------------------------------------------------
       
   536 
       
   537 #ifdef __TARM_SYMBIAN_CONVERGENCY  
       
   538 void CDMCertNotifier::StartL( MDMCertNotifierCallback* aCallback )
       
   539 	{
       
   540 	RDEBUG("CDMCertNotifier::StartL.....");
       
   541 	
       
   542 	if( IsActive() )
       
   543         {
       
   544         Cancel();
       
   545         }
       
   546 
       
   547 	iCallback = aCallback;
       
   548 	
       
   549 	// initial cache reset
       
   550 	ResetCertCache();
       
   551 	
       
   552 	TCertInfo ci;
       
   553     TPckg<TCertInfo> certp( ci );
       
   554     certp.Fill( TChar( 0 ) );
       
   555     
       
   556     TInt err = iCertificateProperty.Get( certp );
       
   557     if( err == KErrNone )
       
   558     	{
       
   559     	RDEBUG("	initial certificate found, saving to cache .. ");
       
   560     	// content found, save to cache
       
   561     	SaveCertToCache();
       
   562     	RDEBUG("	initial certificate found, saving to cache .. done");
       
   563     	}
       
   564     
       
   565     // ask for notifications in certificate changes
       
   566     iCertificateProperty.Subscribe( iStatus );
       
   567     SetActive();
       
   568     RDEBUG("CDMCertNotifier::StartL.....end");
       
   569 	}
       
   570 #else // Nokia SyncML framework used
       
   571 void CDMCertNotifier::StartL( MDMCertNotifierCallback* aCallback )
       
   572     {
       
   573 	RDEBUG("CDMCertNotifier::StartL.....");
       
   574     if( IsActive() )
       
   575         {
       
   576         Cancel();
       
   577         }
       
   578 
       
   579     if( !IsActive() )
       
   580         {
       
   581         if( aCallback != 0)
       
   582             {
       
   583             iCallback = aCallback;
       
   584             }
       
   585 
       
   586         delete iRepository; iRepository = 0;
       
   587         iRepository = CRepository::NewL ( KCRUidPolicyManagementUtilInternalKeys );
       
   588 		// initial cache reset
       
   589 		ResetCertCache();
       
   590         
       
   591         TCertInfo ci;
       
   592         TPckg<TCertInfo> certp( ci );
       
   593         certp.Fill( TChar(0) );
       
   594 
       
   595         TInt result = iRepository->Get( KSyncMLSessionCertificate, certp );
       
   596         if( KErrNone == result )
       
   597             {
       
   598             // get initial cache content
       
   599             SaveCertToCache();
       
   600             if( KErrNone == iRepository->NotifyRequest( KSyncMLSessionCertificate, iStatus ) )
       
   601                 {
       
   602                 SetActive();
       
   603                 }
       
   604             }
       
   605         else
       
   606             {
       
   607             RDEBUG_2("**** CDMCertNotifier::StartL ERROR Failed to Get certificate repository key: %d", result);
       
   608             User::Leave( result );
       
   609             }
       
   610         }
       
   611     else
       
   612         {
       
   613     	RDEBUG("**** CDMCertNotifier::StartL: ERROR failed to start notifier");
       
   614         }
       
   615     RDEBUG("CDMCertNotifier::StartL....DONE!");
       
   616     }
       
   617 #endif
       
   618 
       
   619 
       
   620 
       
   621 void CDMCertNotifier::RunLToBeTrappedL()
       
   622 	{
       
   623 	RDEBUG_2("CDMCertNotifier::RunLToBeTrappedL( %d )", iStatus.Int() );
       
   624 
       
   625 	TInt status = iStatus.Int();
       
   626 
       
   627 #ifdef __TARM_SYMBIAN_CONVERGENCY  
       
   628 
       
   629 	// resubscribe before processing new value to prevent missing updates
       
   630 	iCertificateProperty.Subscribe( iStatus );
       
   631 	SetActive();
       
   632 #else
       
   633 // nothing, see the end of this function
       
   634 #endif
       
   635 
       
   636     // Report status to callback
       
   637     if( iCallback != 0 )
       
   638         {
       
   639 #ifdef __TARM_SYMBIAN_CONVERGENCY  
       
   640 		if( status == KErrNone )
       
   641 #else        
       
   642         if( status == KSyncMLSessionCertificate )
       
   643 #endif        
       
   644             {
       
   645             TSessionCertStatus certStatus = GetCertStatus();
       
   646             
       
   647             if( certStatus == ESessionCertContentZero )
       
   648             	{
       
   649             	// this case indicates that the DM session has been terminated
       
   650             	// -> clear the certificate cache
       
   651             	RDEBUG("	<-> session certificate notification - cert data reseted - reset cert cache");
       
   652             	ResetCertCache();
       
   653             	// this will eventually cause the indicator flag update
       
   654             	iCallback->CertificateChangedL();
       
   655             	}
       
   656             else
       
   657             if( certStatus == ESessionCertHasChanged )
       
   658             	{
       
   659             	RDEBUG("CDMCertNotifier::RunLToBeTrappedL: DM Certificate has changed");
       
   660             	// cache the new session certificate data
       
   661             	RDEBUG("	<-> session certificate notification - cert data changed - save cert to cache");
       
   662             	SaveCertToCache();
       
   663             	// notify (to update ACLs)
       
   664             	RDEBUG("	<-> session certificate notification - cert data changed - notify call-back");
       
   665             	iCallback->CertificateChangedL();
       
   666             	}
       
   667             else
       
   668             if( certStatus == ESessionCertNoChange )
       
   669             	{
       
   670             	// nothing to do <-> if the session certificate has not changed -> we have
       
   671             	// no need to update the ACLs
       
   672             	RDEBUG("	<-> session certificate notification - no change in the cert data - nothing to do");
       
   673             	}
       
   674             }
       
   675         else if( 0 > status )
       
   676             {
       
   677             RDEBUG("CDMCertNotifier::RunLToBeTrappedL: iCallback->NotifierErrorL( KErrGeneral );");
       
   678             iCallback->NotifierErrorL( status );
       
   679             }
       
   680         }
       
   681 
       
   682 #ifdef __TARM_SYMBIAN_CONVERGENCY  
       
   683 // nothing, see the start of this function
       
   684 #else
       
   685     // Start again anyway ...
       
   686     if( iRepository != 0 )
       
   687         {
       
   688         RDEBUG("CDMCertNotifier::RunLToBeTrappedL: iRepository->NotifyRequest( KSyncMLSessionCertificate, iStatus ) );");
       
   689         TInt err( iRepository->NotifyRequest( KSyncMLSessionCertificate, iStatus ) );
       
   690         if( KErrNone == err )
       
   691             {
       
   692             RDEBUG("CDMCertNotifier::RunLToBeTrappedL: Setting active...");
       
   693             SetActive();
       
   694             }
       
   695         else
       
   696             {
       
   697             if( iCallback != 0)
       
   698                 {
       
   699                 RDEBUG("CDMCertNotifier::RunLToBeTrappedL: iCallback->NotifierErrorL( KErrAbort );");
       
   700                 iCallback->NotifierErrorL( KErrAbort );
       
   701                 }
       
   702             }
       
   703         }
       
   704 #endif
       
   705 	}
       
   706 
       
   707 
       
   708 // ----------------------------------------------------------------------------------------
       
   709 // CDMCertNotifier::RunL
       
   710 // ----------------------------------------------------------------------------------------
       
   711 void CDMCertNotifier::RunL()
       
   712     {
       
   713 	RDEBUG("CDMCertNotifier::RunL");
       
   714     
       
   715     TRAPD( err, RunLToBeTrappedL());
       
   716    	
       
   717    	if( err != KErrNone )
       
   718    		{
       
   719    		ResetCertCache();
       
   720    		RDEBUG_2("**** CDMCertNotifier::RunL - LEAVE: %d", err);
       
   721    		}
       
   722     }
       
   723 
       
   724 // ----------------------------------------------------------------------------------------
       
   725 // CDMCertNotifier::DoCancel
       
   726 // ----------------------------------------------------------------------------------------
       
   727 void CDMCertNotifier::DoCancel()
       
   728     {
       
   729 	RDEBUG("CDMCertNotifier::DoCancel");
       
   730 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
   731 	iCertificateProperty.Cancel();	
       
   732 	ResetCertCache();
       
   733 #else	
       
   734     if( iRepository != 0 )
       
   735         {
       
   736         ResetCertCache();
       
   737         iRepository->NotifyCancel( KSyncMLSessionCertificate );
       
   738         }
       
   739 #endif        
       
   740     }
       
   741 
       
   742 // ----------------------------------------------------------------------------------------
       
   743 
       
   744 
       
   745 
       
   746 void CDMCertNotifier::SaveCertToCache()
       
   747 	{
       
   748 	TPckg<TCertInfo> certp( iCachedSessionCertificate );
       
   749 	
       
   750 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
   751     TInt err = iCertificateProperty.Get( certp );
       
   752 #else	
       
   753 	TInt err = iRepository->Get( KSyncMLSessionCertificate, certp );
       
   754 #endif
       
   755 	
       
   756 	if( err != KErrNone )
       
   757 		{
       
   758 		RDEBUG_2("**** Failed to save certificate data to cache: %d", err );
       
   759 		}		
       
   760 	}
       
   761 	
       
   762 CDMCertNotifier::TSessionCertStatus CDMCertNotifier::GetCertStatus()
       
   763 	{
       
   764 	TCertInfo ci;
       
   765     TPckg<TCertInfo> certp( ci );
       
   766     certp.Fill( TChar( 0 ) );
       
   767 
       
   768 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
   769 	TInt result = iCertificateProperty.Get( certp );
       
   770 #else    
       
   771     TInt result = iRepository->Get( KSyncMLSessionCertificate, certp );
       
   772 #endif
       
   773     
       
   774     if( result != KErrNone )
       
   775     	{
       
   776     	RDEBUG_2("**** Failed to fetch certificate data from centrep: %d", result );
       
   777     	return ESessionCertNoChange;
       
   778     	}
       
   779     	
       
   780     if( IsEmpty( ci ) )
       
   781     	{
       
   782     	RDEBUG("	Session certificate content is empty - DM session closed");
       
   783     	return ESessionCertContentZero;
       
   784     	}
       
   785     	
       
   786     if( !IsEqual( ci, iCachedSessionCertificate ) )
       
   787     	{
       
   788     	RDEBUG("	Session certificate data has changed");
       
   789     	return ESessionCertHasChanged;
       
   790     	}
       
   791     	
       
   792     return ESessionCertNoChange;
       
   793 	}
       
   794 	
       
   795 void CDMCertNotifier::ResetCertCache()
       
   796 	{
       
   797     TPckg<TCertInfo> certp( iCachedSessionCertificate );
       
   798     certp.Fill( TChar( 0 ) );
       
   799 	}
       
   800 
       
   801 
       
   802 TBool CDMCertNotifier::IsEmpty( const TCertInfo& aCertInfo ) const
       
   803 	{
       
   804 	/*
       
   805 	TPckg<TCertInfo> certp1( aCertInfo );
       
   806 	if( certp1.Length() == 0 )
       
   807 		{
       
   808 		return ETrue;
       
   809 		}
       
   810 	*/
       
   811 	if( aCertInfo.iFingerprint.Length() == 0 )
       
   812 		{
       
   813 		return ETrue;
       
   814 		}
       
   815 		
       
   816 	return EFalse;
       
   817 	}
       
   818 	
       
   819 TBool CDMCertNotifier::IsEqual( const TCertInfo& aCertInfo1, 
       
   820 								const TCertInfo& aCertInfo2 ) const
       
   821 	{
       
   822 	TInt result = aCertInfo1.iFingerprint.Compare( aCertInfo2.iFingerprint );
       
   823 	if( result != 0 )
       
   824 		{
       
   825 		return EFalse;
       
   826 		}
       
   827 	
       
   828 	result = aCertInfo1.iSerialNo.Compare( aCertInfo2.iSerialNo );
       
   829 	if( result != 0 )
       
   830 		{
       
   831 		return EFalse;
       
   832 		}
       
   833 	
       
   834 	if( aCertInfo1.iVersionNo != aCertInfo2.iVersionNo )
       
   835 		{
       
   836 		return EFalse;
       
   837 		}
       
   838 
       
   839 	return ETrue;
       
   840 	}	
       
   841 
       
   842 
       
   843 TInt CDMCertNotifier::GetCert( TCertInfo& aCertInfo )
       
   844     {
       
   845 	RDEBUG("CDMUtilServer::GetCertFromCentRep");
       
   846 	
       
   847 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
   848 	TPckg<TCertInfo> pcert( aCertInfo );
       
   849 	pcert.Fill( TChar( 0 ) );
       
   850 	return iCertificateProperty.Get( pcert );
       
   851 #else	
       
   852     TPckg<TCertInfo> certp( aCertInfo );
       
   853     certp.Fill( TChar( 0 ) );
       
   854 	return iRepository->Get( KSyncMLSessionCertificate, certp );
       
   855 #endif
       
   856     }
       
   857 
       
   858 // End of file
       
   859 
       
   860 
       
   861 
       
   862 
       
   863