#!/bin/sh

rm -rf .ca
mkdir .ca
touch .ca/index.txt
echo "01" > .ca/serial
openssl genrsa -out root.key 2048
openssl req -new -x509 -key root.key -out root.crt \
    -config ./ca_openssl.conf
openssl genrsa -out polyorb.key 2048
openssl req -new -key polyorb.key -out polyorb.req \
    -config ./polyorb_openssl.conf
printf "y\ny\n" | openssl ca -keyfile root.key -cert root.crt \
    -in polyorb.req -out polyorb.crt \
    -config ./ca_openssl.conf || true
rm -rf .ca

trap "killall server client; rm -f ior" 0 1 2 3 15

POLYORB_CONF=gssup.conf ./server | tee ior &

j=0
while [ $j -lt 20 ]; do
    [ -f ior ] && [ `wc -l ior | cut -d ' ' -f 1` -ne 0 ] && break
    sleep 1
    j=`expr $j + 1`
done

POLYORB_CONF=gssup.conf ./client `cat ior | head -n 1 | cut -d "'" -f 2`
