Skip to content

Latest commit

 

History

History
119 lines (88 loc) · 6.54 KB

README.md

File metadata and controls

119 lines (88 loc) · 6.54 KB

How to build

  1. follow these instructions here to get the code.
  2. export CHROMIUM_SRC_ROOT and DEPOT_TOOLS_ROOT to their separate directories, such as export CHROMIUM_SRC_ROOT=/root/chromium/src DEPOT_TOOLS_ROOT=/root/depot_tools
  3. run checkout-to-tag.sh to checkout specified tag, for example, 102.0.5005.195.
  4. run build_cronet.sh [debug|release] to build native and java bindings, then package into cronet-$BUILD.aar(BUILD: debug or release).

How to use

  1. Quick Start Guide to Using Cronet, native API, Android API
  2. Perform network operations using Cronet
  3. Samples with test: native sample, Android sample, GoogleChromeLabs / cronet_sample

The key point is Cronet_EngineParams_envoy_url_set(engine_params, "ENVOY_URL") for native or cronetEngineBuilder.setEnvoyUrl("ENVOY_URL") for android.

Envoy URL

In one format of

  • https://DOMAIN/PATH which can be backed up by http servers or even CDN. The full format for this mode is envoy://?k1=v1&k2=v2, see Parameters section below for more.
  • socks5://HOST:PORT which can be any socks5 proxy, and we have a built-in shadowsocks service for the android platform.

Parameters

keys for envoy://?k1=v1[&<more-pairs>...] format:

All keys except url are optional, for example, only resolve without url will just override the DNS setting.

Examples

  1. the simplest form, a simple HTTP/HTTPS URL: https://allowed.example.com/app1/
  2. or via socks5 provided by any proxy server or builtin shadowsocks service(go to android/README.md for shadowsocks integration): socks5://127.0.0.1:1080.
  3. set host:envoy://?url=https%3A%2F%2Fexample.com%2Fapp1%2F%3Fk1%3Dv1&header_Host=forbidden.example.com
  4. only MAP url-host to address: envoy://?url=https%3A%2F%2Fexample.com%2Fapp1%2F%3Fk1%3Dv1&header_Host=forbidden.example.com&address=1.2.3.4
  5. custom host override: envoy://?url=https%3A%2F%2Fexample.com%2Fapp1%2F%3Fk1%3Dv1&header_Host=forbidden.example.com&resolve=MAP%20example.com%201.2.3.4,%20example2.com%201.2.3.5:443
  6. disable some cipher suites: envoy://?url=https%3A%2F%2Fallowed.example.com%2Fapp1%2F%3Fk1%3Dv1&header_Host=forbidden.example.com&address=1.2.3.4&disabled_cipher_suites=0xc024,0xc02f

In example 5: allowed.example.com will be TLS SNI, forbidden.example.com will be Host HTTP header, 1.2.3.4 will be IP for allowed.example.com.

The equivalent curl command(see below for nginx conf):

curl --resolve allowed.example.com:443:1.2.3.4 \ --header 'Host: forbidden.example.com' \ --header 'Url-Orig: https://forbidden.example.com' --header 'Host-Orig: forbidden.example.com' \ https://allowed.example.com/app1/ # --ciphers ECDHE-RSA-AES128-GCM-SHA256

Note: _hash=HASH will be appended to url in all cases for cache invalidation.

Setup

Backend

Use Nginx as areverse proxy, see security for more.

location ~ ^/app1/ {
    proxy_ssl_server_name on;
    proxy_pass $http_url_orig;
    proxy_buffering off; # disable buffer for stream
    proxy_set_header Host $http_host_orig;
    proxy_hide_header Host-Orig;
    proxy_hide_header Url-Orig;
    proxy_pass_request_headers on;
}

Native

sample main.cc

# ... after patching chromium source
export ENVOY_URL=https://example.com/path/
sed -i s#https://example.com/enovy_path/#$ENVOY_URL#g components/cronet/native/sample/main.cc
autoninja -C out/Cronet-Desktop cronet_sample cronet_sample_test
out/Cronet-Desktop/cronet_sample https://ifconfig.co/ip

Android

CronetSampleActivity.java

# ... after patching chromium source
export ENVOY_URL=https://example.com/path/
sed -i s#https://example.com/enovy_path/#$ENVOY_URL#g components/cronet/android/sample/src/org/chromium/cronet_sample_apk/CronetSampleActivity.java
autoninja -C out/Cronet cronet_sample_apk
adb install out/Cronet/apks/CronetSample.apk

Update API version

Update IDL API

  1. Update chromium code then run git ls-files -m|grep -E '.cc|.java' |xargs git cl format # --diff to format changeset(or git diff --patch-with-stat).

  2. Update api bindings:

    if components/cronet/cronet.idl is updated, run

    • components/cronet/tools/generate_idl_bindings.py
    • components/cronet/tools/update_api.py --api_jar out/Cronet/lib.java/components/cronet/android/cronet_api_java.jar

Update translation xtb file

Generate xtb translation id

cd tools/grit && python
>>> from grit.extern.tclib import GenerateMessageId
>>> GenerateMessageId("English string to translate")

TODO

  1. JavaCronetEngine.java has no member envoy_url.?