diff --git a/DESCRIPTION b/DESCRIPTION index ddb3797..eb8b605 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: clandnstine Type: Package -Title: Perform 'DNS' over 'TLS' Queries +Title: Perform Secure-by-default 'DNS' Queries Version: 0.1.0 Date: 2019-01-18 Authors@R: c( diff --git a/NAMESPACE b/NAMESPACE index a59b8e2..90c85b9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,12 +5,22 @@ S3method(print,gdns_response) export("%>%") export(gdns_context) export(gdns_get_address) +export(gdns_get_hosts) +export(gdns_get_resolution_type) +export(gdns_get_resolvconf) export(gdns_get_timeout) +export(gdns_get_tls_ca_file) +export(gdns_get_tls_ca_path) +export(gdns_get_transports) export(gdns_lib_version) export(gdns_query) export(gdns_set_hosts) +export(gdns_set_resolution_type) export(gdns_set_round_robin_upstreams) export(gdns_set_timeout) +export(gdns_set_tls_ca_file) +export(gdns_set_tls_ca_path) +export(gdns_set_transports) export(gdns_update_resolvers) importFrom(Rcpp,sourceCpp) importFrom(jsonlite,fromJSON) diff --git a/R/RcppExports.R b/R/RcppExports.R index b2fe2fb..d3eee3b 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -48,6 +48,76 @@ int_gdns_set_hosts <- function(gctx, hosts) { .Call(`_clandnstine_int_gdns_set_hosts`, gctx, hosts) } +#' Internal version of set_transports() +#' @keywords internal +int_gdns_set_transports <- function(gctx, trans) { + .Call(`_clandnstine_int_gdns_set_transports`, gctx, trans) +} + +#' Internal version of gdns_set_resolution_type() +#' @keywords internal +int_gdns_set_resolution_type <- function(gctx, res_type) { + .Call(`_clandnstine_int_gdns_set_resolution_type`, gctx, res_type) +} + +#' Retreive what transports are used for DNS lookups. +#' +#' @param gctx gdns resolver context created with [gdns_resolver()] +#' @export +gdns_get_transports <- function(gctx) { + .Call(`_clandnstine_gdns_get_transports`, gctx) +} + +#' Retreive the value of the localnames namespace +#' +#' @param gctx gdns resolver context created with [gdns_resolver()] +#' @export +gdns_get_hosts <- function(gctx) { + .Call(`_clandnstine_gdns_get_hosts`, gctx) +} + +#' Retreive the value with which the context's upstream recursive servers and suffixes were initialized +#' +#' @param gctx gdns resolver context created with [gdns_resolver()] +#' @export +gdns_get_resolvconf <- function(gctx) { + .Call(`_clandnstine_gdns_get_resolvconf`, gctx) +} + +#' Retreive the value with which the context's upstream recursive servers and suffixes were initialized +#' +#' @param gctx gdns resolver context created with [gdns_resolver()] +#' @export +gdns_get_tls_ca_path <- function(gctx) { + .Call(`_clandnstine_gdns_get_tls_ca_path`, gctx) +} + +#' Retreive the file location with CA certificates for verification purposes +#' +#' @param gctx gdns resolver context created with [gdns_resolver()] +#' @export +gdns_get_tls_ca_file <- function(gctx) { + .Call(`_clandnstine_gdns_get_tls_ca_file`, gctx) +} + +#' Specify where the location for CA certificates for verification purposes are located +#' +#' @param gctx gdns resolver context created with [gdns_resolver()] +#' @param ca_path directory with Certificate Authority certificates +#' @export +gdns_set_tls_ca_path <- function(gctx, ca_path) { + .Call(`_clandnstine_gdns_set_tls_ca_path`, gctx, ca_path) +} + +#' Specify the file with CA certificates for verification purposes +#' +#' @param gctx gdns resolver context created with [gdns_resolver()] +#' @param ca_file file with Certificate Authority certificates +#' @export +gdns_set_tls_ca_file <- function(gctx, ca_file) { + .Call(`_clandnstine_gdns_set_tls_ca_file`, gctx, ca_file) +} + #' Test whether an object is an external pointer #' #' @param x object to test @@ -64,10 +134,10 @@ is_null_xptr_ <- function(s) { .Call(`_clandnstine_is_null_xptr_`, s) } -#' Internal version of gdns_resolver +#' Internal version of gdns_context #' @keywords internal -int_gdns_resolver <- function(resolvers) { - .Call(`_clandnstine_int_gdns_resolver`, resolvers) +int_gdns_context <- function(resolvers) { + .Call(`_clandnstine_int_gdns_context`, resolvers) } #' Resolve a host to an addrss @@ -91,3 +161,14 @@ int_gdns_query <- function(gctx, name, rr, include_reporting = FALSE) { .Call(`_clandnstine_int_gdns_query`, gctx, name, rr, include_reporting) } +#' Get the current resolution type setting +#' +#' @param gctx gdns resolver context created with [gdns_resolver()] +#' @export +#' @examples +#' x <- gdns_context() +#' gdns_get_resolution_type(x) +gdns_get_resolution_type <- function(gctx) { + .Call(`_clandnstine_gdns_get_resolution_type`, gctx) +} + diff --git a/R/clandnstine-package.R b/R/clandnstine-package.R index c8e9a5c..7c102ad 100644 --- a/R/clandnstine-package.R +++ b/R/clandnstine-package.R @@ -1,4 +1,4 @@ -#' Perform 'DNS' over 'TLS' Queries +#' Perform Secure-by-default 'DNS' Queries #' #' Something something 'DNS. Something something 'TLS'. #' Something something 'getdns API/library'. diff --git a/R/print-context.R b/R/print-context.R index d24860f..9da93e7 100644 --- a/R/print-context.R +++ b/R/print-context.R @@ -12,7 +12,9 @@ print.gctx <- function(x, ...) { "", "\n", sep = "" ) } diff --git a/R/resolver.R b/R/resolver.R index 4a5a327..62cbc16 100644 --- a/R/resolver.R +++ b/R/resolver.R @@ -10,7 +10,7 @@ #' x <- gdns_context() #' x <- gdns_context("1.1.1.1") gdns_context <- function(resolvers = "9.9.9.9") { - int_gdns_resolver(resolvers) + int_gdns_context(resolvers) } #' Changes the list of resolvers in an already created context for use in resolution functions @@ -141,6 +141,7 @@ gdns_set_hosts<- function(gctx, hosts_file) { #' - `x25` #' - `zonemd` #' +#' @note Local hosts files are ignored when using this `getdns` API endpoint #' @param gctx gdns resolver context created with [gdns_resolver()] #' @param name an entity to query for #' @param rr_type what resource record type do you want to queyr for? See `Details`. diff --git a/R/set-res-types.R b/R/set-res-types.R new file mode 100644 index 0000000..3589eea --- /dev/null +++ b/R/set-res-types.R @@ -0,0 +1,21 @@ +.res_types <- c("stub" = 520L, "recursive" = 521L) + +#' Specify whether DNS queries are performed with recursive lookups or as a stub resolver +#' +#' @param gctx gdns resolver context created with [gdns_resolver()] +#' @param res_type length 1 character vector of either "`stub`" or "`recursive`" +#' @export +#' @examples +#' x <- gdns_context() +#' x <- gdns_set_resolution_type(x, "stub") +gdns_set_resolution_type <- function(gctx, res_type = c("stub", "recursive")) { + + match.arg( + unique(tolower(trimws(res_type))), c("stub", "recursive") + ) -> transports + + res_type <- unname(.res_types[res_type]) + + int_gdns_set_resolution_type(gctx, res_type) + +} diff --git a/R/set-transports.R b/R/set-transports.R new file mode 100644 index 0000000..633ae7d --- /dev/null +++ b/R/set-transports.R @@ -0,0 +1,24 @@ +.transport_trans <- c("tls" = 1202L, "tcp" = 1201L, "udp" = 1200L) + +#' Specifies what transport(s) is/ar used for DNS lookups +#' +#' @param gctx gdns resolver context created with [gdns_resolver()] +#' @param transports character vector of any/all of "`udp`", "`tcp`" or "`tls`". +#' Order matters as it specifies that the library will use to try to +#' perform the lookups. +#' @export +#' @examples +#' x <- gdns_context() +#' x <- gdns_set_transports(x, "tls") +gdns_set_transports <- function(gctx, transports = c("tls", "udp", "tcp")) { + + match.arg( + unique(tolower(trimws(transports))), c("tls", "udp", "tcp"), + several.ok = TRUE + ) -> transports + + transports <- unname(.transport_trans[transports]) + + int_gdns_set_transports(gctx, transports) + +} diff --git a/README.Rmd b/README.Rmd index 2761b98..62d8e52 100644 --- a/README.Rmd +++ b/README.Rmd @@ -14,7 +14,7 @@ options(width=120) # clandnstine -Perform 'DNS' over 'TLS' Queries +Perform Secure-by-default 'DNS' Queries ## Description @@ -35,7 +35,7 @@ I've gotten this running on macOS and Ubuntu 16.04. For the latter I had to ensu ## TODO/WAT -I finally grok the getdns api so the package api is going to change wildly and fast. It's only going to support DNS over TLS but will support all types of DNS queries. +I finally grok the getdns api so the package api is going to change wildly and fast. The default mode will be to perform queries using DNS over TLS but also supports UDP and TCP transports. ## Why? @@ -85,15 +85,22 @@ It's stupid slow, consumes more CPU and bandwidth but forces adversaries to work The following functions are implemented: - - `gdns_context`: Create a gdns DNS over TLS context and populate it with a resolver for use in resolution functions - `gdns_get_address`: Resolve a host to an addrss +- `gdns_get_resolution_type`: Get the current resolution type setting - `gdns_get_timeout`: Retreive the number of milliseconds to wait for request to return +- `gdns_get_tls_ca_file`: Retreive the file location with CA certificates for verification purposes +- `gdns_get_tls_ca_path`: Retreive the value with which the context's upstream recursive servers and suffixes were initialized +- `gdns_get_transports`: Retreive what transports are used for DNS lookups. - `gdns_lib_version`: Return gdns library version - `gdns_query`: Arbitrary DNS queries - `gdns_set_hosts`: Initialized the context's local names namespace with values from the given hosts file. +- `gdns_set_resolution_type`: Specify whether DNS queries are performed with recursive lookups or as a stub resolver - `gdns_set_round_robin_upstreams`: Set/unset context to round robin queries over the available upstreams when resolving with the stub resolution type. - `gdns_set_timeout`: Specify the number of milliseconds to wait for request to return +- `gdns_set_tls_ca_file`: Specify the file with CA certificates for verification purposes +- `gdns_set_tls_ca_path`: Specify where the location for CA certificates for verification purposes are located +- `gdns_set_transports`: Specifies what transport(s) is/ar used for DNS lookups - `gdns_update_resolvers`: Changes the list of resolvers in an already created context for use in resolution functions ## Installation @@ -129,6 +136,8 @@ gdns_lib_version() (gdns_update_resolvers(x, "1.1.1.1")) +(gdns_set_transports(x, c("udp", "tls", "tcp"))) + (gdns_get_address(x, "rud.is")) (gdns_get_address(x, "yahoo.com")) diff --git a/README.md b/README.md index 2c27161..540bf35 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Status](https://codecov.io/gh/hrbrmstr/clandnstine/branch/master/graph/badge.svg # clandnstine -Perform ‘DNS’ over ‘TLS’ Queries +Perform Secure-by-default ‘DNS’ Queries ## Description @@ -36,8 +36,8 @@ extract it and `config`/`make`/`make install` (plus `ldconfig` after). ## TODO/WAT I finally grok the getdns api so the package api is going to change -wildly and fast. It’s only going to support DNS over TLS but will -support all types of DNS queries. +wildly and fast. The default mode will be to perform queries using DNS +over TLS but also supports UDP and TCP transports. ## Why? @@ -114,17 +114,32 @@ The following functions are implemented: - `gdns_context`: Create a gdns DNS over TLS context and populate it with a resolver for use in resolution functions - `gdns_get_address`: Resolve a host to an addrss + - `gdns_get_resolution_type`: Get the current resolution type setting - `gdns_get_timeout`: Retreive the number of milliseconds to wait for request to return + - `gdns_get_tls_ca_file`: Retreive the file location with CA + certificates for verification purposes + - `gdns_get_tls_ca_path`: Retreive the value with which the context’s + upstream recursive servers and suffixes were initialized + - `gdns_get_transports`: Retreive what transports are used for DNS + lookups. - `gdns_lib_version`: Return gdns library version - `gdns_query`: Arbitrary DNS queries - `gdns_set_hosts`: Initialized the context’s local names namespace with values from the given hosts file. + - `gdns_set_resolution_type`: Specify whether DNS queries are + performed with recursive lookups or as a stub resolver - `gdns_set_round_robin_upstreams`: Set/unset context to round robin queries over the available upstreams when resolving with the stub resolution type. - `gdns_set_timeout`: Specify the number of milliseconds to wait for request to return + - `gdns_set_tls_ca_file`: Specify the file with CA certificates for + verification purposes + - `gdns_set_tls_ca_path`: Specify where the location for CA + certificates for verification purposes are located + - `gdns_set_transports`: Specifies what transport(s) is/ar used for + DNS lookups - `gdns_update_resolvers`: Changes the list of resolvers in an already created context for use in resolution functions @@ -153,27 +168,30 @@ gdns_lib_version() ## [1] "1.5.1" (x <- gdns_context()) -## +## (x <- gdns_context("1.1.1.1")) -## +## (x <- gdns_context(c("8.8.8.8", "1.1.1.1", "9.9.9.9"))) -## +## (gdns_set_timeout(x, 2000)) -## +## (gdns_update_resolvers(x, "1.1.1.1")) -## +## + +(gdns_set_transports(x, c("udp", "tls", "tcp"))) +## (gdns_get_address(x, "rud.is")) ## [1] "2604:a880:800:10::6bc:2001" "104.236.112.222" (gdns_get_address(x, "yahoo.com")) -## [1] "2001:4998:44:41d::4" "2001:4998:58:1836::10" "2001:4998:58:1836::11" "2001:4998:c:1023::4" -## [5] "2001:4998:c:1023::5" "2001:4998:44:41d::3" "98.138.219.232" "72.30.35.9" -## [9] "72.30.35.10" "98.137.246.7" "98.137.246.8" "98.138.219.231" +## [1] "2001:4998:58:1836::10" "2001:4998:58:1836::11" "2001:4998:c:1023::4" "2001:4998:c:1023::5" +## [5] "2001:4998:44:41d::3" "2001:4998:44:41d::4" "72.30.35.9" "72.30.35.10" +## [9] "98.137.246.7" "98.137.246.8" "98.138.219.231" "98.138.219.232" (gdns_get_address(x, "yahoo.commmm")) ## character(0) @@ -186,7 +204,7 @@ str(leno <- gdns_query(x, "lenovo.com", "txt"), 1) ## List of 5 ## $ answer_type : int 800 ## $ canonical_name: chr "lenovo.com." -## $ replies_full : int [1, 1:936] 55 119 129 128 0 1 0 8 0 0 ... +## $ replies_full : int [1, 1:600] 165 144 129 128 0 1 0 8 0 0 ... ## $ replies_tree :'data.frame': 1 obs. of 7 variables: ## $ status : int 900 ## - attr(*, "class")= chr [1:2] "gdns_response" "list" @@ -209,9 +227,9 @@ Yep. Advertising even in DNS `TXT` records (see item number | Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) | | :--- | -------: | ---: | --: | ---: | ----------: | ---: | -------: | ---: | -| C++ | 3 | 0.25 | 369 | 0.59 | 112 | 0.55 | 77 | 0.20 | -| R | 8 | 0.67 | 242 | 0.38 | 42 | 0.20 | 220 | 0.57 | -| Rmd | 1 | 0.08 | 18 | 0.03 | 51 | 0.25 | 89 | 0.23 | +| C++ | 3 | 0.21 | 608 | 0.65 | 196 | 0.62 | 138 | 0.27 | +| R | 10 | 0.71 | 306 | 0.33 | 68 | 0.22 | 280 | 0.54 | +| Rmd | 1 | 0.07 | 19 | 0.02 | 51 | 0.16 | 97 | 0.19 | ## Code of Conduct diff --git a/man/clandnstine.Rd b/man/clandnstine.Rd index 8e2bcf9..1c415e0 100644 --- a/man/clandnstine.Rd +++ b/man/clandnstine.Rd @@ -4,7 +4,7 @@ \name{clandnstine} \alias{clandnstine} \alias{clandnstine-package} -\title{Perform 'DNS' over 'TLS' Queries} +\title{Perform Secure-by-default 'DNS' Queries} \description{ Something something 'DNS. Something something 'TLS'. Something something 'getdns API/library'. diff --git a/man/gdns_get_hosts.Rd b/man/gdns_get_hosts.Rd new file mode 100644 index 0000000..86afe81 --- /dev/null +++ b/man/gdns_get_hosts.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/RcppExports.R +\name{gdns_get_hosts} +\alias{gdns_get_hosts} +\title{Retreive the value of the localnames namespace} +\usage{ +gdns_get_hosts(gctx) +} +\arguments{ +\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}} +} +\description{ +Retreive the value of the localnames namespace +} diff --git a/man/gdns_get_resolution_type.Rd b/man/gdns_get_resolution_type.Rd new file mode 100644 index 0000000..921125f --- /dev/null +++ b/man/gdns_get_resolution_type.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/RcppExports.R +\name{gdns_get_resolution_type} +\alias{gdns_get_resolution_type} +\title{Get the current resolution type setting} +\usage{ +gdns_get_resolution_type(gctx) +} +\arguments{ +\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}} +} +\description{ +Get the current resolution type setting +} +\examples{ +x <- gdns_context() +gdns_get_resolution_type(x) +} diff --git a/man/gdns_get_resolvconf.Rd b/man/gdns_get_resolvconf.Rd new file mode 100644 index 0000000..ed744e4 --- /dev/null +++ b/man/gdns_get_resolvconf.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/RcppExports.R +\name{gdns_get_resolvconf} +\alias{gdns_get_resolvconf} +\title{Retreive the value with which the context's upstream recursive servers and suffixes were initialized} +\usage{ +gdns_get_resolvconf(gctx) +} +\arguments{ +\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}} +} +\description{ +Retreive the value with which the context's upstream recursive servers and suffixes were initialized +} diff --git a/man/gdns_get_tls_ca_file.Rd b/man/gdns_get_tls_ca_file.Rd new file mode 100644 index 0000000..8dde46d --- /dev/null +++ b/man/gdns_get_tls_ca_file.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/RcppExports.R +\name{gdns_get_tls_ca_file} +\alias{gdns_get_tls_ca_file} +\title{Retreive the file location with CA certificates for verification purposes} +\usage{ +gdns_get_tls_ca_file(gctx) +} +\arguments{ +\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}} +} +\description{ +Retreive the file location with CA certificates for verification purposes +} diff --git a/man/gdns_get_tls_ca_path.Rd b/man/gdns_get_tls_ca_path.Rd new file mode 100644 index 0000000..9332b75 --- /dev/null +++ b/man/gdns_get_tls_ca_path.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/RcppExports.R +\name{gdns_get_tls_ca_path} +\alias{gdns_get_tls_ca_path} +\title{Retreive the value with which the context's upstream recursive servers and suffixes were initialized} +\usage{ +gdns_get_tls_ca_path(gctx) +} +\arguments{ +\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}} +} +\description{ +Retreive the value with which the context's upstream recursive servers and suffixes were initialized +} diff --git a/man/gdns_get_transports.Rd b/man/gdns_get_transports.Rd new file mode 100644 index 0000000..8c74007 --- /dev/null +++ b/man/gdns_get_transports.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/RcppExports.R +\name{gdns_get_transports} +\alias{gdns_get_transports} +\title{Retreive what transports are used for DNS lookups.} +\usage{ +gdns_get_transports(gctx) +} +\arguments{ +\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}} +} +\description{ +Retreive what transports are used for DNS lookups. +} diff --git a/man/gdns_query.Rd b/man/gdns_query.Rd index 1b2d54e..dbf8ffc 100644 --- a/man/gdns_query.Rd +++ b/man/gdns_query.Rd @@ -117,6 +117,9 @@ Valid values for \code{rr_type}: \item \code{zonemd} } } +\note{ +Local hosts files are ignored when using this \code{getdns} API endpoint +} \examples{ x <- gdns_resolver() gdns_query(x, "example.com") diff --git a/man/gdns_set_resolution_type.Rd b/man/gdns_set_resolution_type.Rd new file mode 100644 index 0000000..d779512 --- /dev/null +++ b/man/gdns_set_resolution_type.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/set-res-types.R +\name{gdns_set_resolution_type} +\alias{gdns_set_resolution_type} +\title{Specify whether DNS queries are performed with recursive lookups or as a stub resolver} +\usage{ +gdns_set_resolution_type(gctx, res_type = c("stub", "recursive")) +} +\arguments{ +\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}} + +\item{res_type}{length 1 character vector of either "\code{stub}" or "\code{recursive}"} +} +\description{ +Specify whether DNS queries are performed with recursive lookups or as a stub resolver +} +\examples{ +x <- gdns_context() +x <- gdns_set_resolution_type(x, "stub") +} diff --git a/man/gdns_set_tls_ca_file.Rd b/man/gdns_set_tls_ca_file.Rd new file mode 100644 index 0000000..2764bf4 --- /dev/null +++ b/man/gdns_set_tls_ca_file.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/RcppExports.R +\name{gdns_set_tls_ca_file} +\alias{gdns_set_tls_ca_file} +\title{Specify the file with CA certificates for verification purposes} +\usage{ +gdns_set_tls_ca_file(gctx, ca_file) +} +\arguments{ +\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}} + +\item{ca_file}{file with Certificate Authority certificates} +} +\description{ +Specify the file with CA certificates for verification purposes +} diff --git a/man/gdns_set_tls_ca_path.Rd b/man/gdns_set_tls_ca_path.Rd new file mode 100644 index 0000000..6e45044 --- /dev/null +++ b/man/gdns_set_tls_ca_path.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/RcppExports.R +\name{gdns_set_tls_ca_path} +\alias{gdns_set_tls_ca_path} +\title{Specify where the location for CA certificates for verification purposes are located} +\usage{ +gdns_set_tls_ca_path(gctx, ca_path) +} +\arguments{ +\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}} + +\item{ca_path}{directory with Certificate Authority certificates} +} +\description{ +Specify where the location for CA certificates for verification purposes are located +} diff --git a/man/gdns_set_transports.Rd b/man/gdns_set_transports.Rd new file mode 100644 index 0000000..8c60c44 --- /dev/null +++ b/man/gdns_set_transports.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/set-transports.R +\name{gdns_set_transports} +\alias{gdns_set_transports} +\title{Specifies what transport(s) is/ar used for DNS lookups} +\usage{ +gdns_set_transports(gctx, transports = c("tls", "udp", "tcp")) +} +\arguments{ +\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}} + +\item{transports}{character vector of any/all of "\code{udp}", "\code{tcp}" or "\code{tls}". +Order matters as it specifies that the library will use to try to +perform the lookups.} +} +\description{ +Specifies what transport(s) is/ar used for DNS lookups +} +\examples{ +x <- gdns_context() +x <- gdns_set_transports(x, "tls") +} diff --git a/man/int_gdns_context.Rd b/man/int_gdns_context.Rd new file mode 100644 index 0000000..44169fc --- /dev/null +++ b/man/int_gdns_context.Rd @@ -0,0 +1,12 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/RcppExports.R +\name{int_gdns_context} +\alias{int_gdns_context} +\title{Internal version of gdns_context} +\usage{ +int_gdns_context(resolvers) +} +\description{ +Internal version of gdns_context +} +\keyword{internal} diff --git a/man/int_gdns_resolver.Rd b/man/int_gdns_resolver.Rd deleted file mode 100644 index 8e6d908..0000000 --- a/man/int_gdns_resolver.Rd +++ /dev/null @@ -1,12 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/RcppExports.R -\name{int_gdns_resolver} -\alias{int_gdns_resolver} -\title{Internal version of gdns_resolver} -\usage{ -int_gdns_resolver(resolvers) -} -\description{ -Internal version of gdns_resolver -} -\keyword{internal} diff --git a/man/int_gdns_set_resolution_type.Rd b/man/int_gdns_set_resolution_type.Rd new file mode 100644 index 0000000..7ad1cd0 --- /dev/null +++ b/man/int_gdns_set_resolution_type.Rd @@ -0,0 +1,12 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/RcppExports.R +\name{int_gdns_set_resolution_type} +\alias{int_gdns_set_resolution_type} +\title{Internal version of gdns_set_resolution_type()} +\usage{ +int_gdns_set_resolution_type(gctx, res_type) +} +\description{ +Internal version of gdns_set_resolution_type() +} +\keyword{internal} diff --git a/man/int_gdns_set_transports.Rd b/man/int_gdns_set_transports.Rd new file mode 100644 index 0000000..f80e287 --- /dev/null +++ b/man/int_gdns_set_transports.Rd @@ -0,0 +1,12 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/RcppExports.R +\name{int_gdns_set_transports} +\alias{int_gdns_set_transports} +\title{Internal version of set_transports()} +\usage{ +int_gdns_set_transports(gctx, trans) +} +\description{ +Internal version of set_transports() +} +\keyword{internal} diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 34c2478..60f2d6a 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -74,6 +74,109 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// int_gdns_set_transports +SEXP int_gdns_set_transports(SEXP gctx, IntegerVector trans); +RcppExport SEXP _clandnstine_int_gdns_set_transports(SEXP gctxSEXP, SEXP transSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP); + Rcpp::traits::input_parameter< IntegerVector >::type trans(transSEXP); + rcpp_result_gen = Rcpp::wrap(int_gdns_set_transports(gctx, trans)); + return rcpp_result_gen; +END_RCPP +} +// int_gdns_set_resolution_type +SEXP int_gdns_set_resolution_type(SEXP gctx, int res_type); +RcppExport SEXP _clandnstine_int_gdns_set_resolution_type(SEXP gctxSEXP, SEXP res_typeSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP); + Rcpp::traits::input_parameter< int >::type res_type(res_typeSEXP); + rcpp_result_gen = Rcpp::wrap(int_gdns_set_resolution_type(gctx, res_type)); + return rcpp_result_gen; +END_RCPP +} +// gdns_get_transports +CharacterVector gdns_get_transports(SEXP gctx); +RcppExport SEXP _clandnstine_gdns_get_transports(SEXP gctxSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP); + rcpp_result_gen = Rcpp::wrap(gdns_get_transports(gctx)); + return rcpp_result_gen; +END_RCPP +} +// gdns_get_hosts +CharacterVector gdns_get_hosts(SEXP gctx); +RcppExport SEXP _clandnstine_gdns_get_hosts(SEXP gctxSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP); + rcpp_result_gen = Rcpp::wrap(gdns_get_hosts(gctx)); + return rcpp_result_gen; +END_RCPP +} +// gdns_get_resolvconf +CharacterVector gdns_get_resolvconf(SEXP gctx); +RcppExport SEXP _clandnstine_gdns_get_resolvconf(SEXP gctxSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP); + rcpp_result_gen = Rcpp::wrap(gdns_get_resolvconf(gctx)); + return rcpp_result_gen; +END_RCPP +} +// gdns_get_tls_ca_path +StringVector gdns_get_tls_ca_path(SEXP gctx); +RcppExport SEXP _clandnstine_gdns_get_tls_ca_path(SEXP gctxSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP); + rcpp_result_gen = Rcpp::wrap(gdns_get_tls_ca_path(gctx)); + return rcpp_result_gen; +END_RCPP +} +// gdns_get_tls_ca_file +StringVector gdns_get_tls_ca_file(SEXP gctx); +RcppExport SEXP _clandnstine_gdns_get_tls_ca_file(SEXP gctxSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP); + rcpp_result_gen = Rcpp::wrap(gdns_get_tls_ca_file(gctx)); + return rcpp_result_gen; +END_RCPP +} +// gdns_set_tls_ca_path +SEXP gdns_set_tls_ca_path(SEXP gctx, std::string ca_path); +RcppExport SEXP _clandnstine_gdns_set_tls_ca_path(SEXP gctxSEXP, SEXP ca_pathSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP); + Rcpp::traits::input_parameter< std::string >::type ca_path(ca_pathSEXP); + rcpp_result_gen = Rcpp::wrap(gdns_set_tls_ca_path(gctx, ca_path)); + return rcpp_result_gen; +END_RCPP +} +// gdns_set_tls_ca_file +SEXP gdns_set_tls_ca_file(SEXP gctx, std::string ca_file); +RcppExport SEXP _clandnstine_gdns_set_tls_ca_file(SEXP gctxSEXP, SEXP ca_fileSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP); + Rcpp::traits::input_parameter< std::string >::type ca_file(ca_fileSEXP); + rcpp_result_gen = Rcpp::wrap(gdns_set_tls_ca_file(gctx, ca_file)); + return rcpp_result_gen; +END_RCPP +} // check_is_xptr void check_is_xptr(SEXP s); RcppExport SEXP _clandnstine_check_is_xptr(SEXP sSEXP) { @@ -95,14 +198,14 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } -// int_gdns_resolver -SEXP int_gdns_resolver(std::vector< std::string > resolvers); -RcppExport SEXP _clandnstine_int_gdns_resolver(SEXP resolversSEXP) { +// int_gdns_context +SEXP int_gdns_context(std::vector< std::string > resolvers); +RcppExport SEXP _clandnstine_int_gdns_context(SEXP resolversSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< std::vector< std::string > >::type resolvers(resolversSEXP); - rcpp_result_gen = Rcpp::wrap(int_gdns_resolver(resolvers)); + rcpp_result_gen = Rcpp::wrap(int_gdns_context(resolvers)); return rcpp_result_gen; END_RCPP } @@ -143,6 +246,17 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// gdns_get_resolution_type +CharacterVector gdns_get_resolution_type(SEXP gctx); +RcppExport SEXP _clandnstine_gdns_get_resolution_type(SEXP gctxSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP); + rcpp_result_gen = Rcpp::wrap(gdns_get_resolution_type(gctx)); + return rcpp_result_gen; +END_RCPP +} static const R_CallMethodDef CallEntries[] = { {"_clandnstine_gdns_lib_version", (DL_FUNC) &_clandnstine_gdns_lib_version, 0}, @@ -151,12 +265,22 @@ static const R_CallMethodDef CallEntries[] = { {"_clandnstine_gdns_get_timeout", (DL_FUNC) &_clandnstine_gdns_get_timeout, 1}, {"_clandnstine_gdns_set_round_robin_upstreams", (DL_FUNC) &_clandnstine_gdns_set_round_robin_upstreams, 2}, {"_clandnstine_int_gdns_set_hosts", (DL_FUNC) &_clandnstine_int_gdns_set_hosts, 2}, + {"_clandnstine_int_gdns_set_transports", (DL_FUNC) &_clandnstine_int_gdns_set_transports, 2}, + {"_clandnstine_int_gdns_set_resolution_type", (DL_FUNC) &_clandnstine_int_gdns_set_resolution_type, 2}, + {"_clandnstine_gdns_get_transports", (DL_FUNC) &_clandnstine_gdns_get_transports, 1}, + {"_clandnstine_gdns_get_hosts", (DL_FUNC) &_clandnstine_gdns_get_hosts, 1}, + {"_clandnstine_gdns_get_resolvconf", (DL_FUNC) &_clandnstine_gdns_get_resolvconf, 1}, + {"_clandnstine_gdns_get_tls_ca_path", (DL_FUNC) &_clandnstine_gdns_get_tls_ca_path, 1}, + {"_clandnstine_gdns_get_tls_ca_file", (DL_FUNC) &_clandnstine_gdns_get_tls_ca_file, 1}, + {"_clandnstine_gdns_set_tls_ca_path", (DL_FUNC) &_clandnstine_gdns_set_tls_ca_path, 2}, + {"_clandnstine_gdns_set_tls_ca_file", (DL_FUNC) &_clandnstine_gdns_set_tls_ca_file, 2}, {"_clandnstine_check_is_xptr", (DL_FUNC) &_clandnstine_check_is_xptr, 1}, {"_clandnstine_is_null_xptr_", (DL_FUNC) &_clandnstine_is_null_xptr_, 1}, - {"_clandnstine_int_gdns_resolver", (DL_FUNC) &_clandnstine_int_gdns_resolver, 1}, + {"_clandnstine_int_gdns_context", (DL_FUNC) &_clandnstine_int_gdns_context, 1}, {"_clandnstine_gdns_get_address", (DL_FUNC) &_clandnstine_gdns_get_address, 2}, {"_clandnstine_int_get_resolvers", (DL_FUNC) &_clandnstine_int_get_resolvers, 1}, {"_clandnstine_int_gdns_query", (DL_FUNC) &_clandnstine_int_gdns_query, 4}, + {"_clandnstine_gdns_get_resolution_type", (DL_FUNC) &_clandnstine_gdns_get_resolution_type, 1}, {NULL, NULL, 0} }; diff --git a/src/clandnstine-main.cpp b/src/clandnstine-main.cpp index 0c39fa7..621b8be 100644 --- a/src/clandnstine-main.cpp +++ b/src/clandnstine-main.cpp @@ -13,7 +13,6 @@ std::string gdns_lib_version() { return(std::string(getdns_get_version())); } - //' Internal version of gdns_update_resolvers //' @keywords internal // [[Rcpp::export]] @@ -141,4 +140,236 @@ SEXP int_gdns_set_hosts(SEXP gctx, std::string hosts) { return(gctx); -} \ No newline at end of file +} + +//' Internal version of set_transports() +//' @keywords internal +// [[Rcpp::export]] +SEXP int_gdns_set_transports(SEXP gctx, IntegerVector trans) { + + check_is_xptr(gctx); + + getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx); + + if (gctx == NULL) return(R_NilValue); + + getdns_return_t r; + + getdns_transport_list_t tls_transport[trans.size()]; + for (int i=0; i resolvers) { +SEXP int_gdns_context(std::vector< std::string > resolvers) { bool ok = false; SEXP ptr; @@ -245,4 +245,33 @@ CharacterVector int_gdns_query(SEXP gctx, std::string name, uint16_t rr, if (ok) return(wrap(out)); else return(CharacterVector()); -} \ No newline at end of file +} + +//' Get the current resolution type setting +//' +//' @param gctx gdns resolver context created with [gdns_resolver()] +//' @export +//' @examples +//' x <- gdns_context() +//' gdns_get_resolution_type(x) +// [[Rcpp::export]] +CharacterVector gdns_get_resolution_type(SEXP gctx) { + + check_is_xptr(gctx); + + getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx); + + if (gctx == NULL) return(CharacterVector()); + + getdns_return_t r; + getdns_resolution_t res_type; + + if ((r = getdns_context_get_resolution_type(ctxt, &res_type))) { + Rf_error(getdns_get_errorstr_by_id(r)); + } + + std::string out = res_type == GETDNS_RESOLUTION_STUB ? "stub" : "recursive"; + + return(wrap(out)); + +} diff --git a/tests/testthat/test-clandnstine.R b/tests/testthat/test-clandnstine.R index 4c96c8b..a7b2392 100644 --- a/tests/testthat/test-clandnstine.R +++ b/tests/testthat/test-clandnstine.R @@ -3,12 +3,24 @@ test_that("basic wrapper works", { expect_is(gdns_lib_version(), "character") - r <- gns_context() + r <- gdns_context() + expect_is(r, "gctx") + + expect_is(gdns_lib_version(), "character") + + expect_equal(gdns_get_resolution_type(r), "stub") x <- gdns_get_address(r, "example.com") expect_true(all(c("2606:2800:220:1:248:1893:25c8:1946", "93.184.216.34") %in% x)) - r <- gdns_context(c("8.8.8.8", "1.1.1.1", "9.9.9.9")) + expect_error(gdns_set_timeout(x, 3000)) + + expect_is(gdns_update_resolvers(r, c("8.8.8.8", "1.1.1.1", "9.9.9.9")), "gctx") + expect_is(gdns_set_round_robin_upstreams(r, TRUE), "gctx") + expect_is(gdns_set_hosts(r, "/etc/hosts"), "gctx") + expect_is(gdns_set_timeout(r, 2000), "gctx") + + expect_error(gdns_set_hosts(r, "/etc/hostssss")) x <- gdns_get_address(r, "example.com") expect_true(all(c("2606:2800:220:1:248:1893:25c8:1946", "93.184.216.34") %in% x)) @@ -22,4 +34,13 @@ test_that("basic wrapper works", { expect_equal(x$canonical_name, "example.com.") expect_true(grepl("spf", unlist(x$replies_tree$answer[[1]]$rdata$txt_strings))) + expect_equal(gdns_get_transports(r), "tls") + expect_is(gdns_set_transports(r, c("udp", "tls")), "gctx") + expect_equal(gdns_get_transports(r), c("udp", "tls")) + + expect_true( + all(c("2606:2800:220:1:248:1893:25c8:1946", "93.184.216.34") %in% + gdns_get_address(r, "example.com")) + ) + })