-
Notifications
You must be signed in to change notification settings - Fork 1
/
reproducibility_verifier.sh
executable file
·195 lines (166 loc) · 6.61 KB
/
reproducibility_verifier.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/bin/bash
#
# Copyright (C) 2020 Intel Corporation. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Intel Corporation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Taken from https://github.com/intel/linux-sgx/blob/master/linux/reproducibility/ae_reproducibility_verifier/reproducibility_verifier.sh
usage()
{
echo -e "Usage:
./reproducibility_verifier.sh [developer_signed_ae] [auditor_build_unsigned_ae] [auditor_private_key] [developer_ae_config_xml]
The script is to verify that developer prebuilt AEs are:
* Built using same code and toolsets that being opensourced
* Signed using same config.xml that being opensourced
Arguments:
developer_signed_ae: It's the developer's prebuilt AE to be verified.
auditor_build_unsigned_ae: It's built by yourself in an SGX docker container.
auditor_private_key: It's generated by yourself for signing auditor_build_unsigned_ae in bullet 1.
developer_ae_config_xml: It's the opensource enclave config.xml that the developer used to create the prebuilt AE.
Note:
* All of above 4 arguments are required.
* If no arguments, './reproducibility_verifier.sh' will show the usage.
Result:
* If the verification succeeds:
Display info: Reproducibility Verification PASSED!
Exit status: 0
* If the verification fails:
Display info: Reproducibility Verification FAILED!
Exit status: 1
* Other Error:
Display the specific error info
Exit status: 2"
}
is_file_existed()
{
file=$1
err_msg=$2
if [ ! -f $file ]; then
echo -e "Error: $file is not found. $err_msg\n"
exit 2
fi
}
check_cmd_status()
{
status=$1
err_msg=$2
if [ $status -ne 0 ]; then
echo -e "Error: $err_msg with return value $status!\n"
exit 2
fi
}
check_input_parameter()
{
is_file_existed $1 "Please check the path for $2 is correct!"
echo -e "* $2 is: \t$1"
}
prepare()
{
if [ $# == 0 ]; then
usage
exit 2
fi
# check input parameter list
check_input_parameter $developer_signed_ae 'developer signed AE'
check_input_parameter $auditor_unsigned_ae 'auditor unsigned AE'
check_input_parameter $auditor_key 'auditor private key'
check_input_parameter $developer_config 'developer config.xml'
if [ 0"$SGX_SDK" = 0"" ]; then
echo -e "Error: \$SGX_SDK is not found, please ensure Intel(R) SGX SDK is installed and environment is set!\n"
exit 2
fi
if [ -d $output_dir ]; then
rm -rf $output_dir/*
fi
mkdir -p $output_dir
}
extract_enclave_metadata()
{
# get the whole enclave metadata including keys related
is_file_existed $1 "the signed enclave for sgx dump is not existed"
${SGX_SDK}/bin/x64/sgx_sign dump -enclave $1 -dumpfile $2 > /dev/null 2>&1
check_cmd_status $? "sgn_sign dump the signed enclave failed!"
# extract part of enclave metadata by excluding below fields:
# enclave_css.header.date
# enclave_css.enclave_css.key.modulus
# enclave_css.key.exponent
# enclave_css.key.signature
# enclave_css.buffer.q1
# enclave_css.buffer.q2
is_file_existed $2 "the original enclave_metadata file is not existed for sed to extract"
sed -n '/metadata->magic_num/,/metadata->enclave_css.header.module_vendor/p;/metadata->enclave_css.header.header2/,/metadata->enclave_css.header.hw_version/p;/metadata->enclave_css.body.misc_select/,/metadata->enclave_css.body.isv_svn/p;' $2 > $3
check_cmd_status $? "sed the original enclave metadata failed!"
}
extract_developer_enclave_metadata()
{
extract_enclave_metadata $developer_signed_ae $metadata1_orig $metadata1
}
extract_auditor_enclave_metadata()
{
# sgx_sign auditor's unsigned AE with the developer's config.xml and auditor's private key
${SGX_SDK}/bin/x64/sgx_sign sign -enclave $auditor_unsigned_ae -key $auditor_key -config $developer_config -out $auditor_signed_ae > /dev/null 2>&1
check_cmd_status $? "sgx_sign sign auditor_build_ae failed!"
# extract auditor signed AE's metadata
extract_enclave_metadata $auditor_signed_ae $metadata2_orig $metadata2
}
check_ae_reproducibility()
{
is_file_existed $metadata1 "the developer ae metadata file is not existed for diff to compare"
is_file_existed $metadata2 "the auditor ae metadata file is not existed for diff to compare"
diff $metadata1 $metadata2 > $metadata_diff 2>&1
diff_status=$?
if [ $diff_status -eq 0 ]; then
echo -e "Reproducibility Verification PASSED! \n"
exit 0
elif [ $diff_status -eq 1 ]; then
echo -e "Reproducibility Verification FAILED! \n"
echo -e "Please find the diff contents in $metadata_diff"
exit 1
else
echo -e "Error: There was something wrong with the diff command!\n"
exit 2
fi
}
developer_signed_ae=$1
auditor_unsigned_ae=$2
auditor_key=$3
developer_config=$4
output_dir='output'
auditor_signed_ae=$output_dir'/auditor_ae.signed.so'
metadata1_orig=$output_dir'/developer_metadata_orig.txt'
metadata2_orig=$output_dir'/auditor_metadata_orig.txt'
metadata1=$output_dir'/developer_metadata.txt'
metadata2=$output_dir'/auditor_metadata.txt'
metadata_diff=$output_dir'/metadata_diff.txt'
# Step 1: check input parameters and prepare enviroment
prepare $@
# Step 2: extract developer's signed AE's metadata
extract_developer_enclave_metadata
# Step 3: sgx_sign auditor's local build AE and extract auditor signed AE's metadata
extract_auditor_enclave_metadata
# Step 4: compare metadata between developer signed ae and auditor signed ae
check_ae_reproducibility