blob: ddfb5e92eeec4d30fbd8c96cb873f5c104cd1333 [file] [log] [blame]
[email protected]b47feba2012-04-24 01:34:411// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]6dbdaa82011-08-11 16:05:562// 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]6dbdaa82011-08-11 16:05:567
8#include <jni.h>
Avi Drissman13fc8932015-12-20 04:40:469#include <stddef.h>
wtc69f8ea82015-06-04 00:08:1310#include <stdint.h>
[email protected]6dbdaa82011-08-11 16:05:5611
12#include <string>
13#include <vector>
14
[email protected]71f4b272013-02-13 19:13:4915#include "net/android/cert_verify_result_android.h"
[email protected]3b455502012-12-11 18:22:5816#include "net/base/mime_util.h"
[email protected]be363b22012-11-01 17:38:4717#include "net/base/net_export.h"
[email protected]6dbdaa82011-08-11 16:05:5618
19namespace net {
20namespace android {
21
[email protected]6dbdaa82011-08-11 16:05:5622// |cert_chain| is DER encoded chain of certificates, with the server's own
23// certificate listed first.
[email protected]b47feba2012-04-24 01:34:4124// |auth_type| is as per the Java X509Certificate.checkServerTrusted method.
[email protected]23073f92014-01-17 22:52:1725void 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]6dbdaa82011-08-11 16:05:5631
[email protected]87ccb992012-12-12 01:31:5532// Adds a certificate as a root trust certificate to the trust manager.
33// |cert| is DER encoded certificate, |len| is its length in bytes.
wtc69f8ea82015-06-04 00:08:1334void AddTestRootCertificate(const uint8_t* cert, size_t len);
[email protected]87ccb992012-12-12 01:31:5535
36// Removes all root certificates added by |AddTestRootCertificate| calls.
37void ClearTestRootCertificates();
38
[email protected]6dbdaa82011-08-11 16:05:5639// Helper for the <keygen> handler. Passes the DER-encoded key pair via
[email protected]547d54c2012-10-25 16:28:4440// 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//
wtc69f8ea82015-06-04 00:08:1348bool StoreKeyPair(const uint8_t* public_key,
[email protected]6dbdaa82011-08-11 16:05:5649 size_t public_len,
wtc69f8ea82015-06-04 00:08:1350 const uint8_t* private_key,
[email protected]6dbdaa82011-08-11 16:05:5651 size_t private_len);
52
[email protected]3b455502012-12-11 18:22:5853// 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.
ttuttle859dc7a2015-04-23 19:42:2955NET_EXPORT void StoreCertificate(CertificateMimeType cert_type,
[email protected]4f2b94f2013-02-22 21:06:3756 const void* data,
57 size_t data_len);
[email protected]3b455502012-12-11 18:22:5858
[email protected]c470e1b2012-06-15 07:46:3959// 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.
62bool HaveOnlyLoopbackAddresses();
63
[email protected]6dbdaa82011-08-11 16:05:5664// Get the mime type (if any) that is associated with the file extension.
65// Returns true if a corresponding mime type exists.
66bool GetMimeTypeFromExtension(const std::string& extension,
67 std::string* result);
68
[email protected]74d9c5242014-05-01 05:10:0369// Returns the ISO country code equivalent of the current MCC (mobile country
70// code).
71NET_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.
75NET_EXPORT std::string GetTelephonyNetworkOperator();
76
tbansala2e9f20c2015-09-03 20:05:0877// Returns MCC+MNC (mobile country code + mobile network code) as
78// the numeric name of the current SIM operator.
79NET_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.
83NET_EXPORT bool GetIsRoaming();
84
[email protected]6dbdaa82011-08-11 16:05:5685// Register JNI methods
[email protected]be363b22012-11-01 17:38:4786NET_EXPORT bool RegisterNetworkLibrary(JNIEnv* env);
[email protected]6dbdaa82011-08-11 16:05:5687
88} // namespace android
89} // namespace net
90
91#endif // NET_ANDROID_NETWORK_LIBRARY_H_