Add cli for creating a mailbox - postreich - Unnamed repository; edit this file 'description' to name the repository. DIR Log DIR Files DIR Refs DIR README --- DIR commit dff1a971ef77a24ce8bcefa9f48427c84ba908c3 DIR parent fc8382d31698a17c076eb873c2c25882d360405b HTML Author: Scarlett McAllister <no+reply@roygbyte.com> Date: Thu, 18 Jan 2024 17:08:50 -0400 Add cli for creating a mailbox Diffstat: A main.sh | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+), 0 deletions(-) --- DIR diff --git a/main.sh b/main.sh @@ -0,0 +1,47 @@ +#!/bin/sh + +# extract dependencies + +# handle must be less than 16 bytes + +# set password to ENV variable so it's hidden in the code. Check if it's empty +# before generating the key. + +create_mailbox_url="gopher://localhost/7/postoffice/mailbox/create" + +cupid_encryption() { + # printf "%s" $1 | \ + return 0 +} + +user_encryption() { + return 0 +} + +create_key_pair() { + # check if key exists already? + private_key_name="br_cupid.pem" + public_key_name=$( printf "%s" "$private_key_name" |\ + sed 's/pem$/pub/' ) + # Generate a 2048 bit key + # TODO: am i using safe primes? + openssl genpkey -algorithm RSA -out $private_key_name -pkeyopt -quiet + openssl pkey -in "$private_key_name" -pubout -out "$public_key_name" + if [ ! -r "$private_key_name" -o ! -r "$public_key_name" ]; then + printf "Did not generate private and public keys. Exiting.\n" + fi + return 0 +} + +create_mailbox() { + pub_key_contents=$( cat "br_cupid.pub" | base64 | tr -d "\n" ) + if [ $( printf "%s" "$pub_key_contents" | wc -c ) -gt 1024 ]; then + printf "Public key is larger than 1024 bits. Server might not get it all, \ + (geomyidae limit is 1024, rfc gopher limit is less) but trying anyways..." + fi + handle="definitelyroygbyte" + curl "$create_mailbox_url/$handle?$pub_key_contents" +} + +create_mailbox +