Skip to content

Commit 9884e7f

Browse files
committed
fixes ncurl() 26 crypto error for secure sites using SNI
1 parent 2dfd439 commit 9884e7f

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* 'libmbedtls' is now built from source upon install so the package always has TLS support and uses the latest v3.2.1 release. Windows binaries also updated to include TLS support.
1313
* `nng_version()` now returns the 'Mbed TLS' library version number.
1414
* `device()` gains a confirmation prompt when running interactively for more safety.
15+
* Fixes issue with `ncurl()` that caused a 26 cryptography error with certain secure sites using SNI.
1516

1617
# nanonext 0.5.3
1718

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ aio
384384
#> < recvAio >
385385
#> - $data for message data
386386
aio$data |> str()
387-
#> num [1:100000000] 1.531 0.167 -0.689 -0.619 1.451 ...
387+
#> num [1:100000000] -1.531 1.139 -0.256 -0.362 0.17 ...
388388
```
389389

390390
As `call_aio()` is blocking and will wait for completion, an alternative
@@ -537,11 +537,11 @@ ncurl("https://httpbin.org/headers")
537537
#> [1] 7b 0a 20 20 22 68 65 61 64 65 72 73 22 3a 20 7b 0a 20 20 20 20 22 48 6f 73
538538
#> [26] 74 22 3a 20 22 68 74 74 70 62 69 6e 2e 6f 72 67 22 2c 20 0a 20 20 20 20 22
539539
#> [51] 58 2d 41 6d 7a 6e 2d 54 72 61 63 65 2d 49 64 22 3a 20 22 52 6f 6f 74 3d 31
540-
#> [76] 2d 36 33 30 65 38 33 36 38 2d 36 33 64 35 66 65 30 31 32 33 65 32 33 36 34
541-
#> [101] 32 34 37 30 35 62 35 63 30 22 0a 20 20 7d 0a 7d 0a
540+
#> [76] 2d 36 33 30 66 36 62 39 63 2d 30 39 35 66 35 66 35 31 37 66 38 32 37 61 35
541+
#> [101] 35 36 36 32 31 38 35 31 37 22 0a 20 20 7d 0a 7d 0a
542542
#>
543543
#> $data
544-
#> [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-630e8368-63d5fe0123e236424705b5c0\"\n }\n}\n"
544+
#> [1] "{\n \"headers\": {\n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-630f6b9c-095f5f517f827a5566218517\"\n }\n}\n"
545545
```
546546

547547
For advanced use, supports additional HTTP methods such as POST or PUT.
@@ -556,7 +556,7 @@ res
556556
#> - $raw for raw message
557557

