-
Notifications
You must be signed in to change notification settings - Fork 2
/
makecatexts.sh
executable file
·81 lines (71 loc) · 1.91 KB
/
makecatexts.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
# set -x
# Take a set of named PNGs (cat pics) and make those into a
# file that can be included into an ECHConfig as extensions.
# We omit the overall extensions length so we can still
# catenate files if we want (and because ``openssl ech`` will
# add that anyway). Extension type is made up.
OUTFILE="cat.ext" # default output
CATPICTYPE=4042 # 0x0fca is the 1st extension type - we'll incrememt after
function usage()
{
echo "Read the code, sorry"
exit 99
}
# options may be followed by one colon to indicate they have a required argument
if ! options=$(/usr/bin/getopt -s bash -o o:h -l output:,help -- "$@")
then
# something went wrong, getopt will put out an error message for us
exit 1
fi
#echo "|$options|"
eval set -- "$options"
while [ $# -gt 0 ]
do
case "$1" in
-h|--help) usage;;
-o|--output) OUTFILE=$2; shift;;
(--) shift; break;;
(-*) echo "$0: error - unrecognized option $1" 1>&2; exit 1;;
(*) break;;
esac
shift
done
infiles=$*
exttype=$CATPICTYPE
if [ -f $OUTFILE ]
then
# one backup is enough
mv $OUTFILE $OUTFILE.bak
fi
for file in $infiles
do
echo $file
if [ ! -f $file ]
then
# add empty extension
flen=0
else
flen=`wc -c $file | awk '{print $1}'`
fi
# output type, length, value to $OUTFILE
ah_type="`printf "%04x" $((exttype))`"
exttype=$((exttype+1))
echo $ah_type | xxd -p -r >>$OUTFILE
ah_flen="`printf "%04x" $((flen))`"
echo $ah_flen | xxd -p -r >>$OUTFILE
if [ -f $file ]
then
cat $file >>$OUTFILE
fi
done
# check size of $OUTFILE - we limit extensions to 512 octets max for now, see
# include/openssl/ech.h for the defnition of OSSL_ECH_MAX_ECHCONFIGEXT_LEN
if [ -f $OUTFILE ]
then
fs=`stat -c %s $OUTFILE`
if ((fs > 512))
then
echo "Warning: extensions file too big ($fs > 512) that won't work"
fi
fi