From fcfbe8a14c2a376d84e8f17be123a57373558071 Mon Sep 17 00:00:00 2001 From: C. McEnroe Date: Thu, 13 Feb 2020 01:39:25 -0500 Subject: Add -g for generating certificates Copied from pounce. --- chat.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'chat.c') diff --git a/chat.c b/chat.c index 284302d..c142bc9 100644 --- a/chat.c +++ b/chat.c @@ -25,12 +25,32 @@ #include #include #include +#include #include #include #include #include "chat.h" +#ifndef OPENSSL_BIN +#define OPENSSL_BIN "openssl" +#endif + +static void genCert(const char *path) { + const char *name = strrchr(path, '/'); + name = (name ? &name[1] : path); + char subj[256]; + snprintf(subj, sizeof(subj), "/CN=%.*s", (int)strcspn(name, "."), name); + umask(0066); + execlp( + OPENSSL_BIN, "openssl", "req", + "-x509", "-new", "-newkey", "rsa:4096", "-sha256", "-days", "3650", + "-nodes", "-subj", subj, "-out", path, "-keyout", path, + NULL + ); + err(EX_UNAVAILABLE, "openssl"); +} + char *idNames[IDCap] = { [None] = "", [Debug] = "", @@ -94,7 +114,7 @@ int main(int argc, char *argv[]) { const char *user = NULL; const char *real = NULL; - const char *Opts = "!C:H:N:O:RS:a:c:eh:j:k:n:p:r:s:u:vw:"; + const char *Opts = "!C:H:N:O:RS:a:c:eg:h:j:k:n:p:r:s:u:vw:"; const struct option LongOpts[] = { { "insecure", no_argument, NULL, '!' }, { "copy", required_argument, NULL, 'C' }, @@ -132,6 +152,7 @@ int main(int argc, char *argv[]) { break; case 'a': sasl = true; self.plain = optarg; break; case 'c': cert = optarg; break; case 'e': sasl = true; + break; case 'g': genCert(optarg); break; case 'h': host = optarg; break; case 'j': self.join = optarg; break; case 'k': priv = optarg; -- cgit 1.4.1-2-gfad0