Skip to content

Commit e1e82fe

Browse files
committed
Add diagrams
1 parent 1b9372c commit e1e82fe

1 file changed

Lines changed: 203 additions & 17 deletions

File tree

draft-denis-dprive-dnscrypt.md

Lines changed: 203 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,74 @@ The protocol is designed to be lightweight, extensible, and simple to implement
3737

3838
{::boilerplate bcp14-tagged}
3939

40-
## Protocol Components
40+
# Protocol Flow
41+
42+
The DNSCrypt protocol consists of two distinct phases:
43+
44+
1. **Initial Setup Phase** (one-time):
45+
- The client requests the server's certificate
46+
- The server responds with its certificate containing public keys
47+
48+
2. **Ongoing Communication Phase** (repeated as needed):
49+
- The client sends encrypted DNS queries
50+
- The server responds with encrypted DNS responses
51+
52+
The following diagram illustrates the complete protocol flow:
53+
54+
~~~
55+
+--------+ +--------+
56+
| | | |
57+
| Client | | Server |
58+
| | | |
59+
+--------+ +--------+
60+
| |
61+
| 1. Request Certificate |
62+
|---------------------------->|
63+
| |
64+
| 2. Certificate Response |
65+
|<----------------------------|
66+
| |
67+
| 3. Encrypted Query |
68+
|---------------------------->|
69+
| |
70+
| 4. Encrypted Query |
71+
|---------------------------->|
72+
| |
73+
| 5. Encrypted Response |
74+
|<----------------------------|
75+
| |
76+
| 6. Encrypted Response |
77+
|<----------------------------|
78+
| |
79+
| 7. Encrypted Query |
80+
|---------------------------->|
81+
| |
82+
| 8. Encrypted Response |
83+
|<----------------------------|
84+
| |
85+
| |
86+
~~~
87+
88+
The initial setup phase (steps 1-2) occurs only when:
89+
90+
- A client first starts using a DNSCrypt server
91+
- The client's cached certificate expires
92+
- The client detects a certificate with a higher serial number
93+
94+
After the initial setup, the client and server engage in the ongoing communication phase (steps 3-8), where encrypted queries and responses are exchanged as needed. This phase can be repeated indefinitely until the certificate expires or a new certificate is available.
95+
96+
Key characteristics of the ongoing communication phase:
97+
98+
1. **Stateless Operation**: Each query and response is independent. The server does not maintain state between queries.
99+
100+
2. **Out-of-Order Responses**: Responses may arrive in a different order than the queries were sent. Each response is self-contained and can be processed independently.
101+
102+
3. **Multiple Responses**: A single query may result in multiple responses, and responses can be received without sending new queries. For example, a server might send additional responses for a query that has multiple answers or requires additional processing.
103+
104+
4. **Asynchronous Communication**: The protocol does not require strict request-response pairing. A client can send multiple queries before receiving responses, and responses can be processed as they arrive.
105+
106+
# Protocol Components
107+
41108

42109
Definitions for client queries:
43110

@@ -69,6 +136,46 @@ Definitions for server responses:
69136
- `<resolver-response>`: the unencrypted resolver response. The response is not modified; in particular, the query flags are not altered and the response length MUST be kept in responses prepared to be sent over TCP {{!RFC7766}}.
70137
- `<resolver-response-pad>`: the variable-length padding.
71138

139+
The following diagram shows the structure of a DNSCrypt query packet:
140+
141+
~~~
142+
0 1 2 3
143+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
144+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
145+
| Client Magic |
146+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
147+
| |
148+
+ Client Public Key +
149+
| |
150+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
151+
| |
152+
+ Client Nonce +
153+
| |
154+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
155+
| |
156+
+ Encrypted Query +
157+
| |
158+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
159+
~~~
160+
161+
The following diagram shows the structure of a DNSCrypt response packet:
162+
163+
~~~
164+
0 1 2 3
165+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
166+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
167+
| Resolver Magic |
168+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
169+
| |
170+
+ Nonce +
171+
| |
172+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
173+
| |
174+
+ Encrypted Response +
175+
| |
176+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
177+
~~~
178+
72179
# Protocol Description
73180

