cryptoservices/certificateandkeymgmt/wtlscert/wtlscert.cpp
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 1997-2009 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 the License "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: 
       
    15 * -- FingerPrint Note:
       
    16 * Developers have to be aware that if they are going to change the fingerprint for this certificate
       
    17 * for a different hash, then there are other places that need to reflect this change
       
    18 * -- Location
       
    19 * void CWTLSCertificate::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
       
    20 * EXPORT_C void CWTLSCertificate::InternalizeL(RReadStream& aStream)
       
    21 * Also change the CX509Certificate and search for other occurences of the current
       
    22 * hash.
       
    23 *
       
    24 */
       
    25 
       
    26 
       
    27 #include <wtlscert.h>
       
    28 #include <wtlskeys.h>
       
    29 #include "wtlsdec.h"
       
    30 #include <hash.h>
       
    31 
       
    32 enum TEncAlgorithmType
       
    33 	{
       
    34 	EEncRSA = 0x02
       
    35 	};
       
    36 
       
    37 enum TEncSigAlgorithmType
       
    38 	{
       
    39 	EEncRSAwithSHA1 = 0x02
       
    40 	};
       
    41 
       
    42 const TInt KMinAlgIdLength = 2;
       
    43 const TInt KMinExpLengthBytes = 1;
       
    44 const TInt KMaxExpLengthBytes = 65535;
       
    45 const TInt KMinModLengthBytes = 1;
       
    46 const TInt KMaxModLengthBytes = 65535;
       
    47 
       
    48 //WTLS RSA signature result
       
    49 EXPORT_C CWTLSRSASignatureResult* CWTLSRSASignatureResult::NewL(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest)
       
    50 	{
       
    51 	CWTLSRSASignatureResult* self = CWTLSRSASignatureResult::NewLC(aDigestAlgorithm, aDigest);
       
    52 	CleanupStack::Pop();
       
    53 	return self;
       
    54 	}
       
    55 
       
    56 EXPORT_C CWTLSRSASignatureResult* CWTLSRSASignatureResult::NewLC(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest)
       
    57 	{
       
    58 	CWTLSRSASignatureResult* self = new(ELeave) CWTLSRSASignatureResult;
       
    59 	CleanupStack::PushL(self);
       
    60 	self->ConstructL(aDigestAlgorithm, aDigest);
       
    61 	return self;
       
    62 	}
       
    63 
       
    64 EXPORT_C TBool CWTLSRSASignatureResult::VerifyL(const TDesC8& aResult)
       
    65 	{
       
    66 	return aResult == *iDigest;
       
    67 	}
       
    68 
       
    69 void CWTLSRSASignatureResult::ConstructL(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest)
       
    70 	{
       
    71 	iDigestAlgorithm = CAlgorithmIdentifier::NewL(aDigestAlgorithm);
       
    72 	iDigest = aDigest.AllocL();
       
    73 	}
       
    74 
       
    75 //WTLS KeyFactory
       
    76 CRSAPublicKey* TWTLSKeyFactory::RSAPublicKeyL(const TDesC8& aEncoding) const
       
    77 	{
       
    78 	return CWTLSRSAPublicKey::NewL(aEncoding);
       
    79 	}
       
    80 
       
    81 CRSASignatureResult* TWTLSKeyFactory::RSASignatureResultL(const CAlgorithmIdentifier& aDigestAlgorithm, TDesC8& aDigest) const
       
    82 	{
       
    83 	return CWTLSRSASignatureResult::NewL(aDigestAlgorithm, aDigest);
       
    84 	}
       
    85 
       
    86 CDSAPublicKey* TWTLSKeyFactory::DSAPublicKeyL(const CDSAParameters& /*aParams*/, const TDesC8& /*aEncoding*/) const
       
    87 	{
       
    88 	User::Leave(KErrNotSupported);
       
    89 	return NULL;
       
    90 	}
       
    91 
       
    92 CDSAPublicKey* TWTLSKeyFactory::DSAPublicKeyL(const TDesC8& /*aParams*/, const TDesC8& /*aEncoding*/) const
       
    93 	{
       
    94 	User::Leave(KErrNotSupported);
       
    95 	return NULL;
       
    96 	}
       
    97 
       
    98 CDSASignature* TWTLSKeyFactory::DSASignatureL(const TDesC8& /*aEncoding*/) const
       
    99 {
       
   100 	User::Leave(KErrNotSupported);
       
   101 	return NULL;	
       
   102 }
       
   103 
       
   104 
       
   105 CDSAParameters* TWTLSKeyFactory::DSAParametersL(const TDesC8& /*aParamsEncoding*/) const
       
   106 {
       
   107 	User::Leave(KErrNotSupported);
       
   108 	return NULL;	
       
   109 }
       
   110 
       
   111 //validity period
       
   112 EXPORT_C CWTLSValidityPeriod* CWTLSValidityPeriod::NewL(const TDesC8& aBinaryData)
       
   113 	{
       
   114 	TInt pos = 0;
       
   115 	return CWTLSValidityPeriod::NewL(aBinaryData, pos);
       
   116 	}
       
   117 
       
   118 EXPORT_C CWTLSValidityPeriod* CWTLSValidityPeriod::NewLC(const TDesC8& aBinaryData)
       
   119 	{
       
   120 	TInt pos = 0;
       
   121 	return CWTLSValidityPeriod::NewLC(aBinaryData, pos);
       
   122 	}
       
   123 
       
   124 EXPORT_C CWTLSValidityPeriod* CWTLSValidityPeriod::NewL(const TDesC8& aBinaryData, TInt& aPos)
       
   125 	{
       
   126 	CWTLSValidityPeriod* self = CWTLSValidityPeriod::NewLC(aBinaryData, aPos);
       
   127 	CleanupStack::Pop();
       
   128 	return self;
       
   129 	}
       
   130 
       
   131 EXPORT_C CWTLSValidityPeriod* CWTLSValidityPeriod::NewLC(const TDesC8& aBinaryData, TInt& aPos)
       
   132 	{
       
   133 	CWTLSValidityPeriod* self = new(ELeave) CWTLSValidityPeriod;
       
   134 	CleanupStack::PushL(self);
       
   135 	self->ConstructL(aBinaryData, aPos);
       
   136 	return self;
       
   137 	}
       
   138 
       
   139 CWTLSValidityPeriod::CWTLSValidityPeriod()
       
   140 	{
       
   141 	}
       
   142 
       
   143 void CWTLSValidityPeriod::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
       
   144 	{
       
   145 	TWTLSDecTime timeDec;
       
   146 	iStart = timeDec.DecodeL(aBinaryData, aPos);
       
   147 	iFinish = timeDec.DecodeL(aBinaryData, aPos);
       
   148 	}
       
   149 
       
   150 //algorithm id
       
   151 EXPORT_C CWTLSAlgorithmIdentifier* CWTLSAlgorithmIdentifier::NewL(const TDesC8& aBinaryData)
       
   152 	{
       
   153 	TInt pos = 0;
       
   154 	return CWTLSAlgorithmIdentifier::NewL(aBinaryData, pos);
       
   155 	}
       
   156 
       
   157 EXPORT_C CWTLSAlgorithmIdentifier* CWTLSAlgorithmIdentifier::NewLC(const TDesC8& aBinaryData)
       
   158 	{
       
   159 	TInt pos = 0;
       
   160 	return CWTLSAlgorithmIdentifier::NewLC(aBinaryData, pos);
       
   161 	}
       
   162 
       
   163 EXPORT_C CWTLSAlgorithmIdentifier* CWTLSAlgorithmIdentifier::NewL(const TDesC8& aBinaryData, TInt& aPos)
       
   164 	{
       
   165 	CWTLSAlgorithmIdentifier* self = CWTLSAlgorithmIdentifier::NewLC(aBinaryData, aPos);
       
   166 	CleanupStack::Pop();
       
   167 	return self;
       
   168 	}
       
   169 
       
   170 EXPORT_C CWTLSAlgorithmIdentifier* CWTLSAlgorithmIdentifier::NewLC(const TDesC8& aBinaryData, TInt& aPos)
       
   171 	{
       
   172 	CWTLSAlgorithmIdentifier* self = new(ELeave) CWTLSAlgorithmIdentifier;
       
   173 	CleanupStack::PushL(self);
       
   174 	self->ConstructL(aBinaryData, aPos);
       
   175 	return self;
       
   176 	}
       
   177 
       
   178 CWTLSAlgorithmIdentifier::CWTLSAlgorithmIdentifier()
       
   179 	{
       
   180 	}
       
   181 
       
   182 void CWTLSAlgorithmIdentifier::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
       
   183 	{
       
   184 	if ((aBinaryData.Length() - aPos) < KMinAlgIdLength)
       
   185 		{
       
   186 		User::Leave(KErrArgument);
       
   187 		}
       
   188 	switch (aBinaryData[aPos])
       
   189 		{
       
   190 		case EEncRSA:
       
   191 			{
       
   192 			iAlgorithmId = ERSA;
       
   193 			aPos++;
       
   194 			if (aBinaryData[aPos] != 0)
       
   195 				{
       
   196 				User::Leave(KErrArgument);
       
   197 				}
       
   198 			aPos++;
       
   199 			iEncodedParams = HBufC8::NewL(1);
       
   200 			*iEncodedParams = KNullDesC8;
       
   201 			break;
       
   202 			}
       
   203 		default:
       
   204 			//we only support RSA just now...
       
   205 			{
       
   206 			User::Leave(KErrNotSupported);
       
   207 			}
       
   208 		}
       
   209 	}
       
   210 
       
   211 //signing algorithm id
       
   212 EXPORT_C CWTLSSigningAlgorithmIdentifier* CWTLSSigningAlgorithmIdentifier::NewL(const TDesC8& aBinaryData)
       
   213 	{
       
   214 	TInt pos = 0;
       
   215 	return CWTLSSigningAlgorithmIdentifier::NewL(aBinaryData, pos);
       
   216 	}
       
   217 
       
   218 EXPORT_C CWTLSSigningAlgorithmIdentifier* CWTLSSigningAlgorithmIdentifier::NewLC(const TDesC8& aBinaryData)
       
   219 	{
       
   220 	TInt pos = 0;
       
   221 	return CWTLSSigningAlgorithmIdentifier::NewLC(aBinaryData, pos);
       
   222 	}
       
   223 
       
   224 EXPORT_C CWTLSSigningAlgorithmIdentifier* CWTLSSigningAlgorithmIdentifier::NewL(const TDesC8& aBinaryData, TInt& aPos)
       
   225 	{
       
   226 	CWTLSSigningAlgorithmIdentifier* self = CWTLSSigningAlgorithmIdentifier::NewLC(aBinaryData, aPos);
       
   227 	CleanupStack::Pop();
       
   228 	return self;
       
   229 	}
       
   230 
       
   231 EXPORT_C CWTLSSigningAlgorithmIdentifier* CWTLSSigningAlgorithmIdentifier::NewLC(const TDesC8& aBinaryData, TInt& aPos)
       
   232 	{
       
   233 	CWTLSSigningAlgorithmIdentifier* self = new(ELeave) CWTLSSigningAlgorithmIdentifier;
       
   234 	CleanupStack::PushL(self);
       
   235 	self->ConstructL(aBinaryData, aPos);
       
   236 	return self;
       
   237 	}
       
   238 
       
   239 CWTLSSigningAlgorithmIdentifier::CWTLSSigningAlgorithmIdentifier()
       
   240 	{
       
   241 	}
       
   242 
       
   243 void CWTLSSigningAlgorithmIdentifier::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
       
   244 	{
       
   245 	if ((aBinaryData.Length() - aPos) < 1)
       
   246 		{
       
   247 		User::Leave(KErrArgument);
       
   248 		}
       
   249 	switch (aBinaryData[aPos])
       
   250 		{
       
   251 		case EEncRSAwithSHA1:
       
   252 			{
       
   253 			TAlgorithmId asym = ERSA;
       
   254 			TAlgorithmId dig = ESHA1;
       
   255 			iAsymmetricAlgorithm = CAlgorithmIdentifier::NewL(asym, KNullDesC8);
       
   256 			iDigestAlgorithm = CAlgorithmIdentifier::NewL(dig, KNullDesC8);
       
   257 			aPos++;
       
   258 			break;
       
   259 			}
       
   260 		default:
       
   261 			//we only support RSA-SHA1 just now...
       
   262 			{
       
   263 			User::Leave(KErrNotSupported);
       
   264 			}
       
   265 		}
       
   266 	}
       
   267 
       
   268 //wtls subject public key info
       
   269 EXPORT_C CWTLSSubjectPublicKeyInfo* CWTLSSubjectPublicKeyInfo::NewL(const TDesC8& aBinaryData)
       
   270 	{
       
   271 	TInt pos = 0;
       
   272 	return CWTLSSubjectPublicKeyInfo::NewL(aBinaryData, pos);
       
   273 	}
       
   274 
       
   275 EXPORT_C CWTLSSubjectPublicKeyInfo* CWTLSSubjectPublicKeyInfo::NewLC(const TDesC8& aBinaryData)
       
   276 	{
       
   277 	TInt pos = 0;
       
   278 	return CWTLSSubjectPublicKeyInfo::NewLC(aBinaryData, pos);
       
   279 	}
       
   280 
       
   281 EXPORT_C CWTLSSubjectPublicKeyInfo* CWTLSSubjectPublicKeyInfo::NewL(const TDesC8& aBinaryData, TInt& aPos)
       
   282 	{
       
   283 	CWTLSSubjectPublicKeyInfo* self = CWTLSSubjectPublicKeyInfo::NewLC(aBinaryData, aPos);
       
   284 	CleanupStack::Pop();
       
   285 	return self;
       
   286 	}
       
   287 
       
   288 EXPORT_C CWTLSSubjectPublicKeyInfo* CWTLSSubjectPublicKeyInfo::NewLC(const TDesC8& aBinaryData, TInt& aPos)
       
   289 	{
       
   290 	CWTLSSubjectPublicKeyInfo* self = new(ELeave) CWTLSSubjectPublicKeyInfo;
       
   291 	CleanupStack::PushL(self);
       
   292 	self->ConstructL(aBinaryData, aPos);
       
   293 	return self;
       
   294 	}
       
   295 
       
   296 CWTLSSubjectPublicKeyInfo::CWTLSSubjectPublicKeyInfo()
       
   297 	{
       
   298 	}
       
   299 
       
   300 void CWTLSSubjectPublicKeyInfo::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
       
   301 	{
       
   302 	iAlgId = CWTLSAlgorithmIdentifier::NewL(aBinaryData, aPos);
       
   303 	if (iAlgId->Algorithm() != ERSA)
       
   304 		{
       
   305 		User::Leave(KErrNotSupported);
       
   306 		}
       
   307 	TInt totalLength = aBinaryData.Length();
       
   308 	TInt tempPos = aPos;
       
   309 
       
   310 	const TPtrC8 expEnc = aBinaryData.Right(totalLength - aPos);
       
   311 	TWTLSDecVector exp(expEnc, KMinExpLengthBytes, KMaxExpLengthBytes);
       
   312 	exp.InitL();
       
   313 
       
   314 	aPos += exp.EncodingLength();
       
   315 
       
   316 	const TPtrC8 modEnc = aBinaryData.Right(totalLength - aPos);
       
   317 	TWTLSDecVector mod(modEnc, KMinModLengthBytes, KMaxModLengthBytes);
       
   318 	mod.InitL();
       
   319 
       
   320 	aPos+= mod.EncodingLength();
       
   321 	iEncodedKeyData = (aBinaryData.Mid(tempPos, aPos - tempPos)).AllocL();
       
   322 	}
       
   323 
       
   324 //wtls certificate
       
   325 EXPORT_C CWTLSCertificate* CWTLSCertificate::NewL(const TDesC8& aBinaryData)
       
   326 	{
       
   327 	TInt pos = 0;
       
   328 	return CWTLSCertificate::NewL(aBinaryData, pos);
       
   329 	}
       
   330 
       
   331 EXPORT_C CWTLSCertificate* CWTLSCertificate::NewLC(const TDesC8& aBinaryData)
       
   332 	{
       
   333 	TInt pos = 0;
       
   334 	return CWTLSCertificate::NewLC(aBinaryData, pos);
       
   335 	}
       
   336 
       
   337 EXPORT_C CWTLSCertificate* CWTLSCertificate::NewL(const TDesC8& aBinaryData, TInt& aPos)
       
   338 	{
       
   339 	CWTLSCertificate* self = CWTLSCertificate::NewLC(aBinaryData, aPos);
       
   340 	CleanupStack::Pop();
       
   341 	return self;
       
   342 	}
       
   343 
       
   344 EXPORT_C CWTLSCertificate* CWTLSCertificate::NewLC(const TDesC8& aBinaryData, TInt& aPos)
       
   345 	{
       
   346 	CWTLSCertificate* self = new(ELeave) CWTLSCertificate;
       
   347 	CleanupStack::PushL(self);
       
   348 	self->ConstructL(aBinaryData, aPos);
       
   349 	return self;
       
   350 	}
       
   351 
       
   352 EXPORT_C CWTLSCertificate* CWTLSCertificate::NewL(RReadStream& aStream)
       
   353 	{
       
   354 	CWTLSCertificate* self = CWTLSCertificate::NewLC(aStream);
       
   355 	CleanupStack::Pop();//self
       
   356 	return self;
       
   357 	}
       
   358 
       
   359 EXPORT_C CWTLSCertificate* CWTLSCertificate::NewLC(RReadStream& aStream)
       
   360 	{
       
   361 	CWTLSCertificate* self = new(ELeave) CWTLSCertificate;
       
   362 	CleanupStack::PushL(self);
       
   363 	self->InternalizeL(aStream);
       
   364 	return self;
       
   365 	}
       
   366 /*
       
   367 EXPORT_C CWTLSCertificate* CWTLSCertificate::NewL(CCertStore& aStore, const CCertStoreEntry& aEntry)
       
   368 	{
       
   369 	CWTLSCertificate* self = CWTLSCertificate::NewLC(aStore, aEntry);
       
   370 	CleanupStack::Pop();//self
       
   371 	return self;
       
   372 	}
       
   373 
       
   374 EXPORT_C CWTLSCertificate* CWTLSCertificate::NewLC(CCertStore& aStore, const CCertStoreEntry& aEntry)
       
   375 	{
       
   376 	CWTLSCertificate* self = new(ELeave) CWTLSCertificate;
       
   377 	CleanupStack::PushL(self);
       
   378 	aStore.LoadL(*self, aEntry);
       
   379 	return self;
       
   380 	}
       
   381 */
       
   382 EXPORT_C CWTLSCertificate* CWTLSCertificate::NewL(const CWTLSCertificate& aCert)
       
   383 	{
       
   384 	CWTLSCertificate* self = CWTLSCertificate::NewLC(aCert);
       
   385 	CleanupStack::Pop();//self
       
   386 	return self;
       
   387 	}
       
   388 
       
   389 EXPORT_C CWTLSCertificate* CWTLSCertificate::NewLC(const CWTLSCertificate& aCert)
       
   390 	{
       
   391 	CWTLSCertificate* self = new(ELeave) CWTLSCertificate;
       
   392 	CleanupStack::PushL(self);
       
   393 	self->ConstructL(aCert);
       
   394 	return self;
       
   395 	}
       
   396 
       
   397 EXPORT_C CWTLSCertificate::~CWTLSCertificate()
       
   398 	{
       
   399 	delete iIssuerName;
       
   400 	delete iSubjectName;
       
   401 		
       
   402 	if (iDataElements != NULL)
       
   403 		{
       
   404 		for (TInt i = 0; i < KWTLSCertMaxDataElements; i++)
       
   405 			{
       
   406 			delete iDataElements->At(i);
       
   407 			}
       
   408 		delete iDataElements;
       
   409 		}
       
   410 	}
       
   411 
       
   412 EXPORT_C TBool CWTLSCertificate::IsEqualL(const CWTLSCertificate& aCert) const
       
   413 	{
       
   414 	return	(*(iFingerprint) == (*(aCert.iFingerprint)));
       
   415 	}
       
   416 
       
   417 	//extra accessors
       
   418 EXPORT_C const TPtrC8 CWTLSCertificate::SignedDataL() const
       
   419 	{
       
   420 	return iEncoding->Left(iEncoding->Length() - (iSignature->Length() +2));
       
   421 	}
       
   422 
       
   423 EXPORT_C TInt CWTLSCertificate::Version() const
       
   424 	{
       
   425 	return iVersion;
       
   426 	}
       
   427 
       
   428 EXPORT_C const CWTLSName& CWTLSCertificate::IssuerName() const
       
   429 	{
       
   430 	return *iIssuerName;
       
   431 	}
       
   432 
       
   433 EXPORT_C const CWTLSName& CWTLSCertificate::SubjectName() const
       
   434 	{
       
   435 	return *iSubjectName;
       
   436 	}
       
   437 
       
   438 EXPORT_C HBufC* CWTLSCertificate::IssuerL() const
       
   439 	{
       
   440 	return iIssuerName->DisplayNameL();
       
   441 	}
       
   442 
       
   443 EXPORT_C HBufC* CWTLSCertificate::SubjectL() const
       
   444 	{
       
   445 	return iSubjectName->DisplayNameL();
       
   446 	}
       
   447 
       
   448 EXPORT_C TBool CWTLSCertificate::IsSelfSignedL() const
       
   449 	{
       
   450 	return iSubjectName->ExactMatchL(*iIssuerName);
       
   451 	}
       
   452 
       
   453 EXPORT_C const TPtrC8* CWTLSCertificate::DataElementEncoding(const TUint aIndex) const
       
   454 	{
       
   455 	return iDataElements->At(aIndex);
       
   456 	}
       
   457 
       
   458 EXPORT_C void CWTLSCertificate::InternalizeL(RReadStream& aStream)
       
   459 	{
       
   460 	if (iIssuerName != NULL) //just to check cert is uninitialised
       
   461 		{
       
   462 		User::Leave(KErrArgument);
       
   463 		}
       
   464 	iKeyFactory = new(ELeave) TWTLSKeyFactory;
       
   465 	TInt len = aStream.ReadInt32L();
       
   466 	iEncoding = HBufC8::NewL(aStream,len);
       
   467 	TInt pos = 0;
       
   468 	ConstructCertL(*iEncoding, pos);
       
   469 
       
   470 	TWTLSDecUnsignedInteger decInt;
       
   471 	TInt sigLength = decInt.DecodeShortL(*iEncoding, pos, 2);
       
   472 	iSignature = (iEncoding->Mid(pos, sigLength)).AllocL();
       
   473 	CSHA1* hash = CSHA1::NewL();
       
   474 	CleanupStack::PushL(hash);
       
   475 	iFingerprint = hash->Final(Encoding()).AllocL();
       
   476 	CleanupStack::PopAndDestroy();
       
   477 
       
   478 	InitEncodedDataElementsL();
       
   479 	}
       
   480 
       
   481 EXPORT_C TBool CWTLSCertificate::IsTCAL() const
       
   482 	{
       
   483 	TBool isTCA = EFalse;
       
   484 	TPtrC8 nameData = SubjectName().NameData();
       
   485 	CWTLSStructuredText* sText = NULL; //inited to get rid of warning
       
   486 	TRAPD(err, sText = CWTLSStructuredText::NewL(nameData) );
       
   487 	if( err == KErrNone )
       
   488 	    {
       
   489 		const TWTLSStructuredTextField* sTextField = sText->FieldByName(KWTLSTCAType);
       
   490 		if(sTextField != NULL)
       
   491 			{
       
   492 			if(sTextField->Value().Compare(KWTLSTCAValue) == 0)
       
   493 				{
       
   494 				isTCA = ETrue;
       
   495 				}
       
   496 			}
       
   497 		delete sText;
       
   498 		}
       
   499 	return isTCA;
       
   500 	}
       
   501 
       
   502 CWTLSCertificate::CWTLSCertificate()
       
   503 	{
       
   504 	}
       
   505 
       
   506 void CWTLSCertificate::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
       
   507 	{
       
   508 	TInt tempPos = aPos;
       
   509 	ConstructCertL(aBinaryData, aPos);
       
   510 	iKeyFactory = new(ELeave) TWTLSKeyFactory;
       
   511 
       
   512 	TWTLSDecUnsignedInteger decInt;
       
   513 	TInt sigLength = decInt.DecodeShortL(aBinaryData, aPos, 2);
       
   514 	if ((sigLength + aPos) > aBinaryData.Length())
       
   515 		{
       
   516 		User::Leave(KErrArgument);
       
   517 		}
       
   518 	iSignature = (aBinaryData.Mid(aPos, sigLength)).AllocL();
       
   519 	aPos+= sigLength;
       
   520 	iEncoding = aBinaryData.Mid(tempPos, aPos - tempPos).AllocL();
       
   521 
       
   522 	CSHA1* hash = CSHA1::NewL();
       
   523 	CleanupStack::PushL(hash);
       
   524 	iFingerprint = hash->Final(Encoding()).AllocL();
       
   525 	CleanupStack::PopAndDestroy();
       
   526 	
       
   527 	InitEncodedDataElementsL();
       
   528 	}
       
   529 
       
   530 void CWTLSCertificate::ConstructL(const CWTLSCertificate& aCertificate)
       
   531 	{
       
   532 	iEncoding = aCertificate.Encoding().AllocL();
       
   533 	iKeyFactory = new(ELeave) TWTLSKeyFactory;
       
   534 	iSignature = aCertificate.Signature().AllocL();
       
   535 	iFingerprint = aCertificate.Fingerprint().AllocL();
       
   536 	iSigningAlgorithm = CSigningAlgorithmIdentifier::NewL(aCertificate.SigningAlgorithm());
       
   537 	iSerialNumber = aCertificate.iSerialNumber->Des().AllocL();
       
   538 	iIssuerName = CWTLSName::NewL(*(aCertificate.iIssuerName));
       
   539 	iValidityPeriod = new(ELeave) CValidityPeriod(*(aCertificate.iValidityPeriod));
       
   540 	iSubjectName = CWTLSName::NewL(*(aCertificate.iSubjectName));
       
   541 	iSubjectPublicKeyInfo = CSubjectPublicKeyInfo::NewL(*(aCertificate.iSubjectPublicKeyInfo));
       
   542 
       
   543 	InitEncodedDataElementsL();
       
   544 	}
       
   545 
       
   546 void CWTLSCertificate::ConstructCertL(const TDesC8& aBinaryData, TInt& aPos)
       
   547 	{
       
   548 	if ((aBinaryData.Length() - aPos) < 1)
       
   549 		{
       
   550 		User::Leave(KErrArgument);
       
   551 		}
       
   552 	iVersion = aBinaryData[aPos];
       
   553 
       
   554 	aPos++;
       
   555 	iSigningAlgorithm = CWTLSSigningAlgorithmIdentifier::NewL(aBinaryData, aPos);
       
   556 	iIssuerName = CWTLSName::NewL(aBinaryData, aPos);
       
   557 	iValidityPeriod = CWTLSValidityPeriod::NewL(aBinaryData, aPos);
       
   558 	iSubjectName = CWTLSName::NewL(aBinaryData, aPos);
       
   559 	iSubjectPublicKeyInfo = CWTLSSubjectPublicKeyInfo::NewL(aBinaryData, aPos);
       
   560 	iSerialNumber = HBufC8::NewL(0);
       
   561 	*iSerialNumber = KNullDesC8;
       
   562 	}
       
   563 
       
   564 void CWTLSCertificate::InitEncodedDataElementsL()
       
   565 	{
       
   566 	iDataElements = new(ELeave) TFixedArray<TPtrC8*, KWTLSCertMaxDataElements>;
       
   567 	iDataElements->Reset();
       
   568 	const TPtrC8 signedData = SignedDataL();
       
   569 	TInt aPos = 0;
       
   570 	TPtrC8** pElement = iDataElements->Begin();
       
   571 	*pElement++ = new(ELeave) TPtrC8(signedData.Left(++aPos));
       
   572 	*pElement++ = new(ELeave) TPtrC8(signedData.Mid(aPos, aPos));
       
   573 	aPos++;	//	Defect fix from Jetstream
       
   574 	TInt issuerEncodedLength = IssuerName().NameData().Length() + 1;//1 for the identifier type
       
   575 	*pElement++ = new(ELeave) TPtrC8(signedData.Mid(aPos, issuerEncodedLength));
       
   576 	aPos+=+issuerEncodedLength;
       
   577 	*pElement++ = new(ELeave) TPtrC8(signedData.Mid(aPos, 8));
       
   578 	aPos+=8;
       
   579 	TInt subjectEncodedLength = SubjectName().NameData().Length() + 1;//1 for the identifier type
       
   580 	*pElement++ = new(ELeave) TPtrC8(signedData.Mid(aPos, subjectEncodedLength));
       
   581 	aPos+=+subjectEncodedLength;
       
   582 	*pElement++ = new(ELeave) TPtrC8(signedData.Right(signedData.Length() - aPos));
       
   583 	}