os/security/cryptomgmtlibs/cryptotokenfw/source/ctframework/Cctcertinfo.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include "cctcertinfo.h"
sl@0
    20
sl@0
    21
#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
sl@0
    22
sl@0
    23
/** Mask constants used for serializing iDeletable and iFormat attributes 
sl@0
    24
*/
sl@0
    25
const TUint KReadOnlyFlagMask = 128;
sl@0
    26
const TUint KFormatMask = 127;
sl@0
    27
sl@0
    28
/** The UID of a CertInfo MCTTokenObject. */
sl@0
    29
const TInt KCTObjectCertInfo = 0x101F50E6;
sl@0
    30
sl@0
    31
#endif
sl@0
    32
sl@0
    33
// MCertInfo ///////////////////////////////////////////////////////////////////
sl@0
    34
sl@0
    35
EXPORT_C MCertInfo::MCertInfo() :
sl@0
    36
	iDeletable(ETrue)
sl@0
    37
	{
sl@0
    38
	}
sl@0
    39
sl@0
    40
EXPORT_C MCertInfo::MCertInfo(const TDesC& aLabel,
sl@0
    41
							  TCertificateFormat aFormat,
sl@0
    42
							  TCertificateOwnerType aCertificateOwnerType, 
sl@0
    43
							  TInt aSize,
sl@0
    44
							  const TKeyIdentifier* aSubjectKeyId,
sl@0
    45
							  const TKeyIdentifier* aIssuerKeyId,
sl@0
    46
							  TInt aCertificateId,
sl@0
    47
							  TBool aDeletable) :
sl@0
    48
	iLabel(aLabel), iCertificateId(aCertificateId),
sl@0
    49
	iFormat(aFormat), iCertificateOwnerType(aCertificateOwnerType),
sl@0
    50
	iSize(aSize), iDeletable(aDeletable)
sl@0
    51
	{
sl@0
    52
	if (aSubjectKeyId)
sl@0
    53
		{
sl@0
    54
		iSubjectKeyId = *aSubjectKeyId;
sl@0
    55
		}
sl@0
    56
	else
sl@0
    57
		{
sl@0
    58
		iSubjectKeyId = KNullDesC8;
sl@0
    59
		}
sl@0
    60
	if (aIssuerKeyId)
sl@0
    61
		{
sl@0
    62
		iIssuerKeyId = *aIssuerKeyId;
sl@0
    63
		}
sl@0
    64
	else
sl@0
    65
		{
sl@0
    66
		iIssuerKeyId = KNullDesC8;
sl@0
    67
		}
sl@0
    68
	}
sl@0
    69
sl@0
    70
EXPORT_C MCertInfo::MCertInfo(const MCertInfo& aOther) :
sl@0
    71
	iLabel(aOther.iLabel),
sl@0
    72
	iCertificateId(aOther.iCertificateId),
sl@0
    73
	iFormat(aOther.iFormat),
sl@0
    74
	iCertificateOwnerType(aOther.iCertificateOwnerType),
sl@0
    75
	iSize(aOther.iSize),
sl@0
    76
	iSubjectKeyId(aOther.iSubjectKeyId),
sl@0
    77
	iIssuerKeyId(aOther.iIssuerKeyId),
sl@0
    78
	iDeletable(aOther.iDeletable)
sl@0
    79
	{
sl@0
    80
	}
sl@0
    81
sl@0
    82
EXPORT_C MCertInfo::~MCertInfo()
sl@0
    83
	{
sl@0
    84
	delete iIssuerHash;
sl@0
    85
	}
sl@0
    86
sl@0
    87
const TDesC8* MCertInfo::IssuerHash() const
sl@0
    88
	{
sl@0
    89
	return iIssuerHash;
sl@0
    90
	}
sl@0
    91
sl@0
    92
EXPORT_C void MCertInfo::ConstructL(const TDesC8* aIssuerHash)
sl@0
    93
	{
sl@0
    94
	delete iIssuerHash;
sl@0
    95
	iIssuerHash = NULL;
sl@0
    96
	if (aIssuerHash)
sl@0
    97
		{
sl@0
    98
		iIssuerHash = aIssuerHash->AllocL();
sl@0
    99
		}
sl@0
   100
sl@0
   101
	if (!Valid())
sl@0
   102
		{
sl@0
   103
		User::Leave(KErrArgument);
sl@0
   104
		}
sl@0
   105
	}
