chiark / gitweb /
dirmngr: New option --no-use-tor and internal changes.
[gnupg2.git] / dirmngr / dns-stuff.h
1 /* dns-stuff.c - DNS related code including CERT RR (rfc-4398)
2  * Copyright (C) 2006 Free Software Foundation, Inc.
3  * Copyright (C) 2006, 2015 Werner Koch
4  *
5  * This file is part of GnuPG.
6  *
7  * This file is free software; you can redistribute it and/or modify
8  * it under the terms of either
9  *
10  *   - the GNU Lesser General Public License as published by the Free
11  *     Software Foundation; either version 3 of the License, or (at
12  *     your option) any later version.
13  *
14  * or
15  *
16  *   - the GNU General Public License as published by the Free
17  *     Software Foundation; either version 2 of the License, or (at
18  *     your option) any later version.
19  *
20  * or both in parallel, as here.
21  *
22  * This file is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, see <https://www.gnu.org/licenses/>.
29  */
30 #ifndef GNUPG_DIRMNGR_DNS_STUFF_H
31 #define GNUPG_DIRMNGR_DNS_STUFF_H
32
33 #ifdef HAVE_W32_SYSTEM
34 # ifdef HAVE_WINSOCK2_H
35 #  include <winsock2.h>
36 # endif
37 # include <windows.h>
38 #else
39 # include <sys/types.h>
40 # include <sys/socket.h>
41 #endif
42
43 /*
44  * Flags used with resolve_dns_addr.
45  */
46 #define DNS_NUMERICHOST        1  /* Force numeric output format.  */
47 #define DNS_WITHBRACKET        2  /* Put brackets around numeric v6
48                                      addresses.  */
49
50 /*
51  * Constants for use with get_dns_cert.
52  */
53 #define DNS_CERTTYPE_ANY       0 /* Internal catch all type. */
54 /* Certificate types according to RFC-4398:  */
55 #define DNS_CERTTYPE_PKIX      1 /* X.509 as per PKIX. */
56 #define DNS_CERTTYPE_SPKI      2 /* SPKI certificate.  */
57 #define DNS_CERTTYPE_PGP       3 /* OpenPGP packet.  */
58 #define DNS_CERTTYPE_IPKIX     4 /* The URL of an X.509 data object. */
59 #define DNS_CERTTYPE_ISPKI     5 /* The URL of an SPKI certificate.  */
60 #define DNS_CERTTYPE_IPGP      6 /* The fingerprint
61                                     and URL of an OpenPGP packet.  */
62 #define DNS_CERTTYPE_ACPKIX    7 /* Attribute Certificate.  */
63 #define DNS_CERTTYPE_IACPKIX   8 /* The URL of an Attribute Certificate.  */
64 #define DNS_CERTTYPE_URI     253 /* URI private.  */
65 #define DNS_CERTTYPE_OID     254 /* OID private.  */
66 /* Hacks for our implementation.  */
67 #define DNS_CERTTYPE_RRBASE 1024 /* Base of special constants.  */
68 #define DNS_CERTTYPE_RR61   (DNS_CERTTYPE_RRBASE + 61)
69
70
71
72 struct dns_addrinfo_s;
73 typedef struct dns_addrinfo_s *dns_addrinfo_t;
74 struct dns_addrinfo_s
75 {
76   dns_addrinfo_t next;
77   int family;
78   int socktype;
79   int protocol;
80   int addrlen;
81   struct sockaddr addr[1];
82 };
83
84
85 struct srventry
86 {
87   unsigned short priority;
88   unsigned short weight;
89   unsigned short port;
90   int run_count;
91   char target[1025];
92 };
93
94
95 /* Set verbosity and debug mode for this module. */
96 void set_dns_verbose (int verbose, int debug);
97
98 /* Set the Disable-IPv4 flag so that the name resolver does not return
99  * A addresses.  */
100 void set_dns_disable_ipv4 (int yes);
101
102 /* Set the timeout for libdns requests to SECONDS.  */
103 void set_dns_timeout (int seconds);
104
105 /* Calling this function with YES set to True forces the use of the
106  * standard resolver even if dirmngr has been built with support for
107  * an alternative resolver.  */
108 void enable_standard_resolver (int yes);
109
110 /* Return true if the standard resolver is used.  */
111 int standard_resolver_p (void);
112
113 /* Calling this function with YES switches libdns into recursive mode.
114  * It has no effect on the standard resolver.  */
115 void enable_recursive_resolver (int yes);
116
117 /* Return true iff the recursive resolver is used.  */
118 int recursive_resolver_p (void);
119
120 /* Put this module eternally into Tor mode.  When called agained with
121  * NEW_CIRCUIT request a new TOR circuit for the next DNS query.  */
122 void enable_dns_tormode (int new_circuit);
123 void disable_dns_tormode (void);
124
125 /* Change the default IP address of the nameserver to IPADDR.  The
126    address needs to be a numerical IP address and will be used for the
127    next DNS query.  Note that this is only used in Tor mode.  */
128 void set_dns_nameserver (const char *ipaddr);
129
130 /* SIGHUP action handler for this module.  */
131 void reload_dns_stuff (int force);
132
133 void free_dns_addrinfo (dns_addrinfo_t ai);
134
135 /* Function similar to getaddrinfo.  */
136 gpg_error_t resolve_dns_name (const char *name, unsigned short port,
137                               int want_family, int want_socktype,
138                               dns_addrinfo_t *r_dai, char **r_canonname);
139
140 /* Function similar to getnameinfo.  */
141 gpg_error_t resolve_dns_addr (const struct sockaddr *addr, int addrlen,
142                               unsigned int flags, char **r_name);
143
144 /* Return true if NAME is a numerical IP address.  */
145 int is_ip_address (const char *name);
146
147 /* Return true if NAME is an onion address.  */
148 int is_onion_address (const char *name);
149
150 /* Get the canonical name for NAME.  */
151 gpg_error_t get_dns_cname (const char *name, char **r_cname);
152
153 /* Return a CERT record or an arbitray RR.  */
154 gpg_error_t get_dns_cert (const char *name, int want_certtype,
155                           void **r_key, size_t *r_keylen,
156                           unsigned char **r_fpr, size_t *r_fprlen,
157                           char **r_url);
158
159 /* Return an array of SRV records.  */
160 gpg_error_t get_dns_srv (const char *name,
161                          const char *service, const char *proto,
162                          struct srventry **list, unsigned int *r_count);
163
164
165 #endif /*GNUPG_DIRMNGR_DNS_STUFF_H*/