post remote tests and fixes and logs removed
This commit is contained in:
parent
5a9970ff59
commit
05025d209a
7 changed files with 77 additions and 18 deletions
|
@ -167,11 +167,9 @@ export const remote1 = {
|
||||||
try {
|
try {
|
||||||
let server = await outbagURLfromTag(data.server);
|
let server = await outbagURLfromTag(data.server);
|
||||||
var cert = await getRemote(server);
|
var cert = await getRemote(server);
|
||||||
console.log(server, cert);
|
|
||||||
var tagAcert = `${data.name}@${server.host}:${server.port}-${data.publicKey}`;
|
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();
|
||||||
console.log("verify");
|
|
||||||
aws("error", "signature");
|
aws("error", "signature");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -183,7 +181,6 @@ export const remote1 = {
|
||||||
client.remoteKey = data.publicKey;
|
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");
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ export const addPostMethods = (server: express.Express) => {
|
||||||
}
|
}
|
||||||
debug("POST", "reveived:", req.body);
|
debug("POST", "reveived:", req.body);
|
||||||
const aws = (state: string, data: any) => {
|
const aws = (state: string, data: any) => {
|
||||||
|
debug("POST", "send:", state, data);
|
||||||
res.status(state == "error" ? 400 : 200);
|
res.status(state == "error" ? 400 : 200);
|
||||||
res.json({ data });
|
res.json({ data });
|
||||||
};
|
};
|
||||||
|
@ -38,8 +39,10 @@ export const addPostMethods = (server: express.Express) => {
|
||||||
try {
|
try {
|
||||||
let auth = authorization.parse(req.headers["authorization"] ?? "");
|
let auth = authorization.parse(req.headers["authorization"] ?? "");
|
||||||
if (auth.scheme == "outbagServer") {
|
if (auth.scheme == "outbagServer") {
|
||||||
|
debug("POST", "auth: outbag Server");
|
||||||
throw new Error("not implemented");
|
throw new Error("not implemented");
|
||||||
} else if (auth.token != null && typeof auth.token == "string") {
|
} else if (auth.token != null && typeof auth.token == "string") {
|
||||||
|
debug("POST", "auth: temp Token");
|
||||||
if (tempTokens[auth.token] != null) {
|
if (tempTokens[auth.token] != null) {
|
||||||
client = tempTokens[auth.token];
|
client = tempTokens[auth.token];
|
||||||
} else {
|
} else {
|
||||||
|
@ -47,7 +50,15 @@ export const addPostMethods = (server: express.Express) => {
|
||||||
aws("error", "token");
|
aws("error", "token");
|
||||||
return;
|
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 = new postClient(req.ip);
|
||||||
client.client.name = auth?.params?.name;
|
client.client.name = auth?.params?.name;
|
||||||
let serverTag = auth?.params?.server;
|
let serverTag = auth?.params?.server;
|
||||||
|
@ -100,35 +111,30 @@ export class postClient {
|
||||||
let { state, data, right, func } = act;
|
let { state, data, right, func } = act;
|
||||||
if (!(state & this.client.state)) {
|
if (!(state & this.client.state)) {
|
||||||
aws("error", "wrongstate");
|
aws("error", "wrongstate");
|
||||||
debug("POST", "send:", "error", "wrongstate");
|
|
||||||
this.client.suspect();
|
this.client.suspect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (typeof json.data == "undefined") {
|
if (typeof json.data == "undefined") {
|
||||||
aws("error", "data");
|
aws("error", "data");
|
||||||
debug("POST", "send:", "error", "data");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (data) {
|
if (data) {
|
||||||
for (let d in data) {
|
for (let d in data) {
|
||||||
if (!checktype(json.data[d], data[d])) {
|
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", "Data check error. Key: ", d, "; Type:", data[d], "; Value:", json.data[d]);
|
||||||
debug("POST", "send:", "error", "data");
|
aws("error", "data");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (right && !(await this.client.checkRight(right))) {
|
if (right && !(await this.client.checkRight(right))) {
|
||||||
aws("error", "right");
|
aws("error", "right");
|
||||||
debug("POST", "send:", "error", "right");
|
|
||||||
this.client.suspect();
|
this.client.suspect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var send = false;
|
var send = false;
|
||||||
try {
|
try {
|
||||||
await func(this.client, json.data, (state, data = "") => {
|
await func(this.client, json.data, (state, data = "") => {
|
||||||
debug("POST", "send:", state, data);
|
|
||||||
aws(state, data);
|
aws(state, data);
|
||||||
send = true;
|
send = true;
|
||||||
});
|
});
|
||||||
|
@ -137,11 +143,9 @@ export class postClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!send) {
|
if (!send) {
|
||||||
debug("POST", "send:", "error", "server");
|
|
||||||
aws("error", "server");
|
aws("error", "server");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
debug("POST", "error:", error);
|
|
||||||
aws("error", "server");
|
aws("error", "server");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@ export const generateTag = async () => {
|
||||||
selfTag = serverHostPort;
|
selfTag = serverHostPort;
|
||||||
} else selfTag = mainServerHost;
|
} else selfTag = mainServerHost;
|
||||||
if (initselfTag.httpsURL != selfTag.httpsURL) {
|
if (initselfTag.httpsURL != selfTag.httpsURL) {
|
||||||
console.log(initselfTag, initselfTag.httpsURL, selfTag.httpsURL);
|
|
||||||
debug("Outbag", "Not matching Server host, port, path and expected server link.");
|
debug("Outbag", "Not matching Server host, port, path and expected server link.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ function shallowEqual(object1, object2) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (let key of keys1) {
|
for (let key of keys1) {
|
||||||
if (object1[key] != object2[key]) {
|
if (object1[key] != null && object1[key] != object2[key]) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,21 +14,80 @@ const list = [
|
||||||
server: "localhost:7224",
|
server: "localhost:7224",
|
||||||
accountKey
|
accountKey
|
||||||
}, "ok", "");
|
}, "ok", "");
|
||||||
|
|
||||||
await req({}, "signup", {
|
await req({}, "signup", {
|
||||||
name: name1,
|
name: name1,
|
||||||
server: "localhost:7224",
|
server: "localhost:7224",
|
||||||
accountKey
|
accountKey
|
||||||
}, "error", "existence");
|
}, "error", "existence");
|
||||||
|
|
||||||
await req({}, "signup", {
|
await req({}, "signup", {
|
||||||
name: name2,
|
name: name2,
|
||||||
server: "localhost:7224",
|
server: "localhost:7224",
|
||||||
accountKey
|
accountKey
|
||||||
}, "ok", "");
|
}, "ok", "");
|
||||||
|
|
||||||
await req({}, "signup", {
|
await req({}, "signup", {
|
||||||
name: name2,
|
name: name2,
|
||||||
server: "localhost:7224",
|
server: "localhost:7224",
|
||||||
accountKey
|
accountKey
|
||||||
}, "error", "config");
|
}, "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", "");
|
||||||
|
|
||||||
}]
|
}]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ const list = [
|
||||||
}, "error", "signature");
|
}, "error", "signature");
|
||||||
await req(h2, "remote1", {
|
await req(h2, "remote1", {
|
||||||
name: name1,
|
name: name1,
|
||||||
server: "localhost:7223",
|
server: "localhost:7224",
|
||||||
publicKey,
|
publicKey,
|
||||||
sign: falseSignature
|
sign: falseSignature
|
||||||
}, "error", "signature");
|
}, "error", "signature");
|
||||||
|
|
|
@ -90,7 +90,7 @@ function shallowEqual(object1, object2) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (let key of keys1) {
|
for (let key of keys1) {
|
||||||
if (object1[key] != object2[key]) {
|
if (object1[key] != null && object1[key] != object2[key]) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue