Merge pull request #630 from kinode-dao/dr/9-to-10-password-transition

Dr/9 to 10 password transition
This commit is contained in:
doria 2024-12-18 15:37:03 -05:00 committed by GitHub
commit b536548831
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 88 additions and 4 deletions

View File

@ -156,6 +156,9 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/argon2-browser/1.18.0/argon2-bundled.min.js" <script src="https://cdnjs.cloudflare.com/ajax/libs/argon2-browser/1.18.0/argon2-bundled.min.js"
integrity="sha512-Alrh8vbmKDc5xiq7I/y8LTDwy9nw1nT9S/yR73HMMoWrpX4S1kizNPdWM896c/CDIGILNwAiaih627A94kRhYQ==" integrity="sha512-Alrh8vbmKDc5xiq7I/y8LTDwy9nw1nT9S/yR73HMMoWrpX4S1kizNPdWM896c/CDIGILNwAiaih627A94kRhYQ=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script> crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<!-- REMOVE IN 1.0.0 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.2.0/crypto-js.min.js"></script>
<!--------------------->
<script> <script>
let isInitialized = false; let isInitialized = false;
@ -207,6 +210,24 @@
if (result.status == 200) { if (result.status == 200) {
window.location.reload(); window.location.reload();
} else { } else {
// REMOVE IN 1.0.0
const hashHex = '0x' + CryptoJS.SHA256(password).toString(CryptoJS.enc.Hex);
const result = await fetch("/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
password_hash: hashHex,
subdomain: isSecureSubdomain ? firstPathItem : '',
}),
});
if (result.status == 200) {
window.location.reload();
} else {
throw new Error("Login failed");
}
// END REMOVE IN 1.0.0
throw new Error("Login failed"); throw new Error("Login failed");
} }
}).catch(err => { }).catch(err => {

View File

@ -874,8 +874,20 @@ async fn login_with_password(
let password_hash_hex = format!("0x{}", password_hash); let password_hash_hex = format!("0x{}", password_hash);
let k = keygen::decode_keyfile(&disk_keyfile, &password_hash_hex) // SWITCH BACK TO THIS IN 1.0.0
.expect("could not decode keyfile, password incorrect"); // let k = keygen::decode_keyfile(&disk_keyfile, &password_hash_hex)
// .expect("could not decode keyfile, password incorrect");
// REMOVE IN 1.0.0
let k = match keygen::decode_keyfile(&disk_keyfile, &password_hash_hex) {
Ok(k) => k,
Err(_) => {
use sha2::{Digest, Sha256};
let password_hash = format!("0x{}", hex::encode(Sha256::digest(password)));
keygen::decode_keyfile(&disk_keyfile, &password_hash)
.expect("could not decode keyfile, password incorrect")
}
};
let mut our = Identity { let mut our = Identity {
name: k.username.clone(), name: k.username.clone(),

View File

@ -7,6 +7,8 @@ import {
import { PageProps } from "../lib/types"; import { PageProps } from "../lib/types";
import Loader from "../components/Loader"; import Loader from "../components/Loader";
import { redirectToHomepage } from "../utils/redirect-to-homepage"; import { redirectToHomepage } from "../utils/redirect-to-homepage";
// REMOVE IN 1.0.0
import { sha256, toBytes } from "viem";
interface ImportKeyfileProps extends PageProps { } interface ImportKeyfileProps extends PageProps { }
@ -69,7 +71,28 @@ function ImportKeyfile({
}); });
if (result.status > 399) { if (result.status > 399) {
throw new Error(await result.text());
// REMOVE IN 1.0.0
let hashed_password = sha256(toBytes(pw));
const result = await fetch("/import-keyfile", {
method: "POST",
credentials: 'include',
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
keyfile: Buffer.from(localKey).toString('utf8'),
password_hash: hashed_password,
}),
});
if (result.status > 399) {
throw new Error("Incorrect password");
} else {
redirectToHomepage();
}
// END REMOVE IN 1.0.0
// BRING BACK IN 1.0.0
// throw new Error(await result.text());
} }
redirectToHomepage(); redirectToHomepage();
}).catch(err => { }).catch(err => {

View File

@ -4,6 +4,8 @@ import Loader from "../components/Loader";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { Tooltip } from "../components/Tooltip"; import { Tooltip } from "../components/Tooltip";
import { redirectToHomepage } from "../utils/redirect-to-homepage"; import { redirectToHomepage } from "../utils/redirect-to-homepage";
// REMOVE IN 1.0.0
import { sha256, toBytes } from "viem";
interface LoginProps extends PageProps { } interface LoginProps extends PageProps { }
@ -54,7 +56,27 @@ function Login({
); );
if (result.status > 399) { if (result.status > 399) {
throw new Error(await result.text());
// REMOVE IN 1.0.0
let hashed_password = sha256(toBytes(pw));
const result = await fetch(
"/login",
{
method: "POST",
credentials: 'include',
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ password_hash: hashed_password }),
}
);
if (result.status > 399) {
throw new Error(await result.text());
} else {
redirectToHomepage();
}
// END REMOVE IN 1.0.0
// BRING BACK IN 1.0.0
// throw new Error(await result.text());
} }
redirectToHomepage(); redirectToHomepage();
}).catch(err => { }).catch(err => {

6
package-lock.json generated Normal file
View File

@ -0,0 +1,6 @@
{
"name": "kinode",
"lockfileVersion": 2,
"requires": true,
"packages": {}
}