• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef HEADER_CURL_DOH_H
2 #define HEADER_CURL_DOH_H
3 /***************************************************************************
4  *                                  _   _ ____  _
5  *  Project                     ___| | | |  _ \| |
6  *                             / __| | | | |_) | |
7  *                            | (__| |_| |  _ <| |___
8  *                             \___|\___/|_| \_\_____|
9  *
10  * Copyright (C) 2018 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
11  *
12  * This software is licensed as described in the file COPYING, which
13  * you should have received as part of this distribution. The terms
14  * are also available at https://curl.se/docs/copyright.html.
15  *
16  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17  * copies of the Software, and permit persons to whom the Software is
18  * furnished to do so, under the terms of the COPYING file.
19  *
20  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21  * KIND, either express or implied.
22  *
23  ***************************************************************************/
24 
25 #include "urldata.h"
26 #include "curl_addrinfo.h"
27 
28 #ifndef CURL_DISABLE_DOH
29 
30 /*
31  * Curl_doh() resolve a name using DoH (DNS-over-HTTPS). It resolves a name
32  * and returns a 'Curl_addrinfo *' with the address information.
33  */
34 
35 struct Curl_addrinfo *Curl_doh(struct Curl_easy *data,
36                                const char *hostname,
37                                int port,
38                                int *waitp);
39 
40 CURLcode Curl_doh_is_resolved(struct Curl_easy *data,
41                               struct Curl_dns_entry **dns);
42 
43 int Curl_doh_getsock(struct connectdata *conn, curl_socket_t *socks);
44 
45 typedef enum {
46   DOH_OK,
47   DOH_DNS_BAD_LABEL,    /* 1 */
48   DOH_DNS_OUT_OF_RANGE, /* 2 */
49   DOH_DNS_LABEL_LOOP,   /* 3 */
50   DOH_TOO_SMALL_BUFFER, /* 4 */
51   DOH_OUT_OF_MEM,       /* 5 */
52   DOH_DNS_RDATA_LEN,    /* 6 */
53   DOH_DNS_MALFORMAT,    /* 7 */
54   DOH_DNS_BAD_RCODE,    /* 8 - no such name */
55   DOH_DNS_UNEXPECTED_TYPE,  /* 9 */
56   DOH_DNS_UNEXPECTED_CLASS, /* 10 */
57   DOH_NO_CONTENT,           /* 11 */
58   DOH_DNS_BAD_ID,           /* 12 */
59   DOH_DNS_NAME_TOO_LONG     /* 13 */
60 } DOHcode;
61 
62 typedef enum {
63   DNS_TYPE_A = 1,
64   DNS_TYPE_NS = 2,
65   DNS_TYPE_CNAME = 5,
66   DNS_TYPE_AAAA = 28,
67   DNS_TYPE_DNAME = 39           /* RFC6672 */
68 } DNStype;
69 
70 #define DOH_MAX_ADDR 24
71 #define DOH_MAX_CNAME 4
72 
73 struct dohaddr {
74   int type;
75   union {
76     unsigned char v4[4]; /* network byte order */
77     unsigned char v6[16];
78   } ip;
79 };
80 
81 struct dohentry {
82   struct dynbuf cname[DOH_MAX_CNAME];
83   struct dohaddr addr[DOH_MAX_ADDR];
84   int numaddr;
85   unsigned int ttl;
86   int numcname;
87 };
88 
89 
90 #ifdef DEBUGBUILD
91 DOHcode doh_encode(const char *host,
92                    DNStype dnstype,
93                    unsigned char *dnsp, /* buffer */
94                    size_t len,  /* buffer size */
95                    size_t *olen); /* output length */
96 DOHcode doh_decode(const unsigned char *doh,
97                    size_t dohlen,
98                    DNStype dnstype,
99                    struct dohentry *d);
100 void de_init(struct dohentry *d);
101 void de_cleanup(struct dohentry *d);
102 #endif
103 
104 #else /* if DoH is disabled */
105 #define Curl_doh(a,b,c,d) NULL
106 #define Curl_doh_is_resolved(x,y) CURLE_COULDNT_RESOLVE_HOST
107 #endif
108 
109 #endif /* HEADER_CURL_DOH_H */
110