-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Dominic Ayre <[email protected]> Co-authored-by: Joe Powell <[email protected]> Co-authored-by: Kapil Vaswani <[email protected]> Co-authored-by: Ken Gordon <[email protected]> Co-authored-by: Mahati Chamarthy <[email protected]> Co-authored-by: Ronny Bjones <[email protected]>
- Loading branch information
1 parent
b503ce7
commit 46b4a32
Showing
61 changed files
with
3,485 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Portions Copyright (c) Microsoft Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
load("@rules_cc//cc:defs.bzl", "cc_library") | ||
|
||
package(default_visibility = ["//scp/cc/azure:__subpackages__"]) | ||
|
||
# A dummy library to propagate the include directories. | ||
cc_library( | ||
name = "include_dir", | ||
includes = ["."], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Portions Copyright (c) Microsoft Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
load("@rules_cc//cc:defs.bzl", "cc_library") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
cc_library( | ||
name = "aci_attestation_lib", | ||
srcs = glob( | ||
[ | ||
"**/*.cc", | ||
"**/*.h", | ||
], | ||
), | ||
deps = [ | ||
"@boost//:system", | ||
"@com_google_absl//absl/strings", | ||
"@com_google_absl//absl/log:check", | ||
":get-snp-report", | ||
"@nlohmann_json//:lib", | ||
"//scp/cc/core/utils/src:core_utils", | ||
], | ||
) | ||
|
||
cc_library( | ||
name="get-snp-report", | ||
srcs=glob(["get-snp-report/*.c"]), | ||
hdrs=glob(["get-snp-report/*.h"]), | ||
) | ||
|
||
cc_binary( | ||
name = "print_snp_json", | ||
srcs = ["print_snp_json.cc"], | ||
linkopts=['-static'], | ||
linkstatic=True, | ||
features = ["fully_static_link"], | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"aci_attestation_lib", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Portions Copyright (c) Microsoft Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
bool fetchAttestationReport5(const char* report_data_hexstring, void **snp_report); | ||
|
||
// does /dev/sev exists. This is where the PSP is exposed in 5.15.* | ||
bool supportsDevSev(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Portions Copyright (c) Microsoft Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
bool fetchAttestationReport6(const char* report_data_hexstring, void **snp_report); | ||
|
||
// 6.1 linux exposees the PSP via /dev/sev-guest | ||
|
||
bool supportsDevSevGuest(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Portions Copyright (c) Microsoft Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "get-snp-report.h" | ||
|
||
bool fetchSnpReport(const char* report_data_hexstring, void** snp_report) { | ||
bool success = false; | ||
uint8_t *snp_report_hex; | ||
|
||
if (supportsDevSev()) { | ||
success = fetchAttestationReport5(report_data_hexstring, (void*) &snp_report_hex); | ||
} else if (supportsDevSevGuest()) { | ||
success = fetchAttestationReport6(report_data_hexstring, (void*) &snp_report_hex); | ||
} else { | ||
fprintf(stderr, "No supported SNP device found\n"); | ||
} | ||
|
||
if (success) { | ||
*snp_report = snp_report_hex; | ||
return 0; | ||
} | ||
|
||
return -1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Portions Copyright (c) Microsoft Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <fcntl.h> | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <sys/ioctl.h> | ||
#include <sys/stat.h> | ||
#include <sys/types.h> | ||
|
||
#include "fetch5.h" | ||
#include "fetch6.h" | ||
#include "snp-attestation.h" | ||
|
||
bool fetchSnpReport(const char* report_data_hexstring, void** snp_report); |
101 changes: 101 additions & 0 deletions
101
scp/cc/azure/attestation/get-snp-report/get-snp-report5.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Portions Copyright (c) Microsoft Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <sys/ioctl.h> | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <unistd.h> | ||
#include <string.h> | ||
#include <stdbool.h> | ||
#include <stdlib.h> | ||
|
||
#include "snp-attestation.h" | ||
#include "snp-ioctl5.h" | ||
|
||
#include "helpers.h" | ||
|
||
bool supportsDevSev() | ||
{ | ||
return access("/dev/sev", W_OK) == 0; | ||
} | ||
|
||
bool fetchAttestationReport5(const char* report_data_hexstring, void **snp_report) | ||
{ | ||
msg_report_req msg_report_in; | ||
msg_response_resp msg_report_out; | ||
|
||
int fd, rc; | ||
|
||
struct sev_snp_guest_request payload = { | ||
.req_msg_type = SNP_MSG_REPORT_REQ, | ||
.rsp_msg_type = SNP_MSG_REPORT_RSP, | ||
.msg_version = 1, | ||
.request_len = sizeof(msg_report_in), | ||
.request_uaddr = (uint64_t) (void*) &msg_report_in, | ||
.response_len = sizeof(msg_report_out), | ||
.response_uaddr = (uint64_t) (void*) &msg_report_out, | ||
.error = 0 | ||
}; | ||
|
||
memset((void*) &msg_report_in, 0, sizeof(msg_report_in)); | ||
memset((void*) &msg_report_out, 0, sizeof(msg_report_out)); | ||
|
||
// the report data is passed as a hexstring which needs to be decoded into an array of | ||
// unsigned bytes | ||
// MAA expects a SHA-256. So we use left align the bytes in the report data | ||
|
||
uint8_t *reportData = decodeHexString(report_data_hexstring, sizeof(msg_report_in.report_data)); | ||
memcpy(msg_report_in.report_data, reportData, sizeof(msg_report_in.report_data)); | ||
|
||
// open the file descriptor of the PSP | ||
fd = open("/dev/sev", O_RDWR | O_CLOEXEC); | ||
|
||
if (fd < 0) { | ||
fprintf(stderr, "Failed to open /dev/sev\n"); | ||
return false; | ||
} | ||
|
||
// issue the custom SEV_SNP_GUEST_MSG_REPORT sys call to the sev driver | ||
rc = ioctl(fd, SEV_SNP_GUEST_MSG_REPORT, &payload); | ||
|
||
if (rc < 0) { | ||
fprintf(stderr, "Failed to issue ioctl SEV_SNP_GUEST_MSG_REPORT\n"); | ||
return false; | ||
} | ||
|
||
#ifdef DEBUG_OUTPUT | ||
fprintf(stderr, "Response header:\n"); | ||
uint8_t *hdr = (uint8_t*) &msg_report_out; | ||
|
||
for (size_t i = 0; i < 32; i++) { | ||
fprintf(stderr, "%02x", hdr[i]); | ||
if (i % 16 == 15) | ||
fprintf(stderr, "\n"); | ||
else | ||
fprintf(stderr, " "); | ||
} | ||
fprintf(stderr, "Attestation report:\n"); | ||
printReport(&msg_report_out.report); | ||
#endif | ||
|
||
*snp_report = (snp_attestation_report *) malloc (sizeof(snp_attestation_report)); | ||
memcpy(*snp_report, &msg_report_out.report, sizeof(snp_attestation_report)); | ||
|
||
return true; | ||
} |
Oops, something went wrong.