sbotc.cView |
---|
94 | 94 … | 0x08, 0x39, 0xb7, 0x55, 0x84, 0x5a, 0x9f, 0xfb |
95 | 95 … | }; |
96 | 96 … | |
97 | 97 … | 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>] " |
99 | 99 … | "<method> [<argument>...]\n", stderr); |
100 | 100 … | exit(EXIT_FAILURE); |
101 | 101 … | } |
102 | 102 … | |
758 | 758 … | const char *key = NULL; |
759 | 759 … | const char *host = NULL; |
760 | 760 … | const char *port = "8008"; |
761 | 761 … | const char *typestr = NULL, *methodstr; |
| 762 … | + const char *shs_cap_key_str = NULL; |
762 | 763 … | size_t argument_len; |
763 | 764 … | unsigned char private_key[64]; |
764 | 765 … | unsigned char public_key[32]; |
765 | 766 … | unsigned char remote_key[32]; |
| 767 … | + unsigned char shs_cap_key[32]; |
766 | 768 … | enum muxrpc_type type; |
767 | 769 … | enum pkt_type ptype = pkt_type_buffer; |
768 | 770 … | char method[256]; |
769 | 771 … | char app_dir[_POSIX_PATH_MAX]; |
775 | 777 … | len = read_file(config_buf, sizeof(config_buf), "%s/config", app_dir); |
776 | 778 … | if (len > 0) { |
777 | 779 … | ssize_t host_len = json_get_value(config_buf, "host", &host); |
778 | 780 … | 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); |
779 | 782 … | if (host_len >= 0) ((char *)host)[host_len] = '\0'; |
780 | 783 … | if (port_len >= 0) ((char *)port)[port_len] = '\0'; |
| 784 … | + if (shs_cap_len >= 0) ((char *)shs_cap_key_str)[shs_cap_len] = '\0'; |
781 | 785 … | } else if (len < 0 && errno != ENOENT) { |
782 | 786 … | err(1, "failed to read config"); |
783 | 787 … | } |
784 | 788 … | |
785 | 789 … | for (i = 1; i < argc && (argv[i][0] == '-'); i++) { |
786 | 790 … | switch (argv[i][1]) { |
| 791 … | + case 'c': shs_cap_key_str = argv[++i]; break; |
787 | 792 … | case 'j': ptype = pkt_type_json; break; |
788 | 793 … | case 's': host = argv[++i]; break; |
789 | 794 … | case 'k': key = argv[++i]; break; |
790 | 795 … | case 'p': port = argv[++i]; break; |
793 | 798 … | } |
794 | 799 … | } |
795 | 800 … | if (i < argc) methodstr = argv[i++]; else usage(); |
796 | 801 … | |
| 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 … | + |
797 | 810 … | argument_len = args_to_json_length(argc-i, argv+i); |
798 | 811 … | char argument[argument_len]; |
799 | 812 … | rc = args_to_json(argument, sizeof(argument), argc-i, argv+i); |
800 | 813 … | if (rc < 0) errx(0, "unable to collect arguments"); |
834 | 847 … | s = tcp_connect(host, port); |
835 | 848 … | if (s < 0) err(1, "tcp_connect"); |
836 | 849 … | |
837 | 850 … | 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); |
839 | 852 … | |
840 | 853 … | muxrpc_call(&bs, method, argument, type, typestr, 1); |
841 | 854 … | |
842 | 855 … | switch (type) { |