74181
## Overview
@@ -182,6 +289,38 @@ After having received a response from the resolver, the client and the resolver
182289

183290
## Certificates
184291

292+
The following diagram shows the structure of a DNSCrypt certificate:
293+
294+
~~~
295+
0 1 2 3
296+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
297+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
298+
| Cert Magic |
299+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
300+
| ES Version | Protocol Minor Version | Reserved |
301+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
302+
| |
303+
+ Signature +
304+
| |
305+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
306+
| |
307+
+ Resolver Public Key +
308+
| |
309+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
310+
| Client Magic |
311+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
312+
| Serial |
313+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
314+
| TS Start |
315+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
316+
| TS End |
317+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
318+
| |
319+
+ Extensions +
320+
| |
321+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
322+
~~~
323+
185324
To initiate a DNSCrypt session, a client transmits an ordinary unencrypted `TXT` DNS query to the resolver's IP address and DNSCrypt port. The attempt is first made using UDP; if unsuccessful due to failure, timeout, or truncation, the client then proceeds with TCP.
186325

187326
Resolvers are not required to serve certificates both on UDP and TCP.
@@ -257,10 +396,13 @@ This section discusses security considerations for the DNSCrypt protocol.
257396

258397
The DNSCrypt protocol provides several security benefits:
259398

260-
1. **Confidentiality**: DNS queries and responses are encrypted using XChaCha20-Poly1305 {{!RFC8439}}, preventing eavesdropping of DNS traffic.
261-
2. **Integrity**: Message authentication using Poly1305 {{!RFC8439}} ensures that responses cannot be tampered with in transit.
262-
3. **Authentication**: The use of X25519 {{!RFC7748}} for key exchange and Ed25519 for certificate signatures provides strong authentication of resolvers.
263-
4. **Forward Secrecy**: Short-term key pairs are used for each session, providing forward secrecy.
399+
1. **Confidentiality**: DNS queries and responses are encrypted using XChaCha20-Poly1305 {{!RFC8439}}, preventing eavesdropping of DNS traffic. For example, a query for "example.com" would be encrypted and appear as random data to an observer.
400+
401+
2. **Integrity**: Message authentication using Poly1305 {{!RFC8439}} ensures that responses cannot be tampered with in transit. Any modification to the encrypted response would be detected and rejected by the client.
402+
403+
3. **Authentication**: The use of X25519 {{!RFC7748}} for key exchange and Ed25519 for certificate signatures provides strong authentication of resolvers. Clients can verify they are communicating with the intended resolver and not an impostor.
404+
405+
4. **Forward Secrecy**: Short-term key pairs are used for each session, providing forward secrecy. Even if a long-term key is compromised, past communications remain secure.
264406

265407
## Implementation Security
266408

@@ -270,46 +412,70 @@ Implementations should consider the following security aspects:
270412
- Resolvers MUST rotate their short-term key pairs at least every 24 hours
271413
- Previous secret keys MUST be securely erased after rotation
272414
- Provider secret keys used for certificate signing SHOULD be stored in hardware security modules (HSMs)
415+
- Example: A resolver might generate new key pairs daily at midnight UTC
273416

274417
2. **Nonce Management**:
275418
- Nonces MUST NOT be reused for a given shared secret
276419
- Clients SHOULD include timestamps in their nonces to prevent replay attacks
277-
- Resolvers SHOULD verify that nonces are within a reasonable time window
420+
- Resolvers SHOULD verify that nonces are within a reasonable time window (e.g., ±5 minutes)
421+
- Example: A nonce might be constructed as: `timestamp || random_bytes`
278422

279423
3. **Padding**:
280424
- Implementations MUST use the specified padding scheme to prevent traffic analysis
281425
- The minimum query length SHOULD be adjusted based on network conditions
426+
- Example: A 50-byte query might be padded to 256 bytes to prevent size-based fingerprinting
282427

283428
4. **Certificate Validation**:
284429
- Clients MUST verify certificate signatures using the provider's public key
285430
- Certificates MUST be checked for validity periods
286431
- Clients MUST prefer certificates with higher serial numbers
432+
- Example: A client might cache valid certificates and check for updates hourly
287433

