Skip to content

Commit e5e8470

Browse files
committed
adapt ncurl and stream PEM file interface
1 parent 434cbf2 commit e5e8470

File tree

8 files changed

+35
-36
lines changed

8 files changed

+35
-36
lines changed

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#### New Features
44

55
* Implements `sha224()`, `sha256()`, `sha384()` and `sha512()` series of fast, optimised cryptographic hash and HMAC generation functions using the 'Mbed TLS' library.
6-
* `ncurl()` and `stream()` gain the argmument 'ca_file' for optionally specifying a certificate authority certificate chain file when connecting to secure sites.
6+
* `ncurl()` and `stream()` gain the argmument 'pem' for optionally specifying a certificate authority certificate chain PEM file for authenticating secure sites.
77
* `ncurl()` now returns an additional `$status` field.
88
* `messenger()` gains the argument 'auth' for authenticating communications based on a pre-shared key.
99
* `random()` gains the argument 'n' for generating a vector of random numbers.

R/ncurl.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
#' HTTP request headers e.g. \code{list(`Content-Type` = "text/plain")} or
3030
#' \code{c(Authorization = "Bearer APIKEY")}.
3131
#' @param data (optional) the request data to be submitted.
32-
#' @param ca_file (optional) applicable to secure HTTPS sites only. The path to
33-
#' a file containing X.509 certificate(s) in PEM format, comprising the
34-
#' certificate authority certificate chain. If missing or NULL, certificates
35-
#' are not validated.
32+
#' @param pem (optional) applicable to secure HTTPS sites only. The path to a
33+
#' file containing X.509 certificate(s) in PEM format, comprising the
34+
#' certificate authority certificate chain (and revocation list if present).
35+
#' If missing or NULL, certificates are not validated.
3636
#'
3737
#' @return Named list of 3 elements:
3838
#' \itemize{
@@ -70,13 +70,13 @@ ncurl <- function(url,
7070
method = NULL,
7171
headers = NULL,
7272
data = NULL,
73-
ca_file = NULL) {
73+
pem = NULL) {
7474

7575
data <- if (!missing(data)) writeBin(object = data, con = raw())
7676

7777
if (async) {
7878

79-
aio <- .Call(rnng_ncurl_aio, url, method, headers, data, ca_file)
79+
aio <- .Call(rnng_ncurl_aio, url, method, headers, data, pem)
8080
is.integer(aio) && return(aio)
8181

8282
convert <- missing(convert) || isTRUE(convert)
@@ -136,7 +136,7 @@ ncurl <- function(url,
136136

137137
} else {
138138

139-
res <- .Call(rnng_ncurl, url, convert, method, headers, data, ca_file)
139+
res <- .Call(rnng_ncurl, url, convert, method, headers, data, pem)
140140

141141
is.integer(res) && return(res)
142142
is.character(res) && {

R/stream.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
#' (not all transports are supported).
3232
#' @param textframes [default FALSE] applicable to the websocket transport only,
3333
#' enables sending and receiving of TEXT frames (ignored otherwise).
34-
#' @param ca_file (optional) applicable to secure websockets only. The path to a
34+
#' @param pem (optional) applicable to secure websockets only. The path to a
3535
#' file containing X.509 certificate(s) in PEM format, comprising the
36-
#' certificate authority certificate chain. If missing or NULL, certificates
37-
#' are not validated.
36+
#' certificate authority certificate chain (and revocation list if present).
37+
#' If missing or NULL, certificates are not validated.
3838
#'
3939
#' @return A Stream (object of class 'nanoStream' and 'nano').
4040
#'
@@ -54,16 +54,16 @@
5454
#'
5555
#' @export
5656
#'
57-
stream <- function(dial = NULL, listen = NULL, textframes = FALSE, ca_file = NULL) {
57+
stream <- function(dial = NULL, listen = NULL, textframes = FALSE, pem = NULL) {
5858

5959
if (missing(dial)) {
6060
if (missing(listen)) {
6161
stop("specify a URL for either 'dial' or 'listen'")
6262
} else {
63-
.Call(rnng_stream_listen, listen, textframes, ca_file)
63+
.Call(rnng_stream_listen, listen, textframes, pem)
6464
}
6565
} else {
66-
.Call(rnng_stream_dial, dial, textframes, ca_file)
66+
.Call(rnng_stream_dial, dial, textframes, pem)
6767
}
6868

6969
}

man/ncurl.Rd

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/stream.Rd

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/aio.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ SEXP rnng_stream_send_aio(SEXP stream, SEXP data, SEXP timeout) {
542542

543543
// ncurl aio -------------------------------------------------------------------
544544

545-
SEXP rnng_ncurl_aio(SEXP http, SEXP method, SEXP headers, SEXP data, SEXP ca_file) {
545+
SEXP rnng_ncurl_aio(SEXP http, SEXP method, SEXP headers, SEXP data, SEXP pem) {
546546

547547
const char *httr = CHAR(STRING_ELT(http, 0));
548548
nano_aio *haio = R_Calloc(1, nano_aio);
@@ -674,7 +674,7 @@ SEXP rnng_ncurl_aio(SEXP http, SEXP method, SEXP headers, SEXP data, SEXP ca_fil
674674
R_Free(haio);
675675
return mk_error(xc);
676676
}
677-
if (ca_file == R_NilValue) {
677+
if (pem == R_NilValue) {
678678
if ((xc = nng_tls_config_server_name(handle->cfg, handle->url->u_hostname)) ||
679679
(xc = nng_tls_config_auth_mode(handle->cfg, NNG_TLS_AUTH_MODE_NONE)) ||
680680
(xc = nng_http_client_set_tls(handle->cli, handle->cfg))) {
@@ -690,7 +690,7 @@ SEXP rnng_ncurl_aio(SEXP http, SEXP method, SEXP headers, SEXP data, SEXP ca_fil
690690
}
691691
} else {
692692
if ((xc = nng_tls_config_server_name(handle->cfg, handle->url->u_hostname)) ||
693-
(xc = nng_tls_config_ca_file(handle->cfg, CHAR(STRING_ELT(ca_file, 0)))) ||
693+
(xc = nng_tls_config_ca_file(handle->cfg, CHAR(STRING_ELT(pem, 0)))) ||
694694
(xc = nng_tls_config_auth_mode(handle->cfg, NNG_TLS_AUTH_MODE_REQUIRED)) ||
695695
(xc = nng_http_client_set_tls(handle->cli, handle->cfg))) {
696696
nng_tls_config_free(handle->cfg);

src/core.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,6 @@ SEXP rnng_listener_close(SEXP listener) {
748748
}
749749

750750
// send and recv ---------------------------------------------------------------
751-
// nng flags: bitmask of NNG_FLAG_ALLOC = 1u + NNG_FLAG_NONBLOCK = 2u
752751

753752
SEXP rnng_send(SEXP socket, SEXP data, SEXP block, SEXP echo) {
754753

src/utils.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ SEXP rnng_random(SEXP n) {
117117

118118
// ncurl - minimalist http client ----------------------------------------------
119119

120-
SEXP rnng_ncurl(SEXP http, SEXP convert, SEXP method, SEXP headers, SEXP data, SEXP ca_file) {
120+
SEXP rnng_ncurl(SEXP http, SEXP convert, SEXP method, SEXP headers, SEXP data, SEXP pem) {
121121

122122
nng_url *url;
123123
nng_http_client *client;
@@ -222,7 +222,7 @@ SEXP rnng_ncurl(SEXP http, SEXP convert, SEXP method, SEXP headers, SEXP data, S
222222
return mk_error(xc);
223223
}
224224

225-
if (ca_file == R_NilValue) {
225+
if (pem == R_NilValue) {
226226
if ((xc = nng_tls_config_server_name(cfg, url->u_hostname)) ||
227227
(xc = nng_tls_config_auth_mode(cfg, NNG_TLS_AUTH_MODE_NONE)) ||
228228
(xc = nng_http_client_set_tls(client, cfg))) {
@@ -236,7 +236,7 @@ SEXP rnng_ncurl(SEXP http, SEXP convert, SEXP method, SEXP headers, SEXP data, S
236236
}
237237
} else {
238238
if ((xc = nng_tls_config_server_name(cfg, url->u_hostname)) ||
239-
(xc = nng_tls_config_ca_file(cfg, CHAR(STRING_ELT(ca_file, 0)))) ||
239+
(xc = nng_tls_config_ca_file(cfg, CHAR(STRING_ELT(pem, 0)))) ||
240240
(xc = nng_tls_config_auth_mode(cfg, NNG_TLS_AUTH_MODE_REQUIRED)) ||
241241
(xc = nng_http_client_set_tls(client, cfg))) {
242242
nng_tls_config_free(cfg);
@@ -320,7 +320,7 @@ SEXP rnng_ncurl(SEXP http, SEXP convert, SEXP method, SEXP headers, SEXP data, S
320320

321321
// streams ---------------------------------------------------------------------
322322

323-
SEXP rnng_stream_dial(SEXP url, SEXP textframes, SEXP ca_file) {
323+
SEXP rnng_stream_dial(SEXP url, SEXP textframes, SEXP pem) {
324324

325325
const char *add = CHAR(STRING_ELT(url, 0));
326326
const int mod = LOGICAL(textframes)[0];
@@ -360,7 +360,7 @@ SEXP rnng_stream_dial(SEXP url, SEXP textframes, SEXP ca_file) {
360360
return mk_error(xc);
361361
}
362362

363-
if (ca_file == R_NilValue) {
363+
if (pem == R_NilValue) {
364364
if ((xc = nng_tls_config_server_name(cfg, up->u_hostname)) ||
365365
(xc = nng_tls_config_auth_mode(cfg, NNG_TLS_AUTH_MODE_NONE)) ||
366366
(xc = nng_stream_dialer_set_ptr(dp, NNG_OPT_TLS_CONFIG, cfg))) {
@@ -371,7 +371,7 @@ SEXP rnng_stream_dial(SEXP url, SEXP textframes, SEXP ca_file) {
371371
}
372372
} else {
373373
if ((xc = nng_tls_config_server_name(cfg, up->u_hostname)) ||
374-
(xc = nng_tls_config_ca_file(cfg, CHAR(STRING_ELT(ca_file, 0)))) ||
374+
(xc = nng_tls_config_ca_file(cfg, CHAR(STRING_ELT(pem, 0)))) ||
375375
(xc = nng_tls_config_auth_mode(cfg, NNG_TLS_AUTH_MODE_REQUIRED)) ||
376376
(xc = nng_stream_dialer_set_ptr(dp, NNG_OPT_TLS_CONFIG, cfg))) {
377377
nng_tls_config_free(cfg);
@@ -429,7 +429,7 @@ SEXP rnng_stream_dial(SEXP url, SEXP textframes, SEXP ca_file) {
429429

430430
}
431431

432-
SEXP rnng_stream_listen(SEXP url, SEXP textframes, SEXP ca_file) {
432+
SEXP rnng_stream_listen(SEXP url, SEXP textframes, SEXP pem) {
433433

434434
const char *add = CHAR(STRING_ELT(url, 0));
435435
const int mod = LOGICAL(textframes)[0];
@@ -468,7 +468,7 @@ SEXP rnng_stream_listen(SEXP url, SEXP textframes, SEXP ca_file) {
468468
nng_url_free(up);
469469
return mk_error(xc);
470470
}
471-
if (ca_file == R_NilValue) {
471+
if (pem == R_NilValue) {
472472
if ((xc = nng_tls_config_server_name(cfg, up->u_hostname)) ||
473473
(xc = nng_tls_config_auth_mode(cfg, NNG_TLS_AUTH_MODE_NONE)) ||
474474
(xc = nng_stream_listener_set_ptr(lp, "tls-config", cfg))) {
@@ -479,7 +479,7 @@ SEXP rnng_stream_listen(SEXP url, SEXP textframes, SEXP ca_file) {
479479
}
480480
} else {
481481
if ((xc = nng_tls_config_server_name(cfg, up->u_hostname)) ||
482-
(xc = nng_tls_config_ca_file(cfg, CHAR(STRING_ELT(ca_file, 0)))) ||
482+
(xc = nng_tls_config_ca_file(cfg, CHAR(STRING_ELT(pem, 0)))) ||
483483
(xc = nng_tls_config_auth_mode(cfg, NNG_TLS_AUTH_MODE_REQUIRED)) ||
484484
(xc = nng_stream_listener_set_ptr(lp, "tls-config", cfg))) {
485485
nng_tls_config_free(cfg);

0 commit comments

Comments
 (0)