New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setopt: add CURLOPT_DOH_URL #2668

Closed
wants to merge 4 commits into
base: master
from

Conversation

Projects
None yet
3 participants
@bagder
Member

bagder commented Jun 18, 2018

Support for DNS-over-HTTPS for name resolving when doing transfers.

Complies with dns-over-https-14, tested a bit against the cloudflare end-point.

Wiki page with status, TODO and more.

This is still early days.

simplest example:

#include <stdio.h>
#include <curl/curl.h>

int main(void)
{
  CURL *curl;
  CURLcode res;

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "https://curl.haxx.se/");
    curl_easy_setopt(curl, CURLOPT_DOH_URL, "https://dns.cloudflare.com/dns-query");
    res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
  }
  return 0;
}

@bagder bagder added the name lookup label Jun 26, 2018

@bagder bagder changed the title from setopt: add CURLOPT_DOH_URL [WIP] to setopt: add CURLOPT_DOH_URL Jun 27, 2018

@bagder bagder removed the on-hold label Jun 27, 2018

@danielgustafsson

A few scattered comments from skimming the code.

lib/doh.c Outdated
static const char *doh_strerror(DOHcode code)
{
return errors[code];

This comment has been minimized.

@danielgustafsson

danielgustafsson Aug 30, 2018

Member

Should this do bounds checking? While not at risk in the current coding, belts are stylish when coupled with suspenders..

This comment has been minimized.

@bagder

bagder Aug 31, 2018

Member

You're totally correct of course. I'll fix!

lib/doh.c Outdated
result = CURLE_OUT_OF_MEMORY;
goto error;
}
p->serverdoh.size = 0;

This comment has been minimized.

@danielgustafsson

danielgustafsson Aug 30, 2018

Member

Shouldn't this be set to 1 per the above allocation? (the addition in doh_write_cb() relies on this being "incorrect" but that seems a bit magic) On that note, is there a reason to allocate 1 rather than use a NULL ptr to indicate "reallocation required" since realloc() on a NULL ptr is identical to malloc()?

This comment has been minimized.

@bagder

bagder Aug 31, 2018

Member

You're right on the size assign. But I think it should rather allocate a sensible default size that can make it avoid the realloc in typical responses. I'll make it a 100 bytes I think.

heap space.
Note that \fIcurl_easy_setopt(3)\fP won't actually parse the given string so
given a bad DOH URL, curl will not be detected a problem until it tries to

This comment has been minimized.

@danielgustafsson

danielgustafsson Aug 30, 2018

Member

Was this intended to say "will not detect a problem"?

This comment has been minimized.

@bagder
lib/doh.c Outdated
}
#define ERROR_CHECK_SETOPT(x,y) result = curl_easy_setopt(doh, x, y); \
if(result) goto error;

This comment has been minimized.

@gvanem

gvanem Aug 31, 2018

Member

This will trigger -Wextra-semi warnings with clang.

This comment has been minimized.

@bagder

bagder Aug 31, 2018

Member

Thanks, I'll fix!

size_t size;
};
/* one of these for each DOH HTTP request */

This comment has been minimized.

@danielgustafsson

danielgustafsson Aug 31, 2018

Member

Nitpick, but should this say "DOH HTTPS request"?

This comment has been minimized.

@bagder

bagder Sep 1, 2018

Member

correct!

This comment has been minimized.

@bagder

bagder Sep 1, 2018

Member

or perhaps just "each DoH request" ...

@bagder

This comment has been minimized.

Member

bagder commented Sep 1, 2018

The short name of the protocol became DoH while this patch was in development, I'm changing source comments to use the new abbreviation.

Show resolved Hide resolved lib/doh.c Outdated
Show resolved Hide resolved lib/doh.c Outdated
@danielgustafsson

This comment has been minimized.

Member

danielgustafsson commented Sep 4, 2018

bagder added some commits Jun 17, 2018

@bagder bagder closed this in abff183 Sep 6, 2018

@bagder bagder deleted the bagder/DOH branch Sep 6, 2018

falconindy added a commit to falconindy/curl that referenced this pull request Sep 10, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment