|
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 #include <mctwritablecertstore.h> |
|
20 |
|
21 #include "certtool_commands.h" |
|
22 #include "certtool_controller.h" |
|
23 |
|
24 #include "keytool_utils.h" |
|
25 |
|
26 /*static*/ CCertToolRemoveApps* CCertToolRemoveApps::NewLC(CCertToolController* aController) |
|
27 { |
|
28 CCertToolRemoveApps* self = new (ELeave) CCertToolRemoveApps(aController); |
|
29 CleanupStack::PushL(self); |
|
30 self->ConstructL(); |
|
31 return self; |
|
32 } |
|
33 |
|
34 /*static*/ CCertToolRemoveApps* CCertToolRemoveApps::NewL(CCertToolController* aController) |
|
35 { |
|
36 CCertToolRemoveApps* self = CCertToolRemoveApps::NewLC(aController); |
|
37 CleanupStack::Pop(self); |
|
38 return self; |
|
39 } |
|
40 |
|
41 CCertToolRemoveApps::CCertToolRemoveApps(CCertToolController* aController) : CCertToolList(aController) |
|
42 { |
|
43 } |
|
44 |
|
45 |
|
46 CCertToolRemoveApps::~CCertToolRemoveApps() |
|
47 { |
|
48 Cancel(); |
|
49 } |
|
50 |
|
51 void CCertToolRemoveApps::RunL() |
|
52 { |
|
53 if (iStatus.Int() != KErrNone) |
|
54 { |
|
55 // A problem occured. Handle gracefully. |
|
56 User::Leave(iStatus.Int()); |
|
57 } |
|
58 switch (iState) |
|
59 { |
|
60 case EListCerts: |
|
61 { |
|
62 if (iCertInfos.Count()==0) |
|
63 { |
|
64 iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_EMPTY); |
|
65 CActiveScheduler::Stop(); |
|
66 } |
|
67 else |
|
68 { |
|
69 if (iParams->iDefault) |
|
70 { |
|
71 // Look for a specific certificate |
|
72 TInt certIndex = -1; |
|
73 for (TInt j = 0; j < iCertInfos.Count(); j++) |
|
74 { |
|
75 if (iCertInfos[j]->Label() == *iParams->iDefault) |
|
76 { |
|
77 certIndex = j; |
|
78 break; |
|
79 } |
|
80 } |
|
81 |
|
82 if (certIndex != -1) |
|
83 { |
|
84 iIndex = certIndex; |
|
85 // Certificate found set app uids! |
|
86 if (iParams->iCertstoreIndex == -1) |
|
87 { |
|
88 iParams->iCertstoreIndex = 0; |
|
89 } |
|
90 if (iParams->iCertstoreIndex >= iCertStore->CertStoreCount()) |
|
91 { |
|
92 iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_NOTEXIST); |
|
93 User::Leave(KErrArgument); |
|
94 } |
|
95 iCertStore->Applications(*iCertInfos[iIndex], iApps, iStatus); |
|
96 iState = ERemoveApps; |
|
97 SetActive(); |
|
98 } |
|
99 else |
|
100 { |
|
101 User::Leave(KErrNotFound); |
|
102 } |
|
103 } |
|
104 } |
|
105 |
|
106 } |
|
107 break; |
|
108 case ERemoveApps: |
|
109 { |
|
110 if (iParams->iCertstoreIndex == -1) |
|
111 { |
|
112 iParams->iCertstoreIndex = 0; |
|
113 } |
|
114 if (iParams->iCertstoreIndex >= iCertStore->CertStoreCount()) |
|
115 { |
|
116 iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_NOTEXIST); |
|
117 User::Leave(KErrArgument); |
|
118 } |
|
119 TInt failCount = 0; |
|
120 // Check for duplicates |
|
121 for (TInt k = 0; k < iParams->iUIDs.Count(); k++) |
|
122 { |
|
123 TInt idx = iApps.Find(iParams->iUIDs[k]); |
|
124 if ( idx == KErrNotFound) |
|
125 { |
|
126 failCount++; |
|
127 TBuf<128> msg; |
|
128 const TDesC& tmp = KeyToolUtils::Uid2Des(iParams->iUIDs[k]); |
|
129 msg.Format(_L("The certificate wan not trusted for application %S."), &tmp); |
|
130 iController->DisplayErrorL(msg, iParams->iPageWise); |
|
131 } |
|
132 else |
|
133 { |
|
134 iApps.Remove(idx); |
|
135 } |
|
136 } |
|
137 |
|
138 if (failCount == iParams->iUIDs.Count()) |
|
139 { |
|
140 CActiveScheduler::Stop(); |
|
141 } |
|
142 else |
|
143 { |
|
144 iState = EFinished; |
|
145 iCertStore->SetApplicability(*iCertInfos[iIndex], iApps, iStatus); |
|
146 SetActive(); |
|
147 } |
|
148 } |
|
149 break; |
|
150 case EFinished: |
|
151 { |
|
152 iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_REMOVEAPPS_SUCCESS); |
|
153 CActiveScheduler::Stop(); |
|
154 } |
|
155 break; |
|
156 default: |
|
157 { |
|
158 User::Panic(_L("REMOVEAPPS action: Illegal state."), 1); |
|
159 } |
|
160 } |
|
161 |
|
162 } |
|
163 |
|
164 TInt CCertToolRemoveApps::RunError(TInt aError) |
|
165 { |
|
166 CActiveScheduler::Stop(); |
|
167 |
|
168 switch (aError) |
|
169 { |
|
170 case KErrNotFound : |
|
171 { |
|
172 TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_NOTFOUND)); |
|
173 TRAP_IGNORE(iController->DisplayErrorL(_L("\n"), iParams->iPageWise)); |
|
174 } |
|
175 break; |
|
176 default: |
|
177 { |
|
178 TRAP_IGNORE(iController->DisplayErrorL(_L("RemoveApps: Unknown error. "), aError)); |
|
179 TRAP_IGNORE(iController->DisplayErrorL(_L("\n"), iParams->iPageWise)); |
|
180 } |
|
181 } |
|
182 |
|
183 return KErrNone; |
|
184 } |