fix on new idpk
This commit is contained in:
parent
101bcbce9c
commit
abadb37baf
@ -90,6 +90,7 @@ export default class Connection {
|
|||||||
licence_key: localStorage.getItem("key") || undefined,
|
licence_key: localStorage.getItem("key") || undefined,
|
||||||
conn_type,
|
conn_type,
|
||||||
nat_type,
|
nat_type,
|
||||||
|
token: localStorage.getItem("access_token") || undefined,
|
||||||
});
|
});
|
||||||
ws.sendRendezvous({ punch_hole_request });
|
ws.sendRendezvous({ punch_hole_request });
|
||||||
const msg = (await ws.next()) as rendezvous.RendezvousMessage;
|
const msg = (await ws.next()) as rendezvous.RendezvousMessage;
|
||||||
@ -131,7 +132,7 @@ export default class Connection {
|
|||||||
const pk = rr.pk;
|
const pk = rr.pk;
|
||||||
let uri = rr.relay_server;
|
let uri = rr.relay_server;
|
||||||
if (uri) {
|
if (uri) {
|
||||||
uri = getrUriFromRs(uri, true);
|
uri = getrUriFromRs(uri, true, 2);
|
||||||
} else {
|
} else {
|
||||||
uri = getDefaultUri(true);
|
uri = getDefaultUri(true);
|
||||||
}
|
}
|
||||||
@ -155,7 +156,13 @@ export default class Connection {
|
|||||||
if (pk) {
|
if (pk) {
|
||||||
const RS_PK = "OeVuKk5nlHiXp+APNn0Y3pC1Iwpwn44JGqrQCsWqmBw=";
|
const RS_PK = "OeVuKk5nlHiXp+APNn0Y3pC1Iwpwn44JGqrQCsWqmBw=";
|
||||||
try {
|
try {
|
||||||
pk = await globals.verify(pk, RS_PK).catch();
|
pk = await globals.verify(pk, localStorage.getItem("key") || RS_PK);
|
||||||
|
if (pk) {
|
||||||
|
const idpk = message.IdPk.decode(pk);
|
||||||
|
if (idpk.id == this._id) {
|
||||||
|
pk = idpk.pk;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (pk?.length != 32) {
|
if (pk?.length != 32) {
|
||||||
pk = undefined;
|
pk = undefined;
|
||||||
}
|
}
|
||||||
@ -170,14 +177,16 @@ export default class Connection {
|
|||||||
}
|
}
|
||||||
if (!pk) {
|
if (!pk) {
|
||||||
// send an empty message out in case server is setting up secure and waiting for first message
|
// send an empty message out in case server is setting up secure and waiting for first message
|
||||||
this._ws?.sendMessage({});
|
const public_key = message.PublicKey.fromPartial({});
|
||||||
|
this._ws?.sendMessage({ public_key });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const msg = (await this._ws?.next()) as message.Message;
|
const msg = (await this._ws?.next()) as message.Message;
|
||||||
let signedId: any = msg?.signed_id;
|
let signedId: any = msg?.signed_id;
|
||||||
if (!signedId) {
|
if (!signedId) {
|
||||||
console.error("Handshake failed: invalid message type");
|
console.error("Handshake failed: invalid message type");
|
||||||
this._ws?.sendMessage({});
|
const public_key = message.PublicKey.fromPartial({});
|
||||||
|
this._ws?.sendMessage({ public_key });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -190,21 +199,21 @@ export default class Connection {
|
|||||||
this._ws?.sendMessage({ public_key });
|
this._ws?.sendMessage({ public_key });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
signedId = new TextDecoder().decode(signedId!);
|
const idpk = message.IdPk.decode(signedId);
|
||||||
const tmp = signedId.split("\0");
|
const id = idpk.id;
|
||||||
const id = tmp[0];
|
const theirPk = idpk.pk;
|
||||||
let theirPk = tmp[1];
|
|
||||||
if (id != this._id!) {
|
if (id != this._id!) {
|
||||||
console.error("Handshake failed: sign failure");
|
console.error("Handshake failed: sign failure");
|
||||||
this._ws?.sendMessage({});
|
const public_key = message.PublicKey.fromPartial({});
|
||||||
|
this._ws?.sendMessage({ public_key });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
theirPk = globals.decodeBase64(theirPk);
|
|
||||||
if (theirPk.length != 32) {
|
if (theirPk.length != 32) {
|
||||||
console.error(
|
console.error(
|
||||||
"Handshake failed: invalid public box key length from peer"
|
"Handshake failed: invalid public box key length from peer"
|
||||||
);
|
);
|
||||||
this._ws?.sendMessage({});
|
const public_key = message.PublicKey.fromPartial({});
|
||||||
|
this._ws?.sendMessage({ public_key });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const [mySk, asymmetric_value] = globals.genBoxKeyPair();
|
const [mySk, asymmetric_value] = globals.genBoxKeyPair();
|
||||||
@ -703,14 +712,18 @@ testDelay();
|
|||||||
|
|
||||||
function getDefaultUri(isRelay: Boolean = false): string {
|
function getDefaultUri(isRelay: Boolean = false): string {
|
||||||
const host = localStorage.getItem("custom-rendezvous-server");
|
const host = localStorage.getItem("custom-rendezvous-server");
|
||||||
return SCHEMA + (host || HOST) + ":" + (PORT + (isRelay ? 3 : 2));
|
return getrUriFromRs(host || HOST, isRelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getrUriFromRs(uri: string, isRelay: Boolean = false): string {
|
function getrUriFromRs(
|
||||||
|
uri: string,
|
||||||
|
isRelay: Boolean = false,
|
||||||
|
roffset: number = 0
|
||||||
|
): string {
|
||||||
if (uri.indexOf(":") > 0) {
|
if (uri.indexOf(":") > 0) {
|
||||||
const tmp = uri.split(":");
|
const tmp = uri.split(":");
|
||||||
const port = parseInt(tmp[1]);
|
const port = parseInt(tmp[1]);
|
||||||
uri = tmp[0] + ":" + (port + (isRelay ? 3 : 2));
|
uri = tmp[0] + ":" + (port + (isRelay ? roffset || 3 : 2));
|
||||||
} else {
|
} else {
|
||||||
uri += ":" + (PORT + (isRelay ? 3 : 2));
|
uri += ":" + (PORT + (isRelay ? 3 : 2));
|
||||||
}
|
}
|
||||||
|
1092
src/message.ts
1092
src/message.ts
File diff suppressed because it is too large
Load Diff
@ -100,6 +100,7 @@ export interface PunchHoleRequest {
|
|||||||
nat_type: NatType;
|
nat_type: NatType;
|
||||||
licence_key: string;
|
licence_key: string;
|
||||||
conn_type: ConnType;
|
conn_type: ConnType;
|
||||||
|
token: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PunchHole {
|
export interface PunchHole {
|
||||||
@ -275,6 +276,7 @@ export interface RequestRelay {
|
|||||||
secure: boolean;
|
secure: boolean;
|
||||||
licence_key: string;
|
licence_key: string;
|
||||||
conn_type: ConnType;
|
conn_type: ConnType;
|
||||||
|
token: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RelayResponse {
|
export interface RelayResponse {
|
||||||
@ -461,7 +463,7 @@ export const RegisterPeerResponse = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function createBasePunchHoleRequest(): PunchHoleRequest {
|
function createBasePunchHoleRequest(): PunchHoleRequest {
|
||||||
return { id: "", nat_type: 0, licence_key: "", conn_type: 0 };
|
return { id: "", nat_type: 0, licence_key: "", conn_type: 0, token: "" };
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PunchHoleRequest = {
|
export const PunchHoleRequest = {
|
||||||
@ -481,6 +483,9 @@ export const PunchHoleRequest = {
|
|||||||
if (message.conn_type !== 0) {
|
if (message.conn_type !== 0) {
|
||||||
writer.uint32(32).int32(message.conn_type);
|
writer.uint32(32).int32(message.conn_type);
|
||||||
}
|
}
|
||||||
|
if (message.token !== "") {
|
||||||
|
writer.uint32(42).string(message.token);
|
||||||
|
}
|
||||||
return writer;
|
return writer;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -503,6 +508,9 @@ export const PunchHoleRequest = {
|
|||||||
case 4:
|
case 4:
|
||||||
message.conn_type = reader.int32() as any;
|
message.conn_type = reader.int32() as any;
|
||||||
break;
|
break;
|
||||||
|
case 5:
|
||||||
|
message.token = reader.string();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
reader.skipType(tag & 7);
|
reader.skipType(tag & 7);
|
||||||
break;
|
break;
|
||||||
@ -519,6 +527,7 @@ export const PunchHoleRequest = {
|
|||||||
conn_type: isSet(object.conn_type)
|
conn_type: isSet(object.conn_type)
|
||||||
? connTypeFromJSON(object.conn_type)
|
? connTypeFromJSON(object.conn_type)
|
||||||
: 0,
|
: 0,
|
||||||
|
token: isSet(object.token) ? String(object.token) : "",
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -531,6 +540,7 @@ export const PunchHoleRequest = {
|
|||||||
(obj.licence_key = message.licence_key);
|
(obj.licence_key = message.licence_key);
|
||||||
message.conn_type !== undefined &&
|
message.conn_type !== undefined &&
|
||||||
(obj.conn_type = connTypeToJSON(message.conn_type));
|
(obj.conn_type = connTypeToJSON(message.conn_type));
|
||||||
|
message.token !== undefined && (obj.token = message.token);
|
||||||
return obj;
|
return obj;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -542,6 +552,7 @@ export const PunchHoleRequest = {
|
|||||||
message.nat_type = object.nat_type ?? 0;
|
message.nat_type = object.nat_type ?? 0;
|
||||||
message.licence_key = object.licence_key ?? "";
|
message.licence_key = object.licence_key ?? "";
|
||||||
message.conn_type = object.conn_type ?? 0;
|
message.conn_type = object.conn_type ?? 0;
|
||||||
|
message.token = object.token ?? "";
|
||||||
return message;
|
return message;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -1222,6 +1233,7 @@ function createBaseRequestRelay(): RequestRelay {
|
|||||||
secure: false,
|
secure: false,
|
||||||
licence_key: "",
|
licence_key: "",
|
||||||
conn_type: 0,
|
conn_type: 0,
|
||||||
|
token: "",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1251,6 +1263,9 @@ export const RequestRelay = {
|
|||||||
if (message.conn_type !== 0) {
|
if (message.conn_type !== 0) {
|
||||||
writer.uint32(56).int32(message.conn_type);
|
writer.uint32(56).int32(message.conn_type);
|
||||||
}
|
}
|
||||||
|
if (message.token !== "") {
|
||||||
|
writer.uint32(66).string(message.token);
|
||||||
|
}
|
||||||
return writer;
|
return writer;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -1282,6 +1297,9 @@ export const RequestRelay = {
|
|||||||
case 7:
|
case 7:
|
||||||
message.conn_type = reader.int32() as any;
|
message.conn_type = reader.int32() as any;
|
||||||
break;
|
break;
|
||||||
|
case 8:
|
||||||
|
message.token = reader.string();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
reader.skipType(tag & 7);
|
reader.skipType(tag & 7);
|
||||||
break;
|
break;
|
||||||
@ -1305,6 +1323,7 @@ export const RequestRelay = {
|
|||||||
conn_type: isSet(object.conn_type)
|
conn_type: isSet(object.conn_type)
|
||||||
? connTypeFromJSON(object.conn_type)
|
? connTypeFromJSON(object.conn_type)
|
||||||
: 0,
|
: 0,
|
||||||
|
token: isSet(object.token) ? String(object.token) : "",
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -1325,6 +1344,7 @@ export const RequestRelay = {
|
|||||||
(obj.licence_key = message.licence_key);
|
(obj.licence_key = message.licence_key);
|
||||||
message.conn_type !== undefined &&
|
message.conn_type !== undefined &&
|
||||||
(obj.conn_type = connTypeToJSON(message.conn_type));
|
(obj.conn_type = connTypeToJSON(message.conn_type));
|
||||||
|
message.token !== undefined && (obj.token = message.token);
|
||||||
return obj;
|
return obj;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -1339,6 +1359,7 @@ export const RequestRelay = {
|
|||||||
message.secure = object.secure ?? false;
|
message.secure = object.secure ?? false;
|
||||||
message.licence_key = object.licence_key ?? "";
|
message.licence_key = object.licence_key ?? "";
|
||||||
message.conn_type = object.conn_type ?? 0;
|
message.conn_type = object.conn_type ?? 0;
|
||||||
|
message.token = object.token ?? "";
|
||||||
return message;
|
return message;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user