Skip to content

Commit f9ade19

Browse files
authored
Merge pull request #131 from Dstack-TEE/kms-tcb
kms: Add tcbStatus and advisoryIds to BootInfo
2 parents 9648b93 + 085b747 commit f9ade19

File tree

17 files changed

+101
-11
lines changed

17 files changed

+101
-11
lines changed

kms/auth-eth/contracts/IAppAuth.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ interface IAppAuth {
1010
bytes32 mrAggregated;
1111
bytes32 mrSystem;
1212
bytes32 mrImage;
13+
string tcbStatus;
14+
string[] advisoryIds;
1315
}
1416

1517
function isAppAllowed(

kms/auth-eth/contracts/KmsAuth.sol

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ contract KmsAuth is
131131
}
132132

133133
// Function to deregister an aggregated MR measurement
134-
function removeKmsAggregatedMr(
135-
bytes32 mrAggregated
136-
) external onlyOwner {
134+
function removeKmsAggregatedMr(bytes32 mrAggregated) external onlyOwner {
137135
kmsAllowedAggregatedMrs[mrAggregated] = false;
138136
emit KmsAggregatedMrRemoved(mrAggregated);
139137
}
@@ -178,6 +176,14 @@ contract KmsAuth is
178176
function isKmsAllowed(
179177
AppBootInfo calldata bootInfo
180178
) external view returns (bool isAllowed, string memory reason) {
179+
// Check if the TCB status is up to date
180+
if (
181+
keccak256(abi.encodePacked(bootInfo.tcbStatus)) !=
182+
keccak256(abi.encodePacked("UpToDate"))
183+
) {
184+
return (false, "TCB status is not up to date");
185+
}
186+
181187
// Check if the aggregated MR is allowed
182188
if (!kmsAllowedAggregatedMrs[bootInfo.mrAggregated]) {
183189
return (false, "Aggregated MR not allowed");

kms/auth-eth/src/ethereum.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ export class EthereumBackend {
3636
deviceId: this.decodeHex(bootInfo.deviceId, 32),
3737
mrSystem: this.decodeHex(bootInfo.mrSystem, 32),
3838
mrAggregated: this.decodeHex(bootInfo.mrAggregated, 32),
39-
mrImage: this.decodeHex(bootInfo.mrImage, 32)
39+
mrImage: this.decodeHex(bootInfo.mrImage, 32),
40+
tcbStatus: bootInfo.tcbStatus,
41+
advisoryIds: bootInfo.advisoryIds
4042
};
4143
let response;
4244
if (isKms) {

kms/auth-eth/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export interface BootInfo {
2+
tcbStatus: string;
3+
advisoryIds: string[];
24
mrAggregated: string;
35
mrImage: string;
46
mrSystem: string;

kms/auth-eth/test/AppAuth.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ describe("AppAuth", function () {
7575
deviceId,
7676
mrAggregated,
7777
mrImage,
78-
mrSystem
78+
mrSystem,
79+
tcbStatus: "UpToDate",
80+
advisoryIds: []
7981
};
8082

8183
const [isAllowed, reason] = await appAuth.isAppAllowed(bootInfo);
@@ -85,6 +87,8 @@ describe("AppAuth", function () {
8587

8688
it("Should reject invalid app ID", async function () {
8789
const bootInfo = {
90+
tcbStatus: "UpToDate",
91+
advisoryIds: [],
8892
appId: ethers.Wallet.createRandom().address,
8993
composeHash,
9094
instanceId,
@@ -101,6 +105,8 @@ describe("AppAuth", function () {
101105

102106
it("Should reject unallowed compose hash", async function () {
103107
const bootInfo = {
108+
tcbStatus: "UpToDate",
109+
advisoryIds: [],
104110
appId: appId,
105111
composeHash: ethers.randomBytes(32),
106112
instanceId,

kms/auth-eth/test/ethereum.integration.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ describe('Integration Tests', () => {
3838
mrImage: ethers.encodeBytes32String('22'),
3939
composeHash: ethers.encodeBytes32String('33'),
4040
mrSystem: ethers.encodeBytes32String('44'),
41+
tcbStatus: "UpToDate",
42+
advisoryIds: []
4143
};
4244
});
4345

@@ -89,6 +91,8 @@ describe('Integration Tests', () => {
8991
beforeEach(async () => {
9092
appId = global.testContracts.appId;
9193
mockBootInfo = {
94+
tcbStatus: "UpToDate",
95+
advisoryIds: [],
9296
appId,
9397
composeHash: ethers.encodeBytes32String("33"),
9498
instanceId: ethers.Wallet.createRandom().address,

kms/auth-eth/test/ethereum.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ describe('EthereumBackend', () => {
2525

2626
// Create mock boot info with valid addresses
2727
mockBootInfo = {
28+
tcbStatus: "UpToDate",
29+
advisoryIds: [],
2830
appId,
2931
composeHash: ethers.encodeBytes32String('0x1234567890abcdef'),
3032
instanceId: ethers.Wallet.createRandom().address,

kms/auth-eth/test/main.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ jest.mock('../src/ethereum', () => {
1414
describe('Server', () => {
1515
let app: FastifyInstance;
1616
const mockBootInfo: BootInfo = {
17+
tcbStatus: "UpToDate",
18+
advisoryIds: [],
1719
mrAggregated: '0x1234',
1820
mrImage: '0x5678',
1921
mrSystem: '0x9012',

kms/auth-eth/test/setup.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ beforeAll(async () => {
4545
deviceId: ethers.encodeBytes32String("test-device-id"),
4646
mrSystem: ethers.encodeBytes32String("test-mr-system"),
4747
mrAggregated: ethers.encodeBytes32String("test-mr-aggregated"),
48-
mrImage: ethers.encodeBytes32String("test-mr-image")
48+
mrImage: ethers.encodeBytes32String("test-mr-image"),
49+
tcbStatus: "UpToDate",
50+
advisoryIds: []
4951
};
5052
// Register some test enclaves and images
5153
await kmsAuth.addKmsAggregatedMr(ethers.encodeBytes32String("11"));

kms/auth-eth/typechain-types/contracts/AppAuth.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export declare namespace IAppAuth {
3232
mrAggregated: BytesLike;
3333
mrSystem: BytesLike;
3434
mrImage: BytesLike;
35+
tcbStatus: string;
36+
advisoryIds: string[];
3537
};
3638

3739
export type AppBootInfoStructOutput = [
@@ -41,7 +43,9 @@ export declare namespace IAppAuth {
4143
deviceId: string,
4244
mrAggregated: string,
4345
mrSystem: string,
44-
mrImage: string
46+
mrImage: string,
47+
tcbStatus: string,
48+
advisoryIds: string[]
4549
] & {
4650
appId: string;
4751
composeHash: string;
@@ -50,6 +54,8 @@ export declare namespace IAppAuth {
5054
mrAggregated: string;
5155
mrSystem: string;
5256
mrImage: string;
57+
tcbStatus: string;
58+
advisoryIds: string[];
5359
};
5460
}
5561

0 commit comments

Comments
 (0)