Compare commits
2 commits
1b3435ec86
...
9bddae5f11
Author | SHA1 | Date | |
---|---|---|---|
Simon Bruder | 9bddae5f11 | ||
Simon Bruder | 5e49335c2c |
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -1,6 +1,7 @@
|
|||
# Rust
|
||||
/backend/target/
|
||||
/backend/pkg/
|
||||
/target/
|
||||
/pkg/
|
||||
/dist/
|
||||
|
||||
# Nix
|
||||
/result*
|
||||
|
|
46
backend/Cargo.lock → Cargo.lock
generated
46
backend/Cargo.lock → Cargo.lock
generated
|
@ -119,12 +119,6 @@ dependencies = [
|
|||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.126"
|
||||
|
@ -151,6 +145,12 @@ dependencies = [
|
|||
"opaque-debug",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
|
||||
|
||||
[[package]]
|
||||
name = "opaque-debug"
|
||||
version = "0.3.0"
|
||||
|
@ -174,9 +174,9 @@ checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
|
|||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.40"
|
||||
version = "1.0.71"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7"
|
||||
checksum = "75cb1540fadbd5b8fbccc4dddad2734eba435053f725621c070711a14bb5f4b8"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
@ -198,9 +198,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.20"
|
||||
version = "1.0.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804"
|
||||
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
@ -269,9 +269,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.98"
|
||||
version = "2.0.43"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd"
|
||||
checksum = "ee659fb5f3d355364e1f3e5bc10fb82068efbf824a1e9d1c9504244a6469ad53"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -304,9 +304,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
|||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.81"
|
||||
version = "0.2.89"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7c53b543413a17a202f4be280a7e5c62a1c69345f5de525ee64f8cfdbc954994"
|
||||
checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"wasm-bindgen-macro",
|
||||
|
@ -314,13 +314,13 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-backend"
|
||||
version = "0.2.81"
|
||||
version = "0.2.89"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5491a68ab4500fa6b4d726bd67408630c3dbe9c4fe7bda16d5c82a1fd8c7340a"
|
||||
checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
|
@ -329,9 +329,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.81"
|
||||
version = "0.2.89"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c441e177922bc58f1e12c022624b6216378e5febc2f0533e41ba443d505b80aa"
|
||||
checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
|
@ -339,9 +339,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.81"
|
||||
version = "0.2.89"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048"
|
||||
checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -352,6 +352,6 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.81"
|
||||
version = "0.2.89"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be"
|
||||
checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f"
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "password-hash-self-service-backend"
|
||||
name = "password-hash-self-service"
|
||||
version = "0.0.0"
|
||||
authors = ["Simon Bruder <simon@sbruder.de>"]
|
||||
license = "AGPL-3.0-or-later"
|
2
Trunk.toml
Normal file
2
Trunk.toml
Normal file
|
@ -0,0 +1,2 @@
|
|||
[build]
|
||||
offline = true
|
8
app.js
8
app.js
|
@ -1,5 +1,3 @@
|
|||
import init, { hash_bcrypt, hash_sha512crypt } from "./backend/pkg/password_hash_self_service_backend.js"
|
||||
|
||||
function displayHash(hash) {
|
||||
document.getElementById("hash").innerText = hash
|
||||
document.getElementById("hash-container").classList.add("done")
|
||||
|
@ -31,17 +29,15 @@ function getHashSetup(formData) {
|
|||
function getHasher(hashType) {
|
||||
switch (hashType) {
|
||||
case "bcrypt":
|
||||
return (password, { cost }) => hash_bcrypt(password, cost)
|
||||
return (password, { cost }) => wasmBindings.hash_bcrypt(password, cost)
|
||||
case "sha512crypt":
|
||||
return (password, { rounds }) => hash_sha512crypt(password, rounds)
|
||||
return (password, { rounds }) => wasmBindings.hash_sha512crypt(password, rounds)
|
||||
default:
|
||||
throw Error("Invalid hash type specified: " + hashType)
|
||||
}
|
||||
}
|
||||
|
||||
(async () => {
|
||||
await init()
|
||||
|
||||
document.getElementById("generate").addEventListener("click", e => {
|
||||
e.target.disabled = true
|
||||
const buttonText = e.target.innerText
|
||||
|
|
42
flake.lock
42
flake.lock
|
@ -1,12 +1,15 @@
|
|||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1656928814,
|
||||
"narHash": "sha256-RIFfgBuKz6Hp89yRr7+NR5tzIAbn52h8vT6vXkYjZoM=",
|
||||
"lastModified": 1701680307,
|
||||
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "7e2a3b3dfd9af950a856d66b0a7d01e3c18aa249",
|
||||
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -22,11 +25,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1655042882,
|
||||
"narHash": "sha256-9BX8Fuez5YJlN7cdPO63InoyBy7dm3VlJkkmTt6fS1A=",
|
||||
"lastModified": 1698420672,
|
||||
"narHash": "sha256-/TdeHMPRjjdJub7p7+w55vyABrsJlt5QkznPYy55vKA=",
|
||||
"owner": "nmattia",
|
||||
"repo": "naersk",
|
||||
"rev": "cddffb5aa211f50c4b8750adbec0bbbdfb26bb9f",
|
||||
"rev": "aeb58d5e8faead8980a807c840232697982d47b9",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -37,11 +40,11 @@
|
|||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1657802959,
|
||||
"narHash": "sha256-9+JWARSdlL8KiH3ymnKDXltE1vM+/WEJ78F5B1kjXys=",
|
||||
"lastModified": 1703438236,
|
||||
"narHash": "sha256-aqVBq1u09yFhL7bj1/xyUeJjzr92fXVvQSSEx6AdB1M=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "4a01ca36d6bfc133bc617e661916a81327c9bbc8",
|
||||
"rev": "5f64a12a728902226210bf01d25ec6cbb9d9265b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -69,11 +72,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1657939629,
|
||||
"narHash": "sha256-8lX/pZNetbLCN2cW/O+vUz1rG8ig4RaVX5PWe5m4VLA=",
|
||||
"lastModified": 1703729606,
|
||||
"narHash": "sha256-5QlUMNPKv++mWlS2r3F8bffoSBHXq1qHg+V5mnfSixg=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "2cd36d4aef875867ee1d7963541ccb3ae50b358c",
|
||||
"rev": "347789ef125df15b685e8295364ad8ed331fef94",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -81,6 +84,21 @@
|
|||
"repo": "rust-overlay",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
|
|
61
flake.nix
61
flake.nix
|
@ -16,22 +16,23 @@
|
|||
let
|
||||
overlays = [
|
||||
rust-overlay.overlays.default
|
||||
(final: prev: {
|
||||
rustc = final.rust-bin.stable.latest.default.override { targets = [ "wasm32-unknown-unknown" ]; };
|
||||
cargo = final.rust-bin.stable.latest.default.override { targets = [ "wasm32-unknown-unknown" ]; };
|
||||
})
|
||||
];
|
||||
pkgs = import nixpkgs { inherit system overlays; };
|
||||
naerskLib = pkgs.callPackage naersk { };
|
||||
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
|
||||
naerskLib = pkgs.callPackage naersk {
|
||||
rustc = rustToolchain;
|
||||
cargo = rustToolchain;
|
||||
};
|
||||
in
|
||||
rec {
|
||||
packages = {
|
||||
backend = naerskLib.buildPackage {
|
||||
src = ./backend;
|
||||
password-hash-self-service = naerskLib.buildPackage {
|
||||
src = self;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
binaryen # wasm-opt
|
||||
trunk
|
||||
wasm-bindgen-cli
|
||||
wasm-pack
|
||||
];
|
||||
|
||||
# required, otherwise the dependencies are built for the host system
|
||||
|
@ -40,60 +41,28 @@
|
|||
overrideMain = (o: o // {
|
||||
buildPhase = ''
|
||||
runHook preBuild
|
||||
wasm-pack build --target web --release --mode no-install -- --offline
|
||||
trunk build --release --offline --frozen
|
||||
runHook postBuild
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
cp -r pkg $out
|
||||
cp -r dist $out
|
||||
runHook postInstall
|
||||
'';
|
||||
});
|
||||
};
|
||||
|
||||
frontend = pkgs.stdenvNoCC.mkDerivation {
|
||||
name = "password-hash-self-service";
|
||||
|
||||
src = self;
|
||||
|
||||
dontBuild = true;
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
|
||||
mkdir $out
|
||||
cp \
|
||||
index.html \
|
||||
style.css \
|
||||
app.js \
|
||||
$out
|
||||
|
||||
mkdir $out/backend
|
||||
ln -s ${packages.backend} $out/backend/pkg
|
||||
|
||||
runHook postInstall
|
||||
'';
|
||||
};
|
||||
|
||||
default = packages.frontend;
|
||||
default = packages.password-hash-self-service;
|
||||
};
|
||||
|
||||
devShell = pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
binaryen # wasm-opt
|
||||
rustToolchain
|
||||
trunk
|
||||
wasm-bindgen-cli
|
||||
wasm-pack
|
||||
(rust-bin.stable.latest.default.override { targets = [ "wasm32-unknown-unknown" ]; })
|
||||
];
|
||||
};
|
||||
|
||||
apps = {
|
||||
serve = {
|
||||
type = "app";
|
||||
program = toString (pkgs.writeShellScript "serve" ''
|
||||
${pkgs.python3}/bin/python3 -m http.server
|
||||
'');
|
||||
};
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
<meta name="viewport" content="width=device-width">
|
||||
<meta name="description" content="A simple web-app to generate bcrypt and SHA512-crypt hashes">
|
||||
<title>Password Hash Self-Service</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<link rel="preload" href="backend/pkg/password_hash_self_service_backend.js" as="script" crossOrigin="anonymous">
|
||||
<link rel="css" href="style.css" data-trunk>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
|
@ -53,6 +52,7 @@
|
|||
</footer>
|
||||
</div>
|
||||
|
||||
<script type="module" src="app.js"></script>
|
||||
<link data-trunk rel="rust" href="Cargo.toml" data-wasm-opt="z"/>
|
||||
<script src="app.js" data-trunk></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
5
rust-toolchain.toml
Normal file
5
rust-toolchain.toml
Normal file
|
@ -0,0 +1,5 @@
|
|||
[toolchain]
|
||||
channel = "stable"
|
||||
components = []
|
||||
profile = "default"
|
||||
targets = ["wasm32-unknown-unknown"]
|
Loading…
Reference in a new issue