sl@0
   106
	
sl@0
   107
TBool MCertInfo::Valid() const
sl@0
   108
	{
sl@0
   109
	if (iLabel.Length() == 0)
sl@0
   110
		{
sl@0
   111
		return EFalse;
sl@0
   112
		}
sl@0
   113
sl@0
   114
	if (iCertificateId < 0)
sl@0
   115
		{
sl@0
   116
		return EFalse;
sl@0
   117
		}
sl@0
   118
sl@0
   119
	if (iFormat != EX509Certificate && iFormat != EWTLSCertificate &&
sl@0
   120
		iFormat != EX968Certificate && iFormat != EX509CertificateUrl &&
sl@0
   121
		iFormat != EWTLSCertificateUrl && iFormat != EX968CertificateUrl)
sl@0
   122
		{
sl@0
   123
		return EFalse;
sl@0
   124
		}
sl@0
   125
	
sl@0
   126
	if (iCertificateOwnerType != ECACertificate &&
sl@0
   127
		iCertificateOwnerType != EUserCertificate &&
sl@0
   128
		iCertificateOwnerType != EPeerCertificate)
sl@0
   129
		{
sl@0
   130
		return EFalse;
sl@0
   131
		}
sl@0
   132
sl@0
   133
	if (iSize <= 0)
sl@0
   134
		{
sl@0
   135
		return EFalse;
sl@0
   136
		}
sl@0
   137
sl@0
   138
	if (iIssuerHash && *iIssuerHash == KNullDesC8)
sl@0
   139
		{
sl@0
   140
		return EFalse;
sl@0
   141
		}
sl@0
   142
sl@0
   143
	return ETrue;
sl@0
   144
	}
sl@0
   145
sl@0
   146
/**
sl@0
   147
		EXPORT_C void MCertInfo::ExternalizeL(RWriteStream& aStream) const
sl@0
   148
		
sl@0
   149
	This method externalizes the MCertInfo object to the given stream.
sl@0
   150
	The iDeletable boolean attribute is combined with the iFormat attribute
sl@0
   151
	for certstore backward compatibility
sl@0
   152
*/
sl@0
   153
EXPORT_C void MCertInfo::ExternalizeL(RWriteStream& aStream) const
sl@0
   154
	{
sl@0
   155
	// insert iDeletable flag as most significant digit of iFormat in order
sl@0
   156
	//   store the flag without changing the externalized record format
sl@0
   157
	//   The value is OPPOSITE for backward compatibility
sl@0
   158
	TUint8 tmpValue = static_cast <TUint8>(iFormat | (iDeletable ? 0 : KReadOnlyFlagMask));
sl@0
   159
	
sl@0
   160
	aStream.WriteUint8L(tmpValue);
sl@0
   161
	aStream.WriteInt32L(iSize);
sl@0
   162
	aStream << iLabel;
sl@0
   163
	aStream.WriteInt32L(iCertificateId);
sl@0
   164
	aStream.WriteUint8L(iCertificateOwnerType);
sl@0
   165
	aStream << iSubjectKeyId;
sl@0
   166
	aStream << iIssuerKeyId;
sl@0
   167
	}
sl@0
   168
sl@0
   169
/**
sl@0
   170
	EXPORT_C void MCertInfo::InternalizeL(RReadStream& aStream)
sl@0
   171
	
sl@0
   172
	This method internalizes a MCertInfo object from the given stream.
sl@0
   173
	The iDeletable boolean and iFormat attributes are both extracted
sl@0
   174
	from the stored iFormat value using for certstore backward compatibility
sl@0
   175
*/
sl@0
   176
