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
5 * This file is part of GnuPG.
7 * This file is free software; you can redistribute it and/or modify
8 * it under the terms of either
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.
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.
20 * or both in parallel, as here.
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.
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/>.
30 #ifndef GNUPG_DIRMNGR_DNS_STUFF_H
31 #define GNUPG_DIRMNGR_DNS_STUFF_H
33 #ifdef HAVE_W32_SYSTEM
34 # ifdef HAVE_WINSOCK2_H
35 # include <winsock2.h>
39 # include <sys/types.h>
40 # include <sys/socket.h>
44 * Flags used with resolve_dns_addr.
46 #define DNS_NUMERICHOST 1 /* Force numeric output format. */
47 #define DNS_WITHBRACKET 2 /* Put brackets around numeric v6
51 * Constants for use with get_dns_cert.
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)
72 struct dns_addrinfo_s;
73 typedef struct dns_addrinfo_s *dns_addrinfo_t;
81 struct sockaddr addr[1];
87 unsigned short priority;
88 unsigned short weight;
95 /* Set verbosity and debug mode for this module. */
96 void set_dns_verbose (int verbose, int debug);
98 /* Set the timeout for libdns requests to SECONDS. */
99 void set_dns_timeout (int seconds);
101 /* Calling this function with YES set to True forces the use of the
102 * standard resolver even if dirmngr has been built with support for
103 * an alternative resolver. */
104 void enable_standard_resolver (int yes);
106 /* Return true if the standard resolver is used. */
107 int standard_resolver_p (void);
109 /* Calling this function with YES switches libdns into recursive mode.
110 * It has no effect on the standard resolver. */
111 void enable_recursive_resolver (int yes);
113 /* Return true iff the recursive resolver is used. */
114 int recursive_resolver_p (void);
116 /* Put this module eternally into Tor mode. When called agained with
117 * NEW_CIRCUIT request a new TOR circuit for the next DNS query. */
118 void enable_dns_tormode (int new_circuit);
120 /* Change the default IP address of the nameserver to IPADDR. The
121 address needs to be a numerical IP address and will be used for the
122 next DNS query. Note that this is only used in Tor mode. */
123 void set_dns_nameserver (const char *ipaddr);
125 /* SIGHUP action handler for this module. */
126 void reload_dns_stuff (int force);
128 void free_dns_addrinfo (dns_addrinfo_t ai);
130 /* Function similar to getaddrinfo. */
131 gpg_error_t resolve_dns_name (const char *name, unsigned short port,
132 int want_family, int want_socktype,
133 dns_addrinfo_t *r_dai, char **r_canonname);
135 /* Function similar to getnameinfo. */
136 gpg_error_t resolve_dns_addr (const struct sockaddr *addr, int addrlen,
137 unsigned int flags, char **r_name);
139 /* Return true if NAME is a numerical IP address. */
140 int is_ip_address (const char *name);
142 /* Return true if NAME is an onion address. */
143 int is_onion_address (const char *name);
145 /* Get the canonical name for NAME. */
146 gpg_error_t get_dns_cname (const char *name, char **r_cname);
148 /* Return a CERT record or an arbitray RR. */
149 gpg_error_t get_dns_cert (const char *name, int want_certtype,
150 void **r_key, size_t *r_keylen,
151 unsigned char **r_fpr, size_t *r_fprlen,
154 /* Return an array of SRV records. */
155 gpg_error_t get_dns_srv (const char *name,
156 struct srventry **list, unsigned int *r_count);
159 #endif /*GNUPG_DIRMNGR_DNS_STUFF_H*/