Skip to content
This repository was archived by the owner on Mar 24, 2026. It is now read-only.

Commit bf865c7

Browse files
takuro-satoDomAyredarracottkapilvgitKenGordon
committed
Add Azure support
Co-authored-by: Dominic Ayre <dominicayre@microsoft.com> Co-authored-by: Joe Powell <joepowell@microsoft.com> Co-authored-by: Kapil Vaswani <kapilv@microsoft.com> Co-authored-by: Ken Gordon <Ken.Gordon@microsoft.com> Co-authored-by: Mahati Chamarthy <mahati.chamarthy@microsoft.com> Co-authored-by: Ronny Bjones <ronny.bjones@microsoft.com>
1 parent b503ce7 commit bf865c7

61 files changed

Lines changed: 3485 additions & 8 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.bazelrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,12 @@ build:instance_gcp --//:instance=gcp
111111

112112
build:instance_aws --//:instance=aws
113113

114+
build:instance_azure --//:instance=azure
115+
114116
build:platform_aws --//:platform=aws
115117

118+
build:platform_azure --//:platform=azure
119+
116120
build:platform_gcp --//:platform=gcp
117121

118122
build:local_aws --config=instance_local
@@ -128,5 +132,12 @@ build:gcp_gcp --config=platform_gcp
128132
build:aws_aws --config=instance_aws
129133
build:aws_aws --config=platform_aws
130134

135+
136+
build:local_azure --config=instance_local
137+
build:local_azure --config=platform_azure
138+
139+
build:azure_azure --config=instance_azure
140+
build:azure_azure --config=platform_azure
141+
131142
build:non_prod --//:build_flavor=non_prod
132143
build:prod --//:build_flavor=prod