EXPORT_C void MCertInfo::InternalizeL(RReadStream& aStream)
sl@0
   177
	{
sl@0
   178
	// get first byte from stream containing iDeletable flag and iFormat value
sl@0
   179
	TUint8 tmpValue = aStream.ReadUint8L();
sl@0
   180
	
sl@0
   181
	// extract iDeletable flag from most significant digit of iFormat
sl@0
   182
	//   set iDeletable to the OPPOSITE of the 8th bit value
sl@0
   183
	iDeletable = !(tmpValue & KReadOnlyFlagMask);
sl@0
   184
		
sl@0
   185
	// extract iFormat = the value of the 7 least significant bits
sl@0
   186
	iFormat = static_cast <TCertificateFormat>(tmpValue & KFormatMask);
sl@0
   187
sl@0
   188
	iSize = aStream.ReadInt32L();
sl@0
   189
	aStream >> iLabel;
sl@0
   190
	iCertificateId = aStream.ReadInt32L();
sl@0
   191
	iCertificateOwnerType = static_cast<TCertificateOwnerType>(aStream.ReadUint8L());
sl@0
   192
	aStream >> iSubjectKeyId;
sl@0
   193
	aStream >> iIssuerKeyId;
sl@0
   194
	
sl@0
   195
	if (!Valid())
sl@0
   196
		{
sl@0
   197
		User::Leave(KErrCorrupt);
sl@0
   198
		}
sl@0
   199
	}
sl@0
   200
sl@0
   201
// CCTCertInfo /////////////////////////////////////////////////////////////////
sl@0
   202
sl@0
   203
EXPORT_C CCTCertInfo* CCTCertInfo::NewL(RReadStream& aStream, MCTToken& aToken)
sl@0
   204
	{
sl@0
   205
	CCTCertInfo* self = CCTCertInfo::NewLC(aStream, aToken);
sl@0
   206
	CleanupStack::Pop(self);
sl@0
   207
	return self;
sl@0
   208
	}
sl@0
   209
sl@0
   210
EXPORT_C CCTCertInfo* CCTCertInfo::NewLC(RReadStream& aStream, MCTToken& aToken)
sl@0
   211
	{
sl@0
   212
	CCTCertInfo* self = new(ELeave) CCTCertInfo(aToken);
sl@0
   213
	CleanupReleasePushL(*self);
sl@0
   214
	self->ConstructL(aStream);
sl@0
   215
	return self;
sl@0
   216
	}
sl@0
   217
sl@0
   218
EXPORT_C CCTCertInfo* CCTCertInfo::NewL(const TDesC& aLabel,
sl@0
   219
										TCertificateFormat aFormat,
sl@0
   220
										TCertificateOwnerType aCertificateOwnerType,
sl@0
   221
										TInt aSize,
sl@0
   222
										const TKeyIdentifier* aSubjectKeyId,		
sl@0
   223
										const TKeyIdentifier* aIssuerKeyId,
sl@0
   224
										MCTToken& aToken,		
sl@0
   225
										TInt aCertificateId)
sl@0
   226
	{
sl@0
   227
	CCTCertInfo* self = CCTCertInfo::NewLC(aLabel,
sl@0
   228
		aFormat, aCertificateOwnerType, aSize, aSubjectKeyId, aIssuerKeyId, aToken,
sl@0
   229
		aCertificateId, ETrue);
sl@0
   230
	CleanupStack::Pop(self);
sl@0
   231
	return self;
sl@0
   232
	}
sl@0
   233
sl@0
   234
EXPORT_C CCTCertInfo* CCTCertInfo::NewL(const TDesC& aLabel,
sl@0
   235
										TCertificateFormat aFormat,
sl@0
   236
										TCertificateOwnerType aCertificateOwnerType,
sl@0
   237
										TInt aSize,
sl@0
   238
										const TKeyIdentifier* aSubjectKeyId,		
sl@0
   239
										const TKeyIdentifier* aIssuerKeyId,
sl@0
   240
										MCTToken& aToken,		
sl@0
   241
										TInt aCertificateId, 
sl@0
   242
										TBool aIsDeletable, 
sl@0
   243
										const TDesC8* aIssuerHash)
sl@0
   244
	{
sl@0
   245
	CCTCertInfo* self = CCTCertInfo::NewLC(aLabel,
sl@0
   246
		aFormat, aCertificateOwnerType, aSize, aSubjectKeyId, aIssuerKeyId, aToken,
sl@0
   247
		aCertificateId, aIsDeletable, aIssuerHash);
sl@0
   248
	CleanupStack::Pop(self);
sl@0
   249
	return self;
sl@0
   250
	}
