feat: manage TLSA records
Test / test (push) Successful in 28m4s
Build and publish image / image (push) Successful in 28m43s

This commit is contained in:
bryanpedini committed 2026-11-22 11:31:59 +01:00
1 parent 9c2fb9d15b
commit a67183b646
14 files changed
+141 -15

No files matched your search

+8
View File
@@ -44,6 +44,7 @@ const IPV4: Field = { valid: ['192.0.2.55', '198.51.100.7', '203.0.113.200'], ho
const IPV6: Field = { valid: ['2001:db8::55', '2001:db8:0:0:0:0:0:56', '2001:DB8::57'], hostile: ['192.0.2.55', '::ffff:192.0.2.1', '2001:db8::g', SQL_INJECTION, SCRIPT, '', 1] };
const CAA_TAG: Field = { valid: ['issue', 'issuewild', 'iodef'], hostile: ['bad tag', SCRIPT, SQL_INJECTION, '', 'x'.repeat(256), 1] };
const CAA_FLAG: Field = { valid: [0, 128], hostile: [256, -1, '0', SQL_INJECTION, null] };
const OCTET: Field = { valid: [0, 1, 2, 3, 255], hostile: [256, -1, '3', 1.5, null, SQL_INJECTION] };
const SOA_TIMER: Field = { valid: [60, 3600, 604800, 2147483647], hostile: [0, -1, 2147483648, 4294967296, '3600', null, SQL_INJECTION] };
function hosts(zone: string): Field {
@@ -71,6 +72,13 @@ function fields(zone: string, type: RecordType): Record<string, Field> {
return { priority: U16, weight: U16, port: U16, target: { valid: ['sip.example.net.', '.'], hostile: host.hostile } };
case 'CAA':
return { flag: CAA_FLAG, tag: CAA_TAG, value: { valid: TEXT.valid.filter((t) => t !== '' && String(t).length < 256), hostile: TEXT.hostile } };
case 'TLSA':
return {
usage: OCTET,
selector: OCTET,
matching_type: { valid: [0], hostile: OCTET.hostile },
certificate: { valid: ['0123456789abcdef', '30' + 'AB'.repeat(40), 'ff'], hostile: ['', 'abc', 'xyz0', '0x1234', 'ab cd', SCRIPT, SQL_INJECTION, 7, null] },
};
case 'SOA':
return {
ns: { valid: ['ns1.example.net.', `ns1.${zone}`], hostile: host.hostile },
+6 -1
View File
@@ -3,7 +3,7 @@
import { expect } from '@playwright/test';
export const TYPES = ['A', 'AAAA', 'CNAME', 'NS', 'MX', 'TXT', 'SRV', 'CAA', 'SOA'] as const;
export const TYPES = ['A', 'AAAA', 'CNAME', 'NS', 'MX', 'TXT', 'SRV', 'CAA', 'TLSA', 'SOA'] as const;
export type RecordType = (typeof TYPES)[number];
export const EDITABLE_TYPES = TYPES.filter((t) => t !== 'SOA');
@@ -16,6 +16,7 @@ export const CANONICAL_KEYS: Readonly<Record<RecordType, readonly string[]>> = {
TXT: ['text'],
SRV: ['priority', 'weight', 'port', 'target'],
CAA: ['flag', 'tag', 'value'],
TLSA: ['usage', 'selector', 'matching_type', 'certificate'],
SOA: ['ns', 'MBox', 'refresh', 'retry', 'expire', 'minttl', 'serial'],
};
@@ -92,6 +93,8 @@ export function digData(type: RecordType, d: RecordData): string {
return `${d.priority} ${d.weight} ${d.port} ${d.target}`;
case 'CAA':
return `${d.flag} ${d.tag} ${dnsQuote(String(d.value))}`;
case 'TLSA':
return `${d.usage} ${d.selector} ${d.matching_type} ${d.certificate}`;
case 'SOA':
return `${d.ns} ${d.MBox} ${d.serial} ${d.refresh} ${d.retry} ${d.expire} ${d.minttl}`;
}
@@ -113,6 +116,8 @@ export function uiValue(type: RecordType, d: RecordData): string {
return `${d.priority} ${d.weight} ${d.port} ${d.target}`;
case 'CAA':
return `${d.flag} ${d.tag} "${d.value}"`;
case 'TLSA':
return `${d.usage} ${d.selector} ${d.matching_type} ${d.certificate}`;
case 'SOA':
return [d.ns, d.MBox, d.serial ?? 'dynamic', d.refresh, d.retry, d.expire, d.minttl].join(' ');
}
+15 -2
View File
@@ -7,7 +7,7 @@ import type { GroupConfig } from './env';
import type { RecordRow } from './mysql';
import type { Recorder } from './recorder';
export const PLUGIN_TYPES = ['A', 'AAAA', 'CNAME', 'NS', 'MX', 'TXT', 'SRV', 'CAA', 'SOA'];
export const PLUGIN_TYPES = ['A', 'AAAA', 'CNAME', 'NS', 'MX', 'TXT', 'SRV', 'CAA', 'TLSA', 'SOA'];
const MAX_CNAME_CHAIN = 10;
const DEFAULT_TTL = 360;
@@ -123,6 +123,14 @@ function rrFor(row: RecordRow, now: () => number): ModelRR | null {
if (str(c.value) === '' || str(c.tag) === '') return null;
return { name: owner, ttl, type: 'CAA', data: `${u32(c.flag) & 0xff} ${str(c.tag)} ${quote(str(c.value))}` };
}
case 'TLSA': {
const octet = (v: unknown) => typeof v === 'number' && Number.isInteger(v) && v >= 0 && v <= 255;
if (!octet(c.usage) || !octet(c.selector) || !octet(c.matching_type)) throw new ModelFailure('SERVFAIL');
const cert = str(c.certificate);
if (cert === '' || cert.length % 2 !== 0 || !/^[0-9a-fA-F]+$/.test(cert)) throw new ModelFailure('SERVFAIL');
if ((c.matching_type === 1 && cert.length !== 64) || (c.matching_type === 2 && cert.length !== 128)) throw new ModelFailure('SERVFAIL');
return { name: owner, ttl, type: 'TLSA', data: `${c.usage} ${c.selector} ${c.matching_type} ${cert.toLowerCase()}` };
}
case 'SOA': {
const serial = u32(c.serial) === 0 ? now() : u32(c.serial);
return {
@@ -242,12 +250,17 @@ export class PluginModel {
}
}
function tlsaData(data: string): string {
const [usage, selector, matching, ...certificate] = data.trim().split(/\s+/);
return `${usage} ${selector} ${matching} ${certificate.join('').toLowerCase()}`;
}
function canon(rrs: Array<ModelRR | DigRR>, wildcardOk: string): string[] {
return rrs
.map((r) => {
const name = r.name.toLowerCase();
const n = name.startsWith('*.') ? wildcardOk : name;
const data = r.type === 'SOA' ? r.data.toLowerCase().replace(/^(\S+ \S+) \d+/, '$1 SERIAL') : r.data;
const data = r.type === 'SOA' ? r.data.toLowerCase().replace(/^(\S+ \S+) \d+/, '$1 SERIAL') : r.type === 'TLSA' ? tlsaData(r.data) : r.data;
return `${n} ${r.ttl} ${r.type} ${data}`;
})
.sort();
+8
View File
@@ -168,6 +168,8 @@ test.describe('core flow', () => {
nosrv: { name: '_none._tcp', type: 'SRV', ttl: 3600, data: { priority: 0, weight: 0, port: 0, target: '.' } },
caa: { name: '', type: 'CAA', ttl: 3600, data: { flag: 0, tag: 'issue', value: 'ca.example.net' } },
iodef: { name: '', type: 'CAA', ttl: 3600, data: { flag: 128, tag: 'iodef', value: 'mailto:security@example.net' } },
tlsa: { name: '_25._tcp.mail', type: 'TLSA', ttl: 3600, data: { usage: 3, selector: 1, matching_type: 1, certificate: '0123456789abcdef'.repeat(4) } },
tlsafull: { name: '_443._tcp.www', type: 'TLSA', ttl: 300, data: { usage: 0, selector: 1, matching_type: 0, certificate: '302a300506032b6570032100d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a' } },
sub: { name: 'sub', type: 'NS', ttl: 3600, data: { host: 'ns.example.net.' } },
wild: { name: '*', type: 'A', ttl: 0, data: { ip: '192.0.2.99' } },
wilddev: { name: '*.dev', type: 'TXT', ttl: 600, data: { text: 'wildcard dev' } },
@@ -235,6 +237,8 @@ test.describe('core flow', () => {
await add('SRV with the . target', R.nosrv, input(R.nosrv, { priority: '0', weight: '0', port: '0', target: '.' }));
await add('CAA issue', R.caa, input(R.caa, { flag: '0', tag: 'issue', value: 'ca.example.net' }));
await add('CAA iodef critical', R.iodef, input(R.iodef, { flag: '128', tag: 'iodef', value: 'mailto:security@example.net' }));
await add('TLSA DANE-EE SHA-256 pasted with colons and uppercase', R.tlsa, input(R.tlsa, { usage: '3', selector: '1', matching_type: '1', certificate: '01:23:45:67:89:AB:CD:EF:'.repeat(4).slice(0, -1) }));
await add('TLSA with zero usage and exact match', R.tlsafull, input(R.tlsafull, { usage: '0', selector: '1', matching_type: '0', certificate: String(R.tlsafull.data.certificate) }));
await add('NS of a delegated subdomain', R.sub, input(R.sub, { host: 'ns.example.net' }));
await add('wildcard A with TTL 0', R.wild, input(R.wild, { ip: '192.0.2.99' }));
await adminUi.expectRow({ name: '*', type: 'A', value: '192.0.2.99', ttl: 'default (360 s)' });
@@ -271,6 +275,9 @@ test.describe('core flow', () => {
R.srv = { ...R.srv, data: { ...R.srv.data, port: 5061 } };
await edit('edit CAA value', R.iodef, { ...R.iodef, data: { flag: 128, tag: 'iodef', value: 'mailto:dns@example.net' } }, input(R.iodef, { flag: '128', tag: 'iodef', value: 'mailto:dns@example.net' }));
R.iodef = { ...R.iodef, data: { flag: 128, tag: 'iodef', value: 'mailto:dns@example.net' } };
const sha512 = 'fedcba9876543210'.repeat(8);
await edit('edit TLSA to SHA-512', R.tlsa, { ...R.tlsa, data: { usage: 2, selector: 0, matching_type: 2, certificate: sha512 } }, input(R.tlsa, { usage: '2', selector: '0', matching_type: '2', certificate: sha512 }));
R.tlsa = { ...R.tlsa, data: { usage: 2, selector: 0, matching_type: 2, certificate: sha512 } };
await edit('edit NS host', R.sub, { ...R.sub, data: { host: 'ns2.example.net.' } }, input(R.sub, { host: 'ns2.example.net.' }));
R.sub = { ...R.sub, data: { host: 'ns2.example.net.' } };
await edit('edit wildcard address', R.wild, { ...R.wild, data: { ip: '192.0.2.98' } }, input(R.wild, { ip: '192.0.2.98' }));
@@ -287,6 +294,7 @@ test.describe('core flow', () => {
await del('delete long TXT', R.longtxt);
await del('delete SRV with the . target', R.nosrv);
await del('delete CAA', R.iodef);
await del('delete TLSA', R.tlsafull);
await del('delete NS of the subdomain', R.sub);
await del('delete wildcard TXT', R.wilddev);
await del('delete one A of an RRset', R.www2);
+1
View File
@@ -132,6 +132,7 @@ test('seeded requests cover every API operation, path parameter, filter and DNS
TXT: { text: 'random fixture' },
SRV: { priority: 0, weight: 0, port: 0, target: '.' },
CAA: { flag: 0, tag: 'issue', value: 'ca.example.net' },
TLSA: { usage: 3, selector: 1, matching_type: 1, certificate: '0123456789abcdef'.repeat(4) },
SOA: { ns: 'ns.example.net.', MBox: 'hostmaster.example.net.', refresh: 3600, retry: 600, expire: 604800, minttl: 300 },
};
for (const [type, data] of Object.entries(types)) {