bug fixes

This commit is contained in:
jusax23 2023-03-07 18:47:37 +01:00
parent 143b63f16d
commit 999ef760c0
Signed by: jusax23
GPG key ID: 499E2AA870C1CD41
6 changed files with 25 additions and 18 deletions

View file

@ -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");
}

View file

@ -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);
}

View file

@ -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}`;
}
};

View file

@ -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");
};

View file

@ -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) },

View file

@ -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;
}