summaryrefslogtreecommitdiffstats
path: root/keystore/java/android/security/KeyPairGeneratorSpec.java
diff options
context:
space:
mode:
authorAlex Klyubin <klyubin@google.com>2015-04-14 20:43:54 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-04-14 20:43:54 +0000
commit8e5fbc70e19c5e294e8f99939161e1a8ff78bd6f (patch)
treecec813fa6b240b7d80a6c4f81dce84e94865816e /keystore/java/android/security/KeyPairGeneratorSpec.java
parent1740c625c6b2b39d6b35d08a7bd362ea907cf082 (diff)
parentfa2bd4fe5c10b8132a155f0f8d0207435ca2c8dc (diff)
downloadframeworks_base-8e5fbc70e19c5e294e8f99939161e1a8ff78bd6f.zip
frameworks_base-8e5fbc70e19c5e294e8f99939161e1a8ff78bd6f.tar.gz
frameworks_base-8e5fbc70e19c5e294e8f99939161e1a8ff78bd6f.tar.bz2
am fa2bd4fe: am 888f5cb7: am ecfda064: Merge "Make specifying self-signed cert parameters optional."
* commit 'fa2bd4fe5c10b8132a155f0f8d0207435ca2c8dc': Make specifying self-signed cert parameters optional.
Diffstat (limited to 'keystore/java/android/security/KeyPairGeneratorSpec.java')
-rw-r--r--keystore/java/android/security/KeyPairGeneratorSpec.java48
1 files changed, 38 insertions, 10 deletions
diff --git a/keystore/java/android/security/KeyPairGeneratorSpec.java b/keystore/java/android/security/KeyPairGeneratorSpec.java
index e297d26..5e5cf37 100644
--- a/keystore/java/android/security/KeyPairGeneratorSpec.java
+++ b/keystore/java/android/security/KeyPairGeneratorSpec.java
@@ -52,6 +52,11 @@ import javax.security.auth.x500.X500Principal;
*/
public final class KeyPairGeneratorSpec implements AlgorithmParameterSpec {
+ private static final X500Principal DEFAULT_CERT_SUBJECT = new X500Principal("CN=fake");
+ private static final BigInteger DEFAULT_CERT_SERIAL_NUMBER = new BigInteger("1");
+ private static final Date DEFAULT_CERT_NOT_BEFORE = new Date(0L); // Jan 1 1970
+ private static final Date DEFAULT_CERT_NOT_AFTER = new Date(2461449600000L); // Jan 1 2048
+
private final Context mContext;
private final String mKeystoreAlias;
@@ -147,22 +152,29 @@ public final class KeyPairGeneratorSpec implements AlgorithmParameterSpec {
throw new IllegalArgumentException("context == null");
} else if (TextUtils.isEmpty(keyStoreAlias)) {
throw new IllegalArgumentException("keyStoreAlias must not be empty");
- } else if (subjectDN == null) {
- throw new IllegalArgumentException("subjectDN == null");
- } else if (serialNumber == null) {
- throw new IllegalArgumentException("serialNumber == null");
- } else if (startDate == null) {
- throw new IllegalArgumentException("startDate == null");
- } else if (endDate == null) {
- throw new IllegalArgumentException("endDate == null");
- } else if (endDate.before(startDate)) {
- throw new IllegalArgumentException("endDate < startDate");
} else if ((userAuthenticationValidityDurationSeconds < 0)
&& (userAuthenticationValidityDurationSeconds != -1)) {
throw new IllegalArgumentException(
"userAuthenticationValidityDurationSeconds must not be negative");
}
+ if (subjectDN == null) {
+ subjectDN = DEFAULT_CERT_SUBJECT;
+ }
+ if (startDate == null) {
+ startDate = DEFAULT_CERT_NOT_BEFORE;
+ }
+ if (endDate == null) {
+ endDate = DEFAULT_CERT_NOT_AFTER;
+ }
+ if (serialNumber == null) {
+ serialNumber = DEFAULT_CERT_SERIAL_NUMBER;
+ }
+
+ if (endDate.before(startDate)) {
+ throw new IllegalArgumentException("endDate < startDate");
+ }
+
mContext = context;
mKeystoreAlias = keyStoreAlias;
mKeyType = keyType;
@@ -556,6 +568,10 @@ public final class KeyPairGeneratorSpec implements AlgorithmParameterSpec {
/**
* Sets the subject used for the self-signed certificate of the
* generated key pair.
+ *
+ * <p>The subject must be specified on API Level
+ * {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1 LOLLIPOP_MR1} and older platforms. On
+ * newer platforms the subject defaults to {@code CN=fake} if not specified.
*/
public Builder setSubject(X500Principal subject) {
if (subject == null) {
@@ -568,6 +584,10 @@ public final class KeyPairGeneratorSpec implements AlgorithmParameterSpec {
/**
* Sets the serial number used for the self-signed certificate of the
* generated key pair.
+ *
+ * <p>The serial number must be specified on API Level
+ * {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1 LOLLIPOP_MR1} and older platforms. On
+ * newer platforms the serial number defaults to {@code 1} if not specified.
*/
public Builder setSerialNumber(BigInteger serialNumber) {
if (serialNumber == null) {
@@ -580,6 +600,10 @@ public final class KeyPairGeneratorSpec implements AlgorithmParameterSpec {
/**
* Sets the start of the validity period for the self-signed certificate
* of the generated key pair.
+ *
+ * <p>The date must be specified on API Level
+ * {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1 LOLLIPOP_MR1} and older platforms. On
+ * newer platforms the date defaults to {@code Jan 1 1970} if not specified.
*/
public Builder setStartDate(Date startDate) {
if (startDate == null) {
@@ -592,6 +616,10 @@ public final class KeyPairGeneratorSpec implements AlgorithmParameterSpec {
/**
* Sets the end of the validity period for the self-signed certificate
* of the generated key pair.
+ *
+ * <p>The date must be specified on API Level
+ * {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1 LOLLIPOP_MR1} and older platforms. On
+ * newer platforms the date defaults to {@code Jan 1 2048} if not specified.
*/
public Builder setEndDate(Date endDate) {
if (endDate == null) {