Skip to content

Commit

Permalink
Define the built-in access method "Encrypted DNS proxy"
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPettersson98 committed Oct 21, 2024
1 parent 7fc1e2a commit d12ad3e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
3 changes: 3 additions & 0 deletions mullvad-daemon/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,9 @@ fn resolve_connection_mode(
);
ApiConnectionMode::Direct
}),
AccessMethod::BuiltIn(BuiltInAccessMethod::EncryptedDnsProxy) => {
todo!("Implement me!")
}
AccessMethod::Custom(config) => ApiConnectionMode::Proxied(ProxyConfig::from(config)),
}
}
Expand Down
7 changes: 5 additions & 2 deletions mullvad-management-interface/proto/management_interface.proto
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,12 @@ message CustomProxy {
message AccessMethod {
message Direct {}
message Bridges {}
message EncryptedDnsProxy {}
oneof access_method {
Direct direct = 1;
Bridges bridges = 2;
CustomProxy custom = 3;
EncryptedDnsProxy encrypted_dns_proxy = 3;
CustomProxy custom = 4;
}
}

Expand All @@ -434,7 +436,8 @@ message NewAccessMethodSetting {
message ApiAccessMethodSettings {
AccessMethodSetting direct = 1;
AccessMethodSetting mullvad_bridges = 2;
repeated AccessMethodSetting custom = 3;
AccessMethodSetting encrypted_dns_proxy = 3;
repeated AccessMethodSetting custom = 4;
}

message Settings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod settings {
Self {
direct: Some(settings.direct().clone().into()),
mullvad_bridges: Some(settings.mullvad_bridges().clone().into()),
encrypted_dns_proxy: Some(settings.encrypted_dns_proxy().clone().into()),
custom: settings
.iter_custom()
.cloned()
Expand Down Expand Up @@ -37,6 +38,13 @@ mod settings {
))
.and_then(access_method::AccessMethodSetting::try_from)?;

let encrypted_dns_proxy = settings
.encrypted_dns_proxy
.ok_or(FromProtobufTypeError::InvalidArgument(
"Could not deserialize Encrypted DNS proxy Access Method from protobuf",
))
.and_then(access_method::AccessMethodSetting::try_from)?;

let custom = settings
.custom
.iter()
Expand All @@ -46,6 +54,7 @@ mod settings {
Ok(access_method::Settings::new(
direct,
mullvad_bridges,
encrypted_dns_proxy,
custom,
))
}
Expand Down Expand Up @@ -118,6 +127,9 @@ mod data {
Ok(match access_method {
proto::access_method::AccessMethod::Direct(direct) => AccessMethod::from(direct),
proto::access_method::AccessMethod::Bridges(bridge) => AccessMethod::from(bridge),
proto::access_method::AccessMethod::EncryptedDnsProxy(proxy) => {
AccessMethod::from(proxy)
}
proto::access_method::AccessMethod::Custom(custom) => {
CustomProxy::try_from(custom).map(AccessMethod::from)?
}
Expand Down Expand Up @@ -146,6 +158,12 @@ mod data {
}
}

impl From<proto::access_method::EncryptedDnsProxy> for AccessMethod {
fn from(_value: proto::access_method::EncryptedDnsProxy) -> Self {
AccessMethod::from(BuiltInAccessMethod::EncryptedDnsProxy)
}
}

impl TryFrom<proto::Socks5Local> for AccessMethod {
type Error = FromProtobufTypeError;

Expand Down Expand Up @@ -187,6 +205,11 @@ mod data {
mullvad_types::access_method::BuiltInAccessMethod::Bridge => {
proto::access_method::AccessMethod::Bridges(proto::access_method::Bridges {})
}
mullvad_types::access_method::BuiltInAccessMethod::EncryptedDnsProxy => {
proto::access_method::AccessMethod::EncryptedDnsProxy(
proto::access_method::EncryptedDnsProxy {},
)
}
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions mullvad-types/src/access_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use talpid_types::net::proxy::{CustomProxy, Shadowsocks, Socks5Local, Socks5Remo
pub struct Settings {
direct: AccessMethodSetting,
mullvad_bridges: AccessMethodSetting,
encrypted_dns_proxy: AccessMethodSetting,
/// Custom API access methods.
custom: Vec<AccessMethodSetting>,
}
Expand All @@ -14,11 +15,13 @@ impl Settings {
pub fn new(
direct: AccessMethodSetting,
mullvad_bridges: AccessMethodSetting,
encrypted_dns_proxy: AccessMethodSetting,
custom: Vec<AccessMethodSetting>,
) -> Settings {
Settings {
direct,
mullvad_bridges,
encrypted_dns_proxy,
custom,
}
}
Expand Down Expand Up @@ -93,6 +96,7 @@ impl Settings {
use std::iter::once;
once(&self.direct)
.chain(once(&self.mullvad_bridges))
.chain(once(&self.encrypted_dns_proxy))
.chain(&self.custom)
}

Expand Down Expand Up @@ -125,6 +129,10 @@ impl Settings {
&self.mullvad_bridges
}

pub fn encrypted_dns_proxy(&self) -> &AccessMethodSetting {
&self.encrypted_dns_proxy
}

fn create_direct() -> AccessMethodSetting {
let method = BuiltInAccessMethod::Direct;
AccessMethodSetting::new(method.canonical_name(), true, AccessMethod::from(method))
Expand All @@ -134,13 +142,19 @@ impl Settings {
let method = BuiltInAccessMethod::Bridge;
AccessMethodSetting::new(method.canonical_name(), true, AccessMethod::from(method))
}

fn create_encrypted_dns_proxy() -> AccessMethodSetting {
let method = BuiltInAccessMethod::EncryptedDnsProxy;
AccessMethodSetting::new(method.canonical_name(), true, AccessMethod::from(method))
}
}

impl Default for Settings {
fn default() -> Self {
Self {
direct: Settings::create_direct(),
mullvad_bridges: Settings::create_mullvad_bridges(),
encrypted_dns_proxy: Settings::create_encrypted_dns_proxy(),
custom: vec![],
}
}
Expand Down Expand Up @@ -271,6 +285,7 @@ impl AccessMethodSetting {
pub enum BuiltInAccessMethod {
Direct,
Bridge,
EncryptedDnsProxy,
}

impl AccessMethod {
Expand All @@ -287,6 +302,7 @@ impl BuiltInAccessMethod {
match self {
BuiltInAccessMethod::Direct => "Direct".to_string(),
BuiltInAccessMethod::Bridge => "Mullvad Bridges".to_string(),
BuiltInAccessMethod::EncryptedDnsProxy => "Encrypted DNS proxy".to_string(),
}
}
}
Expand Down

0 comments on commit d12ad3e

Please sign in to comment.