1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/wtlscert/wtlscert.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,584 @@
1.4 +/*
1.5 +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* -- FingerPrint Note:
1.19 +* Developers have to be aware that if they are going to change the fingerprint for this certificate
1.20 +* for a different hash, then there are other places that need to reflect this change
1.21 +* -- Location
1.22 +* void CWTLSCertificate::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
1.23 +* EXPORT_C void CWTLSCertificate::InternalizeL(RReadStream& aStream)
1.24 +* Also change the CX509Certificate and search for other occurences of the current
1.25 +* hash.
1.26 +*
1.27 +*/
1.28 +
1.29 +
1.30 +#include <wtlscert.h>
1.31 +#include <wtlskeys.h>
1.32 +#include "wtlsdec.h"
1.33 +#include <hash.h>
1.34 +
1.35 +enum TEncAlgorithmType
1.36 + {
1.37 + EEncRSA = 0x02
1.38 + };
1.39 +
1.40 +enum TEncSigAlgorithmType
1.41 + {
1.42 + EEncRSAwithSHA1 = 0x02
1.43 + };
1.44 +
1.45 +const TInt KMinAlgIdLength = 2;
1.46 +const TInt KMinExpLengthBytes = 1;
1.47 +const TInt KMaxExpLengthBytes = 65535;
1.48 +const TInt KMinModLengthBytes = 1;
1.49 +const TInt KMaxModLengthBytes = 65535;
1.50 +
1.51 +//WTLS RSA signature result
1.52 +EXPORT_C CWTLSRSASignatureResult* CWTLSRSASignatureResult::NewL(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest)
1.53 + {
1.54 + CWTLSRSASignatureResult* self = CWTLSRSASignatureResult::NewLC(aDigestAlgorithm, aDigest);
1.55 + CleanupStack::Pop();
1.56 + return self;
1.57 + }
1.58 +
1.59 +EXPORT_C CWTLSRSASignatureResult* CWTLSRSASignatureResult::NewLC(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest)
1.60 + {
1.61 + CWTLSRSASignatureResult* self = new(ELeave) CWTLSRSASignatureResult;
1.62 + CleanupStack::PushL(self);
1.63 + self->ConstructL(aDigestAlgorithm, aDigest);
1.64 + return self;
1.65 + }
1.66 +
1.67 +EXPORT_C TBool CWTLSRSASignatureResult::VerifyL(const TDesC8& aResult)
1.68 + {
1.69 + return aResult == *iDigest;
1.70 + }
1.71 +
1.72 +void CWTLSRSASignatureResult::ConstructL(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest)
1.73 + {
1.74 + iDigestAlgorithm = CAlgorithmIdentifier::NewL(aDigestAlgorithm);
1.75 + iDigest = aDigest.AllocL();
1.76 + }
1.77 +
1.78 +//WTLS KeyFactory
1.79 +CRSAPublicKey* TWTLSKeyFactory::RSAPublicKeyL(const TDesC8& aEncoding) const
1.80 + {
1.81 + return CWTLSRSAPublicKey::NewL(aEncoding);
1.82 + }
1.83 +
1.84 +CRSASignatureResult* TWTLSKeyFactory::RSASignatureResultL(const CAlgorithmIdentifier& aDigestAlgorithm, TDesC8& aDigest) const
1.85 + {
1.86 + return CWTLSRSASignatureResult::NewL(aDigestAlgorithm, aDigest);
1.87 + }
1.88 +
1.89 +CDSAPublicKey* TWTLSKeyFactory::DSAPublicKeyL(const CDSAParameters& /*aParams*/, const TDesC8& /*aEncoding*/) const
1.90 + {
1.91 + User::Leave(KErrNotSupported);
1.92 + return NULL;
1.93 + }
1.94 +
1.95 +CDSAPublicKey* TWTLSKeyFactory::DSAPublicKeyL(const TDesC8& /*aParams*/, const TDesC8& /*aEncoding*/) const
1.96 + {
1.97 + User::Leave(KErrNotSupported);
1.98 + return NULL;
1.99 + }
1.100 +
1.101 +CDSASignature* TWTLSKeyFactory::DSASignatureL(const TDesC8& /*aEncoding*/) const
1.102 +{
1.103 + User::Leave(KErrNotSupported);
1.104 + return NULL;
1.105 +}
1.106 +
1.107 +
1.108 +CDSAParameters* TWTLSKeyFactory::DSAParametersL(const TDesC8& /*aParamsEncoding*/) const
1.109 +{
1.110 + User::Leave(KErrNotSupported);
1.111 + return NULL;
1.112 +}
1.113 +
1.114 +//validity period
1.115 +EXPORT_C CWTLSValidityPeriod* CWTLSValidityPeriod::NewL(const TDesC8& aBinaryData)
1.116 + {
1.117 + TInt pos = 0;
1.118 + return CWTLSValidityPeriod::NewL(aBinaryData, pos);
1.119 + }
1.120 +
1.121 +EXPORT_C CWTLSValidityPeriod* CWTLSValidityPeriod::NewLC(const TDesC8& aBinaryData)
1.122 + {
1.123 + TInt pos = 0;
1.124 + return CWTLSValidityPeriod::NewLC(aBinaryData, pos);
1.125 + }
1.126 +
1.127 +EXPORT_C CWTLSValidityPeriod* CWTLSValidityPeriod::NewL(const TDesC8& aBinaryData, TInt& aPos)
1.128 + {
1.129 + CWTLSValidityPeriod* self = CWTLSValidityPeriod::NewLC(aBinaryData, aPos);
1.130 + CleanupStack::Pop();
1.131 + return self;
1.132 + }
1.133 +
1.134 +EXPORT_C CWTLSValidityPeriod* CWTLSValidityPeriod::NewLC(const TDesC8& aBinaryData, TInt& aPos)
1.135 + {
1.136 + CWTLSValidityPeriod* self = new(ELeave) CWTLSValidityPeriod;
1.137 + CleanupStack::PushL(self);
1.138 + self->ConstructL(aBinaryData, aPos);
1.139 + return self;
1.140 + }
1.141 +
1.142 +CWTLSValidityPeriod::CWTLSValidityPeriod()
1.143 + {
1.144 + }
1.145 +
1.146 +void CWTLSValidityPeriod::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
1.147 + {
1.148 + TWTLSDecTime timeDec;
1.149 + iStart = timeDec.DecodeL(aBinaryData, aPos);
1.150 + iFinish = timeDec.DecodeL(aBinaryData, aPos);
1.151 + }
1.152 +
1.153 +//algorithm id
1.154 +EXPORT_C CWTLSAlgorithmIdentifier* CWTLSAlgorithmIdentifier::NewL(const TDesC8& aBinaryData)
1.155 + {
1.156 + TInt pos = 0;
1.157 + return CWTLSAlgorithmIdentifier::NewL(aBinaryData, pos);
1.158 + }
1.159 +
1.160 +EXPORT_C CWTLSAlgorithmIdentifier* CWTLSAlgorithmIdentifier::NewLC(const TDesC8& aBinaryData)
1.161 + {
1.162 + TInt pos = 0;
1.163 + return CWTLSAlgorithmIdentifier::NewLC(aBinaryData, pos);
1.164 + }
1.165 +
1.166 +EXPORT_C CWTLSAlgorithmIdentifier* CWTLSAlgorithmIdentifier::NewL(const TDesC8& aBinaryData, TInt& aPos)
1.167 + {
1.168 + CWTLSAlgorithmIdentifier* self = CWTLSAlgorithmIdentifier::NewLC(aBinaryData, aPos);
1.169 + CleanupStack::Pop();
1.170 + return self;
1.171 + }
1.172 +
1.173 +EXPORT_C CWTLSAlgorithmIdentifier* CWTLSAlgorithmIdentifier::NewLC(const TDesC8& aBinaryData, TInt& aPos)
1.174 + {
1.175 + CWTLSAlgorithmIdentifier* self = new(ELeave) CWTLSAlgorithmIdentifier;
1.176 + CleanupStack::PushL(self);
1.177 + self->ConstructL(aBinaryData, aPos);
1.178 + return self;
1.179 + }
1.180 +
1.181 +CWTLSAlgorithmIdentifier::CWTLSAlgorithmIdentifier()
1.182 + {
1.183 + }
1.184 +
1.185 +void CWTLSAlgorithmIdentifier::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
1.186 + {
1.187 + if ((aBinaryData.Length() - aPos) < KMinAlgIdLength)
1.188 + {
1.189 + User::Leave(KErrArgument);
1.190 + }
1.191 + switch (aBinaryData[aPos])
1.192 + {
1.193 + case EEncRSA:
1.194 + {
1.195 + iAlgorithmId = ERSA;
1.196 + aPos++;
1.197 + if (aBinaryData[aPos] != 0)
1.198 + {
1.199 + User::Leave(KErrArgument);
1.200 + }
1.201 + aPos++;
1.202 + iEncodedParams = HBufC8::NewL(1);
1.203 + *iEncodedParams = KNullDesC8;
1.204 + break;
1.205 + }
1.206 + default:
1.207 + //we only support RSA just now...
1.208 + {
1.209 + User::Leave(KErrNotSupported);
1.210 + }
1.211 + }
1.212 + }
1.213 +
1.214 +//signing algorithm id
1.215 +EXPORT_C CWTLSSigningAlgorithmIdentifier* CWTLSSigningAlgorithmIdentifier::NewL(const TDesC8& aBinaryData)
1.216 + {
1.217 + TInt pos = 0;
1.218 + return CWTLSSigningAlgorithmIdentifier::NewL(aBinaryData, pos);
1.219 + }
1.220 +
1.221 +EXPORT_C CWTLSSigningAlgorithmIdentifier* CWTLSSigningAlgorithmIdentifier::NewLC(const TDesC8& aBinaryData)
1.222 + {
1.223 + TInt pos = 0;
1.224 + return CWTLSSigningAlgorithmIdentifier::NewLC(aBinaryData, pos);
1.225 + }
1.226 +
1.227 +EXPORT_C CWTLSSigningAlgorithmIdentifier* CWTLSSigningAlgorithmIdentifier::NewL(const TDesC8& aBinaryData, TInt& aPos)
1.228 + {
1.229 + CWTLSSigningAlgorithmIdentifier* self = CWTLSSigningAlgorithmIdentifier::NewLC(aBinaryData, aPos);
1.230 + CleanupStack::Pop();
1.231 + return self;
1.232 + }
1.233 +
1.234 +EXPORT_C CWTLSSigningAlgorithmIdentifier* CWTLSSigningAlgorithmIdentifier::NewLC(const TDesC8& aBinaryData, TInt& aPos)
1.235 + {
1.236 + CWTLSSigningAlgorithmIdentifier* self = new(ELeave) CWTLSSigningAlgorithmIdentifier;
1.237 + CleanupStack::PushL(self);
1.238 + self->ConstructL(aBinaryData, aPos);
1.239 + return self;
1.240 + }
1.241 +
1.242 +CWTLSSigningAlgorithmIdentifier::CWTLSSigningAlgorithmIdentifier()
1.243 + {
1.244 + }
1.245 +
1.246 +void CWTLSSigningAlgorithmIdentifier::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
1.247 + {
1.248 + if ((aBinaryData.Length() - aPos) < 1)
1.249 + {
1.250 + User::Leave(KErrArgument);
1.251 + }
1.252 + switch (aBinaryData[aPos])
1.253 + {
1.254 + case EEncRSAwithSHA1:
1.255 + {
1.256 + TAlgorithmId asym = ERSA;
1.257 + TAlgorithmId dig = ESHA1;
1.258 + iAsymmetricAlgorithm = CAlgorithmIdentifier::NewL(asym, KNullDesC8);
1.259 + iDigestAlgorithm = CAlgorithmIdentifier::NewL(dig, KNullDesC8);
1.260 + aPos++;
1.261 + break;
1.262 + }
1.263 + default:
1.264 + //we only support RSA-SHA1 just now...
1.265 + {
1.266 + User::Leave(KErrNotSupported);
1.267 + }
1.268 + }
1.269 + }
1.270 +
1.271 +//wtls subject public key info
1.272 +EXPORT_C CWTLSSubjectPublicKeyInfo* CWTLSSubjectPublicKeyInfo::NewL(const TDesC8& aBinaryData)
1.273 + {
1.274 + TInt pos = 0;
1.275 + return CWTLSSubjectPublicKeyInfo::NewL(aBinaryData, pos);
1.276 + }
1.277 +
1.278 +EXPORT_C CWTLSSubjectPublicKeyInfo* CWTLSSubjectPublicKeyInfo::NewLC(const TDesC8& aBinaryData)
1.279 + {
1.280 + TInt pos = 0;
1.281 + return CWTLSSubjectPublicKeyInfo::NewLC(aBinaryData, pos);
1.282 + }
1.283 +
1.284 +EXPORT_C CWTLSSubjectPublicKeyInfo* CWTLSSubjectPublicKeyInfo::NewL(const TDesC8& aBinaryData, TInt& aPos)
1.285 + {
1.286 + CWTLSSubjectPublicKeyInfo* self = CWTLSSubjectPublicKeyInfo::NewLC(aBinaryData, aPos);
1.287 + CleanupStack::Pop();
1.288 + return self;
1.289 + }
1.290 +
1.291 +EXPORT_C CWTLSSubjectPublicKeyInfo* CWTLSSubjectPublicKeyInfo::NewLC(const TDesC8& aBinaryData, TInt& aPos)
1.292 + {
1.293 + CWTLSSubjectPublicKeyInfo* self = new(ELeave) CWTLSSubjectPublicKeyInfo;
1.294 + CleanupStack::PushL(self);
1.295 + self->ConstructL(aBinaryData, aPos);
1.296 + return self;
1.297 + }
1.298 +
1.299 +CWTLSSubjectPublicKeyInfo::CWTLSSubjectPublicKeyInfo()
1.300 + {
1.301 + }
1.302 +
1.303 +void CWTLSSubjectPublicKeyInfo::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
1.304 + {
1.305 + iAlgId = CWTLSAlgorithmIdentifier::NewL(aBinaryData, aPos);
1.306 + if (iAlgId->Algorithm() != ERSA)
1.307 + {
1.308 + User::Leave(KErrNotSupported);
1.309 + }
1.310 + TInt totalLength = aBinaryData.Length();
1.311 + TInt tempPos = aPos;
1.312 +
1.313 + const TPtrC8 expEnc = aBinaryData.Right(totalLength - aPos);
1.314 + TWTLSDecVector exp(expEnc, KMinExpLengthBytes, KMaxExpLengthBytes);
1.315 + exp.InitL();
1.316 +
1.317 + aPos += exp.EncodingLength();
1.318 +
1.319 + const TPtrC8 modEnc = aBinaryData.Right(totalLength - aPos);
1.320 + TWTLSDecVector mod(modEnc, KMinModLengthBytes, KMaxModLengthBytes);
1.321 + mod.InitL();
1.322 +
1.323 + aPos+= mod.EncodingLength();
1.324 + iEncodedKeyData = (aBinaryData.Mid(tempPos, aPos - tempPos)).AllocL();
1.325 + }
1.326 +
1.327 +//wtls certificate
1.328 +EXPORT_C CWTLSCertificate* CWTLSCertificate::NewL(const TDesC8& aBinaryData)
1.329 + {
1.330 + TInt pos = 0;
1.331 + return CWTLSCertificate::NewL(aBinaryData, pos);
1.332 + }
1.333 +
1.334 +EXPORT_C CWTLSCertificate* CWTLSCertificate::NewLC(const TDesC8& aBinaryData)
1.335 + {
1.336 + TInt pos = 0;
1.337 + return CWTLSCertificate::NewLC(aBinaryData, pos);
1.338 + }
1.339 +
1.340 +EXPORT_C CWTLSCertificate* CWTLSCertificate::NewL(const TDesC8& aBinaryData, TInt& aPos)
1.341 + {
1.342 + CWTLSCertificate* self = CWTLSCertificate::NewLC(aBinaryData, aPos);
1.343 + CleanupStack::Pop();
1.344 + return self;
1.345 + }
1.346 +
1.347 +EXPORT_C CWTLSCertificate* CWTLSCertificate::NewLC(const TDesC8& aBinaryData, TInt& aPos)
1.348 + {
1.349 + CWTLSCertificate* self = new(ELeave) CWTLSCertificate;
1.350 + CleanupStack::PushL(self);
1.351 + self->ConstructL(aBinaryData, aPos);
1.352 + return self;
1.353 + }
1.354 +
1.355 +EXPORT_C CWTLSCertificate* CWTLSCertificate::NewL(RReadStream& aStream)
1.356 + {
1.357 + CWTLSCertificate* self = CWTLSCertificate::NewLC(aStream);
1.358 + CleanupStack::Pop();//self
1.359 + return self;
1.360 + }
1.361 +
1.362 +EXPORT_C CWTLSCertificate* CWTLSCertificate::NewLC(RReadStream& aStream)
1.363 + {
1.364 + CWTLSCertificate* self = new(ELeave) CWTLSCertificate;
1.365 + CleanupStack::PushL(self);
1.366 + self->InternalizeL(aStream);
1.367 + return self;
1.368 + }
1.369 +/*
1.370 +EXPORT_C CWTLSCertificate* CWTLSCertificate::NewL(CCertStore& aStore, const CCertStoreEntry& aEntry)
1.371 + {
1.372 + CWTLSCertificate* self = CWTLSCertificate::NewLC(aStore, aEntry);
1.373 + CleanupStack::Pop();//self
1.374 + return self;
1.375 + }
1.376 +
1.377 +EXPORT_C CWTLSCertificate* CWTLSCertificate::NewLC(CCertStore& aStore, const CCertStoreEntry& aEntry)
1.378 + {
1.379 + CWTLSCertificate* self = new(ELeave) CWTLSCertificate;
1.380 + CleanupStack::PushL(self);
1.381 + aStore.LoadL(*self, aEntry);
1.382 + return self;
1.383 + }
1.384 +*/
1.385 +EXPORT_C CWTLSCertificate* CWTLSCertificate::NewL(const CWTLSCertificate& aCert)
1.386 + {
1.387 + CWTLSCertificate* self = CWTLSCertificate::NewLC(aCert);
1.388 + CleanupStack::Pop();//self
1.389 + return self;
1.390 + }
1.391 +
1.392 +EXPORT_C CWTLSCertificate* CWTLSCertificate::NewLC(const CWTLSCertificate& aCert)
1.393 + {
1.394 + CWTLSCertificate* self = new(ELeave) CWTLSCertificate;
1.395 + CleanupStack::PushL(self);
1.396 + self->ConstructL(aCert);
1.397 + return self;
1.398 + }
1.399 +
1.400 +EXPORT_C CWTLSCertificate::~CWTLSCertificate()
1.401 + {
1.402 + delete iIssuerName;
1.403 + delete iSubjectName;
1.404 +
1.405 + if (iDataElements != NULL)
1.406 + {
1.407 + for (TInt i = 0; i < KWTLSCertMaxDataElements; i++)
1.408 + {
1.409 + delete iDataElements->At(i);
1.410 + }
1.411 + delete iDataElements;
1.412 + }
1.413 + }
1.414 +
1.415 +EXPORT_C TBool CWTLSCertificate::IsEqualL(const CWTLSCertificate& aCert) const
1.416 + {
1.417 + return (*(iFingerprint) == (*(aCert.iFingerprint)));
1.418 + }
1.419 +
1.420 + //extra accessors
1.421 +EXPORT_C const TPtrC8 CWTLSCertificate::SignedDataL() const
1.422 + {
1.423 + return iEncoding->Left(iEncoding->Length() - (iSignature->Length() +2));
1.424 + }
1.425 +
1.426 +EXPORT_C TInt CWTLSCertificate::Version() const
1.427 + {
1.428 + return iVersion;
1.429 + }
1.430 +
1.431 +EXPORT_C const CWTLSName& CWTLSCertificate::IssuerName() const
1.432 + {
1.433 + return *iIssuerName;
1.434 + }
1.435 +
1.436 +EXPORT_C const CWTLSName& CWTLSCertificate::SubjectName() const
1.437 + {
1.438 + return *iSubjectName;
1.439 + }
1.440 +
1.441 +EXPORT_C HBufC* CWTLSCertificate::IssuerL() const
1.442 + {
1.443 + return iIssuerName->DisplayNameL();
1.444 + }
1.445 +
1.446 +EXPORT_C HBufC* CWTLSCertificate::SubjectL() const
1.447 + {
1.448 + return iSubjectName->DisplayNameL();
1.449 + }
1.450 +
1.451 +EXPORT_C TBool CWTLSCertificate::IsSelfSignedL() const
1.452 + {
1.453 + return iSubjectName->ExactMatchL(*iIssuerName);
1.454 + }
1.455 +
1.456 +EXPORT_C const TPtrC8* CWTLSCertificate::DataElementEncoding(const TUint aIndex) const
1.457 + {
1.458 + return iDataElements->At(aIndex);
1.459 + }
1.460 +
1.461 +EXPORT_C void CWTLSCertificate::InternalizeL(RReadStream& aStream)
1.462 + {
1.463 + if (iIssuerName != NULL) //just to check cert is uninitialised
1.464 + {
1.465 + User::Leave(KErrArgument);
1.466 + }
1.467 + iKeyFactory = new(ELeave) TWTLSKeyFactory;
1.468 + TInt len = aStream.ReadInt32L();
1.469 + iEncoding = HBufC8::NewL(aStream,len);
1.470 + TInt pos = 0;
1.471 + ConstructCertL(*iEncoding, pos);
1.472 +
1.473 + TWTLSDecUnsignedInteger decInt;
1.474 + TInt sigLength = decInt.DecodeShortL(*iEncoding, pos, 2);
1.475 + iSignature = (iEncoding->Mid(pos, sigLength)).AllocL();
1.476 + CSHA1* hash = CSHA1::NewL();
1.477 + CleanupStack::PushL(hash);
1.478 + iFingerprint = hash->Final(Encoding()).AllocL();
1.479 + CleanupStack::PopAndDestroy();
1.480 +
1.481 + InitEncodedDataElementsL();
1.482 + }
1.483 +
1.484 +EXPORT_C TBool CWTLSCertificate::IsTCAL() const
1.485 + {
1.486 + TBool isTCA = EFalse;
1.487 + TPtrC8 nameData = SubjectName().NameData();
1.488 + CWTLSStructuredText* sText = NULL; //inited to get rid of warning
1.489 + TRAPD(err, sText = CWTLSStructuredText::NewL(nameData) );
1.490 + if( err == KErrNone )
1.491 + {
1.492 + const TWTLSStructuredTextField* sTextField = sText->FieldByName(KWTLSTCAType);
1.493 + if(sTextField != NULL)
1.494 + {
1.495 + if(sTextField->Value().Compare(KWTLSTCAValue) == 0)
1.496 + {
1.497 + isTCA = ETrue;
1.498 + }
1.499 + }
1.500 + delete sText;
1.501 + }
1.502 + return isTCA;
1.503 + }
1.504 +
1.505 +CWTLSCertificate::CWTLSCertificate()
1.506 + {
1.507 + }
1.508 +
1.509 +void CWTLSCertificate::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
1.510 + {
1.511 + TInt tempPos = aPos;
1.512 + ConstructCertL(aBinaryData, aPos);
1.513 + iKeyFactory = new(ELeave) TWTLSKeyFactory;
1.514 +
1.515 + TWTLSDecUnsignedInteger decInt;
1.516 + TInt sigLength = decInt.DecodeShortL(aBinaryData, aPos, 2);
1.517 + if ((sigLength + aPos) > aBinaryData.Length())
1.518 + {
1.519 + User::Leave(KErrArgument);
1.520 + }
1.521 + iSignature = (aBinaryData.Mid(aPos, sigLength)).AllocL();
1.522 + aPos+= sigLength;
1.523 + iEncoding = aBinaryData.Mid(tempPos, aPos - tempPos).AllocL();
1.524 +
1.525 + CSHA1* hash = CSHA1::NewL();
1.526 + CleanupStack::PushL(hash);
1.527 + iFingerprint = hash->Final(Encoding()).AllocL();
1.528 + CleanupStack::PopAndDestroy();
1.529 +
1.530 + InitEncodedDataElementsL();
1.531 + }
1.532 +
1.533 +void CWTLSCertificate::ConstructL(const CWTLSCertificate& aCertificate)
1.534 + {
1.535 + iEncoding = aCertificate.Encoding().AllocL();
1.536 + iKeyFactory = new(ELeave) TWTLSKeyFactory;
1.537 + iSignature = aCertificate.Signature().AllocL();
1.538 + iFingerprint = aCertificate.Fingerprint().AllocL();
1.539 + iSigningAlgorithm = CSigningAlgorithmIdentifier::NewL(aCertificate.SigningAlgorithm());
1.540 + iSerialNumber = aCertificate.iSerialNumber->Des().AllocL();
1.541 + iIssuerName = CWTLSName::NewL(*(aCertificate.iIssuerName));
1.542 + iValidityPeriod = new(ELeave) CValidityPeriod(*(aCertificate.iValidityPeriod));
1.543 + iSubjectName = CWTLSName::NewL(*(aCertificate.iSubjectName));
1.544 + iSubjectPublicKeyInfo = CSubjectPublicKeyInfo::NewL(*(aCertificate.iSubjectPublicKeyInfo));
1.545 +
1.546 + InitEncodedDataElementsL();
1.547 + }
1.548 +
1.549 +void CWTLSCertificate::ConstructCertL(const TDesC8& aBinaryData, TInt& aPos)
1.550 + {
1.551 + if ((aBinaryData.Length() - aPos) < 1)
1.552 + {
1.553 + User::Leave(KErrArgument);
1.554 + }
1.555 + iVersion = aBinaryData[aPos];
1.556 +
1.557 + aPos++;
1.558 + iSigningAlgorithm = CWTLSSigningAlgorithmIdentifier::NewL(aBinaryData, aPos);
1.559 + iIssuerName = CWTLSName::NewL(aBinaryData, aPos);
1.560 + iValidityPeriod = CWTLSValidityPeriod::NewL(aBinaryData, aPos);
1.561 + iSubjectName = CWTLSName::NewL(aBinaryData, aPos);
1.562 + iSubjectPublicKeyInfo = CWTLSSubjectPublicKeyInfo::NewL(aBinaryData, aPos);
1.563 + iSerialNumber = HBufC8::NewL(0);
1.564 + *iSerialNumber = KNullDesC8;
1.565 + }
1.566 +
1.567 +void CWTLSCertificate::InitEncodedDataElementsL()
1.568 + {
1.569 + iDataElements = new(ELeave) TFixedArray<TPtrC8*, KWTLSCertMaxDataElements>;
1.570 + iDataElements->Reset();
1.571 + const TPtrC8 signedData = SignedDataL();
1.572 + TInt aPos = 0;
1.573 + TPtrC8** pElement = iDataElements->Begin();
1.574 + *pElement++ = new(ELeave) TPtrC8(signedData.Left(++aPos));
1.575 + *pElement++ = new(ELeave) TPtrC8(signedData.Mid(aPos, aPos));
1.576 + aPos++; // Defect fix from Jetstream
1.577 + TInt issuerEncodedLength = IssuerName().NameData().Length() + 1;//1 for the identifier type
1.578 + *pElement++ = new(ELeave) TPtrC8(signedData.Mid(aPos, issuerEncodedLength));
1.579 + aPos+=+issuerEncodedLength;
1.580 + *pElement++ = new(ELeave) TPtrC8(signedData.Mid(aPos, 8));
1.581 + aPos+=8;
1.582 + TInt subjectEncodedLength = SubjectName().NameData().Length() + 1;//1 for the identifier type
1.583 + *pElement++ = new(ELeave) TPtrC8(signedData.Mid(aPos, subjectEncodedLength));
1.584 + aPos+=+subjectEncodedLength;
1.585 + *pElement++ = new(ELeave) TPtrC8(signedData.Right(signedData.Length() - aPos));
1.586 + }
1.587 +