1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/wtlscert/wtlscertchain.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,200 @@
1.4 +/*
1.5 +* Copyright (c) 1998-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 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include <wtlscertchain.h>
1.23 +#include <wtlskeys.h>
1.24 +#include "wtlscertchainao.h"
1.25 +
1.26 +//validation status
1.27 +EXPORT_C TWTLSValidationStatus::TWTLSValidationStatus(const TValidationError aError,
1.28 + const TInt aCert)
1.29 + :iReason(aError), iCert(aCert)
1.30 + {
1.31 + }
1.32 +
1.33 +//validationresult
1.34 +
1.35 +EXPORT_C CWTLSValidationResult* CWTLSValidationResult::NewLC()
1.36 + {
1.37 + CWTLSValidationResult* s = new(ELeave) CWTLSValidationResult;
1.38 + CleanupStack::PushL(s);
1.39 + s->ConstructL();
1.40 + return s;
1.41 + }
1.42 +
1.43 +EXPORT_C CWTLSValidationResult* CWTLSValidationResult::NewL()
1.44 + {
1.45 + CWTLSValidationResult* s = CWTLSValidationResult::NewLC();
1.46 + CleanupStack::Pop();
1.47 + return s;
1.48 + }
1.49 +
1.50 +EXPORT_C CWTLSValidationResult::~CWTLSValidationResult()
1.51 + {
1.52 + delete iWarnings;
1.53 + }
1.54 +
1.55 +CWTLSValidationResult::CWTLSValidationResult()
1.56 + :iError(EValidatedOK, 0)
1.57 + {
1.58 + }
1.59 +
1.60 +void CWTLSValidationResult::ConstructL()
1.61 + {
1.62 + iWarnings = new(ELeave) CArrayFixFlat<TWTLSValidationStatus> (1);
1.63 + }
1.64 +
1.65 +EXPORT_C const TWTLSValidationStatus CWTLSValidationResult::Error() const
1.66 + {
1.67 + return iError;
1.68 + }
1.69 +
1.70 +EXPORT_C const CArrayFixFlat<TWTLSValidationStatus>& CWTLSValidationResult::Warnings() const
1.71 + {
1.72 + return *iWarnings;
1.73 + }
1.74 +
1.75 +void CWTLSValidationResult::Reset()
1.76 + {
1.77 + iError = TWTLSValidationStatus(EValidatedOK, 0);
1.78 + iWarnings->Reset();
1.79 + }
1.80 +
1.81 +void CWTLSValidationResult::SetError(const TValidationError aError, const TInt aCert)
1.82 + {
1.83 + iError.iReason = aError;
1.84 + iError.iCert = aCert;
1.85 + }
1.86 +
1.87 +void CWTLSValidationResult::AppendWarningL(TWTLSValidationStatus aWarning)
1.88 + {
1.89 + iWarnings->AppendL(aWarning);
1.90 + }
1.91 +
1.92 + //WTLS cert chain
1.93 +
1.94 + //constructors
1.95 +EXPORT_C CWTLSCertChain* CWTLSCertChain::NewL(RFs& aFs,
1.96 + const TPtrC8& aEncodedCerts,
1.97 + const TUid aClient)
1.98 + {
1.99 + CWTLSCertChain* self = CWTLSCertChain::NewLC(aFs, aEncodedCerts, aClient);
1.100 + CleanupStack::Pop(); //self
1.101 + return self;
1.102 + }
1.103 +
1.104 +EXPORT_C CWTLSCertChain* CWTLSCertChain::NewLC(RFs& aFs,
1.105 + const TPtrC8& aEncodedCerts,
1.106 + const TUid aClient)
1.107 + {
1.108 + CWTLSCertChain* self = new(ELeave) CWTLSCertChain(aFs);
1.109 + CleanupStack::PushL(self);
1.110 + self->ConstructL(aEncodedCerts, aClient);
1.111 + return self;
1.112 + }
1.113 +
1.114 +EXPORT_C CWTLSCertChain* CWTLSCertChain::NewL(RFs& aFs,
1.115 + const TPtrC8& aEncodedCerts,
1.116 + const CArrayPtr<CWTLSCertificate>& aRootCerts)
1.117 + {
1.118 + CWTLSCertChain* self = CWTLSCertChain::NewLC(aFs, aEncodedCerts, aRootCerts);
1.119 + CleanupStack::Pop();//self
1.120 + return self;
1.121 + }
1.122 +
1.123 +EXPORT_C CWTLSCertChain* CWTLSCertChain::NewLC(RFs& aFs,
1.124 + const TPtrC8& aEncodedCerts,
1.125 + const CArrayPtr<CWTLSCertificate>& aRootCerts)
1.126 + {
1.127 + CWTLSCertChain* self = new(ELeave) CWTLSCertChain(aFs);
1.128 + CleanupStack::PushL(self);
1.129 + self->ConstructL(aEncodedCerts, aRootCerts);
1.130 + return self;
1.131 + }
1.132 +
1.133 + //destructor
1.134 +EXPORT_C CWTLSCertChain::~CWTLSCertChain()
1.135 + {
1.136 + if (iChain)
1.137 + iChain->ResetAndDestroy();
1.138 + delete iChain;
1.139 + delete iActiveObject;
1.140 + }
1.141 +
1.142 + //validation
1.143 +EXPORT_C void CWTLSCertChain::ValidateL(CWTLSValidationResult& aValidationResult,
1.144 + const TTime& aValidationTime,
1.145 + TRequestStatus& aStatus)
1.146 + {
1.147 + __ASSERT_DEBUG(iActiveObject, User::Panic(_L("CWTLSCertChain"), 1));
1.148 +
1.149 + iActiveObject->Validate(aValidationResult, aValidationTime, aStatus);
1.150 + }
1.151 +
1.152 + //accessors
1.153 +EXPORT_C TInt CWTLSCertChain::Count() const
1.154 + {
1.155 + return iChain->Count();
1.156 + }
1.157 +
1.158 +EXPORT_C const CWTLSCertificate& CWTLSCertChain::Cert(TInt aIndex) const
1.159 + {
1.160 + return *(iChain->At(aIndex));
1.161 + }
1.162 +
1.163 +EXPORT_C TBool CWTLSCertChain::ChainHasRoot() const
1.164 + {
1.165 + return iChainHasRoot;
1.166 + }
1.167 +
1.168 +EXPORT_C void CWTLSCertChain::AppendCertsL(const TPtrC8& aEncodedCerts)
1.169 + {
1.170 + for(TInt pos = 0; pos < aEncodedCerts.Size(); )
1.171 + {
1.172 + CWTLSCertificate* eeCert = CWTLSCertificate::NewLC(aEncodedCerts, pos);
1.173 + iChain->AppendL(eeCert);
1.174 + CleanupStack::Pop(eeCert);
1.175 + }
1.176 + }
1.177 +
1.178 +//private functions
1.179 +CWTLSCertChain::CWTLSCertChain(RFs& aFs)
1.180 + : iFs(aFs), iChainHasRoot(EFalse)
1.181 + {
1.182 + }
1.183 +
1.184 +void CWTLSCertChain::ConstructL(const TPtrC8& aEncodedCerts, const TUid aClient)
1.185 + {
1.186 + iActiveObject = CWTLSCertChainAO::NewL(iFs, *this, aClient);
1.187 + DoConstructL(aEncodedCerts);
1.188 + }
1.189 +
1.190 +void CWTLSCertChain::ConstructL(const TPtrC8& aEncodedCerts, const CArrayPtr<CWTLSCertificate>& aRootCerts)
1.191 + {
1.192 + iActiveObject = CWTLSCertChainAO::NewL(iFs, *this, aRootCerts);
1.193 + DoConstructL(aEncodedCerts);
1.194 + }
1.195 +
1.196 +void CWTLSCertChain::DoConstructL(const TPtrC8& aEncodedCerts)
1.197 + {
1.198 + iChain = new(ELeave) CArrayPtrFlat<CWTLSCertificate> (5);
1.199 + //typical cert chain unlikely to be more than 5
1.200 + AppendCertsL(aEncodedCerts);
1.201 + }
1.202 +
1.203 +