Skip to content

Commit 25d8bae

Browse files
committed
AA: get_token API add runtime_data paramter
Signed-off-by: Jiale Zhang <[email protected]>
1 parent 8b0dbeb commit 25d8bae

File tree

15 files changed

+141
-34
lines changed

15 files changed

+141
-34
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api-server-rest/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ $ curl http://127.0.0.1:8006/cdh/resource/default/key/1
1313
$ curl http://127.0.0.1:8006/aa/evidence\?runtime_data\=xxxx
1414
{"svn":"1","report_data":"eHh4eA=="}
1515

16-
$ curl http://127.0.0.1:8006/aa/token\?token_type\=kbs
16+
$ curl http://127.0.0.1:8006/aa/token\?token_type\=kbs\?structured_runtime_data=xxx
1717
{"token":"eyJhbGciOiJFi...","tee_keypair":"-----BEGIN... "}
1818
```

api-server-rest/build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ use utoipa::OpenApi;
1212
get,
1313
path = "/aa/token",
1414
params(
15-
("token_type" = String, Query, description = "Token Type")
15+
("token_type" = String, Query, description = "Token Type"),
16+
("structured_runtime_data" = Option<String>, Query, description = "Structured data in JSON format, which will be hashed as runtime data")
1617
),
1718
responses(
1819
(status = 200, description = "success response",

api-server-rest/openapi/api.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@
8080
"schema": {
8181
"type": "string"
8282
}
83+
},
84+
{
85+
"name": "structured_runtime_data",
86+
"in": "query",
87+
"description": "Structured data in JSON format, which will be hashed as runtime data",
88+
"required": false,
89+
"schema": {
90+
"type": "string",
91+
"nullable": true
92+
}
8393
}
8494
],
8595
"responses": {

api-server-rest/protos/attestation_agent.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ message GetEvidenceResponse {
1212

1313
message GetTokenRequest {
1414
string TokenType = 1;
15+
optional string StructuredRuntimeData = 2;
1516
}
1617

1718
message GetTokenResponse {

api-server-rest/src/aa.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@ impl ApiHandler for AAClient {
5757
match url_path {
5858
AA_TOKEN_URL => match params.get("token_type") {
5959
Some(token_type) => {
60+
let default_structed_runtime_data = String::from("{}");
61+
let structured_runtime_data = params
62+
.get("structured_runtime_data")
63+
.unwrap_or(&default_structed_runtime_data);
6064
let results = self
61-
.get_token(token_type)
65+
.get_token(token_type, &structured_runtime_data)
6266
.await
6367
.unwrap_or_else(|e| e.to_string().into());
6468
return self.octet_stream_response(results);
@@ -95,9 +99,14 @@ impl AAClient {
9599
})
96100
}
97101

98-
pub async fn get_token(&self, token_type: &str) -> Result<Vec<u8>> {
102+
pub async fn get_token(
103+
&self,
104+
token_type: &str,
105+
structured_runtime_data: &str,
106+
) -> Result<Vec<u8>> {
99107
let req = GetTokenRequest {
100108
TokenType: token_type.to_string(),
109+
StructuredRuntimeData: Some(structured_runtime_data.to_string()),
101110
..Default::default()
102111
};
103112
let res = self

api-server-rest/src/ttrpc_proto/attestation_agent.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ pub struct GetTokenRequest {
275275
// message fields
276276
// @@protoc_insertion_point(field:attestation_agent.GetTokenRequest.TokenType)
277277
pub TokenType: ::std::string::String,
278+
// @@protoc_insertion_point(field:attestation_agent.GetTokenRequest.StructuredRuntimeData)
279+
pub StructuredRuntimeData: ::std::option::Option<::std::string::String>,
278280
// special fields
279281
// @@protoc_insertion_point(special_field:attestation_agent.GetTokenRequest.special_fields)
280282
pub special_fields: ::protobuf::SpecialFields,
@@ -292,13 +294,18 @@ impl GetTokenRequest {
292294
}
293295

294296
fn generated_message_descriptor_data() -> ::protobuf::reflect::GeneratedMessageDescriptorData {
295-
let mut fields = ::std::vec::Vec::with_capacity(1);
297+
let mut fields = ::std::vec::Vec::with_capacity(2);
296298
let mut oneofs = ::std::vec::Vec::with_capacity(0);
297299
fields.push(::protobuf::reflect::rt::v2::make_simpler_field_accessor::<_, _>(
298300
"TokenType",
299301
|m: &GetTokenRequest| { &m.TokenType },
300302
|m: &mut GetTokenRequest| { &mut m.TokenType },
301303
));
304+
fields.push(::protobuf::reflect::rt::v2::make_option_accessor::<_, _>(
305+
"StructuredRuntimeData",
306+
|m: &GetTokenRequest| { &m.StructuredRuntimeData },
307+
|m: &mut GetTokenRequest| { &mut m.StructuredRuntimeData },
308+
));
302309
::protobuf::reflect::GeneratedMessageDescriptorData::new_2::<GetTokenRequest>(
303310
"GetTokenRequest",
304311
fields,
@@ -320,6 +327,9 @@ impl ::protobuf::Message for GetTokenRequest {
320327
10 => {
321328
self.TokenType = is.read_string()?;
322329
},
330+
18 => {
331+
self.StructuredRuntimeData = ::std::option::Option::Some(is.read_string()?);
332+
},
323333
tag => {
324334
::protobuf::rt::read_unknown_or_skip_group(tag, is, self.special_fields.mut_unknown_fields())?;
325335
},
@@ -335,6 +345,9 @@ impl ::protobuf::Message for GetTokenRequest {
335345
if !self.TokenType.is_empty() {
336346
my_size += ::protobuf::rt::string_size(1, &self.TokenType);
337347
}
348+
if let Some(v) = self.StructuredRuntimeData.as_ref() {
349+
my_size += ::protobuf::rt::string_size(2, &v);
350+
}
338351
my_size += ::protobuf::rt::unknown_fields_size(self.special_fields.unknown_fields());
339352
self.special_fields.cached_size().set(my_size as u32);
340353
my_size
@@ -344,6 +357,9 @@ impl ::protobuf::Message for GetTokenRequest {
344357
if !self.TokenType.is_empty() {
345358
os.write_string(1, &self.TokenType)?;
346359
}
360+
if let Some(v) = self.StructuredRuntimeData.as_ref() {
361+
os.write_string(2, v)?;
362+
}
347363
os.write_unknown_fields(self.special_fields.unknown_fields())?;
348364
::std::result::Result::Ok(())
349365
}
@@ -362,12 +378,14 @@ impl ::protobuf::Message for GetTokenRequest {
362378

363379
fn clear(&mut self) {
364380
self.TokenType.clear();
381+
self.StructuredRuntimeData = ::std::option::Option::None;
365382
self.special_fields.clear();
366383
}
367384

368385
fn default_instance() -> &'static GetTokenRequest {
369386
static instance: GetTokenRequest = GetTokenRequest {
370387
TokenType: ::std::string::String::new(),
388+
StructuredRuntimeData: ::std::option::Option::None,
371389
special_fields: ::protobuf::SpecialFields::new(),
372390
};
373391
&instance
@@ -517,12 +535,14 @@ static file_descriptor_proto_data: &'static [u8] = b"\
517535
\n\x17attestation_agent.proto\x12\x11attestation_agent\"6\n\x12GetEviden\
518536
ceRequest\x12\x20\n\x0bRuntimeData\x18\x01\x20\x01(\x0cR\x0bRuntimeData\
519537
\"1\n\x13GetEvidenceResponse\x12\x1a\n\x08Evidence\x18\x01\x20\x01(\x0cR\
520-
\x08Evidence\"/\n\x0fGetTokenRequest\x12\x1c\n\tTokenType\x18\x01\x20\
521-
\x01(\tR\tTokenType\"(\n\x10GetTokenResponse\x12\x14\n\x05Token\x18\x01\
522-
\x20\x01(\x0cR\x05Token2\xcc\x01\n\x17AttestationAgentService\x12\\\n\
523-
\x0bGetEvidence\x12%.attestation_agent.GetEvidenceRequest\x1a&.attestati\
524-
on_agent.GetEvidenceResponse\x12S\n\x08GetToken\x12\".attestation_agent.\
525-
GetTokenRequest\x1a#.attestation_agent.GetTokenResponseb\x06proto3\
538+
\x08Evidence\"\x84\x01\n\x0fGetTokenRequest\x12\x1c\n\tTokenType\x18\x01\
539+
\x20\x01(\tR\tTokenType\x129\n\x15StructuredRuntimeData\x18\x02\x20\x01(\
540+
\tH\0R\x15StructuredRuntimeData\x88\x01\x01B\x18\n\x16_StructuredRuntime\
541+
Data\"(\n\x10GetTokenResponse\x12\x14\n\x05Token\x18\x01\x20\x01(\x0cR\
542+
\x05Token2\xcc\x01\n\x17AttestationAgentService\x12\\\n\x0bGetEvidence\
543+
\x12%.attestation_agent.GetEvidenceRequest\x1a&.attestation_agent.GetEvi\
544+
denceResponse\x12S\n\x08GetToken\x12\".attestation_agent.GetTokenRequest\
545+
\x1a#.attestation_agent.GetTokenResponseb\x06proto3\
526546
";
527547

528548
/// `FileDescriptorProto` object which was a source for this generated file

attestation-agent/app/src/rpc/attestation/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ pub mod grpc {
4545
debug!("Call AA to get token ...");
4646

4747
let token = attestation_agent
48-
.get_token(&request.token_type)
48+
.get_token(
49+
&request.token_type,
50+
&request
51+
.structured_runtime_data
52+
.unwrap_or_else(|| String::from("{}")),
53+
)
4954
.await
5055
.map_err(|e| {
5156
error!("Call AA to get token failed: {}", e);
@@ -156,7 +161,11 @@ pub mod ttrpc {
156161
let mut attestation_agent = attestation_agent_mutex_clone.lock().await;
157162

158163
let token = attestation_agent
159-
.get_token(&req.TokenType)
164+
.get_token(
165+
&req.TokenType,
166+
&req.StructuredRuntimeData
167+
.unwrap_or_else(|| String::from("{}")),
168+
)
160169
.await
161170
.map_err(|e| {
162171
error!("Call AA-KBC to get token failed: {}", e);

attestation-agent/kbs_protocol/src/token_provider/aa/attestation_agent.rs

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ pub struct GetTokenRequest {
275275
// message fields
276276
// @@protoc_insertion_point(field:attestation_agent.GetTokenRequest.TokenType)
277277
pub TokenType: ::std::string::String,
278+
// @@protoc_insertion_point(field:attestation_agent.GetTokenRequest.StructuredRuntimeData)
279+
pub StructuredRuntimeData: ::std::option::Option<::std::string::String>,
278280
// special fields
279281
// @@protoc_insertion_point(special_field:attestation_agent.GetTokenRequest.special_fields)
280282
pub special_fields: ::protobuf::SpecialFields,
@@ -292,13 +294,18 @@ impl GetTokenRequest {
292294
}
293295

294296
fn generated_message_descriptor_data() -> ::protobuf::reflect::GeneratedMessageDescriptorData {
295-
let mut fields = ::std::vec::Vec::with_capacity(1);
297+
let mut fields = ::std::vec::Vec::with_capacity(2);
296298
let mut oneofs = ::std::vec::Vec::with_capacity(0);
297299
fields.push(::protobuf::reflect::rt::v2::make_simpler_field_accessor::<_, _>(
298300
"TokenType",
299301
|m: &GetTokenRequest| { &m.TokenType },
300302
|m: &mut GetTokenRequest| { &mut m.TokenType },
301303
));
304+
fields.push(::protobuf::reflect::rt::v2::make_option_accessor::<_, _>(
305+
"StructuredRuntimeData",
306+
|m: &GetTokenRequest| { &m.StructuredRuntimeData },
307+
|m: &mut GetTokenRequest| { &mut m.StructuredRuntimeData },
308+
));
302309
::protobuf::reflect::GeneratedMessageDescriptorData::new_2::<GetTokenRequest>(
303310
"GetTokenRequest",
304311
fields,
@@ -320,6 +327,9 @@ impl ::protobuf::Message for GetTokenRequest {
320327
10 => {
321328
self.TokenType = is.read_string()?;
322329
},
330+
18 => {
331+
self.StructuredRuntimeData = ::std::option::Option::Some(is.read_string()?);
332+
},
323333
tag => {
324334
::protobuf::rt::read_unknown_or_skip_group(tag, is, self.special_fields.mut_unknown_fields())?;
325335
},
@@ -335,6 +345,9 @@ impl ::protobuf::Message for GetTokenRequest {
335345
if !self.TokenType.is_empty() {
336346
my_size += ::protobuf::rt::string_size(1, &self.TokenType);
337347
}
348+
if let Some(v) = self.StructuredRuntimeData.as_ref() {
349+
my_size += ::protobuf::rt::string_size(2, &v);
350+
}
338351
my_size += ::protobuf::rt::unknown_fields_size(self.special_fields.unknown_fields());
339352
self.special_fields.cached_size().set(my_size as u32);
340353
my_size
@@ -344,6 +357,9 @@ impl ::protobuf::Message for GetTokenRequest {
344357
if !self.TokenType.is_empty() {
345358
os.write_string(1, &self.TokenType)?;
346359
}
360+
if let Some(v) = self.StructuredRuntimeData.as_ref() {
361+
os.write_string(2, v)?;
362+
}
347363
os.write_unknown_fields(self.special_fields.unknown_fields())?;
348364
::std::result::Result::Ok(())
349365
}
@@ -362,12 +378,14 @@ impl ::protobuf::Message for GetTokenRequest {
362378

363379
fn clear(&mut self) {
364380
self.TokenType.clear();
381+
self.StructuredRuntimeData = ::std::option::Option::None;
365382
self.special_fields.clear();
366383
}
367384

368385
fn default_instance() -> &'static GetTokenRequest {
369386
static instance: GetTokenRequest = GetTokenRequest {
370387
TokenType: ::std::string::String::new(),
388+
StructuredRuntimeData: ::std::option::Option::None,
371389
special_fields: ::protobuf::SpecialFields::new(),
372390
};
373391
&instance
@@ -760,18 +778,20 @@ static file_descriptor_proto_data: &'static [u8] = b"\
760778
\n\x17attestation-agent.proto\x12\x11attestation_agent\"6\n\x12GetEviden\
761779
ceRequest\x12\x20\n\x0bRuntimeData\x18\x01\x20\x01(\x0cR\x0bRuntimeData\
762780
\"1\n\x13GetEvidenceResponse\x12\x1a\n\x08Evidence\x18\x01\x20\x01(\x0cR\
763-
\x08Evidence\"/\n\x0fGetTokenRequest\x12\x1c\n\tTokenType\x18\x01\x20\
764-
\x01(\tR\tTokenType\"(\n\x10GetTokenResponse\x12\x14\n\x05Token\x18\x01\
765-
\x20\x01(\x0cR\x05Token\"v\n\x1fExtendRuntimeMeasurementRequest\x12\x16\
766-
\n\x06Events\x18\x01\x20\x03(\x0cR\x06Events\x12)\n\rRegisterIndex\x18\
767-
\x02\x20\x01(\x04H\0R\rRegisterIndex\x88\x01\x01B\x10\n\x0e_RegisterInde\
768-
x\"\"\n\x20ExtendRuntimeMeasurementResponse2\xd2\x02\n\x17AttestationAge\
769-
ntService\x12\\\n\x0bGetEvidence\x12%.attestation_agent.GetEvidenceReque\
770-
st\x1a&.attestation_agent.GetEvidenceResponse\x12S\n\x08GetToken\x12\".a\
771-
ttestation_agent.GetTokenRequest\x1a#.attestation_agent.GetTokenResponse\
772-
\x12\x83\x01\n\x18ExtendRuntimeMeasurement\x122.attestation_agent.Extend\
773-
RuntimeMeasurementRequest\x1a3.attestation_agent.ExtendRuntimeMeasuremen\
774-
tResponseb\x06proto3\
781+
\x08Evidence\"\x84\x01\n\x0fGetTokenRequest\x12\x1c\n\tTokenType\x18\x01\
782+
\x20\x01(\tR\tTokenType\x129\n\x15StructuredRuntimeData\x18\x02\x20\x01(\
783+
\tH\0R\x15StructuredRuntimeData\x88\x01\x01B\x18\n\x16_StructuredRuntime\
784+
Data\"(\n\x10GetTokenResponse\x12\x14\n\x05Token\x18\x01\x20\x01(\x0cR\
785+
\x05Token\"v\n\x1fExtendRuntimeMeasurementRequest\x12\x16\n\x06Events\
786+
\x18\x01\x20\x03(\x0cR\x06Events\x12)\n\rRegisterIndex\x18\x02\x20\x01(\
787+
\x04H\0R\rRegisterIndex\x88\x01\x01B\x10\n\x0e_RegisterIndex\"\"\n\x20Ex\
788+
tendRuntimeMeasurementResponse2\xd2\x02\n\x17AttestationAgentService\x12\
789+
\\\n\x0bGetEvidence\x12%.attestation_agent.GetEvidenceRequest\x1a&.attes\
790+
tation_agent.GetEvidenceResponse\x12S\n\x08GetToken\x12\".attestation_ag\
791+
ent.GetTokenRequest\x1a#.attestation_agent.GetTokenResponse\x12\x83\x01\
792+
\n\x18ExtendRuntimeMeasurement\x122.attestation_agent.ExtendRuntimeMeasu\
793+
rementRequest\x1a3.attestation_agent.ExtendRuntimeMeasurementResponseb\
794+
\x06proto3\
775795
";
776796

777797
/// `FileDescriptorProto` object which was a source for this generated file

attestation-agent/lib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ resource_uri.workspace = true
1717
reqwest = { workspace = true, features = ["json"], optional = true }
1818
serde.workspace = true
1919
serde_json.workspace = true
20+
sha2.workspace = true
2021
strum.workspace = true
2122
thiserror.workspace = true
2223
tokio = { workspace = true, features = ["fs"] }

0 commit comments

Comments
 (0)