3 # Copyright (c) 2007, 2008, 2010 Zmanda Inc. All Rights Reserved.
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License version 2 as published
7 # by the Free Software Foundation.
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 # You should have received a copy of the GNU General Public License along
15 # with this program; if not, write to the Free Software Foundation, Inc.,
16 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # Contact information: Zmanda Inc, 465 S. Mathilda Ave., Suite 300
19 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
23 exec_prefix="@exec_prefix@"
25 amlibexecdir="@amlibexecdir@"
26 . "${amlibexecdir}/amanda-sh-lib.sh"
28 # add sbin and ucb dirs
29 PATH="$PATH:/usr/sbin:/sbin:/usr/ucb"
32 # wrapper script to use aespipe
33 # based on bz2aespipe distributed by aespipe from
34 # http://loop-aes.sourceforge.net/
36 # 10 bytes: constant string 'bz2aespipe'
37 # 10 bytes: itercountk digits
38 # 1 byte: '0' = AES128, '1' = AES192, '2' = AES256
39 # 1 byte: '0' = SHA256, '1' = SHA384, '2' = SHA512, '3' = RMD160
40 # 24 bytes: random seed string
41 # remaining bytes are aespipe encrypted
43 # These definitions are only used when encrypting.
44 # Decryption will autodetect these definitions from archive.
49 AMANDA_HOME=~@CLIENT_LOGIN@
50 GPGKEY="$AMANDA_HOME/.gnupg/am_key.gpg"
53 if test x$1 = x-d ; then
55 n=`/bin/dd bs=10 count=1 2> /dev/null | tr -d -c 0-9a-zA-Z`
56 if test x${n} != xbz2aespipe ; then
57 echo "bz2aespipe: wrong magic - aborted" >/dev/tty
60 itercountk=`/bin/dd bs=10 count=1 2> /dev/null | tr -d -c 0-9`
61 if test x${itercountk} = x ; then itercountk=0; fi
62 n=`/bin/dd bs=1 count=1 2> /dev/null | tr -d -c 0-9`
64 if test x${n} = x1 ; then encryption=AES192; fi
65 if test x${n} = x2 ; then encryption=AES256; fi
66 n=`/bin/dd bs=1 count=1 2> /dev/null | tr -d -c 0-9`
68 if test x${n} = x1 ; then hashfunc=SHA384; fi
69 if test x${n} = x2 ; then hashfunc=SHA512; fi
70 if test x${n} = x3 ; then hashfunc=RMD160; fi
71 seedstr=`/bin/dd bs=24 count=1 2> /dev/null | tr -d -c 0-9a-zA-Z+/`
72 aespipe -K ${GPGKEY} -p ${FDNUMBER} -e ${encryption} -H ${hashfunc} \
73 -S ${seedstr} -C ${itercountk} -d
77 echo ${ITERCOUNTK} | awk '{printf "%10u", $1;}'
78 n=`echo ${ENCRYPTION} | tr -d -c 0-9`
80 if test x${n} = x192 ; then aesstr=1; fi
81 if test x${n} = x256 ; then aesstr=2; fi
82 n=`echo ${HASHFUNC} | tr -d -c 0-9`
84 if test x${n} = x384 ; then hashstr=1; fi
85 if test x${n} = x512 ; then hashstr=2; fi
86 if test x${n} = x160 ; then hashstr=3; fi
87 seedstr=`head -c 18 /dev/urandom | uuencode -m - | head -n 2 | tail -n 1`
88 echo -n ${aesstr}${hashstr}${seedstr}
89 aespipe -K ${GPGKEY} -p ${FDNUMBER} -e ${ENCRYPTION} -H ${HASHFUNC} \
90 -S ${seedstr} -C ${ITERCOUNTK} -w ${WAITSECONDS}