diff options
author | Kenny Root <kroot@google.com> | 2014-04-30 17:03:11 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-04-30 17:03:11 +0000 |
commit | d3d58171cc734f59faa5a03ce1cd5d5c00e9ffbd (patch) | |
tree | ac781fb6377a03dfa58a0b7801f076d28bbedbd4 /luni/src/main/java/org | |
parent | e0350a80cbcce86445c29c043ab5be3b46e28181 (diff) | |
parent | 2bc5e811a817a8c667bca4318ae98582b0ee6dc6 (diff) | |
download | libcore-d3d58171cc734f59faa5a03ce1cd5d5c00e9ffbd.zip libcore-d3d58171cc734f59faa5a03ce1cd5d5c00e9ffbd.tar.gz libcore-d3d58171cc734f59faa5a03ce1cd5d5c00e9ffbd.tar.bz2 |
am 2bc5e811: Add API to check certificate chain signatures
* commit '2bc5e811a817a8c667bca4318ae98582b0ee6dc6':
Add API to check certificate chain signatures
Diffstat (limited to 'luni/src/main/java/org')
-rw-r--r-- | luni/src/main/java/org/apache/harmony/security/utils/JarUtils.java | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/luni/src/main/java/org/apache/harmony/security/utils/JarUtils.java b/luni/src/main/java/org/apache/harmony/security/utils/JarUtils.java index f6efb8a..de3cdea 100644 --- a/luni/src/main/java/org/apache/harmony/security/utils/JarUtils.java +++ b/luni/src/main/java/org/apache/harmony/security/utils/JarUtils.java @@ -52,18 +52,27 @@ public class JarUtils { new int[] {1, 2, 840, 113549, 1, 9, 4}; /** + * @see #verifySignature(InputStream, InputStream, boolean) + */ + public static Certificate[] verifySignature(InputStream signature, InputStream signatureBlock) + throws IOException, GeneralSecurityException { + return verifySignature(signature, signatureBlock, false); + } + + /** * This method handle all the work with PKCS7, ASN1 encoding, signature verifying, * and certification path building. * See also PKCS #7: Cryptographic Message Syntax Standard: * http://www.ietf.org/rfc/rfc2315.txt * @param signature - the input stream of signature file to be verified * @param signatureBlock - the input stream of corresponding signature block file + * @param chainCheck - whether to validate certificate chain signatures * @return array of certificates used to verify the signature file * @throws IOException - if some errors occurs during reading from the stream * @throws GeneralSecurityException - if signature verification process fails */ public static Certificate[] verifySignature(InputStream signature, InputStream - signatureBlock) throws IOException, GeneralSecurityException { + signatureBlock, boolean chainCheck) throws IOException, GeneralSecurityException { BerInputStream bis = new BerInputStream(signatureBlock); ContentInfo info = (ContentInfo)ContentInfo.ASN1.decode(bis); @@ -171,10 +180,11 @@ public class JarUtils { throw new SecurityException("Incorrect signature"); } - return createChain(certs[issuerSertIndex], certs); + return createChain(certs[issuerSertIndex], certs, chainCheck); } - private static X509Certificate[] createChain(X509Certificate signer, X509Certificate[] candidates) { + private static X509Certificate[] createChain(X509Certificate signer, + X509Certificate[] candidates, boolean chainCheck) { LinkedList chain = new LinkedList(); chain.add(0, signer); @@ -185,9 +195,10 @@ public class JarUtils { Principal issuer = signer.getIssuerDN(); X509Certificate issuerCert; + X509Certificate subjectCert = signer; int count = 1; while (true) { - issuerCert = findCert(issuer, candidates); + issuerCert = findCert(issuer, candidates, subjectCert, chainCheck); if( issuerCert == null) { break; } @@ -197,13 +208,22 @@ public class JarUtils { break; } issuer = issuerCert.getIssuerDN(); + subjectCert = issuerCert; } return (X509Certificate[])chain.toArray(new X509Certificate[count]); } - private static X509Certificate findCert(Principal issuer, X509Certificate[] candidates) { + private static X509Certificate findCert(Principal issuer, X509Certificate[] candidates, + X509Certificate subjectCert, boolean chainCheck) { for (int i = 0; i < candidates.length; i++) { if (issuer.equals(candidates[i].getSubjectDN())) { + if (chainCheck) { + try { + subjectCert.verify(candidates[i].getPublicKey()); + } catch (Exception e) { + continue; + } + } return candidates[i]; } } |