|
13 | 13 | * limitations under the License.
|
14 | 14 | */
|
15 | 15 |
|
16 |
| -#include <string> |
17 | 16 | #include <stdio.h>
|
18 |
| -#include <iostream> |
19 | 17 | #include <string.h>
|
| 18 | +#include <string> |
| 19 | + |
| 20 | +#include <sgx_utils.h> |
| 21 | +#include <sgx_quote.h> |
20 | 22 |
|
21 | 23 | #include "ias_attestation_util.h"
|
22 | 24 | #include "verify-report.h"
|
23 | 25 | #include "tcf_error.h"
|
24 | 26 | #include "parson.h"
|
25 | 27 | #include "jsonvalue.h"
|
| 28 | +#include "types.h" |
26 | 29 |
|
27 | 30 | bool verify_ias_report_signature(const std::string& signing_cert_pem,
|
28 |
| - const std::string& ias_report, |
29 |
| - const std::string& ias_signature) { |
| 31 | + const std::string& ias_report, |
| 32 | + const std::string& ias_signature) { |
| 33 | + /* Verify IAS report signature |
| 34 | + * @param signing_cert_pem signing certificate |
| 35 | + * @param ias_report attestion report |
| 36 | + * @param ias_signature attestation report signature |
| 37 | + * Returns true if signature verification success |
| 38 | + * otherwise false |
| 39 | + */ |
30 | 40 |
|
31 | 41 | // Parse JSON serialized IAS report
|
32 | 42 | JsonValue report_parsed(json_parse_string(ias_report.c_str()));
|
@@ -54,3 +64,30 @@ bool verify_quote(const std::string& ias_report, int group_out_of_date_is_ok) {
|
54 | 64 | return quote_status;
|
55 | 65 | }
|
56 | 66 |
|
| 67 | +bool verify_mr_enclave_value(const std::string& enclave_quote_body, |
| 68 | + const std::string& mr_enclave) { |
| 69 | + /* Verify MR enclave in the attestation |
| 70 | + * report and compare with the value passed |
| 71 | + * @param enclave_quote_body Enclave quote body |
| 72 | + * @param mr_enclave MR enclave value in hex format |
| 73 | + * Return true if comparision matches otherwise false |
| 74 | + **/ |
| 75 | + if (mr_enclave.size() != 0) { |
| 76 | + /* Extract ReportData and MR_ENCLAVE from isvEnclaveQuoteBody |
| 77 | + present in Verification Report */ |
| 78 | + ByteArray quote_bytes = Base64EncodedStringToByteArray( |
| 79 | + enclave_quote_body.c_str()); |
| 80 | + sgx_quote_t* quote_body = reinterpret_cast<sgx_quote_t*>( |
| 81 | + quote_bytes.data()); |
| 82 | + sgx_report_body_t* report_body = "e_body->report_body; |
| 83 | + sgx_measurement_t mr_enclave_from_report = *(&report_body->mr_enclave); |
| 84 | + ByteArray mr_enclave_bytes = HexEncodedStringToByteArray(mr_enclave); |
| 85 | + if (memcmp(mr_enclave_from_report.m, mr_enclave_bytes.data(), |
| 86 | + SGX_HASH_SIZE) == 0) { |
| 87 | + return true; |
| 88 | + } |
| 89 | + else { |
| 90 | + return false; |
| 91 | + } |
| 92 | + } |
| 93 | +} |
0 commit comments