-
Notifications
You must be signed in to change notification settings - Fork 222
Add DNS oracle protocol #917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Jim8y
wants to merge
28
commits into
master
Choose a base branch
from
feature/dns-doh
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
9a72c1a
Add DNS oracle protocol
Jim8y 6aa0a8e
Align oracle DNS protocol with RFC 4501
Jim8y 4118a19
Guard DoH certificate parsing against oversized payloads
Jim8y a40b561
Merge branch 'master' into feature/dns-doh
erikzhang 9e27fda
Merge branch 'master' into feature/dns-doh
ajara87 2b9f772
Merge branch 'master' into feature/dns-doh
ajara87 55a5023
Merge branch 'master' into feature/dns-doh
ajara87 ba3ed0f
Merge branch 'master' into feature/dns-doh
Jim8y 769f160
Update plugins/OracleService/OracleSettings.cs
Jim8y 9071047
Update docs/oracle-dns-protocol.md
Jim8y 6ec4813
Update DNS oracle to RFC 8484 application/dns-message format
Jim8y 22f4f0e
Simplify DNS DoH handling and tighten safeguards
Jim8y 12fcdbf
Merge branch 'master' into feature/dns-doh
Jim8y ba19dba
Align oracle DNS protocol with RFC4501
Jim8y 1f4d451
Merge branch 'master' into feature/dns-doh
ajara87 27e07cd
Oracle DNS: return struct result for contracts
Jim8y 6b23c71
Merge branch 'master' into feature/dns-doh
Jim8y 5ee06cc
Update plugins/OracleService/OracleService.cs
Jim8y 37604ce
Merge branch 'master' into feature/dns-doh
Jim8y 9b87928
style: format oracle dns files
Jim8y a1c1bf1
fix: restore compatibility with current Neo package
Jim8y 3e5c77f
Merge branch 'master' into feature/dns-doh
Jim8y 122f490
Use PipeReader for DoH responses
Jim8y 4725a47
check bool result
shargon d4c4380
Address Oracle DNS review comments
Jim8y 09d4a4b
Address DNS oracle review feedback
Jim8y 4c4583f
Pin DNS resolver connections
Jim8y 93c5c00
Merge branch 'master' into feature/dns-doh
shargon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| # Oracle DNS Protocol | ||
|
|
||
| The Oracle plugin resolves RFC 4501 `dns:` URIs through a DNS-over-HTTPS (DoH) gateway. This lets oracle nodes read authoritative DNS data (TXT for DKIM/SPF/DIDs, CERT/TLSA, etc.) without sending plaintext DNS queries. | ||
|
|
||
| > **When should I use it?** | ||
| > Whenever you need DNS data on-chain and want the request to stay encrypted end-to-end. | ||
|
|
||
| ## Enable and configure | ||
|
|
||
| 1. Install or build the `OracleService` plugin and copy `OracleService.json` next to the plugin binary. | ||
| 2. Add the `Dns` section (defaults shown): | ||
|
|
||
| ```jsonc | ||
| { | ||
| "PluginConfiguration": { | ||
| // ... | ||
| "Dns": { | ||
| "EndPoint": "https://cloudflare-dns.com/dns-query", | ||
| "Timeout": 5000 | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| - `EndPoint` must point to a DoH resolver that supports [RFC 8484](https://www.rfc-editor.org/rfc/rfc8484.html) with `application/dns-message` format. | ||
| - `Timeout` is the maximum milliseconds the oracle will wait for a DoH response before returning `OracleResponseCode.Timeout`. | ||
|
|
||
| > You can run your own DoH gateway and point the oracle to it if you need custom trust anchors or strict egress controls. | ||
|
|
||
| ### RFC 8484 Compliance | ||
|
|
||
| This implementation uses the standard `application/dns-message` content type as defined in RFC 8484. DNS queries are sent as POST requests with binary DNS wire format (RFC 1035). Compatible DoH endpoints include: | ||
|
|
||
| | Provider | Endpoint | | ||
| |----------|----------| | ||
| | Cloudflare | `https://cloudflare-dns.com/dns-query` | | ||
| | Google | `https://dns.google/dns-query` | | ||
| | Quad9 | `https://dns.quad9.net/dns-query` | | ||
|
|
||
| Any RFC 8484-compliant DoH server should work with this oracle protocol. | ||
|
|
||
| ## RFC 4501 URI format | ||
|
|
||
| ``` | ||
| dns:[//authority/]domain[?CLASS=class;TYPE=type] | ||
| ``` | ||
|
|
||
| - `domain` is the DNS owner name (relative or absolute). Percent-encoding and escaped dots (`%5c.`) follow RFC 4501 rules. | ||
| - `domain` must not include additional path segments; only the owner name belongs here. | ||
| - `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. | ||
| - `CLASS` is optional and case-insensitive. Only `IN` (`1`) is supported; other classes are rejected. | ||
| - `TYPE` is optional and case-insensitive. Use mnemonics (`TXT`, `TLSA`, `CERT`, `A`, `AAAA`, …) or numeric values. Defaults to `A` per RFC 4501. | ||
|
|
||
| Query parameters can be separated by `;` (RFC style) or `&`. | ||
|
|
||
| Examples: | ||
|
|
||
| - `dns:1alhai._domainkey.icloud.com?TYPE=TXT` — DKIM TXT record. | ||
| - `dns:simon.example.org?TYPE=CERT` — CERT RDATA is returned as-is (type, key tag, algorithm, base64). | ||
| - `dns://dns.google/ftp.example.org?TYPE=A` — uses Google's DoH server (`https://dns.google/dns-query`) instead of the configured endpoint. | ||
| - `dns://cloudflare-dns.com/example.org?TYPE=TXT` — uses Cloudflare's DoH server for this specific query. | ||
|
|
||
| ## Response schema | ||
|
|
||
| Successful queries return a NeoVM-serialized **Struct** (use `StdLib.Deserialize(result)` in contracts). | ||
|
|
||
| Struct schema: | ||
|
|
||
| - `Envelope` (Struct, 3 items): `[Name, Type, Answers]` | ||
| - `Answer` (Struct, 4 items): `[Name, Type, Ttl, Data]` | ||
|
|
||
| Notes: | ||
|
|
||
| - `Answers` mirrors the DoH answer section but normalizes record types and names. | ||
| - CERT records are returned verbatim in `Answer[3]` (type, key tag, algorithm, base64 payload). Contracts can parse the certificate themselves if needed. | ||
| - If the DoH server responds with NXDOMAIN, the oracle returns `OracleResponseCode.NotFound`. | ||
| - Results exceeding `OracleResponse.MaxResultSize` yield `OracleResponseCode.ResponseTooLarge`. | ||
| - Oracle `filter` is not supported for DNS responses in struct mode; pass an empty filter string. | ||
|
|
||
| ## Contract usage example | ||
|
|
||
| ```csharp | ||
| public static void RequestAppleDkim() | ||
| { | ||
| const string url = "dns:1alhai._domainkey.icloud.com?TYPE=TXT"; | ||
| Oracle.Request(url, "", nameof(OnOracleCallback), Runtime.CallingScriptHash, 5_00000000); | ||
| } | ||
|
|
||
| public static void OnOracleCallback(string url, byte[] userData, int code, byte[] result) | ||
| { | ||
| if (code != (int)OracleResponseCode.Success) throw new Exception("Oracle query failed"); | ||
|
|
||
| // Envelope = [Name, Type, Answers] | ||
| var envelope = (object[])StdLib.Deserialize(result); | ||
| var answers = (object[])envelope[2]; | ||
|
|
||
| // Answer = [Name, Type, Ttl, Data] | ||
| var first = (object[])answers[0]; | ||
| Storage.Put(Storage.CurrentContext, "dkim", (string)first[3]); | ||
| } | ||
| ``` | ||
|
|
||
| Tips: | ||
|
|
||
| 1. Always set `TYPE` when you need anything other than an A record. | ||
| 2. Budget enough `gasForResponse` to cover payload size (TXT records are often kilobytes). | ||
| 3. Validate TTL or fingerprint data before trusting it. | ||
| 4. DNS oracle responses do not support the oracle `filter`; request the record type you need and parse `Answers` in-contract. | ||
|
|
||
| ## Manual testing | ||
|
|
||
| Use the same resolver the oracle will contact to inspect responses: | ||
|
|
||
| ```bash | ||
| printf 'bR4BAAABAAAAAAAABjFhbGhhaQpfZG9tYWlua2V5BmljbG91ZANjb20AAAEAAQ==' | \ | ||
| base64 -d | \ | ||
| curl -s \ | ||
| -X POST \ | ||
| -H 'accept: application/dns-message' \ | ||
| -H 'content-type: application/dns-message' \ | ||
| --data-binary @- \ | ||
| 'https://cloudflare-dns.com/dns-query' | ||
| ``` | ||
|
|
||
| Compare the DNS answer content with `Answer[3]` returned by your contract callback (after `StdLib.Deserialize`). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.