558558
call_aio(res)$data
559-
#> [1] "{\n \"args\": {}, \n \"data\": \"{\\\"key\\\": \\\"value\\\"}\", \n \"files\": {}, \n \"form\": {}, \n \"headers\": {\n \"Authorization\": \"Bearer APIKEY\", \n \"Content-Length\": \"16\", \n \"Content-Type\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-630e8369-6dadfb4917077d153d623f45\"\n }, \n \"json\": {\n \"key\": \"value\"\n }, \n \"origin\": \"185.225.45.49\", \n \"url\": \"http://httpbin.org/post\"\n}\n"
559+
#> [1] "{\n \"args\": {}, \n \"data\": \"{\\\"key\\\": \\\"value\\\"}\", \n \"files\": {}, \n \"form\": {}, \n \"headers\": {\n \"Authorization\": \"Bearer APIKEY\", \n \"Content-Length\": \"16\", \n \"Content-Type\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"X-Amzn-Trace-Id\": \"Root=1-630f6b9c-0b5c391a11ad759e225b0401\"\n }, \n \"json\": {\n \"key\": \"value\"\n }, \n \"origin\": \"79.173.129.2\", \n \"url\": \"http://httpbin.org/post\"\n}\n"
560560
```
561561

562562
In this respect, it may be used as a performant and lightweight method
@@ -599,10 +599,10 @@ s |> send('{"action": "subscribe", "symbols": "EURUSD"}')
599599
#> [26] 73 79 6d 62 6f 6c 73 22 3a 20 22 45 55 52 55 53 44 22 7d 00
600600

601601
s |> recv(keep.raw = FALSE)
602-
#> [1] "{\"s\":\"EURUSD\",\"a\":1.0017,\"b\":1.0014,\"dc\":\"0.0639\",\"dd\":\"0.0006\",\"ppms\":false,\"t\":1661895535000}"
602+
#> [1] "{\"s\":\"EURUSD\",\"a\":1.00133,\"b\":1.00131,\"dc\":\"-0.1009\",\"dd\":\"-0.0010\",\"ppms\":false,\"t\":1661954973000}"
603603

604604
s |> recv(keep.raw = FALSE)
605-
#> [1] "{\"s\":\"EURUSD\",\"a\":1.0018,\"b\":1.0015,\"dc\":\"0.0739\",\"dd\":\"0.0007\",\"ppms\":false,\"t\":1661895540000}"
605+
#> [1] "{\"s\":\"EURUSD\",\"a\":1.00131,\"b\":1.00129,\"dc\":\"-0.1029\",\"dd\":\"-0.0010\",\"ppms\":false,\"t\":1661954974000}"
606606

607607
close(s)
608608
```

