summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenny Root <kroot@google.com>2015-02-27 12:19:58 -0800
committerKenny Root <kroot@google.com>2015-02-27 12:20:00 -0800
commitbd0455bd920b3e06cef4a420d5087996c896603a (patch)
treed89a573ffc87d34f5d0d6cd8e6fef124c66d8dca
parent450c5ad6a6efc16de0383f5aecdfdeac2736ca30 (diff)
downloadgoogle-tv-pairing-protocol-bd0455bd920b3e06cef4a420d5087996c896603a.tar.gz
Update for removed BC API
Bouncycastle removed the API used in this code to compute SubjectKeyIdentifier from a PublicKey. Add in the analog code to do this for us. Bug: 19268019 Change-Id: Id522b557d4b66b8098330709f1d171bd6d742160
-rw-r--r--java/src/com/google/polo/ssl/SslUtil.java20
1 files changed, 19 insertions, 1 deletions
diff --git a/java/src/com/google/polo/ssl/SslUtil.java b/java/src/com/google/polo/ssl/SslUtil.java
index e575770..899c4d9 100644
--- a/java/src/com/google/polo/ssl/SslUtil.java
+++ b/java/src/com/google/polo/ssl/SslUtil.java
@@ -40,6 +40,7 @@ import java.security.GeneralSecurityException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.KeyStore;
+import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.cert.Certificate;
@@ -178,7 +179,7 @@ public class SslUtil {
certGen.addExtension(X509Extensions.AuthorityKeyIdentifier, true,
authIdentifier);
certGen.addExtension(X509Extensions.SubjectKeyIdentifier, true,
- SubjectKeyIdentifier.getInstance(pair.getPublic().getEncoded()));
+ createSubjectKeyIdentifier(pair.getPublic()));
certGen.addExtension(X509Extensions.SubjectAlternativeName, false, new GeneralNames(
new GeneralName(GeneralName.rfc822Name, "android-tv-remote-support@google.com")));
@@ -221,6 +222,23 @@ public class SslUtil {
}
/**
+ * Creates a SubjectKeyIdentifier from a public key.
+ * <p>
+ * @param publicKey the public key
+ * @return a new {@link SubjectKeyIdentifier}
+ */
+ static SubjectKeyIdentifier createSubjectKeyIdentifier(PublicKey publicKey) {
+ SubjectPublicKeyInfo info = SubjectPublicKeyInfo.getInstance(publicKey.getEncoded());
+ MessageDigest digester;
+ try {
+ digester = MessageDigest.getInstance("SHA-1");
+ } catch (NoSuchAlgorithmException e) {
+ throw new RuntimeException("Could not get SHA-1 digest instance");
+ }
+ return new SubjectKeyIdentifier(digester.digest(info.getPublicKeyData().getBytes()));
+ }
+
+ /**
* Wrapper for {@link SslUtil#generateX509V3Certificate(KeyPair, String, Date, Date, BigInteger)}
* which uses a default validity period and serial number.
* <p>