Initial import of BugPass
This commit is contained in:
commit
df3554542c
20 files changed
+1588
No files matched your search
@@ -0,0 +1,46 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<script type="module" src="autofill.js"></script>
|
||||
</head>
|
||||
<body class="dropdown">
|
||||
<section id="accounts">
|
||||
<ul id="rows" class="items"></ul>
|
||||
</section>
|
||||
|
||||
<form id="prompt" hidden>
|
||||
<div class="row"><b id="who"></b></div>
|
||||
<div class="row master">
|
||||
<input name="master" type="password" placeholder="Master password" autocomplete="off">
|
||||
<span class="fp"></span>
|
||||
</div>
|
||||
<output class="err"></output>
|
||||
</form>
|
||||
|
||||
<form id="create" hidden>
|
||||
<b>New account on <span class="dom"></span></b>
|
||||
<input name="login" placeholder="Username" autocomplete="off">
|
||||
<details>
|
||||
<summary>Options</summary>
|
||||
<div class="row opts">
|
||||
<label><input type="checkbox" name="lowercase">a-z</label>
|
||||
<label><input type="checkbox" name="uppercase">A-Z</label>
|
||||
<label><input type="checkbox" name="digits">0-9</label>
|
||||
<label><input type="checkbox" name="symbols">%!@</label>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Length <input type="number" name="len" min="5" max="35"></label>
|
||||
<label>Counter <input type="number" name="counter" min="1"></label>
|
||||
</div>
|
||||
</details>
|
||||
<div class="row master" id="cmaster" hidden>
|
||||
<input name="master" type="password" placeholder="Master password" autocomplete="off">
|
||||
<span class="fp"></span>
|
||||
</div>
|
||||
<button class="primary">Create</button>
|
||||
<output class="err"></output>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,102 @@
|
||||
import { $, bg, askMaster, fingerprint, readOpts, writeOpts, DEFAULTS, getDomain } from "./common.js";
|
||||
|
||||
const q = new URLSearchParams(location.search), id = q.get("id"), site = getDomain(q.get("host"));
|
||||
const prompt = $("#prompt"), create = $("#create");
|
||||
// Extension frames inside web pages get no `tabs` API in Firefox; background uses sender.tab instead.
|
||||
const relay = (msg) => bg("relay", { msg: { ...msg, id } });
|
||||
const close = (refocus) => relay({ type: "close", refocus });
|
||||
let rows = [], sel = -1, focusEl = null;
|
||||
|
||||
for (const el of document.querySelectorAll(".dom")) el.textContent = site;
|
||||
for (const f of [prompt, create]) fingerprint(f.elements.master, f.querySelector(".fp"));
|
||||
new ResizeObserver(() => relay({ type: "resize", h: Math.ceil(document.documentElement.getBoundingClientRect().height) }))
|
||||
.observe(document.body);
|
||||
|
||||
// switch from the list to a form: pull keyboard focus into the iframe
|
||||
function show(form, el) {
|
||||
$("#accounts").hidden = true;
|
||||
form.hidden = false;
|
||||
focusEl = el;
|
||||
relay({ type: "focus" });
|
||||
el.focus();
|
||||
}
|
||||
addEventListener("focus", () => focusEl?.focus());
|
||||
|
||||
async function fill(profile, toast) {
|
||||
try {
|
||||
const r = await bg("fill", { profile, toast });
|
||||
if (r?.locked) {
|
||||
$("#who").textContent = profile.login || site;
|
||||
show(prompt, prompt.elements.master);
|
||||
await askMaster(prompt, () => {}, () => {});
|
||||
await bg("fill", { profile, toast });
|
||||
}
|
||||
} catch (e) { (prompt.hidden ? create : prompt).querySelector("output").textContent = e.message; }
|
||||
}
|
||||
|
||||
async function newAccount() {
|
||||
writeOpts(create, DEFAULTS);
|
||||
create.elements.login.value = q.get("login") ?? "";
|
||||
$("#cmaster").hidden = (await bg("status")).unlocked;
|
||||
show(create, create.elements.login.value && !$("#cmaster").hidden ? create.elements.master : create.elements.login);
|
||||
}
|
||||
create.onsubmit = async (e) => {
|
||||
e.preventDefault();
|
||||
const out = create.querySelector("output"), m = create.elements.master;
|
||||
try {
|
||||
if (!$("#cmaster").hidden) {
|
||||
if (!m.value) return m.focus();
|
||||
const master = m.value;
|
||||
m.value = "";
|
||||
m.dispatchEvent(new Event("input"));
|
||||
await bg("unlock", { master });
|
||||
}
|
||||
const profile = { site, login: create.elements.login.value.trim(), ...readOpts(create) };
|
||||
await bg("save", { profile });
|
||||
await fill(profile, true);
|
||||
} catch (err) { out.textContent = err.message; }
|
||||
};
|
||||
|
||||
const select = (i) => {
|
||||
sel = (i + rows.length) % rows.length;
|
||||
rows.forEach((li, j) => li.classList.toggle("sel", j === sel));
|
||||
rows[sel].scrollIntoView({ block: "nearest" });
|
||||
};
|
||||
const li = (cls, act, ...kids) => {
|
||||
const el = document.createElement("li");
|
||||
el.className = cls;
|
||||
el.append(...kids);
|
||||
el.onclick = act;
|
||||
el.act = act;
|
||||
return el;
|
||||
};
|
||||
const span = (cls, text) => Object.assign(document.createElement(cls === "b" ? "b" : "span"), { className: cls, textContent: text });
|
||||
|
||||
browser.runtime.onMessage.addListener((m, s) => {
|
||||
if (m.type !== "key" || m.id !== id || s.id !== browser.runtime.id || $("#accounts").hidden || !rows.length) return;
|
||||
if (m.key === "ArrowDown") select(sel + 1);
|
||||
else if (m.key === "ArrowUp") select(sel < 0 ? -1 : sel - 1);
|
||||
else if (m.key === "Enter" && sel >= 0) rows[sel].act();
|
||||
});
|
||||
addEventListener("keydown", (e) => {
|
||||
if (e.key === "Escape") close(true);
|
||||
else if (!$("#accounts").hidden && rows.length && ["ArrowDown", "ArrowUp", "Enter"].includes(e.key)) {
|
||||
e.preventDefault();
|
||||
if (e.key === "Enter") sel >= 0 && rows[sel].act();
|
||||
else select(sel + (e.key === "ArrowDown" ? 1 : -1));
|
||||
}
|
||||
});
|
||||
addEventListener("blur", () => close());
|
||||
|
||||
let profiles = [], err = "";
|
||||
try { profiles = (await bg("list")).profiles.filter((p) => p.site === site); } catch (e) { err = `Native host: ${e.message}`; }
|
||||
const sep = document.createElement("li");
|
||||
sep.className = "sep";
|
||||
rows = [
|
||||
...profiles.map((p) => li("acct", () => fill(p), span("b", p.login || "(no login)"), span("dim", p.site))),
|
||||
...(err ? [li("dim", null, err)] : []),
|
||||
];
|
||||
$("#rows").replaceChildren(...rows, ...(rows.length ? [sep] : []),
|
||||
li("act", newAccount, `Create new account on ${site}…`),
|
||||
li("act", () => { bg("openManager"); close(); }, "Manage accounts"));
|
||||
rows = [...$("#rows").children].filter((el) => el.act);
|
||||
@@ -0,0 +1,3 @@
|
||||
<!doctype html>
|
||||
<meta charset="utf-8">
|
||||
<script type="module" src="background.js"></script>
|
||||
@@ -0,0 +1,79 @@
|
||||
// All password generation happens here. The master password lives only in `master` (RAM):
|
||||
// never stored, hashed, or sent anywhere except into generatePassword/buildFingerprint.
|
||||
import { generatePassword, buildFingerprint } from "./lesspass.js";
|
||||
import { getDomain } from "./domain.js";
|
||||
|
||||
const DEFAULTS = { lowercase: true, uppercase: true, digits: true, symbols: true, length: 16, counter: 1 };
|
||||
const IDLE_MS = 30 * 60 * 1000;
|
||||
const LOCKED = { locked: true };
|
||||
|
||||
let master = null, idleTimer, clipHash = null;
|
||||
const lock = () => { master = null; clearTimeout(idleTimer); };
|
||||
const touch = () => { clearTimeout(idleTimer); idleTimer = setTimeout(lock, IDLE_MS); };
|
||||
const gen = (p) => generatePassword({ ...DEFAULTS, ...p }, master);
|
||||
const sha = async (s) => [...new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(s)))].join();
|
||||
|
||||
const native = async (msg) => {
|
||||
const r = await browser.runtime.sendNativeMessage("bugpass", msg);
|
||||
if (r.error) throw new Error(r.error);
|
||||
return r;
|
||||
};
|
||||
|
||||
// Only our own pages (popup, manager, autofill iframe) may talk to us; content scripts have page URLs.
|
||||
const isExt = (s) => s.id === browser.runtime.id && (s.url ?? "").startsWith(browser.runtime.getURL(""));
|
||||
|
||||
const handlers = {
|
||||
status: () => ({ unlocked: master !== null }),
|
||||
async unlock({ master: m }) {
|
||||
if (typeof m !== "string" || !m) throw new Error("Master password required");
|
||||
master = m;
|
||||
return { unlocked: true, fingerprint: await buildFingerprint(m) };
|
||||
},
|
||||
lock: () => { lock(); return { unlocked: false }; },
|
||||
list: async () => ({ profiles: (await native({ cmd: "list" })).profiles }),
|
||||
save: ({ profile }) => native({ cmd: "save", profile }),
|
||||
delete: ({ site, login }) => native({ cmd: "delete", site, login }),
|
||||
openManager: () => browser.tabs.create({ url: browser.runtime.getURL("manager.html") }).then(() => ({ ok: true })),
|
||||
async fill({ tabId, profile, toast }, sender) {
|
||||
if (!master) return LOCKED;
|
||||
tabId ??= sender.tab?.id; // autofill iframe: its own tab
|
||||
// never hand a password to a page that isn't on the profile's site (tab may have navigated)
|
||||
const tab = await browser.tabs.get(tabId);
|
||||
let host = "";
|
||||
try { host = new URL(tab.url).hostname; } catch {}
|
||||
if (!profile?.site || !host || getDomain(host) !== profile.site) throw new Error(`Tab is not on ${profile?.site}`);
|
||||
const password = await gen(profile);
|
||||
await browser.tabs.sendMessage(tabId, { type: "fill", username: profile.login, password, toast: !!toast }, { frameId: 0 });
|
||||
return { ok: true };
|
||||
},
|
||||
async copy({ profile }) {
|
||||
if (!master) return LOCKED;
|
||||
const pw = await gen(profile);
|
||||
await navigator.clipboard.writeText(pw);
|
||||
const h = clipHash = await sha(pw);
|
||||
// clear after 30s, only if the clipboard still holds this password
|
||||
setTimeout(async () => {
|
||||
if (clipHash === h && await sha(await navigator.clipboard.readText()) === h) await navigator.clipboard.writeText("");
|
||||
}, 30000);
|
||||
return { ok: true };
|
||||
},
|
||||
async reveal({ profile }) {
|
||||
if (!master) return LOCKED;
|
||||
return { password: await gen(profile) };
|
||||
},
|
||||
// autofill iframe -> its tab's top-frame content script (UI-only messages, no secrets)
|
||||
relay({ msg }, sender) {
|
||||
if (sender.tab && ["close", "resize", "focus"].includes(msg?.type))
|
||||
return browser.tabs.sendMessage(sender.tab.id, msg, { frameId: 0 });
|
||||
},
|
||||
};
|
||||
|
||||
export async function onMessage(m, sender) {
|
||||
if (!isExt(sender)) throw new Error("BugPass: forbidden");
|
||||
const r = await handlers[m.type](m, sender);
|
||||
if (master) touch(); // auto-lock after 30 min without use
|
||||
return r;
|
||||
}
|
||||
|
||||
// Unknown types (e.g. "key" broadcasts meant for the autofill iframe) are left for other listeners.
|
||||
browser.runtime.onMessage.addListener((m, s) => (m && Object.hasOwn(handlers, m.type) ? onMessage(m, s) : undefined));
|
||||
@@ -0,0 +1,87 @@
|
||||
import { buildFingerprint } from "./lesspass.js";
|
||||
import { getDomain } from "./domain.js";
|
||||
import { ICONS } from "./icons.js";
|
||||
export { getDomain } from "./domain.js";
|
||||
|
||||
export const DEFAULTS = { lowercase: true, uppercase: true, digits: true, symbols: true, length: 16, counter: 1 };
|
||||
export const $ = (s) => document.querySelector(s);
|
||||
|
||||
// Everything secret goes through background.js; pages only see passwords via reveal.
|
||||
export const bg = (type, data) => browser.runtime.sendMessage({ type, ...data });
|
||||
|
||||
// Show `form` (with input[name=master] + .fp), resolve once background is unlocked.
|
||||
export function askMaster(form, show = () => { form.hidden = false; }, hide = () => { form.hidden = true; }) {
|
||||
show();
|
||||
const input = form.elements.master, out = form.querySelector("output");
|
||||
input.focus();
|
||||
return new Promise((resolve) => {
|
||||
form.onsubmit = async (e) => {
|
||||
e.preventDefault();
|
||||
const master = input.value;
|
||||
input.value = "";
|
||||
input.dispatchEvent(new Event("input"));
|
||||
if (!master) return input.focus();
|
||||
try { await bg("unlock", { master }); } catch (err) { if (out) out.textContent = err.message; return; }
|
||||
hide();
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
// Run a background action; if it reports locked, prompt via `ask()` and retry once.
|
||||
export async function withUnlock(type, data, ask) {
|
||||
let r = await bg(type, data);
|
||||
if (r?.locked) { await ask(); r = await bg(type, data); }
|
||||
return r;
|
||||
}
|
||||
|
||||
export const domainOfTab = (tab) => {
|
||||
try { const u = new URL(tab.url); if (u.protocol.startsWith("http")) return getDomain(u.hostname); } catch {}
|
||||
return "";
|
||||
};
|
||||
|
||||
// Live fingerprint (3 colored glyphs) next to a master password input.
|
||||
export function fingerprint(input, el) {
|
||||
let timer, seq = 0;
|
||||
input.addEventListener("input", () => {
|
||||
clearTimeout(timer);
|
||||
const n = ++seq;
|
||||
if (!input.value) return el.replaceChildren();
|
||||
timer = setTimeout(async () => {
|
||||
const fp = await buildFingerprint(input.value);
|
||||
if (n !== seq) return;
|
||||
el.replaceChildren(...fp.map(({ icon, color }) => {
|
||||
const s = document.createElement("span");
|
||||
s.textContent = ICONS[icon] ?? "?";
|
||||
s.title = icon.slice(3);
|
||||
s.style.background = color;
|
||||
return s;
|
||||
}));
|
||||
}, 300);
|
||||
});
|
||||
}
|
||||
|
||||
// Pull the active browser theme's colors into our CSS vars.
|
||||
export async function applyTheme() {
|
||||
const c = (await browser.theme.getCurrent())?.colors ?? {};
|
||||
const vars = {
|
||||
bg: c.popup, fg: c.popup_text, border: c.popup_border, hl: c.popup_highlight, "hl-fg": c.popup_highlight_text,
|
||||
field: c.toolbar_field, "field-fg": c.toolbar_field_text, "btn-active": c.button_background_active,
|
||||
accent: c.accentcolor ?? c.frame,
|
||||
};
|
||||
for (const [k, v] of Object.entries(vars))
|
||||
if (v) document.documentElement.style.setProperty(`--${k}`, Array.isArray(v) ? `rgb(${v})` : v);
|
||||
}
|
||||
applyTheme().catch(() => {});
|
||||
|
||||
// Options form (a-z, A-Z, 0-9, %!@, length, counter) <-> profile object.
|
||||
export const OPTS = ["lowercase", "uppercase", "digits", "symbols"];
|
||||
export const readOpts = (form) => ({
|
||||
...Object.fromEntries(OPTS.map((k) => [k, form.elements[k].checked])),
|
||||
length: +form.elements.len.value, counter: +form.elements.counter.value,
|
||||
});
|
||||
export const writeOpts = (form, p) => {
|
||||
for (const k of OPTS) form.elements[k].checked = p[k];
|
||||
form.elements.len.value = p.length;
|
||||
form.elements.counter.value = p.counter;
|
||||
};
|
||||
@@ -0,0 +1,89 @@
|
||||
// Anchors the extension-owned autofill.html dropdown under login fields and fills on {fill} from background.
|
||||
// Never sees the master password; only receives a generated password for this page's own site.
|
||||
if (/^(https?|file):$/.test(location.protocol)) {
|
||||
const isPw = (el) => el.type === "password";
|
||||
const isUser = (el) => ["text", "email", ""].includes(el.getAttribute("type") ?? "") || el.type === "email";
|
||||
const pwIn = (root) => [...(root ?? document).querySelectorAll("input[type=password]")];
|
||||
const wanted = (el) => el instanceof HTMLInputElement && !el.readOnly && !el.disabled && (isPw(el) ||
|
||||
(isUser(el) && (/username|email/.test(el.autocomplete) || el.type === "email" || (el.form && pwIn(el.form).length))));
|
||||
// username field: the anchor itself, else the last text/email input before the first password field
|
||||
const userFor = (root, pws, a) => (a && !isPw(a) ? a : pws[0]
|
||||
? [...root.querySelectorAll("input")].filter((el) => isUser(el) && el.compareDocumentPosition(pws[0]) & Node.DOCUMENT_POSITION_FOLLOWING).pop()
|
||||
: document.querySelector("input[autocomplete~=username], input[autocomplete~=email], input[type=email]"));
|
||||
|
||||
let frame, anchor, id = 0, nav = false, skip = null;
|
||||
const send = (m) => browser.runtime.sendMessage({ ...m, id: String(id) }).catch(() => {}); // reaches the iframe directly
|
||||
const place = () => {
|
||||
const r = anchor.getBoundingClientRect();
|
||||
Object.assign(frame.style, { top: `${r.bottom + 2}px`, left: `${r.left}px`, width: `${Math.max(r.width, 280)}px` });
|
||||
};
|
||||
const close = (refocus) => {
|
||||
const a = anchor;
|
||||
frame?.remove();
|
||||
frame = anchor = null;
|
||||
removeEventListener("scroll", place, true);
|
||||
removeEventListener("resize", place);
|
||||
if (refocus && a) { skip = a; a.focus(); }
|
||||
};
|
||||
const open = (el) => {
|
||||
close();
|
||||
anchor = el;
|
||||
nav = false;
|
||||
const root = el.form ?? document, login = userFor(root, pwIn(root), el)?.value ?? "";
|
||||
frame = document.createElement("iframe");
|
||||
frame.src = browser.runtime.getURL(`autofill.html?id=${++id}&host=${encodeURIComponent(location.hostname)}&login=${encodeURIComponent(login)}`);
|
||||
frame.style.cssText = "position:fixed;height:0;border:0;border-radius:8px;z-index:2147483647;" +
|
||||
"box-shadow:0 4px 16px rgba(0,0,0,.3);color-scheme:normal;background:transparent";
|
||||
document.documentElement.append(frame);
|
||||
place();
|
||||
addEventListener("scroll", place, true);
|
||||
addEventListener("resize", place);
|
||||
};
|
||||
|
||||
document.addEventListener("focusin", (e) => {
|
||||
if (!wanted(e.target) || e.target === anchor) return;
|
||||
if (e.target === skip) { skip = null; return; }
|
||||
open(e.target);
|
||||
});
|
||||
document.addEventListener("click", (e) => !frame && wanted(e.target) && open(e.target));
|
||||
document.addEventListener("focusout", (e) => e.target === anchor &&
|
||||
setTimeout(() => document.activeElement !== frame && document.activeElement !== anchor && close(), 150));
|
||||
document.addEventListener("keydown", (e) => {
|
||||
if (!frame || e.target !== anchor) return;
|
||||
if (e.key === "Escape") return close();
|
||||
if (e.key === "ArrowDown" || e.key === "ArrowUp") nav = true;
|
||||
else if (!(e.key === "Enter" && nav)) return;
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
send({ type: "key", key: e.key });
|
||||
}, true);
|
||||
|
||||
const set = (el, v) => {
|
||||
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value").set.call(el, v); // bypass React's tracker
|
||||
for (const t of ["input", "change"]) el.dispatchEvent(new Event(t, { bubbles: true }));
|
||||
};
|
||||
const toast = (text) => {
|
||||
const d = document.createElement("div");
|
||||
d.textContent = text;
|
||||
d.style.cssText = "position:fixed;right:16px;bottom:16px;z-index:2147483647;padding:8px 14px;border-radius:6px;" +
|
||||
"background:#2b2a33;color:#fbfbfe;font:13px system-ui,sans-serif;box-shadow:0 4px 16px rgba(0,0,0,.3)";
|
||||
document.documentElement.append(d);
|
||||
setTimeout(() => d.remove(), 3000);
|
||||
};
|
||||
|
||||
browser.runtime.onMessage.addListener((m, sender) => {
|
||||
if (sender.id !== browser.runtime.id) return;
|
||||
if (m.type === "fill") {
|
||||
const root = anchor?.form ?? pwIn()[0]?.form ?? document, pws = pwIn(root), user = userFor(root, pws, anchor);
|
||||
if (user && m.username) set(user, m.username);
|
||||
for (const el of pws) set(el, m.password); // incl. "confirm password"
|
||||
close();
|
||||
if (m.toast) toast("Saved to BugPass");
|
||||
return;
|
||||
}
|
||||
if (!frame || m.id !== String(id)) return;
|
||||
if (m.type === "close") close(m.refocus);
|
||||
else if (m.type === "resize") frame.style.height = `${Math.min(m.h, 480)}px`;
|
||||
else if (m.type === "focus") frame.focus();
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import rules from "./psl.js";
|
||||
|
||||
// Registrable domain (eTLD+1) per the Public Suffix List algorithm. IPs/single labels returned as-is.
|
||||
export function getDomain(hostname) {
|
||||
const host = hostname.toLowerCase().replace(/\.$/, "");
|
||||
if (!host.includes(".") || host.includes(":") || /^[\d.]+$/.test(host)) return host;
|
||||
const labels = host.split(".");
|
||||
let suffix = 1; // implicit "*" rule
|
||||
for (let i = 0; i < labels.length; i++) { // longest suffix first
|
||||
const s = labels.slice(i).join(".");
|
||||
if (rules.has("!" + s)) { suffix = labels.length - i - 1; break; }
|
||||
if (rules.has(s) || rules.has(["*", ...labels.slice(i + 1)].join("."))) { suffix = labels.length - i; break; }
|
||||
}
|
||||
return suffix >= labels.length ? host : labels.slice(-suffix - 1).join(".");
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// Glyphs for every FontAwesome 4 icon LessPass fingerprints can emit (build test checks coverage).
|
||||
export const ICONS = {
|
||||
"fa-hashtag": "#", "fa-heart": "❤", "fa-hotel": "🏨", "fa-university": "🏛", "fa-plug": "🔌",
|
||||
"fa-ambulance": "🚑", "fa-bus": "🚌", "fa-car": "🚗", "fa-plane": "✈", "fa-rocket": "🚀",
|
||||
"fa-ship": "🚢", "fa-subway": "🚇", "fa-truck": "🚚", "fa-jpy": "¥", "fa-eur": "€",
|
||||
"fa-btc": "₿", "fa-usd": "$", "fa-gbp": "£", "fa-archive": "🗄", "fa-area-chart": "📈",
|
||||
"fa-bed": "🛏", "fa-beer": "🍺", "fa-bell": "🔔", "fa-binoculars": "🔭", "fa-birthday-cake": "🎂",
|
||||
"fa-bomb": "💣", "fa-briefcase": "💼", "fa-bug": "🐛", "fa-camera": "📷", "fa-cart-plus": "🛒",
|
||||
"fa-certificate": "📜", "fa-coffee": "☕", "fa-cloud": "☁", "fa-comment": "💬", "fa-cube": "📦",
|
||||
"fa-cutlery": "🍴", "fa-database": "🛢", "fa-diamond": "💎", "fa-exclamation-circle": "❗", "fa-eye": "👁",
|
||||
"fa-flag": "🚩", "fa-flask": "🧪", "fa-futbol-o": "⚽", "fa-gamepad": "🎮", "fa-graduation-cap": "🎓",
|
||||
};
|
||||
@@ -0,0 +1,65 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>BugPass</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<script type="module" src="manager.js"></script>
|
||||
</head>
|
||||
<body class="manager">
|
||||
<header class="row topbar">
|
||||
<b class="grow">BugPass</b>
|
||||
<span id="state" class="dim"></span>
|
||||
<button id="lock"></button>
|
||||
</header>
|
||||
<main>
|
||||
<aside>
|
||||
<input id="search" type="search" placeholder="Search accounts" autofocus>
|
||||
<button id="new" class="primary">New account</button>
|
||||
<ul id="list" class="items"></ul>
|
||||
</aside>
|
||||
|
||||
<section id="view" hidden>
|
||||
<h2 id="title"></h2>
|
||||
<label>Website</label>
|
||||
<a id="site" target="_blank" rel="noopener"></a>
|
||||
<label>Username</label>
|
||||
<div class="row"><span id="login" class="grow"></span><button id="copyLogin">Copy</button></div>
|
||||
<label>Password</label>
|
||||
<div class="row"><span id="pw" class="grow mono">••••••••</span><button id="reveal" title="Reveal">👁</button><button id="copyPw">Copy</button></div>
|
||||
<div class="row"><button id="edit">Edit</button><button id="remove">Remove</button></div>
|
||||
<output id="out"></output>
|
||||
</section>
|
||||
|
||||
<form id="editor" hidden>
|
||||
<h2 id="etitle"></h2>
|
||||
<label>Website <input name="site" placeholder="example.org" required></label>
|
||||
<label>Username <input name="login" placeholder="Username"></label>
|
||||
<div class="row opts">
|
||||
<label><input type="checkbox" name="lowercase">a-z</label>
|
||||
<label><input type="checkbox" name="uppercase">A-Z</label>
|
||||
<label><input type="checkbox" name="digits">0-9</label>
|
||||
<label><input type="checkbox" name="symbols">%!@</label>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Length <input type="number" name="len" min="5" max="35"></label>
|
||||
<label>Counter <input type="number" name="counter" min="1"></label>
|
||||
</div>
|
||||
<div class="row"><button class="primary">Save</button><button type="button" id="cancel">Cancel</button></div>
|
||||
<output class="err"></output>
|
||||
</form>
|
||||
</main>
|
||||
|
||||
<dialog id="dlg">
|
||||
<form id="prompt">
|
||||
<b>Unlock BugPass</b>
|
||||
<div class="row master">
|
||||
<input name="master" type="password" placeholder="Master password" autocomplete="off">
|
||||
<span class="fp"></span>
|
||||
</div>
|
||||
<div class="row"><button class="primary">Unlock</button><button type="button" id="dlgCancel">Cancel</button></div>
|
||||
<output class="err"></output>
|
||||
</form>
|
||||
</dialog>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,96 @@
|
||||
import { $, bg, askMaster, withUnlock, fingerprint, readOpts, writeOpts, DEFAULTS, getDomain } from "./common.js";
|
||||
|
||||
const dlg = $("#dlg"), prompt = $("#prompt"), editor = $("#editor"), out = $("#out");
|
||||
fingerprint(prompt.elements.master, prompt.querySelector(".fp"));
|
||||
$("#dlgCancel").onclick = () => dlg.close();
|
||||
const ask = () => askMaster(prompt, () => dlg.showModal(), () => dlg.close()).then(state);
|
||||
const say = (t, err) => { out.textContent = t; out.className = err ? "err" : ""; };
|
||||
const hidePw = () => { $("#pw").textContent = "••••••••"; $("#reveal").title = "Reveal"; };
|
||||
let profiles = [], cur = null;
|
||||
|
||||
async function state() {
|
||||
const { unlocked } = await bg("status");
|
||||
$("#state").textContent = unlocked ? "🔓 Unlocked" : "🔒 Locked";
|
||||
$("#lock").textContent = unlocked ? "Lock" : "Unlock";
|
||||
$("#lock").onclick = unlocked ? () => { hidePw(); bg("lock").then(state); } : ask;
|
||||
}
|
||||
|
||||
function renderList() {
|
||||
const q = $("#search").value.toLowerCase();
|
||||
$("#list").replaceChildren(...profiles
|
||||
.filter((p) => `${p.site} ${p.login}`.toLowerCase().includes(q))
|
||||
.sort((a, b) => a.site.localeCompare(b.site) || a.login.localeCompare(b.login))
|
||||
.map((p) => {
|
||||
const li = document.createElement("li");
|
||||
li.tabIndex = 0;
|
||||
li.classList.toggle("sel", p === cur);
|
||||
li.append(Object.assign(document.createElement("b"), { textContent: p.site }),
|
||||
Object.assign(document.createElement("span"), { className: "dim", textContent: p.login || "(no login)" }));
|
||||
li.onclick = li.onkeydown = (e) => (e.type === "click" || e.key === "Enter") && view(p);
|
||||
return li;
|
||||
}));
|
||||
}
|
||||
|
||||
async function refresh(keep) {
|
||||
try { profiles = (await bg("list")).profiles; } catch (e) { $("#list").textContent = `Native host: ${e.message}`; return; }
|
||||
cur = keep && profiles.find((p) => p.site === keep.site && p.login === keep.login) || null;
|
||||
renderList();
|
||||
cur ? view(cur) : ($("#view").hidden = true);
|
||||
}
|
||||
|
||||
function view(p) {
|
||||
cur = p;
|
||||
hidePw();
|
||||
say("");
|
||||
$("#title").textContent = p.site;
|
||||
$("#site").textContent = p.site;
|
||||
$("#site").href = `https://${p.site}`;
|
||||
$("#login").textContent = p.login || "(no login)";
|
||||
editor.hidden = true;
|
||||
$("#view").hidden = false;
|
||||
renderList();
|
||||
}
|
||||
|
||||
function edit(p) {
|
||||
editor.elements.site.value = p?.site ?? "";
|
||||
editor.elements.login.value = p?.login ?? "";
|
||||
writeOpts(editor, { ...DEFAULTS, ...p });
|
||||
$("#etitle").textContent = p ? `Edit ${p.site}` : "New account";
|
||||
editor.querySelector("output").textContent = "";
|
||||
$("#view").hidden = true;
|
||||
editor.hidden = false;
|
||||
editor.elements[p ? "login" : "site"].focus();
|
||||
}
|
||||
|
||||
const act = (fn) => async () => { try { await fn(); } catch (e) { say(e.message, true); } };
|
||||
$("#search").oninput = renderList;
|
||||
$("#new").onclick = () => { cur = null; renderList(); edit(null); };
|
||||
$("#edit").onclick = () => edit(cur);
|
||||
$("#cancel").onclick = () => (cur ? view(cur) : (editor.hidden = true));
|
||||
$("#copyLogin").onclick = act(async () => { await navigator.clipboard.writeText(cur.login); say("Username copied"); });
|
||||
$("#copyPw").onclick = act(async () => { await withUnlock("copy", { profile: cur }, ask); say("Password copied — clears in 30s"); });
|
||||
$("#reveal").onclick = act(async () => {
|
||||
if ($("#reveal").title === "Hide") return hidePw();
|
||||
$("#pw").textContent = (await withUnlock("reveal", { profile: cur }, ask)).password;
|
||||
$("#reveal").title = "Hide";
|
||||
});
|
||||
$("#remove").onclick = act(async () => {
|
||||
if (!confirm(`Remove ${cur.login || "(no login)"} on ${cur.site}?`)) return;
|
||||
await bg("delete", { site: cur.site, login: cur.login });
|
||||
refresh();
|
||||
});
|
||||
editor.onsubmit = async (e) => {
|
||||
e.preventDefault();
|
||||
const raw = editor.elements.site.value.trim();
|
||||
let host = raw;
|
||||
try { host = new URL(raw.includes("://") ? raw : `https://${raw}`).hostname; } catch {}
|
||||
const p = { site: getDomain(host), login: editor.elements.login.value.trim(), ...readOpts(editor) };
|
||||
try {
|
||||
await bg("save", { profile: p });
|
||||
if (cur && (cur.site !== p.site || cur.login !== p.login)) await bg("delete", { site: cur.site, login: cur.login });
|
||||
refresh(p);
|
||||
} catch (err) { editor.querySelector("output").textContent = err.message; }
|
||||
};
|
||||
addEventListener("focus", state);
|
||||
state();
|
||||
refresh();
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"manifest_version": 2,
|
||||
"name": "BugPass",
|
||||
"version": "2.1",
|
||||
"description": "Stateless LessPass-compatible password manager",
|
||||
"browser_specific_settings": { "gecko": { "id": "bugpass@local" } },
|
||||
"permissions": ["nativeMessaging", "tabs", "clipboardRead", "clipboardWrite", "theme"],
|
||||
"background": { "page": "background.html" },
|
||||
"browser_action": { "default_title": "BugPass", "default_popup": "popup.html" },
|
||||
"content_scripts": [{ "matches": ["<all_urls>"], "js": ["content.js"], "run_at": "document_idle" }],
|
||||
"web_accessible_resources": ["autofill.html"]
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<script type="module" src="popup.js"></script>
|
||||
</head>
|
||||
<body class="popup">
|
||||
<header class="row">
|
||||
<b id="dom" class="grow"></b>
|
||||
<span id="state" class="dim"></span>
|
||||
<button id="lock"></button>
|
||||
</header>
|
||||
<ul id="accounts" class="items"></ul>
|
||||
<form id="prompt" hidden>
|
||||
<div class="row master">
|
||||
<input name="master" type="password" placeholder="Master password" autocomplete="off">
|
||||
<span class="fp"></span>
|
||||
</div>
|
||||
<output class="err"></output>
|
||||
</form>
|
||||
<output id="out"></output>
|
||||
<button id="manager">Open manager</button>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,35 @@
|
||||
import { $, bg, askMaster, withUnlock, fingerprint, domainOfTab } from "./common.js";
|
||||
|
||||
const prompt = $("#prompt"), out = $("#out");
|
||||
fingerprint(prompt.elements.master, prompt.querySelector(".fp"));
|
||||
const [tab] = await browser.tabs.query({ active: true, currentWindow: true });
|
||||
const site = domainOfTab(tab);
|
||||
const say = (t, err) => { out.textContent = t; out.className = err ? "err" : ""; };
|
||||
const ask = () => askMaster(prompt).then(state);
|
||||
|
||||
async function state() {
|
||||
const { unlocked } = await bg("status");
|
||||
$("#state").textContent = unlocked ? "Unlocked" : "Locked";
|
||||
$("#lock").textContent = unlocked ? "Lock" : "Unlock";
|
||||
$("#lock").onclick = unlocked ? () => bg("lock").then(state) : ask;
|
||||
}
|
||||
|
||||
const btn = (text, fn) => Object.assign(document.createElement("button"), { textContent: text, onclick: fn });
|
||||
const act = (fn) => async () => { try { await fn(); } catch (e) { say(e.message, true); } };
|
||||
|
||||
$("#dom").textContent = site || "No site";
|
||||
$("#manager").onclick = () => { browser.tabs.create({ url: browser.runtime.getURL("manager.html") }); close(); };
|
||||
state();
|
||||
try {
|
||||
const profiles = site ? (await bg("list")).profiles.filter((p) => p.site === site) : [];
|
||||
$("#accounts").replaceChildren(...profiles.map((p) => {
|
||||
const li = document.createElement("li");
|
||||
li.className = "row";
|
||||
li.append(Object.assign(document.createElement("span"), { className: "grow", textContent: p.login || "(no login)" }),
|
||||
btn("Fill", act(async () => { await withUnlock("fill", { tabId: tab.id, profile: p }, ask); close(); })),
|
||||
btn("Copy user", act(async () => { await navigator.clipboard.writeText(p.login); say("Username copied"); })),
|
||||
btn("Copy pass", act(async () => { await withUnlock("copy", { profile: p }, ask); say("Password copied — clears in 30s"); })));
|
||||
return li;
|
||||
}));
|
||||
if (site && !profiles.length) say(`No accounts for ${site}`);
|
||||
} catch (e) { say(`Native host: ${e.message}`, true); }
|
||||
@@ -0,0 +1,55 @@
|
||||
:root {
|
||||
color-scheme: light dark;
|
||||
--bg: Canvas; --fg: CanvasText; --border: ButtonBorder;
|
||||
--hl: AccentColor; --hl-fg: AccentColorText;
|
||||
--field: Field; --field-fg: FieldText;
|
||||
--btn: ButtonFace; --btn-active: ButtonBorder; --accent: AccentColor;
|
||||
font: 13px system-ui, sans-serif;
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
body { margin: 0; padding: 8px; background: var(--bg); color: var(--fg); }
|
||||
body.popup { width: 320px; }
|
||||
body.dropdown { border: 1px solid var(--border); border-radius: 8px; padding: 4px; }
|
||||
section, form { display: flex; flex-direction: column; gap: 6px; }
|
||||
[hidden] { display: none !important; }
|
||||
.row { display: flex; gap: 6px; align-items: center; }
|
||||
.row > input:not([type=checkbox]) { flex: 1; min-width: 0; }
|
||||
.opts label, .row label { display: flex; align-items: center; gap: 3px; }
|
||||
input:not([type=checkbox]), button {
|
||||
font: inherit; color: var(--field-fg); background: var(--field);
|
||||
border: 1px solid var(--border); border-radius: 4px; padding: 4px 6px;
|
||||
}
|
||||
input[type=number] { width: 4.5em; }
|
||||
button { background: var(--btn); color: var(--fg); cursor: pointer; }
|
||||
button:active { background: var(--btn-active); }
|
||||
button.primary { background: var(--accent); color: var(--hl-fg); border-color: transparent; }
|
||||
input:focus-visible, button:focus-visible, li:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }
|
||||
.items { list-style: none; margin: 0; padding: 0; max-height: 300px; overflow: auto; }
|
||||
.items li { padding: 5px 6px; border-radius: 4px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.items li:hover, .items li:focus, .items li.sel { background: var(--hl); color: var(--hl-fg); }
|
||||
.items li.sep { height: 0; padding: 0; margin: 4px 0; border-top: 1px solid var(--border); background: none !important; cursor: default; }
|
||||
.items li.acct { display: flex; flex-direction: column; }
|
||||
.items li.row { cursor: default; }
|
||||
.items li.row:hover { background: none; color: inherit; }
|
||||
.items li.row button { padding: 2px 6px; }
|
||||
.dim { opacity: .65; font-size: 12px; }
|
||||
.grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
||||
.mono { font-family: ui-monospace, monospace; user-select: all; word-break: break-all; }
|
||||
details summary { cursor: pointer; padding: 2px 0; }
|
||||
details[open] { display: flex; flex-direction: column; gap: 6px; }
|
||||
dialog { background: var(--bg); color: var(--fg); border: 1px solid var(--border); border-radius: 8px; width: 340px; }
|
||||
body.manager { padding: 0; height: 100vh; display: flex; flex-direction: column; font-size: 14px; }
|
||||
.topbar { padding: 8px 16px; border-bottom: 1px solid var(--border); }
|
||||
main { flex: 1; display: flex; min-height: 0; }
|
||||
aside { width: 300px; padding: 12px; border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
|
||||
aside .items { max-height: none; flex: 1; }
|
||||
aside .items li { display: flex; flex-direction: column; }
|
||||
#view, #editor { padding: 16px 32px; max-width: 560px; flex: 1; display: flex; flex-direction: column; gap: 6px; }
|
||||
#view > label { margin-top: 10px; opacity: .65; font-size: 12px; }
|
||||
#editor label:not(.opts label) { display: flex; flex-direction: column; gap: 3px; }
|
||||
h2 { margin: 0 0 6px; font-weight: 600; }
|
||||
a { color: var(--accent); }
|
||||
.fp { display: flex; gap: 2px; min-width: 66px; }
|
||||
.fp span { width: 20px; height: 20px; border-radius: 4px; display: grid; place-items: center; font-size: 12px; color: #fff; }
|
||||
output { font-family: ui-monospace, monospace; word-break: break-all; user-select: all; }
|
||||
output.err { font-family: inherit; color: #d70022; user-select: none; }
|
||||
Reference in new issue
Block a user