src/aio.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,8 @@ SEXP rnng_ncurl_aio(SEXP http, SEXP method, SEXP headers, SEXP data, SEXP ca_fil
675675
return mk_error(xc);
676676
}
677677
if (ca_file == R_NilValue) {
678-
if ((xc = nng_tls_config_auth_mode(handle->cfg, NNG_TLS_AUTH_MODE_NONE)) ||
678+
if ((xc = nng_tls_config_server_name(handle->cfg, handle->url->u_hostname)) ||
679+
(xc = nng_tls_config_auth_mode(handle->cfg, NNG_TLS_AUTH_MODE_NONE)) ||
679680
(xc = nng_http_client_set_tls(handle->cli, handle->cfg))) {
680681
nng_tls_config_free(handle->cfg);
681682
nng_aio_free(haio->aio);
@@ -688,8 +689,9 @@ SEXP rnng_ncurl_aio(SEXP http, SEXP method, SEXP headers, SEXP data, SEXP ca_fil
688689
return mk_error(xc);
689690
}
690691
} else {
691-
if ((xc = nng_tls_config_auth_mode(handle->cfg, NNG_TLS_AUTH_MODE_REQUIRED)) ||
692+
if ((xc = nng_tls_config_server_name(handle->cfg, handle->url->u_hostname)) ||
692693
(xc = nng_tls_config_ca_file(handle->cfg, CHAR(STRING_ELT(ca_file, 0)))) ||
694+
(xc = nng_tls_config_auth_mode(handle->cfg, NNG_TLS_AUTH_MODE_REQUIRED)) ||
693695
(xc = nng_http_client_set_tls(handle->cli, handle->cfg))) {
694696
nng_tls_config_free(handle->cfg);
695697
nng_aio_free(haio->aio);

src/utils.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ SEXP rnng_ncurl(SEXP http, SEXP method, SEXP headers, SEXP data, SEXP ca_file) {
222222
}
223223

224224
if (ca_file == R_NilValue) {
225-
if ((xc = nng_tls_config_auth_mode(cfg, NNG_TLS_AUTH_MODE_NONE)) ||
225+
if ((xc = nng_tls_config_server_name(cfg, url->u_hostname)) ||
226+
(xc = nng_tls_config_auth_mode(cfg, NNG_TLS_AUTH_MODE_NONE)) ||
226227
(xc = nng_http_client_set_tls(client, cfg))) {
227228
nng_tls_config_free(cfg);
228229
nng_aio_free(aio);
@@ -233,8 +234,9 @@ SEXP rnng_ncurl(SEXP http, SEXP method, SEXP headers, SEXP data, SEXP ca_file) {
233234
return mk_error(xc);
234235
}
235236
} else {
236-
if ((xc = nng_tls_config_auth_mode(cfg, NNG_TLS_AUTH_MODE_REQUIRED)) ||
237+
if ((xc = nng_tls_config_server_name(cfg, url->u_hostname)) ||
237238
(xc = nng_tls_config_ca_file(cfg, CHAR(STRING_ELT(ca_file, 0)))) ||
239+
(xc = nng_tls_config_auth_mode(cfg, NNG_TLS_AUTH_MODE_REQUIRED)) ||
238240
(xc = nng_http_client_set_tls(client, cfg))) {
239241
nng_tls_config_free(cfg);
240242
nng_aio_free(aio);
@@ -340,16 +342,18 @@ SEXP rnng_stream_dial(SEXP url, SEXP textframes, SEXP ca_file) {
340342
}
341343

342344
if (ca_file == R_NilValue) {
343-
if ((xc = nng_tls_config_auth_mode(cfg, NNG_TLS_AUTH_MODE_NONE)) ||
345+
if ((xc = nng_tls_config_server_name(cfg, up->u_hostname)) ||
346+
(xc = nng_tls_config_auth_mode(cfg, NNG_TLS_AUTH_MODE_NONE)) ||
344347
(xc = nng_stream_dialer_set_ptr(dp, NNG_OPT_TLS_CONFIG, cfg))) {
345348
nng_tls_config_free(cfg);
346349
nng_stream_dialer_free(dp);
347350
nng_url_free(up);
348351
return mk_error(xc);
349352
}
350353
} else {
351-
if ((xc = nng_tls_config_auth_mode(cfg, NNG_TLS_AUTH_MODE_REQUIRED)) ||
354+
if ((xc = nng_tls_config_server_name(cfg, up->u_hostname)) ||
352355
(xc = nng_tls_config_ca_file(cfg, CHAR(STRING_ELT(ca_file, 0)))) ||
356+
(xc = nng_tls_config_auth_mode(cfg, NNG_TLS_AUTH_MODE_REQUIRED)) ||
353357
(xc = nng_stream_dialer_set_ptr(dp, NNG_OPT_TLS_CONFIG, cfg))) {
354358
nng_tls_config_free(cfg);
355359
nng_stream_dialer_free(dp);
@@ -446,16 +450,18 @@ SEXP rnng_stream_listen(SEXP url, SEXP textframes, SEXP ca_file) {
446450
return mk_error(xc);
447451
}
448452
if (ca_file == R_NilValue) {
449-
if ((xc = nng_tls_config_auth_mode(cfg, NNG_TLS_AUTH_MODE_NONE)) ||
453+
if ((xc = nng_tls_config_server_name(cfg, up->u_hostname)) ||
454+
(xc = nng_tls_config_auth_mode(cfg, NNG_TLS_AUTH_MODE_NONE)) ||
450455
(xc = nng_stream_listener_set_ptr(lp, "tls-config", cfg))) {
451456
nng_tls_config_free(cfg);
452457
nng_stream_listener_free(lp);
453458
nng_url_free(up);
454459
return mk_error(xc);
455460
}
456461
} else {
457-
if ((xc = nng_tls_config_auth_mode(cfg, NNG_TLS_AUTH_MODE_REQUIRED)) ||
462+
if ((xc = nng_tls_config_server_name(cfg, up->u_hostname)) ||
458463
(xc = nng_tls_config_ca_file(cfg, CHAR(STRING_ELT(ca_file, 0)))) ||
464+
(xc = nng_tls_config_auth_mode(cfg, NNG_TLS_AUTH_MODE_REQUIRED)) ||
459465
(xc = nng_stream_listener_set_ptr(lp, "tls-config", cfg))) {
460466
nng_tls_config_free(cfg);
461467
nng_stream_listener_free(lp);

0 commit comments

Comments
 (0)