|
1 /* |
|
2 * Copyright (c) 2004-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 /** |
|
20 @file |
|
21 @released |
|
22 @internalTechnology |
|
23 */ |
|
24 |
|
25 #include "certificateretriever.h" |
|
26 |
|
27 #include <securitydefs.h> |
|
28 #include <ccertattributefilter.h> |
|
29 #include <swicertstore.h> |
|
30 |
|
31 #include "log.h" |
|
32 |
|
33 _LIT(KCertificateRetriever, "_CCertificateRetriever_"); |
|
34 |
|
35 using namespace Swi; |
|
36 |
|
37 /*static*/ CCertificateRetriever* CCertificateRetriever::NewL(CSWICertStore& aCerstore) |
|
38 { |
|
39 CCertificateRetriever* self = CCertificateRetriever::NewLC(aCerstore); |
|
40 CleanupStack::Pop(self); |
|
41 return self; |
|
42 } |
|
43 |
|
44 /*static*/ CCertificateRetriever* CCertificateRetriever::NewLC(CSWICertStore& aCerstore) |
|
45 { |
|
46 CCertificateRetriever* self = new(ELeave) CCertificateRetriever(aCerstore); |
|
47 CleanupStack::PushL(self); |
|
48 self->ConstructL(); |
|
49 return self; |
|
50 } |
|
51 |
|
52 CCertificateRetriever::CCertificateRetriever(CSWICertStore& aCerstore) : CActive(EPriorityNormal), iCertStore(aCerstore) |
|
53 { |
|
54 CActiveScheduler::Add(this); |
|
55 } |
|
56 |
|
57 CCertificateRetriever::~CCertificateRetriever() |
|
58 { |
|
59 Deque(); |
|
60 |
|
61 delete iFilter; |
|
62 } |
|
63 |
|
64 void CCertificateRetriever::ConstructL() |
|
65 { |
|
66 iFilter = CCertAttributeFilter::NewL(); |
|
67 iFilter->SetOwnerType(ECACertificate); // We only want root certs! |
|
68 } |
|
69 |
|
70 // |
|
71 // From CActive |
|
72 // |
|
73 |
|
74 void CCertificateRetriever::RunL() |
|
75 { |
|
76 DEBUG_PRINTF3(_L8("Security Manager - CCertificateRetriever::RunL(). State: %d, Status: %d."), |
|
77 iState, iStatus.Int()); |
|
78 |
|
79 if (iStatus.Int() != KErrNone) |
|
80 { |
|
81 User::Leave(iStatus.Int()); // Hop into RunError() |
|
82 } |
|
83 |
|
84 switch (iState) |
|
85 { |
|
86 case EBuildCAList: |
|
87 { |
|
88 // Nothing else to do |
|
89 User::RequestComplete(iClientStatus, KErrNone); |
|
90 break; |
|
91 } |
|
92 default: |
|
93 { |
|
94 User::Panic(KCertificateRetriever, 1); |
|
95 } |
|
96 } |
|
97 } |
|
98 |
|
99 void CCertificateRetriever::DoCancel() |
|
100 { |
|
101 DEBUG_PRINTF2(_L8("Security Manager - Cancelling certificate retriever in state %d."), iState); |
|
102 |
|
103 switch (iState) |
|
104 { |
|
105 case EBuildCAList: |
|
106 { |
|
107 iCertStore.CancelList(); |
|
108 break; |
|
109 } |
|
110 default: |
|
111 { |
|
112 // mandatory call is syncronoue so no need for cancel |
|
113 // Do Nothing |
|
114 } |
|
115 } |
|
116 } |
|
117 |
|
118 TInt CCertificateRetriever::RunError(TInt aError) |
|
119 { |
|
120 DEBUG_PRINTF2(_L8("Security Manager - CCertificateRetriever::RunError(). Error code: %d."), aError); |
|
121 |
|
122 User::RequestComplete(iClientStatus, aError); |
|
123 return KErrNone; |
|
124 } |
|
125 |
|
126 |
|
127 // |
|
128 // Business methods |
|
129 // |
|
130 void CCertificateRetriever::RetrieveCACertificates(RMPointerArray<CCTCertInfo>& aCertificateListOut, TRequestStatus& aClientStatus) |
|
131 { |
|
132 iState = EBuildCAList; |
|
133 DoInitialize(aCertificateListOut, aClientStatus); |
|
134 } |
|
135 |
|
136 void CCertificateRetriever::DoInitialize(RMPointerArray<CCTCertInfo>& aCertificateListOut, TRequestStatus& aClientStatus) |
|
137 { |
|
138 iClientStatus = &aClientStatus; |
|
139 *iClientStatus = KRequestPending; |
|
140 |
|
141 iCertificateList = &aCertificateListOut; |
|
142 SetActive(); |
|
143 iCertStore.List(*iCertificateList, *iFilter, iStatus); // Get all the root certs |
|
144 } |
|
145 |
|
146 |