small changes
This commit is contained in:
parent
ed4b74362e
commit
8accb3fd2f
8 changed files with 42 additions and 25 deletions
|
@ -144,7 +144,7 @@ export const addOTA = {
|
|||
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
|
||||
try {
|
||||
await insert(signupOTA.token, signupOTA.expires, signupOTA.usesLeft)
|
||||
.add(data.token, data.expires, data. usesLeft)
|
||||
.add(data.token, data.expires, data.usesLeft)
|
||||
.query(db);
|
||||
} catch (error) {
|
||||
await update(signupOTA)
|
||||
|
|
|
@ -6,8 +6,22 @@ import { oConf } from "../../sys/config.js";
|
|||
import { sha256, verify } from "../../sys/crypto.js";
|
||||
import { accounts, db, signupOTA as signupOTATable } from "../../sys/db.js";
|
||||
import { get64, uts } from "../../sys/tools.js";
|
||||
import { addTempToken, postClient } from "../post.js";
|
||||
import { Act, Client, STATE } from "../user.js";
|
||||
|
||||
export const requestTempToken: Act = {
|
||||
state: STATE.no,
|
||||
right: 0,
|
||||
data: {},
|
||||
func: async (client: Client, data: any, aws: (code: string, data: any) => void): Promise<void> => {
|
||||
if (!(client instanceof postClient)) return void aws("error", "mode");
|
||||
let token = addTempToken(client);
|
||||
aws("ok", {
|
||||
token
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const signup: Act = {
|
||||
state: STATE.no,
|
||||
right: 0,
|
||||
|
@ -128,7 +142,7 @@ export const remote1 = {
|
|||
},
|
||||
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
|
||||
data.server = await outbagURLshort(data.server);
|
||||
try{
|
||||
try {
|
||||
var cert = await getRemote(data.server);
|
||||
var tagAcert = data.name + "@" + data.server + "-" + data.key;
|
||||
if (!(await verify(tagAcert, data.sign, cert))) {
|
||||
|
@ -143,9 +157,9 @@ export const remote1 = {
|
|||
client.state = STATE.remoteP;
|
||||
client.remoteKey = data.key;
|
||||
aws("ok", client.challenge);
|
||||
}catch (e){
|
||||
} catch (e) {
|
||||
client.suspect();
|
||||
aws("error","signature");
|
||||
aws("error", "signature");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -157,10 +171,10 @@ export const remote2 = {
|
|||
sign: "string"
|
||||
},
|
||||
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
|
||||
if(await verify(client.challenge,data.sign,client.remoteKey)){
|
||||
if (await verify(client.challenge, data.sign, client.remoteKey)) {
|
||||
aws("ok", "");
|
||||
client.state = STATE.remote;
|
||||
}else{
|
||||
} else {
|
||||
client.suspect();
|
||||
aws("error", "signature");
|
||||
}
|
||||
|
|
0
src/api/acts/server.ts
Normal file
0
src/api/acts/server.ts
Normal file
|
@ -28,11 +28,13 @@ export const addPostMethods = (server: express.Express) => {
|
|||
let client: postClient | null = null;
|
||||
try {
|
||||
let auth = authorization.parse(req.headers["authorization"] ?? "");
|
||||
if (auth.token != null && typeof auth.token == "string") {
|
||||
if (auth.scheme == "outbagServer") {
|
||||
|
||||
} else if (auth.token != null && typeof auth.token == "string") {
|
||||
if (tempTokens[auth.token] != null) {
|
||||
client = tempTokens[auth.token];
|
||||
} else {
|
||||
if(req.suspect)req.suspect();
|
||||
if (req.suspect) req.suspect();
|
||||
aws("error", "token");
|
||||
return;
|
||||
}
|
||||
|
@ -50,7 +52,7 @@ export const addPostMethods = (server: express.Express) => {
|
|||
.query(db);
|
||||
|
||||
if (query.length == 0 || query[0].accountKey != sha256((query[0].accountKeySalt ?? '') + accountKey)) {
|
||||
if(req.suspect)req.suspect();
|
||||
if (req.suspect) req.suspect();
|
||||
aws("error", "auth");
|
||||
return;
|
||||
}
|
||||
|
@ -72,7 +74,7 @@ export const addPostMethods = (server: express.Express) => {
|
|||
}
|
||||
}
|
||||
|
||||
class postClient extends Client {
|
||||
export class postClient extends Client {
|
||||
lastReq = uts();
|
||||
constructor(ip: string) {
|
||||
super(ip);
|
||||
|
|
|
@ -3,10 +3,11 @@ import { accounts, db, roomMembers, rooms } from "../sys/db.js";
|
|||
import { addBruteforcePotantial } from "../sys/bruteforce.js";
|
||||
|
||||
export const STATE = {
|
||||
no: 0b0001,
|
||||
remoteP: 0b0010,
|
||||
remote: 0b0100,
|
||||
client: 0b1000
|
||||
no: 0b00001,
|
||||
remoteP: 0b00010,
|
||||
remote: 0b00100,
|
||||
client: 0b01000,
|
||||
server: 0b10000,
|
||||
};
|
||||
|
||||
export const MODE = {
|
||||
|
|
|
@ -15,7 +15,7 @@ export const wsOnConnection = (socket: ws.WebSocket, req: http.IncomingMessage)
|
|||
|
||||
let clients: wsClient[] = [];
|
||||
|
||||
class wsClient extends Client {
|
||||
export class wsClient extends Client {
|
||||
socket: ws.WebSocket;
|
||||
open = true;
|
||||
activeRequests = 0;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { outbagURL } from "./outbagURL.js";
|
||||
import { outbagURL, outbagURLshort } from "./outbagURL.js";
|
||||
import { db, serverCerts } from "../sys/db.js"
|
||||
import { eq, exists, insert, not, remove, select, update } from "dblang";
|
||||
import { eq, insert, select, update } from "dblang";
|
||||
import { error, log } from "../sys/log.js";
|
||||
import { uts } from "../sys/tools.js";
|
||||
import { getSettings, setSettings, SETTINGS } from "../sys/settings.js"
|
||||
|
@ -27,7 +27,6 @@ export const startUpdateCerts = () => {
|
|||
}, 100);
|
||||
}
|
||||
|
||||
|
||||
async function updateRemote(url: string, pKey: string = ""): Promise<boolean | string> {
|
||||
var urlP = await outbagURL(url);
|
||||
return new Promise((res, rej) => {
|
||||
|
@ -63,9 +62,9 @@ async function updateRemote(url: string, pKey: string = ""): Promise<boolean | s
|
|||
return;
|
||||
}
|
||||
res(false);
|
||||
})
|
||||
})
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const getRemote = async (url: string) => {
|
||||
let query = await select([serverCerts.publicKey, serverCerts.expires], serverCerts)
|
||||
|
@ -74,4 +73,4 @@ export const getRemote = async (url: string) => {
|
|||
if (query.length == 0 || query[0][serverCerts.expires] < uts() - 60)
|
||||
return await updateRemote(url, query[0][serverCerts.publicKey]);
|
||||
return query[0][serverCerts.publicKey];
|
||||
}
|
||||
};
|
||||
|
|
|
@ -72,7 +72,8 @@ serverCerts.addAttributes({
|
|||
serverCertID: { type: INT, primaryKey: true, autoIncrement: true },
|
||||
url: { type: TEXT },
|
||||
publicKey: { type: TEXT },
|
||||
expires: { type: BIGINT }
|
||||
expires: { type: BIGINT },
|
||||
token: { type: TEXT, notNull: false },
|
||||
});
|
||||
|
||||
export const signupOTA = db.newTable("signupOTA");
|
||||
|
|
Loading…
Reference in a new issue