Commit bdf686af authored by Jiří Helebrant's avatar Jiří Helebrant

temp commit

parent 6617a300
{
"supportedProtocols": ["http", "https", "ws", "wss"],
"domains": {
"badRsa": "bad-rsa.test-ipv6.nic.cz",
"badEcdsa": "bad-ecdsa.test-ipv6.nic.cz"
},
"supportedProtocols": ["http:", "https:", "ws:", "wss:", "ftp:", "ftps:"],
"tlsDns": [
{ "name": "CloudFlare", "url": "https://cloudflare-dns.com/dns-query" },
{ "name": "Google", "url": "https://dns.google.com/resolve" },
{ "name": "Quad9", "url": "https://dns9.quad9.net/dns-query" }
],
"defaultTTL": 1200,
"blockInvalid": true,
"blockUnsigned": false,
"resolverStatus": {
"maxAge": 1200,
"cacheKey": "resolver_status"
},
"colors": {
"red": "#ff2600",
"green": "#00ff6a",
"yellow": "#ffb200",
"stroke": "#666",
"badgeBg": "#666",
"badgeText": "#fff"
},
"dnssecWhitelist": [
"bad-rsa.test-ipv6.nic.cz",
"bad-ecdsa.test-ipv6.nic.cz",
"bad.udp53.cz"
]
"defaultSettings": {
"dnssecDomains": {
"badRsa": "bad-rsa.test-ipv6.nic.cz",
"badEcdsa": "bad-ecdsa.test-ipv6.nic.cz"
},
"dnssecWhitelist": [
"bad-rsa.test-ipv6.nic.cz",
"bad-ecdsa.test-ipv6.nic.cz",
"bad.udp53.cz"
],
"colors": {
"red": "#ff2600",
"green": "#00ff6a",
"yellow": "#ffb200",
"outline": "#6a6a6a",
"badgeBg": "#666",
"badgeText": "#fff"
},
"blockInvalid": true,
"blockUnsigned": false,
"tlsDns": "https://cloudflare-dns.com/dns-query",
"cacheTime": {
"resolver": 60,
"domain": 60
}
}
}
......@@ -29,6 +29,7 @@
"options_ui": {
"page": "pages/options.html"
},
"persistent": true,
"permissions": [
"storage",
"dns",
......
......@@ -8,9 +8,7 @@
<body>
<form>
<section class="form-section">
<label
><input type="checkbox" name="showAdvanced" /> show advanced options</label
>
<label><input type="checkbox" name="showAdvanced" /> show advanced options</label>
</section>
<section class="form-section">
<h3>Request blocking</h3>
......
......@@ -2,10 +2,13 @@ import { updateIcon } from './lib/icon'
import { processRequest } from './lib/requests'
import { clearTabData } from './lib/tabs'
import { memoryStore } from './lib/storage'
import settingsStore from './lib/settings'
browser.runtime.onInstalled.addListener(details => {
browser.runtime.onInstalled.addListener(async details => {
memoryStore.init()
console.log('previousVersion', details.previousVersion)
settingsStore.init()
// console.log('SETTINGS', await settingsStore.getAll())
// console.log('VERSION', await settingsStore.get('version'))
})
browser.tabs.onUpdated.addListener(updateIcon)
......@@ -21,3 +24,5 @@ browser.tabs.onRemoved.addListener(tabId => clearTabData(tabId))
browser.webRequest.onBeforeRequest.addListener(processRequest,
{ urls: ['<all_urls>'] }, ['blocking']
)
// browser.webRequest.onHeadersReceived.addListener(rStarted, { urls: ['<all_urls>'] })
import config from '../../config.json'
import storage from './storage'
const dnsUrl = config.tlsDns[0].url
// import settingsStore from './settings'
import config from '../../config.json'
const getTTL = j =>
j.hasOwnProperty('Answer') && j['Answer'].length > 0 && j['Answer'][0].hasOwnProperty('TTL')
? j['Answer'][0]['TTL']
: config.defaultTTL
? Math.max(j['Answer'][0]['TTL'], 15)
: config.defaultSettings.cacheTime.domain
const resolveDnssecStatus = async hostname =>
fetch(`${dnsUrl}?name=${hostname}&cd=0`, {
fetch(`${config.tlsDns[0].url}?name=${hostname}&cd=0`, {
// https://developers.cloudflare.com/1.1.1.1/dns-over-https/json-format/
headers: { accept: 'application/dns-json' }
})
......@@ -18,14 +17,13 @@ const resolveDnssecStatus = async hostname =>
const status = j['Status']
const verified = j['AD']
const ttl = getTTL(j)
// const ttl = config.defaultTTL
// https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-6
if (status === 0 && verified === true) return { dnssec: true, valid: true, ttl } // valid dnssec
if (status === 0 && verified === false) return { dnssec: false, ttl } // no dnssec
if (status === 2) return { dnssec: true, valid: false, ttl } // broken dnssec
if (status === 1 || status > 3) return { dnssec: false, ttl }
})
.catch(() => ({ dnssec: false, ttl: config.defaultTTL }))
.catch(async () => ({ dnssec: false, ttl: config.defaultSettings.cacheTime.domain }))
const updateDomainStatus = async hostname => {
const status = {
......@@ -45,9 +43,10 @@ const getDomainStatus = async hostname => {
return result.status
}
console.log('domain outdated:', hostname, `${age} >= ${result.status.ttl}`)
return updateDomainStatus(hostname)
updateDomainStatus(hostname)
return result.status
}
return updateDomainStatus(hostname)
}
export { getDomainStatus, dnsUrl }
export { getDomainStatus }
import config from '../../config.json'
import { getActiveTabId } from './tabs'
import { getResolverStatus } from './resolver'
import storage from './storage'
import { getDomainStatus } from './domain'
import config from '../../config.json'
// import settingsStore from './settings'
const getResolverIconColor = async () => {
const status = await getResolverStatus()
// const colors = await settingsStore.get('colors')
const colors = config.defaultSettings.colors
if (status.rsa && status.ecdsa) {
return config.colors.green
return colors.green
}
if (status.rsa || status.ecdsa) {
return config.colors.yellow
return colors.yellow
}
if (!status.rsa && !status.ecdsa) {
return config.colors.red
return colors.red
}
}
......@@ -40,21 +44,23 @@ const getTabIconColor = async tabId => {
}
const domains = await storage('tabDomains', 'get', { id: tabId })
// const colors = await settingsStore.get('colors')
const colors = config.defaultSettings.colors
if (domains && domains.length > 0) {
const { invalid, unsigned } = await getDomainStatusCount(domains)
if (invalid > 0) {
return config.colors.red
return colors.red
}
if (unsigned === 0 && invalid === 0) {
return config.colors.green
return colors.green
}
return config.colors.outline
return colors.outline
}
return config.colors.outline
return colors.outline
}
const drawTabStatus = (ctx, color) => {
......@@ -118,6 +124,8 @@ const drawResolverStatus = (ctx, color) => {
}
const drawIcon = async tabId => {
// const colors = await settingsStore.get('colors')
const colors = config.defaultSettings.colors
const canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d')
......@@ -139,7 +147,7 @@ const updateIcon = async () => {
const tabId = await getActiveTabId()
browser.browserAction.setIcon({ imageData: await drawIcon(tabId) })
const count = await storage('tabCounters', 'get', { id: tabId })
console.log('COUNT', count)
if (count === undefined || count === 0) {
browser.browserAction.setBadgeText({ text: '' })
} else {
......
import config from '../../config.json'
import storage from '../lib/storage'
import { getDomainStatus, dnsUrl } from './domain'
import { getDomainStatus } from './domain'
import { updateIcon } from './icon'
import Url from 'url-parse'
// import settingsStore from './settings'
const dnsHost = new Url(dnsUrl).hostname
const protocols = ['http:', 'https:', 'ws:', 'wss:', 'ftp:', 'ftps:']
const protocols = config.supportedProtocols
const dnsHost = new Url(config.tlsDns[0].url).hostname
const blockRequest = async tabId => {
await storage('tabCounters', 'inc', { id: tabId })
updateIcon()
return { cancel: true }
// return { cancel: false }
}
const processRequest = async requestDetails => {
// const blockUnsigned = await settingsStore.get('blockUnsigned')
// const blockInvalid = await settingsStore.get('blockInvalid')
const blockUnsigned = false
const blockInvalid = true
const url = new Url(requestDetails.url)
if (url.hostname && url.hostname !== dnsHost && protocols.includes(url.protocol)) {
if (
requestDetails.originUrl &&
requestDetails.originUrl.startsWith('moz-extension://')
) {
return { cancel: false }
}
if (
url.hostname &&
url.hostname !== dnsHost &&
protocols.includes(url.protocol)
) {
storage('tabDomains', 'add', { id: requestDetails.tabId, hostname: url.hostname })
const status = await getDomainStatus(url.hostname)
if (config.blockUnsigned) {
if (status !== undefined && blockUnsigned) {
if (!status.dnssec || !status.valid) {
return blockRequest(requestDetails.tabId)
}
return { cancel: false }
}
if (config.blockInvalid) {
if (status !== undefined && blockInvalid) {
if (status.dnssec && !status.valid) {
return blockRequest(requestDetails.tabId)
}
......@@ -34,4 +52,6 @@ const processRequest = async requestDetails => {
}
}
export { processRequest }
const rStarted = requestDetails => console.log(requestDetails.url, requestDetails.ip)
export { processRequest, rStarted }
......@@ -26,7 +26,8 @@ const getResolverStatus = async () => {
const age = +new Date() - result.timestamp
const cacheTime = config.defaultSettings.cacheTime.resolver
if (age > cacheTime * 1000) {
return updateResolverStatus()
updateResolverStatus()
return result
}
return result
}
......
import config from '../../config.json'
const settingsStore = {
init: async () => {
const settings = await browser.storage.sync.get()
if (!settings.version) {
console.log('INIT SETTINGS')
const version = browser.runtime.getManifest().version
const defaults = { ...config.defaultSettings, version }
await browser.storage.sync.set(defaults)
return defaults
}
return settings
},
save: settings => {
const version = browser.runtime.getManifest().version
browser.storage.sync.set({ ...settings, version })
},
getAll: async () => browser.storage.sync.get(),
get: async key => {
const settings = await browser.storage.sync.get()
return settings[key]
},
reset: () => {
const version = browser.runtime.getManifest().version
const defaults = { version, ...config.defaultSettings }
browser.storage.sync.set(defaults)
}
}
export default settingsStore
import '../styles/options.scss'
const initOptionsPage = () => {}
const createButton = (type, text, onclick) => {
const button = document.createElement('button')
button.type = type
button.innerText = text
if (onclick) {
button.addEventListener('click', onclick)
}
return button
}
const saveOptions = event => {
event.preventDefault()
console.log('saVE')
}
const initOptionsPage = settings => {
const form = document.querySelector('form')
form.innerHTML = ''
form.addEventListener('submit', saveOptions)
form.appendChild(createButton('submit', 'Save'))
form.appendChild(createButton('button', 'Reset to defaults', () => console.log('reset')))
}
document.addEventListener('DOMContentLoaded', initOptionsPage)
......@@ -29,7 +29,7 @@ table {
td {
white-space: nowrap;
text-align: center;
text-align: right;
&:first-child {
text-align: left;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment