1 | /* |
---|
2 | Tibisay Movil |
---|
3 | |
---|
4 | Copyright (C) 2013 Antonio Araujo (aaraujo@cenditel.gob.ve), Jose Ruiz |
---|
5 | (jruiz@cenditel.gob.ve), Fundacion Centro Nacional de Desarrollo e |
---|
6 | Investigacion en Tecnologias Libres - CENDITEL. |
---|
7 | |
---|
8 | La Fundación CENDITEL concede permiso para usar, copiar, distribuir y/o |
---|
9 | modificar este programa, reconociendo el derecho que la humanidad posee al |
---|
10 | libre acceso al conocimiento, bajo los términos de la licencia de software |
---|
11 | GPL versión 2.0 de la Free Software Foundation. |
---|
12 | |
---|
13 | Este programa se distribuye con la esperanza de que sea util, pero SIN |
---|
14 | NINGUNA GARANTIA; tampoco las implicitas garantias de MERCANTILIDAD o |
---|
15 | ADECUACION A UN PROPOSITO PARTICULAR. |
---|
16 | |
---|
17 | Para mayor información sobre los términos de la licencia ver el archivo |
---|
18 | llamado "gpl-2.0.txt" en ingles. |
---|
19 | */ |
---|
20 | |
---|
21 | package ve.gob.cenditel.tibisaymovil; |
---|
22 | |
---|
23 | import android.net.Uri; |
---|
24 | import android.os.Build; |
---|
25 | import android.os.Bundle; |
---|
26 | import android.app.Activity; |
---|
27 | import android.app.AlertDialog; |
---|
28 | import android.content.Context; |
---|
29 | import android.content.DialogInterface; |
---|
30 | import android.content.Intent; |
---|
31 | import android.util.Log; |
---|
32 | import android.view.Menu; |
---|
33 | import android.view.MenuItem; |
---|
34 | import android.view.View; |
---|
35 | import android.view.Window; |
---|
36 | import android.widget.AdapterView; |
---|
37 | import android.widget.AdapterView.OnItemClickListener; |
---|
38 | import android.widget.ArrayAdapter; |
---|
39 | import android.widget.ListView; |
---|
40 | import android.widget.TextView; |
---|
41 | import android.widget.Toast; |
---|
42 | |
---|
43 | |
---|
44 | public class TibisayMovilActivity extends Activity { |
---|
45 | |
---|
46 | |
---|
47 | public DirectKeyChain keyChain; |
---|
48 | |
---|
49 | @Override |
---|
50 | protected void onCreate(Bundle savedInstanceState) { |
---|
51 | super.onCreate(savedInstanceState); |
---|
52 | |
---|
53 | final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); |
---|
54 | setContentView(R.layout.activity_main); |
---|
55 | if(customTitleSupported) |
---|
56 | getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar); |
---|
57 | |
---|
58 | // listview de funciones |
---|
59 | final ListView listViewFunctions = (ListView) findViewById(R.id.listViewFunctions); |
---|
60 | |
---|
61 | String[] values = new String[] {getString(R.string.firmar), |
---|
62 | getString(R.string.verificar), |
---|
63 | getString(R.string.cifrar), |
---|
64 | getString(R.string.descifrar), |
---|
65 | getString(R.string.compartir), |
---|
66 | getString(R.string.certificados), |
---|
67 | getString(R.string.preferencias) }; |
---|
68 | |
---|
69 | |
---|
70 | FunctionListAdapter ad = new FunctionListAdapter(this, values); |
---|
71 | listViewFunctions.setAdapter(ad); |
---|
72 | |
---|
73 | |
---|
74 | |
---|
75 | |
---|
76 | /*************** Dialogos de submenus *******************/ |
---|
77 | //Crear dialogo de opciones para firmar |
---|
78 | final AlertDialog sign_dialog = makeSignatureOptionsDialog(); |
---|
79 | |
---|
80 | //Crear dialogo de opciones para compartir archivo |
---|
81 | final AlertDialog share_dialog = makeShareOptionsDialog(); |
---|
82 | |
---|
83 | //Crear dialogo de opciones para compartir cifrar archivo |
---|
84 | final AlertDialog certificate_dialog = makeCertificateOptionsDialog(); |
---|
85 | |
---|
86 | |
---|
87 | listViewFunctions.setOnItemClickListener(new OnItemClickListener(){ |
---|
88 | |
---|
89 | @Override |
---|
90 | public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, |
---|
91 | long arg3) { |
---|
92 | |
---|
93 | Context context = getApplicationContext(); |
---|
94 | //CharSequence text = "Click!"; |
---|
95 | int duration = Toast.LENGTH_SHORT; |
---|
96 | //Toast.makeText(context, text, duration).show(); |
---|
97 | |
---|
98 | View curr = arg0.getChildAt((int) arg3); |
---|
99 | TextView c = (TextView)curr.findViewById(R.id.textListMainMenu); |
---|
100 | String function = c.getText().toString(); |
---|
101 | //Toast.makeText(context, function, duration).show(); |
---|
102 | |
---|
103 | // seleccion de firmar |
---|
104 | if(function.equals(getString(R.string.firmar))) { |
---|
105 | sign_dialog.show(); |
---|
106 | } |
---|
107 | |
---|
108 | // seleccion de verificar |
---|
109 | if(function.equals(getString(R.string.verificar))) { |
---|
110 | //Toast.makeText(context, "VERIFICAR", duration).show(); |
---|
111 | verifyBDOCSignedFile(); |
---|
112 | } |
---|
113 | |
---|
114 | // seleccion de cifrar |
---|
115 | if(function.equals(getString(R.string.cifrar))) { |
---|
116 | //Toast.makeText(context, "CIFRAR", duration).show(); |
---|
117 | encryptFile(); |
---|
118 | } |
---|
119 | |
---|
120 | // seleccion de descifrar |
---|
121 | if(function.equals(getString(R.string.descifrar))) { |
---|
122 | //Toast.makeText(context, "DESCIFRAR", duration).show(); |
---|
123 | decryptFile(); |
---|
124 | } |
---|
125 | |
---|
126 | // seleccion de gestionar certificados |
---|
127 | if (function.equals(getString(R.string.certificados))){ |
---|
128 | //Toast.makeText(context, "Gestionar repositorio", duration).show(); |
---|
129 | certificate_dialog.show(); |
---|
130 | |
---|
131 | } |
---|
132 | |
---|
133 | // seleccion de compartir archivo |
---|
134 | if (function.equals(getString(R.string.compartir))){ |
---|
135 | //Toast.makeText(context, "Compartir Archivo", duration).show(); |
---|
136 | share_dialog.show(); |
---|
137 | |
---|
138 | } |
---|
139 | // seleccion de firmar |
---|
140 | if(function.equals(getString(R.string.preferencias))) { |
---|
141 | preferences(); |
---|
142 | } |
---|
143 | |
---|
144 | } |
---|
145 | }); //setOnItemClickListener |
---|
146 | } // end onCreate |
---|
147 | |
---|
148 | @Override |
---|
149 | public boolean onCreateOptionsMenu(Menu menu) { |
---|
150 | // Inflate the menu; this adds items to the action bar if it is present. |
---|
151 | getMenuInflater().inflate(R.menu.menu, menu); |
---|
152 | return true; |
---|
153 | } |
---|
154 | |
---|
155 | @Override |
---|
156 | public boolean onOptionsItemSelected(MenuItem item) { |
---|
157 | switch (item.getItemId()) { |
---|
158 | case R.id.MnuAbout: |
---|
159 | Intent intentAbout = new Intent(TibisayMovilActivity.this,AboutActivity.class); |
---|
160 | startActivity(intentAbout); |
---|
161 | return true; |
---|
162 | case R.id.MnuHelp: |
---|
163 | Intent intent = new Intent(); |
---|
164 | intent.setAction(Intent.ACTION_VIEW); |
---|
165 | intent.addCategory(Intent.CATEGORY_BROWSABLE); |
---|
166 | intent.setData(Uri.parse("http://seguridad.cenditel.gob.ve/proyectos/tibisay-movil/ayuda-de-tibisay-movil/")); |
---|
167 | startActivity(intent); |
---|
168 | return true; |
---|
169 | default: |
---|
170 | return super.onOptionsItemSelected(item); |
---|
171 | } |
---|
172 | } |
---|
173 | |
---|
174 | |
---|
175 | private void testRepository(){ |
---|
176 | |
---|
177 | // this.keyChain = DirectKeyChain.getInstance(); |
---|
178 | // this.keyChain.setListView(this.viewHolder.aliases); |
---|
179 | // this.keyChain.setMasterActivity((Activity) this); |
---|
180 | // this.keyChain.choosePrivateKeyAlias(); |
---|
181 | |
---|
182 | Intent intent = new Intent(this, CertificateRepositoryActivity.class); |
---|
183 | startActivity(intent); |
---|
184 | } |
---|
185 | |
---|
186 | private void fileToSignHandwrittenSignature(){ |
---|
187 | Intent intent = new Intent(this, FileToSignHandwrittenSignatureActivity.class); |
---|
188 | startActivity(intent); |
---|
189 | } |
---|
190 | |
---|
191 | private void filesToPKCS7Sign(){ |
---|
192 | Intent intent = new Intent(this, FilesToPKCS7SignActivity.class); |
---|
193 | startActivity(intent); |
---|
194 | } |
---|
195 | |
---|
196 | private void filesToPDFSign(){ |
---|
197 | Intent intent = new Intent(this, FilesToPDFSignActivity.class); |
---|
198 | startActivity(intent); |
---|
199 | } |
---|
200 | |
---|
201 | |
---|
202 | // lanza activity para verificar un documento firmado |
---|
203 | private void verifyBDOCSignedFile(){ |
---|
204 | //Intent intent = new Intent(this, FileToSignHandwrittenSignatureActivity.class); |
---|
205 | Intent intent = new Intent(this, FileToVerifySignatureActivity.class); |
---|
206 | startActivity(intent); |
---|
207 | } |
---|
208 | |
---|
209 | // lanza activity para compartir un documento |
---|
210 | private void shareFile(String path){ |
---|
211 | Intent intent = new Intent(this, FileToShareActivity.class); |
---|
212 | |
---|
213 | intent.putExtra("path", path); |
---|
214 | |
---|
215 | startActivity(intent); |
---|
216 | } |
---|
217 | |
---|
218 | // lanza activity para cifrar un documento |
---|
219 | private void encryptFile(){ |
---|
220 | Intent intent = new Intent(this, FileToEncryptActivity.class); |
---|
221 | startActivity(intent); |
---|
222 | } |
---|
223 | |
---|
224 | |
---|
225 | // lanza activity para descifrar un documento |
---|
226 | private void decryptFile(){ |
---|
227 | Intent intent = new Intent(this, FileToDecryptActivity.class); |
---|
228 | startActivity(intent); |
---|
229 | } |
---|
230 | |
---|
231 | |
---|
232 | // lanza la activity para gestionar los certificados de destinarios (cifrado) |
---|
233 | private void manageRecipientCertificates() { |
---|
234 | Intent intent = new Intent(this, EncryptionCertificatesActivity.class); |
---|
235 | startActivity(intent); |
---|
236 | } |
---|
237 | |
---|
238 | |
---|
239 | //Crea dialogo de opciones para firma electronica |
---|
240 | public AlertDialog makeSignatureOptionsDialog() { |
---|
241 | final String[] option = new String[] {getString(R.string.firmar_man_pdf), getString(R.string.firmar_elec_pdf), getString(R.string.firmar_pkcs7) }; |
---|
242 | ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, |
---|
243 | android.R.layout.select_dialog_item, option); |
---|
244 | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
---|
245 | |
---|
246 | builder.setTitle(getString(R.string.seleccione_opcion)); |
---|
247 | builder.setAdapter(adapter, new DialogInterface.OnClickListener() { |
---|
248 | |
---|
249 | public void onClick(DialogInterface dialog, int which) { |
---|
250 | |
---|
251 | switch (which) { |
---|
252 | case 0: // Firma Manuscrita PDF |
---|
253 | Log.i("DEBUG", "antes de activity call"); |
---|
254 | fileToSignHandwrittenSignature(); |
---|
255 | break; |
---|
256 | case 1: // Firma Electronica PDF |
---|
257 | filesToPDFSign(); |
---|
258 | break; |
---|
259 | case 2: // Firma PKCS7 |
---|
260 | filesToPKCS7Sign(); |
---|
261 | break; |
---|
262 | |
---|
263 | default: |
---|
264 | break; |
---|
265 | } |
---|
266 | } |
---|
267 | |
---|
268 | }); |
---|
269 | |
---|
270 | return builder.create(); |
---|
271 | } |
---|
272 | |
---|
273 | |
---|
274 | // lanza activity para preferencias |
---|
275 | private void preferences(){ |
---|
276 | Intent intent = new Intent(this, PreferencesActivity.class); |
---|
277 | startActivity(intent); |
---|
278 | } |
---|
279 | |
---|
280 | //Crea dialogo de opciones para compartir archivos |
---|
281 | public AlertDialog makeShareOptionsDialog() { |
---|
282 | final String[] option = new String[] {getString(R.string.share_pdf_signed), |
---|
283 | getString(R.string.share_bdoc_downloaded), getString(R.string.share_extracted_file_from_bdoc), |
---|
284 | getString(R.string.share_encrypted) }; |
---|
285 | ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, |
---|
286 | android.R.layout.select_dialog_item, option); |
---|
287 | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
---|
288 | |
---|
289 | builder.setTitle(getString(R.string.seleccione_opcion)); |
---|
290 | builder.setAdapter(adapter, new DialogInterface.OnClickListener() { |
---|
291 | |
---|
292 | public void onClick(DialogInterface dialog, int which) { |
---|
293 | |
---|
294 | switch (which) { |
---|
295 | case 0: // Archivo Firmado |
---|
296 | Log.i("DEBUG", "antes de activity call"); |
---|
297 | shareFile("archivoFirmado"); |
---|
298 | break; |
---|
299 | case 1: // Archivos BDOC Descargados |
---|
300 | shareFile("bdocDescargado"); |
---|
301 | break; |
---|
302 | case 2: // Archivos extraídos de BDOC |
---|
303 | shareFile("extraidoDeBdoc"); |
---|
304 | break; |
---|
305 | |
---|
306 | case 3: // Archivos cifrados |
---|
307 | shareFile("cifrado"); |
---|
308 | break; |
---|
309 | default: |
---|
310 | break; |
---|
311 | } |
---|
312 | } |
---|
313 | |
---|
314 | }); |
---|
315 | |
---|
316 | return builder.create(); |
---|
317 | } |
---|
318 | |
---|
319 | //Crea dialogo de opciones para gestionar certificados |
---|
320 | public AlertDialog makeCertificateOptionsDialog() { |
---|
321 | ; |
---|
322 | final String[] option; |
---|
323 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH){ |
---|
324 | option = new String[] {getString(R.string.manage_personal_certificates), getString(R.string.manage_certificates_for_encryption) }; |
---|
325 | } else { |
---|
326 | option = new String[] {getString(R.string.manage_certificates_for_encryption) }; |
---|
327 | } |
---|
328 | |
---|
329 | ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, |
---|
330 | android.R.layout.select_dialog_item, option); |
---|
331 | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
---|
332 | |
---|
333 | builder.setTitle(getString(R.string.seleccione_opcion)); |
---|
334 | builder.setAdapter(adapter, new DialogInterface.OnClickListener() { |
---|
335 | |
---|
336 | public void onClick(DialogInterface dialog, int which) { |
---|
337 | |
---|
338 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH){ |
---|
339 | |
---|
340 | switch (which) { |
---|
341 | case 0: // Certificados personales |
---|
342 | testRepository(); |
---|
343 | break; |
---|
344 | case 1: // Certificados para cifrado |
---|
345 | manageRecipientCertificates(); |
---|
346 | break; |
---|
347 | } |
---|
348 | |
---|
349 | } else { |
---|
350 | |
---|
351 | switch (which) { |
---|
352 | case 0: // Certificados para cifrado |
---|
353 | manageRecipientCertificates(); |
---|
354 | break; |
---|
355 | } |
---|
356 | |
---|
357 | } |
---|
358 | |
---|
359 | } |
---|
360 | |
---|
361 | }); |
---|
362 | |
---|
363 | return builder.create(); |
---|
364 | } |
---|
365 | |
---|
366 | } |
---|