2 sptps_test.c -- Simple Peer-to-Peer Security test program
3 Copyright (C) 2011-2022 Guus Sliepen <guus@tinc-vpn.org>,
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 void logger(debug_t level, int priority, const char *format, ...) {
34 vfprintf(stderr, format, ap);
40 static void usage(void) {
41 fprintf(stderr, "Usage: %s [options] private_key_file public_key_file\n\n", program_name);
42 fprintf(stderr, "Valid options are:\n"
43 " --help Display this help and exit.\n"
45 fprintf(stderr, "Report bugs to tinc@tinc-vpn.org.\n");
48 typedef enum option_t {
55 static struct option const long_options[] = {
56 {"help", no_argument, NULL, OPT_HELP},
60 static int generate_keypair(char *argv[]) {
61 ecdsa_t *key = ecdsa_generate();
67 FILE *fp = fopen(argv[1], "w");
70 if(!ecdsa_write_pem_private_key(key, fp)) {
71 fprintf(stderr, "Could not write ECDSA private key\n");
78 fprintf(stderr, "Could not open '%s' for writing: %s\n", argv[1], strerror(errno));
83 fp = fopen(argv[2], "w");
86 if(!ecdsa_write_pem_public_key(key, fp)) {
87 fprintf(stderr, "Could not write ECDSA public key\n");
94 fprintf(stderr, "Could not open '%s' for writing: %s\n", argv[2], strerror(errno));
100 int main(int argc, char *argv[]) {
101 program_name = argv[0];
103 int option_index = 0;
105 while((r = getopt_long(argc, argv, "", long_options, &option_index)) != EOF) {
106 switch((option_t) r) {
107 case OPT_LONG_OPTION:
127 fprintf(stderr, "Wrong number of arguments.\n");
135 int result = generate_keypair(argv);