summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjsing <>2016-08-13 13:09:10 +0000
committerjsing <>2016-08-13 13:09:10 +0000
commit953fb160a74666f1e0eeadee53bcdcdf6fe32a13 (patch)
tree0193fc94f1a1509ca1e205f9b48de6fbe5d548c3 /src
parent38f2d99e3768c4c4ef734bdce72659cc2b781447 (diff)
downloadopenbsd-953fb160a74666f1e0eeadee53bcdcdf6fe32a13.tar.gz
openbsd-953fb160a74666f1e0eeadee53bcdcdf6fe32a13.tar.bz2
openbsd-953fb160a74666f1e0eeadee53bcdcdf6fe32a13.zip
Let libtls load the CA, certificate and key files for nc(1), now that it
does this at the time the tls_config_set_*_file() function is called. ok bluhm@
Diffstat (limited to 'src')
-rw-r--r--src/usr.bin/nc/netcat.c37
1 files changed, 15 insertions, 22 deletions
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c
index bb74bb6070..d30dd938f3 100644
--- a/src/usr.bin/nc/netcat.c
+++ b/src/usr.bin/nc/netcat.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: netcat.c,v 1.161 2016/07/30 22:04:04 halex Exp $ */ 1/* $OpenBSD: netcat.c,v 1.162 2016/08/13 13:09:10 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> 3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
4 * Copyright (c) 2015 Bob Beck. All rights reserved. 4 * Copyright (c) 2015 Bob Beck. All rights reserved.
@@ -104,12 +104,6 @@ int tls_cachanged; /* Using non-default CA file */
104int TLSopt; /* TLS options */ 104int TLSopt; /* TLS options */
105char *tls_expectname; /* required name in peer cert */ 105char *tls_expectname; /* required name in peer cert */
106char *tls_expecthash; /* required hash of peer cert */ 106char *tls_expecthash; /* required hash of peer cert */
107uint8_t *cacert;
108size_t cacertlen;
109uint8_t *privkey;
110size_t privkeylen;
111uint8_t *pubcert;
112size_t pubcertlen;
113 107
114int timeout = -1; 108int timeout = -1;
115int family = AF_UNSPEC; 109int family = AF_UNSPEC;
@@ -444,29 +438,22 @@ main(int argc, char *argv[])
444 } 438 }
445 439
446 if (usetls) { 440 if (usetls) {
447 if (Rflag && (cacert = tls_load_file(Rflag, &cacertlen, NULL)) == NULL)
448 errx(1, "unable to load root CA file %s", Rflag);
449 if (Cflag && (pubcert = tls_load_file(Cflag, &pubcertlen, NULL)) == NULL)
450 errx(1, "unable to load TLS certificate file %s", Cflag);
451 if (Kflag && (privkey = tls_load_file(Kflag, &privkeylen, NULL)) == NULL)
452 errx(1, "unable to load TLS key file %s", Kflag);
453
454 if (Pflag) { 441 if (Pflag) {
455 if (pledge("stdio inet dns tty", NULL) == -1) 442 if (pledge("stdio inet dns tty rpath", NULL) == -1)
456 err(1, "pledge"); 443 err(1, "pledge");
457 } else if (pledge("stdio inet dns", NULL) == -1) 444 } else if (pledge("stdio inet dns rpath", NULL) == -1)
458 err(1, "pledge"); 445 err(1, "pledge");
459 446
460 if (tls_init() == -1) 447 if (tls_init() == -1)
461 errx(1, "unable to initialize TLS"); 448 errx(1, "unable to initialize TLS");
462 if ((tls_cfg = tls_config_new()) == NULL) 449 if ((tls_cfg = tls_config_new()) == NULL)
463 errx(1, "unable to allocate TLS config"); 450 errx(1, "unable to allocate TLS config");
464 if (Rflag && tls_config_set_ca_mem(tls_cfg, cacert, cacertlen) == -1) 451 if (Rflag && tls_config_set_ca_file(tls_cfg, Rflag) == -1)
465 errx(1, "unable to set root CA file %s", Rflag); 452 errx(1, "%s", tls_config_error(tls_cfg));
466 if (Cflag && tls_config_set_cert_mem(tls_cfg, pubcert, pubcertlen) == -1) 453 if (Cflag && tls_config_set_cert_file(tls_cfg, Cflag) == -1)
467 errx(1, "unable to set TLS certificate file %s", Cflag); 454 errx(1, "%s", tls_config_error(tls_cfg));
468 if (Kflag && tls_config_set_key_mem(tls_cfg, privkey, privkeylen) == -1) 455 if (Kflag && tls_config_set_key_file(tls_cfg, Kflag) == -1)
469 errx(1, "unable to set TLS key file %s", Kflag); 456 errx(1, "%s", tls_config_error(tls_cfg));
470 if (TLSopt & TLS_LEGACY) { 457 if (TLSopt & TLS_LEGACY) {
471 tls_config_set_protocols(tls_cfg, TLS_PROTOCOLS_ALL); 458 tls_config_set_protocols(tls_cfg, TLS_PROTOCOLS_ALL);
472 tls_config_set_ciphers(tls_cfg, "all"); 459 tls_config_set_ciphers(tls_cfg, "all");
@@ -481,6 +468,12 @@ main(int argc, char *argv[])
481 "together"); 468 "together");
482 tls_config_insecure_noverifycert(tls_cfg); 469 tls_config_insecure_noverifycert(tls_cfg);
483 } 470 }
471
472 if (Pflag) {
473 if (pledge("stdio inet dns tty", NULL) == -1)
474 err(1, "pledge");
475 } else if (pledge("stdio inet dns", NULL) == -1)
476 err(1, "pledge");
484 } 477 }
485 if (lflag) { 478 if (lflag) {
486 struct tls *tls_cctx = NULL; 479 struct tls *tls_cctx = NULL;