fix on new idpk

This commit is contained in:
rustdesk 2022-03-26 16:30:38 +08:00
parent 101bcbce9c
commit abadb37baf
3 changed files with 1141 additions and 15 deletions

View File

@ -90,6 +90,7 @@ export default class Connection {
licence_key: localStorage.getItem("key") || undefined,
conn_type,
nat_type,
token: localStorage.getItem("access_token") || undefined,
});
ws.sendRendezvous({ punch_hole_request });
const msg = (await ws.next()) as rendezvous.RendezvousMessage;
@ -131,7 +132,7 @@ export default class Connection {
const pk = rr.pk;
let uri = rr.relay_server;
if (uri) {
uri = getrUriFromRs(uri, true);
uri = getrUriFromRs(uri, true, 2);
} else {
uri = getDefaultUri(true);
}
@ -155,7 +156,13 @@ export default class Connection {
if (pk) {
const RS_PK = "OeVuKk5nlHiXp+APNn0Y3pC1Iwpwn44JGqrQCsWqmBw=";
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) {
pk = undefined;
}
@ -170,14 +177,16 @@ export default class Connection {
}
if (!pk) {
// 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;
}
const msg = (await this._ws?.next()) as message.Message;
let signedId: any = msg?.signed_id;
if (!signedId) {
console.error("Handshake failed: invalid message type");
this._ws?.sendMessage({});
const public_key = message.PublicKey.fromPartial({});
this._ws?.sendMessage({ public_key });
return;
}
try {
@ -190,21 +199,21 @@ export default class Connection {
this._ws?.sendMessage({ public_key });
return;
}
signedId = new TextDecoder().decode(signedId!);
const tmp = signedId.split("\0");
const id = tmp[0];
let theirPk = tmp[1];
const idpk = message.IdPk.decode(signedId);
const id = idpk.id;
const theirPk = idpk.pk;
if (id != this._id!) {
console.error("Handshake failed: sign failure");
this._ws?.sendMessage({});
const public_key = message.PublicKey.fromPartial({});
this._ws?.sendMessage({ public_key });
return;
}
theirPk = globals.decodeBase64(theirPk);
if (theirPk.length != 32) {
console.error(
"Handshake failed: invalid public box key length from peer"
);
this._ws?.sendMessage({});
const public_key = message.PublicKey.fromPartial({});
this._ws?.sendMessage({ public_key });
return;
}
const [mySk, asymmetric_value] = globals.genBoxKeyPair();
@ -703,14 +712,18 @@ testDelay();
function getDefaultUri(isRelay: Boolean = false): string {
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) {
const tmp = uri.split(":");
const port = parseInt(tmp[1]);
uri = tmp[0] + ":" + (port + (isRelay ? 3 : 2));
uri = tmp[0] + ":" + (port + (isRelay ? roffset || 3 : 2));
} else {
uri += ":" + (PORT + (isRelay ? 3 : 2));
}

File diff suppressed because it is too large Load Diff

View File

@ -100,6 +100,7 @@ export interface PunchHoleRequest {
nat_type: NatType;
licence_key: string;
conn_type: ConnType;
token: string;
}
export interface PunchHole {
@ -275,6 +276,7 @@ export interface RequestRelay {
secure: boolean;
licence_key: string;
conn_type: ConnType;
token: string;
}
export interface RelayResponse {
@ -461,7 +463,7 @@ export const RegisterPeerResponse = {
};
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 = {
@ -481,6 +483,9 @@ export const PunchHoleRequest = {
if (message.conn_type !== 0) {
writer.uint32(32).int32(message.conn_type);
}
if (message.token !== "") {
writer.uint32(42).string(message.token);
}
return writer;
},
@ -503,6 +508,9 @@ export const PunchHoleRequest = {
case 4:
message.conn_type = reader.int32() as any;
break;
case 5:
message.token = reader.string();
break;
default:
reader.skipType(tag & 7);
break;
@ -519,6 +527,7 @@ export const PunchHoleRequest = {
conn_type: isSet(object.conn_type)
? connTypeFromJSON(object.conn_type)
: 0,
token: isSet(object.token) ? String(object.token) : "",
};
},
@ -531,6 +540,7 @@ export const PunchHoleRequest = {
(obj.licence_key = message.licence_key);
message.conn_type !== undefined &&
(obj.conn_type = connTypeToJSON(message.conn_type));
message.token !== undefined && (obj.token = message.token);
return obj;
},
@ -542,6 +552,7 @@ export const PunchHoleRequest = {
message.nat_type = object.nat_type ?? 0;
message.licence_key = object.licence_key ?? "";
message.conn_type = object.conn_type ?? 0;
message.token = object.token ?? "";
return message;
},
};
@ -1222,6 +1233,7 @@ function createBaseRequestRelay(): RequestRelay {
secure: false,
licence_key: "",
conn_type: 0,
token: "",
};
}
@ -1251,6 +1263,9 @@ export const RequestRelay = {
if (message.conn_type !== 0) {
writer.uint32(56).int32(message.conn_type);
}
if (message.token !== "") {
writer.uint32(66).string(message.token);
}
return writer;
},
@ -1282,6 +1297,9 @@ export const RequestRelay = {
case 7:
message.conn_type = reader.int32() as any;
break;
case 8:
message.token = reader.string();
break;
default:
reader.skipType(tag & 7);
break;
@ -1305,6 +1323,7 @@ export const RequestRelay = {
conn_type: isSet(object.conn_type)
? connTypeFromJSON(object.conn_type)
: 0,
token: isSet(object.token) ? String(object.token) : "",
};
},
@ -1325,6 +1344,7 @@ export const RequestRelay = {
(obj.licence_key = message.licence_key);
message.conn_type !== undefined &&
(obj.conn_type = connTypeToJSON(message.conn_type));
message.token !== undefined && (obj.token = message.token);
return obj;
},
@ -1339,6 +1359,7 @@ export const RequestRelay = {
message.secure = object.secure ?? false;
message.licence_key = object.licence_key ?? "";
message.conn_type = object.conn_type ?? 0;
message.token = object.token ?? "";
return message;
},
};