2020-06-17 Tiny Gemini Client in Bash

This defines the function “gemini” such that you can visit a Gemini URL from the command line.

function gemini () {
    if [[ $1 =~ gemini://([^/:]+)(:([0-9]+))? ]]; then
	host=${BASH_REMATCH[1]}
	port=${BASH_REMATCH[3]:-1965}
	echo Contacting $host:$port...
	echo "$1" | openssl s_client -quiet -connect $host:$port 2>/dev/null
    else
	echo $1 is not a Gemini URL
    fi
}

I should write another one that uses a client certificate, too. 🙂

And here’s an uploader using Titan.

function titan () {
    if [[ -z "$2" ]]; then
        echo Usage: $0 URL TOKEN [FILE]
	exit
    else
	token=$2
    fi
    if [[ $1 =~ titan://([^/:]+)(:([0-9]+))? ]]; then
	host=${BASH_REMATCH[1]}
	port=${BASH_REMATCH[3]:-1965}
	echo Reading ${2:-/dev/stdin}
	read -d "" file < "${3:-/dev/stdin}"
	size=${#file}
	echo Posting $size bytes to $host:$port...
	printf "$1;token=$token;mime=text/plain;size=$size\r\n$file" \
	    | openssl s_client -quiet -connect $host:$port 2>/dev/null
    else
	echo $1 is not a Titan URL
    fi
}

Here’s how to call it:

echo "This is a Titan test." \
    | titan titan://alexschroeder.ch/raw/Test hello

I put these two functions into a git repo.

Tags:

Comments

I guess the URL schema is superfluous. 🙂

If somebody uses a client certificate with a common name set, we could use this to save a username when saving pages. An excellent way to self-identify.

Sadly, on the server side, I have not found a way to learn anything about the client certificate used. 😟

– Alex Schroeder 2020-06-17 21:41 UTC


I depends upon the library you are using for TLS. I use libtls, which makes it not only easy to use TLS, but to obtain information from the client certificate.

Sean Conner 2020-06-17 22:21 UTC


Hm. I use Perl’s IO::Socket::SSL which allows me to examine the peer certificate, according to the do documentation but when I do it, there is nothing. 😕

– Alex Schroeder 2020-06-18 12:42 UTC


Please make sure you contribute only your own work, or work licensed under the GNU Free Documentation License. Note: in order to facilitate peer review and fight vandalism, we will store your IP number for a number of days. See Privacy Policy for more information. See Info for text formatting rules. You can edit the comment page if you need to fix typos. You can subscribe to new comments by email without leaving a comment.

To save this page you must answer this question:

Just say HELLO