Changeset 6f9915f in dispositivos_moviles for TibisayMovil/src


Ignore:
Timestamp:
Nov 1, 2013, 1:47:02 PM (11 years ago)
Author:
Jose Ruiz <joseruiz@…>
Branches:
master
Children:
67541a6
Parents:
bb739b0 (diff), c14b8d2 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

algunos cambios en la captura de imagen

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

Legend:

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

    r288126d rbb739b0  
    7878       
    7979        //Ruta completa para crear el archivo
    80         mypath= new File(directory,current);
     80        mypath= new File(tempDir,current);
    8181 
    8282        // Obtiene referencia a los recursos del layout
  • TibisayMovil/src/ve/gob/cenditel/tibisaymovil/FilesToPDFSignActivity.java

    r931bb65 r2ff9cec  
    269269            //Si es un directorio el seleccionado se hace un llamado del fileBrowser del directorio
    270270            if (item.isDirectory()) {
    271                 parent.setAdapter(FilesToPDFSignActivity.this.listAdapter = new FileListAdapter(item.getAbsolutePath()));
     271                parent.setAdapter(FilesToPDFSignActivity.this.listAdapter = new FileListAdapter(item.getAbsolutePath(), filterMImeType));
    272272            } else { // Si es un archivo
    273273               
  • 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

    r647bb1f rc14b8d2  
    1313import java.util.Collections;
    1414import java.util.Date;
     15import java.util.Vector;
     16
     17import com.lowagie.text.pdf.PdfReader;
    1518
    1619import ee.sk.digidoc.DataFile;
     
    2225import ee.sk.xmlenc.EncryptedData;
    2326import ee.sk.xmlenc.factory.EncryptedDataParser;
    24 
    2527import ve.gob.cenditel.tibisaymovil.R;
    2628import android.app.Activity;
    2729import android.app.AlertDialog;
    2830import android.app.Dialog;
     31import android.app.ProgressDialog;
    2932import android.content.Context;
    3033import android.content.DialogInterface;
     
    3235import android.graphics.drawable.Drawable;
    3336import android.net.Uri;
     37import android.os.AsyncTask;
    3438import android.os.Bundle;
    3539import android.os.Environment;
     40import android.os.Looper;
    3641import android.util.Log;
    3742import android.view.LayoutInflater;
     
    655660                AlertDialog dialogDetails = null;
    656661               
    657                 AlertDialog.Builder dialogbuilder = new AlertDialog.Builder(this);
     662                final AlertDialog.Builder dialogbuilder = new AlertDialog.Builder(this);
    658663                dialogbuilder.setTitle(R.string.title_pkcs12_password);
    659664                dialogbuilder.setView(dialogview);
     
    669674                    public void onClick(View v) {
    670675                     
    671                      Toast.makeText(PKCS12ToDecryptActivity.this,"  Password : "+ password.getText().toString(), Toast.LENGTH_LONG).show();
     676                     
    672677                     
    673678                     // asignar la contrasena
    674679                     pkcs12Password = password.getText().toString();
     680                     if (!pkcs12Password.isEmpty()){
     681                         //Toast.makeText(PKCS12ToDecryptActivity.this,"PKCS12 Password : "+ password.getText().toString(), Toast.LENGTH_LONG).show();
     682                         
     683                         password.setText("");
     684                         
     685                             // ejecutar el proceso de descifrado.
     686                             decryptFile(fileToDecrypt, pkcs12File, pkcs12Password);
     687
     688                         
     689                     }
    675690                     
    676691                     // ejecutar el proceso de descifrado.
    677                      decryptFile(fileToDecrypt, pkcs12File, pkcs12Password);
     692                     //decryptFile(fileToDecrypt, pkcs12File, pkcs12Password);
    678693                     
    679694                     // borrar el contenido de pkcs12Password
     
    691706       
    692707        /**
    693      * Crea dialogo para obtener la contrasena del archivo P12
     708     * Descifra el archivo pasado como argumento con el archivo P12
    694709     *
    695      * @return Dialog
     710     * @return void
    696711     */
    697         private void decryptFile(String fileToDecrypt, String pkcs12File, String pkcs12Password) {
     712        private void decryptFile(final String fileToDecrypt, final String pkcs12File, final String pkcs12Password) {
    698713               
    699714                Toast.makeText(getApplicationContext(), "Decrypting file: " + fileToDecrypt, Toast.LENGTH_SHORT).show();
    700715               
    701                
     716                // -----------------------------
     717                AsyncTask<Void, Void, ArrayList<String>> task = new AsyncTask<Void, Void, ArrayList<String>>() {
     718
     719            private ProgressDialog pd;
     720
     721            @Override
     722            protected void onPreExecute() {
     723
     724                     pd = new ProgressDialog(PKCS12ToDecryptActivity.this);     
     725                     pd.setTitle("Descifrando archivo");       
     726                     pd.setMessage(getString(R.string.por_favor_epsere));       
     727                     pd.setCancelable(false);   
     728                     pd.setIndeterminate(true);
     729                     pd.show();
     730
     731            }
     732
     733            @Override
     734            protected ArrayList<String> doInBackground(Void... arg0) {
     735
     736                /*
     737                try {
     738                    Thread.sleep(3000);
     739                } catch(InterruptedException ex) {
     740                    Thread.currentThread().interrupt();
     741                }
     742                */
     743               
     744                // para solventar error:
     745                // Can't create handler inside thread that has not called Looper.prepare()
     746                Looper.prepare();
     747               
     748                // arreglo para almacenar resultado de la operacion
     749                ArrayList<String> resultArray = new ArrayList<String>();
     750                resultArray.clear();
     751               
     752                ConfigManager.init("jar://jdigidoc.cfg");
     753                        // signed doc object if used
     754                SignedDoc m_sdoc;
     755                m_sdoc = null;
     756
     757                // encrypted data object if used
     758                EncryptedData m_cdoc;
     759                m_cdoc = null;
     760                       
     761                        String outFile = null, keystoreFile = null, keystorePasswd = null, keystoreType="PKCS12";
     762
     763                        keystoreFile = pkcs12File;
     764
     765                        keystorePasswd = pkcs12Password;
     766
     767                        Log.d("Reading encrypted file: ",  fileToDecrypt);
     768                       
     769                        try {
     770                                EncryptedDataParser dencFac =  ConfigManager.instance().getEncryptedDataParser();
     771                                m_cdoc = dencFac.readEncryptedData(fileToDecrypt);                             
     772                        } catch(Exception ex) {                 
     773                                System.err.println("ERROR: reading encrypted file: " + fileToDecrypt + " - " + ex);
     774                                Log.d("ERROR: reading encrypted file: ",  ex.getMessage());
     775                                ex.printStackTrace(System.err);
     776                                Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_SHORT).show();
     777                               
     778                                //showDialog("Error:", ex.getMessage(), false);
     779                                //return null;
     780                               
     781                                resultArray.add("false");
     782                                resultArray.add("Error");
     783                                resultArray.add(ex.getMessage());
     784                                return resultArray;
     785                        }
     786                       
     787                        int nKey = -1;
     788                       
     789                        try{
     790                               
     791                                Pkcs12SignatureFactory p12fac = new Pkcs12SignatureFactory();
     792                                p12fac.init();
     793                                System.out.println("p12fac.init " );
     794                               
     795                                p12fac.load(keystoreFile, keystoreType, keystorePasswd);
     796                                System.out.println("p12fac.load()");
     797                               
     798                                X509Certificate cert = p12fac.getAuthCertificate(0, keystorePasswd);
     799                                System.out.println("p12fac.getAuthCertificate: " + nKey);
     800                               
     801                                nKey = m_cdoc.getRecvIndex(cert);
     802                                System.out.println("Using recipient: " + nKey);
     803                                if (nKey == -1) {
     804                                        throw(new ArrayIndexOutOfBoundsException(""));
     805                                }
     806                               
     807                               
     808                        } // fin del try interno
     809                        catch(DigiDocException ex){
     810                                System.err.println("ERROR: finding cdoc recipient: " + ex);
     811                               
     812                                Log.d("Error finding cdoc recipient: ",  ex.getMessage());
     813                        ex.printStackTrace(System.err);
     814                        Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_SHORT).show();   
     815                                       
     816                       
     817                       
     818                        if (ex.getCode() == DigiDocException.ERR_TOKEN_LOGIN) {
     819                               
     820                                // el pasword del PKCS12 no es correcto
     821                                //showDialog(getResources().getString(R.string.msg_encryption_error), "password incorrecto", false);
     822                                //return null;
     823                               
     824                                resultArray.add("false");
     825                                resultArray.add(getResources().getString(R.string.msg_encryption_error));
     826                                resultArray.add("contraseña incorrecta.");
     827                                return resultArray;
     828                               
     829                               
     830                        }else{
     831                        //showDialog(getResources().getString(R.string.msg_encryption_error), ex.getMessage(), false);
     832                                //return null;
     833                               
     834                                resultArray.add("false");
     835                                resultArray.add(getResources().getString(R.string.msg_encryption_error));
     836                                resultArray.add(ex.getMessage());
     837                                return resultArray;
     838                        }
     839                       
     840                        } catch(ArrayIndexOutOfBoundsException ex) {
     841                                //showDialog(getResources().getString(R.string.msg_encryption_error),
     842                                //              getResources().getString(R.string.error_decrypting_file_index_out_of_bounds), false);
     843                                //return null;
     844                               
     845                                resultArray.add("false");
     846                                resultArray.add(getResources().getString(R.string.msg_encryption_error));
     847                                resultArray.add(getResources().getString(R.string.error_decrypting_file_index_out_of_bounds));
     848                                return resultArray;
     849                               
     850                        }
     851                       
     852                        System.err.println("**** antes de ejecutar operacion m_cdoc.decryptPkcs12(nKey, keystoreFile, keystorePasswd, keystoreType)");
     853                        // ejecutar la operacion de descifrado:
     854                        try {
     855                               
     856                                m_cdoc.decryptPkcs12(nKey, keystoreFile, keystorePasswd, keystoreType);
     857                               
     858                                String [] absolutePathOriginalFile = fileToDecrypt.split(".cdoc");
     859                                //String fileName = split[0];
     860                                outFile = absolutePathOriginalFile[0];
     861                               
     862                                String [] path = absolutePathOriginalFile[0].split("/");
     863                               
     864                                String originalFileName = path[path.length-1];
     865                               
     866                                FileOutputStream fos = new FileOutputStream( outFile );
     867                               
     868                                Log.d("Decrypting file", "antes de escribir archivo " + outFile);
     869                       
     870                        fos.write(m_cdoc.getData());
     871                       
     872                        Log.d("Decrypting file", "despues de escribir archivo " + outFile);
     873                       
     874                        fos.close();
     875                       
     876                        Log.d("Decrypting file", "despues de cerrar archivo " + outFile);
     877                       
     878                        DigiDocFactory digFac = ConfigManager.instance().getDigiDocFactory();
     879                        Log.d("Decrypting file", "despues ConfigManager.instance().getDigiDocFactory()");               
     880                       
     881                        File file = new File(outFile);
     882                        InputStream selectedFile = null;
     883                        selectedFile = new BufferedInputStream(new FileInputStream(file));
     884                       
     885                        m_sdoc = digFac.readSignedDocFromStreamOfType(selectedFile, false);
     886                        Log.d("----", "leyo el ddoc");
     887                        Toast.makeText(getApplicationContext(), "leyó el ddoc", Toast.LENGTH_SHORT).show();
     888                       
     889                        selectedFile.close();
     890
     891                        // *******
     892                        Log.d("Decrypting file", "antes de m_sdoc.getDataFile(0)");
     893                        DataFile df = m_sdoc.getDataFile(0);
     894                        Log.d("Decrypting file", "despues de m_sdoc.getDataFile(0)");
     895                       
     896                        String decryptedDir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" +
     897                                getResources().getString(R.string.app_name) + "/" +
     898                                getResources().getString(R.string.decrypted_dir_files) + "/";
     899                       
     900                        decryptedFile = decryptedDir+originalFileName;
     901                       
     902                        fos = new FileOutputStream(decryptedFile);
     903                        InputStream is = df.getBodyAsStream();
     904                       
     905                        if(is == null) {
     906                        System.err.println("DataFile has no data!");
     907                        //showDialog(getResources().getString(R.string.msg_encryption_error),
     908                        //              "DataFile has no data!", false);
     909                        //return null;
     910                       
     911                       
     912                        resultArray.add("false");
     913                                resultArray.add(getResources().getString(R.string.msg_encryption_error));
     914                                resultArray.add("DataFile has no data!");
     915                                return resultArray;
     916                       
     917                    }
     918                        byte[] data = new byte[4096];
     919                    int n = 0, m = 0;
     920                    while((n = is.read(data)) > 0) {
     921                        fos.write(data, 0, n);
     922                        m += n;
     923                    }
     924                    fos.close();
     925                    is.close();
     926
     927                    // borrar el archivo ddoc
     928                    File ddocFile = new File(outFile);
     929                    ddocFile.delete();
     930                   
     931                   
     932                    //Toast.makeText(getApplicationContext(), "Descifrado correctamente: " + decryptedFile, Toast.LENGTH_SHORT).show();
     933                        //showDialog("Información:", "Archivo descifrado exitosamente.", true);
     934                   
     935                    resultArray.add("true");
     936                                resultArray.add("Información:");
     937                                resultArray.add("Archivo descifrado exitosamente.");
     938                       
     939                               
     940                               
     941                        } catch (DigiDocException e) {
     942                               
     943                                //showDialog(getResources().getString(R.string.msg_encryption_error),
     944                                //              e.getMessage(), false);
     945                                //return null;
     946                               
     947                                resultArray.add("false");
     948                                resultArray.add(getResources().getString(R.string.msg_encryption_error));
     949                                resultArray.add(e.getMessage());
     950                                return resultArray;
     951                               
     952                        }
     953                       
     954                        catch (FileNotFoundException e) {
     955                                //showDialog(getResources().getString(R.string.msg_encryption_error),
     956                                //              e.getMessage(), false);
     957                                //return null;
     958                               
     959                                resultArray.add("false");
     960                                resultArray.add(getResources().getString(R.string.msg_encryption_error));
     961                                resultArray.add(e.getMessage());
     962                                return resultArray;
     963                               
     964                        } catch (IOException e) {
     965                                //showDialog(getResources().getString(R.string.msg_encryption_error),
     966                                //              e.getMessage(), false);
     967                                //return null;
     968                               
     969                                resultArray.add("false");
     970                                resultArray.add(getResources().getString(R.string.msg_encryption_error));
     971                                resultArray.add(e.getMessage());
     972                                return resultArray;
     973                               
     974                        }
     975                               
     976                return resultArray;
     977         }           
     978         @Override
     979         protected void onPostExecute(ArrayList<String> result) {
     980                 
     981                 if (result.get(0).equals("false")){
     982                         showDialog(result.get(1), result.get(2), false);
     983                 }else{
     984                         showDialog(result.get(1), result.get(2), true);
     985                 }
     986                         
     987
     988             pd.dismiss();
     989
     990         }
     991
     992        };
     993
     994        task.execute((Void[])null);
     995               
     996               
     997                // -----------------------------
     998/*             
    702999                ConfigManager.init("jar://jdigidoc.cfg");
    703                 /** signed doc object if used */
     1000                // signed doc object if used
    7041001        SignedDoc m_sdoc;
    7051002        m_sdoc = null;
    7061003
    707         /** encrypted data object if used */
     1004        // encrypted data object if used
    7081005        EncryptedData m_cdoc;
    7091006        m_cdoc = null;
     
    8751172                        return;
    8761173                }
    877                
     1174*/             
    8781175               
    8791176               
  • TibisayMovil/src/ve/gob/cenditel/tibisaymovil/PreferencesActivity.java

    r288126d r2ff9cec  
    11package ve.gob.cenditel.tibisaymovil;
     2import java.io.File;
     3
     4import android.content.Intent;
     5import android.content.SharedPreferences;
     6import android.database.Cursor;
     7import android.graphics.Bitmap;
     8import android.graphics.BitmapFactory;
     9import android.net.Uri;
    210import android.os.Bundle;
     11import android.preference.ListPreference;
     12import android.preference.Preference;
     13import android.preference.Preference.OnPreferenceChangeListener;
     14import android.preference.Preference.OnPreferenceClickListener;
    315import android.preference.PreferenceActivity;
     16import android.provider.MediaStore;
     17import android.view.Window;
     18import android.widget.Toast;
    419
    5 public class PreferencesActivity extends PreferenceActivity {
     20public class PreferencesActivity extends PreferenceActivity implements OnPreferenceClickListener,OnPreferenceChangeListener{
     21       
     22        static final int PICK_IMAGE = 33;
     23        public static final String imageKey = "image";
     24        public static final String positionKey = "position";
     25        private static final int MAXWIDTH = 400;
     26        private static final int MAXHEIGHT = 400;
     27        private static final long SIZELIMIT = 1024 * 1024;
     28       
     29        private SharedPreferences options;
     30        private Preference imagePreference;
     31       
    632    @Override
    733    public void onCreate(Bundle savedInstanceState) {
     34                //Estilando la barra de titulo
     35                final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
     36
    837        super.onCreate(savedInstanceState);
    9  
     38
    1039        addPreferencesFromResource(R.xml.preferences);
     40       
     41        this.options = this.getPreferenceManager().getSharedPreferences();
     42       
     43       
     44
     45       
     46        this.imagePreference = (Preference) findPreference(PreferencesActivity.imageKey);
     47        this.imagePreference.setOnPreferenceClickListener(this);
     48        this.imagePreference.setOnPreferenceChangeListener(this);
     49       
     50        this.loadSummary();
     51       
     52
     53        //Estilando Barra de titulo
     54                if(customTitleSupported)
     55                        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
     56       
    1157    }
     58   
     59        private void loadSummary() {
     60            String path = options.getString(PreferencesActivity.imageKey, "");
     61        if (!path.equals("")){
     62                this.imagePreference.setSummary(path);
     63        }
     64       
     65        }
     66
     67   
     68   
     69    @Override
     70        public boolean onPreferenceChange(Preference preference, Object newValue) {
     71          String summary="";
     72         
     73         
     74          if (summary!=null && !summary.equals("")){
     75                  preference.setSummary((CharSequence) summary);
     76                         
     77                  }
     78          return true;
     79        }
     80
     81
     82       
     83        @Override
     84        public boolean onPreferenceClick(Preference preference) {
     85               
     86                if (preference.getKey().equals(PreferencesActivity.imageKey)){
     87                                Intent i = new Intent(
     88                                Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
     89                                startActivityForResult(i, PreferencesActivity.PICK_IMAGE);
     90                                return true;
     91                }
     92                return false;
     93        }
     94   
     95        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
     96             super.onActivityResult(requestCode, resultCode, data);
     97             
     98             
     99             if (requestCode == PreferencesActivity.PICK_IMAGE && resultCode == RESULT_OK){
     100                 
     101                 Uri selectedImage = data.getData();
     102                 String[] filePathColumn = { MediaStore.Images.Media.DATA };
     103         
     104                 Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
     105                 cursor.moveToFirst();
     106         
     107                 int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
     108                 String imageSelectedPath = cursor.getString(columnIndex);
     109                 cursor.close();
     110                 
     111                 //Filter images if wrong format.
     112                 boolean validImage = this.validateImage(imageSelectedPath);
     113                 
     114                 if (validImage==true){
     115                         //Save and edit summary text in user interface.
     116                        SharedPreferences.Editor editor = this.options.edit();
     117                        editor.putString(PreferencesActivity.imageKey, imageSelectedPath);
     118                        editor.commit();
     119                        this.imagePreference.setSummary(imageSelectedPath);
     120                 }
     121                 
     122             
     123         
     124             }
     125
     126             
     127             
     128             
     129        }
     130
     131        //Check image dimensions and format.
     132        private boolean validateImage(String imageSelectedPath) {
     133                File f = new File(imageSelectedPath);
     134                long size = f.length();
     135
     136                if (size <= (PreferencesActivity.SIZELIMIT)) {
     137                       
     138                        Bitmap chosenImage = BitmapFactory.decodeFile(imageSelectedPath);
     139                       
     140                        if (chosenImage !=null)
     141                                return this.checkDimensions(chosenImage);
     142                        else{
     143                                Toast.makeText(this, this.getString(R.string.errorformat),Toast.LENGTH_SHORT).show();
     144                                return false;
     145                        }
     146
     147                } else {
     148                        Toast.makeText(this, this.getString(R.string.errorsize)+" "+(PreferencesActivity.SIZELIMIT)/(1024*1024)+"MB",Toast.LENGTH_SHORT).show();
     149                        return false;
     150                }
     151               
     152               
     153               
     154        }
     155
     156
     157        private boolean checkDimensions(Bitmap chosenImage) {
     158
     159                int width = chosenImage.getWidth();
     160                int height = chosenImage.getHeight();
     161
     162                if (width <= PreferencesActivity.MAXWIDTH && height <= PreferencesActivity.MAXHEIGHT) {
     163                        return true;
     164                       
     165                } else {
     166
     167                        Toast.makeText( this,this.getString(R.string.errordimension) +" "+ PreferencesActivity.MAXWIDTH
     168                                                        + "x" + PreferencesActivity.MAXHEIGHT,Toast.LENGTH_SHORT).show();
     169                        return false;
     170                }               
     171        }
     172
     173
     174       
     175
    12176}
  • 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();         
  • TibisayMovil/src/ve/gob/cenditel/tibisaymovil/SelectSignUbicationHandwrittenSignatureActivity.java

    r288126d rbb739b0  
    308308        }catch (DocumentException e) {
    309309            e.printStackTrace();
    310             Toast.makeText(getApplicationContext(), "Error al firmar el archivo doc", Toast.LENGTH_LONG).show();
     310            Toast.makeText(getApplicationContext(), "Error al firmar el archivo", Toast.LENGTH_LONG).show();
    311311        }
    312312                return true;
  • TibisayMovil/src/ve/gob/cenditel/tibisaymovil/SignActivity.java

    r288126d r2ff9cec  
    3434
    3535
     36import com.lowagie.text.exceptions.InvalidPdfException;
    3637// prueba de droidtext
    3738import com.lowagie.text.pdf.*;
     
    287288                                  }
    288289                                });
    289                
    290                 } catch (Exception e) {
    291                         final Activity act = ((Activity) this.context);
    292                         Toast.makeText(act, "exception", Toast.LENGTH_SHORT).show();
    293                     FsUtils.checkOutOfSpace(e, true);
    294                     this.cancel(true);
    295                     //throw new RuntimeException(e);
    296                 }
     290                } catch (InvalidPdfException e) {
     291                        //empty               
     292                    } catch (Exception e) {
     293                        final Activity act = ((Activity) this.context);
     294                        Toast.makeText(act, "exception", Toast.LENGTH_SHORT).show();
     295                        FsUtils.checkOutOfSpace(e, true);
     296                        this.cancel(true);
     297                        //throw new RuntimeException(e);
     298                    }
    297299               
    298300               
Note: See TracChangeset for help on using the changeset viewer.