blob: 6b69b8a3f581d24854fca591cf3348d20f5ae8e5 [file] [log] [blame]
Chia-chi Yeh9b7a3f12009-09-18 12:00:12 +08001/*
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
17package android.security;
18
19import android.content.ActivityNotFoundException;
20import android.content.Context;
21import android.content.Intent;
22import android.util.Log;
23
24import java.security.KeyPair;
25
26/**
27 * {@hide}
28 */
29public class Credentials {
30 private static final String LOGTAG = "Credentials";
Chia-chi Yeh44039172009-09-21 11:53:59 +080031
Chia-chi Yeh44039172009-09-21 11:53:59 +080032 public static final String INSTALL_ACTION = "android.credentials.INSTALL";
33
Brian Carlstrom4a9e1a22011-04-22 15:45:22 -070034 public static final String UNLOCK_ACTION = "com.android.credentials.UNLOCK";
35
Chia-chi Yeh9b7a3f12009-09-18 12:00:12 +080036 /** Key prefix for CA certificates. */
37 public static final String CA_CERTIFICATE = "CACERT_";
38
39 /** Key prefix for user certificates. */
40 public static final String USER_CERTIFICATE = "USRCERT_";
41
42 /** Key prefix for user private keys. */
43 public static final String USER_PRIVATE_KEY = "USRPKEY_";
44
45 /** Key prefix for VPN. */
46 public static final String VPN = "VPN_";
47
48 /** Key prefix for WIFI. */
49 public static final String WIFI = "WIFI_";
50
51 /** Data type for public keys. */
52 public static final String PUBLIC_KEY = "KEY";
53
54 /** Data type for private keys. */
55 public static final String PRIVATE_KEY = "PKEY";
56
57 /** Data type for certificates. */
58 public static final String CERTIFICATE = "CERT";
59
60 /** Data type for PKCS12. */
61 public static final String PKCS12 = "PKCS12";
62
Chia-chi Yeh44039172009-09-21 11:53:59 +080063 private static Credentials singleton;
64
Chia-chi Yeh9b7a3f12009-09-18 12:00:12 +080065 public static Credentials getInstance() {
66 if (singleton == null) {
67 singleton = new Credentials();
68 }
69 return singleton;
70 }
71
72 public void unlock(Context context) {
73 try {
Brian Carlstrom4a9e1a22011-04-22 15:45:22 -070074 Intent intent = new Intent(UNLOCK_ACTION);
Chia-chi Yeh9b7a3f12009-09-18 12:00:12 +080075 context.startActivity(intent);
76 } catch (ActivityNotFoundException e) {
77 Log.w(LOGTAG, e.toString());
78 }
79 }
80
Hung-ying Tyanc5e630a2010-10-08 08:20:16 +080081 private Intent createInstallIntent() {
82 Intent intent = new Intent(INSTALL_ACTION);
83 intent.setClassName("com.android.certinstaller",
84 "com.android.certinstaller.CertInstallerMain");
85 return intent;
86 }
87
Chia-chi Yeh9b7a3f12009-09-18 12:00:12 +080088 public void install(Context context, KeyPair pair) {
89 try {
Hung-ying Tyanc5e630a2010-10-08 08:20:16 +080090 Intent intent = createInstallIntent();
Chia-chi Yeh9b7a3f12009-09-18 12:00:12 +080091 intent.putExtra(PRIVATE_KEY, pair.getPrivate().getEncoded());
92 intent.putExtra(PUBLIC_KEY, pair.getPublic().getEncoded());
93 context.startActivity(intent);
94 } catch (ActivityNotFoundException e) {
95 Log.w(LOGTAG, e.toString());
96 }
97 }
98
99 public void install(Context context, String type, byte[] value) {
100 try {
Hung-ying Tyanc5e630a2010-10-08 08:20:16 +0800101 Intent intent = createInstallIntent();
Chia-chi Yeh9b7a3f12009-09-18 12:00:12 +0800102 intent.putExtra(type, value);
103 context.startActivity(intent);
104 } catch (ActivityNotFoundException e) {
105 Log.w(LOGTAG, e.toString());
106 }
107 }
Chia-chi Yeh9b7a3f12009-09-18 12:00:12 +0800108}