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