Skip to content
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 from
Closed

setopt: add CURLOPT_DOH_URL #2668

wants to merge 4 commits into from

Conversation

bagder
Copy link
Member

@bagder 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 on-hold feature-window A merge of this requires an open feature window labels Jun 18, 2018
@bagder bagder force-pushed the bagder/DOH branch 3 times, most recently from 6bf97fc to eca3d0b Compare June 24, 2018 21:21
@bagder bagder added the name lookup DNS and related tech label Jun 26, 2018
@bagder bagder changed the title setopt: add CURLOPT_DOH_URL [WIP] setopt: add CURLOPT_DOH_URL Jun 27, 2018
@bagder bagder removed the on-hold label Jun 27, 2018
Copy link
Member

@danielgustafsson danielgustafsson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few scattered comments from skimming the code.

lib/doh.c Outdated

static const char *doh_strerror(DOHcode code)
{
return errors[code];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

lib/doh.c Outdated
}

#define ERROR_CHECK_SETOPT(x,y) result = curl_easy_setopt(doh, x, y); \
if(result) goto error;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will trigger -Wextra-semi warnings with clang.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'll fix!

lib/urldata.h Outdated
size_t size;
};

/* one of these for each DOH HTTP request */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or perhaps just "each DoH request" ...

@bagder
Copy link
Member Author

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.

lib/doh.c Outdated Show resolved Hide resolved
lib/doh.c Outdated Show resolved Hide resolved
@danielgustafsson
Copy link
Member

danielgustafsson commented Sep 4, 2018 via email

@bagder bagder closed this in abff183 Sep 6, 2018
@bagder bagder deleted the bagder/DOH branch September 6, 2018 07:18
@bagder bagder removed the feature-window A merge of this requires an open feature window label Sep 6, 2018
falconindy pushed a commit to falconindy/curl that referenced this pull request Sep 10, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Dec 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
name lookup DNS and related tech
Development

Successfully merging this pull request may close these issues.

None yet

3 participants