Package: ccnp
Confidential Cloud-Native Primitives SDK for PythonThe 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.Service is designed to hide the complexity of different TEE platforms and provides common interfaces and scalability for cloud-native environment.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.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.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.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.Source code|Package (PyPI)|API reference documentationGetting startedPrerequisitesIn 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 theservicefolder to install the backend services.Install the packageUser can install the CCNP client library for Python with PyPI:pip install ccnpTo install from source code, user can use the following command:pip install -e .Key concepts and usageThere are three major functionalities provided in this SDK:Quote fetchingMeasurement fetchingEvent log fetchingQuoteUsing this SDK, user could fetch the quote from different platforms, the service detect the platform automatically and return the type and the quote.Quote type for platformTYPE_TDX - This provides the quote fetching based on Intel TDX.TYPE_TPM - This provides the quote fetching based on TPM.Example usage of quote SDKThe interface input of quote isnonceanduser_data, both of them are optional and will be measured in quote.
Here are the example usages of quote SDK:Fetch quote without any inputsfromccnpimportQuotequote=Quote.get_quote()print(quote.quote_type)print(quote.quote)Fetch quote with anonceimportsecretsfromccnpimportQuotenonce=secrets.token_urlsafe()quote=Quote.get_quote(nonce=nonce)print(quote.quote_type)print(quote.quote)Fetch quote with anonceanduser_dataimportbase64importsecretsfromccnpimportQuotenonce=secrets.token_urlsafe()user_data=base64.b64encode(b'This data should be measured.')quote=Quote.get_quote(nonce=nonce,user_data=user_data)print(quote.quote_type)print(quote.quote)# For TD quote, it includes RTMRs, TD report, etc.ifquote.quote_type==Quote.TYPE_TDX:print(quote.rtmrs)print(quote.tdreport)MeasurementUsing this SDK, user could fetch various measurements from different perspective and categories.
Basic support on measurement focus on the platform measurements, including TEE report, values within TDX RTMR registers or values reside in TPM PCR registers.
There's also advanced support to provide measurement for a certain workload or container. The feature is still developing in progress.MeasurementType for platformThe measurement SDK supports fetching different types of evidence depending on the environment.
Currently, CCNP supports the following categories of measurements:TYPE_TEE_REPORT - This provides the report fetching on various Trusted Execution Environment from all kinds of vendors, including Intel TDX, AMD SEV (Working in Progress), etc.TYPE_TDX_RTMR - This provides the measurement fetching on TDX RTMR. Users could fetch the measurement from one single RTMR register with its index.TYPE_TPM_PCR - This provides th measurement fetching on TPM PCR. Users could fetch measurement from one single PCR register with its index.Example usage of measurement SDKHere are the example usages for measurement SDK:Fetch TEE report base on platformfromccnpimportMeasurementfromccnpimportMeasurementType# Fetch TEE report without user datareport=Measurement.get_platform_measurement()# Fetch TEE report with user datadata="testing"report=Measurement.get_platform_measurement(MeasurementType.TYPE_TEE_REPORT,data)Fetch single RTMR measurement for platformfromccnpimportEventlogfromccnpimportMeasurementfromccnpimportMeasurementType# Fetch the value reside in register 1 of RTMRrtmr_measurement=Measurement.get_platform_measurement(MeasurementType.TYPE_TDX_RTMR,None,1)Fetch container measurement (Working in Progress)fromccnpimportMeasurementfromccnpimportMeasurementTypecontainer_measurement=Measurement.get_container_measurement()Event logUsing 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.
From platform perspective, it can support different Trusted Execution Environment and TPM. This sdk can also do fetching on certain number of event logs.EventlogType for platformTYPE_TDX - This provides the event log fetching based on Intel TDX.TYPE_TPM - This provides the event log fetching based on TPM.Example usage of Eventlog SDKHere are the example usages of eventlog SDK:Fetch event log of Intel TDX platform for platform and check the information insidefromccnpimportEventlogfromccnpimportEventlogType# default type for get_platform_eventlog() is 'TYPE_TDX'logs=Eventlog.get_platform_eventlog()# same as setting type as 'TYPE_TDX'logs=Eventlog.get_platform_eventlog(EventlogType.TYPE_TDX)# show total lengthprint(len(logs))# fetch event log attributesprint(logs[2].evt_type)print(logs[2].evt_type_str)print(logs[2].evt_size)print(logs[2].reg_idx)print(logs[2].alg_id)print(logs[2].event)print(logs[2].digest)# fetch 5 event logs from the second onelogs=Eventlog.get_platform_eventlog(EventlogType.TYPE_TDX,2,5)# show log length, which shall equal to 5print(len(logs))Fetch event log of TPM platform (Working in Progress)fromccnpimportEventlogfromccnpimportEventlogType# set type for get_platform_eventlog() as 'TYPE_TPM'logs=Eventlog.get_platform_eventlog(EventlogType.TYPE_TPM)Fetch event log for certain container (Working in Progress)fromccnpimportEventlogfromccnpimportEventlogTypelogs=Eventlog.get_container_eventlog()End-to-end examplesTBA.TroubleshootingTroubleshooting information for the CCNP SDK can be found here.Next stepsFor more information about the Confidential Cloud-Native Primitives, please see our documentation page.ContributingThis 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.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.SeeCONTRIBUTING.mdfor details on building, testing, and contributing to these libraries.Provide FeedbackIf you encounter any bugs or have suggestions, please file an issue in the Issues section of the project.