- fprintf(stderr, _("Generating %d bits keys:\n"), bits);
- rsa_key = RSA_generate_key(bits, 0xFFFF, indicator, NULL);
-
- if(!rsa_key) {
- fprintf(stderr, _("Error during key generation!\n"));
- return -1;
- } else
- fprintf(stderr, _("Done.\n"));
-
- get_config_string(lookup_config(config_tree, "Name"), &name);
-
- if(name)
- asprintf(&filename, "%s/hosts/%s", confbase, name);
- else
- asprintf(&filename, "%s/rsa_key.pub", confbase);
-
- f = ask_and_safe_open(filename, _("public RSA key"), "a");
-
- if(!f)
- return -1;
-
- 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);
- fclose(f);
- free(filename);
-
- asprintf(&filename, "%s/rsa_key.priv", confbase);
- f = ask_and_safe_open(filename, _("private RSA key"), "a");
-
- if(!f)
- return -1;
-
- 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);
- fclose(f);
- free(filename);
-
- return 0;
-}
-
-/*
- Set all files and paths according to netname
-*/
-void make_names(void)
-{
- if(netname) {
- if(!pidfilename)
- asprintf(&pidfilename, LOCALSTATEDIR "/run/tinc.%s.pid", netname);
- if(!logfilename)
- asprintf(&logfilename, LOCALSTATEDIR "/log/tinc.%s.log", netname);
-
- if(!confbase)
- asprintf(&confbase, "%s/tinc/%s", CONFDIR, netname);
- else
- logger(DEBUG_ALWAYS, LOG_INFO, _("Both netname and configuration directory given, using the latter..."));
-
- if(!identname)
- asprintf(&identname, "tinc.%s", netname);
- } else {
- if(!pidfilename)
- pidfilename = LOCALSTATEDIR "/run/tinc.pid";
- if(!logfilename)
- logfilename = LOCALSTATEDIR "/log/tinc.log";
-
- if(!confbase)
- asprintf(&confbase, "%s/tinc", CONFDIR);
-
- if(!identname)
- identname = "tinc";
- }