post remote tests and fixes and logs removed

This commit is contained in:
jusax23 2023-03-12 19:10:36 +01:00
parent 5a9970ff59
commit 05025d209a
Signed by: jusax23
GPG key ID: 499E2AA870C1CD41
7 changed files with 77 additions and 18 deletions

View file

@ -167,11 +167,9 @@ export const remote1 = {
try {
let server = await outbagURLfromTag(data.server);
var cert = await getRemote(server);
console.log(server, cert);
var tagAcert = `${data.name}@${server.host}:${server.port}-${data.publicKey}`;
if (!(await verify(tagAcert, data.sign, cert))) {
client.suspect();
console.log("verify");
aws("error", "signature");
return;
}
@ -183,7 +181,6 @@ export const remote1 = {
client.remoteKey = data.publicKey;
aws("ok", client.challenge);
} catch (e) {
console.log(e);
client.suspect();
aws("error", "signature");
}

View file

@ -31,15 +31,18 @@ export const addPostMethods = (server: express.Express) => {
}
debug("POST", "reveived:", req.body);
const aws = (state: string, data: any) => {
debug("POST", "send:", state, data);
res.status(state == "error" ? 400 : 200);
res.json({data});
res.json({ data });
};
let client: postClient | null = null;
try {
let auth = authorization.parse(req.headers["authorization"] ?? "");
if (auth.scheme == "outbagServer") {
debug("POST", "auth: outbag Server");
throw new Error("not implemented");
} else if (auth.token != null && typeof auth.token == "string") {
debug("POST", "auth: temp Token");
if (tempTokens[auth.token] != null) {
client = tempTokens[auth.token];
} else {
@ -47,7 +50,15 @@ export const addPostMethods = (server: express.Express) => {
aws("error", "token");
return;
}
} else if (auth?.params?.name != null && auth?.params?.server != null && auth?.params?.accountKey != null && typeof auth?.params?.name == "string" && auth?.params?.server == "string" && typeof auth?.params?.accountKey == "string") {
} else if (
auth?.params?.name != null
&& auth?.params?.server != null
&& auth?.params?.accountKey != null
&& typeof auth?.params?.name == "string"
&& typeof auth?.params?.server == "string"
&& typeof auth?.params?.accountKey == "string"
) {
debug("POST", "auth: credentials");
client = new postClient(req.ip);
client.client.name = auth?.params?.name;
let serverTag = auth?.params?.server;
@ -100,35 +111,30 @@ export class postClient {
let { state, data, right, func } = act;
if (!(state & this.client.state)) {
aws("error", "wrongstate");
debug("POST", "send:", "error", "wrongstate");
this.client.suspect();
return;
}
if (typeof json.data == "undefined") {
aws("error", "data");
debug("POST", "send:", "error", "data");
return;
}
if (data) {
for (let d in data) {
if (!checktype(json.data[d], data[d])) {
aws("error", "data");
debug("POST", "Data check error. Key: ", d, "; Type:", data[d], "; Value:", json.data[d]);
debug("POST", "send:", "error", "data");
aws("error", "data");
return;
}
}
}
if (right && !(await this.client.checkRight(right))) {
aws("error", "right");
debug("POST", "send:", "error", "right");
this.client.suspect();
return;
}
var send = false;
try {
await func(this.client, json.data, (state, data = "") => {
debug("POST", "send:", state, data);
aws(state, data);
send = true;
});
@ -137,11 +143,9 @@ export class postClient {
}
if (!send) {
debug("POST", "send:", "error", "server");
aws("error", "server");
}
} catch (error) {
debug("POST", "error:", error);
aws("error", "server");
}
}

View file

@ -28,7 +28,6 @@ export const generateTag = async () => {
selfTag = serverHostPort;
} else selfTag = mainServerHost;
if (initselfTag.httpsURL != selfTag.httpsURL) {
console.log(initselfTag, initselfTag.httpsURL, selfTag.httpsURL);
debug("Outbag", "Not matching Server host, port, path and expected server link.");
return false;
}

View file

@ -31,7 +31,7 @@ function shallowEqual(object1, object2) {
return false;
}
for (let key of keys1) {
if (object1[key] != object2[key]) {
if (object1[key] != null && object1[key] != object2[key]) {
return false;
}
}
@ -47,7 +47,7 @@ async function postTester(url) {
headers: Object.assign({
"Content-Type": "application/json"
}, header),
body: JSON.stringify({data})
body: JSON.stringify({ data })
});
let resp = {

View file

@ -14,21 +14,80 @@ const list = [
server: "localhost:7224",
accountKey
}, "ok", "");
await req({}, "signup", {
name: name1,
server: "localhost:7224",
accountKey
}, "error", "existence");
await req({}, "signup", {
name: name2,
server: "localhost:7224",
accountKey
}, "ok", "");
await req({}, "signup", {
name: name2,
server: "localhost:7224",
accountKey
}, "error", "config");
}], ["remote", async (req) => {
let signature = await req({ "authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}` },
"createSignature", {
publicKey
}, "ok", null);
let falseSignature = await sign("lol", privateKey);
let token = (await req({}, "requestTempToken", {}, "ok", { token: null })).token;
await req({
"authorization": `Bearer ${token}`
}, "remote1", {
name: name1,
server: "localhost:7223",
publicKey,
sign: signature
}, "error", "signature");
await req({
"authorization": `Bearer ${token}`
}, "remote1", {
name: name1,
server: "localhost:7224",
publicKey,
sign: falseSignature
}, "error", "signature");
let challenge = await req({
"authorization": `Bearer ${token}`
}, "remote1", {
name: name1,
server: "localhost:7224",
publicKey,
sign: signature
}, "ok", null);
await req({
"authorization": `Bearer ${token}`
}, "remote1", {
name: name1,
server: "localhost:7224",
publicKey,
sign: signature
}, "error", "wrongstate");
await req({
"authorization": `Bearer ${token}`
}, "remote2", {
sign: await sign(challenge + "lol", privateKey)
}, "error", "signature");
await req({
"authorization": `Bearer ${token}`
}, "remote2", {
sign: await sign(challenge, privateKey)
}, "ok", "");
}]
];

View file

@ -53,7 +53,7 @@ const list = [
}, "error", "signature");
await req(h2, "remote1", {
name: name1,
server: "localhost:7223",
server: "localhost:7224",
publicKey,
sign: falseSignature
}, "error", "signature");

View file

@ -90,7 +90,7 @@ function shallowEqual(object1, object2) {
return false;
}
for (let key of keys1) {
if (object1[key] != object2[key]) {
if (object1[key] != null && object1[key] != object2[key]) {
return false;
}
}