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 java.security.PrivateKey; |
---|
24 | import java.security.cert.X509Certificate; |
---|
25 | |
---|
26 | import android.annotation.SuppressLint; |
---|
27 | import android.content.Context; |
---|
28 | import android.security.KeyChain; |
---|
29 | import android.security.KeyChainAliasCallback; |
---|
30 | import android.security.KeyChainException; |
---|
31 | |
---|
32 | @SuppressLint("NewApi") |
---|
33 | public class AndroidKeyChain extends KeyChainStrategy implements KeyChainAliasCallback { |
---|
34 | |
---|
35 | private static final long serialVersionUID = -5618428393037452012L; |
---|
36 | private static Context context; |
---|
37 | |
---|
38 | private AndroidKeyChain() {} |
---|
39 | |
---|
40 | public static AndroidKeyChain getInstance() { |
---|
41 | |
---|
42 | if (KeyChainStrategy.theInstance == null) { |
---|
43 | |
---|
44 | KeyChainStrategy.theInstance = new AndroidKeyChain(); |
---|
45 | } |
---|
46 | return (AndroidKeyChain) KeyChainStrategy.theInstance; |
---|
47 | } |
---|
48 | |
---|
49 | @Override |
---|
50 | public void setClientActivity(KeyChainClientActivity activity) { |
---|
51 | |
---|
52 | super.setClientActivity(activity); |
---|
53 | AndroidKeyChain.context = activity.getApplicationContext(); |
---|
54 | } |
---|
55 | |
---|
56 | @Override |
---|
57 | public void choosePrivateKeyAlias() { |
---|
58 | |
---|
59 | KeyChain.choosePrivateKeyAlias(KeyChainStrategy.activity, this, null, null, null, -1, null); |
---|
60 | } |
---|
61 | |
---|
62 | @Override |
---|
63 | public void choosePrivateKeyList() { |
---|
64 | KeyChain.choosePrivateKeyAlias(KeyChainStrategy.activity, this, null, null, null, -1, null); |
---|
65 | |
---|
66 | } |
---|
67 | |
---|
68 | @Override |
---|
69 | public X509Certificate[] getCertificateChain(String alias) |
---|
70 | throws InterruptedException, KeystoreException { |
---|
71 | |
---|
72 | try { |
---|
73 | return KeyChain.getCertificateChain(AndroidKeyChain.context, alias); |
---|
74 | } catch (KeyChainException e) { |
---|
75 | throw new KeystoreException(e); |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | @Override |
---|
80 | public PrivateKey getPrivateKey(String alias) |
---|
81 | throws InterruptedException, KeystoreException { |
---|
82 | |
---|
83 | try { |
---|
84 | return KeyChain.getPrivateKey(AndroidKeyChain.context, alias); |
---|
85 | } catch (KeyChainException e) { |
---|
86 | throw new KeystoreException(e); |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | //TODO: |
---|
91 | @Override |
---|
92 | public int deleteCertificate(String alias) throws KeystoreException{ |
---|
93 | /* |
---|
94 | try { |
---|
95 | KeyStore trusted = getKeystore(); |
---|
96 | trusted.deleteEntry(alias); |
---|
97 | } catch (Exception e) { |
---|
98 | throw new KeystoreException(e); |
---|
99 | } |
---|
100 | */ |
---|
101 | return 0; |
---|
102 | |
---|
103 | } |
---|
104 | |
---|
105 | @Override |
---|
106 | public void alias(String alias) { |
---|
107 | |
---|
108 | KeyChainStrategy.activity.setAlias(alias); |
---|
109 | } |
---|
110 | } |
---|