Skip to content

Commit

Permalink
Bug 1823358 - Add new network.trr.ohttp.uri pref r=keeler,necko-revie…
Browse files Browse the repository at this point in the history
…wers,jesup

Differential Revision: https://phabricator.services.mozilla.com/D172988
  • Loading branch information
valenting committed Mar 21, 2023
1 parent f46dd57 commit e5eb61e
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 3 deletions.
6 changes: 6 additions & 0 deletions modules/libpref/init/StaticPrefList.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12053,6 +12053,12 @@
value: ""
mirror: never

# The URI used for the target DoH server when network.trr.use_ohttp is true
- name: network.trr.ohttp.uri
type: String
value: ""
mirror: never

# Allow the network changed event to get sent when a network topology or setup
# change is noticed while running.
- name: network.notify.changed
Expand Down
7 changes: 6 additions & 1 deletion netwerk/dns/TRRService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ void TRRService::SetDetectedTrrURI(const nsACString& aURI) {
return;
}

if (StaticPrefs::network_trr_use_ohttp()) {
LOG(("No autodetection when using OHTTP"));
return;
}

mURISetByDetection = MaybeSetPrivateURI(aURI);
}

Expand Down Expand Up @@ -360,7 +365,7 @@ nsresult TRRService::ReadPrefs(const char* name) {
}
if (!name || !strcmp(name, TRR_PREF("uri")) ||
!strcmp(name, TRR_PREF("default_provider_uri")) ||
!strcmp(name, kRolloutURIPref)) {
!strcmp(name, kRolloutURIPref) || !strcmp(name, TRR_PREF("ohttp.uri"))) {
OnTRRURIChange();
}
if (!name || !strcmp(name, TRR_PREF("credentials"))) {
Expand Down
6 changes: 6 additions & 0 deletions netwerk/dns/TRRServiceBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ void TRRServiceBase::ProcessURITemplate(nsACString& aURI) {
void TRRServiceBase::CheckURIPrefs() {
mURISetByDetection = false;

if (StaticPrefs::network_trr_use_ohttp() && !mOHTTPURIPref.IsEmpty()) {
MaybeSetPrivateURI(mOHTTPURIPref);
return;
}

// The user has set a custom URI so it takes precedence.
if (!mURIPref.IsEmpty()) {
MaybeSetPrivateURI(mURIPref);
Expand Down Expand Up @@ -163,6 +168,7 @@ void TRRServiceBase::OnTRRURIChange() {
Preferences::GetCString("network.trr.uri", mURIPref);
Preferences::GetCString(kRolloutURIPref, mRolloutURIPref);
Preferences::GetCString("network.trr.default_provider_uri", mDefaultURIPref);
Preferences::GetCString("network.trr.ohttp.uri", mOHTTPURIPref);

CheckURIPrefs();
}
Expand Down
1 change: 1 addition & 0 deletions netwerk/dns/TRRServiceBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class TRRServiceBase : public nsIProxyConfigChangedCallback {
nsCString mURIPref;
nsCString mRolloutURIPref;
nsCString mDefaultURIPref;
nsCString mOHTTPURIPref;

Atomic<nsIDNSService::ResolverMode, Relaxed> mMode{
nsIDNSService::MODE_NATIVEONLY};
Expand Down
3 changes: 2 additions & 1 deletion netwerk/dns/TRRServiceParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ void TRRServiceParent::PrefsChanged(const char* aName, void* aSelf) {
void TRRServiceParent::prefsChanged(const char* aName) {
if (!aName || !strcmp(aName, "network.trr.uri") ||
!strcmp(aName, "network.trr.default_provider_uri") ||
!strcmp(aName, kRolloutURIPref)) {
!strcmp(aName, kRolloutURIPref) ||
!strcmp(aName, "network.trr.ohttp.uri")) {
OnTRRURIChange();
}

Expand Down
2 changes: 2 additions & 0 deletions netwerk/test/unit/test_dooh.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ async function forwardToTRR(request, response) {

add_setup(async function setup() {
h2Port = trr_test_setup();
runningOHTTPTests = true;

if (mozinfo.socketprocess_networking) {
Services.dns; // Needed to trigger socket process.
Expand Down Expand Up @@ -123,6 +124,7 @@ add_setup(async function setup() {
Services.prefs.clearUserPref("network.trr.use_ohttp");
Services.prefs.clearUserPref("network.trr.ohttp.config_uri");
Services.prefs.clearUserPref("network.trr.ohttp.relay_uri");
Services.prefs.clearUserPref("network.trr.ohttp.uri");
await new Promise((resolve, reject) => {
httpServer.stop(resolve);
});
Expand Down
20 changes: 19 additions & 1 deletion netwerk/test/unit/trr_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ async function SetParentalControlEnabled(aEnabled) {
}

let runningODoHTests = false;
let runningOHTTPTests = false;
let h2Port;

function setModeAndURIForODoH(mode, path) {
Expand All @@ -50,8 +51,25 @@ function setModeAndURIForODoH(mode, path) {
Services.prefs.setCharPref("network.trr.odoh.target_path", `${path}`);
}

function setModeAndURIForOHTTP(mode, path, domain) {
Services.prefs.setIntPref("network.trr.mode", mode);
if (domain) {
Services.prefs.setCharPref(
"network.trr.ohttp.uri",
`https://${domain}:${h2Port}/${path}`
);
} else {
Services.prefs.setCharPref(
"network.trr.ohttp.uri",
`https://${TRR_Domain}:${h2Port}/${path}`
);
}
}

function setModeAndURI(mode, path, domain) {
if (runningODoHTests) {
if (runningOHTTPTests) {
setModeAndURIForOHTTP(mode, path, domain);
} else if (runningODoHTests) {
setModeAndURIForODoH(mode, path);
} else {
Services.prefs.setIntPref("network.trr.mode", mode);
Expand Down

0 comments on commit e5eb61e

Please sign in to comment.