sl@0
   251
sl@0
   252
EXPORT_C CCTCertInfo* CCTCertInfo::NewLC(const TDesC& aLabel,
sl@0
   253
										 TCertificateFormat aFormat,
sl@0
   254
										 TCertificateOwnerType aCertificateOwnerType,
sl@0
   255
										 TInt aSize,
sl@0
   256
										 const TKeyIdentifier* aSubjectKeyId,
sl@0
   257
										 const TKeyIdentifier* aIssuerKeyId,
sl@0
   258
										 MCTToken& aToken, 
sl@0
   259
										 TInt aCertificateId)
sl@0
   260
	{
sl@0
   261
	return CCTCertInfo::NewLC(aLabel,
sl@0
   262
		aFormat, aCertificateOwnerType, aSize, aSubjectKeyId, aIssuerKeyId, 
sl@0
   263
		aToken, aCertificateId, ETrue);
sl@0
   264
	}
sl@0
   265
sl@0
   266
EXPORT_C CCTCertInfo* CCTCertInfo::NewLC(const TDesC& aLabel,
sl@0
   267
										 TCertificateFormat aFormat,
sl@0
   268
										 TCertificateOwnerType aCertificateOwnerType,
sl@0
   269
										 TInt aSize,
sl@0
   270
										 const TKeyIdentifier* aSubjectKeyId,
sl@0
   271
										 const TKeyIdentifier* aIssuerKeyId,
sl@0
   272
										 MCTToken& aToken, 
sl@0
   273
										 TInt aCertificateId, 
sl@0
   274
										 TBool aIsDeletable, 
sl@0
   275
										 const TDesC8* aIssuerHash)
sl@0
   276
	{
sl@0
   277
	CCTCertInfo* self = new(ELeave) CCTCertInfo(aLabel,
sl@0
   278
		aFormat, aCertificateOwnerType, aSize, aSubjectKeyId,
sl@0
   279
		aIssuerKeyId, aToken, aCertificateId, aIsDeletable);
sl@0
   280
	CleanupReleasePushL(*self);
sl@0
   281
	self->ConstructL(aIssuerHash);
sl@0
   282
	return self;
sl@0
   283
	}
sl@0
   284
sl@0
   285
EXPORT_C CCTCertInfo* CCTCertInfo::NewL(const CCTCertInfo& aCertInfo)
sl@0
   286
	{
sl@0
   287
	CCTCertInfo* self = CCTCertInfo::NewLC(aCertInfo);
sl@0
   288
	CleanupStack::Pop(self);
sl@0
   289
	return self;
sl@0
   290
	}
sl@0
   291
sl@0
   292
EXPORT_C CCTCertInfo* CCTCertInfo::NewLC(const CCTCertInfo& aCertInfo)
sl@0
   293
	{
sl@0
   294
	CCTCertInfo* self = new(ELeave) CCTCertInfo(aCertInfo);
sl@0
   295
	CleanupReleasePushL(*self);
sl@0
   296
	self->ConstructL(aCertInfo.IssuerHash());
sl@0
   297
	return self;
sl@0
   298
	}
sl@0
   299
sl@0
   300
CCTCertInfo::CCTCertInfo(MCTToken& aToken)
sl@0
   301
	: MCTTokenObject(aToken), iToken(aToken)
sl@0
   302
	{
sl@0
   303
	}
sl@0
   304
sl@0
   305
CCTCertInfo::CCTCertInfo(const TDesC& aLabel, 
sl@0
   306
						 TCertificateFormat aFormat,
sl@0
   307
						 TCertificateOwnerType aCertificateOwnerType,
sl@0
   308
						 TInt aSize,
sl@0
   309
						 const TKeyIdentifier* aSubjectKeyId,
sl@0
   310
						 const TKeyIdentifier* aIssuerKeyId,
sl@0
   311
						 MCTToken& aToken, 
sl@0
   312
						 TInt aCertificateId,
sl@0
   313
						 TBool aIsDeletable)
sl@0
   314
	: MCTTokenObject(aToken),
