bug fixes
This commit is contained in:
parent
143b63f16d
commit
999ef760c0
6 changed files with 25 additions and 18 deletions
|
@ -32,7 +32,7 @@ export const signup: Act = {
|
||||||
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
|
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
|
||||||
let countAlias = alias(count(accounts.accID), "countAlias") as any;
|
let countAlias = alias(count(accounts.accID), "countAlias") as any;
|
||||||
let query = await select([countAlias], accounts)
|
let query = await select([countAlias], accounts)
|
||||||
.query(db, true);
|
.query(db);
|
||||||
let maxUsers = oConf.get("Settings", "maxUsers");
|
let maxUsers = oConf.get("Settings", "maxUsers");
|
||||||
let userNum = query[0][countAlias];
|
let userNum = query[0][countAlias];
|
||||||
if (maxUsers > -1 && userNum > 0 && userNum >= maxUsers) {
|
if (maxUsers > -1 && userNum > 0 && userNum >= maxUsers) {
|
||||||
|
@ -137,14 +137,14 @@ export const remote1 = {
|
||||||
data: {
|
data: {
|
||||||
name: "string",
|
name: "string",
|
||||||
server: "string",
|
server: "string",
|
||||||
key: "string",
|
publicKey: "string",
|
||||||
sign: "string",
|
sign: "string",
|
||||||
},
|
},
|
||||||
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
|
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
|
||||||
let server = await outbagURLfromTag(data.server);
|
let server = await outbagURLfromTag(data.server);
|
||||||
try {
|
try {
|
||||||
var cert = await getRemote(server);
|
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))) {
|
if (!(await verify(tagAcert, data.sign, cert))) {
|
||||||
client.suspect();
|
client.suspect();
|
||||||
aws("error", "signature");
|
aws("error", "signature");
|
||||||
|
@ -155,9 +155,10 @@ export const remote1 = {
|
||||||
client.server = server;
|
client.server = server;
|
||||||
client.challenge = get64(64);
|
client.challenge = get64(64);
|
||||||
client.state = STATE.remoteP;
|
client.state = STATE.remoteP;
|
||||||
client.remoteKey = data.key;
|
client.remoteKey = data.publicKey;
|
||||||
aws("ok", client.challenge);
|
aws("ok", client.challenge);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
client.suspect();
|
client.suspect();
|
||||||
aws("error", "signature");
|
aws("error", "signature");
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ export const addPostMethods = (server: express.Express) => {
|
||||||
))
|
))
|
||||||
.query(db);
|
.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();
|
if (req.suspect) req.suspect();
|
||||||
aws("error", "auth");
|
aws("error", "auth");
|
||||||
return;
|
return;
|
||||||
|
@ -128,6 +128,7 @@ export class postClient {
|
||||||
send = true;
|
send = true;
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
error("POST", "act error:", e);
|
error("POST", "act error:", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,9 +47,9 @@ export class outbagServer {
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
}
|
}
|
||||||
get httpsURL() {
|
get httpsURL() {
|
||||||
return `https://${this.host}:${this.port}${this.path}/`;
|
return `https://${this.host}:${this.port}${this.path}`;
|
||||||
}
|
}
|
||||||
get wsURL() {
|
get wsURL() {
|
||||||
return `wss://${this.host}:${this.port}${this.path}/`;
|
return `wss://${this.host}:${this.port}${this.path}`;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -89,12 +89,12 @@ const updateCert = async (server: outbagServer) => {
|
||||||
let resp = await fetch(server.httpsURL + "api/server/publicKey")
|
let resp = await fetch(server.httpsURL + "api/server/publicKey")
|
||||||
let json = await resp.json();
|
let json = await resp.json();
|
||||||
let { publicKey, expires } = 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 {
|
try {
|
||||||
await insert(servers.tag)
|
await insert(servers.tag)
|
||||||
.add(server.tag)
|
.add(server.tag)
|
||||||
.query(db);
|
.query(db);
|
||||||
} catch (error) {}
|
} catch (error) { }
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -103,6 +103,7 @@ const updateCert = async (server: outbagServer) => {
|
||||||
|
|
||||||
export const getRemote = async (server: outbagServer) => {
|
export const getRemote = async (server: outbagServer) => {
|
||||||
if (certList[server.tag] == null || certList[server.tag].exp >= uts()) await updateCert(server);
|
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;
|
if (certList[server.tag] != null) return certList[server.tag].cert;
|
||||||
else throw new Error("Cert Error");
|
else throw new Error("Cert Error");
|
||||||
};
|
};
|
|
@ -47,7 +47,7 @@ accounts.addAttributes({
|
||||||
accID: { type: INT, primaryKey: true, autoIncrement: true },
|
accID: { type: INT, primaryKey: true, autoIncrement: true },
|
||||||
name: { type: VARCHAR(100), default: PERMISSIONS.DEFAULT },
|
name: { type: VARCHAR(100), default: PERMISSIONS.DEFAULT },
|
||||||
|
|
||||||
rights: { type: BIGINT, default: PERMISSIONS.DEFAULT },
|
rights: { type: INT, default: PERMISSIONS.DEFAULT },
|
||||||
|
|
||||||
accountKeySalt: { type: VARCHAR(64) },
|
accountKeySalt: { type: VARCHAR(64) },
|
||||||
accountKey: { type: VARCHAR(64) },
|
accountKey: { type: VARCHAR(64) },
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
export const debug = (name: string, ...args: any[]) => {
|
export const debug = (name: string, ...args: any[]) => {
|
||||||
if (!global.debug) return;
|
if (!global.debug) return;
|
||||||
consorArgs(args);
|
args = consorArgs(args);
|
||||||
console.log(
|
console.log(
|
||||||
"\x1b[33m%s\x1b[0m" +
|
"\x1b[33m%s\x1b[0m" +
|
||||||
"\x1b[1m\x1b[32m%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[]) => {
|
export const log = (name: string, ...args: string[]) => {
|
||||||
consorArgs(args);
|
args = consorArgs(args);
|
||||||
console.log(
|
console.log(
|
||||||
"\x1b[33m%s\x1b[0m" +
|
"\x1b[33m%s\x1b[0m" +
|
||||||
"\x1b[1m\x1b[36m%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[]) => {
|
export const warn = (name: string, ...args: any[]) => {
|
||||||
consorArgs(args);
|
args = consorArgs(args);
|
||||||
console.warn(
|
console.warn(
|
||||||
"\x1b[33m%s\x1b[0m" +
|
"\x1b[33m%s\x1b[0m" +
|
||||||
"\x1b[1m\x1b[36m%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[]) => {
|
export const error = (name: string, ...args: any[]) => {
|
||||||
consorArgs(args);
|
args = consorArgs(args);
|
||||||
console.error(
|
console.error(
|
||||||
"\x1b[33m%s\x1b[0m" +
|
"\x1b[33m%s\x1b[0m" +
|
||||||
"\x1b[1m\x1b[41m%s\x1b[0m\x1b[41m",
|
"\x1b[1m\x1b[41m%s\x1b[0m\x1b[41m",
|
||||||
|
@ -45,15 +45,19 @@ export const error = (name: string, ...args: any[]) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const consorArgs = (args: any[]) => {
|
const consorArgs = (args: any[]) => {
|
||||||
|
let out = [];
|
||||||
for (let i = 0; i < args.length; i++) {
|
for (let i = 0; i < args.length; i++) {
|
||||||
const arg = args[i];
|
const arg = args[i];
|
||||||
censorLogArg(arg);
|
out[i] = censorLogArg(arg);
|
||||||
}
|
}
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
const censorLogArg = (arg: any) => {
|
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) {
|
for (let key in arg) {
|
||||||
if (key == "accountKey") arg[key] = new Array(arg[key].length).fill("*").join("");
|
if (key == "accountKey") out[key] = new Array(arg[key].length).fill("*").join("");
|
||||||
censorLogArg(arg[key]);
|
out[key] = censorLogArg(arg[key]);
|
||||||
}
|
}
|
||||||
|
return out;
|
||||||
}
|
}
|
Loading…
Reference in a new issue