- fprintf(stderr, _("Please copy the private key to tinc.conf and the\npublic key to your host configuration file:\n\n"));
- printf("PublicKey = %s\n", BN_bn2hex(rsa_key->n));
- printf("PrivateKey = %s\n", BN_bn2hex(rsa_key->d));
+ if(config && (cfg = get_config_val(config, config_name)))
+ asprintf(&filename, "%s/hosts/%s", confbase, cfg->data.ptr);
+ else
+ asprintf(&filename, "%s/rsa_key.priv");
+
+ if((f = ask_and_safe_open(filename, _("public RSA key"), "a")) == NULL)
+ return -1;
+
+ if(ftell(f))
+ fprintf(stderr, _("Appending key to existing contents.\nMake sure only one key is stored in the file."));
+
+ PEM_write_RSAPublicKey(f, rsa_key);
+ fclose(f);
+ free(filename);