[email protected] | b47feba | 2012-04-24 01:34:41 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 6dbdaa8 | 2011-08-11 16:05:56 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef NET_ANDROID_NETWORK_LIBRARY_H_ |
| 6 | #define NET_ANDROID_NETWORK_LIBRARY_H_ |
[email protected] | 6dbdaa8 | 2011-08-11 16:05:56 | [diff] [blame] | 7 | |
| 8 | #include <jni.h> |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 9 | #include <stddef.h> |
wtc | 69f8ea8 | 2015-06-04 00:08:13 | [diff] [blame] | 10 | #include <stdint.h> |
Paul Jensen | ec3c1112 | 2017-11-28 16:48:38 | [diff] [blame] | 11 | #include <sys/types.h> |
[email protected] | 6dbdaa8 | 2011-08-11 16:05:56 | [diff] [blame] | 12 | |
| 13 | #include <string> |
| 14 | #include <vector> |
| 15 | |
[email protected] | 71f4b27 | 2013-02-13 19:13:49 | [diff] [blame] | 16 | #include "net/android/cert_verify_result_android.h" |
pauljensen | f3ef7a58 | 2017-01-10 16:14:50 | [diff] [blame] | 17 | #include "net/base/ip_endpoint.h" |
[email protected] | 3b45550 | 2012-12-11 18:22:58 | [diff] [blame] | 18 | #include "net/base/mime_util.h" |
[email protected] | be363b2 | 2012-11-01 17:38:47 | [diff] [blame] | 19 | #include "net/base/net_export.h" |
Paul Jensen | ec3c1112 | 2017-11-28 16:48:38 | [diff] [blame] | 20 | #include "net/socket/socket_descriptor.h" |
[email protected] | 6dbdaa8 | 2011-08-11 16:05:56 | [diff] [blame] | 21 | |
| 22 | namespace net { |
| 23 | namespace android { |
| 24 | |
[email protected] | 6dbdaa8 | 2011-08-11 16:05:56 | [diff] [blame] | 25 | // |cert_chain| is DER encoded chain of certificates, with the server's own |
| 26 | // certificate listed first. |
[email protected] | b47feba | 2012-04-24 01:34:41 | [diff] [blame] | 27 | // |auth_type| is as per the Java X509Certificate.checkServerTrusted method. |
[email protected] | 23073f9 | 2014-01-17 22:52:17 | [diff] [blame] | 28 | void VerifyX509CertChain(const std::vector<std::string>& cert_chain, |
| 29 | const std::string& auth_type, |
| 30 | const std::string& host, |
| 31 | CertVerifyStatusAndroid* status, |
| 32 | bool* is_issued_by_known_root, |
| 33 | std::vector<std::string>* verified_chain); |
[email protected] | 6dbdaa8 | 2011-08-11 16:05:56 | [diff] [blame] | 34 | |
[email protected] | 87ccb99 | 2012-12-12 01:31:55 | [diff] [blame] | 35 | // Adds a certificate as a root trust certificate to the trust manager. |
| 36 | // |cert| is DER encoded certificate, |len| is its length in bytes. |
wtc | 69f8ea8 | 2015-06-04 00:08:13 | [diff] [blame] | 37 | void AddTestRootCertificate(const uint8_t* cert, size_t len); |
[email protected] | 87ccb99 | 2012-12-12 01:31:55 | [diff] [blame] | 38 | |
| 39 | // Removes all root certificates added by |AddTestRootCertificate| calls. |
| 40 | void ClearTestRootCertificates(); |
| 41 | |
mgersh | d21d6d14 | 2016-12-14 23:06:36 | [diff] [blame] | 42 | // Returns true if cleartext traffic to |host| is allowed by the app. Always |
| 43 | // true on L and older. |
| 44 | bool IsCleartextPermitted(const std::string& host); |
| 45 | |
[email protected] | c470e1b | 2012-06-15 07:46:39 | [diff] [blame] | 46 | // Returns true if it can determine that only loopback addresses are configured. |
| 47 | // i.e. if only 127.0.0.1 and ::1 are routable. |
| 48 | // Also returns false if it cannot determine this. |
| 49 | bool HaveOnlyLoopbackAddresses(); |
| 50 | |
[email protected] | 6dbdaa8 | 2011-08-11 16:05:56 | [diff] [blame] | 51 | // Get the mime type (if any) that is associated with the file extension. |
| 52 | // Returns true if a corresponding mime type exists. |
| 53 | bool GetMimeTypeFromExtension(const std::string& extension, |
| 54 | std::string* result); |
| 55 | |
[email protected] | 74d9c524 | 2014-05-01 05:10:03 | [diff] [blame] | 56 | // Returns the ISO country code equivalent of the current MCC (mobile country |
| 57 | // code). |
| 58 | NET_EXPORT std::string GetTelephonyNetworkCountryIso(); |
| 59 | |
| 60 | // Returns MCC+MNC (mobile country code + mobile network code) as |
| 61 | // the numeric name of the current registered operator. |
| 62 | NET_EXPORT std::string GetTelephonyNetworkOperator(); |
| 63 | |
tbansal | a2e9f20c | 2015-09-03 20:05:08 | [diff] [blame] | 64 | // Returns MCC+MNC (mobile country code + mobile network code) as |
| 65 | // the numeric name of the current SIM operator. |
| 66 | NET_EXPORT std::string GetTelephonySimOperator(); |
| 67 | |
| 68 | // Returns true if the device is roaming on the currently active network. When |
| 69 | // true, it suggests that use of data may incur extra costs. |
| 70 | NET_EXPORT bool GetIsRoaming(); |
| 71 | |
tbansal | a7581d8 | 2016-11-24 18:00:33 | [diff] [blame] | 72 | // Returns true if the system's captive portal probe was blocked for the current |
| 73 | // default data network. The method will return false if the captive portal |
| 74 | // probe was not blocked, the login process to the captive portal has been |
| 75 | // successfully completed, or if the captive portal status can't be determined. |
| 76 | // Requires ACCESS_NETWORK_STATE permission. Only available on Android |
| 77 | // Marshmallow and later versions. Returns false on earlier versions. |
| 78 | NET_EXPORT bool GetIsCaptivePortal(); |
| 79 | |
tbansal | c5a1c91 | 2016-07-01 22:11:56 | [diff] [blame] | 80 | // Gets the SSID of the currently associated WiFi access point if there is one. |
| 81 | // Otherwise, returns empty string. |
| 82 | NET_EXPORT_PRIVATE std::string GetWifiSSID(); |
| 83 | |
pauljensen | f3ef7a58 | 2017-01-10 16:14:50 | [diff] [blame] | 84 | // Gets the DNS servers and puts them in |dns_servers|. |
| 85 | // Only callable on Marshmallow and newer releases. |
| 86 | NET_EXPORT_PRIVATE void GetDnsServers(std::vector<IPEndPoint>* dns_servers); |
| 87 | |
Paul Jensen | ec3c1112 | 2017-11-28 16:48:38 | [diff] [blame] | 88 | // Apply TrafficStats tag |tag| and UID |uid| to |socket|. Future network |
| 89 | // traffic used by |socket| will be attributed to |uid| and |tag|. |
| 90 | NET_EXPORT_PRIVATE void TagSocket(SocketDescriptor socket, |
| 91 | uid_t uid, |
| 92 | int32_t tag); |
| 93 | |
[email protected] | 6dbdaa8 | 2011-08-11 16:05:56 | [diff] [blame] | 94 | } // namespace android |
| 95 | } // namespace net |
| 96 | |
| 97 | #endif // NET_ANDROID_NETWORK_LIBRARY_H_ |