Changeset c14b8d2 in dispositivos_moviles for TibisayMovil/src/ve/gob


Ignore:
Timestamp:
Nov 1, 2013, 10:34:18 AM (11 years ago)
Author:
Antonio Araujo Brett <aaraujo@…>
Branches:
master
Children:
58c7f6a
Parents:
f32914c
Message:

*- Modificaciones en actividad para ejecutar cifrado de un archivo a través de una tarea asíncrona (AsyncTask?). Se muestra un diálogo de progreso durante el proceso de cifrado.

Location:
TibisayMovil/src/ve/gob/cenditel/tibisaymovil
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • TibisayMovil/src/ve/gob/cenditel/tibisaymovil/PDFVerifyResultActivity.java

    re68708b rc14b8d2  
    5555    private LinearLayout button_finish;
    5656
    57  // ruta absoluta al archivo a verificar
     57    // ruta absoluta al archivo a verificar
    5858    private String pdfToVerify;
    5959       
  • TibisayMovil/src/ve/gob/cenditel/tibisaymovil/PKCS12ToDecryptActivity.java

    rf32914c rc14b8d2  
    679679                     pkcs12Password = password.getText().toString();
    680680                     if (!pkcs12Password.isEmpty()){
    681                          Toast.makeText(PKCS12ToDecryptActivity.this,"PKCS12 Password : "+ password.getText().toString(), Toast.LENGTH_LONG).show();
     681                         //Toast.makeText(PKCS12ToDecryptActivity.this,"PKCS12 Password : "+ password.getText().toString(), Toast.LENGTH_LONG).show();
    682682                         
    683683                         password.setText("");
  • TibisayMovil/src/ve/gob/cenditel/tibisaymovil/SelectCertificateToEncryptActivity.java

    rfd4a5b9 rc14b8d2  
    1414import ee.sk.xmlenc.EncryptedData;
    1515import ee.sk.xmlenc.EncryptedKey;
    16 
    1716import ve.gob.cenditel.tibisaymovil.R;
    1817import android.app.Activity;
    1918import android.app.AlertDialog;
     19import android.app.ProgressDialog;
    2020import android.content.Context;
    2121import android.content.DialogInterface;
     
    2323import android.graphics.drawable.Drawable;
    2424import android.net.Uri;
     25import android.os.AsyncTask;
    2526import android.os.Bundle;
    2627import android.os.Environment;
     28import android.os.Looper;
    2729import android.util.Log;
    2830import android.view.LayoutInflater;
     
    495497     */
    496498        // funcion para desplegar el gestor de certificados de destinatarios para cifrar
    497         private void encryptFile(String fileToEncrypt, String certificateToEncrypt) {
     499        private void encryptFile(final String fileToEncrypt, final String certificateToEncrypt) {
    498500               
    499501                Toast.makeText(getApplicationContext(), "Encrypting file: " + fileToEncrypt, Toast.LENGTH_SHORT).show();
    500        
    501                 // TODO chequear que se pueda escribir en el directorio /mnt/sdcard/TibisayMovil/EncryptedFiles
     502               
     503               
    502504                // chequear disponibilidad de directorio de certificados
    503505            if (!checkCertificatesDirectoryAvailability()){
     
    508510            }
    509511               
    510                
     512                // ********************* prueba de AsyncTask ******************************
     513               
     514                AsyncTask<Void, Void, ArrayList<String>> task = new AsyncTask<Void, Void, ArrayList<String>>() {
     515
     516            private ProgressDialog pd;
     517
     518            @Override
     519            protected void onPreExecute() {
     520
     521                     pd = new ProgressDialog(SelectCertificateToEncryptActivity.this); 
     522                     pd.setTitle("Cifrando archivo");   
     523                     pd.setMessage(getString(R.string.por_favor_epsere));       
     524                     pd.setCancelable(false);   
     525                     pd.setIndeterminate(true);
     526                     pd.show();
     527
     528            }
     529
     530            @Override
     531            protected ArrayList<String> doInBackground(Void... arg0) {
     532           
     533                /*
     534                try {
     535                    Thread.sleep(3000);
     536                } catch(InterruptedException ex) {
     537                    Thread.currentThread().interrupt();
     538                }
     539                */
     540               
     541                // para solventar error:
     542                // Can't create handler inside thread that has not called Looper.prepare()
     543                Looper.prepare();
     544               
     545                // arreglo para almacenar resultado de la operacion
     546                ArrayList<String> resultArray = new ArrayList<String>();
     547                resultArray.clear();
     548               
     549               
     550                ConfigManager.init("jar://jdigidoc.cfg");
     551                        Log.d("despues de:", "ConfigManager.init");
     552               
     553                // signed doc object if used
     554                SignedDoc m_sdoc;
     555                m_sdoc = null;
     556
     557                // encrypted data object if used
     558                EncryptedData m_cdoc;
     559                m_cdoc = null;
     560               
     561                String inFile = null, outFile = null;
     562                String certFile = null;
     563                String recipient = null;
     564                String keyName = null;
     565                String carriedKeyName = null;
     566                String sId = null;     
     567                       
     568                inFile = fileToEncrypt;
     569                certFile = certificateToEncrypt;
     570               
     571                // agregar el destinatario
     572                try {
     573
     574                        if (m_cdoc == null){
     575                                Log.d("m_cdoc == null", "-");
     576                                m_cdoc = new EncryptedData(null, null, null, EncryptedData.DENC_XMLNS_XMLENC, EncryptedData.DENC_ENC_METHOD_AES128);
     577                        }
     578                        Log.d("Adding recipient", certFile);
     579                        X509Certificate recvCert = SignedDoc.readCertificate(new File(certFile));
     580                        if (recvCert != null && recipient == null)
     581                                recipient = SignedDoc.getCommonName(recvCert.getSubjectDN().getName());
     582                        Log.d("Recipient", recipient);
     583                        if (sId == null){
     584                                int n = m_cdoc.getNumKeys() + 1;
     585                                sId = "ID" + n;
     586                               
     587                        }
     588                       
     589                        EncryptedKey ekey = new EncryptedKey(sId, recipient, EncryptedData.DENC_ENC_METHOD_RSA1_5, keyName, carriedKeyName, recvCert);
     590                        m_cdoc.addEncryptedKey(ekey);
     591
     592                       
     593                }catch(Exception e){
     594                        Log.d("Error adding EncryptedKey: ", e.getMessage());
     595                        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
     596                       
     597                        //showDialog(getResources().getString(R.string.msg_encryption_error), e.getMessage());
     598                        //return;
     599                       
     600                        resultArray.add("false");
     601                                resultArray.add(getResources().getString(R.string.msg_encryption_error));
     602                                resultArray.add(e.getMessage());
     603                                return resultArray;
     604                }
     605               
     606                // ejecutar el cifrado
     607                try {
     608
     609                        Log.d("Encrypting file:", inFile + " to: " + outFile);
     610                        File fIn = new File(inFile);
     611                        // create a ddoc intermediate file
     612                        m_sdoc = new SignedDoc(SignedDoc.FORMAT_DIGIDOC_XML, SignedDoc.VERSION_1_3);
     613                       
     614                        Log.d("Encrypting file:", "paso new SignedDoc");
     615                       
     616                        DataFile df = m_sdoc.addDataFile(new File(inFile), SignedDoc.xmlns_digidoc13, DataFile.CONTENT_EMBEDDED_BASE64);
     617                                       
     618                        Log.d("Encrypting file:", "paso addDataFile");
     619                       
     620                       
     621                        byte[] data = SignedDoc.readFile(new File(inFile));
     622                       
     623                        Log.d("Encrypting file:", "paso readFile");
     624                       
     625                        df.setBase64Body(data);
     626                       
     627                        Log.d("Encrypting file:", "paso setBase64Body");
     628                       
     629                        byte[] inData = m_sdoc.toXML().getBytes("UTF-8");
     630                       
     631                        Log.d("Encrypting file:", "paso toXML()");
     632                       
     633                        Log.d("Encrypting file", "Content: " + inFile + " size: " + data.length);
     634                        Log.d("Encrypting file", "DF: " + new String(inData));
     635                       
     636                        m_cdoc.setData(inData);
     637                        m_cdoc.setDataStatus(EncryptedData.DENC_DATA_STATUS_UNENCRYPTED_AND_NOT_COMPRESSED);
     638                        m_cdoc.addProperty(EncryptedData.ENCPROP_FILENAME, inFile + ".ddoc");
     639                        m_cdoc.setMimeType(EncryptedData.DENC_ENCDATA_TYPE_DDOC);
     640                        StringBuffer sb = new StringBuffer();
     641                        sb.append(fIn.getName());
     642                        sb.append("|");
     643                        sb.append(new Long(fIn.length()).toString() + " B|");
     644                        sb.append("application/unknown|");
     645                        sb.append("/" + fIn.getName());
     646                        m_cdoc.addProperty(EncryptedData.ENCPROP_ORIG_FILE, sb.toString());
     647                        //m_cdoc.addProperty(EncryptedData.ENCPROP_ORIG_SIZE, new Long(inData.length).toString());
     648                       
     649                        int nCompressOption = 0;
     650                       
     651                        m_cdoc.encrypt(nCompressOption);
     652                                       
     653                        // genera el archivo cifrado en /data/data/ve.gob.cenditel/files
     654                        //FileOutputStream fos = openFileOutput(outFile, Context.MODE_WORLD_WRITEABLE);
     655                       
     656                        outFile = encrypted_dir_files + fIn.getName()+".cdoc";
     657                        Toast.makeText(getApplicationContext(), "outFile: " + outFile, Toast.LENGTH_SHORT).show();
     658                       
     659                       
     660                        FileOutputStream fos = new FileOutputStream( outFile );
     661                       
     662                        Log.d("Encrypting file", "antes de escribir archivo " + outFile);
     663                       
     664                        fos.write(m_cdoc.toXML());
     665                       
     666                        Log.d("Encrypting file", "despues de escribir archivo " + outFile);
     667                       
     668                        fos.close();
     669                       
     670                        Log.d("Encrypting file", "despues de cerrar archivo " + outFile);
     671                       
     672                        Toast.makeText(getApplicationContext(), "Cifrado correctamente: " + outFile, Toast.LENGTH_SHORT).show();
     673                       
     674                        // lanzar la actividad para mostrar el resultado del cifrado
     675                        //showEncryptionResults(fileToEncrypt, outFile, recipient);             
     676                        resultArray.add("true"); // [0]
     677                        resultArray.add(outFile); // [1]
     678                        resultArray.add(recipient); // [2]
     679
     680
     681                } catch(Exception e) {
     682                        Log.d("Error encrypting file: ", inFile + " - " + e.getMessage());
     683                        e.printStackTrace(System.err);
     684                        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
     685                       
     686                        //showDialog(getResources().getString(R.string.msg_encryption_error), e.getMessage());
     687                        //return;
     688                       
     689                        resultArray.add("false");
     690                                resultArray.add(getResources().getString(R.string.msg_encryption_error));
     691                                resultArray.add(e.getMessage());
     692                                return resultArray;
     693                       
     694                }               
     695               
     696                return resultArray;
     697            }
     698           
     699            @Override
     700            protected void onPostExecute(ArrayList<String> result) {
     701                 
     702               
     703                        if (result.get(0).equals("false")){
     704                                showDialog(result.get(1), result.get(2));
     705                        }else{
     706                                //showDialog(result.get(1), result.get(2), true);
     707                                showEncryptionResults(fileToEncrypt, result.get(1), result.get(2));
     708                        }
     709                               
     710                pd.dismiss();
     711            }
     712                       
     713                };
     714               
     715                task.execute((Void[])null);
     716               
     717                // ********************* fin prueba de AsyncTask ******************************
     718       
     719/*             
    511720        ConfigManager.init("jar://jdigidoc.cfg");
    512721                Log.d("despues de:", "ConfigManager.init");
    513722       
    514         /** signed doc object if used */
     723        // signed doc object if used
    515724        SignedDoc m_sdoc;
    516725        m_sdoc = null;
    517726
    518         /** encrypted data object if used */
     727        // encrypted data object if used
    519728        EncryptedData m_cdoc;
    520729        m_cdoc = null;
     
    640849        // lanzar la actividad para mostrar el resultado del cifrado
    641850        showEncryptionResults(fileToEncrypt, outFile, recipient);
    642        
     851*/     
    643852       
    644853               
     
    775984                });
    776985               
    777                 // 3. Get the AlertDialog from create()                         
     986                // 3. Get the AlertDialog from create()
    778987                AlertDialog dialog = builder.create();
    779988                dialog.show();         
Note: See TracChangeset for help on using the changeset viewer.