GithubHelp home page GithubHelp logo

junkurihara / doh-auth-proxy Goto Github PK

View Code? Open in Web Editor NEW
23.0 4.0 6.0 975 KB

Local DNS proxy for DNS over HTTPS (DoH), Oblivious DoH (ODoH) and Multiple-relay-based ODoH extension (Mutualized ODoH; MODoH), which additionally supports domain-based filtering and proxy/resolver authentication

Home Page: https://junkurihara.github.io/dns

License: MIT License

Rust 94.60% Shell 4.23% Dockerfile 1.17%
dns rust doh odoh dns-over-https oblivious-doh mutualized-odoh ad-blocking domain-blocker domain-filtering

doh-auth-proxy's Introduction

doh-auth-proxy

License: MIT Unit Test Build and Publish Docker ShiftLeft Scan Docker Image Size (latest by date)

Local proxy for DoH, Oblivious DoH and ODoH-based Mutualized Oblivious DNS (ODoH-based μODNS; μODoH) supporting super-fast domain-based blocking and authenticated connection, written in Rust.

For the detailed information on μODNS, please also refer to https://junkurihara.github.io/dns/.

Introduction

DNS over HTTPS (DoH) is an encrypted DNS protocol in which DNS queries and responses are exchanged with the target full-service resolver via HTTPS, i.e., over an encrypted-secure channel (RFC8484). To enhance the privacy of DoH, Oblivious DNS over HTTPS (ODoH) has been developed (RFC9230). ODoH leverages an intermediate relay (or proxy) and an end-to-end encryption (HPKE) in order to decouple the client's IP address and content of his queries. Mutualized Oblivious DNS over HTTPS (μODoH) is an extension of ODoH, which has been (is still being) developed from the concern of the collusion between the relay and the target resolver and corruption of the client's privacy (Resource). To this end, μODNS leverages multiple relays towards the target resolver, where relays are selected in a random fashion and employed in a distributed manner.

doh-auth-proxy is client software that translates the standard DNS over port 53 (Do53) protocol to these three encrypted and privacy-enhanced DNS protocols. In other words, doh-auth-proxy protects the plaintext Do53 queries from being eavesdropped by encryption.

Network structure of μODoH

Here is an example of the network architecture of μODoH.

μODoH Network Structure

The μODoH network consists of μODoH client (doh-auth-proxy), μODoH relay and target servers(modoh-server), and supplementary authentication server (rust-token-server). Note that when there exist two modoh-server, i.e., single relay and single target available, it exactly coincides with ODoH.

doh-auth-proxy and modoh-server supplementary provide access control function for queries, i.e., client authentication. In this mechanism, client queries are authenticated by Bearer token in their HTTP header. Note that to enable this client authentication, the rust-token-server must be configured and deployed on the Internet.

Installing/building an executable binary

You can build an executable binary yourself by checking out this Git repository.

# debug mode
% cargo build

# release mode
% cargo build --release

Now you have a compiled executable binary doh-auth-proxy in ./target/debug/ or ./target/release/.

Basic Usage

First step: Connecting to Google public DoH server

Start doh-auth-proxy as

% ./path/to/doh-auth-proxy --config config.toml

where we assume that config.toml is configured like follows.

listen_addresses = ['127.0.0.1:50053', '[::1]:50053']
bootstrap_dns = ["1.1.1.1"]

target_urls = ["https://dns.google/dns-query"]

Now you can query through 127.0.0.1:50053 as

% dig github.com @localhost -p 50053
~~~~~~~
;; ANSWER SECTION:
github.com.             60      IN      A       52.69.186.44
~~~~~~~

The parameter bootstrap_dns is used to resolve the IP address of the host of target_urls (i.e., target DoH server). The bootstrap_dns allows non-standard DNS ports other than 53 and TCP queries, which can be specified as an url-like format, e.g., tcp://1.1.1.1, tcp://127.0.0.1:12345, 127.0.0.1:50053, where UDP and port 53 are used if omitted.

If you run without --config option, i.e., simply hit $ ./doh-auth-proxy, the followings are applied as default parameters:

listen_addresses = ['127.0.0.1:50053', '[::1]:50053']
bootstrap_dns = ["1.1.1.1"]
endpoint_resolution_period = 60 # mins
healthcheck_period = 10 # mins
max_cache_size = 16384
target_urls = ["https://dns.google/dns-query"]

All the options are referred to below. Using your specific config file is recommended for better setting in your environment.

Second step: Connecting to Cloudflare ODoH server via odohrelay-ams ODoH relay

