Initial import of BugPass
This commit is contained in:
commit
df3554542c
20 files changed
+1588
No files matched your search
@@ -0,0 +1,60 @@
|
||||
# Build-time parts of the bugpass extension (kept out of extension/ so
|
||||
# they are not zipped into the xpi). Returns { lib, host }.
|
||||
{ pkgs, ext ? ../extension }: let
|
||||
lesspass = pkgs.fetchFromGitHub {
|
||||
owner = "lesspass";
|
||||
repo = "lesspass";
|
||||
rev = "d8f29da390d4492a5ea7c106779c93f71aa976ff";
|
||||
hash = "sha256-4BqNYIQFozNEf+XEMdb3uTqjU9JyadadF9DQUIyMtxk=";
|
||||
};
|
||||
core = "${lesspass}/packages/lesspass/src";
|
||||
in {
|
||||
# lesspass.js (bundled LessPass core) + psl.js (Public Suffix List rules), checked against official vectors.
|
||||
lib = pkgs.runCommand "bugpass-lib" { nativeBuildInputs = [ pkgs.esbuild pkgs.nodejs pkgs.python3 ]; } ''
|
||||
mkdir -p $out
|
||||
echo 'export * from "${core}/index.ts"; export { FingerprintIcons } from "${core}/fingerprint/fingerprint.ts";' > entry.ts
|
||||
esbuild entry.ts --bundle --format=esm --target=es2022 --outfile=$out/lesspass.js
|
||||
|
||||
python3 - ${pkgs.publicsuffix-list}/share/publicsuffix/public_suffix_list.dat > $out/psl.js <<'EOF'
|
||||
import json, sys
|
||||
def idna(rule):
|
||||
return ".".join(l if l in ("*", "!") else l.encode("idna").decode() for l in rule.split("."))
|
||||
rules = []
|
||||
for line in open(sys.argv[1], encoding="utf-8"):
|
||||
r = line.split()[0] if line.strip() else ""
|
||||
if r and not r.startswith("//"):
|
||||
bang = r.startswith("!")
|
||||
rules.append(("!" if bang else "") + idna(r.lstrip("!")))
|
||||
print("export default new Set(" + json.dumps(rules, separators=(",", ":")) + ");")
|
||||
EOF
|
||||
|
||||
cp $out/*.js ${ext}/domain.js ${ext}/icons.js ${ext}/background.js . && cp ${./test.mjs} test.mjs && cp ${./test-bg.mjs} test-bg.mjs
|
||||
node test.mjs && node test-bg.mjs
|
||||
'';
|
||||
|
||||
# Native messaging host: stores profiles (never passwords) in $XDG_DATA_HOME/bugpass/profiles.json.
|
||||
host = pkgs.runCommand "bugpass-host" { nativeBuildInputs = [ pkgs.python3 ]; } ''
|
||||
install -Dm755 ${pkgs.writeScript "bugpass-host" "#!${pkgs.python3}/bin/python3\n${builtins.readFile ./host.py}"} $out/bin/bugpass-host
|
||||
mkdir -p $out/lib/mozilla/native-messaging-hosts
|
||||
cat > $out/lib/mozilla/native-messaging-hosts/bugpass.json <<EOF
|
||||
{"name":"bugpass","description":"BugPass profile storage","path":"$out/bin/bugpass-host","type":"stdio","allowed_extensions":["bugpass@local"]}
|
||||
EOF
|
||||
|
||||
# self-test: framed round trip
|
||||
XDG_DATA_HOME=$TMPDIR python3 - $out/bin/bugpass-host <<'EOF'
|
||||
import json, struct, subprocess, sys
|
||||
msgs = [{"cmd": "save", "profile": {"site": "a.org", "login": "me", "lowercase": True, "uppercase": True,
|
||||
"digits": True, "symbols": False, "length": 20, "counter": 2, "password": "nope"}},
|
||||
{"cmd": "save", "profile": {"site": "a.org", "login": "me", "length": 12}},
|
||||
{"cmd": "list"}, {"cmd": "delete", "site": "a.org", "login": "me"}, {"cmd": "list"}]
|
||||
data = b"".join(struct.pack("=I", len(b)) + b for b in (json.dumps(m).encode() for m in msgs))
|
||||
out = subprocess.run([sys.argv[1]], input=data, capture_output=True, check=True).stdout
|
||||
res = []
|
||||
while out:
|
||||
n, = struct.unpack("=I", out[:4]); res.append(json.loads(out[4:4 + n])); out = out[4 + n:]
|
||||
p = res[2]["profiles"]
|
||||
assert len(p) == 1 and p[0]["length"] == 12 and "password" not in p[0], res
|
||||
assert res[4] == {"profiles": []}, res
|
||||
EOF
|
||||
'';
|
||||
}
|
||||
Reference in new issue
Block a user