mirror of
https://gitbruv.vercel.app/api/git/bruv/gitbruv.git
synced 2025-12-20 23:24:09 +01:00
fix?
This commit is contained in:
parent
23b82c000c
commit
c2e82d8299
3 changed files with 27 additions and 26 deletions
|
|
@ -4,36 +4,35 @@ import { users, repositories, accounts } from "@/db/schema";
|
||||||
import { eq, and } from "drizzle-orm";
|
import { eq, and } from "drizzle-orm";
|
||||||
import git from "isomorphic-git";
|
import git from "isomorphic-git";
|
||||||
import { createR2Fs, getRepoPrefix } from "@/lib/r2-fs";
|
import { createR2Fs, getRepoPrefix } from "@/lib/r2-fs";
|
||||||
import { scrypt, timingSafeEqual } from "crypto";
|
import { scryptAsync } from "@noble/hashes/scrypt.js";
|
||||||
|
import { hexToBytes } from "@noble/hashes/utils.js";
|
||||||
|
|
||||||
|
function constantTimeEqual(a: Uint8Array, b: Uint8Array): boolean {
|
||||||
|
if (a.length !== b.length) return false;
|
||||||
|
let result = 0;
|
||||||
|
for (let i = 0; i < a.length; i++) {
|
||||||
|
result |= a[i] ^ b[i];
|
||||||
|
}
|
||||||
|
return result === 0;
|
||||||
|
}
|
||||||
|
|
||||||
async function verifyPassword(password: string, hash: string): Promise<boolean> {
|
async function verifyPassword(password: string, hash: string): Promise<boolean> {
|
||||||
return new Promise((resolve) => {
|
try {
|
||||||
try {
|
const [salt, key] = hash.split(":");
|
||||||
const [, params, salt, key] = hash.split("$");
|
if (!salt || !key) return false;
|
||||||
if (!params || !salt || !key) {
|
|
||||||
resolve(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const paramsObj: Record<string, number> = {};
|
const derivedKey = await scryptAsync(password.normalize("NFKC"), salt, {
|
||||||
params.split(",").forEach((p) => {
|
N: 16384,
|
||||||
const [k, v] = p.split("=");
|
r: 16,
|
||||||
paramsObj[k] = parseInt(v, 10);
|
p: 1,
|
||||||
});
|
dkLen: 64,
|
||||||
|
});
|
||||||
|
|
||||||
const keyBuffer = Buffer.from(key, "base64");
|
return constantTimeEqual(derivedKey, hexToBytes(key));
|
||||||
|
} catch (err) {
|
||||||
scrypt(password, salt, keyBuffer.length, { N: paramsObj.n || 16384, r: paramsObj.r || 8, p: paramsObj.p || 1 }, (err, derivedKey) => {
|
console.error("[Git Auth] Password verify error:", err);
|
||||||
if (err) {
|
return false;
|
||||||
resolve(false);
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
resolve(timingSafeEqual(keyBuffer, derivedKey));
|
|
||||||
});
|
|
||||||
} catch {
|
|
||||||
resolve(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function authenticateUser(authHeader: string | null): Promise<{ id: string; username: string } | null> {
|
async function authenticateUser(authHeader: string | null): Promise<{ id: string; username: string } | null> {
|
||||||
|
|
|
||||||
1
bun.lock
1
bun.lock
|
|
@ -7,6 +7,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/client-s3": "^3.956.0",
|
"@aws-sdk/client-s3": "^3.956.0",
|
||||||
"@hookform/resolvers": "^5.2.2",
|
"@hookform/resolvers": "^5.2.2",
|
||||||
|
"@noble/hashes": "^2.0.1",
|
||||||
"@radix-ui/react-avatar": "^1.1.11",
|
"@radix-ui/react-avatar": "^1.1.11",
|
||||||
"@radix-ui/react-dialog": "^1.1.15",
|
"@radix-ui/react-dialog": "^1.1.15",
|
||||||
"@radix-ui/react-dropdown-menu": "^2.1.16",
|
"@radix-ui/react-dropdown-menu": "^2.1.16",
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/client-s3": "^3.956.0",
|
"@aws-sdk/client-s3": "^3.956.0",
|
||||||
"@hookform/resolvers": "^5.2.2",
|
"@hookform/resolvers": "^5.2.2",
|
||||||
|
"@noble/hashes": "^2.0.1",
|
||||||
"@radix-ui/react-avatar": "^1.1.11",
|
"@radix-ui/react-avatar": "^1.1.11",
|
||||||
"@radix-ui/react-dialog": "^1.1.15",
|
"@radix-ui/react-dialog": "^1.1.15",
|
||||||
"@radix-ui/react-dropdown-menu": "^2.1.16",
|
"@radix-ui/react-dropdown-menu": "^2.1.16",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue