文档

核心模块

更新时间:

SDK 包含以下两个核心模块:

TrustRoot

TrustRoot是 SDK 的核心验证模块,负责验证可信计算应用的身份和计算行为。当初始化配置信息时,其中的信任根信息会注入到TrustRoot模块中。

信任根信息包括 IAS 根证书IASCACert、可信区代码度量值MrEnclave、可信区代码签发者公钥度量值MrSigner,在您首次初始化客户端时注入。您可以设置信任等级 TrustLevel,根据自身需求选择验证级别。

  • 信任等级为 0 时,不校验 MYTF 身份信息。

  • 信任等级为 1 时,校验 MrSigner,即验证该 MYTF 为蚂蚁区块链签发的可信计算引擎。

  • 信任等级为 2 时,校验 MrEnclave,即验证该 MYTF 可信区代码的度量值。

验证 MYTF 是否可信,实际上是验证 IAS Intel 远程验证服务对 MYTF 的远程认证报告。Remote Attestation远程认证流程会验证 MYTF 是否为正确的可信执行代码并生成远程认证报告 AVR。报告中包括 MYTF 代码信息和所在硬件信息。SDK 在初始化时,会自动获取 MYTF 的 AVR 报告,并对该 MYTF 进行核身校验。

参数

类型

说明

trustedMrEnclave

String

用户所信任的代码度量值

trustedMrSigner

String

用户所信任的 MYTF 签发者公钥度量值

trustedIASCert

String

IAS CA 根证书

domainName

String

域名

regionName

String

分区名

  • 使用示例

// 以下场景涉及到三方,第三方服务平台为用户提供隐私保护的可信计算服务,将业务逻辑写成TAPP,安装到 C3S 平台中
// 第三方服务平台安装 TAPP 后获取 MYTFInfo 和 TAPPInfo
 MYTFInfo mytfInfo = restClient.getMYTFInfo();
 TappInfo tappInfo = restClient.getTappInfo(tappId, tappVersion);

 // 第三方服务平台从 MYTFInfo 和 TAPPInfo 中提取证明并将证明提供给第三方服务平台的用户
 String providedMYTFProfile = mytfInfo.getMytfProfile();
 String providedTAPPProfile = tappInfo.getTappProfile();

// 第三方服务平台的用户本地设置信任根和验证方式
TrustRoot userTrustRoot = new TrustRoot(1, IAS_CA_CERT, MYTF_MRSIGNER, MYTF_MRENCLAVE);

// 第三方服务平台的用户验证服务平台提供的 MYTFProfile,检查 MYTFInfo 是否正确以确定第三方服务平台使用的是正确的 C3S 服务
Assert.assertTrue(userTrustRoot.loadMYTFInfo(providedMYTFProfile));

// 第三方服务平台的用户验证服务平台提供的 TAPPProfile,检查 tappInfo 是否正确以确定第三方服务平台使用的是正确的 TAPP
TappInfo tappInfo1 = userTrustRoot.getTappInfo(providedTAPPProfile);

KeyStore

KeyStore是 SDK 的密钥管理模块,负责管理可信计算过程中所需要的密钥,并提供加密、解密、签名、验签等接口。当用户初始化设置配置信息时,其中的密钥信息会注入到KeyStore模块中。

参数

类型

说明

accessKeypair

UserKeyPair

RSA 用户访问公私钥对

identityKeypair

ECCKeypair

ECC 用户身份公私钥对

secretKeypair

Keypair

ECC 用户隐私公私钥对

  • 使用示例

// 获取客户端中的 KeyStore
KeyStore keyStore = restClient.getKeyStore();

// 获取用户密钥
UserKeyPair userAccessKeyPair = restClient.getKeyStore().getAccessKeypair();
UserKeyPair userIdentityKeyPair = restClient.getKeyStore().getIdentityKeypair();
UserKeyPair userSecretKeyPair = restClient.getKeyStore().getSecretKeypair();

// 通过用户隐私密钥,构造并打开 tappEnvelope
String plainData = "this is test for envelopeOpen & envelopeBuild";
byte[] tappEnvelope = restClient.getKeyStore().buildTappEnvelope(tappInfo, plainData.getBytes());
byte[] envelopeRecoverPlainData = restClient.getKeyStore().openTappEnvelope(tappInfo, tappEnvelope);

// 通过用户访问密钥,进行RSA 签名、验签
String plainData2 = "this is test for RSASign & RSAVerify";
byte[] sig = restClient.getKeyStore().accessKeySign(plainData2.getBytes());
Assert.assertTrue(restClient.getKeyStore().accessKeyVerify(plainData2.getBytes(), sig));