Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: net/android/javatests/src/org/chromium/net/X509UtilTest.java

Issue 27500004: Listen for new system certificates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Re-upload Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.net; 5 package org.chromium.net;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.Intent; 8 import android.content.Intent;
9 import android.net.ConnectivityManager; 9 import android.net.ConnectivityManager;
10 import android.telephony.TelephonyManager; 10 import android.telephony.TelephonyManager;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 64
65 private static byte[] readFileBytes(String pathname) throws IOException { 65 private static byte[] readFileBytes(String pathname) throws IOException {
66 RandomAccessFile file = new RandomAccessFile(pathname, "r"); 66 RandomAccessFile file = new RandomAccessFile(pathname, "r");
67 byte[] bytes = new byte[(int) file.length()]; 67 byte[] bytes = new byte[(int) file.length()];
68 int bytesRead = file.read(bytes); 68 int bytesRead = file.read(bytes);
69 if (bytesRead != bytes.length) 69 if (bytesRead != bytes.length)
70 return Arrays.copyOfRange(bytes, 0, bytesRead); 70 return Arrays.copyOfRange(bytes, 0, bytesRead);
71 return bytes; 71 return bytes;
72 } 72 }
73 73
74 private Context GetContext() {
75 return getInstrumentation().getContext();
76 }
77
74 @MediumTest 78 @MediumTest
75 public void testEkusVerified() throws GeneralSecurityException, IOException { 79 public void testEkusVerified() throws GeneralSecurityException, IOException {
76 X509Util.addTestRootCertificate(pemToDer(CERTS_DIRECTORY + BAD_EKU_TEST_ ROOT)); 80 X509Util.addTestRootCertificate(GetContext(),
77 X509Util.addTestRootCertificate(pemToDer(CERTS_DIRECTORY + GOOD_ROOT_CA) ); 81 pemToDer(CERTS_DIRECTORY + BAD_EKU_TEST_ ROOT));
82 X509Util.addTestRootCertificate(GetContext(),
83 pemToDer(CERTS_DIRECTORY + GOOD_ROOT_CA) );
78 84
79 assertFalse(X509Util.verifyKeyUsage( 85 assertFalse(X509Util.verifyKeyUsage(
80 X509Util.createCertificateFromBytes( 86 X509Util.createCertificateFromBytes(
87 GetContext(),
81 pemToDer(CERTS_DIRECTORY + CRITICAL_CODE_SIGNING_EE)))); 88 pemToDer(CERTS_DIRECTORY + CRITICAL_CODE_SIGNING_EE))));
82 89
83 assertFalse(X509Util.verifyKeyUsage( 90 assertFalse(X509Util.verifyKeyUsage(
84 X509Util.createCertificateFromBytes( 91 X509Util.createCertificateFromBytes(
92 GetContext(),
85 pemToDer(CERTS_DIRECTORY + NON_CRITICAL_CODE_SIGNING_EE)))); 93 pemToDer(CERTS_DIRECTORY + NON_CRITICAL_CODE_SIGNING_EE))));
86 94
87 assertFalse(X509Util.verifyKeyUsage( 95 assertFalse(X509Util.verifyKeyUsage(
88 X509Util.createCertificateFromBytes( 96 X509Util.createCertificateFromBytes(
97 GetContext(),
89 readFileBytes(CERTS_DIRECTORY + WEB_CLIENT_AUTH_EE)))); 98 readFileBytes(CERTS_DIRECTORY + WEB_CLIENT_AUTH_EE))));
90 99
91 assertTrue(X509Util.verifyKeyUsage( 100 assertTrue(X509Util.verifyKeyUsage(
92 X509Util.createCertificateFromBytes( 101 X509Util.createCertificateFromBytes(
102 GetContext(),
93 pemToDer(CERTS_DIRECTORY + OK_CERT)))); 103 pemToDer(CERTS_DIRECTORY + OK_CERT))));
94 104
95 try { 105 try {
96 X509Util.clearTestRootCertificates(); 106 X509Util.clearTestRootCertificates(GetContext());
97 } catch (Exception e) { 107 } catch (Exception e) {
98 fail("Could not clear test root certificates: " + e.toString()); 108 fail("Could not clear test root certificates: " + e.toString());
99 } 109 }
100 } 110 }
101 } 111 }
102 112
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698