|
1 /* |
|
2 * Copyright (c) 2008 - 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: |
|
15 */ |
|
16 |
|
17 #include <f32file.h> |
|
18 #include <centralrepository.h> |
|
19 #include <SWInstallerInternalCRKeys.h> |
|
20 #include "comms.h" |
|
21 #include "commsclientendpoint.h" |
|
22 #include "commsmessage.h" |
|
23 #include "securitycommsmessagedefs.h" |
|
24 |
|
25 static const TUid KCRUidJavaSecurity = { 0x2001B289 }; |
|
26 static const TUint32 KPolicy = 0x03; |
|
27 static const TUint32 KWarningsMode = 0x04; |
|
28 |
|
29 using namespace java::comms; |
|
30 |
|
31 static void DoL() |
|
32 { |
|
33 RFile policyConfigFile; |
|
34 RFile certsFile; |
|
35 RFs fsSession; |
|
36 User::LeaveIfError(fsSession.Connect()); |
|
37 TInt err = policyConfigFile.Open(fsSession,_L("c:\\private\\102033E6\\security\\tmp\\old_policy.txt"), EFileStreamText | EFileRead); |
|
38 TBuf8<256> oldPolicy; |
|
39 TBuf8<256> newPolicy; |
|
40 TBuf8<256> oldWarningsMode; |
|
41 TBuf8<256> newWarningsMode; |
|
42 bool updateCerts = false; |
|
43 bool removeCerts = false; |
|
44 if (err == KErrNone) |
|
45 { |
|
46 policyConfigFile.Read(oldPolicy); |
|
47 policyConfigFile.Close(); |
|
48 } |
|
49 else |
|
50 { |
|
51 err = policyConfigFile.Open(fsSession,_L("c:\\private\\102033E6\\security\\tmp\\new_policy.txt"), EFileStreamText | EFileRead); |
|
52 if (err == KErrNone) |
|
53 { |
|
54 policyConfigFile.Read(newPolicy); |
|
55 policyConfigFile.Close(); |
|
56 } |
|
57 } |
|
58 err = policyConfigFile.Open(fsSession,_L("c:\\private\\102033E6\\security\\tmp\\old_warnings_mode.txt"), EFileStreamText | EFileRead); |
|
59 if (err == KErrNone) |
|
60 { |
|
61 policyConfigFile.Read(oldWarningsMode); |
|
62 policyConfigFile.Close(); |
|
63 } |
|
64 else |
|
65 { |
|
66 err = policyConfigFile.Open(fsSession,_L("c:\\private\\102033E6\\security\\tmp\\new_warnings_mode.txt"), EFileStreamText | EFileRead); |
|
67 if (err == KErrNone) |
|
68 { |
|
69 policyConfigFile.Read(newWarningsMode); |
|
70 policyConfigFile.Close(); |
|
71 } |
|
72 } |
|
73 err = certsFile.Open(fsSession,_L("c:\\private\\102033E6\\security\\tmp\\update_certs"), EFileStreamText | EFileRead); |
|
74 if (err == KErrNone) |
|
75 { |
|
76 updateCerts = true; |
|
77 certsFile.Close(); |
|
78 } |
|
79 err = certsFile.Open(fsSession,_L("c:\\private\\102033E6\\security\\tmp\\remove_certs"), EFileStreamText | EFileRead); |
|
80 if (err == KErrNone) |
|
81 { |
|
82 removeCerts = true; |
|
83 certsFile.Close(); |
|
84 } |
|
85 if (oldPolicy.Length() > 0) |
|
86 { |
|
87 // restore the old policy |
|
88 CRepository* repository = CRepository::NewLC(KCRUidJavaSecurity); |
|
89 HBufC* tmp = HBufC::NewLC(oldPolicy.Length()); |
|
90 TPtr tmpPtr(tmp->Des()); |
|
91 tmpPtr.Copy(oldPolicy); |
|
92 repository->Set(KPolicy, tmpPtr); |
|
93 CleanupStack::PopAndDestroy(tmp); |
|
94 CleanupStack::PopAndDestroy(repository); |
|
95 // remove the directory |
|
96 CFileMan* fileMan = CFileMan::NewL(fsSession); |
|
97 fileMan->RmDir(_L("c:\\private\\102033E6\\security\\tmp")); |
|
98 delete fileMan; |
|
99 } |
|
100 else if (newPolicy.Length() > 0) |
|
101 { |
|
102 // save the old policy into old_policy.txt |
|
103 CRepository* repository = CRepository::NewLC(KCRUidJavaSecurity); |
|
104 HBufC* buf = HBufC::NewLC(NCentralRepositoryConstants::KMaxUnicodeStringLength); |
|
105 TPtr policy(buf->Des()); |
|
106 repository->Get(KPolicy, policy); |
|
107 TInt err = policyConfigFile.Replace(fsSession,_L("c:\\private\\102033E6\\security\\tmp\\old_policy.txt"), EFileStreamText | EFileWrite); |
|
108 if (err == KErrNone) |
|
109 { |
|
110 HBufC8* tmp8 = HBufC8::NewLC(policy.Length()); |
|
111 TPtr8 tmpPtr8(tmp8->Des()); |
|
112 tmpPtr8.Copy(policy); |
|
113 policyConfigFile.Write(tmpPtr8); |
|
114 CleanupStack::PopAndDestroy(tmp8); |
|
115 policyConfigFile.Close(); |
|
116 // write the new policy |
|
117 HBufC* tmp = HBufC::NewLC(newPolicy.Length()); |
|
118 TPtr tmpPtr(tmp->Des()); |
|
119 tmpPtr.Copy(newPolicy); |
|
120 repository->Set(KPolicy, tmpPtr); |
|
121 CleanupStack::PopAndDestroy(tmp); |
|
122 } |
|
123 CleanupStack::PopAndDestroy(buf); |
|
124 CleanupStack::PopAndDestroy(repository); |
|
125 } |
|
126 if (oldWarningsMode.Length() > 0) |
|
127 { |
|
128 // restore the old value |
|
129 CRepository* repository = CRepository::NewLC(KCRUidJavaSecurity); |
|
130 if (oldWarningsMode == _L8("1")) |
|
131 { |
|
132 repository->Set(KWarningsMode, 1); |
|
133 } |
|
134 else |
|
135 { |
|
136 repository->Set(KWarningsMode, 2); |
|
137 } |
|
138 CleanupStack::PopAndDestroy(repository); |
|
139 // remove the directory |
|
140 CFileMan* fileMan = CFileMan::NewL(fsSession); |
|
141 fileMan->RmDir(_L("c:\\private\\102033E6\\security\\tmp")); |
|
142 delete fileMan; |
|
143 } |
|
144 else if (newWarningsMode.Length() > 0) |
|
145 { |
|
146 // save the old value |
|
147 CRepository* repository = CRepository::NewLC(KCRUidJavaSecurity); |
|
148 TInt tmp; |
|
149 repository->Get(KWarningsMode, tmp); |
|
150 TInt err = policyConfigFile.Replace(fsSession,_L("c:\\private\\102033E6\\security\\tmp\\old_warnings_mode.txt"), EFileStreamText | EFileWrite); |
|
151 if (err == KErrNone) |
|
152 { |
|
153 if (tmp == 1) |
|
154 { |
|
155 policyConfigFile.Write(_L8("1")); |
|
156 } |
|
157 else |
|
158 { |
|
159 policyConfigFile.Write(_L8("2")); |
|
160 } |
|
161 policyConfigFile.Close(); |
|
162 // write the new value |
|
163 if (newWarningsMode == _L8("1")) |
|
164 { |
|
165 repository->Set(KWarningsMode, 1); |
|
166 } |
|
167 else |
|
168 { |
|
169 repository->Set(KWarningsMode, 2); |
|
170 } |
|
171 } |
|
172 CleanupStack::PopAndDestroy(repository); |
|
173 } |
|
174 if (updateCerts || removeCerts) |
|
175 { |
|
176 if (removeCerts) |
|
177 { |
|
178 CFileMan* fileMan = CFileMan::NewL(fsSession); |
|
179 fileMan->RmDir(_L("c:\\private\\102033E6\\security\\tmp")); |
|
180 delete fileMan; |
|
181 } |
|
182 else |
|
183 { |
|
184 TInt err = certsFile.Replace(fsSession,_L("c:\\private\\102033E6\\security\\tmp\\remove_certs"), EFileStreamText | EFileWrite); |
|
185 certsFile.Close(); |
|
186 } |
|
187 |
|
188 // send the COMMS message to JavaCertStore to do the refresh |
|
189 CommsClientEndpoint cli_conn; |
|
190 if (cli_conn.connect(IPC_ADDRESS_JAVA_CAPTAIN_C) == 0) |
|
191 { |
|
192 CommsMessage s_msg; |
|
193 CommsMessage r_msg; |
|
194 s_msg.setModuleId(PLUGIN_ID_JAVA_CERT_STORE_EXTENSION_C); |
|
195 s_msg.setMessageId(JAVA_CERT_STORE_MSG_ID_REQUEST); |
|
196 s_msg << JAVA_CERT_STORE_OPERATION_REFRESH_CERTS; |
|
197 cli_conn.send(s_msg); |
|
198 } |
|
199 } |
|
200 fsSession.Close(); |
|
201 } |
|
202 |
|
203 TInt E32Main() |
|
204 { |
|
205 //__UHEAP_MARK; |
|
206 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
|
207 TRAPD(error, DoL()); |
|
208 delete cleanupStack; |
|
209 //__UHEAP_MARKEND; |
|
210 return error; |
|
211 } |
|
212 // eof |