about summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--catgirl.111
-rw-r--r--chat.c10
-rw-r--r--chat.h2
-rw-r--r--irc.c15
4 files changed, 14 insertions, 24 deletions
diff --git a/catgirl.1 b/catgirl.1
index 9c8bb32..35e984d 100644
--- a/catgirl.1
+++ b/catgirl.1
@@ -30,10 +30,10 @@
 .Op Ar config ...
 .
 .Nm
+.Fl o
 .Op Fl S Ar bind
 .Op Fl h Ar host
 .Op Fl p Ar port
-.Fl o Ar chain
 .Op Ar config ...
 .
 .Nm
@@ -224,10 +224,9 @@ Set nickname to
 .Ar nick .
 The default nickname is the user's name.
 .
-.It Fl o Ar chain
-Write the server certificate chain
-in PEM format to
-.Ar chain
+.It Fl o
+Print the server certificate chain
+to standard output in PEM format
 and exit.
 .
 .It Fl p Ar port , Cm port = Ar port
@@ -318,7 +317,7 @@ sasl-external
 Connect to the server
 and write its certificate to a file:
 .Bd -literal -offset indent
-catgirl -h irc.example.org -o ~/.config/catgirl/example.pem
+catgirl -o -h irc.example.org > ~/.config/catgirl/example.pem
 .Ed
 .It
 Configure
diff --git a/chat.c b/chat.c
index 99a529c..3f020fd 100644
--- a/chat.c
+++ b/chat.c
@@ -137,10 +137,10 @@ int main(int argc, char *argv[]) {
 #endif
 
 	bool insecure = false;
+	bool printCert = false;
 	const char *bind = NULL;
 	const char *host = NULL;
 	const char *port = "6697";
-	const char *chain = NULL;
 	const char *trust = NULL;
 	const char *cert = NULL;
 	const char *priv = NULL;
@@ -169,7 +169,7 @@ int main(int argc, char *argv[]) {
 		{ .val = 'k', .name = "priv", required_argument },
 		{ .val = 'l', .name = "log", no_argument },
 		{ .val = 'n', .name = "nick", required_argument },
-		{ .val = 'o', .name = "write-chain", required_argument },
+		{ .val = 'o', .name = "print-chain", no_argument },
 		{ .val = 'p', .name = "port", required_argument },
 		{ .val = 'r', .name = "real", required_argument },
 		{ .val = 's', .name = "save", required_argument },
@@ -204,7 +204,7 @@ int main(int argc, char *argv[]) {
 			break; case 'k': priv = optarg;
 			break; case 'l': logEnable = true;
 			break; case 'n': nick = optarg;
-			break; case 'o': insecure = true; chain = optarg;
+			break; case 'o': insecure = true; printCert = true;
 			break; case 'p': port = optarg;
 			break; case 'r': real = optarg;
 			break; case 's': save = optarg;
@@ -238,9 +238,9 @@ int main(int argc, char *argv[]) {
 	commandCompleteAdd();
 
 	ircConfig(insecure, trust, cert, priv);
-	if (chain) {
+	if (printCert) {
 		ircConnect(bind, host, port);
-		ircWriteChain(chain);
+		ircPrintCert();
 		ircClose();
 		return EX_OK;
 	}
diff --git a/chat.h b/chat.h
index 34c450f..41a3683 100644
--- a/chat.h
+++ b/chat.h
@@ -226,7 +226,7 @@ void ircConfig(
 	bool insecure, const char *trust, const char *cert, const char *priv
 );
 int ircConnect(const char *bind, const char *host, const char *port);
-void ircWriteChain(const char *path);
+void ircPrintCert(void);
 void ircRecv(void);
 void ircSend(const char *ptr, size_t len);
 void ircFormat(const char *format, ...)
diff --git a/irc.c b/irc.c
index cbe1808..c98193a 100644
--- a/irc.c
+++ b/irc.c
@@ -160,20 +160,11 @@ int ircConnect(const char *bindHost, const char *host, const char *port) {
 	return sock;
 }
 
-void ircWriteChain(const char *path) {
-	FILE *file = fopen(path, "w");
-	if (!file) err(EX_CANTCREAT, "%s", path);
-
-	int n = fprintf(file, "subject= %s\n", tls_peer_cert_subject(client));
-	if (n < 0) err(EX_IOERR, "%s", path);
-
+void ircPrintCert(void) {
 	size_t len;
 	const byte *pem = tls_peer_cert_chain_pem(client, &len);
-	len = fwrite(pem, len, 1, file);
-	if (!len) err(EX_IOERR, "%s", path);
-
-	int error = fclose(file);
-	if (error) err(EX_IOERR, "%s", path);
+	printf("subject= %s\n", tls_peer_cert_subject(client));
+	fwrite(pem, len, 1, stdout);
 }
 
 enum { MessageCap = 8191 + 512 };