blob: ba2bfb5eb355354faea8b16758e36f6e83ea256a [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// Copyright (c) 2012 The Chromium Authors. All rights reserved.
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_
7
8#include <jni.h>
9
10#include <string>
11#include <vector>
12
13#include "base/basictypes.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000014#include "net/android/cert_verify_result_android.h"
15#include "net/base/mime_util.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000016#include "net/base/net_export.h"
17
18namespace net {
19namespace android {
20
Torne (Richard Coles)58218062012-11-14 11:43:16 +000021// |cert_chain| is DER encoded chain of certificates, with the server's own
22// certificate listed first.
23// |auth_type| is as per the Java X509Certificate.checkServerTrusted method.
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +000024void VerifyX509CertChain(const std::vector<std::string>& cert_chain,
25 const std::string& auth_type,
26 const std::string& host,
27 CertVerifyStatusAndroid* status,
28 bool* is_issued_by_known_root,
29 std::vector<std::string>* verified_chain);
Torne (Richard Coles)58218062012-11-14 11:43:16 +000030
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000031// Adds a certificate as a root trust certificate to the trust manager.
32// |cert| is DER encoded certificate, |len| is its length in bytes.
33void AddTestRootCertificate(const uint8* cert, size_t len);
34
35// Removes all root certificates added by |AddTestRootCertificate| calls.
36void ClearTestRootCertificates();
Torne (Richard Coles)58218062012-11-14 11:43:16 +000037
38// Helper for the <keygen> handler. Passes the DER-encoded key pair via
39// JNI to the Credentials store. Note that the public key must be a DER
40// encoded SubjectPublicKeyInfo (X.509), as returned by i2d_PUBKEY()
41// (and *not* i2d_PublicKey(), which returns a PKCS#1 key).
42//
43// Also, the private key must be in PKCS#8 format, as returned by
44// i2d_PKCS8_PRIV_KEY_INFO(EVP_PKEY2PKCS8(pkey)), which is a different
45// format than what i2d_PrivateKey() returns, so don't use it either.
46//
47bool StoreKeyPair(const uint8* public_key,
48 size_t public_len,
49 const uint8* private_key,
50 size_t private_len);
51
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000052// Helper used to pass the DER-encoded bytes of an X.509 certificate or
53// a PKCS#12 archive holding a private key to the CertInstaller activity.
54NET_EXPORT void StoreCertificate(net::CertificateMimeType cert_type,
55 const void* data,
56 size_t data_len);
57
Torne (Richard Coles)58218062012-11-14 11:43:16 +000058// Returns true if it can determine that only loopback addresses are configured.
59// i.e. if only 127.0.0.1 and ::1 are routable.
60// Also returns false if it cannot determine this.
61bool HaveOnlyLoopbackAddresses();
62
63// Return a string containing a list of network interfaces, each item is a
64// network name and address pair.
65// e.g. "eth0,10.0.0.2;eth0,fe80::5054:ff:fe12:3456" is a result string
66// containing two items.
67std::string GetNetworkList();
68
69// Get the mime type (if any) that is associated with the file extension.
70// Returns true if a corresponding mime type exists.
71bool GetMimeTypeFromExtension(const std::string& extension,
72 std::string* result);
73
Bo Liu5c02ac12014-05-01 10:37:37 -070074// Returns the ISO country code equivalent of the current MCC (mobile country
75// code).
76NET_EXPORT std::string GetTelephonyNetworkCountryIso();
77
78// Returns MCC+MNC (mobile country code + mobile network code) as
79// the numeric name of the current registered operator.
80NET_EXPORT std::string GetTelephonyNetworkOperator();
81
Torne (Richard Coles)58218062012-11-14 11:43:16 +000082// Register JNI methods
83NET_EXPORT bool RegisterNetworkLibrary(JNIEnv* env);
84
85} // namespace android
86} // namespace net
87
88#endif // NET_ANDROID_NETWORK_LIBRARY_H_