1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#![feature(min_specialization)]

use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use tea_codec::pricing::Priced;
use tea_codec::serde::TypeId;
use tea_tapp_common::ra::PcrType;

pub mod error;

extern crate tea_codec as tea_sdk;

pub const NAME: &[u8] = b"tea:nitro";

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct AttestationDocRequest {
	pub user_data: Option<Vec<u8>>,
	pub nonce: Option<Vec<u8>>,
	pub pubkey: Option<Vec<u8>>,
}

pub type AttestationDocResponse = Vec<u8>;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PcrVerifyRequest {
	pub doc_request: AttestationDocRequest,
	pub doc_buf: AttestationDocResponse,
	pub pcr_slots: PcrVerifySlots,
	pub allow_dummy: bool,
}

pub type PcrVerifySlots = Vec<HashMap<PcrType, Vec<u8>>>;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RaPeerRequest {
	pub seq_number: u64,
	pub conn_id: String,
	pub doc_request: AttestationDocRequest,
}

#[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)]
#[price(10000)]
pub struct GetTeaIdRequest;
#[derive(Debug, Clone, Serialize, Deserialize, TypeId)]
pub struct GetTeaIdResponse(pub Vec<u8>);

#[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)]
#[price(10000)]
pub struct EphemeralPubkeyRequest;
#[derive(Debug, Clone, Serialize, Deserialize, TypeId)]
pub struct EphemeralPubkeyResponse(pub Vec<u8>);

#[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)]
#[price(10000)]
pub struct EphemeralKeyRequest;
#[derive(Debug, Clone, Serialize, Deserialize, TypeId)]
pub struct EphemeralKeyResponse(pub Vec<u8>);

#[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)]
#[price(10000)]
#[response(Vec<u8>)]
pub struct GenerateRandomRequest(pub u32);

#[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)]
#[price(10000)]
pub struct GenerateUuidRequest;
#[derive(Debug, Clone, Serialize, Deserialize, TypeId)]
pub struct GenerateUuidResponse(pub String);

#[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)]
#[price(10000)]
pub struct GetAttestationDocRequest(pub AttestationDocRequest);
#[derive(Debug, Clone, Serialize, Deserialize, TypeId)]
pub struct GetAttestationDocResponse(pub AttestationDocResponse);

#[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)]
#[price(10000)]
#[response(())]
pub struct VerifyAttestationDocRequest(pub PcrVerifyRequest);

#[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)]
#[price(10000)]
pub struct GetVerificationPcrsRequest(pub Vec<u8>);
#[derive(Debug, Clone, Serialize, Deserialize, TypeId)]
pub struct GetVerificationPcrsResponse(pub PcrVerifySlots);

#[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)]
#[price(10000)]
#[response(Vec<u8>)]
pub struct NitroEncryptRequest {
	pub tag: String,
	pub data: Vec<u8>,
}

#[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)]
#[price(10000)]
#[response(Vec<u8>)]
pub struct NitroDecryptRequest {
	pub tag: String,
	pub cipher_data: Vec<u8>,
}

#[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)]
#[price(10000)]
pub struct GenerateDataKeyRequest;
#[derive(Debug, Clone, Serialize, Deserialize, TypeId)]
pub struct GenerateDataKeyResponse {
	pub secret: Vec<u8>,
	pub ciphertext: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)]
#[price(10000)]
#[response(Vec<u8>)]
pub struct DecryptDataKeyRequest {
	pub ciphertext: String,
}