master
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24#include "unitcheck.h"
25#include "vdns/doh.h"
27static CURLcode test_unit1650(const char *arg)
28{
29 UNITTEST_BEGIN_SIMPLE
31#ifndef CURL_DISABLE_DOH
33#define DNS_PREAMBLE "\x00\x00\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00"
34#define LABEL_TEST "\x04\x74\x65\x73\x74"
35#define LABEL_HOST "\x04\x68\x6f\x73\x74"
36#define LABEL_NAME "\x04\x6e\x61\x6d\x65"
37#define DNSA_TYPE "\x01"
38#define DNSAAAA_TYPE "\x1c"
39#define DNSA_EPILOGUE "\x00\x00" DNSA_TYPE "\x00\x01"
40#define DNSAAAA_EPILOGUE "\x00\x00" DNSAAAA_TYPE "\x00\x01"
42#define DNS_Q1 DNS_PREAMBLE LABEL_TEST LABEL_HOST LABEL_NAME DNSA_EPILOGUE
43#define DNS_Q2 DNS_PREAMBLE LABEL_TEST LABEL_HOST LABEL_NAME DNSAAAA_EPILOGUE
45 struct dohrequest {
46 /* input */
47 const char *name;
48 DNStype type;
50 /* output */
51 const char *packet;
52 size_t size;
53 DOHcode rc;
54 };
56 static const struct dohrequest req[] = {
57 {"test.host.name",
58 CURL_DNS_TYPE_A, DNS_Q1, CURL_CSTRLEN(DNS_Q1), DOH_OK },
59 {"test.host.name",
60 CURL_DNS_TYPE_AAAA, DNS_Q2, CURL_CSTRLEN(DNS_Q2), DOH_OK },
61 {"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
62 ".host.name",
63 CURL_DNS_TYPE_AAAA, NULL, 0, DOH_DNS_BAD_LABEL }
64 };
66 struct dohresp {
67 /* input */
68 const char *packet;
69 size_t size;
70 DNStype type;
72 /* output */
73 DOHcode rc;
74 const char *out;
75 };
77#define DNS_FOO_EXAMPLE_COM \
78 "\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x00\x03\x66\x6f\x6f" \
79 "\x07\x65\x78\x61\x6d\x70\x6c\x65\x03\x63\x6f\x6d\x00\x00\x01\x00" \
80 "\x01\xc0\x0c\x00\x01\x00\x01\x00\x00\x00\x37\x00\x04\x7f\x00\x00" \
81 "\x01"
83 static const char full49[] = DNS_FOO_EXAMPLE_COM;
85 static const struct dohresp resp[] = {
86 {"\x00\x00", 2, CURL_DNS_TYPE_A, DOH_TOO_SMALL_BUFFER, NULL },
87 {"\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01", 12,
88 CURL_DNS_TYPE_A, DOH_DNS_BAD_ID, NULL },
89 {"\x00\x00\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01", 12,
90 CURL_DNS_TYPE_A, DOH_DNS_BAD_RCODE, NULL },
91 {"\x00\x00\x00\x03\x00\x01\x00\x01\x00\x01\x00\x01", 12,
92 CURL_DNS_TYPE_A, DOH_DNS_NXDOMAIN, NULL },
93 {"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x00\x03\x66\x6f\x6f", 16,
94 CURL_DNS_TYPE_A, DOH_DNS_OUT_OF_RANGE, NULL },
95 {"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x00\x03\x66\x6f\x6f\x00", 17,
96 CURL_DNS_TYPE_A, DOH_DNS_OUT_OF_RANGE, NULL },
97 {"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x00\x03\x66\x6f\x6f\x00"
98 "\x00\x01\x00\x01", 21,
99 CURL_DNS_TYPE_A, DOH_DNS_OUT_OF_RANGE, NULL },
100 {"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x00\x03\x66\x6f\x6f\x00"
101 "\x00\x01\x00\x01"
102 "\x04", 18,
103 CURL_DNS_TYPE_A, DOH_DNS_OUT_OF_RANGE, NULL },
105 {"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x00\x04\x63\x75\x72"
106 "\x6c\x04\x63\x75\x72\x6c\x00\x00\x05\x00\x01\xc0\x0c\x00\x05\x00"
107 "\x01\x00\x00\x00\x37\x00\x11\x08\x61\x6e\x79\x77\x68\x65\x72\x65"
108 "\x06\x72\x65\x61\x6c\x6c\x79\x00", 56,
109 CURL_DNS_TYPE_A, DOH_OK, NULL},
111 {DNS_FOO_EXAMPLE_COM, 49, CURL_DNS_TYPE_A, DOH_OK, "127.0.0.1 (55)"},
113 {"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x00\x04\x61\x61\x61"
114 "\x61\x07\x65\x78\x61\x6d\x70\x6c\x65\x03\x63\x6f\x6d\x00\x00\x1c"
115 "\x00\x01\xc0\x0c\x00\x1c\x00\x01\x00\x00\x01\x37\x00\x10\x20\x20"
116 "\x20\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x20", 62,
117 CURL_DNS_TYPE_AAAA, DOH_OK,
118 "2020:2020:0000:0000:0000:0000:0000:2020 (311)" },
120 {"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x00\x04\x63\x75\x72"
121 "\x6c\x04\x63\x75\x72\x6c\x00\x00\x05\x00\x01\xc0\x0c\x00\x05\x00"
122 "\x01\x00\x00\x00\x37\x00"
123 "\x07\x03\x61\x6e\x79\xc0\x27\x00", 46,
124 CURL_DNS_TYPE_A, DOH_OK, NULL},
126 /* packet with NSCOUNT == 1 */
127 {"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x01\x00\x00\x04\x61\x61\x61"
128 "\x61\x07\x65\x78\x61\x6d\x70\x6c\x65\x03\x63\x6f\x6d\x00\x00\x1c"
129 "\x00\x01\xc0\x0c\x00\x1c\x00\x01\x00\x00\x00\x37\x00\x10\x20\x20"
130 "\x20\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x20"
131 LABEL_TEST LABEL_HOST LABEL_NAME DNSAAAA_EPILOGUE "\x00\x00\x00\x01"
132 "\00\x04\x01\x01\x01\x01", /* RDDATA */
134 62 + 30,
135 CURL_DNS_TYPE_AAAA, DOH_OK,
136 "2020:2020:0000:0000:0000:0000:0000:2020 (55)" },
138 /* packet with ARCOUNT == 1, and a capped TTL */
139 {"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x01\x04\x61\x61\x61"
140 "\x61\x07\x65\x78\x61\x6d\x70\x6c\x65\x03\x63\x6f\x6d\x00\x00\x1c"
141 "\x00\x01\xc0\x0c\x00\x1c\x00\x01\x00\xff\xff\x37\x00\x10\x20\x20"
142 "\x20\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x20"
143 LABEL_TEST LABEL_HOST LABEL_NAME DNSAAAA_EPILOGUE "\x00\x00\x00\x01"
144 "\00\x04\x01\x01\x01\x01", /* RDDATA */
146 62 + 30,
147 CURL_DNS_TYPE_AAAA, DOH_OK,
148 "2020:2020:0000:0000:0000:0000:0000:2020 (86400)" },
150 };
152 size_t size = 0;
153 unsigned char buffer[256];
154 size_t i;
155 unsigned char *p;
157 for(i = 0; i < CURL_ARRAYSIZE(req); i++) {
158 DOHcode rc = doh_req_encode(req[i].name, req[i].type,
159 buffer, sizeof(buffer), &size);
160 if(rc != req[i].rc) {
161 curl_mfprintf(stderr, "req %zu: Expected return code %d got %d\n", i,
162 (int)req[i].rc, (int)rc);
163 abort_if(rc != req[i].rc, "return code");
164 }
165 if(size != req[i].size) {
166 curl_mfprintf(stderr, "req %zu: Expected size %zu got %zu\n", i,
167 req[i].size, size);
168 curl_mfprintf(stderr, "DNS encode made: %s\n", hexdump(buffer, size));
169 abort_if(size != req[i].size, "size");
170 }
171 if(req[i].packet && memcmp(req[i].packet, buffer, size)) {
172 curl_mfprintf(stderr, "DNS encode made: %s\n", hexdump(buffer, size));
173 curl_mfprintf(stderr, "... instead of: %s\n",
174 hexdump((const unsigned char *)req[i].packet, size));
175 abort_if(req[i].packet && memcmp(req[i].packet, buffer, size),
176 "contents");
177 }
178 }
180 for(i = 0; i < CURL_ARRAYSIZE(resp); i++) {
181 struct dohentry d;
182 DOHcode rc;
183 char *ptr;
184 size_t len;
185 int u;
186 de_init(&d);
187 rc = doh_resp_decode((const unsigned char *)resp[i].packet, resp[i].size,
188 resp[i].type, &d);
189 if(rc != resp[i].rc) {
190 curl_mfprintf(stderr, "resp %zu: Expected return code %d got %d\n", i,
191 (int)resp[i].rc, (int)rc);
192 abort_if(rc != resp[i].rc, "return code");
193 }
194 len = sizeof(buffer);
195 ptr = (char *)buffer;
196 for(u = 0; u < d.numaddr; u++) {
197 size_t o;
198 struct dohaddr *a;
199 a = &d.addr[u];
200 if(resp[i].type == CURL_DNS_TYPE_A) {
201 p = &a->ip.v4[0];
202 curl_msnprintf(ptr, len, "%u.%u.%u.%u ", p[0], p[1], p[2], p[3]);
203 o = strlen(ptr);
204 len -= o;
205 ptr += o;
206 }
207 else {
208 int j;
209 for(j = 0; j < 16; j += 2) {
210 size_t l;
211 curl_msnprintf(ptr, len, "%s%02x%02x", j ? ":" : "", a->ip.v6[j],
212 a->ip.v6[j + 1]);
213 l = strlen(ptr);
214 len -= l;
215 ptr += l;
216 }
217 curl_msnprintf(ptr, len, " ");
218 len--;
219 ptr++;
220 }
221 }
222 curl_msnprintf(ptr, len, "(%u)", d.ttl);
223 de_cleanup(&d);
224 if(resp[i].out && strcmp((const char *)buffer, resp[i].out)) {
225 curl_mfprintf(stderr, "resp %zu: Expected %s got %s\n", i,
226 resp[i].out, buffer);
227 abort_if(resp[i].out && strcmp((const char *)buffer, resp[i].out),
228 "content");
229 }
230 }
232#ifdef USE_HTTPSRR
233 {
234 unsigned char httpsrr[] = {
235 0x00, 0x00, 0x81, 0x80, 0x00, 0x00, 0x00, 0x01,
236 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x00,
237 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00,
238 0x00, 0x00
239 };
241 for(i = 0; i <= 3; i++) {
242 struct dohentry d;
243 DOHcode rc;
244 DOHcode expected = i < 3 ? DOH_DNS_RDATA_LEN : DOH_OK;
245 httpsrr[22] = (unsigned char)i;
246 de_init(&d);
247 rc = doh_resp_decode(httpsrr, sizeof(httpsrr) - 3 + i,
248 CURL_DNS_TYPE_HTTPS, &d);
249 if(rc != expected) {
250 curl_mfprintf(stderr,
251 "HTTPS RR length %zu: Expected return code %d got %d\n",
252 i, (int)expected, (int)rc);
253 abort_if(rc != expected, "return code");
254 }
255 fail_unless(d.numhttps_rrs == (i == 3 ? 1 : 0),
256 "unexpected number of HTTPS RRs");
257 de_cleanup(&d);
258 }
259 }
260#endif
262 /* pass all sizes into the decoder until full */
263 for(i = 0; i < CURL_CSTRLEN(full49); i++) {
264 struct dohentry d;
265 DOHcode rc;
266 memset(&d, 0, sizeof(d));
267 rc = doh_resp_decode((const unsigned char *)full49,
268 i, CURL_DNS_TYPE_A, &d);
269 if(!rc) {
270 /* none of them should work */
271 curl_mfprintf(stderr, "%zu: %d\n", i, (int)rc);
272 abort_if(!rc, "error rc");
273 }
274 }
276 /* and try all pieces from the other end of the packet */
277 for(i = 1; i < sizeof(full49); i++) {
278 struct dohentry d;
279 DOHcode rc;
280 memset(&d, 0, sizeof(d));
281 rc = doh_resp_decode((const unsigned char *)&full49[i],
282 sizeof(full49) - i - 1, CURL_DNS_TYPE_A, &d);
283 if(!rc) {
284 /* none of them should work */
285 curl_mfprintf(stderr, "2 %zu: %d\n", i, (int)rc);
286 abort_if(!rc, "error rc");
287 }
288 }
290 {
291 DOHcode rc;
292 struct dohentry d;
293 struct dohaddr *a;
294 memset(&d, 0, sizeof(d));
295 rc = doh_resp_decode((const unsigned char *)full49, CURL_CSTRLEN(full49),
296 CURL_DNS_TYPE_A, &d);
297 fail_if(d.numaddr != 1, "missing address");
298 a = &d.addr[0];
299 p = &a->ip.v4[0];
300 curl_msnprintf((char *)buffer, sizeof(buffer),
301 "%u.%u.%u.%u", p[0], p[1], p[2], p[3]);
302 if(rc || strcmp((const char *)buffer, "127.0.0.1")) {
303 curl_mfprintf(stderr, "bad address decoded: %s, rc == %d\n", buffer,
304 (int)rc);
305 abort_if(rc || strcmp((const char *)buffer, "127.0.0.1"), "bad address");
306 }
307 }
308#endif
310 UNITTEST_END_SIMPLE
311}
Diagnostics4 git calls · 188 ms
CallStatusSizeTime0188 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=183 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2003.0 KiB183 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=3100 git.response.cache=MISS git.response.duration_ms=183 git.fetch.wants=2a9726959c12a3f917925f452d9e95903a5f2c30 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=3100 git.pkt.payload.max=3079 git.sideband.band1.bytes=3078 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e2e6180a162947
- Request
- 05e9271b…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format