|
| 1 | +# Complex DNS Record Types |
| 2 | + |
| 3 | +This section covers advanced DNS record types and their usage patterns. |
| 4 | + |
| 5 | +## CAA (Certification Authority Authorization) |
| 6 | + |
| 7 | +CAA records specify which Certificate Authorities are allowed to issue certificates: |
| 8 | + |
| 9 | +```ts |
| 10 | +const caaResponse = await client.query({ |
| 11 | + name: 'example.com', |
| 12 | + type: 'CAA' |
| 13 | +}) |
| 14 | + |
| 15 | +interface CAARecord { |
| 16 | + flags: number // Record flags |
| 17 | + tag: string // 'issue', 'issuewild', or 'iodef' |
| 18 | + value: string // CA domain or reporting URL |
| 19 | +} |
| 20 | + |
| 21 | +// Example usage |
| 22 | +const caaRecords = caaResponse.answers.map(answer => answer.data as CAARecord) |
| 23 | +caaRecords.forEach((record) => { |
| 24 | + if (record.tag === 'issue') { |
| 25 | + console.log(`Allowed CA: ${record.value}`) |
| 26 | + } |
| 27 | +}) |
| 28 | +``` |
| 29 | + |
| 30 | +## SRV (Service) Records |
| 31 | + |
| 32 | +SRV records define the location of services: |
| 33 | + |
| 34 | +```ts |
| 35 | +const srvResponse = await client.query({ |
| 36 | + name: '_http._tcp.example.com', |
| 37 | + type: 'SRV' |
| 38 | +}) |
| 39 | + |
| 40 | +interface SRVRecord { |
| 41 | + priority: number // Priority of target host (lower is higher priority) |
| 42 | + weight: number // Relative weight for records with same priority |
| 43 | + port: number // TCP/UDP port number |
| 44 | + target: string // Hostname of the target machine |
| 45 | +} |
| 46 | + |
| 47 | +// Example usage with sorting |
| 48 | +const srvRecords = srvResponse.answers |
| 49 | + .map(answer => answer.data as SRVRecord) |
| 50 | + .sort((a, b) => { |
| 51 | + if (a.priority !== b.priority) |
| 52 | + return a.priority - b.priority |
| 53 | + return b.weight - a.weight |
| 54 | + }) |
| 55 | +``` |
| 56 | + |
| 57 | +## TLSA (TLS Authentication) |
| 58 | + |
| 59 | +TLSA records associate TLS certificates with domain names: |
| 60 | + |
| 61 | +```ts |
| 62 | +const tlsaResponse = await client.query({ |
| 63 | + name: '_443._tcp.example.com', |
| 64 | + type: 'TLSA' |
| 65 | +}) |
| 66 | + |
| 67 | +interface TLSARecord { |
| 68 | + certUsage: number // Certificate usage (0-3) |
| 69 | + selector: number // Certificate data type (0-1) |
| 70 | + matchingType: number // Matching type (0-2) |
| 71 | + certificateData: string // Certificate association data |
| 72 | +} |
| 73 | + |
| 74 | +// Example validation |
| 75 | +const tlsaRecords = tlsaResponse.answers.map(answer => answer.data as TLSARecord) |
| 76 | +tlsaRecords.forEach((record) => { |
| 77 | + switch (record.certUsage) { |
| 78 | + case 0: // PKIX-TA |
| 79 | + console.log('Trust anchor certificate') |
| 80 | + break |
| 81 | + case 1: // PKIX-EE |
| 82 | + console.log('End entity certificate') |
| 83 | + break |
| 84 | + case 2: // DANE-TA |
| 85 | + console.log('Trust anchor public key') |
| 86 | + break |
| 87 | + case 3: // DANE-EE |
| 88 | + console.log('End entity public key') |
| 89 | + break |
| 90 | + } |
| 91 | +}) |
| 92 | +``` |
| 93 | + |
| 94 | +## NAPTR (Naming Authority Pointer) |
| 95 | + |
| 96 | +NAPTR records are used for ENUM and other advanced DNS applications: |
| 97 | + |
| 98 | +```ts |
| 99 | +const naptrResponse = await client.query({ |
| 100 | + name: 'example.com', |
| 101 | + type: 'NAPTR' |
| 102 | +}) |
| 103 | + |
| 104 | +interface NAPTRRecord { |
| 105 | + order: number // Processing order |
| 106 | + preference: number // Processing preference |
| 107 | + flags: string // Record flags |
| 108 | + service: string // Service type |
| 109 | + regexp: string // Regular expression |
| 110 | + replacement: string // Replacement pattern |
| 111 | +} |
| 112 | + |
| 113 | +// Example ENUM lookup |
| 114 | +const naptrRecords = naptrResponse.answers |
| 115 | + .map(answer => answer.data as NAPTRRecord) |
| 116 | + .sort((a, b) => { |
| 117 | + if (a.order !== b.order) |
| 118 | + return a.order - b.order |
| 119 | + return a.preference - b.preference |
| 120 | + }) |
| 121 | +``` |
| 122 | + |
| 123 | +## SSHFP (SSH Fingerprint) |
| 124 | + |
| 125 | +SSHFP records store SSH public key fingerprints: |
| 126 | + |
| 127 | +```ts |
| 128 | +const sshfpResponse = await client.query({ |
| 129 | + name: 'example.com', |
| 130 | + type: 'SSHFP' |
| 131 | +}) |
| 132 | + |
| 133 | +interface SSHFPRecord { |
| 134 | + algorithm: number // SSH key algorithm |
| 135 | + fpType: number // Fingerprint type |
| 136 | + fingerprint: string // Key fingerprint |
| 137 | +} |
| 138 | + |
| 139 | +// Example validation |
| 140 | +const sshfpRecords = sshfpResponse.answers.map(answer => answer.data as SSHFPRecord) |
| 141 | +sshfpRecords.forEach((record) => { |
| 142 | + const algo = record.algorithm === 1 |
| 143 | + ? 'RSA' |
| 144 | + : record.algorithm === 2 |
| 145 | + ? 'DSA' |
| 146 | + : record.algorithm === 3 |
| 147 | + ? 'ECDSA' |
| 148 | + : record.algorithm === 4 ? 'Ed25519' : 'Unknown' |
| 149 | + console.log(`${algo} key fingerprint: ${record.fingerprint}`) |
| 150 | +}) |
| 151 | +``` |
| 152 | + |
| 153 | +## Working with Multiple Record Types |
| 154 | + |
| 155 | +Example of querying multiple record types: |
| 156 | + |
| 157 | +```ts |
| 158 | +const multiResponse = await client.query({ |
| 159 | + name: 'example.com', |
| 160 | + type: ['A', 'AAAA', 'MX', 'TXT', 'CAA'] |
| 161 | +}) |
| 162 | + |
| 163 | +interface MultiQueryResult { |
| 164 | + a: string[] |
| 165 | + aaaa: string[] |
| 166 | + mx: Array<{ preference: number, exchange: string }> |
| 167 | + txt: string[][] |
| 168 | + caa: CAARecord[] |
| 169 | +} |
| 170 | + |
| 171 | +const result: MultiQueryResult = { |
| 172 | + a: multiResponse.answers |
| 173 | + .filter(r => r.type === 'A') |
| 174 | + .map(r => r.data as string), |
| 175 | + aaaa: multiResponse.answers |
| 176 | + .filter(r => r.type === 'AAAA') |
| 177 | + .map(r => r.data as string), |
| 178 | + mx: multiResponse.answers |
| 179 | + .filter(r => r.type === 'MX') |
| 180 | + .map(r => r.data as { preference: number, exchange: string }), |
| 181 | + txt: multiResponse.answers |
| 182 | + .filter(r => r.type === 'TXT') |
| 183 | + .map(r => r.data as string[]), |
| 184 | + caa: multiResponse.answers |
| 185 | + .filter(r => r.type === 'CAA') |
| 186 | + .map(r => r.data as CAARecord) |
| 187 | +} |
| 188 | +``` |
0 commit comments