commit
45063e1175
@ -0,0 +1,6 @@ |
||||
# Rust |
||||
/backend/target/ |
||||
/backend/pkg/ |
||||
|
||||
# Nix |
||||
/result* |
@ -0,0 +1,202 @@ |
||||
|
||||
Apache License |
||||
Version 2.0, January 2004 |
||||
http://www.apache.org/licenses/ |
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION |
||||
|
||||
1. Definitions. |
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction, |
||||
and distribution as defined by Sections 1 through 9 of this document. |
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by |
||||
the copyright owner that is granting the License. |
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all |
||||
other entities that control, are controlled by, or are under common |
||||
control with that entity. For the purposes of this definition, |
||||
"control" means (i) the power, direct or indirect, to cause the |
||||
direction or management of such entity, whether by contract or |
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the |
||||
outstanding shares, or (iii) beneficial ownership of such entity. |
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity |
||||
exercising permissions granted by this License. |
||||
|
||||
"Source" form shall mean the preferred form for making modifications, |
||||
including but not limited to software source code, documentation |
||||
source, and configuration files. |
||||
|
||||
"Object" form shall mean any form resulting from mechanical |
||||
transformation or translation of a Source form, including but |
||||
not limited to compiled object code, generated documentation, |
||||
and conversions to other media types. |
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or |
||||
Object form, made available under the License, as indicated by a |
||||
copyright notice that is included in or attached to the work |
||||
(an example is provided in the Appendix below). |
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object |
||||
form, that is based on (or derived from) the Work and for which the |
||||
editorial revisions, annotations, elaborations, or other modifications |
||||
represent, as a whole, an original work of authorship. For the purposes |
||||
of this License, Derivative Works shall not include works that remain |
||||
separable from, or merely link (or bind by name) to the interfaces of, |
||||
the Work and Derivative Works thereof. |
||||
|
||||
"Contribution" shall mean any work of authorship, including |
||||
the original version of the Work and any modifications or additions |
||||
to that Work or Derivative Works thereof, that is intentionally |
||||
submitted to Licensor for inclusion in the Work by the copyright owner |
||||
or by an individual or Legal Entity authorized to submit on behalf of |
||||
the copyright owner. For the purposes of this definition, "submitted" |
||||
means any form of electronic, verbal, or written communication sent |
||||
to the Licensor or its representatives, including but not limited to |
||||
communication on electronic mailing lists, source code control systems, |
||||
and issue tracking systems that are managed by, or on behalf of, the |
||||
Licensor for the purpose of discussing and improving the Work, but |
||||
excluding communication that is conspicuously marked or otherwise |
||||
designated in writing by the copyright owner as "Not a Contribution." |
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity |
||||
on behalf of whom a Contribution has been received by Licensor and |
||||
subsequently incorporated within the Work. |
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of |
||||
this License, each Contributor hereby grants to You a perpetual, |
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable |
||||
copyright license to reproduce, prepare Derivative Works of, |
||||
publicly display, publicly perform, sublicense, and distribute the |
||||
Work and such Derivative Works in Source or Object form. |
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of |
||||
this License, each Contributor hereby grants to You a perpetual, |
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable |
||||
(except as stated in this section) patent license to make, have made, |
||||
use, offer to sell, sell, import, and otherwise transfer the Work, |
||||
where such license applies only to those patent claims licensable |
||||
by such Contributor that are necessarily infringed by their |
||||
Contribution(s) alone or by combination of their Contribution(s) |
||||
with the Work to which such Contribution(s) was submitted. If You |
||||
institute patent litigation against any entity (including a |
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work |
||||
or a Contribution incorporated within the Work constitutes direct |
||||
or contributory patent infringement, then any patent licenses |
||||
granted to You under this License for that Work shall terminate |
||||
as of the date such litigation is filed. |
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the |
||||
Work or Derivative Works thereof in any medium, with or without |
||||
modifications, and in Source or Object form, provided that You |
||||
meet the following conditions: |
||||
|
||||
(a) You must give any other recipients of the Work or |
||||
Derivative Works a copy of this License; and |
||||
|
||||
(b) You must cause any modified files to carry prominent notices |
||||
stating that You changed the files; and |
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works |
||||
that You distribute, all copyright, patent, trademark, and |
||||
attribution notices from the Source form of the Work, |
||||
excluding those notices that do not pertain to any part of |
||||
the Derivative Works; and |
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its |
||||
distribution, then any Derivative Works that You distribute must |
||||
include a readable copy of the attribution notices contained |
||||
within such NOTICE file, excluding those notices that do not |
||||
pertain to any part of the Derivative Works, in at least one |
||||
of the following places: within a NOTICE text file distributed |
||||
as part of the Derivative Works; within the Source form or |
||||
documentation, if provided along with the Derivative Works; or, |
||||
within a display generated by the Derivative Works, if and |
||||
wherever such third-party notices normally appear. The contents |
||||
of the NOTICE file are for informational purposes only and |
||||
do not modify the License. You may add Your own attribution |
||||
notices within Derivative Works that You distribute, alongside |
||||
or as an addendum to the NOTICE text from the Work, provided |
||||
that such additional attribution notices cannot be construed |
||||
as modifying the License. |
||||
|
||||
You may add Your own copyright statement to Your modifications and |
||||
may provide additional or different license terms and conditions |
||||
for use, reproduction, or distribution of Your modifications, or |
||||
for any such Derivative Works as a whole, provided Your use, |
||||
reproduction, and distribution of the Work otherwise complies with |
||||
the conditions stated in this License. |
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise, |
||||
any Contribution intentionally submitted for inclusion in the Work |
||||
by You to the Licensor shall be under the terms and conditions of |
||||
this License, without any additional terms or conditions. |
||||
Notwithstanding the above, nothing herein shall supersede or modify |
||||
the terms of any separate license agreement you may have executed |
||||
with Licensor regarding such Contributions. |
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade |
||||
names, trademarks, service marks, or product names of the Licensor, |
||||
except as required for reasonable and customary use in describing the |
||||
origin of the Work and reproducing the content of the NOTICE file. |
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or |
||||
agreed to in writing, Licensor provides the Work (and each |
||||
Contributor provides its Contributions) on an "AS IS" BASIS, |
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
||||
implied, including, without limitation, any warranties or conditions |
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A |
||||
PARTICULAR PURPOSE. You are solely responsible for determining the |
||||
appropriateness of using or redistributing the Work and assume any |
||||
risks associated with Your exercise of permissions under this License. |
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory, |
||||
whether in tort (including negligence), contract, or otherwise, |
||||
unless required by applicable law (such as deliberate and grossly |
||||
negligent acts) or agreed to in writing, shall any Contributor be |
||||
liable to You for damages, including any direct, indirect, special, |
||||
incidental, or consequential damages of any character arising as a |
||||
result of this License or out of the use or inability to use the |
||||
Work (including but not limited to damages for loss of goodwill, |
||||
work stoppage, computer failure or malfunction, or any and all |
||||
other commercial damages or losses), even if such Contributor |
||||
has been advised of the possibility of such damages. |
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing |
||||
the Work or Derivative Works thereof, You may choose to offer, |
||||
and charge a fee for, acceptance of support, warranty, indemnity, |
||||
or other liability obligations and/or rights consistent with this |
||||
License. However, in accepting such obligations, You may act only |
||||
on Your own behalf and on Your sole responsibility, not on behalf |
||||
of any other Contributor, and only if You agree to indemnify, |
||||
defend, and hold each Contributor harmless for any liability |
||||
incurred by, or claims asserted against, such Contributor by reason |
||||
of your accepting any such warranty or additional liability. |
||||
|
||||
END OF TERMS AND CONDITIONS |
||||
|
||||
APPENDIX: How to apply the Apache License to your work. |
||||
|
||||
To apply the Apache License to your work, attach the following |
||||
boilerplate notice, with the fields enclosed by brackets "[]" |
||||
replaced with your own identifying information. (Don't include |
||||
the brackets!) The text should be enclosed in the appropriate |
||||
comment syntax for the file format. We also recommend that a |
||||
file or class name and description of purpose be included on the |
||||
same "printed page" as the copyright notice for easier |
||||
identification within third-party archives. |
||||
|
||||
Copyright [yyyy] [name of copyright owner] |
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
you may not use this file except in compliance with the License. |
||||
You may obtain a copy of the License at |
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
||||
Unless required by applicable law or agreed to in writing, software |
||||
distributed under the License is distributed on an "AS IS" BASIS, |
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
See the License for the specific language governing permissions and |
||||
limitations under the License. |
@ -0,0 +1,19 @@ |
||||
The MIT License |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining |
||||
a copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE |
||||
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
@ -0,0 +1,10 @@ |
||||
# Password Hash Self-Service |
||||
|
||||
A simple web app for users to generate password hashes |
||||
to be used in services where passwords are set “by hand”. |
||||
It currently supports SHA512-crypt and bcrypt hashes. |
||||
|
||||
## License |
||||
|
||||
This project is dual-licensed under the Apache 2.0 and MIT licenses. See |
||||
LICENSE-APACHE and LICENSE-MIT for details. |
@ -0,0 +1,70 @@ |
||||
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") |
||||
} |
||||
|
||||
function getHashSetup(formData) { |
||||
let setup = { |
||||
password: formData.get("password"), |
||||
hashType: formData.get("hash-type"), |
||||
privateOptions: {}, |
||||
} |
||||
|
||||
switch (setup.hashType) { |
||||
case "bcrypt": |
||||
setup.privateOptions.cost = formData.get("bcrypt-cost") |
||||
break |
||||
case "sha512crypt": |
||||
setup.privateOptions.rounds = formData.get("sha512crypt-rounds") |
||||
break |
||||
default: |
||||
console.warn("Unknown hash type " + setup.hashType + ", not setting private options") |
||||
} |
||||
|
||||
return setup |
||||
} |
||||
|
||||
// Returns function that accepts two arguments: a password and an object of
|
||||
// private options for the hasher.
|
||||
function getHasher(hashType) { |
||||
switch (hashType) { |
||||
case "bcrypt": |
||||
return (password, { cost }) => hash_bcrypt(password, cost) |
||||
case "sha512crypt": |
||||
return (password, { rounds }) => hash_sha512crypt(password, rounds) |
||||
default: |
||||
throw Error("Invalid hash type specified: " + hashType) |
||||
} |
||||
} |
||||
|
||||
(async () => { |
||||
await init() |
||||
|
||||
document.getElementById("advanced-options").addEventListener("change", e => { |
||||
if (e.target.checked) { |
||||
document.body.classList.add("advanced") |
||||
} else { |
||||
document.body.classList.remove("advanced") |
||||
} |
||||
}) |
||||
|
||||
document.getElementById("generate").addEventListener("click", e => { |
||||
e.target.disabled = true |
||||
const buttonText = e.target.innerText |
||||
e.target.innerText = "Calculating hash…" |
||||
|
||||
const formData = new FormData(document.getElementById("hash-setup")) |
||||
const hashSetup = getHashSetup(formData) |
||||
|
||||
console.debug("Hash type:", hashSetup.hashType, "Private options:", hashSetup.privateOptions) |
||||
|
||||
const hasher = getHasher(hashSetup.hashType) |
||||
|
||||
displayHash(hasher(hashSetup.password, hashSetup.privateOptions)) |
||||
|
||||
e.target.innerText = buttonText |
||||
e.target.disabled = false |
||||
}) |
||||
})() |
@ -0,0 +1,367 @@ |
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
version = 3 |
||||
|
||||
[[package]] |
||||
name = "block-buffer" |
||||
version = "0.9.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" |
||||
dependencies = [ |
||||
"generic-array", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "blowfish" |
||||
version = "0.7.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "32fa6a061124e37baba002e496d203e23ba3d7b73750be82dbfbc92913048a5b" |
||||
dependencies = [ |
||||
"byteorder", |
||||
"cipher", |
||||
"opaque-debug", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "bumpalo" |
||||
version = "3.7.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631" |
||||
|
||||
[[package]] |
||||
name = "byteorder" |
||||
version = "1.4.3" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" |
||||
|
||||
[[package]] |
||||
name = "cfg-if" |
||||
version = "1.0.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" |
||||
|
||||
[[package]] |
||||
name = "cipher" |
||||
version = "0.2.5" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "12f8e7987cbd042a63249497f41aed09f8e65add917ea6566effbc56578d6801" |
||||
dependencies = [ |
||||
"generic-array", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "cpufeatures" |
||||
version = "0.1.5" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "66c99696f6c9dd7f35d486b9d04d7e6e202aa3e8c40d553f2fdf5e7e0c6a71ef" |
||||
dependencies = [ |
||||
"libc", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "crypto-mac" |
||||
version = "0.10.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "4857fd85a0c34b3c3297875b747c1e02e06b6a0ea32dd892d8192b9ce0813ea6" |
||||
dependencies = [ |
||||
"generic-array", |
||||
"subtle", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "digest" |
||||
version = "0.9.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" |
||||
dependencies = [ |
||||
"generic-array", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "generic-array" |
||||
version = "0.14.4" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" |
||||
dependencies = [ |
||||
"typenum", |
||||
"version_check", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "getrandom" |
||||
version = "0.2.3" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" |
||||
dependencies = [ |
||||
"cfg-if", |
||||
"js-sys", |
||||
"libc", |
||||
"wasi", |
||||
"wasm-bindgen", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "hmac" |
||||
version = "0.10.1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "c1441c6b1e930e2817404b5046f1f989899143a12bf92de603b69f4e0aee1e15" |
||||
dependencies = [ |
||||
"crypto-mac", |
||||
"digest", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "js-sys" |
||||
version = "0.3.51" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "83bdfbace3a0e81a4253f73b49e960b053e396a11012cbd49b9b74d6a2b67062" |
||||
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.97" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" |
||||
|
||||
[[package]] |
||||
name = "log" |
||||
version = "0.4.14" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" |
||||
dependencies = [ |
||||
"cfg-if", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "md-5" |
||||
version = "0.9.1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "7b5a279bb9607f9f53c22d496eade00d138d1bdcccd07d74650387cf94942a15" |
||||
dependencies = [ |
||||
"block-buffer", |
||||
"digest", |
||||
"opaque-debug", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "opaque-debug" |
||||
version = "0.3.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" |
||||
|
||||
[[package]] |
||||
name = "password-hash-self-service-backend" |
||||
version = "0.0.0" |
||||
dependencies = [ |
||||
"getrandom", |
||||
"pwhash", |
||||
"wasm-bindgen", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "ppv-lite86" |
||||
version = "0.2.10" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" |
||||
|
||||
[[package]] |
||||
name = "proc-macro2" |
||||
version = "1.0.27" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" |
||||
dependencies = [ |
||||
"unicode-xid", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "pwhash" |
||||
version = "1.0.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "419a3ad8fa9f9d445e69d9b185a24878ae6e6f55c96e4512f4a0e28cd3bc5c56" |
||||
dependencies = [ |
||||
"blowfish", |
||||
"byteorder", |
||||
"hmac", |
||||
"md-5", |
||||
"rand", |
||||
"sha-1", |
||||
"sha2", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "quote" |
||||
version = "1.0.9" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" |
||||
dependencies = [ |
||||
"proc-macro2", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "rand" |
||||
version = "0.8.4" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" |
||||
dependencies = [ |
||||
"libc", |
||||
"rand_chacha", |
||||
"rand_core", |
||||
"rand_hc", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "rand_chacha" |
||||
version = "0.3.1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" |
||||
dependencies = [ |
||||
"ppv-lite86", |
||||
"rand_core", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "rand_core" |
||||
version = "0.6.3" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" |
||||
dependencies = [ |
||||
"getrandom", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "rand_hc" |
||||
version = "0.3.1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" |
||||
dependencies = [ |
||||
"rand_core", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "sha-1" |
||||
version = "0.9.6" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "8c4cfa741c5832d0ef7fab46cabed29c2aae926db0b11bb2069edd8db5e64e16" |
||||
dependencies = [ |
||||
"block-buffer", |
||||
"cfg-if", |
||||
"cpufeatures", |
||||
"digest", |
||||
"opaque-debug", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "sha2" |
||||
version = "0.9.5" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "b362ae5752fd2137731f9fa25fd4d9058af34666ca1966fb969119cc35719f12" |
||||
dependencies = [ |
||||
"block-buffer", |
||||
"cfg-if", |
||||
"cpufeatures", |
||||
"digest", |
||||
"opaque-debug", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "subtle" |
||||
version = "2.4.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" |
||||
|
||||
[[package]] |
||||
name = "syn" |
||||
version = "1.0.73" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7" |
||||
dependencies = [ |
||||
"proc-macro2", |
||||
"quote", |
||||
"unicode-xid", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "typenum" |
||||
version = "1.13.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" |
||||
|
||||
[[package]] |
||||
name = "unicode-xid" |
||||
version = "0.2.2" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" |
||||
|
||||
[[package]] |
||||
name = "version_check" |
||||
version = "0.9.3" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" |
||||
|
||||
[[package]] |
||||
name = "wasi" |
||||
version = "0.10.2+wasi-snapshot-preview1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" |
||||
|
||||
[[package]] |
||||
name = "wasm-bindgen" |
||||
version = "0.2.74" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "d54ee1d4ed486f78874278e63e4069fc1ab9f6a18ca492076ffb90c5eb2997fd" |
||||
dependencies = [ |
||||
"cfg-if", |
||||
"wasm-bindgen-macro", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "wasm-bindgen-backend" |
||||
version = "0.2.74" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "3b33f6a0694ccfea53d94db8b2ed1c3a8a4c86dd936b13b9f0a15ec4a451b900" |
||||
dependencies = [ |
||||
"bumpalo", |
||||
"lazy_static", |
||||
"log", |
||||
"proc-macro2", |
||||
"quote", |
||||
"syn", |
||||
"wasm-bindgen-shared", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "wasm-bindgen-macro" |
||||
version = "0.2.74" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "088169ca61430fe1e58b8096c24975251700e7b1f6fd91cc9d59b04fb9b18bd4" |
||||
dependencies = [ |
||||
"quote", |
||||
"wasm-bindgen-macro-support", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "wasm-bindgen-macro-support" |
||||
version = "0.2.74" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "be2241542ff3d9f241f5e2cb6dd09b37efe786df8851c54957683a49f0987a97" |
||||
dependencies = [ |
||||
"proc-macro2", |
||||
"quote", |
||||
"syn", |
||||
"wasm-bindgen-backend", |
||||
"wasm-bindgen-shared", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "wasm-bindgen-shared" |
||||
version = "0.2.74" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "d7cff876b8f18eed75a66cf49b65e7f967cb354a7aa16003fb55dbfd25b44b4f" |
@ -0,0 +1,17 @@ |
||||
[package] |
||||
name = "password-hash-self-service-backend" |
||||
version = "0.0.0" |
||||
authors = ["Simon Bruder <simon@sbruder.de>"] |
||||
license = "MIT/Apache-2.0" |
||||
edition = "2018" |
||||
|
||||
[lib] |
||||
crate-type = ["cdylib", "rlib"] |
||||
|
||||
[dependencies] |
||||
getrandom = { version = "0.2.2", features = ["js"] } |
||||
pwhash = "1.0.0" |
||||
wasm-bindgen = "0.2" |
||||
|
||||
[profile.release] |
||||
opt-level = "z" |
@ -0,0 +1,27 @@ |
||||
use pwhash::{ |
||||
bcrypt::{self, BcryptSetup}, |
||||
sha512_crypt, HashSetup, |
||||
}; |
||||
use wasm_bindgen::prelude::*; |
||||
|
||||
#[wasm_bindgen] |
||||
pub fn hash_bcrypt(password: &str, cost: u32) -> JsValue { |
||||
let setup = BcryptSetup { |
||||
cost: Some(cost), |
||||
..Default::default() |
||||
}; |
||||
bcrypt::hash_with(setup, password) |
||||
.expect("failed to calculate bcrypt hash") |
||||
.into() |
||||
} |
||||
|
||||
#[wasm_bindgen] |
||||
pub fn hash_sha512crypt(password: &str, rounds: u32) -> JsValue { |
||||
let setup = HashSetup { |
||||
rounds: Some(rounds), |
||||
salt: None, |
||||
}; |
||||
sha512_crypt::hash_with(setup, password) |
||||
.expect("failed to calculate sha512-crypt hash") |
||||
.into() |
||||
} |
@ -0,0 +1,114 @@ |
||||
{ |
||||
"nodes": { |
||||
"flake-utils": { |
||||
"locked": { |
||||
"lastModified": 1623875721, |
||||
"narHash": "sha256-A8BU7bjS5GirpAUv4QA+QnJ4CceLHkcXdRp4xITDB0s=", |
||||
"owner": "numtide", |
||||
"repo": "flake-utils", |
||||
"rev": "f7e004a55b120c02ecb6219596820fcd32ca8772", |
||||
"type": "github" |
||||
}, |
||||
"original": { |
||||
"owner": "numtide", |
||||
"repo": "flake-utils", |
||||
"type": "github" |
||||
} |
||||
}, |
||||
"flake-utils_2": { |
||||
"locked": { |
||||
"lastModified": 1614513358, |
||||
"narHash": "sha256-LakhOx3S1dRjnh0b5Dg3mbZyH0ToC9I8Y2wKSkBaTzU=", |
||||
"owner": "numtide", |
||||
"repo": "flake-utils", |
||||
"rev": "5466c5bbece17adaab2d82fae80b46e807611bf3", |
||||
"type": "github" |
||||
}, |
||||
"original": { |
||||
"owner": "numtide", |
||||
"repo": "flake-utils", |
||||
"type": "github" |
||||
} |
||||
}, |
||||
"naersk": { |
||||
"inputs": { |
||||
"nixpkgs": [ |
||||
"nixpkgs" |
||||
] |
||||
}, |
||||
"locked": { |
||||
"lastModified": 1623927034, |
||||
"narHash": "sha256-sGxlmfp5eXL5sAMNqHSb04Zq6gPl+JeltIZ226OYN0w=", |
||||
"owner": "nmattia", |
||||
"repo": "naersk", |
||||
"rev": "e09c320446c5c2516d430803f7b19f5833781337", |
||||
"type": "github" |
||||
}, |
||||
"original": { |
||||
"owner": "nmattia", |
||||
"repo": "naersk", |
||||
"type": "github" |
||||
} |
||||
}, |
||||
"nixpkgs": { |
||||
"locked": { |
||||
"lastModified": 1624271441, |
||||
"narHash": "sha256-26QNDCdRE5mPOWYJrPGpVzgrJ3ZxqvWOONfeMsjryz4=", |
||||
"owner": "nixos", |
||||
"repo": "nixpkgs", |
||||
"rev": "7e567a3d092b7de69cdf5deaeb8d9526de230916", |
||||
"type": "github" |
||||
}, |
||||
"original": { |
||||
"owner": "nixos", |
||||
"ref": "nixos-unstable", |
||||
"repo": "nixpkgs", |
||||
"type": "github" |
||||
} |
||||
}, |
||||
"nixpkgs_2": { |
||||
"locked": { |
||||
"lastModified": 1617325113, |
||||
"narHash": "sha256-GksR0nvGxfZ79T91UUtWjjccxazv6Yh/MvEJ82v1Xmw=", |
||||
"owner": "nixos", |
||||
"repo": "nixpkgs", |
||||
"rev": "54c1e44240d8a527a8f4892608c4bce5440c3ecb", |
||||
"type": "github" |
||||
}, |
||||
"original": { |
||||
"owner": "NixOS", |
||||
"repo": "nixpkgs", |
||||
"type": "github" |
||||
} |
||||
}, |
||||
"root": { |
||||
"inputs": { |
||||
"flake-utils": "flake-utils", |
||||
"naersk": "naersk", |
||||
"nixpkgs": "nixpkgs", |
||||
"rust-overlay": "rust-overlay" |
||||
} |
||||
}, |
||||
"rust-overlay": { |
||||
"inputs": { |
||||
"flake-utils": "flake-utils_2", |
||||
"nixpkgs": "nixpkgs_2" |
||||
}, |
||||
"locked": { |
||||
"lastModified": 1624414452, |
||||
"narHash": "sha256-vvnagNTPTT3zcPNjD8Gz7STHniQkc3+9cs+4h2pcuVU=", |
||||
"owner": "oxalica", |
||||
"repo": "rust-overlay", |
||||
"rev": "09149337f9899b4b9fa6e4f3889467e8646c9fc5", |
||||
"type": "github" |
||||
}, |
||||
"original": { |
||||
"owner": "oxalica", |
||||
"repo": "rust-overlay", |
||||
"type": "github" |
||||
} |
||||
} |
||||
}, |
||||
"root": "root", |
||||
"version": 7 |
||||
} |
@ -0,0 +1,93 @@ |
||||
{ |
||||
inputs = { |
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; |
||||
|
||||
flake-utils.url = "github:numtide/flake-utils"; |
||||
|
||||
rust-overlay.url = "github:oxalica/rust-overlay"; |
||||
|
||||
naersk.url = "github:nmattia/naersk"; |
||||
naersk.inputs.nixpkgs.follows = "nixpkgs"; |
||||
}; |
||||
|
||||
outputs = { self, nixpkgs, rust-overlay, flake-utils, naersk }: flake-utils.lib.eachDefaultSystem (system: |
||||
let |
||||
overlays = [ |
||||
rust-overlay.overlay |
||||
(final: prev: { |
||||
rustc = final.rust-bin.nightly.latest.default.override { targets = [ "wasm32-unknown-unknown" ]; }; |
||||
cargo = final.rust-bin.nightly.latest.default.override { targets = [ "wasm32-unknown-unknown" ]; }; |
||||
}) |
||||
]; |
||||
pkgs = import nixpkgs { inherit system overlays; }; |
||||
naerskLib = pkgs.callPackage naersk { }; |
||||
in |
||||
rec { |
||||
packages = { |
||||
backend = naerskLib.buildPackage { |
||||
src = ./backend; |
||||
|
||||
nativeBuildInputs = with pkgs; [ |
||||
wasm-bindgen-cli |
||||
wasm-pack |
||||
]; |
||||
|
||||
overrideMain = (o: o // { |
||||
buildPhase = '' |
||||
runHook preBuild |
||||
wasm-pack build --target web --release --mode no-install -- --offline |
||||
runHook postBuild |
||||
''; |
||||
|
||||
installPhase = '' |
||||
runHook preInstall |
||||
cp -r pkg $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 |
||||
''; |
||||
}; |
||||
}; |
||||
|
||||
defaultPackage = packages.frontend; |
||||
|
||||
devShell = pkgs.mkShell { |
||||
buildInputs = with pkgs; [ |
||||
wasm-pack |
||||
(rust-bin.nightly.latest.default.override { targets = [ "wasm32-unknown-unknown" ]; }) |
||||
]; |
||||
}; |
||||
|
||||
apps = { |
||||
serve = { |
||||
type = "app"; |
||||
program = toString (pkgs.writeShellScript "serve" '' |
||||
${pkgs.python3}/bin/python3 -m http.server |
||||
''); |
||||
}; |
||||
}; |
||||
}); |
||||
} |
@ -0,0 +1,38 @@ |
||||
<!DOCTYPE html> |
||||
<html> |
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<meta name="viewport" content="width=device-width"> |
||||
<title>Password Hash Self-Service</title> |
||||
<link rel="stylesheet" href="style.css"> |
||||
</head> |
||||
<body> |
||||
<div class="container"> |
||||
<h1>Password Hash Self-Service</h1> |
||||
|
||||
<form id="hash-setup" autocomplete="off"> |
||||
<label for="password">Password</label> |
||||
<input name="password" type="password"></input><br> |
||||
|
||||
<label for="hash-type">Hash Type</label> |
||||
<input name="hash-type" type="radio" value="bcrypt" checked>bcrypt</input> |
||||
<input name="hash-type" type="radio" value="sha512crypt">SHA512-crypt</input><br> |
||||
|
||||
<input id="advanced-options" name="advanced" type="checkbox">Advanced options</input><br> |
||||
|
||||
<div class="advanced"> |
||||
<label for="bcrypt-cost">bcrpyt cost factor</label> |
||||
<input name="bcrypt-cost" type="number" value="12" min="4" max="31"></input><br> |
||||
<label for="sha512crypt-rounds">SHA512-crypt rounds</label> |
||||
<input name="sha512crypt-rounds" type="number" value="100000" min="1000" max="999999999"></input><br> |
||||
</div> |
||||
|
||||
<button type="button" id="generate">Generate</button> |
||||
</form> |
||||
|
||||
<div id="hash-container"><span id="hash"></span></div> |
||||
</div> |
||||
|
||||
<script type="module" src="app.js"></script> |
||||
</body> |
||||
</html> |
@ -0,0 +1,28 @@ |
||||
.container { |
||||
margin: 1em auto; |
||||
max-width: 576px; |
||||
} |
||||
|
||||
#hash-container { |
||||
display: none; |
||||
} |
||||
|
||||
#hash-container.done { |
||||
display: block; |
||||
border: 1px solid red; |
||||
margin: 1em 0em; |
||||
padding: 2px; |
||||
} |
||||
|
||||
#hash { |
||||
font-family: monospace; |
||||
line-break: anywhere; |
||||
} |
||||
|
||||
body .advanced { |
||||
display: none; |
||||
} |
||||
|
||||
body.advanced .advanced { |
||||
display: initial; |
||||
} |
Loading…
Reference in new issue