Start doh-auth-proxy as

% ./path/to/doh-auth-proxy --config config.toml

where we assume that config.toml is configured as follows.

listen_addresses = ['127.0.0.1:50053', '[::1]:50053']
bootstrap_dns = ["8.8.8.8"]

target_urls = ["https://odoh.cloudflare-dns.com/dns-query"]

[anonymization]
odoh_relay_urls = ["https://odoh-nl.alekberg.net:443/proxy"]

This example issues ODoH encrypted queries by an URL https://odoh-nl.alekberg.net:443/proxy?targethost=odoh.cloudflare-dns.com&targetpath=/dns-query.

Now you can query through 127.0.0.1:50053 as

% dig github.com @localhost -p 50053
~~~~~~~
;; ANSWER SECTION:
github.com.             11      IN      A       140.82.121.4
~~~~~~~

where this takes more round-trip time than the above ordinary DoH example due to the intermediate relay (especially when it is far from your location).

Advanced usage

Query plugins for name-based/domain-based blocking and overriding IP addresses

Optionally, doh-auth-proxy has functions of domain-based blocking and overriding (cloaking) IP Addresses. Former means that queries for domain names of specific patterns would be blocked and reject messages would be obtained. This can be done super-fast by enabling a trie-based data structure thanks to Cedarwood crate. Latter means that IP addresses you specified are always obtained for specific domain names.

To enable these functions, specify files defining blocking/overriding rules in config.toml as

[plugins]

domains_blocked_file = "./blocklist.txt"
domains_overridden_file = "./overridelist.txt"

Refer to their example files for detailed format.

Mutualized Oblivious DNS (μODNS) based on ODoH (μODoH)

doh-auth-proxy extends the ODoH protocol to the multiple-relay-based anonymization protocol, where its concept is called Mutualized Oblivious DNS (μODNS). We call by μODoH the ODoH-based μODNS.

To leverage the protocol, you need to run or find relay servers running μODoH. The implementation of the μODoH relay and target server is

Note that the target resolver in μODoH is exactly same as that in the standard ODoH, and hence you can specify existing ODoH targets, e.g., Cloudflare's one https://odoh.cloudflare-dns.com/dns-query.

When you run your relay servers, please make sure their security settings and fully understand the risk. Everything must be done at your own risk.

See also the DNSCrypt-based μODNS as well, by referring to our website.

All options in a configuration file

USAGE:
    doh-auth-proxy --config <config_file>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -c, --config <config_file>    Configuration file path like "doh-auth-proxy.toml"

config.toml can be configured as follows.

##############################################
#                                            #
#        doh-auth-proxy configuration        #
#                                            #
##############################################

##################################
#         Global settings        #
##################################

## Address to listen to.
listen_addresses = ['127.0.0.1:50053', '[::1]:50053']

## DNS (Do53) resolver address for bootstrap
bootstrap_dns = ['8.8.8.8']

## Minutes to re-resolve the IP addr of the nexthop and authentication endpoint url
## Ip addresses are first resolved by bootstrap DNS, after that, they will be resolved by (MO)DoH resolver itself.
# endpoint_resolution_period = 60

## Health check period in minitus. Check health of all path candidates and purge DNS cache.
# healthcheck_period = 10

## Cache entry size (Default 16384)
max_cache_size = 16384

## URL of (O)DoH target server like "https://dns.google/dns-query".
## You can specify multiple servers by repeatedly set this option, then one of given
## servers is randomly chosen every time.
target_urls = ["https://odoh.cloudflare-dns.com/dns-query"]

## According to the suggestion in "Designing for Tussle in Encrypted DNS" (HotNets'21),
## multiple (O)DoH servers should be specified and used in randomized fashion in this
## proxy when "target_randomization = true". Otherwise, the first one is always chosen.
## To this end, 'Global' objects should have Vec<DoHClient> object as clients configured
## with different target servers. Default value is true
target_randomization = true

## Use Get method to query if true. Default is false
# use_get_method = false


##################################
#         Auth settings          #
##################################
[authentication]

## (optional)
## API url to retrieve and refresh tokens and validation keys (jwks) like "https://example.com/v1.0",
## where /tokens and /refresh are used for login and refresh, respectively.
## Also /jwks is used for jwks retrieval.
# token_api = "https://token.api.example.org/v1.0"

## (optional)
## Credential env file path for login endpoint like "./credential.env"
# credential_file = "./.credential"


##################################
#         Anon settings          #
##################################
[anonymization]

