source: dispositivos_moviles/TibisayMovil/src/ve/gob/cenditel/tibisaymovil/KeyChainStrategy.java @ 8379cd8

Last change on this file since 8379cd8 was 8379cd8, checked in by Antonio Araujo Brett <aaraujo@…>, 11 years ago

Agregado encabezado de licencia a archivos fuentes.

  • Property mode set to 100644
File size: 4.5 KB
Line 
1/*
2Tibisay Movil
3
4Copyright (C) 2013 Antonio Araujo (aaraujo@cenditel.gob.ve), Jose Ruiz
5(jruiz@cenditel.gob.ve), Fundacion Centro Nacional de Desarrollo e
6Investigacion en Tecnologias Libres - CENDITEL.
7
8La Fundación CENDITEL concede permiso para usar, copiar, distribuir y/o
9modificar este programa, reconociendo el derecho que la humanidad posee al
10libre acceso al conocimiento, bajo los términos de la licencia de software
11GPL versión 2.0 de la Free Software Foundation.
12
13Este programa se distribuye con la esperanza de que sea util, pero SIN
14NINGUNA GARANTIA; tampoco las implicitas garantias de MERCANTILIDAD o
15ADECUACION A UN PROPOSITO PARTICULAR.
16
17Para mayor información sobre los términos de la licencia ver el archivo
18llamado "gpl-2.0.txt" en ingles.
19*/
20
21package ve.gob.cenditel.tibisaymovil;
22
23import java.io.Serializable;
24import java.security.PrivateKey;
25import java.security.cert.X509Certificate;
26
27import android.os.Build;
28import android.os.Build.VERSION_CODES;
29
30/**
31 * Accesses the KeyChain in a unified way both in Android versions post and pre 4.0. Android 4.0 and later has an
32 * operating system level keychain. This keychain is shared across the operating system and all applications. In prior
33 * versions a custom, application private keychain will be used.
34 *
35 * @author José M. Prieto (jmprieto@emergya.com)
36 */
37public abstract class KeyChainStrategy implements Serializable {
38
39    private static final long serialVersionUID = -5156264665372692833L;
40    protected static KeyChainStrategy theInstance = null;
41
42    protected static KeyChainClientActivity activity;
43
44    public static KeyChainStrategy getInstance() {
45
46        if (theInstance == null) {
47            if (Build.VERSION.SDK_INT < VERSION_CODES.ICE_CREAM_SANDWICH) {
48                // < Android 4.0. Does not have KeyChain API
49                return CustomKeyChain.getInstance();
50            } else {
51                // >= Android 4.0. KeyChain available!
52                return AndroidKeyChain.getInstance();
53            }
54        }
55        return theInstance;
56    }
57
58    /**
59     * Set the KeyChainClientActivity that will be notified of the alias selected by the user. The notification is done
60     * via the {@link KeyChainClientActivity#setAlias(String)} callback.
61     *
62     * @param activity the receiver of notifications
63     */
64    public void setClientActivity(KeyChainClientActivity activity) {
65        KeyChainStrategy.activity = activity;
66    }
67
68    /**
69     * Launches an Activity for the user to select the alias for a private key and certificate pair for authentication.
70     * The selected alias or null will be returned to the {@link KeyChainClientActivity} passed to the previous call to
71     * {@link #setClientActivity(KeyChainClientActivity)} via the
72     * {@link KeyChainClientActivity#setAlias(String)} callback.
73     */
74    public abstract void choosePrivateKeyAlias();
75   
76   
77    /**
78     * Same as before, but only to modify alias list.
79     */
80    public abstract void choosePrivateKeyList();
81   
82
83    /**
84     * Get a certificate chain from the keystore.
85     * This method requires the caller to hold the permission USE_CREDENTIALS on Android >= 4.0.
86     *
87     * @param alias The alias of the desired certificate chain
88     * @return the X509Certificate chain for the requested alias, or null if no there is no result
89     * @throws InterruptedException if the operation has been interrupted before completion
90     * @throws KeystoreException when there is some error accessing the keystore
91     */
92    public abstract X509Certificate[] getCertificateChain(String alias)
93    throws InterruptedException, KeystoreException;
94
95    /**
96     * Get a private key from the keystore.
97     *
98     * @param alias the alias of the desired private key
99     * @return the PrivateKey for the requested alias, or null if no there is no result
100     * @throws InterruptedException if the operation has been interrupted before completion
101     * @throws KeystoreException when there is some error accessing the keystore
102     */
103    public abstract PrivateKey getPrivateKey(String alias)
104    throws InterruptedException, KeystoreException;
105   
106   
107   
108   
109    /**
110     * Delete a certificate from the keystore.
111     *
112     * @param alias the alias of the certificate chain to delete
113     * @throws InterruptedException if the operation has been interrupted before completion
114     * @throws KeystoreException when there is some error accessing the keystore
115     */
116    public abstract int deleteCertificate(String alias) 
117                throws InterruptedException, KeystoreException;
118   
119   
120   
121}
Note: See TracBrowser for help on using the repository browser.