sl@0: /* sl@0: * Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include "wtlscertchainao.h" sl@0: sl@0: //validation status sl@0: EXPORT_C TWTLSValidationStatus::TWTLSValidationStatus(const TValidationError aError, sl@0: const TInt aCert) sl@0: :iReason(aError), iCert(aCert) sl@0: { sl@0: } sl@0: sl@0: //validationresult sl@0: sl@0: EXPORT_C CWTLSValidationResult* CWTLSValidationResult::NewLC() sl@0: { sl@0: CWTLSValidationResult* s = new(ELeave) CWTLSValidationResult; sl@0: CleanupStack::PushL(s); sl@0: s->ConstructL(); sl@0: return s; sl@0: } sl@0: sl@0: EXPORT_C CWTLSValidationResult* CWTLSValidationResult::NewL() sl@0: { sl@0: CWTLSValidationResult* s = CWTLSValidationResult::NewLC(); sl@0: CleanupStack::Pop(); sl@0: return s; sl@0: } sl@0: sl@0: EXPORT_C CWTLSValidationResult::~CWTLSValidationResult() sl@0: { sl@0: delete iWarnings; sl@0: } sl@0: sl@0: CWTLSValidationResult::CWTLSValidationResult() sl@0: :iError(EValidatedOK, 0) sl@0: { sl@0: } sl@0: sl@0: void CWTLSValidationResult::ConstructL() sl@0: { sl@0: iWarnings = new(ELeave) CArrayFixFlat (1); sl@0: } sl@0: sl@0: EXPORT_C const TWTLSValidationStatus CWTLSValidationResult::Error() const sl@0: { sl@0: return iError; sl@0: } sl@0: sl@0: EXPORT_C const CArrayFixFlat& CWTLSValidationResult::Warnings() const sl@0: { sl@0: return *iWarnings; sl@0: } sl@0: sl@0: void CWTLSValidationResult::Reset() sl@0: { sl@0: iError = TWTLSValidationStatus(EValidatedOK, 0); sl@0: iWarnings->Reset(); sl@0: } sl@0: sl@0: void CWTLSValidationResult::SetError(const TValidationError aError, const TInt aCert) sl@0: { sl@0: iError.iReason = aError; sl@0: iError.iCert = aCert; sl@0: } sl@0: sl@0: void CWTLSValidationResult::AppendWarningL(TWTLSValidationStatus aWarning) sl@0: { sl@0: iWarnings->AppendL(aWarning); sl@0: } sl@0: sl@0: //WTLS cert chain sl@0: sl@0: //constructors sl@0: EXPORT_C CWTLSCertChain* CWTLSCertChain::NewL(RFs& aFs, sl@0: const TPtrC8& aEncodedCerts, sl@0: const TUid aClient) sl@0: { sl@0: CWTLSCertChain* self = CWTLSCertChain::NewLC(aFs, aEncodedCerts, aClient); sl@0: CleanupStack::Pop(); //self sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CWTLSCertChain* CWTLSCertChain::NewLC(RFs& aFs, sl@0: const TPtrC8& aEncodedCerts, sl@0: const TUid aClient) sl@0: { sl@0: CWTLSCertChain* self = new(ELeave) CWTLSCertChain(aFs); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aEncodedCerts, aClient); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CWTLSCertChain* CWTLSCertChain::NewL(RFs& aFs, sl@0: const TPtrC8& aEncodedCerts, sl@0: const CArrayPtr& aRootCerts) sl@0: { sl@0: CWTLSCertChain* self = CWTLSCertChain::NewLC(aFs, aEncodedCerts, aRootCerts); sl@0: CleanupStack::Pop();//self sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CWTLSCertChain* CWTLSCertChain::NewLC(RFs& aFs, sl@0: const TPtrC8& aEncodedCerts, sl@0: const CArrayPtr& aRootCerts) sl@0: { sl@0: CWTLSCertChain* self = new(ELeave) CWTLSCertChain(aFs); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aEncodedCerts, aRootCerts); sl@0: return self; sl@0: } sl@0: sl@0: //destructor sl@0: EXPORT_C CWTLSCertChain::~CWTLSCertChain() sl@0: { sl@0: if (iChain) sl@0: iChain->ResetAndDestroy(); sl@0: delete iChain; sl@0: delete iActiveObject; sl@0: } sl@0: sl@0: //validation sl@0: EXPORT_C void CWTLSCertChain::ValidateL(CWTLSValidationResult& aValidationResult, sl@0: const TTime& aValidationTime, sl@0: TRequestStatus& aStatus) sl@0: { sl@0: __ASSERT_DEBUG(iActiveObject, User::Panic(_L("CWTLSCertChain"), 1)); sl@0: sl@0: iActiveObject->Validate(aValidationResult, aValidationTime, aStatus); sl@0: } sl@0: sl@0: //accessors sl@0: EXPORT_C TInt CWTLSCertChain::Count() const sl@0: { sl@0: return iChain->Count(); sl@0: } sl@0: sl@0: EXPORT_C const CWTLSCertificate& CWTLSCertChain::Cert(TInt aIndex) const sl@0: { sl@0: return *(iChain->At(aIndex)); sl@0: } sl@0: sl@0: EXPORT_C TBool CWTLSCertChain::ChainHasRoot() const sl@0: { sl@0: return iChainHasRoot; sl@0: } sl@0: sl@0: EXPORT_C void CWTLSCertChain::AppendCertsL(const TPtrC8& aEncodedCerts) sl@0: { sl@0: for(TInt pos = 0; pos < aEncodedCerts.Size(); ) sl@0: { sl@0: CWTLSCertificate* eeCert = CWTLSCertificate::NewLC(aEncodedCerts, pos); sl@0: iChain->AppendL(eeCert); sl@0: CleanupStack::Pop(eeCert); sl@0: } sl@0: } sl@0: sl@0: //private functions sl@0: CWTLSCertChain::CWTLSCertChain(RFs& aFs) sl@0: : iFs(aFs), iChainHasRoot(EFalse) sl@0: { sl@0: } sl@0: sl@0: void CWTLSCertChain::ConstructL(const TPtrC8& aEncodedCerts, const TUid aClient) sl@0: { sl@0: iActiveObject = CWTLSCertChainAO::NewL(iFs, *this, aClient); sl@0: DoConstructL(aEncodedCerts); sl@0: } sl@0: sl@0: void CWTLSCertChain::ConstructL(const TPtrC8& aEncodedCerts, const CArrayPtr& aRootCerts) sl@0: { sl@0: iActiveObject = CWTLSCertChainAO::NewL(iFs, *this, aRootCerts); sl@0: DoConstructL(aEncodedCerts); sl@0: } sl@0: sl@0: void CWTLSCertChain::DoConstructL(const TPtrC8& aEncodedCerts) sl@0: { sl@0: iChain = new(ELeave) CArrayPtrFlat (5); sl@0: //typical cert chain unlikely to be more than 5 sl@0: AppendCertsL(aEncodedCerts); sl@0: } sl@0: sl@0: