-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopensgx
executable file
·102 lines (88 loc) · 1.59 KB
/
opensgx
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#! /bin/bash
ROOT=$(dirname "$0")
SGXTOOL=$ROOT/user/sgx-tool
SGX=$ROOT/sgx
DEVICEKEY=$ROOT/user/conf/device.key
INTELKEY=$ROOT/user/conf/intel.key
GDBPORT=-1
key_gen() {
FILENAME=sign.key
$SGXTOOL -k 3072 > $FILENAME
}
compile_code() {
BASEDIR=$(dirname $1)
SUBDIR=${BASEDIR#*/}
BASENAME=$(basename $1)
NAME="${BASENAME%.*}"
cd user
make $SUBDIR/$NAME.sgx
}
run_program() {
$SGX $@
}
debug_program() {
$SGX -g $GDBPORT $@
}
measure() {
$SGXTOOL -m $1
}
sign-intel() {
BASEDIR=$(dirname $1)
BASENAME=$(basename $1)
NAME="${BASENAME%.*}"
MEASURE=$BASEDIR/$NAME-measurement.conf
SIG=$BASEDIR/$NAME-sig.conf
TOKEN=$BASEDIR/$NAME-token.conf
CONF=$BASEDIR/$NAME.conf
touch $CONF
measure $1 > $MEASURE
$SGXTOOL -S $MEASURE -I > $SIG
$SGXTOOL -s $SIG --key=$INTELKEY > $CONF
$SGXTOOL -E $CONF >> $CONF
rm $MEASURE $SIG
}
sign() {
BASEDIR=$(dirname $1)
BASENAME=$(basename $1)
NAME="${BASENAME%.*}"
MEASURE=$BASEDIR/$NAME-measurement.conf
SIG=$BASEDIR/$NAME-sig.conf
TOKEN=$BASEDIR/$NAME-token.conf
CONF=$BASEDIR/$NAME.conf
touch $CONF
measure $1 > $MEASURE
$SGXTOOL -S $MEASURE > $SIG
$SGXTOOL -s $SIG --key=$2 > $CONF
$SGXTOOL -E $CONF > $TOKEN
$SGXTOOL -M $TOKEN --key=$DEVICEKEY >> $CONF
rm $MEASURE $SIG $TOKEN
}
case "$1" in
-k|--key)
key_gen
;;
-c|--compile)
compile_code $2
;;
-m|--measure)
measure $2
;;
-s|--sign)
case "$3" in
-k|--key)
sign $2 $4
;;
-I|--intel)
sign-intel $2
;;
esac
;;
-d|--debug)
GDBPORT=$2
shift; shift
debug_program $@
;;
*)
run_program $@
;;
esac