Fields Summary |
---|
private static final String | LOGTAG |
public static final String | INSTALL_ACTION |
public static final String | INSTALL_AS_USER_ACTION |
public static final String | UNLOCK_ACTION |
public static final String | CA_CERTIFICATEKey prefix for CA certificates. |
public static final String | USER_CERTIFICATEKey prefix for user certificates. |
public static final String | USER_PRIVATE_KEYKey prefix for user private keys. |
public static final String | VPNKey prefix for VPN. |
public static final String | WIFIKey prefix for WIFI. |
public static final String | LOCKDOWN_VPNKey containing suffix of lockdown VPN profile. |
public static final String | EXTRA_PUBLIC_KEYData type for public keys. |
public static final String | EXTRA_PRIVATE_KEYData type for private keys. |
public static final String | EXTENSION_CRT |
public static final String | EXTENSION_P12 |
public static final String | EXTENSION_CER |
public static final String | EXTENSION_PFX |
public static final String | EXTRA_INSTALL_AS_UIDIntent extra: install the certificate bundle as this UID instead of
system. |
public static final String | EXTRA_USER_PRIVATE_KEY_NAMEIntent extra: name for the user's private key. |
public static final String | EXTRA_USER_PRIVATE_KEY_DATAIntent extra: data for the user's private key in PEM-encoded PKCS#8. |
public static final String | EXTRA_USER_CERTIFICATE_NAMEIntent extra: name for the user's certificate. |
public static final String | EXTRA_USER_CERTIFICATE_DATAIntent extra: data for the user's certificate in PEM-encoded X.509. |
public static final String | EXTRA_CA_CERTIFICATES_NAMEIntent extra: name for CA certificate chain |
public static final String | EXTRA_CA_CERTIFICATES_DATAIntent extra: data for CA certificate chain in PEM-encoded X.509. |
private static Credentials | singleton |
Methods Summary |
---|
public static java.util.List | convertFromPem(byte[] bytes)Convert objects from PEM format, which is used for
CA_CERTIFICATE and USER_CERTIFICATE entries.
ByteArrayInputStream bai = new ByteArrayInputStream(bytes);
Reader reader = new InputStreamReader(bai, StandardCharsets.US_ASCII);
PemReader pr = new PemReader(reader);
CertificateFactory cf = CertificateFactory.getInstance("X509");
List<X509Certificate> result = new ArrayList<X509Certificate>();
PemObject o;
while ((o = pr.readPemObject()) != null) {
if (o.getType().equals("CERTIFICATE")) {
Certificate c = cf.generateCertificate(new ByteArrayInputStream(o.getContent()));
result.add((X509Certificate) c);
} else {
throw new IllegalArgumentException("Unknown type " + o.getType());
}
}
pr.close();
return result;
|
public static byte[] | convertToPem(java.security.cert.Certificate objects)Convert objects to a PEM format which is used for
CA_CERTIFICATE and USER_CERTIFICATE entries.
ByteArrayOutputStream bao = new ByteArrayOutputStream();
Writer writer = new OutputStreamWriter(bao, StandardCharsets.US_ASCII);
PemWriter pw = new PemWriter(writer);
for (Certificate o : objects) {
pw.writeObject(new PemObject("CERTIFICATE", o.getEncoded()));
}
pw.close();
return bao.toByteArray();
|
static boolean | deleteAllTypesForAlias(KeyStore keystore, java.lang.String alias)Delete all types (private key, certificate, CA certificate) for a
particular {@code alias}. All three can exist for any given alias.
Returns {@code true} if there was at least one of those types.
/*
* Make sure every type is deleted. There can be all three types, so
* don't use a conditional here.
*/
return keystore.delKey(Credentials.USER_PRIVATE_KEY + alias)
| deleteCertificateTypesForAlias(keystore, alias);
|
static boolean | deleteCertificateTypesForAlias(KeyStore keystore, java.lang.String alias)Delete all types (private key, certificate, CA certificate) for a
particular {@code alias}. All three can exist for any given alias.
Returns {@code true} if there was at least one of those types.
/*
* Make sure every certificate type is deleted. There can be two types,
* so don't use a conditional here.
*/
return keystore.delete(Credentials.USER_CERTIFICATE + alias)
| keystore.delete(Credentials.CA_CERTIFICATE + alias);
|
public static android.security.Credentials | getInstance()
if (singleton == null) {
singleton = new Credentials();
}
return singleton;
|
public void | install(android.content.Context context)
try {
Intent intent = KeyChain.createInstallIntent();
context.startActivity(intent);
} catch (ActivityNotFoundException e) {
Log.w(LOGTAG, e.toString());
}
|
public void | install(android.content.Context context, java.security.KeyPair pair)
try {
Intent intent = KeyChain.createInstallIntent();
intent.putExtra(EXTRA_PRIVATE_KEY, pair.getPrivate().getEncoded());
intent.putExtra(EXTRA_PUBLIC_KEY, pair.getPublic().getEncoded());
context.startActivity(intent);
} catch (ActivityNotFoundException e) {
Log.w(LOGTAG, e.toString());
}
|
public void | install(android.content.Context context, java.lang.String type, byte[] value)
try {
Intent intent = KeyChain.createInstallIntent();
intent.putExtra(type, value);
context.startActivity(intent);
} catch (ActivityNotFoundException e) {
Log.w(LOGTAG, e.toString());
}
|
public void | unlock(android.content.Context context)
try {
Intent intent = new Intent(UNLOCK_ACTION);
context.startActivity(intent);
} catch (ActivityNotFoundException e) {
Log.w(LOGTAG, e.toString());
}
|