Chia-chi Yeh | 9b7a3f1 | 2009-09-18 12:00:12 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.security; |
| 18 | |
| 19 | import android.content.ActivityNotFoundException; |
| 20 | import android.content.Context; |
| 21 | import android.content.Intent; |
| 22 | import android.util.Log; |
| 23 | |
| 24 | import java.security.KeyPair; |
| 25 | |
| 26 | /** |
| 27 | * {@hide} |
| 28 | */ |
| 29 | public class Credentials { |
| 30 | private static final String LOGTAG = "Credentials"; |
Chia-chi Yeh | 4403917 | 2009-09-21 11:53:59 +0800 | [diff] [blame] | 31 | |
Chia-chi Yeh | 4403917 | 2009-09-21 11:53:59 +0800 | [diff] [blame] | 32 | public static final String INSTALL_ACTION = "android.credentials.INSTALL"; |
| 33 | |
Chia-chi Yeh | 9b7a3f1 | 2009-09-18 12:00:12 +0800 | [diff] [blame] | 34 | /** Key prefix for CA certificates. */ |
| 35 | public static final String CA_CERTIFICATE = "CACERT_"; |
| 36 | |
| 37 | /** Key prefix for user certificates. */ |
| 38 | public static final String USER_CERTIFICATE = "USRCERT_"; |
| 39 | |
| 40 | /** Key prefix for user private keys. */ |
| 41 | public static final String USER_PRIVATE_KEY = "USRPKEY_"; |
| 42 | |
| 43 | /** Key prefix for VPN. */ |
| 44 | public static final String VPN = "VPN_"; |
| 45 | |
| 46 | /** Key prefix for WIFI. */ |
| 47 | public static final String WIFI = "WIFI_"; |
| 48 | |
| 49 | /** Data type for public keys. */ |
| 50 | public static final String PUBLIC_KEY = "KEY"; |
| 51 | |
| 52 | /** Data type for private keys. */ |
| 53 | public static final String PRIVATE_KEY = "PKEY"; |
| 54 | |
| 55 | /** Data type for certificates. */ |
| 56 | public static final String CERTIFICATE = "CERT"; |
| 57 | |
| 58 | /** Data type for PKCS12. */ |
| 59 | public static final String PKCS12 = "PKCS12"; |
| 60 | |
Chia-chi Yeh | 4403917 | 2009-09-21 11:53:59 +0800 | [diff] [blame] | 61 | private static Credentials singleton; |
| 62 | |
Chia-chi Yeh | 9b7a3f1 | 2009-09-18 12:00:12 +0800 | [diff] [blame] | 63 | public static Credentials getInstance() { |
| 64 | if (singleton == null) { |
| 65 | singleton = new Credentials(); |
| 66 | } |
| 67 | return singleton; |
| 68 | } |
| 69 | |
| 70 | public void unlock(Context context) { |
| 71 | try { |
Chia-chi Yeh | 527f01e | 2011-01-20 20:23:59 +0800 | [diff] [blame] | 72 | Intent intent = new Intent("com.android.credentials.UNLOCK"); |
Chia-chi Yeh | 9b7a3f1 | 2009-09-18 12:00:12 +0800 | [diff] [blame] | 73 | context.startActivity(intent); |
| 74 | } catch (ActivityNotFoundException e) { |
| 75 | Log.w(LOGTAG, e.toString()); |
| 76 | } |
| 77 | } |
| 78 | |
Hung-ying Tyan | c5e630a | 2010-10-08 08:20:16 +0800 | [diff] [blame] | 79 | private Intent createInstallIntent() { |
| 80 | Intent intent = new Intent(INSTALL_ACTION); |
| 81 | intent.setClassName("com.android.certinstaller", |
| 82 | "com.android.certinstaller.CertInstallerMain"); |
| 83 | return intent; |
| 84 | } |
| 85 | |
Chia-chi Yeh | 9b7a3f1 | 2009-09-18 12:00:12 +0800 | [diff] [blame] | 86 | public void install(Context context, KeyPair pair) { |
| 87 | try { |
Hung-ying Tyan | c5e630a | 2010-10-08 08:20:16 +0800 | [diff] [blame] | 88 | Intent intent = createInstallIntent(); |
Chia-chi Yeh | 9b7a3f1 | 2009-09-18 12:00:12 +0800 | [diff] [blame] | 89 | intent.putExtra(PRIVATE_KEY, pair.getPrivate().getEncoded()); |
| 90 | intent.putExtra(PUBLIC_KEY, pair.getPublic().getEncoded()); |
| 91 | context.startActivity(intent); |
| 92 | } catch (ActivityNotFoundException e) { |
| 93 | Log.w(LOGTAG, e.toString()); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | public void install(Context context, String type, byte[] value) { |
| 98 | try { |
Hung-ying Tyan | c5e630a | 2010-10-08 08:20:16 +0800 | [diff] [blame] | 99 | Intent intent = createInstallIntent(); |
Chia-chi Yeh | 9b7a3f1 | 2009-09-18 12:00:12 +0800 | [diff] [blame] | 100 | intent.putExtra(type, value); |
| 101 | context.startActivity(intent); |
| 102 | } catch (ActivityNotFoundException e) { |
| 103 | Log.w(LOGTAG, e.toString()); |
| 104 | } |
| 105 | } |
Chia-chi Yeh | 9b7a3f1 | 2009-09-18 12:00:12 +0800 | [diff] [blame] | 106 | } |