288434
## Attack Mitigation
289435

290436
DNSCrypt provides protection against several types of attacks:
291437

292-
1. **DNS Spoofing**: The use of authenticated encryption prevents spoofed responses
293-
2. **Amplification Attacks**: The padding requirements and minimum query length help prevent amplification attacks {{!RFC5358}}
294-
3. **Fragmentation Attacks**: The protocol handles fragmentation in a way that prevents certain types of attacks
295-
4. **Replay Attacks**: The use of nonces and timestamps helps prevent replay attacks
438+
1. **DNS Spoofing**: The use of authenticated encryption prevents spoofed responses. An attacker cannot forge responses without the server's secret key.
439+
440+
2. **Amplification Attacks**: The padding requirements and minimum query length help prevent amplification attacks {{!RFC5358}}. For example, a 256-byte minimum query size limits the amplification factor.
441+
442+
3. **Fragmentation Attacks**: The protocol handles fragmentation in a way that prevents certain types of attacks. Large responses are properly fragmented and reassembled.
443+
444+
4. **Replay Attacks**: The use of nonces and timestamps helps prevent replay attacks. A replayed query would be detected due to nonce reuse.
296445

297446
## Privacy Considerations
298447

299448
While DNSCrypt encrypts DNS traffic, there are some privacy considerations:
300449

301-
1. **Resolver Knowledge**: Resolvers can still see the client's IP address unless Anonymized DNSCrypt is used
302-
2. **Query Patterns**: Even with encryption, the size and timing of queries may reveal information
303-
3. **Certificate Requests**: Initial certificate requests are unencrypted and may reveal client capabilities
450+
1. **Resolver Knowledge**: Resolvers can still see the client's IP address unless Anonymized DNSCrypt is used. This can reveal the client's location and network.
451+
452+
2. **Query Patterns**: Even with encryption, the size and timing of queries may reveal information. Padding helps mitigate this but doesn't eliminate it completely.
453+
454+
3. **Certificate Requests**: Initial certificate requests are unencrypted and may reveal client capabilities. This is a one-time exposure per session.
304455

305456
## Operational Security
306457

307458
Operators should consider:
308459

309-
1. **Key Distribution**: Provider public keys should be distributed securely to clients
310-
2. **Certificate Management**: Certificates should be signed on dedicated hardware, not on resolvers
311-
3. **Access Control**: Resolvers may implement access control based on client public keys
312-
4. **Monitoring**: Operators should monitor for unusual patterns that may indicate attacks
460+
1. **Key Distribution**: Provider public keys should be distributed securely to clients. This might involve:
461+
- Publishing keys on secure websites
462+
- Using DNSSEC-signed records
463+
- Including keys in software distributions
464+
465+
2. **Certificate Management**: Certificates should be signed on dedicated hardware, not on resolvers. This provides:
466+
- Better key protection
467+
- Centralized certificate management
468+
- Reduced attack surface
469+
470+
3. **Access Control**: Resolvers may implement access control based on client public keys. This can:
471+
- Prevent abuse
472+
- Enable service differentiation
473+
- Support business models
474+
475+
4. **Monitoring**: Operators should monitor for unusual patterns that may indicate attacks:
476+
- High query rates from single clients
477+
- Unusual query patterns
478+
- Certificate request anomalies
313479

314480
# Operational Considerations
315481

@@ -349,6 +515,26 @@ Key properties of Anonymized DNSCrypt:
349515

350516
## Client Queries
351517

518+
The following diagram shows the structure of an Anonymized DNSCrypt query packet:
519+
520+
~~~
521+
0 1 2 3
522+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
523+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
524+
| Anon Magic |
525+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
526+
| |
527+
+ Server IP (IPv6) +
528+
| |
529+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
530+
| Server Port | |
531+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
532+
| |
533+
+ DNSCrypt Query +
534+
| |
535+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
536+
~~~
537+
352538
An Anonymized DNSCrypt query is a standard DNSCrypt query prefixed with information about the target server:
353539

354540
~~~

0 commit comments

Comments
 (0)