BUILD.bazel

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright 2023 Google LLC
2+
# Copyright (C) Microsoft Corporation. All rights reserved.
23
#
34
# Licensed under the Apache License, Version 2.0 (the "License");
45
# you may not use this file except in compliance with the License.
@@ -20,6 +21,7 @@ string_flag(
2021
build_setting_default = "aws",
2122
values = [
2223
"aws",
24+
"azure",
2325
"gcp",
2426
"local",
2527
],
@@ -34,6 +36,14 @@ config_setting(
3436
visibility = ["//visibility:public"],
3537
)
3638

39+
config_setting(
40+
name = "azure_platform",
41+
flag_values = {
42+
":platform": "azure",
43+
},
44+
visibility = ["//visibility:public"],
45+
)
46+
3747
config_setting(
3848
name = "gcp_platform",
3949
flag_values = {
@@ -55,6 +65,7 @@ string_flag(
5565
build_setting_default = "aws",
5666
values = [
5767
"aws",
68+
"azure",
5869
"gcp",
5970
"local",
6071
],
@@ -69,6 +80,14 @@ config_setting(
6980
visibility = ["//visibility:public"],
7081
)
7182

83+
config_setting(
84+
name = "azure_instance",
85+
flag_values = {
86+
":instance": "azure",
87+
},
88+
visibility = ["//visibility:public"],
89+
)
90+
7291
config_setting(
7392
name = "gcp_instance",
7493
flag_values = {

scp/cc/azure/BUILD.bazel

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Portions Copyright (c) Microsoft Corporation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
load("@rules_cc//cc:defs.bzl", "cc_library")
16+
17+
package(default_visibility = ["//scp/cc/azure:__subpackages__"])
18+
19+
# A dummy library to propagate the include directories.
20+
cc_library(
21+
name = "include_dir",
22+
includes = ["."],
23+
)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Portions Copyright (c) Microsoft Corporation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
load("@rules_cc//cc:defs.bzl", "cc_library")
16+
17+
package(default_visibility = ["//visibility:public"])
18+
19+
cc_library(
20+
name = "aci_attestation_lib",
21+
srcs = glob(
22+
[
23+
"**/*.cc",
24+
"**/*.h",
25+
],
26+
),
27+
deps = [
28+
"@boost//:system",
29+
"@com_google_absl//absl/strings",
30+
"@com_google_absl//absl/log:check",
31+
":get-snp-report",
32+
"@nlohmann_json//:lib",
33+
"//scp/cc/core/utils/src:core_utils",
34+
],
35+
)
36+
37+
cc_library(
38+
name="get-snp-report",
39+
srcs=glob(["get-snp-report/*.c"]),
40+
hdrs=glob(["get-snp-report/*.h"]),
41+
)
42+
43+
cc_binary(
44+
name = "print_snp_json",
45+
srcs = ["print_snp_json.cc"],
46+
linkopts=['-static'],
47+
linkstatic=True,
48+
features = ["fully_static_link"],
49+
visibility = ["//visibility:public"],
50+
deps = [
51+
"aci_attestation_lib",
52+
],
53+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Portions Copyright (c) Microsoft Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
bool fetchAttestationReport5(const char* report_data_hexstring, void **snp_report);
20+
21+
// does /dev/sev exists. This is where the PSP is exposed in 5.15.*
22+
bool supportsDevSev();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Portions Copyright (c) Microsoft Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
bool fetchAttestationReport6(const char* report_data_hexstring, void **snp_report);
20+
21+
// 6.1 linux exposees the PSP via /dev/sev-guest
22+
23+
bool supportsDevSevGuest();
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Portions Copyright (c) Microsoft Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "get-snp-report.h"
18+
19+
bool fetchSnpReport(const char* report_data_hexstring, void** snp_report) {
20+
bool success = false;
21+
uint8_t *snp_report_hex;
22+
23+
if (supportsDevSev()) {
24+
success = fetchAttestationReport5(report_data_hexstring, (void*) &snp_report_hex);
25+
} else if (supportsDevSevGuest()) {
26+
success = fetchAttestationReport6(report_data_hexstring, (void*) &snp_report_hex);
27+
} else {
28+
fprintf(stderr, "No supported SNP device found\n");
29+
}
30+
31+
if (success) {
32+
*snp_report = snp_report_hex;
33+
return 0;
34+
}
35+
36+
return -1;
37+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Portions Copyright (c) Microsoft Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <fcntl.h>
18+
#include <stdbool.h>
19+
#include <stdint.h>
20+
#include <stdio.h>
21+
#include <stdlib.h>
22+
#include <string.h>
23+
#include <sys/ioctl.h>
24+
#include <sys/stat.h>
25+
#include <sys/types.h>
26+
27+
#include "fetch5.h"
28+
#include "fetch6.h"
29+
#include "snp-attestation.h"
30+
31+
bool fetchSnpReport(const char* report_data_hexstring, void** snp_report);
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Portions Copyright (c) Microsoft Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <sys/ioctl.h>
18+
#include <sys/types.h>
19+
#include <sys/stat.h>
20+
#include <fcntl.h>
21+
#include <stdio.h>
22+
#include <stdint.h>
23+
#include <unistd.h>
24+
#include <string.h>
25+
#include <stdbool.h>
26+
#include <stdlib.h>
27+
28+
#include "snp-attestation.h"
29+
#include "snp-ioctl5.h"
30+
31+
#include "helpers.h"
32+
33+
bool supportsDevSev()
34+
{
35+
return access("/dev/sev", W_OK) == 0;
36+
}
37+
38+
bool fetchAttestationReport5(const char* report_data_hexstring, void **snp_report)
39+
{
40+
msg_report_req msg_report_in;
41+
msg_response_resp msg_report_out;
42+
43+
int fd, rc;
44+
45+
struct sev_snp_guest_request payload = {
46+
.req_msg_type = SNP_MSG_REPORT_REQ,
47+
.rsp_msg_type = SNP_MSG_REPORT_RSP,
48+
.msg_version = 1,
49+
.request_len = sizeof(msg_report_in),
50+
.request_uaddr = (uint64_t) (void*) &msg_report_in,
51+
.response_len = sizeof(msg_report_out),
52+
.response_uaddr = (uint64_t) (void*) &msg_report_out,
53+
.error = 0
54+
};
55+
56+
memset((void*) &msg_report_in, 0, sizeof(msg_report_in));
57+
memset((void*) &msg_report_out, 0, sizeof(msg_report_out));
58+
59+
// the report data is passed as a hexstring which needs to be decoded into an array of
60+
// unsigned bytes
61+
// MAA expects a SHA-256. So we use left align the bytes in the report data
62+
63+
uint8_t *reportData = decodeHexString(report_data_hexstring, sizeof(msg_report_in.report_data));
64+
memcpy(msg_report_in.report_data, reportData, sizeof(msg_report_in.report_data));
65+
66+
// open the file descriptor of the PSP
67+
fd = open("/dev/sev", O_RDWR | O_CLOEXEC);
68+
69+
if (fd < 0) {
70+
fprintf(stderr, "Failed to open /dev/sev\n");
71+
return false;
72+
}
73+
74+
// issue the custom SEV_SNP_GUEST_MSG_REPORT sys call to the sev driver
75+
rc = ioctl(fd, SEV_SNP_GUEST_MSG_REPORT, &payload);
76+
77+
if (rc < 0) {
78+
fprintf(stderr, "Failed to issue ioctl SEV_SNP_GUEST_MSG_REPORT\n");
79+
return false;
80+
}
81+
82+
#ifdef DEBUG_OUTPUT
83+
fprintf(stderr, "Response header:\n");
84+
uint8_t *hdr = (uint8_t*) &msg_report_out;
85+
86+
for (size_t i = 0; i < 32; i++) {
87+
fprintf(stderr, "%02x", hdr[i]);
88+
if (i % 16 == 15)
89+
fprintf(stderr, "\n");
90+
else
91+
fprintf(stderr, " ");
92+
}
93+
fprintf(stderr, "Attestation report:\n");
94+
printReport(&msg_report_out.report);
95+
#endif
96+
97+
*snp_report = (snp_attestation_report *) malloc (sizeof(snp_attestation_report));
98+
memcpy(*snp_report, &msg_report_out.report, sizeof(snp_attestation_report));
99+
100+
return true;
101+
}

0 commit comments

Comments
 (0)