sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2004-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 "pkixCertChainHelper.h"
|
sl@0
|
20 |
#include <pkixcertchain.h>
|
sl@0
|
21 |
#include <pkixvalidationresult.h>
|
sl@0
|
22 |
#include <unifiedcertstore.h>
|
sl@0
|
23 |
|
sl@0
|
24 |
_LIT(KPanicCat, "CPKIXCertChainHelper");
|
sl@0
|
25 |
|
sl@0
|
26 |
CPKIXCertChainHelper* CPKIXCertChainHelper::NewL(RFs& aFs)
|
sl@0
|
27 |
{
|
sl@0
|
28 |
CPKIXCertChainHelper* self = new (ELeave) CPKIXCertChainHelper();
|
sl@0
|
29 |
CleanupStack::PushL(self);
|
sl@0
|
30 |
self->ConstructL(aFs);
|
sl@0
|
31 |
CleanupStack::Pop(self);
|
sl@0
|
32 |
return self;
|
sl@0
|
33 |
}
|
sl@0
|
34 |
|
sl@0
|
35 |
CPKIXCertChainHelper::CPKIXCertChainHelper() :
|
sl@0
|
36 |
CActive(EPriorityNormal)
|
sl@0
|
37 |
{
|
sl@0
|
38 |
CActiveScheduler::Add(this);
|
sl@0
|
39 |
}
|
sl@0
|
40 |
|
sl@0
|
41 |
void CPKIXCertChainHelper::ConstructL(RFs& aFs)
|
sl@0
|
42 |
{
|
sl@0
|
43 |
iCertStore = CUnifiedCertStore::NewL(aFs, EFalse);
|
sl@0
|
44 |
}
|
sl@0
|
45 |
|
sl@0
|
46 |
CPKIXCertChainHelper::~CPKIXCertChainHelper()
|
sl@0
|
47 |
{
|
sl@0
|
48 |
Cancel();
|
sl@0
|
49 |
delete iCertStore;
|
sl@0
|
50 |
}
|
sl@0
|
51 |
|
sl@0
|
52 |
CUnifiedCertStore& CPKIXCertChainHelper::CertStore()
|
sl@0
|
53 |
{
|
sl@0
|
54 |
return *iCertStore;
|
sl@0
|
55 |
}
|
sl@0
|
56 |
|
sl@0
|
57 |
void CPKIXCertChainHelper::Validate(CPKIXCertChainBase& aCertChain,
|
sl@0
|
58 |
CPKIXValidationResult& aValidationResult,
|
sl@0
|
59 |
const TTime& aValidationTime,
|
sl@0
|
60 |
TRequestStatus& aStatus)
|
sl@0
|
61 |
{
|
sl@0
|
62 |
StartValidate(aCertChain, aValidationResult, aValidationTime, NULL,
|
sl@0
|
63 |
aStatus);
|
sl@0
|
64 |
}
|
sl@0
|
65 |
|
sl@0
|
66 |
void CPKIXCertChainHelper::Validate(CPKIXCertChainBase& aCertChain,
|
sl@0
|
67 |
CPKIXValidationResult& aValidationResult,
|
sl@0
|
68 |
const TTime& aValidationTime,
|
sl@0
|
69 |
const CArrayPtr<HBufC>& aInitialPolicies,
|
sl@0
|
70 |
TRequestStatus& aStatus)
|
sl@0
|
71 |
{
|
sl@0
|
72 |
StartValidate(aCertChain, aValidationResult, aValidationTime, &aInitialPolicies,
|
sl@0
|
73 |
aStatus);
|
sl@0
|
74 |
}
|
sl@0
|
75 |
|
sl@0
|
76 |
void CPKIXCertChainHelper::CancelValidate()
|
sl@0
|
77 |
{
|
sl@0
|
78 |
if (iState == EInitializeCertStore ||
|
sl@0
|
79 |
iState == EValidateChain)
|
sl@0
|
80 |
{
|
sl@0
|
81 |
Cancel();
|
sl@0
|
82 |
}
|
sl@0
|
83 |
}
|
sl@0
|
84 |
|
sl@0
|
85 |
void CPKIXCertChainHelper::StartValidate(CPKIXCertChainBase& aCertChain,
|
sl@0
|
86 |
CPKIXValidationResult& aValidationResult,
|
sl@0
|
87 |
const TTime& aValidationTime,
|
sl@0
|
88 |
const CArrayPtr<HBufC>* aInitialPolicies,
|
sl@0
|
89 |
TRequestStatus& aStatus)
|
sl@0
|
90 |
{
|
sl@0
|
91 |
__ASSERT_ALWAYS(iState == EIdle, User::Panic(KPanicCat, 1));
|
sl@0
|
92 |
iCertChain = &aCertChain;
|
sl@0
|
93 |
iValidationResult = &aValidationResult;
|
sl@0
|
94 |
iValidationTime = aValidationTime;
|
sl@0
|
95 |
iInitialPolicies = aInitialPolicies;
|
sl@0
|
96 |
iClientStatus = &aStatus;
|
sl@0
|
97 |
aStatus = KRequestPending;
|
sl@0
|
98 |
InitializeCertStore();
|
sl@0
|
99 |
}
|
sl@0
|
100 |
|
sl@0
|
101 |
void CPKIXCertChainHelper::InitializeCertStore()
|
sl@0
|
102 |
{
|
sl@0
|
103 |
iState = EInitializeCertStore;
|
sl@0
|
104 |
if (iCertStoreInitialized)
|
sl@0
|
105 |
{
|
sl@0
|
106 |
TRequestStatus* status = &iStatus;
|
sl@0
|
107 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
108 |
}
|
sl@0
|
109 |
else
|
sl@0
|
110 |
{
|
sl@0
|
111 |
iCertStore->Initialize(iStatus);
|
sl@0
|
112 |
}
|
sl@0
|
113 |
SetActive();
|
sl@0
|
114 |
}
|
sl@0
|
115 |
|
sl@0
|
116 |
void CPKIXCertChainHelper::ValidateChainL()
|
sl@0
|
117 |
{
|
sl@0
|
118 |
iState = EValidateChain;
|
sl@0
|
119 |
if (iInitialPolicies)
|
sl@0
|
120 |
{
|
sl@0
|
121 |
iCertChain->ValidateL(*iValidationResult,
|
sl@0
|
122 |
iValidationTime,
|
sl@0
|
123 |
*iInitialPolicies,
|
sl@0
|
124 |
iStatus);
|
sl@0
|
125 |
}
|
sl@0
|
126 |
else
|
sl@0
|
127 |
{
|
sl@0
|
128 |
iCertChain->ValidateL(*iValidationResult,
|
sl@0
|
129 |
iValidationTime,
|
sl@0
|
130 |
iStatus);
|
sl@0
|
131 |
}
|
sl@0
|
132 |
SetActive();
|
sl@0
|
133 |
}
|
sl@0
|
134 |
|
sl@0
|
135 |
void CPKIXCertChainHelper::RunL()
|
sl@0
|
136 |
{
|
sl@0
|
137 |
User::LeaveIfError(iStatus.Int());
|
sl@0
|
138 |
|
sl@0
|
139 |
switch (iState)
|
sl@0
|
140 |
{
|
sl@0
|
141 |
case EInitializeCertStore:
|
sl@0
|
142 |
iCertStoreInitialized = ETrue;
|
sl@0
|
143 |
ValidateChainL();
|
sl@0
|
144 |
break;
|
sl@0
|
145 |
|
sl@0
|
146 |
case EValidateChain:
|
sl@0
|
147 |
Complete(KErrNone);
|
sl@0
|
148 |
break;
|
sl@0
|
149 |
|
sl@0
|
150 |
default:
|
sl@0
|
151 |
User::Invariant();
|
sl@0
|
152 |
}
|
sl@0
|
153 |
}
|
sl@0
|
154 |
|
sl@0
|
155 |
TInt CPKIXCertChainHelper::RunError(TInt aError)
|
sl@0
|
156 |
{
|
sl@0
|
157 |
Complete(aError);
|
sl@0
|
158 |
return KErrNone;
|
sl@0
|
159 |
}
|
sl@0
|
160 |
|
sl@0
|
161 |
void CPKIXCertChainHelper::DoCancel()
|
sl@0
|
162 |
{
|
sl@0
|
163 |
TInt result = KErrCancel;
|
sl@0
|
164 |
|
sl@0
|
165 |
switch (iState)
|
sl@0
|
166 |
{
|
sl@0
|
167 |
case EInitializeCertStore:
|
sl@0
|
168 |
iCertStore->CancelInitialize();
|
sl@0
|
169 |
break;
|
sl@0
|
170 |
|
sl@0
|
171 |
case EValidateChain:
|
sl@0
|
172 |
if (iStatus == KRequestPending)
|
sl@0
|
173 |
{
|
sl@0
|
174 |
iCertChain->CancelValidate();
|
sl@0
|
175 |
}
|
sl@0
|
176 |
else
|
sl@0
|
177 |
{
|
sl@0
|
178 |
result = iStatus.Int();
|
sl@0
|
179 |
}
|
sl@0
|
180 |
break;
|
sl@0
|
181 |
|
sl@0
|
182 |
default:
|
sl@0
|
183 |
// Do nothing
|
sl@0
|
184 |
break;
|
sl@0
|
185 |
}
|
sl@0
|
186 |
|
sl@0
|
187 |
Complete(result);
|
sl@0
|
188 |
}
|
sl@0
|
189 |
|
sl@0
|
190 |
void CPKIXCertChainHelper::Complete(TInt aError)
|
sl@0
|
191 |
{
|
sl@0
|
192 |
iState = EIdle;
|
sl@0
|
193 |
iCertChain = NULL;
|
sl@0
|
194 |
iValidationResult = NULL;
|
sl@0
|
195 |
iInitialPolicies = NULL;
|
sl@0
|
196 |
if (iClientStatus)
|
sl@0
|
197 |
{
|
sl@0
|
198 |
User::RequestComplete(iClientStatus, aError);
|
sl@0
|
199 |
}
|
sl@0
|
200 |
}
|