volcengine-python-sdk-aicc 0.0.41__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. bytedance/__init__.py +4 -0
  2. bytedance/jeddak_secure_channel/__init__.py +28 -0
  3. bytedance/jeddak_secure_channel/client.py +305 -0
  4. bytedance/jeddak_secure_channel/config.py +171 -0
  5. bytedance/jeddak_secure_channel/consts.py +5 -0
  6. bytedance/jeddak_secure_channel/crypto/__init__.py +14 -0
  7. bytedance/jeddak_secure_channel/crypto/aes.py +174 -0
  8. bytedance/jeddak_secure_channel/crypto/envelope.py +395 -0
  9. bytedance/jeddak_secure_channel/crypto/rsa.py +164 -0
  10. bytedance/jeddak_secure_channel/error.py +131 -0
  11. bytedance/jeddak_secure_channel/log/__init__.py +23 -0
  12. bytedance/jeddak_secure_channel/log/config.py +31 -0
  13. bytedance/jeddak_secure_channel/log/logger.py +88 -0
  14. bytedance/jeddak_secure_channel/logger_factory.py +134 -0
  15. bytedance/jeddak_secure_channel/ra.py +772 -0
  16. bytedance/jeddak_secure_channel/server.py +745 -0
  17. bytedance/jeddak_secure_channel/service/__init__.py +16 -0
  18. bytedance/jeddak_secure_channel/service/eps.py +133 -0
  19. bytedance/jeddak_secure_channel/service/eps_models.py +47 -0
  20. bytedance/jeddak_secure_channel/service/ras.py +88 -0
  21. bytedance/jeddak_secure_channel/service/tks.py +51 -0
  22. bytedance/jeddak_secure_channel/service/tks_models.py +334 -0
  23. bytedance/jeddak_secure_channel/utils.py +469 -0
  24. bytedance/jeddak_secure_model/model_automation_tool.py +181 -0
  25. bytedance/jeddak_secure_model/model_encryption.py +416 -0
  26. bytedance/jeddak_secure_model/model_hub_admin.py +116 -0
  27. bytedance/jeddak_secure_model/pcc_utils.py +279 -0
  28. bytedance/jeddak_secure_model/rds_utils.py +63 -0
  29. bytedance/tks/attester.py +41 -0
  30. bytedance/tks/client.py +629 -0
  31. bytedance/tks/consts.py +122 -0
  32. bytedance/tks/crypto/aes.py +47 -0
  33. bytedance/tks/crypto/ec.py +39 -0
  34. bytedance/tks/exceptions.py +22 -0
  35. bytedance/volcengine_aicc_sdk/__init__.py +14 -0
  36. bytedance/volcengine_aicc_sdk/aicc_client.py +277 -0
  37. bytedance/volcengine_aicc_sdk/aicc_inference.py +64 -0
  38. bytedance/volcengine_aicc_sdk/ark_inference_client.py +343 -0
  39. bytedance/volcengine_aicc_sdk/asr_inference_client.py +158 -0
  40. bytedance/volcengine_aicc_sdk/asr_websocket_client.py +705 -0
  41. bytedance/volcengine_aicc_sdk/auc_inference_client.py +305 -0
  42. bytedance/volcengine_aicc_sdk/common/__init__.py +0 -0
  43. bytedance/volcengine_aicc_sdk/common/aes.py +136 -0
  44. bytedance/volcengine_aicc_sdk/common/constant.py +4 -0
  45. bytedance/volcengine_aicc_sdk/common/error.py +21 -0
  46. bytedance/volcengine_aicc_sdk/common/log/__init__.py +24 -0
  47. bytedance/volcengine_aicc_sdk/common/log/config.py +31 -0
  48. bytedance/volcengine_aicc_sdk/common/log/logger.py +88 -0
  49. bytedance/volcengine_aicc_sdk/common/tos_utils.py +341 -0
  50. bytedance/volcengine_aicc_sdk/common/utils.py +45 -0
  51. bytedance/volcengine_aicc_sdk/cu_inference_client.py +292 -0
  52. bytedance/volcengine_aicc_sdk/deepseek_inference_client.py +501 -0
  53. bytedance/volcengine_aicc_sdk/secure_http_client.py +406 -0
  54. bytedance/volcengine_aicc_sdk/seedance_inference_client.py +500 -0
  55. bytedance/volcengine_aicc_sdk/seedream_inference_client.py +213 -0
  56. volcengine_python_sdk_aicc-0.0.41.dist-info/METADATA +79 -0
  57. volcengine_python_sdk_aicc-0.0.41.dist-info/RECORD +60 -0
  58. volcengine_python_sdk_aicc-0.0.41.dist-info/WHEEL +5 -0
  59. volcengine_python_sdk_aicc-0.0.41.dist-info/licenses/LICENSE +202 -0
  60. volcengine_python_sdk_aicc-0.0.41.dist-info/top_level.txt +1 -0
