diff options
author | Jesús <heckyel@hyperbola.info> | 2020-03-15 13:13:27 -0500 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2020-03-15 13:13:27 -0500 |
commit | c6ea3c8b35e3a36be5ff5094997178e0be3b643a (patch) | |
tree | 6e3ab9e7bae9c1ad4bd444fb642906db2dcb5f6e /js/vapi-background.js | |
parent | d62a0f38eeb36866a59f165d7f9bfb8dfd6ac3aa (diff) | |
download | ematrix-c6ea3c8b35e3a36be5ff5094997178e0be3b643a.tar.lz ematrix-c6ea3c8b35e3a36be5ff5094997178e0be3b643a.tar.xz ematrix-c6ea3c8b35e3a36be5ff5094997178e0be3b643a.zip |
Uncloack CNAME hostnames
Diffstat (limited to 'js/vapi-background.js')
-rw-r--r-- | js/vapi-background.js | 47 |
1 files changed, 41 insertions, 6 deletions
diff --git a/js/vapi-background.js b/js/vapi-background.js index e5e6998..061ae29 100644 --- a/js/vapi-background.js +++ b/js/vapi-background.js @@ -313,12 +313,7 @@ return this.mimeTypeMap[mime.slice(0, pos)] || 0; }, - observe: function (channel, topic) { - if (channel instanceof Ci.nsIHttpChannel === false) { - return; - } - - let URI = channel.URI; + operate: function (channel, URI, topic) { let channelData = this.channelDataFromChannel(channel); if (topic.lastIndexOf('http-on-examine-', 0) === 0) { @@ -423,6 +418,46 @@ // Carry data for behind-the-scene redirects channel.setProperty(this.REQDATAKEY, [tabId, rawType]); }, + observe: function (channel, topic) { + if (channel instanceof Ci.nsIHttpChannel === false) { + return; + } + + let URI = channel.URI; + let channelData = this.channelDataFromChannel(channel); + + if (ηMatrix.userSettings.resolveCname === true) { + let CC = Components.classes; + let CI = Components.interfaces; + + let dns = CC['@mozilla.org/network/dns-service;1'] + .createInstance(CI.nsIDNSService); + + let listener = { + onLookupComplete: function (req, rec, stat) { + if (!Components.isSuccessCode(stat)) { + console.error("can't resolve canonical name"); + return; + } + let addr = rec.canonicalName; + + let ios = CC['@mozilla.org/network/io-service;1'] + .createInstance(CI.nsIIOService); + + let uri = ios.newURI(URI.scheme+'://'+addr, null, null); + + vAPI.httpObserver.operate(channel, uri, topic); + }, + }; + + dns.asyncResolve(URI.host, + CI.nsIDNSService.RESOLVE_CANONICAL_NAME, + listener, + null); + } else { + this.operate(channel, URI, topic); + } + }, asyncOnChannelRedirect: function (oldChannel, newChannel, flags, callback) { // contentPolicy.shouldLoad doesn't detect redirects, this |