diff options
author | Brian Carlstrom <bdc@google.com> | 2012-09-04 23:01:07 -0700 |
---|---|---|
committer | Brian Carlstrom <bdc@google.com> | 2012-09-12 10:01:00 -0700 |
commit | 0efca17105d112a0ff568602831b22bdafa00433 (patch) | |
tree | 5a4a8a7cf4d0f4884a75ec7d4b4ecb27bc5a0ad8 /keystore | |
parent | bd0fe8783407bc760b8e9a9952cb96a600d26ea9 (diff) | |
download | frameworks_base-0efca17105d112a0ff568602831b22bdafa00433.zip frameworks_base-0efca17105d112a0ff568602831b22bdafa00433.tar.gz frameworks_base-0efca17105d112a0ff568602831b22bdafa00433.tar.bz2 |
Tracking upgrade to bouncycastle 1.47
Change-Id: I4a3c508c5e65dd46a2df22935b5351092550fad5
Diffstat (limited to 'keystore')
-rw-r--r-- | keystore/java/android/security/Credentials.java | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/keystore/java/android/security/Credentials.java b/keystore/java/android/security/Credentials.java index b233ff6..d8109ce 100644 --- a/keystore/java/android/security/Credentials.java +++ b/keystore/java/android/security/Credentials.java @@ -20,8 +20,9 @@ import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.util.Log; -import com.android.org.bouncycastle.openssl.PEMReader; -import com.android.org.bouncycastle.openssl.PEMWriter; +import com.android.org.bouncycastle.util.io.pem.PemObject; +import com.android.org.bouncycastle.util.io.pem.PemReader; +import com.android.org.bouncycastle.util.io.pem.PemWriter; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -32,6 +33,10 @@ import java.io.Reader; import java.io.Writer; import java.nio.charset.Charsets; import java.security.KeyPair; +import java.security.cert.Certificate; +import java.security.cert.CertificateEncodingException; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.List; @@ -108,34 +113,41 @@ public class Credentials { public static final String EXTRA_CA_CERTIFICATES_DATA = "ca_certificates_data"; /** - * Convert objects to a PEM format, which is used for - * CA_CERTIFICATE, USER_CERTIFICATE, and USER_PRIVATE_KEY - * entries. + * Convert objects to a PEM format which is used for + * CA_CERTIFICATE and USER_CERTIFICATE entries. */ - public static byte[] convertToPem(Object... objects) throws IOException { + public static byte[] convertToPem(Certificate... objects) + throws IOException, CertificateEncodingException { ByteArrayOutputStream bao = new ByteArrayOutputStream(); Writer writer = new OutputStreamWriter(bao, Charsets.US_ASCII); - PEMWriter pw = new PEMWriter(writer); - for (Object o : objects) { - pw.writeObject(o); + PemWriter pw = new PemWriter(writer); + for (Certificate o : objects) { + pw.writeObject(new PemObject("CERTIFICATE", o.getEncoded())); } pw.close(); return bao.toByteArray(); } /** * Convert objects from PEM format, which is used for - * CA_CERTIFICATE, USER_CERTIFICATE, and USER_PRIVATE_KEY - * entries. + * CA_CERTIFICATE and USER_CERTIFICATE entries. */ - public static List<Object> convertFromPem(byte[] bytes) throws IOException { + public static List<X509Certificate> convertFromPem(byte[] bytes) + throws IOException, CertificateException { ByteArrayInputStream bai = new ByteArrayInputStream(bytes); Reader reader = new InputStreamReader(bai, Charsets.US_ASCII); - PEMReader pr = new PEMReader(reader); - - List<Object> result = new ArrayList<Object>(); - Object o; - while ((o = pr.readObject()) != null) { - result.add(o); + 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; |