Skip to content

Commit b8825d2

Browse files
committed
doc: add documentation for golang/rust sdk
Signed-off-by: Ruoyu Ying <[email protected]>
1 parent 3a34a5d commit b8825d2

File tree

3 files changed

+506
-1
lines changed

3 files changed

+506
-1
lines changed

sdk/golang/README.md

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
# Confidential Cloud-Native Primitives SDK for Golang
2+
3+
The Confidential Cloud-Native Primitives (CCNP) project is the solution targeted on simplifying the use of Trusted Execution Environment (TEE) in cloud-native environment. Currently, there are 2 parts included in CCNP, the services and the SDK.
4+
5+
- Service is designed to hide the complexity of different TEE platforms and provides common interfaces and scalability for cloud-native environment.
6+
- SDK is to simplify the use of the service interface for development, it covers communication to the service and parses the results from the services.
7+
8+
The service supports attestation, measurement fetching and event log collecting of various platforms including Intel Trusted Domain Extensions (TDX), Trusted Platform Modules (TPM) and AMD SEV-SNP. More platforms will be supported later.
9+
10+
Attestation is a common process within TEE platform and TPM to verify if the software binaries were properly instantiated on a trusted platform. Third parties can leverage the attestation process to identify the trustworthiness of the platform (by checking the measurements or event logs) as well as the software running on it, in order to decide whether they shall put their confidential information/workload onto the platform.
11+
12+
CCNP, as the overall framework for attestation, measurement and event log fetching, provides user with both customer-facing SDK and overall framework. By leveraging this SDK, user can easily retrieve different kinds of measurements or evidence such as event logs. Working along with different verification services (such as Amber) and configurable policies, user can validate the trustworthiness of the platform and make further decision.
13+
14+
[Source code][source_code]
15+
| [Package (Go package)][ccnp_golang]
16+
| [API reference documentation][api_doc]
17+
18+
## Getting started
19+
20+
### Prerequisites
21+
In order to work properly, user need to have the backend services ready on the TEE or TPM enabled platform first. Please refer to each deployment guide reside in the [service](../../service/) folder to install the backend services.
22+
23+
### Install the package
24+
User can install the CCNP client library for Golang:
25+
26+
```
27+
go get github.com/cc-api/confidential-cloud-native-primitives/sdk/golang/ccnp
28+
```
29+
30+
## Key concepts and usage
31+
There are three major functionalities provided in this SDK:
32+
33+
* [CC report fetching](#cc-report)
34+
* [Measurement fetching](#measurement)
35+
* [Event log fetching](#event-log)
36+
37+
### CC Report
38+
39+
Using this SDK, user could fetch the report from different platforms, the service detect the platform automatically and return the report.
40+
41+
#### Example usage of the SDK
42+
43+
The interface input of CC report is `nonce` and `user_data`, both of them are optional and will be measured in the report.
44+
Here are the example usages of the SDK:
45+
46+
* Fetch report with a `nonce` and `user_data`
47+
```golang
48+
import (
49+
b64 "encoding/base64"
50+
"encoding/binary"
51+
"math"
52+
"math/rand"
53+
"fmt"
54+
"os"
55+
56+
"github.com/cc-api/cc-trusted-api/common/golang/cctrusted_base"
57+
"github.com/cc-api/confidential-cloud-native-primitives/sdk/golang/ccnp"
58+
)
59+
60+
func testGetCCReport() {
61+
sdk := ccnp.SDK{}
62+
63+
num := uint64(rand.Int63n(math.MaxInt64))
64+
b := make([]byte, 8)
65+
binary.LittleEndian.PutUint64(b, num)
66+
nonce := b64.StdEncoding.EncodeToString(b)
67+
68+
rawBytes := []byte("demo user data")
69+
userData := b64.StdEncoding.EncodeToString(rawBytes)
70+
report, err := sdk.GetCCReport(nonce, userData, nil)
71+
if err != nil {
72+
fmt.Println("Error in fetching cc report.")
73+
os.Exit(-1)
74+
}
75+
76+
fmt.Println("Dump the attestation report fetched.")
77+
report.Dump(cctrusted_base.QuoteDumpFormat(cctrusted_base.QuoteDumpFormatRaw))
78+
}
79+
80+
```
81+
82+
83+
### Measurement
84+
85+
Using this SDK, user could fetch various measurements from different perspective and categories.
86+
Basic support on measurement focus on the platform measurements, including TEE report, values within TDX RTMR registers or values reside in TPM PCR registers.
87+
There's also advanced support to provide measurement for a certain workload or container. The feature is still developing in progress.
88+
89+
#### Example usage of the SDK
90+
91+
Here are the example usages for measurement SDK:
92+
93+
* Fetch TEE IMR measurement of the current pod(Fetch IMR[0] in the example)
94+
```golang
95+
import(
96+
"os"
97+
"fmt"
98+
99+
"github.com/cc-api/cc-trusted-api/common/golang/cctrusted_base"
100+
"github.com/cc-api/confidential-cloud-native-primitives/sdk/golang/ccnp"
101+
)
102+
103+
func testGetCCMeasurement() {
104+
sdk := ccnp.SDK{}
105+
106+
// set the imr index to 0
107+
imr_index := 0
108+
alg := cctrusted_base.TPM_ALG_SHA384
109+
110+
measurement, err := sdk.GetCCMeasurement(imr_index, alg)
111+
if err != nil {
112+
os.Exit(-1)
113+
}
114+
115+
fmt.Println("Dump measurement fetched.")
116+
fmt.Println("AlgID: ", measurement.AlgID)
117+
fmt.Println("Digest:")
118+
fmt.Printf(" %02X", measurement.Hash)
119+
}
120+
121+
```
122+
123+
### Event log
124+
125+
Using this SDK, user can fetch the event logs to assist the attestation/verification process. It also enables two different categories of event logs - for the platform or for a single workload/container.
126+
From platform perspective, it can support different Trusted Execution Environment and TPM. This sdk can also do fetching on certain number of event logs.
127+
128+
#### Example usage of the SDK
129+
130+
Here are the example usages of the SDK:
131+
132+
* Fetch event log of platform and check the information inside
133+
```golang
134+
import(
135+
"os"
136+
"fmt"
137+
138+
"github.com/cc-api/cc-trusted-api/common/golang/cctrusted_base"
139+
"github.com/cc-api/confidential-cloud-native-primitives/sdk/golang/ccnp"
140+
)
141+
142+
func testGetCCEventLog() {
143+
sdk := ccnp.SDK{}
144+
145+
/*
146+
Another example to set start to 0 and count to 10 for event log retrieval
147+
start := int32(0)
148+
count := int32(10)
149+
eventLogs, err := sdk.GetCCEventLog(start, count)
150+
*/
151+
eventLogs, err := sdk.GetCCEventLog()
152+
if err != nil {
153+
fmt.Println("Error in fetching event logs.")
154+
os.Exit(-1)
155+
}
156+
157+
fmt.Println("Total ", len(eventLogs), " of event logs fetched.")
158+
for _, log := range eventLogs {
159+
log.Dump()
160+
}
161+
}
162+
163+
```
164+
165+
* Replay the event logs
166+
```golang
167+
import(
168+
"os"
169+
"fmt"
170+
171+
"github.com/cc-api/cc-trusted-api/common/golang/cctrusted_base"
172+
"github.com/cc-api/confidential-cloud-native-primitives/sdk/golang/ccnp"
173+
)
174+
175+
func testReplayCCEventLog() {
176+
sdk := ccnp.SDK{}
177+
178+
eventLogs, err := sdk.GetCCEventLog()
179+
if err != nil {
180+
fmt.Println("Error in fetching event logs.")
181+
os.Exit(-1)
182+
}
183+
184+
fmt.Println("Total ", len(eventLogs), " of event logs fetched.")
185+
res := sdk.ReplayCCEventLog(eventLogs)
186+
for key, value := range res {
187+
fmt.Println(key, ": ", value)
188+
}
189+
190+
}
191+
192+
```
193+
194+
## End-to-end examples
195+
196+
TBA.
197+
198+
## Troubleshooting
199+
200+
Troubleshooting information for the CCNP SDK can be found here.
201+
202+
## Next steps
203+
For more information about the Confidential Cloud-Native Primitives, please see our documentation page.
204+
205+
## Contributing
206+
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit the Contributor License Agreement site.
207+
208+
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
209+
210+
See [CONTRIBUTING.md](../../CONTRIBUTING.md) for details on building, testing, and contributing to these libraries.
211+
212+
## Provide Feedback
213+
If you encounter any bugs or have suggestions, please file an issue in the Issues section of the project.
214+
215+
<!-- LINKS -->
216+
[source_code]: https://github.com/cc-api/confidential-cloud-native-primitives/tree/main/sdk/golang
217+
[ccnp_golang]: https://pkg.go.dev/github.com/cc-api/confidential-cloud-native-primitives/sdk/golang/ccnp
218+
[api_doc]: https://github.com/cc-api/cc-trusted-api?tab=readme-ov-file#3-apis

sdk/golang/example/go-sdk-example.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/cc-api/confidential-cloud-native-primitives/sdk/golang/ccnp"
1313
)
1414

15-
// func to test GetCCMeasurement()
15+
// func to test GetCCReport()
1616
func testGetCCReport(sdk ccnp.SDK, logger *log.Logger) {
1717
logger.Println("Call [GetCCReport] to fetch attestation report...")
1818

0 commit comments

Comments
 (0)