[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> |
[email protected] | 6dbdaa8 | 2011-08-11 16:05:56 | [diff] [blame] | 11 | |
| 12 | #include <string> |
| 13 | #include <vector> |
| 14 | |
[email protected] | 71f4b27 | 2013-02-13 19:13:49 | [diff] [blame] | 15 | #include "net/android/cert_verify_result_android.h" |
[email protected] | 3b45550 | 2012-12-11 18:22:58 | [diff] [blame] | 16 | #include "net/base/mime_util.h" |
[email protected] | be363b2 | 2012-11-01 17:38:47 | [diff] [blame] | 17 | #include "net/base/net_export.h" |
[email protected] | 6dbdaa8 | 2011-08-11 16:05:56 | [diff] [blame] | 18 | |
| 19 | namespace net { |
| 20 | namespace android { |
| 21 | |
[email protected] | 6dbdaa8 | 2011-08-11 16:05:56 | [diff] [blame] | 22 | // |cert_chain| is DER encoded chain of certificates, with the server's own |
| 23 | // certificate listed first. |
[email protected] | b47feba | 2012-04-24 01:34:41 | [diff] [blame] | 24 | // |auth_type| is as per the Java X509Certificate.checkServerTrusted method. |
[email protected] | 23073f9 | 2014-01-17 22:52:17 | [diff] [blame] | 25 | void VerifyX509CertChain(const std::vector<std::string>& cert_chain, |
| 26 | const std::string& auth_type, |
| 27 | const std::string& host, |
| 28 | CertVerifyStatusAndroid* status, |
| 29 | bool* is_issued_by_known_root, |
| 30 | std::vector<std::string>* verified_chain); |
[email protected] | 6dbdaa8 | 2011-08-11 16:05:56 | [diff] [blame] | 31 | |
[email protected] | 87ccb99 | 2012-12-12 01:31:55 | [diff] [blame] | 32 | // Adds a certificate as a root trust certificate to the trust manager. |
| 33 | // |cert| is DER encoded certificate, |len| is its length in bytes. |
wtc | 69f8ea8 | 2015-06-04 00:08:13 | [diff] [blame] | 34 | void AddTestRootCertificate(const uint8_t* cert, size_t len); |
[email protected] | 87ccb99 | 2012-12-12 01:31:55 | [diff] [blame] | 35 | |
| 36 | // Removes all root certificates added by |AddTestRootCertificate| calls. |
| 37 | void ClearTestRootCertificates(); |
| 38 | |
[email protected] | 6dbdaa8 | 2011-08-11 16:05:56 | [diff] [blame] | 39 | // Helper for the <keygen> handler. Passes the DER-encoded key pair via |
[email protected] | 547d54c | 2012-10-25 16:28:44 | [diff] [blame] | 40 | // JNI to the Credentials store. Note that the public key must be a DER |
| 41 | // encoded SubjectPublicKeyInfo (X.509), as returned by i2d_PUBKEY() |
| 42 | // (and *not* i2d_PublicKey(), which returns a PKCS#1 key). |
| 43 | // |
| 44 | // Also, the private key must be in PKCS#8 format, as returned by |
| 45 | // i2d_PKCS8_PRIV_KEY_INFO(EVP_PKEY2PKCS8(pkey)), which is a different |
| 46 | // format than what i2d_PrivateKey() returns, so don't use it either. |
| 47 | // |
wtc | 69f8ea8 | 2015-06-04 00:08:13 | [diff] [blame] | 48 | bool StoreKeyPair(const uint8_t* public_key, |
[email protected] | 6dbdaa8 | 2011-08-11 16:05:56 | [diff] [blame] | 49 | size_t public_len, |
wtc | 69f8ea8 | 2015-06-04 00:08:13 | [diff] [blame] | 50 | const uint8_t* private_key, |
[email protected] | 6dbdaa8 | 2011-08-11 16:05:56 | [diff] [blame] | 51 | size_t private_len); |
| 52 | |
[email protected] | 3b45550 | 2012-12-11 18:22:58 | [diff] [blame] | 53 | // Helper used to pass the DER-encoded bytes of an X.509 certificate or |
| 54 | // a PKCS#12 archive holding a private key to the CertInstaller activity. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 55 | NET_EXPORT void StoreCertificate(CertificateMimeType cert_type, |
[email protected] | 4f2b94f | 2013-02-22 21:06:37 | [diff] [blame] | 56 | const void* data, |
| 57 | size_t data_len); |
[email protected] | 3b45550 | 2012-12-11 18:22:58 | [diff] [blame] | 58 | |
[email protected] | c470e1b | 2012-06-15 07:46:39 | [diff] [blame] | 59 | // Returns true if it can determine that only loopback addresses are configured. |
| 60 | // i.e. if only 127.0.0.1 and ::1 are routable. |
| 61 | // Also returns false if it cannot determine this. |
| 62 | bool HaveOnlyLoopbackAddresses(); |
| 63 | |
[email protected] | 6dbdaa8 | 2011-08-11 16:05:56 | [diff] [blame] | 64 | // Get the mime type (if any) that is associated with the file extension. |
| 65 | // Returns true if a corresponding mime type exists. |
| 66 | bool GetMimeTypeFromExtension(const std::string& extension, |
| 67 | std::string* result); |
| 68 | |
[email protected] | 74d9c524 | 2014-05-01 05:10:03 | [diff] [blame] | 69 | // Returns the ISO country code equivalent of the current MCC (mobile country |
| 70 | // code). |
| 71 | NET_EXPORT std::string GetTelephonyNetworkCountryIso(); |
| 72 | |
| 73 | // Returns MCC+MNC (mobile country code + mobile network code) as |
| 74 | // the numeric name of the current registered operator. |
| 75 | NET_EXPORT std::string GetTelephonyNetworkOperator(); |
| 76 | |
tbansal | a2e9f20c | 2015-09-03 20:05:08 | [diff] [blame] | 77 | // Returns MCC+MNC (mobile country code + mobile network code) as |
| 78 | // the numeric name of the current SIM operator. |
| 79 | NET_EXPORT std::string GetTelephonySimOperator(); |
| 80 | |
| 81 | // Returns true if the device is roaming on the currently active network. When |
| 82 | // true, it suggests that use of data may incur extra costs. |
| 83 | NET_EXPORT bool GetIsRoaming(); |
| 84 | |
[email protected] | 6dbdaa8 | 2011-08-11 16:05:56 | [diff] [blame] | 85 | // Register JNI methods |
[email protected] | be363b2 | 2012-11-01 17:38:47 | [diff] [blame] | 86 | NET_EXPORT bool RegisterNetworkLibrary(JNIEnv* env); |
[email protected] | 6dbdaa8 | 2011-08-11 16:05:56 | [diff] [blame] | 87 | |
| 88 | } // namespace android |
| 89 | } // namespace net |
| 90 | |
| 91 | #endif // NET_ANDROID_NETWORK_LIBRARY_H_ |