#!/bin/sh # Copyright (c) 2017, 2018 Taylor R. Campbell # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. set -Cemu err () { echo >&2 t_oniongen: "$@"; exit 1; } check () { f1="$1" f2="$2" shift 2 "$@" "$f1" "$f2" [ -f "$f1" ] || err "$f1 not generated" [ -f "$f2" ] || err "$f2 not generated" } stoptimer () { if kill -0 %1 2>>/dev/null; then echo t_oniongen: stop timer kill %1 || err 'unstoppable timer' fi } killmocktortle () { if kill -0 %1 2>>/dev/null; then echo t_oniongen: kill mocktortle kill %2 || err 'invincible mocktortle' fi } cleanfiles () { rm -f t_oniongen.sock rm -f t_oniongen.secret t_oniongen.onion rm -f t_oniongen.secret-v2 t_oniongen.onion-v2 rm -f t_oniongen.secret-v3 t_oniongen.onion-v3 rm -f t_oniongen.secret-best t_oniongen.onion-best rm -f t_oniongen.secret-rsa1024 t_oniongen.onion-rsa1024 rm -f t_oniongen.secret-ed25519-v3 t_oniongen.onion-ed25519-v3 } clean () { stoptimer killmocktortle cleanfiles } trap clean EXIT HUP INT TERM cleanfiles echo t_oniongen: start timer (sleep 1; echo >&2 t_oniongen: timeout; kill $$) & echo t_oniongen: start mockturtle socat unix-listen:t_oniongen.sock,end-close,fork exec:./mocktortle.sh & check t_oniongen.secret t_oniongen.onion ./oniongen t_oniongen.sock mocktortle.cookie check t_oniongen.secret-v2 t_oniongen.onion-v2 ./oniongen -V 2 t_oniongen.sock mocktortle.cookie check t_oniongen.secret-v3 t_oniongen.onion-v3 ./oniongen -V 3 t_oniongen.sock mocktortle.cookie check t_oniongen.secret-best t_oniongen.onion-best ./oniongen -t BEST t_oniongen.sock mocktortle.cookie check t_oniongen.secret-rsa1024 t_oniongen.onion-rsa1024 ./oniongen -t RSA1024 t_oniongen.sock mocktortle.cookie check t_oniongen.secret-ed25519-v3 t_oniongen.onion-ed25519-v3 ./oniongen -t ED25519-V3 t_oniongen.sock mocktortle.cookie killmocktortle stoptimer wait echo t_oniongen: success