From 4b5d163492f54533b1cdb36058b74fa0931a7c40 Mon Sep 17 00:00:00 2001 From: Bob Rudis Date: Sat, 9 Apr 2016 17:15:34 -0400 Subject: [PATCH] initial commit --- .Rbuildignore | 5 ++++ .travis.yml | 5 ++++ CONDUCT.md | 25 +++++++++++++++++ DESCRIPTION | 18 ++++++++++--- NAMESPACE | 8 ++++-- R/gdns-package.r | 21 +++++++++++++++ R/gdns.r | 50 ++++++++++++++++++++++++++++++++++ README.Rmd | 67 ++++++++++++++++++++++++++++++++++++++++++++++ README.md | 63 +++++++++++++++++++++++++++++++++++++++++++ gdns.Rproj | 9 +++++++ man/gdns.Rd | 24 +++++++++++++++++ man/query.Rd | 47 ++++++++++++++++++++++++++++++++ tests/testthat.R | 4 +++ tests/testthat/test-gdns.R | 6 +++++ 14 files changed, 346 insertions(+), 6 deletions(-) create mode 100644 .travis.yml create mode 100644 CONDUCT.md create mode 100644 R/gdns-package.r create mode 100644 R/gdns.r create mode 100644 README.Rmd create mode 100644 README.md create mode 100644 man/gdns.Rd create mode 100644 man/query.Rd create mode 100644 tests/testthat.R create mode 100644 tests/testthat/test-gdns.R diff --git a/.Rbuildignore b/.Rbuildignore index 91114bf..e7ccc30 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,2 +1,7 @@ ^.*\.Rproj$ ^\.Rproj\.user$ +^README\.Rmd$ +^README-.*\.png$ +^\.travis\.yml$ +^CONDUCT\.md$ +^README\.md$ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..bfdac82 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +# Sample .travis.yml for R projects + +language: r +warnings_are_errors: true +sudo: required diff --git a/CONDUCT.md b/CONDUCT.md new file mode 100644 index 0000000..52a673e --- /dev/null +++ b/CONDUCT.md @@ -0,0 +1,25 @@ +# Contributor Code of Conduct + +As contributors and maintainers of this project, we pledge to respect all people who +contribute through reporting issues, posting feature requests, updating documentation, +submitting pull requests or patches, and other activities. + +We are committed to making participation in this project a harassment-free experience for +everyone, regardless of level of experience, gender, gender identity and expression, +sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. + +Examples of unacceptable behavior by participants include the use of sexual language or +imagery, derogatory comments or personal attacks, trolling, public or private harassment, +insults, or other unprofessional conduct. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, +commits, code, wiki edits, issues, and other contributions that are not aligned to this +Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed +from the project team. + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by +opening an issue or contacting one or more of the project maintainers. + +This Code of Conduct is adapted from the Contributor Covenant +(http:contributor-covenant.org), version 1.0.0, available at +http://contributor-covenant.org/version/1/0/0/ diff --git a/DESCRIPTION b/DESCRIPTION index 4479180..6b2d4e7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,18 @@ Package: gdns -Title: What the Package Does (one line, title case) -Version: 0.0.0.9000 +Title: Tools to Work with Google DNS Over https API +Version: 0.1.0.9000 Authors@R: c(person("Bob", "Rudis", email = "bob@rudis.net", role = c("aut", "cre"))) -Description: What the package does (one paragraph). -Depends: R (>= 3.2.4) +Maintainer: Bob Rudis +Description: Tools to Work with Google DNS Over https API License: AGPL + file LICENSE LazyData: true +Encoding: UTF-8 +Depends: + R (>= 3.0.0) +Suggests: + testthat +Imports: + httr, + jsonlite, + purrr +RoxygenNote: 5.0.1 diff --git a/NAMESPACE b/NAMESPACE index 884a631..6940d3b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,2 +1,6 @@ -# Generated by roxygen2: fake comment so roxygen2 overwrites silently. -exportPattern("^[^\\.]") +# Generated by roxygen2: do not edit by hand + +export(query) +import(httr) +importFrom(jsonlite,fromJSON) +importFrom(purrr,safely) diff --git a/R/gdns-package.r b/R/gdns-package.r new file mode 100644 index 0000000..3fd0af8 --- /dev/null +++ b/R/gdns-package.r @@ -0,0 +1,21 @@ +#' Tools to Work with Google DNS Over https API +#' +#' Traditional DNS queries and responses are sent over UDP or TCP without +#' encryption. This is vulnerable to eavesdropping and spoofing (including +#' DNS-based Internet filtering). Responses from recursive resolvers to clients +#' are the most vulnerable to undesired or malicious changes, while +#' communications between recursive resolvers and authoritative nameservers +#' often incorporate additional protection.\cr +#' \cr +#' To address this problem, Google Public DNS offers DNS resolution over an +#' encrypted HTTPS connection. DNS-over-HTTPS greatly enhances privacy and +#' security between a client and a recursive resolver, and complements DNSSEC +#' to provide end-to-end authenticated DNS lookups.#' +#' +#' @name gdns +#' @docType package +#' @author Bob Rudis (@@hrbrmstr) +#' @import httr +#' @importFrom jsonlite fromJSON +#' @importFrom purrr safely +NULL diff --git a/R/gdns.r b/R/gdns.r new file mode 100644 index 0000000..bcb48b9 --- /dev/null +++ b/R/gdns.r @@ -0,0 +1,50 @@ +S_GET <- purrr::safely(GET) + +#' Perform DNS over HTTPS queries using Google +#' +#' Traditional DNS queries and responses are sent over UDP or TCP without +#' encryption. This is vulnerable to eavesdropping and spoofing (including +#' DNS-based Internet filtering). Responses from recursive resolvers to clients +#' are the most vulnerable to undesired or malicious changes, while +#' communications between recursive resolvers and authoritative nameservers +#' often incorporate additional protection.\cr +#' \cr +#' To address this problem, Google Public DNS offers DNS resolution over an +#' encrypted HTTPS connection. DNS-over-HTTPS greatly enhances privacy and +#' security between a client and a recursive resolver, and complements DNSSEC +#' to provide end-to-end authenticated DNS lookups. +#' +#' @param name item to lookup. Valid characters are numbers, letters, hyphen, and dot. Length +#' must be between 1 and 255. Names with escaped or non-ASCII characters +#' are not supported. Internationalized domain names must use the +#' punycode format (e.g. "\code{xn--qxam}" rather than "\code{ελ}") +#' @param type RR type can be represented as a number in [1, 65535] or canonical +#' string (A, aaaa, etc.) +#' @param edns_client_subnet The edns0-client-subnet option. Format is an IP +#' address with a subnet mask. Examples: \code{1.2.3.4/24}, +#' \code{2001:700:300::/48}.\cr +#' If you are using DNS-over-HTTPS because of privacy concerns, and do +#' not want any part of your IP address to be sent to authoritative +#' nameservers for geographic location accuracy, use +#' \code{edns_client_subnet=0.0.0.0/0}. Google Public DNS normally sends +#' approximate network information (usually replacing the last part of +#' your IPv4 address with zeroes). +#' @return a \code{list} with the query result or \code{NULL} if an error occurred +#' @export +#' @examples +#' query("rud.is") +query <- function(name, type="1", cd=FALSE, edns_client_subnet=NULL) { + + res <- S_GET("https://dns.google.com/resolve", + query=list(name=name, + type=type, + edns_client_subnet=edns_client_subnet)) + + if (!is.null(res$result)) { + stop_for_status(res$result) + jsonlite::fromJSON(httr::content(res$result, as="text")) + } else { + NULL + } + +} diff --git a/README.Rmd b/README.Rmd new file mode 100644 index 0000000..3edb7c4 --- /dev/null +++ b/README.Rmd @@ -0,0 +1,67 @@ +--- +output: + md_document: + variant: markdown_github +--- + + + +```{r, echo = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + fig.path = "README-" +) +``` + +`gdns` : Tools to work with the Google DNS over HTTPS API + +The following functions are implemented: + +- `query` : perform the DNS query + +### News + +- Version 0.1.0.9000 released + +### Installation + +```{r eval=FALSE} +devtools::install_github("hrbrmstr/gdns") +``` + +```{r echo=FALSE, message=FALSE, warning=FALSE, error=FALSE} +options(width=120) +``` + +### Usage + +```{r} +library(gdns) + +# current verison +packageVersion("gdns") + +``` + +### Test Results + +```{r} +library(gdns) +library(testthat) + +date() + +test_dir("tests/") + +library(purrr) + +hosts <- c("rud.is", "dds.ec", "r-project.org", "rstudio.com") +results <- map(hosts, gdns::query) +map_df(results, "Answer") +``` + +### Code of Conduct + +Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). +By participating in this project you agree to abide by its terms. diff --git a/README.md b/README.md new file mode 100644 index 0000000..1693dd8 --- /dev/null +++ b/README.md @@ -0,0 +1,63 @@ + +`gdns` : Tools to work with the Google DNS over HTTPS API + +The following functions are implemented: + +- `query` : perform the DNS query + +### News + +- Version 0.1.0.9000 released + +### Installation + +``` r +devtools::install_github("hrbrmstr/gdns") +``` + +### Usage + +``` r +library(gdns) + +# current verison +packageVersion("gdns") +#> [1] '0.1.0.9000' +``` + +### Test Results + +``` r +library(gdns) +library(testthat) + +date() +#> [1] "Sat Apr 9 17:14:38 2016" + +test_dir("tests/") +#> testthat results ======================================================================================================== +#> OK: 0 SKIPPED: 0 FAILED: 0 + +library(purrr) +#> +#> Attaching package: 'purrr' +#> The following object is masked from 'package:testthat': +#> +#> is_null + +hosts <- c("rud.is", "dds.ec", "r-project.org", "rstudio.com") +results <- map(hosts, gdns::query) +map_df(results, "Answer") +#> Source: local data frame [4 x 4] +#> +#> name type TTL data +#> (chr) (int) (int) (chr) +#> 1 rud.is. 1 3147 104.236.112.222 +#> 2 dds.ec. 1 299 162.243.111.4 +#> 3 r-project.org. 1 1801 137.208.57.37 +#> 4 rstudio.com. 1 3482 45.79.156.36 +``` + +### Code of Conduct + +Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). By participating in this project you agree to abide by its terms. diff --git a/gdns.Rproj b/gdns.Rproj index d848a9f..773de7e 100644 --- a/gdns.Rproj +++ b/gdns.Rproj @@ -14,3 +14,12 @@ BuildType: Package PackageUseDevtools: Yes PackageInstallArgs: --no-multiarch --with-keep.source PackageRoxygenize: rd,collate,namespace + +UseSpacesForTab: Yes +NumSpacesForTab: 2 + +RnwWeave: Sweave +LaTeX: pdfLaTeX + +PackageBuildArgs: --resave-data +PackageCheckArgs: --as-cran diff --git a/man/gdns.Rd b/man/gdns.Rd new file mode 100644 index 0000000..c934204 --- /dev/null +++ b/man/gdns.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/gdns-package.r +\docType{package} +\name{gdns} +\alias{gdns} +\alias{gdns-package} +\title{Tools to Work with Google DNS Over https API} +\description{ +Traditional DNS queries and responses are sent over UDP or TCP without +encryption. This is vulnerable to eavesdropping and spoofing (including +DNS-based Internet filtering). Responses from recursive resolvers to clients +are the most vulnerable to undesired or malicious changes, while +communications between recursive resolvers and authoritative nameservers +often incorporate additional protection.\cr +\cr +To address this problem, Google Public DNS offers DNS resolution over an +encrypted HTTPS connection. DNS-over-HTTPS greatly enhances privacy and +security between a client and a recursive resolver, and complements DNSSEC +to provide end-to-end authenticated DNS lookups.#' +} +\author{ +Bob Rudis (@hrbrmstr) +} + diff --git a/man/query.Rd b/man/query.Rd new file mode 100644 index 0000000..deeb6bd --- /dev/null +++ b/man/query.Rd @@ -0,0 +1,47 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/gdns.r +\name{query} +\alias{query} +\title{Perform DNS over HTTPS queries using Google} +\usage{ +query(name, type = "1", cd = FALSE, edns_client_subnet = NULL) +} +\arguments{ +\item{name}{item to lookup. Valid characters are numbers, letters, hyphen, and dot. Length +must be between 1 and 255. Names with escaped or non-ASCII characters +are not supported. Internationalized domain names must use the +punycode format (e.g. "\code{xn--qxam}" rather than "\code{ελ}")} + +\item{type}{RR type can be represented as a number in [1, 65535] or canonical +string (A, aaaa, etc.)} + +\item{edns_client_subnet}{The edns0-client-subnet option. Format is an IP +address with a subnet mask. Examples: \code{1.2.3.4/24}, +\code{2001:700:300::/48}.\cr +If you are using DNS-over-HTTPS because of privacy concerns, and do +not want any part of your IP address to be sent to authoritative +nameservers for geographic location accuracy, use +\code{edns_client_subnet=0.0.0.0/0}. Google Public DNS normally sends +approximate network information (usually replacing the last part of +your IPv4 address with zeroes).} +} +\value{ +a \code{list} with the query result or \code{NULL} if an error occurred +} +\description{ +Traditional DNS queries and responses are sent over UDP or TCP without +encryption. This is vulnerable to eavesdropping and spoofing (including +DNS-based Internet filtering). Responses from recursive resolvers to clients +are the most vulnerable to undesired or malicious changes, while +communications between recursive resolvers and authoritative nameservers +often incorporate additional protection.\cr +\cr +To address this problem, Google Public DNS offers DNS resolution over an +encrypted HTTPS connection. DNS-over-HTTPS greatly enhances privacy and +security between a client and a recursive resolver, and complements DNSSEC +to provide end-to-end authenticated DNS lookups. +} +\examples{ +query("rud.is") +} + diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..b022f0d --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,4 @@ +library(testthat) +library(gdns) + +test_check("gdns") diff --git a/tests/testthat/test-gdns.R b/tests/testthat/test-gdns.R new file mode 100644 index 0000000..ab6f62f --- /dev/null +++ b/tests/testthat/test-gdns.R @@ -0,0 +1,6 @@ +context("basic functionality") +test_that("we can do something", { + + #expect_that(some_function(), is_a("data.frame")) + +})