| 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"; |
| 31 | private static final String UNLOCK_ACTION = "android.credentials.UNLOCK"; |
| 32 | private static final String INSTALL_ACTION = "android.credentials.INSTALL"; |
| 33 | private static Credentials singleton; |
| 34 | |
| 35 | /** Key prefix for CA certificates. */ |
| 36 | public static final String CA_CERTIFICATE = "CACERT_"; |
| 37 | |
| 38 | /** Key prefix for user certificates. */ |
| 39 | public static final String USER_CERTIFICATE = "USRCERT_"; |
| 40 | |
| 41 | /** Key prefix for user private keys. */ |
| 42 | public static final String USER_PRIVATE_KEY = "USRPKEY_"; |
| 43 | |
| 44 | /** Key prefix for VPN. */ |
| 45 | public static final String VPN = "VPN_"; |
| 46 | |
| 47 | /** Key prefix for WIFI. */ |
| 48 | public static final String WIFI = "WIFI_"; |
| 49 | |
| 50 | /** Data type for public keys. */ |
| 51 | public static final String PUBLIC_KEY = "KEY"; |
| 52 | |
| 53 | /** Data type for private keys. */ |
| 54 | public static final String PRIVATE_KEY = "PKEY"; |
| 55 | |
| 56 | /** Data type for certificates. */ |
| 57 | public static final String CERTIFICATE = "CERT"; |
| 58 | |
| 59 | /** Data type for PKCS12. */ |
| 60 | public static final String PKCS12 = "PKCS12"; |
| 61 | |
| 62 | public static Credentials getInstance() { |
| 63 | if (singleton == null) { |
| 64 | singleton = new Credentials(); |
| 65 | } |
| 66 | return singleton; |
| 67 | } |
| 68 | |
| 69 | public void unlock(Context context) { |
| 70 | try { |
| 71 | Intent intent = new Intent(UNLOCK_ACTION); |
| 72 | context.startActivity(intent); |
| 73 | } catch (ActivityNotFoundException e) { |
| 74 | Log.w(LOGTAG, e.toString()); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | public void install(Context context, KeyPair pair) { |
| 79 | try { |
| 80 | Intent intent = new Intent(INSTALL_ACTION); |
| 81 | intent.putExtra(PRIVATE_KEY, pair.getPrivate().getEncoded()); |
| 82 | intent.putExtra(PUBLIC_KEY, pair.getPublic().getEncoded()); |
| 83 | context.startActivity(intent); |
| 84 | } catch (ActivityNotFoundException e) { |
| 85 | Log.w(LOGTAG, e.toString()); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | public void install(Context context, String type, byte[] value) { |
| 90 | try { |
| 91 | Intent intent = new Intent(INSTALL_ACTION); |
| 92 | intent.putExtra(type, value); |
| 93 | context.startActivity(intent); |
| 94 | } catch (ActivityNotFoundException e) { |
| 95 | Log.w(LOGTAG, e.toString()); |
| 96 | } |
| 97 | } |
| 98 | } |