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