OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.test.util; | 5 package org.chromium.net.test.util; |
6 | 6 |
7 import android.util.Base64; | 7 import android.util.Base64; |
8 | 8 |
9 import org.chromium.base.PathUtils; | 9 import org.chromium.base.test.util.UrlUtils; |
10 | 10 |
11 import java.io.BufferedReader; | 11 import java.io.BufferedReader; |
12 import java.io.FileReader; | 12 import java.io.FileReader; |
13 import java.io.IOException; | 13 import java.io.IOException; |
14 import java.security.MessageDigest; | 14 import java.security.MessageDigest; |
15 import java.security.NoSuchAlgorithmException; | 15 import java.security.NoSuchAlgorithmException; |
16 import java.security.cert.Certificate; | 16 import java.security.cert.Certificate; |
17 | 17 |
18 /** | 18 /** |
19 * Certificate related utility methods. | 19 * Certificate related utility methods. |
20 */ | 20 */ |
21 public class CertTestUtil { | 21 public class CertTestUtil { |
22 /** | 22 /** |
23 * The location of the directory that contains certificates for testing. | 23 * The location of the directory that contains certificates for testing. |
24 */ | 24 */ |
25 public static final String CERTS_DIRECTORY = | 25 public static final String CERTS_DIRECTORY = |
26 PathUtils.getExternalStorageDirectory() + "/net/data/ssl/certificate
s/"; | 26 UrlUtils.getIsolatedTestFilePath("net/data/ssl/certificates/"); |
27 | 27 |
28 private static final String BEGIN_MARKER = "-----BEGIN CERTIFICATE-----"; | 28 private static final String BEGIN_MARKER = "-----BEGIN CERTIFICATE-----"; |
29 private static final String END_MARKER = "-----END CERTIFICATE-----"; | 29 private static final String END_MARKER = "-----END CERTIFICATE-----"; |
30 | 30 |
31 private CertTestUtil() {} | 31 private CertTestUtil() {} |
32 | 32 |
33 /** | 33 /** |
34 * Converts a PEM formatted cert in a given file to the binary DER format. | 34 * Converts a PEM formatted cert in a given file to the binary DER format. |
35 * | 35 * |
36 * @param pemPathname the location of the certificate to convert. | 36 * @param pemPathname the location of the certificate to convert. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 try { | 68 try { |
69 byte[] publicKey = cert.getPublicKey().getEncoded(); | 69 byte[] publicKey = cert.getPublicKey().getEncoded(); |
70 MessageDigest digest = MessageDigest.getInstance("SHA-256"); | 70 MessageDigest digest = MessageDigest.getInstance("SHA-256"); |
71 return digest.digest(publicKey); | 71 return digest.digest(publicKey); |
72 } catch (NoSuchAlgorithmException ex) { | 72 } catch (NoSuchAlgorithmException ex) { |
73 // This exception should never happen since SHA-256 is known algorit
hm | 73 // This exception should never happen since SHA-256 is known algorit
hm |
74 throw new RuntimeException(ex); | 74 throw new RuntimeException(ex); |
75 } | 75 } |
76 } | 76 } |
77 } | 77 } |
OLD | NEW |