main.sh - postreich - Unnamed repository; edit this file 'description' to name the repository.
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
       main.sh (1602B)
       ---
            1 #!/bin/sh
            2 
            3 # extract dependencies
            4 
            5 # handle must be less than 16 bytes
            6 
            7 # set password to ENV variable so it's hidden in the code. Check if it's empty
            8 # before generating the key.
            9 
           10 create_mailbox_url="gopher://localhost/7/postoffice/mailbox/create"
           11 get_mailbox_url="gopher://localhost/0/postoffice/mailbox/get"
           12 
           13 cupid_encryption() {
           14     #    printf "%s" $1 | \
           15         return 0
           16 }
           17 
           18 user_encryption() {
           19     return 0
           20 }
           21 
           22 create_key_pair() {
           23     # check if key exists already?
           24     private_key_name="br_cupid.pem"
           25     public_key_name=$( printf "%s" "$private_key_name" |\
           26                            sed 's/pem$/pub/' )
           27     # Generate a 2048 bit key
           28     # TODO: am i using safe primes?
           29     openssl genpkey -algorithm RSA -out $private_key_name -pkeyopt -quiet
           30     openssl pkey -in "$private_key_name" -pubout -out "$public_key_name"
           31     if [ ! -r "$private_key_name" -o ! -r "$public_key_name" ]; then
           32         printf "Did not generate private and public keys. Exiting.\n"
           33     fi
           34     return 0
           35 }
           36 
           37 create_mailbox() {
           38     pub_key_contents=$( cat "br_cupid.pub" | base64 | tr -d "\n" ) 
           39     if [ $( printf "%s" "$pub_key_contents" | wc -c ) -gt 1024 ]; then
           40         printf "Public key is larger than 1024 bits. Server might not get it all, \
           41                (geomyidae limit is 1024, rfc gopher limit is less) but trying anyways..."
           42     fi
           43     handle="roygbyte"
           44     curl "$create_mailbox_url/$handle?$pub_key_contents"
           45 }
           46 
           47 open_mailbox() {
           48     result=$( curl "$get_mailbox_url/$1" -s \
           49                   | awk -F ',' '{ system("printf '%s' " $2 "| base64 -d | openssl pkeyutl -decrypt -inkey br_cupid.pem"); print "" }' )
           50     echo "$result"
           51 }
           52 
           53 create_mailbox
           54 #open_mailbox "$1"
           55