Print chain to stdout with -o

master
C. McEnroe 2021-01-10 18:00:41 -05:00
parent cdff668d8f
commit c6cd90c2dd
4 changed files with 14 additions and 24 deletions

View File

@ -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

10
chat.c
View File

@ -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;
}

2
chat.h
View File

@ -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, ...)

15
irc.c
View File

@ -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 };