feat: manage TLSA records
This commit is contained in:
1 parent
9c2fb9d15b
commit
a67183b646
14 files changed
+141
-15
No files matched your search
+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