-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsplitechconfiglist.sh
More file actions
executable file
·52 lines (45 loc) · 1.68 KB
/
splitechconfiglist.sh
File metadata and controls
executable file
·52 lines (45 loc) · 1.68 KB
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
#!/bin/bash
# set -x
function splitlist()
{
# example usage input is base64 encoded ECHconfigList
# list=$echconfiglist
# splitlists=`splitelist`
# result is a space sep list of single-entry base64 encoded ECHConfigLists
# this assumes encoding is valid and does no error checking
olist=""
ah_echlist=`echo $list | base64 -d | xxd -ps -c 200 | tr -d '\n'`
ah_olen=${ah_echlist:0:4}
olen=$((16#$ah_olen))
remaining=$olen
top=${ah_echlist:4}
while ((remaining>0))
do
ah_nlen=${top:4:4}
nlen=$((16#$ah_nlen))
nlen=$((nlen+4))
ah_nlen=$((nlen*2))
ah_thislen="`printf "%04x" $((nlen))`"
thisone=${top:0:ah_nlen}
b64thisone=`echo $ah_thislen$thisone | xxd -p -r | base64 -w 0`
olist="$olist $b64thisone"
remaining=$((remaining-nlen))
top=${top:ah_nlen}
done
echo -e "$olist"
}
# example list of 6 ...
list="AXn+DQA6xQAgACBm54KSIPXu+pQq2oY183wt3ybx7CKbBYX0ogPq5u6FegAEAAEAAQALZXhhbXBsZS5jb20AAP4KADzSACAAIIP+0Qt0WGBF3H5fz8HuhVRTCEMuHS4Khu6ibR/6qER4AAQAAQABAAAAC2V4YW1wbGUuY29tAAD+CQA7AAtleGFtcGxlLmNvbQAgoyQr+cP8mh42znOp1bjPxpLCBi4A0ftttr8MPXRJPBcAIAAEAAEAAQAAAAD+DQA6QwAgACB3xsNUtSgipiYpUkW6OSrrg03I4zIENMFa0JR2+Mm1WwAEAAEAAQALZXhhbXBsZS5jb20AAP4KADwDACAAIH0BoAdiJCX88gv8nYpGVX5BpGBa9yT0Pac3Kwx6i8URAAQAAQABAAAAC2V4YW1wbGUuY29tAAD+DQA6QwAgACDcZIAx7OcOiQuk90VV7/DO4lFQr5I3Zw9tVbK8MGw1dgAEAAEAAQALZXhhbXBsZS5jb20AAA=="
if [[ "$1" != "" ]]
then
# assume param is a PEM file
if [ -f $1 ]
then
list=`cat $1 | sed -n '/BEGIN ECHCONFIG/,/END ECHCONFIG/p' | head -n -1 | tail -n -1`
fi
fi
splitlists=`splitlist`
for list in $splitlists
do
echo $list
done