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