Allow self-hosted relays to opt into wss:// (#767)
* Add relay TLS schema fields * Wire relay TLS into websocket URLs * Propagate relay TLS from pairing offers * Expose relay TLS opt-in * Mark relay TLS fallback for removal * Preserve explicit relay TLS false * Align relay TLS defaults outside config loader
This commit is contained in:
@@ -40,6 +40,39 @@ describe("connection offer", () => {
|
||||
expect(parseConnectionOfferFromUrl(`https://app.paseo.sh/#offer=${encoded}`)).toEqual(offer);
|
||||
});
|
||||
|
||||
it("defaults relay TLS to false when absent", () => {
|
||||
expect(
|
||||
ConnectionOfferSchema.parse({
|
||||
v: 2,
|
||||
serverId: "server-123",
|
||||
daemonPublicKeyB64: "pubkey",
|
||||
relay: { endpoint: "relay.example.com:80" },
|
||||
}),
|
||||
).toEqual({
|
||||
v: 2,
|
||||
serverId: "server-123",
|
||||
daemonPublicKeyB64: "pubkey",
|
||||
relay: { endpoint: "relay.example.com:80", useTls: false },
|
||||
});
|
||||
});
|
||||
|
||||
it("round-trips relay TLS in offers without rejecting extra relay fields", () => {
|
||||
const offer = ConnectionOfferSchema.parse({
|
||||
v: 2,
|
||||
serverId: "server-123",
|
||||
daemonPublicKeyB64: "pubkey",
|
||||
relay: { endpoint: "relay.example.com:443", useTls: true, extra: "future" },
|
||||
});
|
||||
const encoded = encodeBase64UrlNoPadUtf8(JSON.stringify(offer));
|
||||
|
||||
expect(parseConnectionOfferFromUrl(`https://app.paseo.sh/#offer=${encoded}`)).toEqual({
|
||||
v: 2,
|
||||
serverId: "server-123",
|
||||
daemonPublicKeyB64: "pubkey",
|
||||
relay: { endpoint: "relay.example.com:443", useTls: true },
|
||||
});
|
||||
});
|
||||
|
||||
it("returns null when the URL has no offer fragment", () => {
|
||||
expect(parseConnectionOfferFromUrl("https://app.paseo.sh/pair")).toBeNull();
|
||||
});
|
||||
|
||||
@@ -12,6 +12,7 @@ export const ConnectionOfferV2Schema = z.object({
|
||||
daemonPublicKeyB64: z.string().min(1),
|
||||
relay: z.object({
|
||||
endpoint: z.string().min(1),
|
||||
useTls: z.boolean().optional().default(false),
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
buildDaemonWebSocketUrl,
|
||||
buildRelayWebSocketUrl,
|
||||
CURRENT_RELAY_PROTOCOL_VERSION,
|
||||
extractHostPortFromWebSocketUrl,
|
||||
normalizeRelayProtocolVersion,
|
||||
parseConnectionUri,
|
||||
serializeConnectionUri,
|
||||
@@ -173,4 +174,17 @@ describe("relay websocket URLs", () => {
|
||||
|
||||
expect(url.protocol).toBe("wss:");
|
||||
});
|
||||
|
||||
test("round-trips IPv6 relay endpoints with TLS enabled", () => {
|
||||
const wsUrl = buildRelayWebSocketUrl({
|
||||
endpoint: "[::1]:443",
|
||||
useTls: true,
|
||||
serverId: "srv_test",
|
||||
role: "client",
|
||||
});
|
||||
const url = new URL(wsUrl);
|
||||
|
||||
expect(url.protocol).toBe("wss:");
|
||||
expect(extractHostPortFromWebSocketUrl(wsUrl)).toBe("[::1]:443");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -198,6 +198,10 @@ export function buildRelayWebSocketUrl(params: {
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Migration fallback for stored relay connections/offers that predate
|
||||
* explicit relay useTls. Delete after two release cycles.
|
||||
*/
|
||||
export function shouldUseTlsForDefaultHostedRelay(endpoint: string): boolean {
|
||||
try {
|
||||
return normalizeHostPort(endpoint) === DEFAULT_RELAY_ENDPOINT;
|
||||
|
||||
Reference in New Issue
Block a user