@@ -0,0 +1,16 @@
1
+ __all__ = [
2
+ "EpsClient",
3
+ "EpsClient",
4
+ "EpsConfig",
5
+ "EpsConfig",
6
+ "RasClient",
7
+ "RasConfig",
8
+ "TksAppOptions",
9
+ "TksClient",
10
+ "TksConfig",
11
+ ]
12
+
13
+ from .eps import EpsClient, EpsConfig
14
+ from .ras import RasClient, RasConfig
15
+ from .tks import TksClient, TksConfig
16
+ from .tks_models import AppOptions as TksAppOptions
@@ -0,0 +1,133 @@
1
+ """
2
+ 证明生成服务 (Evidence Provision Service, EPS) 的客户端.
3
+ """
4
+
5
+ __all__ = ["EpsClient", "EpsConfig"]
6
+
7
+ import logging
8
+ from dataclasses import dataclass
9
+
10
+ from typing_extensions import Any, Mapping
11
+
12
+ from .. import error
13
+ from .eps_models import Evidence, ExtendRuntimeMeasurementParams, NonceData
14
+
15
+ logger = logging.getLogger(__name__)
16
+
17
+
18
+ @dataclass
19
+ class EpsConfig:
20
+ """访问证明生成服务所需的配置."""
21
+
22
+ eps_url: str = "http://localhost:8006"
23
+ """EPS 服务 Attestation Agent 的 HTTP 地址."""
24
+
25
+
26
+ def aa_request(endpoint: str, params: Mapping[str, Any], config: EpsConfig) -> str:
27
+ """
28
+ 向 Attestation Agent 的指定端点发送 HTTP GET 请求.
29
+
30
+ Returns:
31
+ 响应体的字符串.
32
+ """
33
+ import requests
34
+
35
+ try:
36
+ response = requests.get(config.eps_url + endpoint, params)
37
+ except Exception as e:
38
+ logger.exception(f"Network error: service={config.eps_url} {endpoint=}")
39
+ raise error.NetworkError("EPS", config.eps_url, endpoint) from e
40
+
41
+ if response.status_code != 200:
42
+ logger.error(
43
+ f"Service error: service={config.eps_url} {endpoint=} code={response.status_code}"
44
+ )
45
+ raise error.ServiceError("EPS", config.eps_url, endpoint, f"code={response.status_code}")
46
+
47
+ content_type = response.headers.get("content-type", "")
48
+ if not (content_type.startswith("application/octet-stream") or content_type.startswith("application/json")
49
+ or content_type.startswith("text/plain")):
50
+ logger.error(f"Service error: service={config.eps_url} {endpoint=} {content_type=}")
51
+ raise error.ServiceError("EPS", config.eps_url, endpoint, f"{content_type=}")
52
+
53
+ try:
54
+ return str(response.content, encoding="utf-8")
55
+ except UnicodeDecodeError as e:
56
+ logger.exception(f"Service error: service={config.eps_url} {endpoint=}")
57
+ raise error.ServiceError("EPS", config.eps_url, endpoint, "cannot decode text") from e
58
+
59
+
60
+ @dataclass(eq=False)
61
+ class EpsClient:
62
+ """
63
+ 证明生成服务 (Evidence Provision Service, EPS) 的客户端.
64
+
65
+ 本类的所有方法是线程安全的.
66
+ """
67
+
68
+ config: EpsConfig
69
+ """访问证明生成服务所需的配置."""
70
+
71
+ def get_token(self, token_type: str) -> str:
72
+ """
73
+ 访问 Attestation Agent 的 `/aa/token` 端点, 获取令牌.
74
+
75
+ Returns:
76
+ 令牌.
77
+ """
78
+ return aa_request("/aa/token", {"token_type": token_type}, self.config)
79
+
80
+ def get_evidence_raw(self, nonce: str) -> str:
81
+ """
82
+ 访问 Attestation Agent 的 `/aa/evidence` 端点, 获取证明.
83
+
84
+ Returns:
85
+ JSON 编码的证明. 包含 `cc_eventlog`, `quote`, `aa_eventlog` 字段.
86
+ """
87
+ nonce_data = NonceData(runtime_data="", nonce=nonce, user_data="")
88
+
89
+ return aa_request("/aa/evidence", nonce_data, self.config)
90
+
91
+ def get_evidence(self, nonce: str) -> Evidence:
92
+ """
93
+ 访问 Attestation Agent 的 `/aa/evidence` 端点, 获取证明.
94
+
95
+ Returns:
96
+ 证明内容, 包含 `cc_eventlog`, `quote`, `aa_eventlog` 字段.
97
+ """
98
+ import json
99
+
100
+ raw = self.get_evidence_raw(nonce)
101
+
102
+ return json.loads(raw)
103
+
104
+ def get_eventlog(self, nonce: str) -> str:
105
+ """
106
+ 访问 Attestation Agent 的 `/aa/eventlog` 端点, 获取事件日志.
107
+
108
+ Returns:
109
+ Base64 编码的事件日志. 事件日志长度较大 (~1.5MB).
110
+ """
111
+ nonce_data = NonceData(runtime_data="", nonce=nonce, user_data="")
112
+
113
+ return aa_request("/aa/eventlog", nonce_data, self.config)
114
+
115
+ def get_quote(self, nonce: str) -> str:
116
+ """
117
+ 访问 Attestation Agent 的 `/aa/quote` 端点, 获取度量值.
118
+
119
+ Returns:
120
+ Base64 编码的度量值.
121
+ """
122
+ nonce_data = NonceData(runtime_data="", nonce=nonce, user_data="")
123
+
124
+ return aa_request("/aa/quote", nonce_data, self.config)
125
+
126
+ def get_extended_runtime_measurement(self, params: ExtendRuntimeMeasurementParams) -> str:
127
+ """
128
+ 访问 Attestation Agent 的 `/aa/extend_runtime_measurement` 端点, 获取运行时度量事件日志.
129
+
130
+ Returns:
131
+ 明文的运行时度量事件日志.
132
+ """
133
+ return aa_request("/aa/extend_runtime_measurement", params, self.config)
@@ -0,0 +1,47 @@
1
+ """
2
+ 证明生成服务 (EPS) 定义的数据类型.
3
+ """
4
+
5
+ from typing_extensions import NotRequired, TypedDict
6
+
7
+
8
+ class NonceData(TypedDict):
9
+ """
10
+ Attestation Agent 的 `/aa/evidence`, `/aa/quote`, `/aa/eventlog` 端点的请求体.
11
+ 目前 Attestation Agent 会将三个字段值直接连接.
12
+ """
13
+
14
+ runtime_data: str
15
+
16
+ nonce: str
17
+
18
+ user_data: str
19
+
20
+
21
+ class ExtendRuntimeMeasurementParams(TypedDict):
22
+ """
23
+ Attestation Agent 的 `/aa/extend_runtime_measurement` 端点的请求体.
24
+ """
25
+
26
+ domain: str
27
+
28
+ operation: str
29
+
30
+ context: str
31
+
32
+ register_index: NotRequired[int]
33
+
34
+
35
+ class Evidence(TypedDict):
36
+ """
37
+ Attestation Agent 的 `/aa/evidence` 端点的响应体.
38
+ """
39
+
40
+ cc_eventlog: str
41
+ """Base64 编码的事件日志. 事件日志长度较大 (~1.5MB)."""
42
+
43
+ quote: str
44
+ """Base64 编码的度量值."""
45
+
46
+ aa_eventlog: str
47
+ """明文的运行时度量事件日志."""
@@ -0,0 +1,88 @@
1
+ """
2
+ 远程证明服务 (Remote Attestation Service, RAS) 的客户端.
3
+ """
4
+
5
+ __all__ = ["RasClient", "RasConfig"]
6
+
7
+ import base64
8
+ import json
9
+ import logging
10
+ from dataclasses import dataclass
11
+
12
+ from typing_extensions import Any
13
+
14
+ from .. import error
15
+
16
+ # try:
17
+ # import grpc
18
+ #
19
+ # from .ras_models import attestation_pb2, attestation_pb2_grpc
20
+ # except ModuleNotFoundError:
21
+ # grpc = None
22
+ # attestation_pb2_grpc = None
23
+
24
+
25
+ logger = logging.getLogger(__name__)
26
+
27
+ KNOWN_TEE = ["SEV", "SGX", "SNP", "TDX", "Sample", "AzSnpVtpm", "CSV", "CCA", "AzTdxVtpm"]
28
+
29
+
30
+ @dataclass
31
+ class RasConfig:
32
+ """访问远程证明服务所需的配置."""
33
+
34
+ ras_address: str = "localhost:50004"
35
+ """远程证明服务的 GRPC 地址."""
36
+
37
+
38
+ def encode_base64_no_pad(data: Any) -> str:
39
+ return base64.urlsafe_b64encode(json.dumps(data).encode("utf-8")).decode("utf-8").rstrip("=")
40
+
41
+
42
+ @dataclass(eq=False)
43
+ class RasClient:
44
+ """
45
+ 远程证明服务 (Remote Attestation Service, RAS) 的客户端.
46
+
47
+ 本类的所有方法是线程安全的.
48
+ """
49
+
50
+ config: RasConfig
51
+ """访问远程证明服务所需的配置."""
52
+
53
+ def get_attestation_evaluation(self, tee: str, quote: str) -> str:
54
+ """
55
+ 访问远程证明服务的 AttestationRequest 端点来验证度量值.
56
+
57
+ Args:
58
+ tee: 所属 TEE 环境类型.
59
+ quote: Base64 编码的度量值. 参考 `EpsClient#get_quote()`.
60
+ Returns:
61
+ Base64 编码的验证令牌.
62
+ """
63
+ pass
64
+
65
+ # if grpc is None or attestation_pb2_grpc is None:
66
+ # raise error.ConfigError(self, "RAS depends on grpcio which is not installed")
67
+ #
68
+ # # An early sanity check.
69
+ # if tee not in KNOWN_TEE:
70
+ # raise error.ParamError("tee", f"Unknown TEE type '{tee}'")
71
+ #
72
+ # encoded_evidence = encode_base64_no_pad({"quote": quote})
73
+ # request = attestation_pb2.AttestationRequest( # pyright: ignore
74
+ # tee=tee, evidence=encoded_evidence, policy_ids=[]
75
+ # )
76
+ #
77
+ # try:
78
+ # channel = grpc.insecure_channel(self.config.ras_address)
79
+ # client = attestation_pb2_grpc.AttestationServiceStub(channel)
80
+ #
81
+ # response = client.AttestationEvaluate(request)
82
+ # except Exception as e:
83
+ # logger.exception(
84
+ # f"Network error service={self.config.ras_address} endpoint=AttestationEvaluate"
85
+ # )
86
+ # raise error.NetworkError("RAS", self.config.ras_address, "AttestationEvaluate") from e
87
+ #
88
+ # return response.attestation_token
@@ -0,0 +1,51 @@
1
+ """
2
+ 密钥管理服务 (Trusted Key Service, TKS) 的客户端.
3
+ TCA采用背调模式
4
+ """
5
+
6
+ __all__ = ["TksClient", "TksConfig"]
7
+
8
+ from dataclasses import dataclass, field
9
+ from typing_extensions import Any, Optional, Tuple
10
+
11
+ from .eps import EpsClient
12
+ from .ras import RasClient
13
+
14
+
15
+ @dataclass
16
+ class TksConfig:
17
+ """访问密钥管理服务所需的配置."""
18
+
19
+ tks_url: str = "http://localhost:6789"
20
+ """TKS 服务的 HTTP 地址."""
21
+
22
+ tks_timezone: float = 8.0
23
+ """TKS 服务使用的时区. 一般不需要修改."""
24
+
25
+ tks_enable_server_auth: bool = True
26
+ """
27
+ 是否对 TKS 服务提供的证明报告进行验证.
28
+ 默认为是.
29
+ """
30
+
31
+ tks_enable_bi_auth: bool = True
32
+ """
33
+ 是否将客户端的证明报告发送给 TKS 服务.
34
+ 默认为是.
35
+ """
36
+
37
+
38
+ @dataclass(eq=False)
39
+ class TksClient:
40
+ """
41
+ 密钥管理服务 (Trusted Key Service, TKS) 的客户端.
42
+
43
+ 本类的所有方法是线程安全的.
44
+ """
45
+
46
+ config: TksConfig
47
+ """访问密钥管理服务所需的配置."""
48
+
49
+ ras_client: Optional[RasClient] = field(repr=False, default=None)
50
+
51
+ eps_client: Optional[EpsClient] = field(repr=False, default=None)
@@ -0,0 +1,334 @@
1
+ """
2
+ 密钥管理服务 (TKS) 定义的数据类型.
3
+ """
4
+
5
+ from dataclasses import dataclass
6
+
7
+ from typing_extensions import Generic, Literal, NotRequired, Optional, TypedDict, TypeVar
8
+
9
+
10
+ class TksAuthHeaders(TypedDict):
11
+ AppID: str
12
+ """请求TKS的客户端的身份ID"""
13
+
14
+ Timestamp: str
15
+ """
16
+ Unix时间戳(UTC+8)
17
+ Example: 1722253648
18
+ """
19
+
20
+ Signature: NotRequired[str]
21
+ """
22
+ 对请求Body的签名,仅当账号注册时的认证方式带有cert时(cert | cert+zti)
23
+ """
24
+
25
+ Token: NotRequired[str]
26
+ """
27
+ 认证Token,仅当账号注册时的认证方式带有zti时(zti | cert+zti)
28
+ """
29
+
30
+
31
+ class ResponseError(TypedDict):
32
+ Code: int
33
+ """
34
+ 错误码
35
+ Example: 69905
36
+ """
37
+
38
+ Message: str
39
+ """
40
+ 请求处理错误原因,正常请求为空
41
+ Example: error occured while processing your request
42
+ """
43
+
44
+
45
+ class ResponseMeta(TypedDict):
46
+ Method: str
47
+ """
48
+ 请求方法
49
+ Example: KeyGet
50
+ """
51
+
52
+ Error: NotRequired[ResponseError]
53
+ """错误信息,在请求正常响应情况下为空"""
54
+
55
+
56
+ T = TypeVar("T")
57
+
58
+
59
+ class TksResponse(Generic[T], TypedDict):
60
+ ResponseMetadata: ResponseMeta
61
+ """描述响应状态的元信息"""
62
+
63
+ Result: NotRequired[T]
64
+ """返回结果,当请求出错时为空"""
65
+
66
+
67
+ class ClientChallenge(TypedDict):
68
+ NonceDown: str
69
+ """
70
+ 经过hex编码后,长度为256 bits的随机挑战值
71
+ Example: 5779d18b2b8718cef025282df2a313f154ad4f7b862b2948ecf6cf401de17634
72
+ """
73
+
74
+ RxpirationTime: int
75
+ """
76
+ 时区为UTC+8的Unix时间戳,表示随机挑战的过期时间
77
+ Example: 1721972547
78
+ """
79
+
80
+ ChallSig: int
81
+ """
82
+ 经过Based64编码后的,TKS针对challenge自身的签名。使用TKS RA阶段提供的cert对应的私钥签名(ECDSA-SECP384R1)
83
+ Example: yk63SiKLaBB7E0OVQs3Flw8NsTRNEYJIUos8s9F14sg=
84
+ """
85
+
86
+
87
+ class SecurityAttestation(TypedDict):
88
+ NonceUp: str
89
+ """
90
+ 随机字符串,针对TSK进行远程证明的挑战值(32随机bytes,经过Hex编码)
91
+ Example: a314b43502077cd89d21378b29954207aaf5b3848d4d7fa9f16682ba1f6f3317
92
+ """
93
+
94
+ BiAuth: NotRequired[bool]
95
+ """
96
+ 是否要求TKS挑战请求方
97
+ Example: true
98
+ """
99
+
100
+
101
+ class AttestationResult(TypedDict):
102
+ RAType: str
103
+ """
104
+ TKS提供的远程证明报告的类型
105
+ Example: sgx | tdx
106
+ """
107
+
108
+ Report: str
109
+ """
110
+ 经过base64编码后的远程证明报告,需要根据raType来进行验证
111
+ Example: MTIzNA==
112
+ """
113
+
114
+ Cert: str
115
+ """
116
+ 经过base64编码后的,PEM形式的证书(ECDH-SECP384R1-SHA256)
117
+ Example: LS0tLS1CRUdJTiBQVU==
118
+ """
119
+
120
+ DHParam: str
121
+ """
122
+ 经过base64编码后的,密钥协商公共参数(ECDH-SECP384R1-SHA256)
123
+ Example: LS0tLS1CRUdJTiBQVUJMSUMg
124
+ """
125
+
126
+ Challenge: NotRequired[ClientChallenge]
127
+ """当biAuth参数为true时,返回的针对请求方的挑战内容"""
128
+
129
+
130
+ class KMSInfo(TypedDict):
131
+ Type: Literal["tks"]
132
+ """托管密钥服务的类型,当前仅支持tks"""
133
+
134
+
135
+ class RAEvidence(TypedDict):
136
+ TEEType: str
137
+ """指定请求方的TEE类型"""
138
+
139
+ Report: str
140
+ """
141
+ 经过Base64编码的,请求方TEE生成的远程证明报告,需要包含clientChall中提供的随机挑战nonceDown
142
+ Example: OUeRWgdMoQahtmzTA0/36qA5Lh8wp8nIK/ySOe0wQeA=
143
+ """
144
+
145
+
146
+ class ZTIEvidence(TypedDict):
147
+ Token: str
148
+ """
149
+ 请求方的ZTI JWT Token
150
+ """
151
+
152
+
153
+ class CertEvidence(TypedDict):
154
+ Signature: str
155
+ """
156
+ 经过Base64编码的,请求方的私钥签名的nonceDown
157
+ Example: RZeo3OjJM/Gam+aiun+hNzD1mMnnJmpiWckLnVfqqBE=
158
+ """
159
+
160
+
161
+ class KeyIndex(TypedDict):
162
+ AppID: str
163
+ """
164
+ 指定要获取的密钥Owner的AppID (PSM)
165
+ Example: security.research.tks_owner
166
+ """
167
+
168
+ RingID: str
169
+ """
170
+ 密钥环ID
171
+ Example: 640a7c2a-c061-4964-b7d8-951e9272da21
172
+ """
173
+
174
+ KeyID: str
175
+ """
176
+ 指定要获取的密钥的ID
177
+ Example: d880cf63-7c3e-45e1-83e5-ab62ba3d3441
178
+ """
179
+
180
+
181
+ class KeyIndexWithVersion(KeyIndex):
182
+ Version: int
183
+ """
184
+ 返回Key的版本,从1开始
185
+ Example: 1
186
+ """
187
+
188
+
189
+ class ChallengeResponse(TypedDict):
190
+ ClientChall: NotRequired[ClientChallenge]
191
+ """
192
+ 在远程阶段获取到的,由TKS返回的挑战信息。
193
+ """
194
+
195
+ RAEvidence: NotRequired[RAEvidence]
196
+ """
197
+ 提供基于TEE远程证明相关的证明信息,当访问控制策略中包含RA类型时需要提供
198
+ """
199
+
200
+ ZTIEvidence: NotRequired[ZTIEvidence]
201
+ """
202
+ 提供基于ZTI相关的证明信息,当访问控制策略中包含ZTI类型时需要提供
203
+ """
204
+
205
+ CertEvidence: NotRequired[CertEvidence]
206
+ """
207
+ 提供基于证书相关的证明信息,当访问控制策略中包含Cert类型时需要提供
208
+ """
209
+
210
+
211
+ class KeyExportation(KeyIndex, ChallengeResponse):
212
+ DHParam: str
213
+ """
214
+ 经过Base64编码的,请求方的DH公共参数
215
+ Example: KGIW9H8TCIi+ZNwikN8cc4V2cTNzOi/VfLNF7oYBwvE=
216
+ """
217
+
218
+ KMSInfo: NotRequired[KMSInfo]
219
+ """
220
+ 描述密钥所在的KMS位置,当前仅支持TKS
221
+ """
222
+
223
+ Passport: NotRequired[str]
224
+ """
225
+ JWT Token。由TKS签发的访问Token,获取Token的参与方在验证通过可以直接获取密钥。
226
+ """
227
+
228
+
229
+ class ExportationResult(KeyIndexWithVersion):
230
+ Key: str
231
+ """
232
+ 经过Base64编码后的Key的密文,通过请求参数密钥协商出来的密钥加密(AES-256-GCM)
233
+ Example: aq1xcWeuyyKTDY8kXqgqk9TmBjhqFhwZB7+p0GgK60I=
234
+ """
235
+
236
+
237
+ class KeyCreation(TypedDict):
238
+ RingID: str
239
+ """
240
+ 密钥环ID(为空情况下,放置到用户的一个default密钥环下)
241
+ Example: 640a7c2a-c061-4964-b7d8-951e9272da21
242
+ """
243
+
244
+ KeyID: NotRequired[str]
245
+ """
246
+ 密钥ID,置空则由TKS随机分配一个UUID
247
+ Example: d880cf63-7c3e-45e1-83e5-ab62ba3d3441
248
+ """
249
+
250
+ KeyName: str
251
+ """
252
+ 密钥名称
253
+ Example: test-demo-key
254
+ """
255
+
256
+ KeyAlgo: str
257
+ """
258
+ 密钥算法(当前仅支持基于对称加密算法)
259
+ Example: SYMMTRIC_128 | SYMMTRIC_256
260
+ """
261
+
262
+ Source: Literal["external", "internal"]
263
+ """
264
+ 密钥来源
265
+ - external: 外部导入
266
+ - internal: 由TKS生成
267
+ Example: internal
268
+ """
269
+
270
+ Description: NotRequired[str]
271
+ """
272
+ 密钥描述信息
273
+ Example: Key for test
274
+ """
275
+
276
+ Lifetime: NotRequired[int]
277
+ """
278
+ 密钥生命周期,Unix时间戳(UTC+8)。默认情况为-1,表示无限期
279
+ Example: 1722254231
280
+ """
281
+
282
+ KMSInfo: NotRequired[KMSInfo]
283
+ """
284
+ 描述密钥托管位置
285
+ """
286
+
287
+ ACLRules: NotRequired[str]
288
+ """
289
+ 描述密钥的访问控制策略,JSON字符串,默认情况下允许所有人访问,即
290
+ {"default": "accept","rules": [],"range": "keyID","issueToken": "false"}
291
+ Example: {"type": "RA", "tee": "tdx", "measurements":
292
+ {"tdx.rtmr0": "561bf3eee22f", "tdx.rtmr1": "d4247b6bd6eb"}}
293
+ """
294
+
295
+
296
+ class KeyImportation(TypedDict):
297
+ RingID: str
298
+ """
299
+ 密钥环ID(为空情况下,放置到用户的一个default密钥环下
300
+ Example: 640a7c2a-c061-4964-b7d8-951e9272da21
301
+ """
302
+
303
+ KeyID: str
304
+ """
305
+ 密钥ID,置空则由TKS随机分配一个UUID
306
+ Example: d880cf63-7c3e-45e1-83e5-ab62ba3d3441
307
+ """
308
+
309
+ Key: str
310
+ """
311
+ 密钥密文。经过Base64编码后的密钥密文,加密密钥应通过AES-GCM-256加密,
312
+ AES密钥基于TKS公共参数协商得出(ECDH-SECP384R1-SHA256)。可为空,置空后密钥状态为empty
313
+ Example: wjBXVnzCFOc/NhQ6vXZhllGa1Kirs9VvE+GVSuYCEZM=
314
+ """
315
+
316
+ DHParam: str
317
+ """
318
+ 经过Base64编码后的请求方侧的密钥协商参数,帮助TKS派生出通信密钥(ECDH-SECP384R1-SHA256)
319
+ Example: wjBXVnzCFOc/NhQ6vXZhllGa1Kirs9VvE+GVSuYCEZM=
320
+ """
321
+
322
+
323
+ @dataclass
324
+ class AppOptions:
325
+ """特定于 App 的认证选项."""
326
+
327
+ id: str
328
+ """App ID."""
329
+
330
+ signing_key: Optional[str] = None
331
+ """PEM 格式的 App 私钥. 当 TKS 中 authType 设置为 cert 时使用."""
332
+
333
+ zti_token: Optional[str] = None
334
+ """ZTI 令牌. 当 TKS 中 authType 设置为 zti 时使用."""