-
Notifications
You must be signed in to change notification settings - Fork 20
/
AGDnsProxy.h
798 lines (703 loc) · 23.4 KB
/
AGDnsProxy.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
#import <Foundation/Foundation.h>
#import "AGDnsProxyEvents.h"
/**
* @defgroup enums
*/
/**
* DNS proxy error domain
*/
extern NSErrorDomain const AGDnsProxyErrorDomain;
/**
* @ingroup enums
* DNS error codes.
*
* Defines the different DNS error codes used in the application
*/
typedef NS_ENUM(NSInteger, AGDnsProxyInitError) {
/** The DNS proxy is not set */
AGDPE_PROXY_NOT_SET,
/** The event loop is not set */
AGDPE_EVENT_LOOP_NOT_SET,
/** The provided address is invalid */
AGDPE_INVALID_ADDRESS,
/** The proxy is empty */
AGDPE_EMPTY_PROXY,
/** There is an error in the protocol */
AGDPE_PROTOCOL_ERROR,
/** Failed to initialize the listener */
AGDPE_LISTENER_INIT_ERROR,
/** The provided IPv4 address is invalid */
AGDPE_INVALID_IPV4,
/** The provided IPv6 address is invalid */
AGDPE_INVALID_IPV6,
/** Failed to initialize the upstream */
AGDPE_UPSTREAM_INIT_ERROR,
/** Failed to initialize the fallback filter */
AGDPE_FALLBACK_FILTER_INIT_ERROR,
/** Failed to load the filter */
AGDPE_FILTER_LOAD_ERROR,
/** The memory limit has been reached */
AGDPE_MEM_LIMIT_REACHED,
/** The filter ID is not unique */
AGDPE_NON_UNIQUE_FILTER_ID,
/** Failed to test the upstream */
AGDPE_TEST_UPSTREAM_ERROR,
/** Failed to initialize the proxy */
AGDPE_PROXY_INIT_ERROR,
/** Failed to initialize the listener during proxy initialization */
AGDPE_PROXY_INIT_LISTENER_ERROR,
/** Failed to initialize the helper during proxy initialization */
AGDPE_PROXY_INIT_HELPER_ERROR,
/** Failed to bind the helper during proxy initialization */
AGDPE_PROXY_INIT_HELPER_BIND_ERROR,
};
/**
* @ingroup enums
* Logging levels.
*
* Defines the different logging levels used in the application.
*/
typedef NS_ENUM(NSInteger, AGDnsLogLevel) {
/** Error: Indicates an error that requires immediate attention */
AGDLLErr,
/** Warning: Indicates a potential issue that may cause problems */
AGDLLWarn,
/** Information: Provides general information about the application state */
AGDLLInfo,
/** Debug: Contains detailed debugging information for developers */
AGDLLDebug,
/** Trace: Contains low-level tracing information for developers */
AGDLLTrace,
};
/**
* @ingroup enums
* Listener protocols.
*
* Defines the different listener protocols used in the application.
*/
typedef NS_ENUM(NSInteger, AGDnsListenerProtocol) {
/** User Datagram Protocol (UDP) */
AGLP_UDP,
/** Transmission Control Protocol (TCP) */
AGLP_TCP,
};
/**
* @ingroup enums
* Specifies how to respond to blocked requests.
*
* A request is blocked if it matches a blocking AdBlock-style rule,
* or a blocking hosts-style rule. A blocking hosts-style rule is
* a hosts-style rule with a loopback or all-zeroes address.
*
* Requests matching a hosts-style rule with an address that is
* neither loopback nor all-zeroes are always responded
* with the address specified by the rule.
*/
typedef NS_ENUM(NSInteger, AGDnsBlockingMode) {
/** Respond with REFUSED response code */
AGBM_REFUSED,
/** Respond with NXDOMAIN response code */
AGBM_NXDOMAIN,
/**
* Respond with an address that is all-zeroes, or
* a custom blocking address, if it is specified, or
* an empty SOA response if request type is not A/AAAA.
*/
AGBM_ADDRESS,
/**
* Respond with an address that is all zeroes regardless of the custom blocking address setting,
* or an empty SOA response if request type is not A/AAAA.
*/
AGBM_UNSPECIFIED_ADDRESS,
};
/**
* @interface AGLogger
* Class for configuring logging for DNS library.
*
* Provides a way to configure logging for the DNS library.
* The logging level and the logging function can be set using the provided methods.
*/
@interface AGDnsLogger : NSObject
/**
* Set the default logging level
*
* @param level logging level to be set
*/
+ (void) setLevel: (AGDnsLogLevel) level;
/**
* A function that outputs a log message.
*
* This block is called when a log message needs to be output.
* The message is already formatted, including the line terminator.
*
* @param level The log level of the message
* @param msg The formatted log message
* @param length The length of the log message
*/
typedef void (^logCallback)(AGDnsLogLevel level, const char *msg, int length);
/**
* Set log callback
*
* @param func logging function
*/
+ (void) setCallback: (logCallback) func;
@end
/**
* @interface AGDnsUpstream
*
* Represents a DNS upstream server.
*/
@interface AGDnsUpstream : AGDnsXPCObject <NSSecureCoding>
/**
* Server address.
* One of the following kinds:
* * `8.8.8.8:53` -- plain DNS (must specify IP address, not hostname)
* * `tcp://8.8.8.8:53` -- plain DNS over TCP (must specify IP address, not hostname)
* * `tls://dns.adguard.com` -- DNS-over-TLS
* * `https://dns.adguard.com/dns-query` -- DNS-over-HTTPS
* * `sdns://...` -- DNS stamp (see https://dnscrypt.info/stamps-specifications)
* * `quic://dns.adguard.com:853` -- DNS-over-QUIC
* * `h3://` -- DNS-over-HTTP/3
*/
@property(nonatomic) NSString *address;
/**
* List of plain DNS servers.
* List used to resolve the hostname in the upstream's address when necessary.
* These servers will help establish the initial connection to the upstream DNS server
* if its address is specified as a hostname.
*/
@property(nonatomic) NSArray<NSString *> *bootstrap;
/**
* Upstream's IP address.
* Pre-resolved IP address for the upstream server. If this field is specified, the @ref bootstrap
* DNS servers won't be used for resolving the upstream's address.
*/
@property(nonatomic) NSData *serverIp;
/**
* User-provided ID for this upstream
*/
@property(nonatomic) NSInteger id;
/**
* Name of the network interface to route traffic through.
* Optional on macOS, nil is default.
* Required on iOS.
*/
@property(nonatomic) NSString *outboundInterfaceName;
/**
* (Optional) List of upstreams base64 encoded SPKI fingerprints to verify. If at least one of them is matched in the
* certificate chain, the verification will be successful
*/
@property(nonatomic) NSArray<NSString *> *fingerprints;
- (instancetype)initWithCoder:(NSCoder *)coder;
- (void)encodeWithCoder:(NSCoder *)coder;
- (NSString*)description;
@end
/**
* @interface AGDns64Settings
* Represents DNS64 settings for the DNS proxy.
*/
@interface AGDns64Settings : AGDnsXPCObject <NSSecureCoding>
/**
* The upstream to use for discovery of DNS64 prefixes
*/
@property(nonatomic) NSArray<AGDnsUpstream *> *upstreams;
/**
* How many times, at most, to try DNS64 prefixes discovery before giving up
*/
@property(nonatomic) NSInteger maxTries;
/**
* How long to wait before a dns64 prefixes discovery attempt, in milliseconds
*/
@property(nonatomic) NSInteger waitTimeMs;
- (instancetype)initWithCoder:(NSCoder *)coder;
- (void)encodeWithCoder:(NSCoder *)coder;
- (NSString*)description;
@end
/**
* @interface AGDnsProxySettingsOverrides
* The subset of AGDnsProxyConfig available for overriding on a specific listener.
*/
@interface AGDnsProxySettingsOverrides : AGDnsXPCObject <NSSecureCoding>
/** Overrides AGDnsProxyConfig.block_ech if not nil */
@property(nonatomic) NSNumber *blockEch;
- (instancetype)initWithCoder:(NSCoder *)coder;
- (void)encodeWithCoder:(NSCoder *)coder;
- (NSString*)description;
@end
/**
* @interface AGListenerSettings
* Settings for a DNS proxy listener.
*/
@interface AGDnsListenerSettings : AGDnsXPCObject <NSSecureCoding>
/**
* The port to listen on
* This is the address on which the listener will wait for incoming DNS queries.
*/
@property(nonatomic) NSString *address;
/**
* The port to listen on.
* This is the port on which the listener will wait for incoming DNS queries.
*/
@property(nonatomic) NSInteger port;
/**
* The protocol to listen for
*/
@property(nonatomic) AGDnsListenerProtocol proto;
/**
* Whether the listener should keep the TCP connection open after sending the first response.
* If set to true, the connection will not be closed immediately,
* allowing for multiple requests and responses over the same connection.
*/
@property(nonatomic) BOOL persistent;
/**
* Idle timeout.
* Duration (in milliseconds) after which the listener should close the TCP connection if no
* requests have been received. This setting helps to prevent idle connections from consuming resources.
*/
@property(nonatomic) NSInteger idleTimeoutMs;
/**
* Overridden settings
*/
@property(nonatomic) AGDnsProxySettingsOverrides *settingsOverrides;
- (instancetype)initWithCoder:(NSCoder *)coder;
- (void)encodeWithCoder:(NSCoder *)coder;
- (NSString*)description;
@end
/**
* @ingroup enums
* Outbound proxy protocols.
*
* Defines the different outbound proxy protocols used in the application.
*/
typedef NS_ENUM(NSInteger, AGDnsOutboundProxyProtocol) {
/** Plain HTTP proxy */
AGOPP_HTTP_CONNECT,
/** HTTPS proxy */
AGOPP_HTTPS_CONNECT,
/** SOCKS4 proxy */
AGOPP_SOCKS4,
/** SOCKS5 proxy without UDP support */
AGOPP_SOCKS5,
/** SOCKS5 proxy with UDP support */
AGOPP_SOCKS5_UDP,
};
/**
* @interface AGOutboundProxyAuthInfo
* Represents authentication information for an outbound proxy.
*/
@interface AGDnsOutboundProxyAuthInfo : AGDnsXPCObject <NSSecureCoding>
/** User name for authentication */
@property(nonatomic) NSString *username;
/** Password for authentication */
@property(nonatomic) NSString *password;
- (instancetype) init NS_UNAVAILABLE;
- (instancetype)initWithCoder:(NSCoder *)coder;
- (void)encodeWithCoder:(NSCoder *)coder;
- (NSString*)description;
@end
/**
* @interface AGOutboundProxySettings
* Represents settings for an outbound proxy.
*/
@interface AGDnsOutboundProxySettings : AGDnsXPCObject <NSSecureCoding>
/** The proxy protocol */
@property(nonatomic) AGDnsOutboundProxyProtocol protocol;
/** The proxy server IP address or hostname */
@property(nonatomic) NSString *address;
/** The proxy server port */
@property(nonatomic) NSInteger port;
/**
* List of the DNS server URLs to be used to resolve a hostname in the proxy server address.
* The URLs MUST contain the resolved server addresses, not hostnames.
* E.g. `https://94.140.14.14` is correct, while `dns.adguard.com:53` is not.
* MUST NOT be empty in case the `address` is a hostname.
*/
@property(nonatomic) NSArray<NSString *> *bootstrap;
/** The authentication information (if nil, authentication is not performed) */
@property(nonatomic) AGDnsOutboundProxyAuthInfo *authInfo;
/** If true and the proxy connection is secure, the certificate won't be verified */
@property(nonatomic) BOOL trustAnyCertificate;
- (instancetype) init NS_UNAVAILABLE;
- (instancetype)initWithCoder:(NSCoder *)coder;
- (void)encodeWithCoder:(NSCoder *)coder;
- (NSString*)description;
@end
/**
* @interface AGDnsFilterParams
* Represents the parameters for an individual filter used in the filter engine.
*/
@interface AGDnsFilterParams : AGDnsXPCObject <NSSecureCoding>
/**
* Filter identifier
*/
@property(nonatomic) NSInteger id;
/**
* Filter data
* Either path to file with rules, or rules as a string
*/
@property(nonatomic) NSString *data;
/**
* If YES, data is rules, otherwise data is path to file with rules
*/
@property(nonatomic) BOOL inMemory;
- (instancetype)initWithCoder:(NSCoder *)coder;
- (void)encodeWithCoder:(NSCoder *)coder;
- (NSString*)description;
@end
/**
* @interface AGDnsProxyConfig
* Represents settings for the DNS proxy.
*
* Defines the various configuration options that can be used to specify the DNS proxy settings.
*/
@interface AGDnsProxyConfig : AGDnsXPCObject <NSSecureCoding>
/**
* Upstreams settings
*/
@property(nonatomic) NSArray<AGDnsUpstream *> *upstreams;
/**
* Fallback upstreams settings
*/
@property(nonatomic) NSArray<AGDnsUpstream *> *fallbacks;
/**
* Requests for these domains will be forwarded directly to the fallback upstreams, if there are any.
* A wildcard character, `*`, which stands for any number of characters, is allowed to appear multiple
* times anywhere except at the end of the domain (which implies that a domain consisting only of
* wildcard characters is invalid).
*/
@property(nonatomic) NSArray<NSString *> *fallbackDomains;
/**
* If enabled, DNS search domains will be automatically appended to the fallback domains,
* allowing to forward requests for, e.g., *.local, directly to the fallback upstreams.
*/
@property(nonatomic) BOOL detectSearchDomains;
/**
* Filters
*/
@property(nonatomic) NSArray<AGDnsFilterParams *> *filters;
#if TARGET_OS_IPHONE
/**
* If not zero, the filtering engine might not load some rules from the configured
* filters to try to keep the estimated memory usage below this limit.
* If any rules are not loaded because of this limit, a warning will be returned
* from `[AGDnsProxy initWithConfig:]`.
*/
@property(nonatomic) NSUInteger filtersMemoryLimitBytes;
#endif // TARGET_OS_IPHONE
/**
* TTL of the record for the blocked domains (in seconds)
*/
@property(nonatomic) NSInteger blockedResponseTtlSecs;
/**
* DNS64 settings. If nil, DNS64 is disabled
*/
@property(nonatomic) AGDns64Settings *dns64Settings;
/**
* List of addresses/ports/protocols/etc... to listen on
*/
@property(nonatomic) NSArray<AGDnsListenerSettings *> *listeners;
/**
* Outbound proxy settings
*/
@property(nonatomic) AGDnsOutboundProxySettings *outboundProxy;
/**
* If true, bootstrappers will fetch AAAA records
*/
@property(nonatomic) BOOL ipv6Available;
/**
* Block AAAA requests.
*/
@property(nonatomic) BOOL blockIpv6;
/**
* How to respond to requests blocked by AdBlock-style rules
*/
@property(nonatomic) AGDnsBlockingMode adblockRulesBlockingMode;
/**
* How to respond to requests blocked by hosts-style rules
*/
@property(nonatomic) AGDnsBlockingMode hostsRulesBlockingMode;
/**
* Custom IPv4 address to return for filtered requests
*/
@property(nonatomic) NSString *customBlockingIpv4;
/**
* Custom IPv6 address to return for filtered requests
*/
@property(nonatomic) NSString *customBlockingIpv6;
/**
* Maximum number of cached responses
*/
@property(nonatomic) NSUInteger dnsCacheSize;
/**
* Maximum amount of time, in milliseconds, allowed for upstream exchange.
* A timeout of 0 means "default".
*/
@property(nonatomic) NSUInteger upstreamTimeoutMs;
/**
* Enable optimistic DNS caching
*/
@property(nonatomic) BOOL optimisticCache;
/**
* Enable DNSSEC OK extension.
* This options tells server that we want to receive DNSSEC records along with normal queries.
* If they exist, request processed event will have DNSSEC flag on.
* WARNING: may increase data usage and probability of TCP fallbacks.
*/
@property(nonatomic) BOOL enableDNSSECOK;
/**
* If enabled, detect retransmitted requests and handle them using fallback upstreams only.
*/
@property(nonatomic) BOOL enableRetransmissionHandling;
/**
* If enabled, our own route resolver will be used to resolve routes.
* This is needed when DnsProxy is used inside network extension and needs to use routes of some VPN.
*/
@property(nonatomic) BOOL enableRouteResolver;
/**
* If enabled, strip Encrypted Client Hello parameters from responses.
*/
@property(nonatomic) BOOL blockEch;
/**
* If true, all upstreams are queried in parallel, and the first response is returned.
*/
@property(nonatomic) BOOL enableParallelUpstreamQueries;
/**
* If true, normal queries will be forwarded to fallback upstreams if all normal upstreams failed.
* Otherwise, fallback upstreams will only be used to resolve domains from `fallback_domains`.
*/
@property(nonatomic) BOOL enableFallbackOnUpstreamsFailure;
/**
* If true, when all upstreams (including fallback upstreams) fail to provide a response,
* the proxy will respond with a SERVFAIL packet. Otherwise, no response is sent on such a failure.
*/
@property(nonatomic) BOOL enableServfailOnUpstreamsFailure;
/**
* Enable HTTP/3 for DNS-over-HTTPS upstreams if it's able to connect quicker.
*/
@property(nonatomic) BOOL enableHttp3;
/**
* Path to adguard-tun-helper (macOS only)
*/
@property(nonatomic) NSString *helperPath;
- (instancetype)initWithCoder:(NSCoder *)coder;
- (void)encodeWithCoder:(NSCoder *)coder;
- (NSString *)description;
/**
* Get default DNS proxy settings
*/
+ (instancetype) getDefault;
@end
/**
* @ingroup enums
* Rule generation options.
*
* Defines the different rule generation options used in the application.
*/
typedef NS_ENUM(NSUInteger, AGDnsRuleGenerationOptions) {
/** Add an $important modifier */
AGRGOImportant = 1u << 0,
/** Add a $dnstype modifier */
AGRGODnstype = 1u << 1,
};
/**
* @interface AGRuleTemplate
* An object representing a template for generating DNS rules.
*/
@interface AGDnsRuleTemplate : NSObject
- (NSString *)description; /**< String representation. */
/**
* Generate a rule using this template and the specified options.
* @param options Union of `AGRuleGenerationOptions` values
* @return The resulting rule or `nil` on error
*/
- (NSString *)generateRuleWithOptions:(NSUInteger)options;
@end
/**
* @interface AGFilteringLogAction
* Provides a way to suggest rules based on filtering event.
*/
@interface AGDnsFilteringLogAction : NSObject
@property(nonatomic) NSArray<AGDnsRuleTemplate *> *templates; /**< A set of rule templates */
@property(nonatomic) NSUInteger allowedOptions; /**< Options that are allowed to be passed to `generate_rule` */
@property(nonatomic) NSUInteger requiredOptions; /**< Options that are required for the generated rule to be correct */
@property(nonatomic) BOOL blocking; /**< Whether something will be blocked or un-blocked as a result of this action */
/**
* Suggest an action based on filtering event.
* @param event Processed event
* @return The action or nil on error
*/
+ (instancetype)actionFromEvent:(AGDnsRequestProcessedEvent *)event;
@end
/** Out-of-band information about the DNS message or how to process it. */
@interface AGDnsMessageInfo : NSObject
/**
* If `true`, the proxy will handle the message transparently: queries are returned to the caller
* instead of being forwarded to the upstream by the proxy, responses are processed as if they were received
* from an upstream, and the processed response is returned to the caller. The proxy may return a response
* when transparently handling a query if the query is blocked. The proxy may still perform an upstream
* query when handling a message transparently, for example, to process CNAME-rewrites.
*/
@property(nonatomic) BOOL transparent;
@end
/**
* @interface AGDnsProxy
* Represents a DNS proxy.
*
* Provides methods for provides management and interaction with proxy server.
*
* Usage example:
* @code{.mm}
* int main() {
* auto *listener = [[AGListenerSettings alloc] init];
* auto *handler = [[AGDnsProxyEvents alloc] init];
* NSError *error;
* auto *proxy = [[AGDnsProxy alloc] initWithConfig:config handler:handler error:&error];
* if (error || !proxy) {
* [proxy stop];
* return 1;
* }
* ...
* [proxy stop];
* return 0;
* }
* @endcode
*/
@interface AGDnsProxy : NSObject
/**
* Initialize DNS proxy with the given configuration.
*
* @param config proxy configuration
* @param events proxy events handler
* @param error error reference
*/
- (instancetype) initWithConfig: (AGDnsProxyConfig *) config
handler: (AGDnsProxyEvents *) events
error: (NSError **) error NS_SWIFT_NOTHROW;
/**
* Process UDP/TCP packet payload.
*
* @param Packet data to process
* @param completionHandler Completion handler
* @return The response packet payload, or nil if nothing shoud be sent in response
*/
- (void) handlePacket: (NSData *) packet completionHandler: (void (^)(NSData *)) completionHandler;
/**
* Process a DNS message (query or response).
* @param message A complete DNS message in wire format.
* @param info Additional parameters.
* @param handler Completion handler. Will be called on an unspecified thread with the result message.
*/
- (void)handleMessage:(NSData *)message
withInfo:(AGDnsMessageInfo *)info
withCompletionHandler:(void (^)(NSData *))handler;
/**
* Stop DnsProxy.
* @note Should be called before dealloc
*/
- (void) stop;
/**
* Check if string is a valid rule
* @param str string to check
* @return True if string is a valid rule, false otherwise
*/
+ (BOOL) isValidRule: (NSString *) str;
/**
* Gets the library version
* @return The DNS proxy library version
*/
+ (NSString *) libraryVersion;
@end
/**
* @ingroup enums
* Stamp protocol types.
*
* Defines the different stamp protocol types used in the application.
*/
typedef NS_ENUM(NSInteger, AGStampProtoType) {
/** Plain DNS */
AGSPT_PLAIN,
/** DNSCrypt */
AGSPT_DNSCRYPT,
/** DNS-over-HTTPS */
AGSPT_DOH,
/** DNS-over-TLS */
AGSPT_TLS,
/** DNS-over-QUIC */
AGSPT_DOQ,
};
/**
* @interface AGDnsStamp
* Represents a DNS stamp.
*/
@interface AGDnsStamp : AGDnsXPCObject <NSSecureCoding>
/**
* Protocol.
*/
@property(nonatomic) AGStampProtoType proto;
/**
* Server numerical IP address, represented as a string.
*/
@property(nonatomic) NSString *serverAddr;
/**
* Optional provider name (i.e. hostname in case of DoH/DoQ)
* and optional port (written as ":<PortNumber>").
* The grammar is something like this:
* ```
* providerName := [(ProviderName | Hostname)] [":" PortNumber]
* PortNumber := DIGIT+
* ```
*/
@property(nonatomic) NSString *providerName;
/**
* Optional path (for DOH).
*/
@property(nonatomic) NSString *path;
/**
* The DNSCrypt provider’s Ed25519 public key, as 32 raw bytes. Empty for other types.
*/
@property(nonatomic) NSData *serverPublicKey;
/**
* Hash is the SHA256 digest of one of the TBS certificate found in the validation chain, typically
* the certificate used to sign the resolver’s certificate. Multiple hashes can be provided for seamless
* rotations.
*/
@property(nonatomic) NSArray<NSData *> *hashes;
/** Server properties */
/** Resolver does DNSSEC validation */
@property(nonatomic) BOOL dnssec;
/** Resolver does not record logs */
@property(nonatomic) BOOL noLog;
/** Resolver doesn't intentionally block domains */
@property(nonatomic) BOOL noFilter;
- (instancetype) init NS_UNAVAILABLE;
- (instancetype)initWithCoder:(NSCoder *)coder;
- (void)encodeWithCoder:(NSCoder *)coder;
/** Init a stamp from "sdns://" string */
- (instancetype) initWithString:(NSString *)stampStr error:(NSError **)error NS_SWIFT_NOTHROW;
/** Create a stamp from "sdns://" string */
+ (instancetype) stampWithString:(NSString *)stampStr error:(NSError **)error NS_SWIFT_NOTHROW;
/** A URL representation of this stamp which can be used as a valid AGDnsUpstream address */
@property(nonatomic, readonly) NSString *prettyUrl;
/** A URL representation of this stamp which is prettier, but can NOT be used as a valid AGDnsUpstream address */
@property(nonatomic, readonly) NSString *prettierUrl;
/** An "sdns://" string representation */
@property(nonatomic, readonly) NSString *stringValue;
@end
/**
* @interface AGDnsUtils
* Represents DNS utils
*/
@interface AGDnsUtils : NSObject
/**
* Checks if upstream is valid and available
* @param opts Upstream options
* @param timeoutMs Upstream exchange timeout
* @param ipv6Available If true, bootstrapper is allowed to make AAAA queries (Whether IPv6 is available)
* @param offline If true, don't perform online upstream check
* @return If it is, no error is returned. Otherwise this method returns an error with an explanation
*/
+ (NSError *)testUpstream:(AGDnsUpstream *)opts
timeoutMs:(NSUInteger)timeoutMs
ipv6Available:(BOOL)ipv6Available
offline:(BOOL)offline;
@end