cpsecplugins/cpadvancedsecplugin/src/cpcerttrustview.cpp
branchRCL_3
changeset 22 03674e5abf46
parent 21 09b1ac925e3f
child 23 94da73d93b58
equal deleted inserted replaced
21:09b1ac925e3f 22:03674e5abf46
     1 /*
       
     2 * Copyright (c) 2010 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 class CCertManUIContainerTrust.
       
    15 *                Maintains correct list of trusted clients depending
       
    16 *                on the certificate that was in focus in Authority
       
    17 *                certificates view when Trust Settings view was entered.
       
    18 *                Shows and changes correct Yes/No text for the Trusted client.
       
    19 *
       
    20 */
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include <certificateapps.h>
       
    24 #include <mctcertapps.h>
       
    25 #include <mctcertstore.h>
       
    26 
       
    27 #include <QGraphicsLinearLayout>
       
    28 #include <QString>
       
    29 #include <QList>
       
    30 
       
    31 #include <hbdataform.h>
       
    32 #include <hbdataformmodel.h>
       
    33 #include <hbdataformmodelitem.h>
       
    34 #include <hblistwidgetitem.h>
       
    35 #include <hblistwidget.h>
       
    36 
       
    37 #include <memory>
       
    38 #include <../../inc/cpsecplugins.h>
       
    39 #include "cpcerttrustview.h"
       
    40 #include "cpcertdatacontainer.h"
       
    41 #include "cpcertmanuisyncwrapper.h"
       
    42 #include "cpuitrustids.h"
       
    43 
       
    44 const TInt KMidpCertStoreUid = 0x101F5B71;
       
    45 
       
    46 // ============================= LOCAL FUNCTIONS ===============================
       
    47 
       
    48 // ================= MEMBER FUNCTIONS =======================
       
    49 
       
    50 CpCertTrustView::CpCertTrustView( TInt certificateIndex, CpCertDataContainer& certDataContainer, QGraphicsItem *parent /*= 0*/)
       
    51 		: CpBaseSettingView(0,parent), mCertDataContainer(certDataContainer), mCertificateIndex(certificateIndex)
       
    52 		{
       
    53 		setTitle(tr("Trust Settings"));
       
    54 		viewTrustSettings();	 
       
    55 		}
       
    56 
       
    57 // ---------------------------------------------------------
       
    58 // CpCertTrustView::~CpCertTrustView()
       
    59 // Destructor
       
    60 // ---------------------------------------------------------
       
    61 //
       
    62 CpCertTrustView::~CpCertTrustView()
       
    63     {
       
    64     delete mAppInfoManager;
       
    65     mClientUids.Close();
       
    66     delete mFormModel;	
       
    67     mTrustedClients.erase(mTrustedClients.begin(), mTrustedClients.end());
       
    68     mTrustValues.erase(mTrustValues.begin(), mTrustValues.end());
       
    69     }
       
    70 
       
    71 
       
    72 void CpCertTrustView::viewTrustSettings()
       
    73 	{
       
    74 	RDEBUG("0", 0);
       
    75 	mTrustedClients << " \tWAP connection\t\t";
       
    76 	mTrustedClients << " \tMail and Image conn.\t\t";
       
    77 	mTrustedClients << " \tNative installing\t\t";
       
    78 	mTrustedClients << " \tJava installing\t\t";
       
    79 	mTrustedClients << " \tOCSP validation\t\t";
       
    80 	mTrustedClients << " \tVPN\t\t";
       
    81 	mTrustedClients << " \tWidget Installation\t\t";
       
    82 	
       
    83 	mTrustValues << "On";
       
    84 	mTrustValues << "Off";
       
    85 		
       
    86 	try
       
    87 		{
       
    88 		QT_TRAP_THROWING( mAppInfoManager =
       
    89 			CCertificateAppInfoManager::NewL( mCertDataContainer.iRfs, EFalse );
       
    90 			updateListBoxL();)
       
    91 		}
       
    92 	catch(std::exception& exception)
       
    93 		{
       
    94 		QString error(exception.what());
       
    95 		QT_TRAP_THROWING(	mCertDataContainer.ShowErrorNoteL( error.toInt()) );
       
    96 		throw(exception);
       
    97 		}
       
    98 	}
       
    99 
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // CpCertTrustView::UpdateListBoxL()
       
   103 // Puts correct Trust Settings text to listbox and correct value (yes/no)
       
   104 // to the setting, asks the value from CheckCertificateClientTrust
       
   105 // For X509 certificates, only one Application is currently supported
       
   106 // (Application controller), more applications maybe added later however,
       
   107 // so one additional application has been left in comments as an example.
       
   108 // WAP connection and Application installer have their names from resources
       
   109 // and thus localized,  other additional application get their names from
       
   110 // TCertificateAppInfo's Name() function.
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 
       
   114 void CpCertTrustView::updateListBoxL()
       
   115     {
       
   116     RDEBUG("0", 0);
       
   117     mClientUids.Reset();
       
   118 
       
   119     TInt clientCount = 0;
       
   120 
       
   121     // Use certificate index from previous view
       
   122     CCTCertInfo* entry = mCertDataContainer.iCALabelEntries[ mCertificateIndex ]->iCAEntry;
       
   123 
       
   124     // Here MCTCertApps should be used to get client options, but it is not properly
       
   125     // supported in any cert store. It should be possible to get the MCTCertApps
       
   126     // through token's GetInterface function.
       
   127     if ( entry->Token().TokenType().Type() == TUid::Uid( KTokenTypeFileCertstore ) )
       
   128         {
       
   129         if ( !mAppInfoManager )
       
   130             {
       
   131             User::Leave( KErrArgument );
       
   132             }
       
   133         RArray<TCertificateAppInfo> apps;
       
   134         apps = mAppInfoManager->Applications();
       
   135         for ( TInt i = 0; i < apps.Count(); i++ )
       
   136             {
       
   137             if ( apps[i].Id() != KCertManUIViewTrustJavaInstallingId &&
       
   138             		apps[i].Id() != KCertManUIViewTrustApplicationControllerId )
       
   139                 {
       
   140                 mClientUids.Append( apps[i].Id() );
       
   141                 }
       
   142             }
       
   143         }
       
   144     else
       
   145         {
       
   146 		mCertDataContainer.iWrapper->GetApplicationsL(
       
   147 				mCertDataContainer.CertManager(), *entry, mClientUids );
       
   148         }
       
   149 
       
   150     // This is needed because MIDPCertStore does not support MCTCertApps
       
   151     if ( mClientUids.Count() == 0 &&
       
   152         entry->Token().TokenType().Type() == TUid::Uid( KMidpCertStoreUid ) )
       
   153         {
       
   154         mClientUids.Append( KCertManUIViewTrustJavaInstallingId );
       
   155         }
       
   156     
       
   157     if ( EX509Certificate != entry->CertificateFormat() )
       
   158         {
       
   159 		return;
       
   160         }
       
   161 	TInt resIndex = KErrNotFound;
       
   162 	QList <int> itemArray;
       
   163 	QList <int> trustValue;
       
   164 	clientCount = mClientUids.Count();
       
   165 	if ( clientCount > 0 )
       
   166 		{
       
   167 		for ( TInt k = 0; k < clientCount; k++ )
       
   168 			{
       
   169 			resIndex = trustIdIndex( mClientUids[k] );
       
   170 			if ( resIndex == KErrNotFound )
       
   171 				{
       
   172 				continue;
       
   173 				}
       
   174 			
       
   175 			// based on the trust list update the array
       
   176 			TBool trustState = EFalse;
       
   177 			QString item = mTrustedClients[ resIndex ];
       
   178 			trustState = checkCertificateClientTrustL( mClientUids[k], *entry );
       
   179 			// insert the index which would be used to retrieve the value from mTrustedClients
       
   180 			itemArray.insert(k,resIndex);
       
   181 			
       
   182 			if ( trustState )
       
   183 				{
       
   184 				trustValue.insert(k,1);
       
   185 				}
       
   186 			else
       
   187 				{
       
   188 				trustValue.insert(k,0);
       
   189 				}
       
   190 			}
       
   191 		}
       
   192     // display the list
       
   193     QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
       
   194     setLayout(layout);
       
   195     std::auto_ptr<HbDataForm> form(new HbDataForm());
       
   196 	mFormModel = new HbDataFormModel();
       
   197 	
       
   198 	HbListWidget* mCertLabelList = new HbListWidget(this); 
       
   199 	std::auto_ptr<HbListWidgetItem> certLabel(q_check_ptr(new HbListWidgetItem()));
       
   200 	const TDesC& label = entry->Label();
       
   201 	certLabel->setText(QString( (QChar*)label.Ptr(),label.Length() ) );
       
   202 	mCertLabelList->addItem(certLabel.get());
       
   203 	certLabel.release();
       
   204 	
       
   205 	RDEBUG("0", 0);
       
   206 	
       
   207 	int count = itemArray.size();
       
   208 	for( int index = 0 ;index < count; ++index)
       
   209 		{
       
   210 		std::auto_ptr<HbDataFormModelItem> item (q_check_ptr(new HbDataFormModelItem( 
       
   211 										HbDataFormModelItem::ToggleValueItem,
       
   212 										mTrustedClients[itemArray[index]] ) ));
       
   213 		
       
   214 		if( trustValue[index] == 1)
       
   215 			{
       
   216 			item->setContentWidgetData("text",mTrustValues[0]);
       
   217 			item->setContentWidgetData("additionalText",mTrustValues[1]);
       
   218 			}
       
   219 		else
       
   220 			{
       
   221 			item->setContentWidgetData("text",mTrustValues[1]);
       
   222 			item->setContentWidgetData("additionalText",mTrustValues[0]);
       
   223 			}
       
   224 		mFormModel->appendDataFormItem(item.get());
       
   225 		item.release();
       
   226 		}
       
   227 	
       
   228 	form->setModel(mFormModel);
       
   229 	layout->addItem(mCertLabelList);
       
   230 	layout->addItem(form.get());
       
   231 	form.release();
       
   232     }
       
   233 
       
   234 
       
   235 void CpCertTrustView::saveTrustSettings()
       
   236 	{
       
   237 	RDEBUG("0", 0);
       
   238 	CCTCertInfo& entry = *( mCertDataContainer.iCALabelEntries[ mCertificateIndex ]->iCAEntry );
       
   239 	if ( entry.IsDeletable() )
       
   240 		{
       
   241 		TInt itemCount = mFormModel->rowCount();
       
   242 		RArray<TUid> newUids;
       
   243 		QT_TRAP_THROWING
       
   244 			(	
       
   245 			CleanupClosePushL( newUids );
       
   246 			
       
   247 			for(int index = 0;index<itemCount;++index)
       
   248 				{
       
   249 				HbDataFormModelItem *item = mFormModel->item(index);
       
   250 				QString trustValue = item->contentWidgetData("text").toString();
       
   251 				if(trustValue == "On")
       
   252 					{
       
   253 					newUids.Append(trusterId(mTrustedClients[index]));
       
   254 					}
       
   255 				}
       
   256 			if(newUids.Count() > 0 )
       
   257 				{
       
   258 				mCertDataContainer.iWrapper->SetApplicabilityL( mCertDataContainer.CertManager(), entry, newUids );
       
   259 				}
       
   260 			CleanupStack::PopAndDestroy(&newUids);
       
   261 			)
       
   262 		}
       
   263 	}
       
   264 
       
   265 TUid CpCertTrustView::trusterId(const QString& clientDescription) const
       
   266 	{
       
   267 	RDEBUG("0", 0);
       
   268 	TUid retValue = TUid::Uid(0);
       
   269 	if( clientDescription ==  " \tWAP connection\t\t" )
       
   270 		retValue = KCertManUIViewTrustWapConnectionId;
       
   271 	else if( clientDescription ==  " \tMail and Image conn.\t\t" )
       
   272 		retValue = KCertManUIViewTrustMailAndImageConnId;
       
   273 	else if( clientDescription ==  " \tNative installing\t\t" )
       
   274 		retValue = KCertManUIViewTrustApplicationControllerId;
       
   275 	else if( clientDescription ==  " \tJava installing\t\t" )
       
   276 		retValue = KCertManUIViewTrustJavaInstallingId;
       
   277 	else if( clientDescription ==  " \tOCSP validation\t\t" )
       
   278 		retValue = KCertManUIViewOCSPCheckInstallingId;
       
   279 	else if( clientDescription ==  " \tVPN\t\t" )
       
   280 		retValue = KCertManUIViewTrustVPNId;
       
   281 	else if( clientDescription ==  " \tWidget Installation\t\t" )
       
   282 		retValue = KCertManUIViewTrustWidgetInstallId;
       
   283 	return retValue;
       
   284 	}
       
   285 
       
   286 // ---------------------------------------------------------------------------
       
   287 // CpCertTrustView::trustIdIndex( TUid trustUid )
       
   288 // ---------------------------------------------------------------------------
       
   289 //
       
   290 TInt CpCertTrustView::trustIdIndex( TUid trustUid ) const
       
   291     {
       
   292     RDEBUG("0", 0);
       
   293     TInt resIndex = KErrNotFound;
       
   294     
       
   295     if ( trustUid == KCertManUIViewTrustApplicationControllerId )
       
   296         {
       
   297         resIndex = KTrustSettingsResourceIndexAppCtrl;
       
   298         }
       
   299     else if( trustUid == KCertManUIViewTrustWapConnectionId )
       
   300     	{
       
   301 		resIndex = KTrustSettingsResourceIndexWAP;
       
   302     	}
       
   303     else if ( trustUid == KCertManUIViewTrustMailAndImageConnId )
       
   304         {
       
   305         resIndex = KTrustSettingsResourceIndexMailAndImageConn;
       
   306         }
       
   307     else if ( trustUid == KCertManUIViewTrustJavaInstallingId )
       
   308         {
       
   309         resIndex = KTrustSettingsResourceIndexJavaInstall;
       
   310         }
       
   311     else if ( trustUid == KCertManUIViewOCSPCheckInstallingId )
       
   312         {
       
   313         resIndex = KTrustSettingsResourceIndexOCSPCheck;
       
   314         }
       
   315     else if ( trustUid == KCertManUIViewTrustVPNId )
       
   316         {
       
   317         resIndex = KTrustSettingsResourceIndexVPN;
       
   318         }
       
   319     else if ( trustUid == KCertManUIViewTrustWidgetInstallId )
       
   320 		{
       
   321 		resIndex = KTrustSettingsResourceIndexWidget;
       
   322 		}
       
   323     return resIndex;
       
   324     }
       
   325 
       
   326 
       
   327 // ---------------------------------------------------------------------------
       
   328 // CpCertTrustView::CheckCertificateClientTrustL(const TUid aClientTUid,
       
   329 // CCTCertInfo& aEntry) const
       
   330 // Checks if a certificate trusts a client
       
   331 // * Certificate format == ECrX509Certificate ECrX968Certificate ECrCertificateURL
       
   332 // are not supported if certificate location == ECrCertLocationWIMCard
       
   333 // * Certificate format == ECrX968Certificate ECrCertificateURL are not supported
       
   334 // if certificate location == ECrCertLocationCertMan
       
   335 // * Certificate location == ECrCertLocationWIMURL ECrCertLocationPhoneMemory
       
   336 // ECrCertLocationPhoneMemoryURL are not supported
       
   337 // ---------------------------------------------------------------------------
       
   338 //
       
   339 TBool CpCertTrustView::checkCertificateClientTrustL(
       
   340     const TUid clientUid, const CCTCertInfo& entry ) const
       
   341     {
       
   342     RDEBUG("0", 0);
       
   343     TBool trustSettingTrusted = EFalse;
       
   344     TCertificateFormat format = entry.CertificateFormat();
       
   345 
       
   346     if ( format == EX509Certificate )
       
   347         {
       
   348 
       
   349         RArray<TUid> trusterUids;
       
   350         CleanupClosePushL( trusterUids );
       
   351 
       
   352         //Owned by mCertDataContainer.
       
   353         CUnifiedCertStore*& store = mCertDataContainer.CertManager();
       
   354         // Get trusting applications' Uids for the one selected
       
   355         // certificate entry
       
   356         mCertDataContainer.iWrapper->GetApplicationsL( store, entry, trusterUids );
       
   357 
       
   358         // get the number of trusting applications for one
       
   359         // selected certificate entry
       
   360         TInt trusterCount = trusterUids.Count();
       
   361         // in this loop, for every trusting application in one
       
   362         // selected certificate entry
       
   363         for ( TInt i = 0; i < trusterCount; ++i )
       
   364             {
       
   365             // put the trusting application's Uid to TUid truster
       
   366             if ( clientUid == trusterUids[i] )
       
   367                 {
       
   368                 trustSettingTrusted = ETrue;
       
   369                 break;
       
   370                 }
       
   371             }
       
   372         CleanupStack::PopAndDestroy(&trusterUids);  
       
   373         }
       
   374     
       
   375     return trustSettingTrusted;
       
   376     }
       
   377 
       
   378 // End of File
       
   379