Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
TLSOptions
继承: RefCounted < Object
客户端与服务器的 TLS 配置。
描述
TLSOptions 是对 StreamPeerTLS 和 PacketPeerDTLS 类中配置选项的抽象。
无法直接实例化这个类的对象,应改用静态方法 client()、client_unsafe() 或 server()。
# 创建 TLS 客户端配置,使用自定义 CA 信任链。
var client_trusted_cas = load("res://my_trusted_cas.crt")
var client_tls_options = TLSOptions.client(client_trusted_cas)
# 创建 TLS 服务器配置。
var server_certs = load("res://my_server_cas.crt")
var server_key = load("res://my_server_key.key")
var server_tls_options = TLSOptions.server(server_key, server_certs)
方法
client(trusted_chain: X509Certificate = null, common_name_override: String = "") static |
|
client_unsafe(trusted_chain: X509Certificate = null) static |
|
get_common_name_override() const |
|
get_own_certificate() const |
|
get_private_key() const |
|
get_trusted_ca_chain() const |
|
is_server() const |
|
is_unsafe_client() const |
|
server(key: CryptoKey, certificate: X509Certificate) static |
方法说明
TLSOptions client(trusted_chain: X509Certificate = null, common_name_override: String = "") static 🔗
创建 TLS 客户端配置,验证证书及其通用名称(完整域名)。
你可以指定自定义的证书颁发机构信任链 trusted_chain
(如果为 null
则使用默认 CA 列表)。如果你希望证书拥有服务器 FQDN 之外的通用名称,还可以提供通用名称覆盖 common_name_override
。
注意:在 Web 平台上,TLS 验证始终强制使用 Web 浏览器的 CA 列表。这是一种安全特性。
TLSOptions client_unsafe(trusted_chain: X509Certificate = null) static 🔗
创建不安全的 TLS 客户端配置,证书验证为可选项。你可以选择提供有效的信任链 trusted_chain
,但永远不会对证书的通用名称进行检查。这种配置不推荐用于测试之外的用途。
注意:在 Web 平台上,TLS 验证始终强制使用 Web 浏览器的 CA 列表。这是一种安全特性。
String get_common_name_override() const 🔗
返回使用 client() 创建时指定的通用名(域名)覆盖项。
X509Certificate get_own_certificate() const 🔗
返回使用 server() 创建时指定的 X509Certificate。
CryptoKey get_private_key() const 🔗
返回使用 server() 创建时指定的 CryptoKey。
X509Certificate get_trusted_ca_chain() const 🔗
返回使用 client() 或 client_unsafe() 创建时使用的 CA X509Certificate 链。
如果是通过 server() 创建的则返回 true
,否则返回 false
。
bool is_unsafe_client() const 🔗
如果是通过 client_unsafe() 创建的则返回 true
,否则返回 false
。
TLSOptions server(key: CryptoKey, certificate: X509Certificate) static 🔗
使用提供的密钥 key
和证书 certificate
创建 TLS 服务器配置。
注意:certificate
中应当包含签名 CA 的完整证书链(可以使用通用文本编辑器连接证书文件)。