feat(native): a client certificate can be added on the address screen before connecting

The import was only offered once the check saw the proxy ask for a certificate during the handshake. A proxy that refuses without asking left no way in. The wiki also points to the certificate's new place in Settings and explains why a certificate from an iOS configuration profile cannot be used by the app.
This commit is contained in:
Maurice
2026-11-12 08:42:16 +01:00
parent 1323183cce
commit cc5eca5553
4 changed files with 63 additions and 5 deletions
+16 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it, vi } from 'vitest';
import { candidateUrls, probeDemo, probeServer, type ProbeResponse } from './serverAddress';
import { candidateUrls, certificateTargetFor, probeDemo, probeServer, type ProbeResponse } from './serverAddress';
const features = (
url: string,
@@ -24,6 +24,21 @@ describe('candidateUrls', () => {
});
});
describe('certificateTargetFor', () => {
it('keeps a certificate for the https address the typed text stands for', () => {
expect(certificateTargetFor('Trek.Example.com')).toEqual({ host: 'trek.example.com', port: 443 });
expect(certificateTargetFor(' nas.local:8443/trek ')).toEqual({ host: 'nas.local', port: 8443 });
expect(certificateTargetFor('https://trek.example.com:443/')).toEqual({ host: 'trek.example.com', port: 443 });
});
it('has no target for a plain http address or nothing typed', () => {
expect(certificateTargetFor('http://nas.local:3001')).toBeNull();
expect(certificateTargetFor('')).toBeNull();
expect(certificateTargetFor(' ')).toBeNull();
expect(certificateTargetFor('ftp://trek.example.com')).toBeNull();
});
});
describe('probeServer', () => {
it('accepts a server at the minimum native API version or above', async () => {
for (const nativeApi of [2, 3]) {
+12
View File
@@ -74,6 +74,18 @@ export function candidateUrls(input: string): string[] {
return candidates.filter((url): url is string => url !== null);
}
/**
* The host and port a client certificate added on the address screen, before
* any check, is kept for: the https address the typed text stands for. Null
* for nothing typed or a plain http address, which never gets a certificate.
*/
export function certificateTargetFor(input: string): { host: string; port: number } | null {
const https = candidateUrls(input).find((url) => url.startsWith('https://'));
if (!https) return null;
const url = new URL(https);
return { host: url.hostname.toLowerCase(), port: url.port ? Number(url.port) : 443 };
}
function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === 'object' && value !== null;
}