From 999ef760c0c2820cd7f8775c87ec85ae13c016d8 Mon Sep 17 00:00:00 2001 From: jusax23 Date: Tue, 7 Mar 2023 18:47:37 +0100 Subject: [PATCH] bug fixes --- src/api/acts/login.ts | 9 +++++---- src/api/post.ts | 3 ++- src/server/outbagURL.ts | 4 ++-- src/server/serverCerts.ts | 5 +++-- src/sys/db.ts | 2 +- src/sys/log.ts | 20 ++++++++++++-------- 6 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/api/acts/login.ts b/src/api/acts/login.ts index 9983093..15242e8 100644 --- a/src/api/acts/login.ts +++ b/src/api/acts/login.ts @@ -32,7 +32,7 @@ export const signup: Act = { func: async (client: Client, data: any, aws: (code: string, data: any) => void) => { let countAlias = alias(count(accounts.accID), "countAlias") as any; let query = await select([countAlias], accounts) - .query(db, true); + .query(db); let maxUsers = oConf.get("Settings", "maxUsers"); let userNum = query[0][countAlias]; if (maxUsers > -1 && userNum > 0 && userNum >= maxUsers) { @@ -137,14 +137,14 @@ export const remote1 = { data: { name: "string", server: "string", - key: "string", + publicKey: "string", sign: "string", }, func: async (client: Client, data: any, aws: (code: string, data: any) => void) => { let server = await outbagURLfromTag(data.server); try { var cert = await getRemote(server); - var tagAcert = data.name + "@" + data.server + "-" + data.key; + var tagAcert = `${data.name}@${server.host}:${server.port}-${data.publicKey}` if (!(await verify(tagAcert, data.sign, cert))) { client.suspect(); aws("error", "signature"); @@ -155,9 +155,10 @@ export const remote1 = { client.server = server; client.challenge = get64(64); client.state = STATE.remoteP; - client.remoteKey = data.key; + client.remoteKey = data.publicKey; aws("ok", client.challenge); } catch (e) { + console.log(e); client.suspect(); aws("error", "signature"); } diff --git a/src/api/post.ts b/src/api/post.ts index b5885ae..0507bea 100644 --- a/src/api/post.ts +++ b/src/api/post.ts @@ -60,7 +60,7 @@ export const addPostMethods = (server: express.Express) => { )) .query(db); - if (query.length == 0 || query[0].accountKey != sha256((query[0].accountKeySalt ?? '') + accountKey)) { + if (query.length == 0 || query[0][accounts.accountKey] != sha256((query[0][accounts.accountKeySalt] ?? '') + accountKey)) { if (req.suspect) req.suspect(); aws("error", "auth"); return; @@ -128,6 +128,7 @@ export class postClient { send = true; }); } catch (e) { + console.log(e); error("POST", "act error:", e); } diff --git a/src/server/outbagURL.ts b/src/server/outbagURL.ts index de70f3d..4cd6c4c 100644 --- a/src/server/outbagURL.ts +++ b/src/server/outbagURL.ts @@ -47,9 +47,9 @@ export class outbagServer { this.tag = tag; } get httpsURL() { - return `https://${this.host}:${this.port}${this.path}/`; + return `https://${this.host}:${this.port}${this.path}`; } get wsURL() { - return `wss://${this.host}:${this.port}${this.path}/`; + return `wss://${this.host}:${this.port}${this.path}`; } }; diff --git a/src/server/serverCerts.ts b/src/server/serverCerts.ts index cb4bae0..4f037d0 100644 --- a/src/server/serverCerts.ts +++ b/src/server/serverCerts.ts @@ -89,12 +89,12 @@ const updateCert = async (server: outbagServer) => { let resp = await fetch(server.httpsURL + "api/server/publicKey") let json = await resp.json(); let { publicKey, expires } = json; - certList[server.tag] = { exp: Math.min(expires, deleteafter), cert: publicKey }; + certList[server.tag] = { exp: Math.min(expires, uts() + deleteafter), cert: publicKey }; try { await insert(servers.tag) .add(server.tag) .query(db); - } catch (error) {} + } catch (error) { } return true; } catch (error) { return false; @@ -103,6 +103,7 @@ const updateCert = async (server: outbagServer) => { export const getRemote = async (server: outbagServer) => { if (certList[server.tag] == null || certList[server.tag].exp >= uts()) await updateCert(server); + console.log(server.tag, certList[server.tag]); if (certList[server.tag] != null) return certList[server.tag].cert; else throw new Error("Cert Error"); }; \ No newline at end of file diff --git a/src/sys/db.ts b/src/sys/db.ts index fca31e5..a682c24 100644 --- a/src/sys/db.ts +++ b/src/sys/db.ts @@ -47,7 +47,7 @@ accounts.addAttributes({ accID: { type: INT, primaryKey: true, autoIncrement: true }, name: { type: VARCHAR(100), default: PERMISSIONS.DEFAULT }, - rights: { type: BIGINT, default: PERMISSIONS.DEFAULT }, + rights: { type: INT, default: PERMISSIONS.DEFAULT }, accountKeySalt: { type: VARCHAR(64) }, accountKey: { type: VARCHAR(64) }, diff --git a/src/sys/log.ts b/src/sys/log.ts index 5442028..99ffe45 100644 --- a/src/sys/log.ts +++ b/src/sys/log.ts @@ -1,6 +1,6 @@ export const debug = (name: string, ...args: any[]) => { if (!global.debug) return; - consorArgs(args); + args = consorArgs(args); console.log( "\x1b[33m%s\x1b[0m" + "\x1b[1m\x1b[32m%s\x1b[0m", @@ -11,7 +11,7 @@ export const debug = (name: string, ...args: any[]) => { }; export const log = (name: string, ...args: string[]) => { - consorArgs(args); + args = consorArgs(args); console.log( "\x1b[33m%s\x1b[0m" + "\x1b[1m\x1b[36m%s\x1b[0m", @@ -22,7 +22,7 @@ export const log = (name: string, ...args: string[]) => { }; export const warn = (name: string, ...args: any[]) => { - consorArgs(args); + args = consorArgs(args); console.warn( "\x1b[33m%s\x1b[0m" + "\x1b[1m\x1b[36m%s\x1b[0m", @@ -33,7 +33,7 @@ export const warn = (name: string, ...args: any[]) => { }; export const error = (name: string, ...args: any[]) => { - consorArgs(args); + args = consorArgs(args); console.error( "\x1b[33m%s\x1b[0m" + "\x1b[1m\x1b[41m%s\x1b[0m\x1b[41m", @@ -45,15 +45,19 @@ export const error = (name: string, ...args: any[]) => { }; const consorArgs = (args: any[]) => { + let out = []; for (let i = 0; i < args.length; i++) { const arg = args[i]; - censorLogArg(arg); + out[i] = censorLogArg(arg); } + return out; } const censorLogArg = (arg: any) => { - if (typeof arg != "object") return; + if (typeof arg != "object" || arg == null) return arg; + let out: any = {}; for (let key in arg) { - if (key == "accountKey") arg[key] = new Array(arg[key].length).fill("*").join(""); - censorLogArg(arg[key]); + if (key == "accountKey") out[key] = new Array(arg[key].length).fill("*").join(""); + out[key] = censorLogArg(arg[key]); } + return out; } \ No newline at end of file