## (optional) URL of ODoH nexthop relay server like "https://relay.example.com/relay"
odoh_relay_urls = ["https://odoh-nl.alekberg.net:443/proxy"]


## (optional)
## Choose ODoH relay in a randomized fashion from `odoh_relay_urls`.
odoh_relay_randomization = true

## (optional)
## URL of multiple-relay-based ODoH's intermediate relay like "https://relay.example.com/inter-relay".
## Specified relay is used after the relay of 'odoh_relay_url' in a randomized fashion.
# mid_relay_urls = ["htps://relay.url.after.surfdomeinen.example.org/proxy"]

## (optional)
## Maximum number of intermediate relays between nexthop and target.
# max_mid_relays = 2

##################################
#       Plugin settings          #
##################################
# [plugins]

## (optional)
## List of domain names to be blocked.
# domains_blocked_file = "./blocklist.txt"

## (optional)
## List of pairs of a domain name and an IPv4/v6 address, which will be overridden by specified address.
# domains_overridden_file = "./overridelist.txt"

Docker container

You can run this proxy as a docker container, where the docker image is hosted at Docker Hub. You can run the docker container by appropriately configure env vers or an env file imported by the container.

See the ./docker directory and ./docker/README.md for the detailed configuration for the docker container.

Authentication at the next hop node (DoH target or ODoH relay)

This proxy provides authenticated connection to a DoH target resolver (in DoH) or to an ODoH relay (in ODoH). This function allows the nexthop node (DoH target/ODoH relay) to be private to users, and avoids unauthorized access. This additional function is introduced in order to prevent attacks against external servers through our relays.

To leverage the function, an authentication server issuing Authorization Bearer tokens and an authentication-enabled DoH target/ODoH relay, given in the following.

  • modoh-server: Relay and target implementation for Oblivious DoH (ODoH) and ODoH-based Mutualized Oblivious DNS (ODoH-based μODNS; μODoH) supporting authenticated connection, written in Rust. Standard DoH target server is also supported.

  • rust-token-server: An implementation of authentication server issueing id_token in the context of OIDC.

Distribution of queries to multiple target resolvers and relays

Referring to the recent paper from Princeton University, we added a function to distribute queries among multiple target resolver. This is in order to support "design for choice".

A. Hounsel, et al., "Designing for Tussle in Encrypted DNS", ACM HotNets'21

Currently if you specify multiple target resolvers and target_randomization = true in config.toml, your query is dispatched towards one of targets chosen in a random fashion. Otherwise, the first one is always selected.

From the same perspective of distribution of queries, our implementation enables the relay randomization in (Mutualized) Oblivious DNS over HTTPS simultaneously with the target randomization. This can be enabled by odoh_relay_randomization = true in config.toml.

We plan to implement kinds of 'round-robin' based distribution and other variants.

Notes

ODoH implementation follows RFC9230.

doh-auth-proxy's People

Contributors

dependabot[bot] avatar junkurihara avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

doh-auth-proxy's Issues

Renaming to `modoh-proxy`?

Yesterday, we published the DoH, ODoH and μODoH server application, modoh-server. The naming of modoh-server was from the original name of μODoH, Mutualized Oblivious DNS over HTTPS.

doh-auth-proxy was designed to fully leverage the functionalities of μODoH in addition to DoH and ODoH. IMHO, the naming convention of client and server software should be consistent, and hence the naming modoh-proxy would be better than doh-auth-proxy.

Any opinion?

Feature request: Connectivity test and bootstrap resolvers

I thinking on using doh-auth-proxy with systemd and in some Windows 10 PCs as a service.

I want to use a list of 2 ODoH relays and 10 ODoH servers, sometimes some servers are down and I cannot predict this, if using doh-auth-proxy with systemd won't work if one of the servers are down.

A good feature would be an automatic network connectivity test: The app would wait until the network is up and a check in the relays/servers would be performed to select only online relays/servers. This option would make doh-auth-proxy work fine with systemd or as a Windows service. This feature is implemented in dnscrypt-proxy: https://github.com/DNSCrypt/dnscrypt-proxy/blob/master/dnscrypt-proxy/example-dnscrypt-proxy.toml#L282-L300

Another feature that would be good to be implemented is the ability of using bootstrap resolvers: If using doh-auth-proxy alone as a DNS forwarder for the network, it couldn't find any DNS server to resolve the hostnames of relays/servers. This feature is also implemented in dnscrypt-proxy: https://github.com/DNSCrypt/dnscrypt-proxy/blob/master/dnscrypt-proxy/example-dnscrypt-proxy.toml#L234-L279

These are my suggestions.

Windows support

I've tried to compile doh-auth-proxy for Windows target but I have no success:

$ cargo build --release --target x86_64-pc-windows-gnu
  Downloaded windows-targets v0.48.2
  Downloaded windows_x86_64_gnu v0.48.2
  Downloaded 2 crates (808.5 KB) in 3.12s
   Compiling cfg-if v1.0.0
   Compiling typenum v1.16.0
   Compiling generic-array v0.14.7
   Compiling zeroize v1.6.0
   Compiling subtle v2.5.0
   Compiling getrandom v0.2.10
   Compiling const-oid v0.9.5
   Compiling windows_x86_64_gnu v0.48.2
   Compiling once_cell v1.18.0
   Compiling windows-targets v0.48.2
   Compiling windows-sys v0.48.0
   Compiling rand_core v0.6.4
   Compiling block-buffer v0.10.4
   Compiling base64ct v1.6.0
   Compiling serde v1.0.183
   Compiling crypto-common v0.1.6
   Compiling winapi-x86_64-pc-windows-gnu v0.4.0
   Compiling digest v0.10.7
   Compiling itoa v1.0.9
   Compiling winapi v0.3.9
   Compiling pin-project-lite v0.2.12
   Compiling cpufeatures v0.2.9
   Compiling bytes v1.4.0
   Compiling futures-core v0.3.28
   Compiling hmac v0.12.1
   Compiling pem-rfc7468 v0.7.0
   Compiling der v0.7.8
   Compiling tracing-core v0.1.31
   Compiling smallvec v1.11.0
   Compiling ryu v1.0.15
   Compiling futures-sink v0.3.28
   Compiling spin v0.5.2
   Compiling futures-task v0.3.28
   Compiling serde_json v1.0.105
   Compiling lazy_static v1.4.0
   Compiling slab v0.4.8
   Compiling spki v0.7.2
   Compiling hkdf v0.12.3
   Compiling num_cpus v1.16.0
   Compiling ppv-lite86 v0.2.17
   Compiling base16ct v0.2.0
   Compiling libm v0.2.7
   Compiling serdect v0.2.0
   Compiling futures-util v0.3.28
   Compiling tracing v0.1.37
   Compiling pkcs8 v0.10.2
   Compiling rand_chacha v0.3.1
   Compiling ff v0.13.0
   Compiling inout v0.1.3
   Compiling tinyvec_macros v0.1.1
   Compiling pin-utils v0.1.0
   Compiling futures-channel v0.3.28
   Compiling tinyvec v1.6.0
   Compiling cipher v0.4.4
   Compiling num-traits v0.2.16
   Compiling group v0.13.0
   Compiling rand v0.8.5
   Compiling sec1 v0.7.3
   Compiling libc v0.2.147
   Compiling universal-hash v0.5.1
   Compiling crypto-bigint v0.5.2
   Compiling opaque-debug v0.3.0
   Compiling byteorder v1.4.3
   Compiling socket2 v0.5.3
   Compiling mio v0.8.8
   Compiling elliptic-curve v0.13.5
   Compiling thiserror v1.0.46
   Compiling ahash v0.8.3
   Compiling tokio v1.32.0
   Compiling unicode-normalization v0.1.22
   Compiling sha2 v0.10.7
   Compiling pem-rfc7468 v0.6.0
   Compiling percent-encoding v2.3.0
   Compiling fnv v1.0.7
   Compiling unicode-bidi v0.3.13
   Compiling http v0.2.9
   Compiling form_urlencoded v1.2.0
   Compiling der v0.6.1
   Compiling memchr v2.5.0
   Compiling indexmap v1.9.3
   Compiling num-integer v0.1.45
   Compiling rfc6979 v0.4.0
   Compiling signature v2.1.0
   Compiling allocator-api2 v0.2.16
   Compiling hashbrown v0.12.3
   Compiling native-tls v0.2.11
   Compiling httparse v1.8.0
   Compiling hashbrown v0.14.0
   Compiling tokio-util v0.7.8
   Compiling spki v0.6.0
   Compiling parking_lot_core v0.9.8
   Compiling lock_api v0.4.10
   Compiling num-iter v0.1.43
   Compiling ecdsa v0.16.8
   Compiling idna v0.4.0
   Compiling schannel v0.1.22
   Compiling polyval v0.6.1
   Compiling aead v0.5.2
   Compiling digest v0.9.0
   Compiling ipconfig v0.3.2
   Compiling match_cfg v0.1.0
   Compiling matches v0.1.10
   Compiling rand_core v0.5.1
   Compiling futures-io v0.3.28
   Compiling try-lock v0.2.4
   Compiling scopeguard v1.2.0
   Compiling want v0.3.1
   Compiling curve25519-dalek v3.2.0
   Compiling idna v0.2.3
   Compiling num-bigint-dig v0.8.4
   Compiling hostname v0.3.1
   Compiling ghash v0.5.0
   Compiling url v2.4.0
   Compiling aho-corasick v1.0.4
   Compiling h2 v0.3.20
   Compiling pkcs8 v0.9.0
   Compiling http-body v0.4.5
   Compiling primeorder v0.13.2
   Compiling winreg v0.50.0
   Compiling poly1305 v0.8.0
   Compiling chacha20 v0.9.1
   Compiling ctr v0.9.2
   Compiling aes v0.8.3
   Compiling socket2 v0.4.9
   Compiling quick-error v1.2.3
   Compiling regex-syntax v0.7.4
   Compiling data-encoding v2.4.0
   Compiling widestring v1.0.2
   Compiling winreg v0.10.1
   Compiling httpdate v1.0.3
   Compiling regex-syntax v0.6.29
   Compiling log v0.4.20
   Compiling ipnet v2.8.0
   Compiling equivalent v1.0.1
   Compiling tower-service v0.3.2
   Compiling linked-hash-map v0.5.6
   Compiling lru-cache v0.1.2
   Compiling trust-dns-proto v0.22.0
   Compiling hyper v0.14.27
   Compiling regex-automata v0.1.10
   Compiling anyhow v1.0.75
   Compiling indexmap v2.0.0
   Compiling regex-automata v0.3.6
   Compiling resolv-conf v0.7.0
   Compiling aes-gcm v0.10.2
   Compiling chacha20poly1305 v0.10.1
   Compiling pkcs1 v0.4.1
   Compiling parking_lot v0.12.1
   Compiling tikv-jemalloc-sys v0.5.4+5.3.0-patched
   Compiling x25519-dalek v2.0.0-pre.1
   Compiling tokio-native-tls v0.3.1
   Compiling terminal_size v0.2.6
   Compiling serde_spanned v0.6.3
   Compiling toml_datetime v0.6.3
   Compiling signature v1.6.4
   Compiling clap_lex v0.5.0
   Compiling overload v0.1.1
   Compiling winnow v0.5.12
   Compiling ct-codecs v1.1.1
   Compiling anstyle v1.0.1
   Compiling clap_builder v4.3.21
   Compiling toml_edit v0.19.14
   Compiling ed25519-compact v2.0.4
   Compiling nu-ansi-term v0.46.0
   Compiling rsa v0.7.2
   Compiling regex v1.9.3
   Compiling hyper-tls v0.5.0
   Compiling hpke v0.10.0 (https://github.com/junkurihara/rust-hpke.git#4dd82caf)
   Compiling trust-dns-resolver v0.22.0
   Compiling matchers v0.1.0
   Compiling tracing-log v0.1.3
   Compiling p384 v0.13.0
   Compiling p256 v0.13.2
   Compiling k256 v0.13.1
   Compiling serde_urlencoded v0.7.1
   Compiling coarsetime v0.1.23
   Compiling time v0.1.45
   Compiling sharded-slab v0.1.4
   Compiling hmac-sha512 v1.1.5
   Compiling hmac-sha256 v1.1.7
   Compiling thread_local v1.1.7
   Compiling encoding_rs v0.8.32
   Compiling binstring v0.1.1
   Compiling mime v0.3.17
   Compiling base64 v0.21.2
   Compiling hmac-sha1-compact v1.1.4
   Compiling jwt-simple v0.11.6
   Compiling tracing-subscriber v0.3.17
   Compiling reqwest v0.11.18
   Compiling chrono v0.4.26
   Compiling odoh-rs v1.0.1 (https://github.com/junkurihara/odoh-rs.git#25c3ed9a)
   Compiling clap v4.3.21
   Compiling toml v0.7.6
   Compiling futures v0.3.28
   Compiling hashlink v0.8.3
   Compiling cedarwood v0.4.6
   Compiling urlencoding v2.1.3
   Compiling rustc-hash v1.1.0
   Compiling dotenv v0.15.0
   Compiling tikv-jemallocator v0.5.4
error: could not find native static library `jemalloc`, perhaps an -L flag is missing?

error: could not compile `tikv-jemalloc-sys` (lib) due to previous error

@junkurihara

Is it possible to add support for compiling to Windows targets? Does it exist a similar library like tikv-jemallocator that compiles to Windows?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.