Skip to content

Commit

Permalink
Rename API AndroidKey* -> Key*
Browse files Browse the repository at this point in the history
Bug: 8657552
Change-Id: Id9102b7c2c2f6d27fba7645f0629750cfe1eb510
  • Loading branch information
kruton committed Apr 19, 2013
1 parent a454c57 commit 1c219f6
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 107 deletions.
62 changes: 31 additions & 31 deletions api/current.txt
Expand Up @@ -21120,37 +21120,6 @@ package android.sax {

package android.security {

public final class AndroidKeyPairGeneratorSpec implements java.security.spec.AlgorithmParameterSpec {
method public android.content.Context getContext();
method public java.util.Date getEndDate();
method public java.lang.String getKeystoreAlias();
method public java.math.BigInteger getSerialNumber();
method public java.util.Date getStartDate();
method public javax.security.auth.x500.X500Principal getSubjectDN();
method public boolean isEncryptionRequired();
}

public static final class AndroidKeyPairGeneratorSpec.Builder {
ctor public AndroidKeyPairGeneratorSpec.Builder(android.content.Context);
method public android.security.AndroidKeyPairGeneratorSpec build();
method public android.security.AndroidKeyPairGeneratorSpec.Builder setAlias(java.lang.String);
method public android.security.AndroidKeyPairGeneratorSpec.Builder setEncryptionRequired();
method public android.security.AndroidKeyPairGeneratorSpec.Builder setEndDate(java.util.Date);
method public android.security.AndroidKeyPairGeneratorSpec.Builder setSerialNumber(java.math.BigInteger);
method public android.security.AndroidKeyPairGeneratorSpec.Builder setStartDate(java.util.Date);
method public android.security.AndroidKeyPairGeneratorSpec.Builder setSubject(javax.security.auth.x500.X500Principal);
}

public final class AndroidKeyStoreParameter implements java.security.KeyStore.ProtectionParameter {
method public boolean isEncryptionRequired();
}

public static final class AndroidKeyStoreParameter.Builder {
ctor public AndroidKeyStoreParameter.Builder(android.content.Context);
method public android.security.AndroidKeyStoreParameter build();
method public android.security.AndroidKeyStoreParameter.Builder setEncryptionRequired();
}

public final class KeyChain {
ctor public KeyChain();
method public static void choosePrivateKeyAlias(android.app.Activity, android.security.KeyChainAliasCallback, java.lang.String[], java.security.Principal[], java.lang.String, int, java.lang.String);
Expand All @@ -21176,6 +21145,37 @@ package android.security {
ctor public KeyChainException(java.lang.Throwable);
}

public final class KeyPairGeneratorSpec implements java.security.spec.AlgorithmParameterSpec {
method public android.content.Context getContext();
method public java.util.Date getEndDate();
method public java.lang.String getKeystoreAlias();
method public java.math.BigInteger getSerialNumber();
method public java.util.Date getStartDate();
method public javax.security.auth.x500.X500Principal getSubjectDN();
method public boolean isEncryptionRequired();
}

public static final class KeyPairGeneratorSpec.Builder {
ctor public KeyPairGeneratorSpec.Builder(android.content.Context);
method public android.security.KeyPairGeneratorSpec build();
method public android.security.KeyPairGeneratorSpec.Builder setAlias(java.lang.String);
method public android.security.KeyPairGeneratorSpec.Builder setEncryptionRequired();
method public android.security.KeyPairGeneratorSpec.Builder setEndDate(java.util.Date);
method public android.security.KeyPairGeneratorSpec.Builder setSerialNumber(java.math.BigInteger);
method public android.security.KeyPairGeneratorSpec.Builder setStartDate(java.util.Date);
method public android.security.KeyPairGeneratorSpec.Builder setSubject(javax.security.auth.x500.X500Principal);
}

public final class KeyStoreParameter implements java.security.KeyStore.ProtectionParameter {
method public boolean isEncryptionRequired();
}

public static final class KeyStoreParameter.Builder {
ctor public KeyStoreParameter.Builder(android.content.Context);
method public android.security.KeyStoreParameter build();
method public android.security.KeyStoreParameter.Builder setEncryptionRequired(boolean);
}

}

package android.service.dreams {
Expand Down
14 changes: 7 additions & 7 deletions keystore/java/android/security/AndroidKeyPairGenerator.java
Expand Up @@ -52,12 +52,12 @@
public class AndroidKeyPairGenerator extends KeyPairGeneratorSpi {
private android.security.KeyStore mKeyStore;

private AndroidKeyPairGeneratorSpec mSpec;
private KeyPairGeneratorSpec mSpec;

/**
* Generate a KeyPair which is backed by the Android keystore service. You
* must call {@link KeyPairGenerator#initialize(AlgorithmParameterSpec)}
* with an {@link AndroidKeyPairGeneratorSpec} as the {@code params}
* with an {@link KeyPairGeneratorSpec} as the {@code params}
* argument before calling this otherwise an {@code IllegalStateException}
* will be thrown.
* <p>
Expand All @@ -73,7 +73,7 @@ public class AndroidKeyPairGenerator extends KeyPairGeneratorSpi {
public KeyPair generateKeyPair() {
if (mKeyStore == null || mSpec == null) {
throw new IllegalStateException(
"Must call initialize with an AndroidKeyPairGeneratorSpec first");
"Must call initialize with an android.security.KeyPairGeneratorSpec first");
}

if (((mSpec.getFlags() & KeyStore.FLAG_ENCRYPTED) != 0)
Expand Down Expand Up @@ -156,13 +156,13 @@ public void initialize(AlgorithmParameterSpec params, SecureRandom random)
throws InvalidAlgorithmParameterException {
if (params == null) {
throw new InvalidAlgorithmParameterException(
"must supply params of type AndroidKeyPairGenericSpec");
} else if (!(params instanceof AndroidKeyPairGeneratorSpec)) {
"must supply params of type android.security.KeyPairGeneratorSpec");
} else if (!(params instanceof KeyPairGeneratorSpec)) {
throw new InvalidAlgorithmParameterException(
"params must be of type AndroidKeyPairGeneratorSpec");
"params must be of type android.security.KeyPairGeneratorSpec");
}

AndroidKeyPairGeneratorSpec spec = (AndroidKeyPairGeneratorSpec) params;
KeyPairGeneratorSpec spec = (KeyPairGeneratorSpec) params;

mSpec = spec;
mKeyStore = android.security.KeyStore.getInstance();
Expand Down
9 changes: 5 additions & 4 deletions keystore/java/android/security/AndroidKeyStore.java
Expand Up @@ -209,7 +209,7 @@ public void engineSetKeyEntry(String alias, Key key, char[] password, Certificat
}

private void setPrivateKeyEntry(String alias, PrivateKey key, Certificate[] chain,
AndroidKeyStoreParameter params) throws KeyStoreException {
KeyStoreParameter params) throws KeyStoreException {
byte[] keyBytes = null;

final String pkeyAlias;
Expand Down Expand Up @@ -544,15 +544,16 @@ public void engineSetEntry(String alias, Entry entry, ProtectionParameter param)
return;
}

if (param != null && !(param instanceof AndroidKeyStoreParameter)) {
throw new KeyStoreException("protParam should be AndroidKeyStoreParameter; was: "
if (param != null && !(param instanceof KeyStoreParameter)) {
throw new KeyStoreException(
"protParam should be android.security.KeyStoreParameter; was: "
+ param.getClass().getName());
}

if (entry instanceof PrivateKeyEntry) {
PrivateKeyEntry prE = (PrivateKeyEntry) entry;
setPrivateKeyEntry(alias, prE.getPrivateKey(), prE.getCertificateChain(),
(AndroidKeyStoreParameter) param);
(KeyStoreParameter) param);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions keystore/java/android/security/AndroidKeyStoreProvider.java
Expand Up @@ -24,7 +24,7 @@
* @hide
*/
public class AndroidKeyStoreProvider extends Provider {
public static final String PROVIDER_NAME = "AndroidKeyStoreProvider";
public static final String PROVIDER_NAME = "AndroidKeyStore";

public AndroidKeyStoreProvider() {
super(PROVIDER_NAME, 1.0, "Android KeyStore security provider");
Expand All @@ -33,6 +33,6 @@ public AndroidKeyStoreProvider() {
put("KeyStore." + AndroidKeyStore.NAME, AndroidKeyStore.class.getName());

// java.security.KeyPairGenerator
put("KeyPairGenerator." + AndroidKeyStore.NAME, AndroidKeyPairGenerator.class.getName());
put("KeyPairGenerator.RSA", AndroidKeyPairGenerator.class.getName());
}
}
Expand Up @@ -29,9 +29,9 @@

/**
* This provides the required parameters needed for initializing the
* {@code KeyPairGenerator} that works with <a href="{@docRoot}
* guide/topics/security/keystore.html">Android KeyStore facility</a>. The
* Android KeyStore facility is accessed through a
* {@code KeyPairGenerator} that works with
* <a href="{@docRoot}guide/topics/security/keystore.html">Android KeyStore
* facility</a>. The Android KeyStore facility is accessed through a
* {@link java.security.KeyPairGenerator} API using the {@code AndroidKeyStore}
* provider. The {@code context} passed in may be used to pop up some UI to ask
* the user to unlock or initialize the Android KeyStore facility.
Expand All @@ -49,7 +49,7 @@
* The self-signed X.509 certificate may be replaced at a later time by a
* certificate signed by a real Certificate Authority.
*/
public final class AndroidKeyPairGeneratorSpec implements AlgorithmParameterSpec {
public final class KeyPairGeneratorSpec implements AlgorithmParameterSpec {
private final String mKeystoreAlias;

private final Context mContext;
Expand Down Expand Up @@ -91,9 +91,9 @@ public final class AndroidKeyPairGeneratorSpec implements AlgorithmParameterSpec
* period
* @throws IllegalArgumentException when any argument is {@code null} or
* {@code endDate} is before {@code startDate}.
* @hide should be built with AndroidKeyPairGeneratorSpecBuilder
* @hide should be built with KeyPairGeneratorSpecBuilder
*/
public AndroidKeyPairGeneratorSpec(Context context, String keyStoreAlias,
public KeyPairGeneratorSpec(Context context, String keyStoreAlias,
X500Principal subjectDN, BigInteger serialNumber, Date startDate, Date endDate,
int flags) {
if (context == null) {
Expand Down Expand Up @@ -184,7 +184,7 @@ public boolean isEncryptionRequired() {
}

/**
* Builder class for {@link AndroidKeyPairGeneratorSpec} objects.
* Builder class for {@link KeyPairGeneratorSpec} objects.
* <p>
* This will build a parameter spec for use with the <a href="{@docRoot}
* guide/topics/security/keystore.html">Android KeyStore facility</a>.
Expand All @@ -198,14 +198,10 @@ public boolean isEncryptionRequired() {
* Calendar end = new Calendar();
* end.add(1, Calendar.YEAR);
*
* AndroidKeyPairGeneratorSpec spec =
* new AndroidKeyPairGeneratorSpec.Builder(mContext)
* .setAlias(&quot;myKey&quot;)
* .setSubject(new X500Principal(&quot;CN=myKey&quot;))
* .setSerial(BigInteger.valueOf(1337))
* .setStartDate(start.getTime())
* .setEndDate(end.getTime())
* .build();
* KeyPairGeneratorSpec spec =
* new KeyPairGeneratorSpec.Builder(mContext).setAlias(&quot;myKey&quot;)
* .setSubject(new X500Principal(&quot;CN=myKey&quot;)).setSerial(BigInteger.valueOf(1337))
* .setStartDate(start.getTime()).setEndDate(end.getTime()).build();
* </pre>
*/
public final static class Builder {
Expand Down Expand Up @@ -309,13 +305,13 @@ public Builder setEncryptionRequired() {
}

/**
* Builds the instance of the {@code AndroidKeyPairGeneratorSpec}.
* Builds the instance of the {@code KeyPairGeneratorSpec}.
*
* @throws IllegalArgumentException if a required field is missing
* @return built instance of {@code AndroidKeyPairGeneratorSpec}
* @return built instance of {@code KeyPairGeneratorSpec}
*/
public AndroidKeyPairGeneratorSpec build() {
return new AndroidKeyPairGeneratorSpec(mContext, mKeystoreAlias, mSubjectDN,
public KeyPairGeneratorSpec build() {
return new KeyPairGeneratorSpec(mContext, mKeystoreAlias, mSubjectDN,
mSerialNumber, mStartDate, mEndDate, mFlags);
}
}
Expand Down
Expand Up @@ -17,7 +17,7 @@
package android.security;

import android.content.Context;
import android.security.AndroidKeyPairGeneratorSpec.Builder;
import android.security.KeyPairGeneratorSpec.Builder;

import java.security.KeyPairGenerator;
import java.security.PrivateKey;
Expand All @@ -26,9 +26,9 @@

/**
* This provides the optional parameters that can be specified for
* {@code KeyStore} entries that work with <a href="{@docRoot}
* guide/topics/security/keystore.html">Android KeyStore facility</a>. The
* Android KeyStore facility is accessed through a
* {@code KeyStore} entries that work with
* <a href="{@docRoot}guide/topics/security/keystore.html">Android KeyStore
* facility</a>. The Android KeyStore facility is accessed through a
* {@link java.security.KeyStore} API using the {@code AndroidKeyStore}
* provider. The {@code context} passed in may be used to pop up some UI to ask
* the user to unlock or initialize the Android KeyStore facility.
Expand All @@ -39,15 +39,15 @@
* {@code KeyStore}.
* <p>
* Keys may be generated using the {@link KeyPairGenerator} facility with a
* {@link AndroidKeyPairGeneratorSpec} to specify the entry's {@code alias}. A
* {@link KeyPairGeneratorSpec} to specify the entry's {@code alias}. A
* self-signed X.509 certificate will be attached to generated entries, but that
* may be replaced at a later time by a certificate signed by a real Certificate
* Authority.
*/
public final class AndroidKeyStoreParameter implements ProtectionParameter {
public final class KeyStoreParameter implements ProtectionParameter {
private int mFlags;

private AndroidKeyStoreParameter(int flags) {
private KeyStoreParameter(int flags) {
mFlags = flags;
}

Expand All @@ -67,19 +67,20 @@ public boolean isEncryptionRequired() {
}

/**
* Builder class for {@link AndroidKeyStoreParameter} objects.
* Builder class for {@link KeyStoreParameter} objects.
* <p>
* This will build protection parameters for use with the <a
* href="{@docRoot} guide/topics/security/keystore.html">Android KeyStore
* This will build protection parameters for use with the
* <a href="{@docRoot}guide/topics/security/keystore.html">Android KeyStore
* facility</a>.
* <p>
* This can be used to require that KeyStore entries be stored encrypted.
* <p>
* Example:
*
* <pre class="prettyprint">
* AndroidKeyStoreParameter params =
* new AndroidKeyStoreParameter.Builder(mContext).setEncryptionRequired().build();
* KeyStoreParameter params = new KeyStoreParameter.Builder(mContext)
* .setEncryptionRequired()
* .build();
* </pre>
*/
public final static class Builder {
Expand All @@ -105,19 +106,23 @@ public Builder(Context context) {
* screen (e.g., PIN, password) before creating or using the generated
* key is successful.
*/
public Builder setEncryptionRequired() {
mFlags |= KeyStore.FLAG_ENCRYPTED;
public Builder setEncryptionRequired(boolean required) {
if (required) {
mFlags |= KeyStore.FLAG_ENCRYPTED;
} else {
mFlags &= ~KeyStore.FLAG_ENCRYPTED;
}
return this;
}

/**
* Builds the instance of the {@code AndroidKeyPairGeneratorSpec}.
* Builds the instance of the {@code KeyPairGeneratorSpec}.
*
* @throws IllegalArgumentException if a required field is missing
* @return built instance of {@code AndroidKeyPairGeneratorSpec}
* @return built instance of {@code KeyPairGeneratorSpec}
*/
public AndroidKeyStoreParameter build() {
return new AndroidKeyStoreParameter(mFlags);
public KeyStoreParameter build() {
return new KeyStoreParameter(mFlags);
}
}
}

0 comments on commit 1c219f6

Please sign in to comment.