Skip to content

Commit 22f4f0e

Browse files
committed
Simplify DNS DoH handling and tighten safeguards
1 parent 6ec4813 commit 22f4f0e

File tree

4 files changed

+93
-406
lines changed

4 files changed

+93
-406
lines changed

docs/oracle-dns-protocol.md

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,22 @@ Any RFC 8484-compliant DoH server should work with this oracle protocol.
4242
## RFC 4501 URI format
4343

4444
```
45-
dns:[//authority/]domain[?CLASS=class;TYPE=type][;FORMAT=x509]
45+
dns:[//authority/]domain[?CLASS=class;TYPE=type]
4646
```
4747

4848
- `domain` is the DNS owner name (relative or absolute). Percent-encoding and escaped dots (`%5c.`) follow RFC 4501 rules.
4949
- `domain` must not include additional path segments; only the owner name belongs here.
5050
- `authority` is the optional DoH server to use for this query (RFC 4501). When specified, the oracle connects to `https://{authority}/dns-query`. If omitted, the configured `EndPoint` is used.
5151
- `CLASS` is optional and case-insensitive. Only `IN` (`1`) is supported; other classes are rejected.
5252
- `TYPE` is optional and case-insensitive. Use mnemonics (`TXT`, `TLSA`, `CERT`, `A`, `AAAA`, …) or numeric values. Defaults to `A` per RFC 4501.
53-
- `FORMAT` is an oracle extension; use `format=x509` (or `cert`) to parse TXT/CERT payloads into the `Certificate` field.
5453
- `name` is an oracle extension; if present, it overrides `domain` entirely (useful for percent-encoding complex owner names).
5554

5655
Query parameters can be separated by `;` (RFC style) or `&`.
5756

5857
Examples:
5958

6059
- `dns:1alhai._domainkey.icloud.com?TYPE=TXT` — DKIM TXT record.
61-
- `dns:simon.example.org?TYPE=CERT;FORMAT=x509`extract the X.509 payload into `Certificate`.
60+
- `dns:simon.example.org?TYPE=CERT`CERT RDATA is returned as-is (type, key tag, algorithm, base64).
6261
- `dns://dns.google/ftp.example.org?TYPE=A` — uses Google's DoH server (`https://dns.google/dns-query`) instead of the configured endpoint.
6362
- `dns://cloudflare-dns.com/example.org?TYPE=TXT` — uses Cloudflare's DoH server for this specific query.
6463
- `dns:ignored?name=weird%5c.label.example&type=TXT` — uses the `name` override (decoded to `weird.label.example`).
@@ -78,27 +77,12 @@ Successful queries return UTF-8 JSON. Attributes correspond to the `ResultEnvelo
7877
"Ttl": 299,
7978
"Data": "\"k=rsa; p=...IDAQAB\""
8079
}
81-
],
82-
"Certificate": {
83-
"Subject": "CN=example.com",
84-
"Issuer": "CN=Example Root",
85-
"Thumbprint": "ABCD1234...",
86-
"NotBefore": "2024-01-16T00:00:00Z",
87-
"NotAfter": "2025-01-16T00:00:00Z",
88-
"Der": "MIIC...",
89-
"PublicKey": {
90-
"Algorithm": "RSA",
91-
"Encoded": "MIIBIjANBg...",
92-
"Modulus": "B968DE...",
93-
"Exponent": "010001"
94-
}
95-
}
80+
]
9681
}
9782
```
9883

9984
- `Answers` mirrors the DoH response but normalizes record types and names.
100-
- `Certificate` is present only when `TYPE=CERT` or `FORMAT=x509`. `Der` is the base64-encoded certificate, while `PublicKey` provides both the encoded SubjectPublicKeyInfo (`Encoded`) and algorithm-specific fields (`Modulus`/`Exponent` for RSA, `Curve`/`X`/`Y` for EC).
101-
- For RSA keys the modulus/exponent strings are big-endian hex. For EC keys the X/Y coordinates are hex-encoded affine coordinates on the reported `Curve`.
85+
- CERT records are returned verbatim in `Answers[].Data` (type, key tag, algorithm, base64 payload). Contracts can parse the certificate themselves if needed.
10286
- If the DoH server responds with NXDOMAIN, the oracle returns `OracleResponseCode.NotFound`.
10387
- Responses exceeding `OracleResponse.MaxResultSize` yield `OracleResponseCode.ResponseTooLarge`.
10488

plugins/OracleService/OracleSettings.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public DnsSettings(IConfigurationSection section)
4545
{
4646
string endpoint = section.GetValue("EndPoint", "https://cloudflare-dns.com/dns-query");
4747
EndPoint = new Uri(endpoint, UriKind.Absolute);
48-
Timeout = TimeSpan.FromMilliseconds(section.GetValue("TimeoutMilliseconds", 5000));
48+
int timeoutMs = section.GetValue("TimeoutMilliseconds", section.GetValue("Timeout", 5000));
49+
Timeout = TimeSpan.FromMilliseconds(timeoutMs);
4950
}
5051
}
5152

0 commit comments

Comments
 (0)