|
1 /* |
|
2 * Copyright (c) 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 "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: An XmlSec interface to the Symbian Unified Certificate Store |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "xmlsecmsymbiancertchain.h" |
|
19 |
|
20 // --------------------------------------------------------------------------- |
|
21 // Constructor |
|
22 // --------------------------------------------------------------------------- |
|
23 // |
|
24 CSymbianCertChain::CSymbianCertChain() |
|
25 : CActive( EPriorityStandard ), |
|
26 iCertChain( NULL ), |
|
27 iValidationResult( NULL ), |
|
28 iState( EUnitialized ) |
|
29 { |
|
30 } |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // Second phase constructor |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 void CSymbianCertChain::ConstructL() |
|
37 { |
|
38 User::LeaveIfError(iFs.Connect()); |
|
39 CActiveScheduler::Add(this); |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // Two phase constructor |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 EXPORT_C CSymbianCertChain* CSymbianCertChain::NewL() |
|
47 { |
|
48 CSymbianCertChain* self = new( ELeave ) CSymbianCertChain; |
|
49 |
|
50 CleanupStack::PushL( self ); |
|
51 self->ConstructL(); |
|
52 CleanupStack::Pop(self); |
|
53 |
|
54 return self; |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // Destructor |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 EXPORT_C CSymbianCertChain::~CSymbianCertChain() |
|
62 { |
|
63 Cancel(); |
|
64 |
|
65 if (iCertChain) |
|
66 { |
|
67 delete iCertChain; |
|
68 } |
|
69 |
|
70 if (iValidationResult) |
|
71 { |
|
72 delete iValidationResult; |
|
73 } |
|
74 |
|
75 iFs.Close(); |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // RunL |
|
80 // Handles an active object's request completion event. |
|
81 // (other items were commented in a header). |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 void CSymbianCertChain::RunL() |
|
85 { |
|
86 TInt errorCode = iStatus.Int(); |
|
87 if ( errorCode ) |
|
88 { |
|
89 User::Leave(errorCode); |
|
90 } |
|
91 |
|
92 switch(iState) |
|
93 { |
|
94 case EValidate: |
|
95 CActiveScheduler::Stop(); |
|
96 break; |
|
97 default: |
|
98 break; |
|
99 |
|
100 } |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // DoCancel |
|
105 // This function is called as part of the active object's Cancel(). |
|
106 // (other items were commented in a header). |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 void CSymbianCertChain::DoCancel() |
|
110 { |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CSymbianCertStore::RunError |
|
115 // Handles Leaves from RunL function. |
|
116 // (other items were commented in a header). |
|
117 // ----------------------------------------------------------------------------- |
|
118 // |
|
119 TInt CSymbianCertChain::RunError(TInt aError) |
|
120 { |
|
121 iError=aError; |
|
122 CActiveScheduler::Stop(); |
|
123 return KErrNone; |
|
124 } |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // InitializeL |
|
128 // Creates the CPKIXCertChain |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 EXPORT_C void CSymbianCertChain::InitializeL( |
|
132 TUint8 *aEncodedCerts, // One or more concatenated DER encoded X.509 certificates |
|
133 TUint aEncodedCertsLen, // Length of the DER encoded X.509 certificates |
|
134 const RPointerArray< CX509Certificate > &aRootCerts) // An array of certificates which the chain will treat as candidate root certificates |
|
135 { |
|
136 |
|
137 TPtrC8 certPtr(aEncodedCerts, aEncodedCertsLen); |
|
138 |
|
139 if (iCertChain) |
|
140 { |
|
141 delete iCertChain; |
|
142 iCertChain = NULL; |
|
143 } |
|
144 |
|
145 iCertChain = CPKIXCertChain::NewL(iFs, certPtr, aRootCerts); |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // ValidateL |
|
150 // Validate the certificate |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 EXPORT_C void CSymbianCertChain::ValidateL() |
|
154 { |
|
155 // iValidationResult will contain the result of the validation |
|
156 __ASSERT_ALWAYS(iCertChain, User::Leave(KErrGeneral)); |
|
157 |
|
158 if (iValidationResult) |
|
159 { |
|
160 delete iValidationResult; |
|
161 iValidationResult = NULL; |
|
162 } |
|
163 |
|
164 TTime validationTime; |
|
165 validationTime.HomeTime(); |
|
166 |
|
167 iValidationResult = CPKIXValidationResult::NewL(); |
|
168 |
|
169 iCertChain->ValidateL(*iValidationResult, validationTime, iStatus); |
|
170 |
|
171 iState = EValidate; |
|
172 SetActive(); |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // GetValidateResult |
|
177 // Get the result of the validation |
|
178 // Returns: EValidatedOK (0) if validation succeeds |
|
179 // -1 if no result can be fetched |
|
180 // enum TValidationError if validation fails |
|
181 // ----------------------------------------------------------------------------- |
|
182 // |
|
183 EXPORT_C TInt CSymbianCertChain::GetValidateResult() |
|
184 { |
|
185 // iValidationResult contains the result of the validation |
|
186 if (!iValidationResult) |
|
187 return -1; |
|
188 |
|
189 return iValidationResult->Error().iReason; |
|
190 |
|
191 } |
|
192 |
|
193 // ----------------------------------------------------------------------------- |
|
194 // GetError |
|
195 // Get the error flag |
|
196 // Returns: error code |
|
197 // ----------------------------------------------------------------------------- |
|
198 // |
|
199 EXPORT_C TInt CSymbianCertChain::GetError() |
|
200 { |
|
201 return iError; |
|
202 } |