feat: manage TLSA records
This commit is contained in:
1 parent
9c2fb9d15b
commit
a67183b646
14 files changed
+141
-15
No files matched your search
@@ -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 },
|
||||
|
||||
@@ -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
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user