sl@0
   315
	  MCertInfo(aLabel, aFormat, aCertificateOwnerType, aSize, aSubjectKeyId,
sl@0
   316
				aIssuerKeyId, aCertificateId, aIsDeletable),
sl@0
   317
	  iToken(aToken)
sl@0
   318
	{
sl@0
   319
	}
sl@0
   320
sl@0
   321
CCTCertInfo::CCTCertInfo(const CCTCertInfo& aOther)
sl@0
   322
	: MCTTokenObject(aOther.iToken), MCertInfo(aOther), iToken(aOther.iToken)
sl@0
   323
	{
sl@0
   324
	}
sl@0
   325
sl@0
   326
void CCTCertInfo::ConstructL(RReadStream& aStream)
sl@0
   327
	{
sl@0
   328
	InternalizeL(aStream);
sl@0
   329
	}
sl@0
   330
sl@0
   331
void CCTCertInfo::ConstructL(const TDesC8* aIssuerHash)
sl@0
   332
	{
sl@0
   333
	MCertInfo::ConstructL(aIssuerHash);
sl@0
   334
	}
sl@0
   335
sl@0
   336
EXPORT_C CCTCertInfo::~CCTCertInfo()
sl@0
   337
	{
sl@0
   338
	}
sl@0
   339
sl@0
   340
const TDesC& CCTCertInfo::Label() const
sl@0
   341
	{
sl@0
   342
	return iLabel;
sl@0
   343
	}
sl@0
   344
sl@0
   345
TUid CCTCertInfo::Type() const
sl@0
   346
	{
sl@0
   347
	TUid uid = { KCTObjectCertInfo };
sl@0
   348
	return uid;
sl@0
   349
	}
sl@0
   350
sl@0
   351
EXPORT_C const TKeyIdentifier& CCTCertInfo::SubjectKeyId() const
sl@0
   352
	{
sl@0
   353
	return iSubjectKeyId;
sl@0
   354
	}
sl@0
   355
sl@0
   356
EXPORT_C const TKeyIdentifier& CCTCertInfo::IssuerKeyId() const
sl@0
   357
	{
sl@0
   358
	return iIssuerKeyId;
sl@0
   359
	}
sl@0
   360
sl@0
   361
EXPORT_C TCertificateFormat CCTCertInfo::CertificateFormat() const
sl@0
   362
	{
sl@0
   363
	return iFormat;
sl@0
   364
	}
sl@0
   365
sl@0
   366
EXPORT_C TCertificateOwnerType CCTCertInfo::CertificateOwnerType() const
sl@0
   367
	{
sl@0
   368
	return iCertificateOwnerType;
sl@0
   369
	}
sl@0
   370
sl@0
   371
EXPORT_C TInt CCTCertInfo::Size() const
sl@0
   372
	{
sl@0
   373
	return iSize;
sl@0
   374
	}
sl@0
   375
sl@0
   376
MCTToken& CCTCertInfo::Token() const
sl@0
   377
	{
sl@0
   378
	return iToken;
sl@0
   379
	}
sl@0
   380
sl@0
   381
EXPORT_C TCTTokenObjectHandle CCTCertInfo::Handle() const
sl@0
   382
	{
sl@0
   383
	return TCTTokenObjectHandle(iToken.Handle(), iCertificateId);
sl@0
   384
	}
sl@0
   385
sl@0
   386
EXPORT_C TBool CCTCertInfo::IsDeletable() const
sl@0
   387
	{
sl@0
   388
	return iDeletable;
sl@0
   389
	}
sl@0
   390
sl@0
   391
EXPORT_C const TDesC8* CCTCertInfo::IssuerHash() const
sl@0
   392
	{
sl@0
   393
	return MCertInfo::IssuerHash();
sl@0
   394
	}
sl@0
   395
sl@0
   396
EXPORT_C TBool CCTCertInfo::operator==(const CCTCertInfo& aCertInfo) const
sl@0
   397
	{
sl@0
   398
	return aCertInfo.iLabel == iLabel;
sl@0
   399
	}
sl@0
   400
sl@0
   401
EXPORT_C void CCTCertInfo::SetCertificateId(TInt aCertId)
sl@0
   402
{
sl@0
   403
	iCertificateId = aCertId;
sl@0
   404
}