os/security/cryptoservices/certificateandkeymgmt/wtlscert/wtlscertchain.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.
     1 /*
     2 * Copyright (c) 1998-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 *
    16 */
    17 
    18 
    19 #include <wtlscertchain.h>
    20 #include <wtlskeys.h>
    21 #include "wtlscertchainao.h"
    22 
    23 //validation status
    24 EXPORT_C TWTLSValidationStatus::TWTLSValidationStatus(const TValidationError aError,
    25 													  const TInt aCert)
    26 	:iReason(aError), iCert(aCert)
    27 	{
    28 	}
    29 
    30 //validationresult
    31 
    32 EXPORT_C CWTLSValidationResult* CWTLSValidationResult::NewLC()
    33 	{
    34 	CWTLSValidationResult* s = new(ELeave) CWTLSValidationResult;
    35 	CleanupStack::PushL(s);
    36 	s->ConstructL();
    37 	return s;
    38 	}
    39 
    40 EXPORT_C CWTLSValidationResult* CWTLSValidationResult::NewL()
    41 	{
    42 	CWTLSValidationResult* s = CWTLSValidationResult::NewLC();
    43 	CleanupStack::Pop();
    44 	return s;
    45 	}
    46 
    47 EXPORT_C CWTLSValidationResult::~CWTLSValidationResult()
    48 	{
    49 	delete iWarnings;
    50 	}
    51 
    52 CWTLSValidationResult::CWTLSValidationResult()
    53 	:iError(EValidatedOK, 0)
    54 	{
    55 	}
    56 
    57 void CWTLSValidationResult::ConstructL()
    58 	{
    59 	iWarnings = new(ELeave) CArrayFixFlat<TWTLSValidationStatus> (1);
    60 	}
    61 
    62 EXPORT_C const TWTLSValidationStatus CWTLSValidationResult::Error() const
    63 	{
    64 	return iError;
    65 	}
    66 
    67 EXPORT_C const CArrayFixFlat<TWTLSValidationStatus>& CWTLSValidationResult::Warnings() const
    68 	{
    69 	return *iWarnings;
    70 	}
    71 
    72 void CWTLSValidationResult::Reset()
    73 	{
    74 	iError = TWTLSValidationStatus(EValidatedOK, 0);
    75 	iWarnings->Reset();
    76 	}
    77 
    78 void CWTLSValidationResult::SetError(const TValidationError aError, const TInt aCert)
    79 	{
    80 	iError.iReason = aError;
    81 	iError.iCert = aCert;
    82 	}
    83 
    84 void CWTLSValidationResult::AppendWarningL(TWTLSValidationStatus aWarning)
    85 	{
    86 	iWarnings->AppendL(aWarning);
    87 	}
    88 
    89 		//WTLS cert chain
    90 
    91 		//constructors
    92 EXPORT_C CWTLSCertChain* CWTLSCertChain::NewL(RFs& aFs,
    93 											  const TPtrC8& aEncodedCerts,
    94 											  const TUid aClient)
    95 	{
    96 	CWTLSCertChain* self = CWTLSCertChain::NewLC(aFs, aEncodedCerts, aClient);
    97 	CleanupStack::Pop();	//self
    98 	return self;
    99 	}
   100 
   101 EXPORT_C CWTLSCertChain* CWTLSCertChain::NewLC(RFs& aFs,
   102 											   const TPtrC8& aEncodedCerts,
   103 											   const TUid aClient)
   104 	{
   105 	CWTLSCertChain* self = new(ELeave) CWTLSCertChain(aFs);
   106 	CleanupStack::PushL(self);
   107 	self->ConstructL(aEncodedCerts, aClient);
   108 	return self;
   109 	}
   110 
   111 EXPORT_C CWTLSCertChain* CWTLSCertChain::NewL(RFs& aFs, 
   112 											  const TPtrC8& aEncodedCerts, 
   113 											  const CArrayPtr<CWTLSCertificate>& aRootCerts)
   114 	{
   115 	CWTLSCertChain* self = CWTLSCertChain::NewLC(aFs, aEncodedCerts, aRootCerts);
   116 	CleanupStack::Pop();//self
   117 	return self;
   118 	}
   119 
   120 EXPORT_C CWTLSCertChain* CWTLSCertChain::NewLC(RFs& aFs, 
   121 											   const TPtrC8& aEncodedCerts, 
   122 											   const CArrayPtr<CWTLSCertificate>& aRootCerts)
   123 	{
   124 	CWTLSCertChain* self = new(ELeave) CWTLSCertChain(aFs);
   125 	CleanupStack::PushL(self);
   126 	self->ConstructL(aEncodedCerts, aRootCerts);
   127 	return self;
   128 	}
   129 
   130 		//destructor	
   131 EXPORT_C CWTLSCertChain::~CWTLSCertChain()
   132 	{
   133 	if (iChain)
   134 		iChain->ResetAndDestroy();
   135 	delete iChain;
   136 	delete iActiveObject;
   137 	}
   138 
   139 		//validation
   140 EXPORT_C void CWTLSCertChain::ValidateL(CWTLSValidationResult& aValidationResult,
   141 										const TTime& aValidationTime,
   142 										TRequestStatus& aStatus)
   143 	{
   144 	__ASSERT_DEBUG(iActiveObject, User::Panic(_L("CWTLSCertChain"), 1));
   145 
   146 	iActiveObject->Validate(aValidationResult, aValidationTime, aStatus);
   147 	}
   148 
   149 		//accessors
   150 EXPORT_C TInt CWTLSCertChain::Count() const
   151 	{
   152 	return iChain->Count();
   153 	}
   154 
   155 EXPORT_C const CWTLSCertificate& CWTLSCertChain::Cert(TInt aIndex) const
   156 	{
   157 	return *(iChain->At(aIndex));
   158 	}
   159 
   160 EXPORT_C TBool CWTLSCertChain::ChainHasRoot() const
   161 	{
   162 	return iChainHasRoot;
   163 	}
   164 
   165 EXPORT_C void CWTLSCertChain::AppendCertsL(const TPtrC8& aEncodedCerts)
   166 	{
   167 	for(TInt pos = 0; pos < aEncodedCerts.Size(); ) 
   168 		{
   169 		CWTLSCertificate* eeCert = CWTLSCertificate::NewLC(aEncodedCerts, pos);
   170 		iChain->AppendL(eeCert);
   171 		CleanupStack::Pop(eeCert);
   172 		}
   173 	}
   174 
   175 //private functions
   176 CWTLSCertChain::CWTLSCertChain(RFs& aFs)
   177 	: iFs(aFs), iChainHasRoot(EFalse)
   178 	{
   179 	}
   180 	
   181 void CWTLSCertChain::ConstructL(const TPtrC8& aEncodedCerts, const TUid aClient)
   182 	{
   183 	iActiveObject = CWTLSCertChainAO::NewL(iFs, *this, aClient);
   184 	DoConstructL(aEncodedCerts);
   185 	}
   186 
   187 void CWTLSCertChain::ConstructL(const TPtrC8& aEncodedCerts, const CArrayPtr<CWTLSCertificate>& aRootCerts)
   188 	{
   189 	iActiveObject = CWTLSCertChainAO::NewL(iFs, *this, aRootCerts);
   190 	DoConstructL(aEncodedCerts);
   191 	}
   192 
   193 void CWTLSCertChain::DoConstructL(const TPtrC8& aEncodedCerts)
   194 	{
   195 	iChain = new(ELeave) CArrayPtrFlat<CWTLSCertificate> (5);
   196 	//typical cert chain unlikely to be more than 5
   197 	AppendCertsL(aEncodedCerts);
   198 	}
   199 
   200