X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Ftincctl.c;h=814800e8969c6c62c7060f26786789ef8fb63671;hp=38bc4cf77b00e7b52e326c75270a6850d5899658;hb=551cd19406a560d0d206bff5b4e9da064ec222b6;hpb=a9bdfb424e7a469d15156aa44bbe2fd0b8e28531 diff --git a/src/tincctl.c b/src/tincctl.c index 38bc4cf7..814800e8 100644 --- a/src/tincctl.c +++ b/src/tincctl.c @@ -22,17 +22,12 @@ #include "system.h" #include -#include -#include -#include -#include -#include - #include #include "xalloc.h" #include "protocol.h" #include "control_common.h" +#include "rsagen.h" /* The name this program was run with. */ char *program_name = NULL; @@ -192,56 +187,19 @@ FILE *ask_and_open(const char *filename, const char *what, const char *mode) { return r; } -/* This function prettyprints the key generation process */ - -static void indicator(int a, int b, void *p) { - switch (a) { - case 0: - fprintf(stderr, "."); - break; - - case 1: - fprintf(stderr, "+"); - break; - - case 2: - fprintf(stderr, "-"); - break; - - case 3: - switch (b) { - case 0: - fprintf(stderr, " p\n"); - break; - - case 1: - fprintf(stderr, " q\n"); - break; - - default: - fprintf(stderr, "?"); - } - break; - - default: - fprintf(stderr, "?"); - } -} - /* Generate a public/private RSA keypair, and ask for a file to store them in. */ static bool keygen(int bits) { - RSA *rsa_key; + rsa_t key; FILE *f; char *name = NULL; char *filename; fprintf(stderr, _("Generating %d bits keys:\n"), bits); - rsa_key = RSA_generate_key(bits, 0x10001, indicator, NULL); - if(!rsa_key) { + if(!rsa_generate(&key, bits, 0x10001)) { fprintf(stderr, _("Error during key generation!\n")); return false; } else @@ -261,7 +219,8 @@ static bool keygen(int bits) { if(ftell(f)) fprintf(stderr, _("Appending key to existing contents.\nMake sure only one key is stored in the file.\n")); - PEM_write_RSAPrivateKey(f, rsa_key, NULL, NULL, 0, NULL, NULL); + rsa_write_pem_private_key(&key, f); + fclose(f); free(filename); @@ -278,7 +237,8 @@ static bool keygen(int bits) { if(ftell(f)) fprintf(stderr, _("Appending key to existing contents.\nMake sure only one key is stored in the file.\n")); - PEM_write_RSAPublicKey(f, rsa_key); + rsa_write_pem_public_key(&key, f); + fclose(f); free(filename); @@ -292,7 +252,7 @@ static void make_names(void) { #ifdef HAVE_MINGW HKEY key; char installdir[1024] = ""; - long len = sizeof(installdir); + long len = sizeof installdir; #endif if(netname) @@ -360,7 +320,7 @@ static int send_ctl_request(int fd, enum request_type type, tinc_ctl_request_t req; int rv; struct iovec vector[2] = { - {&req, sizeof(req)}, + {&req, sizeof req}, {(void*) outdata, outdatalen} }; void *indata; @@ -425,7 +385,7 @@ static int send_ctl_request_cooked(int fd, enum request_type type, } if(buf != NULL) { - printf("%*s", buflen, buf); + printf("%*s", (int)buflen, buf); free(buf); } @@ -611,7 +571,7 @@ int main(int argc, char *argv[], char *envp[]) { } debuglevel = atoi(argv[optind+1]); return send_ctl_request_cooked(fd, REQ_SET_DEBUG, &debuglevel, - sizeof(debuglevel)) != -1; + sizeof debuglevel) != -1; } if(!strcasecmp(argv[optind], "retry")) {