OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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.ActivityNotFoundException; | 7 import android.content.ActivityNotFoundException; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.content.Intent; | 9 import android.content.Intent; |
10 import android.content.IntentFilter; | 10 import android.content.IntentFilter; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 58 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
59 context.startActivity(intent); | 59 context.startActivity(intent); |
60 return true; | 60 return true; |
61 } catch (ActivityNotFoundException e) { | 61 } catch (ActivityNotFoundException e) { |
62 Log.w(TAG, "could not store key pair: " + e); | 62 Log.w(TAG, "could not store key pair: " + e); |
63 } | 63 } |
64 return false; | 64 return false; |
65 } | 65 } |
66 | 66 |
67 /** | 67 /** |
68 * Adds a cryptographic file (User certificate, a CA certificate or | |
69 * PKCS#12 keychain) through the system's CertInstaller activity. | |
70 * | |
71 * @param context current application context. | |
72 * @param certType cryptographic file type. E.g. CertificateMimeType.X509_U
SER_CERT | |
73 * @param data certificate/keychain data bytes. | |
74 * @return true on success, false on failure. | |
75 * | |
76 * Note that failure only indicates that the function couldn't launch the | |
77 * CertInstaller activity, not that the certificate/keychain was properly | |
78 * installed to the keystore. | |
79 */ | |
80 @CalledByNative | |
81 public static boolean storeCertificate(Context context, int certType, byte[]
data) { | |
82 try { | |
83 Intent intent = KeyChain.createInstallIntent(); | |
84 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
85 | |
86 switch (certType) { | |
87 case CertificateMimeType.X509_USER_CERT: | |
88 case CertificateMimeType.X509_CA_CERT: | |
89 intent.putExtra(KeyChain.EXTRA_CERTIFICATE, data); | |
90 break; | |
91 | |
92 case CertificateMimeType.PKCS12_ARCHIVE: | |
93 intent.putExtra(KeyChain.EXTRA_PKCS12, data); | |
94 break; | |
95 | |
96 default: | |
97 Log.w(TAG, "invalid certificate type: " + certType); | |
98 return false; | |
99 } | |
100 context.startActivity(intent); | |
101 return true; | |
102 } catch (ActivityNotFoundException e) { | |
103 Log.w(TAG, "could not store crypto file: " + e); | |
104 } | |
105 return false; | |
106 } | |
107 | |
108 /** | |
109 * @return the mime type (if any) that is associated with the file | 68 * @return the mime type (if any) that is associated with the file |
110 * extension. Returns null if no corresponding mime type exists. | 69 * extension. Returns null if no corresponding mime type exists. |
111 */ | 70 */ |
112 @CalledByNative | 71 @CalledByNative |
113 public static String getMimeTypeFromExtension(String extension) { | 72 public static String getMimeTypeFromExtension(String extension) { |
114 return URLConnection.guessContentTypeFromName("foo." + extension); | 73 return URLConnection.guessContentTypeFromName("foo." + extension); |
115 } | 74 } |
116 | 75 |
117 /** | 76 /** |
118 * @return true if it can determine that only loopback addresses are | 77 * @return true if it can determine that only loopback addresses are |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 if (wifiInfo != null) { | 208 if (wifiInfo != null) { |
250 final String ssid = wifiInfo.getSSID(); | 209 final String ssid = wifiInfo.getSSID(); |
251 if (ssid != null) { | 210 if (ssid != null) { |
252 return ssid; | 211 return ssid; |
253 } | 212 } |
254 } | 213 } |
255 } | 214 } |
256 return ""; | 215 return ""; |
257 } | 216 } |
258 } | 217 } |
OLD | NEW |