sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit f38d666a09182e73b3a20395c6a9e874b61efb1d
parent 05132d203391ae45522eac2e8b976864e443474a
Author: Jan Klemkow <j.klemkow@wemelug.de>
Date:   Sun, 16 Oct 2022 22:16:21 +0200

ii: add patch for libtls support

Diffstat:
Atools.suckless.org/ii/patches/tls/ii-2.0-tls.diff | 143+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools.suckless.org/ii/patches/tls/index.md | 15+++++++++++++++
2 files changed, 158 insertions(+), 0 deletions(-)

diff --git a/tools.suckless.org/ii/patches/tls/ii-2.0-tls.diff b/tools.suckless.org/ii/patches/tls/ii-2.0-tls.diff @@ -0,0 +1,143 @@ +commit fbe27f507fa28ffabe1c777285cfafde2b5b6f5a +Author: Jan Klemkow <j.klemkow@wemelug.de> +Date: Sun Oct 16 22:10:00 2022 +0200 + + Use libtls to encrypt connections. + +diff --git a/Makefile b/Makefile +index 28c7781..8c19387 100644 +--- a/Makefile ++++ b/Makefile +@@ -12,7 +12,7 @@ OBJ = $(SRC:.c=.o) + + # use system flags. + II_CFLAGS = $(CFLAGS) +-II_LDFLAGS = $(LDFLAGS) ++II_LDFLAGS = $(LDFLAGS) -ltls + + # on systems which provide strlcpy(3), + # remove NEED_STRLCPY from CPPFLAGS and +diff --git a/ii.1 b/ii.1 +index 59fd798..9f5d93c 100644 +--- a/ii.1 ++++ b/ii.1 +@@ -3,6 +3,7 @@ + ii - irc it or irc improved + .SH SYNOPSIS + .B ii ++.RB [ -t ] + .B -s + .I host + .RB [ -p +@@ -34,6 +35,9 @@ For example if you will join a channel just do echo "/j #channel" > in + and ii creates a new channel directory with in and out file. + .SH OPTIONS + .TP ++.BI -t ++TLS encrypted connection ++.TP + .BI -s " host" + server/host to connect to, for example: irc.freenode.net + .TP +diff --git a/ii.c b/ii.c +index c402a87..86ad918 100644 +--- a/ii.c ++++ b/ii.c +@@ -20,6 +20,9 @@ + #include <time.h> + #include <unistd.h> + ++#include <tls.h> ++struct tls *tls = NULL; ++int ircfd; + char *argv0; + + #include "arg.h" +@@ -101,7 +104,7 @@ die(const char *fmt, ...) + static void + usage(void) + { +- die("usage: %s -s host [-p port | -u sockname] [-i ircdir]\n" ++ die("usage: %s [-t] -s host [-p port | -u sockname] [-i ircdir]\n" + " [-n nickname] [-f fullname] [-k env_pass]\n", argv0); + } + +@@ -113,11 +116,17 @@ ewritestr(int fd, const char *s) + + len = strlen(s); + for (off = 0; off < len; off += w) { +- if ((w = write(fd, s + off, len - off)) == -1) ++ if (tls && (w = tls_write(tls, s + off, len - off)) == -1) + break; ++ if (!tls && (w = write(fd, s + off, len - off)) == -1) ++ break; ++ } ++ if (w == -1) { ++ if (tls) ++ die("%s: tls_write: %s\n", argv0, tls_error(tls)); ++ else ++ die("%s: write: %s\n", argv0, strerror(errno)); + } +- if (w == -1) +- die("%s: write: %s\n", argv0, strerror(errno)); + } + + /* creates directories bottom-up, if necessary */ +@@ -686,8 +695,15 @@ read_line(int fd, char *buf, size_t bufsiz) + char c = '\0'; + + do { +- if (read(fd, &c, sizeof(char)) != sizeof(char)) +- return -1; ++ if (tls && fd == ircfd) { ++ if (tls_read(tls, &c, sizeof(c)) == -1) { ++ die(""); ++ return -1; ++ } ++ } else { ++ if (read(fd, &c, sizeof(char)) != sizeof(char)) ++ return -1; ++ } + buf[i++] = c; + } while (c != '\n' && i < bufsiz); + buf[i - 1] = '\0'; /* eliminates '\n' */ +@@ -799,7 +815,8 @@ main(int argc, char *argv[]) + const char *key = NULL, *fullname = NULL, *host = ""; + const char *uds = NULL, *service = "6667"; + char prefix[PATH_MAX]; +- int ircfd, r; ++ int r; ++ struct tls_config *tls_config = NULL; + + /* use nickname and home dir of user by default */ + if (!(spw = getpwuid(getuid()))) +@@ -827,6 +844,17 @@ main(int argc, char *argv[]) + case 's': + host = EARGF(usage()); + break; ++ case 't': ++ if (tls != NULL) ++ break; ++ ++ if ((tls = tls_client()) == NULL) ++ die("%s: tls_client\n", argv0); ++ if ((tls_config = tls_config_new()) == NULL) ++ die("%s: tls_config_new\n", argv0); ++ if (tls_configure(tls, tls_config) == -1) ++ die("%s: tls_configure\n", argv0); ++ break; + case 'u': + uds = EARGF(usage()); + break; +@@ -843,6 +871,11 @@ main(int argc, char *argv[]) + else + ircfd = tcpopen(host, service); + ++ if (tls && tls_connect_socket(tls, ircfd, host) == -1) ++ die("%s: tls_connect_socket: %s\n", argv0, tls_error(tls)); ++ if (tls && tls_handshake(tls) == -1) ++ die("%s: tls_handshake: %s\n", argv0, tls_error(tls)); ++ + #ifdef __OpenBSD__ + /* OpenBSD pledge(2) support */ + if (pledge("stdio rpath wpath cpath dpath", NULL) == -1) diff --git a/tools.suckless.org/ii/patches/tls/index.md b/tools.suckless.org/ii/patches/tls/index.md @@ -0,0 +1,15 @@ +TLS +=== + +Description +----------- +Adds tls encryption support via the `-t` argument. +This patch depends on libtls from [https://www.libressl.org/](LibreSSL). + +Download +-------- +* [ii-2.0-tls.diff](ii-2.0-tls.diff) + +Author +------ +* Written for 2.0 by Jan Klemkow