×
Namespaces

Variants
Actions
Revision as of 04:20, 15 June 2012 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Archived:Listing the certificates on the device using unified certificate store API

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Article Metadata
Tested with
Devices(s): Tested on Nokia N95
Compatibility
Platform(s): S60 3rd Edition, FP1
S60 3rd Edition, FP2
S60 3rd Edition FP2
S60 3rd Edition FP1
Article
Keywords: CUnifiedCertStore
Created: User:TechnicalWriter2 (23 Jun 2009)
Last edited: hamishwillee (15 Jun 2012)

Description

The CUnifiedCertStore class provides a certificate store whose contents are the sum of the contents of all certificate store implementations on the device. It is intended as the single point of access for clients wishing to use certificate stores.

Solution

The following sample code shows how to retrieve the certificates present on the device.

MyClass.h

 #include <unifiedcertstore.h>     // link against certstore.lib 
#include <f32file.h> // link against efsrv.lib
#include <ccertattributefilter.h> // link against ctframework.lib
 
// Desclaration of CMyClass
 
class CMyClass : public CActive
{
public:
 
enum TState
{
EGetCerts,
EInitialize
};
 
static CMyClass* NewL();
~CMyClass();
 
void InitL();
void DoListL();
void PopulateListL();
 
protected: // From CActive
virtual void DoCancel();
virtual void RunL();
 
private: // Private constructors
CMyClass();
void ConstructL();
 
private: // Data
 
CUnifiedCertStore* iCertStore;
RMPointerArray<CCTCertInfo> iCerts;
CActiveSchedulerWait iWait;
 
TState iCertCmd;
RFs iFs;
};

MyClass.cpp

 #include "MyClass.h"
 
 
CMyClass* CMyClass::NewL()
{
CMyClass* self = new (ELeave) CMyClass;
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop(); // self
return self;
}
 
 
CMyClass::CMyClass()
: CActive(CActive::EPriorityStandard)
{
CActiveScheduler::Add( this );
}
 
 
CMyClass::~CMyClass()
{
Cancel();
 
delete iCertStore;
iFs.Close();
iCerts.Close();
}
 
 
void CMyClass::ConstructL()
{
User::LeaveIfError( iFs.Connect() );
iCertStore = CUnifiedCertStore::NewL( iFs, EFalse );
InitL();
}
 
 
void CMyClass::InitL()
{
if( IsActive() )
{
return;
}
 
iCertStore->Initialize( iStatus );
SetActive();
iCertCmd = EInitialize;
iWait.Start();
// RunL called when this completes
}
 
 
void CMyClass::DoListL()
{
CCertAttributeFilter* certFilter = CCertAttributeFilter::NewLC();
certFilter->SetFormat( EX509Certificate );
iCertStore->List(iCerts, *certFilter, iStatus);
SetActive();
iCertCmd = EGetCerts;
iWait.Start();
// RunL called when this completes
 
CleanupStack::PopAndDestroy(); // certFilter
}
 
 
void CMyClass::RunL()
{
iWait.AsyncStop();
if(iStatus == KErrNone)
{
switch(iCertCmd)
{
case EInitialize:
{
DoListL();
PopulateListL();
break;
}
default:
break;
}
}
}
 
 
void CMyClass::DoCancel()
{
switch(iCertCmd)
{
case EInitialize:
{
iCertStore->CancelInitialize();
break;
}
case EGetCerts:
{
iCertStore->CancelList();
break;
}
default:
break;
}
}
 
 
void CMyClass::PopulateListL()
{
for( TInt i = 0; i < iCerts.Count(); i++ )
{
TBuf<KMaxCertLabelLength> iCertLabel;
iCertLabel.Copy( iCerts[i]->Label() );
// ... process each cert label here
}
}

Required capabilities: ReadDeviceData

This page was last modified on 15 June 2012, at 04:20.
95 page views in the last 30 days.
×