git ssb

8+

cel / sbotc



Commit ded10ff5977b000c87f81dcae77b34ea8b5a98ca

Make shs cap key configurable

cel committed on 8/8/2017, 9:10:16 PM
Parent: 3b557d1cefdd37c0eaca05d064b97b564329a15d

Files changed

sbotc.1changed
sbotc.cchanged
sbotc.1View
@@ -7,8 +7,9 @@
77 .Nd Call a scuttlebot/secret-stack RPC method
88 .Sh SYNOPSIS
99 .Nm
1010 .Op Fl j
11 +.Op Fl a Ar cap
1112 .Op Fl s Ar host
1213 .Op Fl p Ar port
1314 .Op Fl k Ar key
1415 .Op Fl t Ar type
@@ -20,8 +21,11 @@
2021 .Sh OPTIONS
2122 .Bl -tag
2223 .It Fl j
2324 Send stdin data as JSON.
25 +.It Fl c Ar cap
26 +Capability key for secret-handshake. Default is SSB's capability key,
27 +.Li 1KHLiKZvAvjbY1ziZEHMXawbCEIM6qwjCDm3VYRan/s= .
2428 .It Fl s Ar host
2529 The hostname to connect to. Default is localhost.
2630 .It Fl p Ar port
2731 The port to connect to. Default is 8008.
@@ -61,13 +65,14 @@
6165 secret-handshake protocol.
6266 .It Pa ~/.ssb/manifest.json
6367 A map of method names to method types.
6468 .It Pa ~/.ssb/config
65-JSON file containing host and port to use if the
66-.Ar -s
69 +JSON file containing host, port, and SHS cap key to use if the
70 +.Ar -s ,
71 +.Ar -p
6772 or
68-.Ar -p
69-options are not given.
73 +.Ar -c
74 +options are not given, respectively.
7075 .El
7176 .Pp
7277 The base path
7378 .Dq ~/.ssb/
sbotc.cView
@@ -94,9 +94,9 @@
9494 0x08, 0x39, 0xb7, 0x55, 0x84, 0x5a, 0x9f, 0xfb
9595 };
9696
9797 static void usage() {
98- fputs("usage: sbotc [-j] [-s <host>] [-p <port>] [-k <key>] [-t <type>] "
98 + fputs("usage: sbotc [-j] [-a <cap>] [-s <host>] [-p <port>] [-k <key>] [-t <type>] "
9999 "<method> [<argument>...]\n", stderr);
100100 exit(EXIT_FAILURE);
101101 }
102102
@@ -758,12 +758,14 @@
758758 const char *key = NULL;
759759 const char *host = NULL;
760760 const char *port = "8008";
761761 const char *typestr = NULL, *methodstr;
762 + const char *shs_cap_key_str = NULL;
762763 size_t argument_len;
763764 unsigned char private_key[64];
764765 unsigned char public_key[32];
765766 unsigned char remote_key[32];
767 + unsigned char shs_cap_key[32];
766768 enum muxrpc_type type;
767769 enum pkt_type ptype = pkt_type_buffer;
768770 char method[256];
769771 char app_dir[_POSIX_PATH_MAX];
@@ -775,16 +777,19 @@
775777 len = read_file(config_buf, sizeof(config_buf), "%s/config", app_dir);
776778 if (len > 0) {
777779 ssize_t host_len = json_get_value(config_buf, "host", &host);
778780 ssize_t port_len = json_get_value(config_buf, "port", &port);
781 + ssize_t shs_cap_len = json_get_value(config_buf, "caps.shs", &shs_cap_key_str);
779782 if (host_len >= 0) ((char *)host)[host_len] = '\0';
780783 if (port_len >= 0) ((char *)port)[port_len] = '\0';
784 + if (shs_cap_len >= 0) ((char *)shs_cap_key_str)[shs_cap_len] = '\0';
781785 } else if (len < 0 && errno != ENOENT) {
782786 err(1, "failed to read config");
783787 }
784788
785789 for (i = 1; i < argc && (argv[i][0] == '-'); i++) {
786790 switch (argv[i][1]) {
791 + case 'c': shs_cap_key_str = argv[++i]; break;
787792 case 'j': ptype = pkt_type_json; break;
788793 case 's': host = argv[++i]; break;
789794 case 'k': key = argv[++i]; break;
790795 case 'p': port = argv[++i]; break;
@@ -793,8 +798,16 @@
793798 }
794799 }
795800 if (i < argc) methodstr = argv[i++]; else usage();
796801
802 + if (shs_cap_key_str) {
803 + rc = pubkey_decode(shs_cap_key_str, shs_cap_key);
804 + if (rc < 0) err(1, "unable to decode cap key '%s'", shs_cap_key_str);
805 + } else {
806 + memcpy(shs_cap_key, ssb_cap, 32);
807 + }
808 +
809 +
797810 argument_len = args_to_json_length(argc-i, argv+i);
798811 char argument[argument_len];
799812 rc = args_to_json(argument, sizeof(argument), argc-i, argv+i);
800813 if (rc < 0) errx(0, "unable to collect arguments");
@@ -834,9 +847,9 @@
834847 s = tcp_connect(host, port);
835848 if (s < 0) err(1, "tcp_connect");
836849
837850 struct boxs bs;
838- shs_connect(s, public_key, private_key, ssb_cap, remote_key, &bs);
851 + shs_connect(s, public_key, private_key, shs_cap_key, remote_key, &bs);
839852
840853 muxrpc_call(&bs, method, argument, type, typestr, 1);
841854
842855 switch (type) {

Built with git-ssb-web