Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

TLSOptions

继承: RefCounted < Object

客户端与服务器的 TLS 配置。

描述

TLSOptions 是对 StreamPeerTLSPacketPeerDTLS 类中配置选项的抽象。

无法直接实例化这个类的对象,应改用静态方法 clientclient_unsafeserver

# 创建 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)

方法

TLSOptions

client ( X509Certificate trusted_chain=null, String common_name_override="" ) static

TLSOptions

client_unsafe ( X509Certificate trusted_chain=null ) static

TLSOptions

server ( CryptoKey key, X509Certificate certificate ) static


方法说明

TLSOptions client ( X509Certificate trusted_chain=null, String common_name_override="" ) static

创建 TLS 客户端配置,验证证书及其通用名称(完整域名)。

你可以指定自定义的证书颁发机构信任链 trusted_chain(如果为 null 则使用默认 CA 列表)。如果你希望证书拥有服务器 FQDN 之外的通用名称,还可以提供通用名称覆盖 common_name_override

注意:在 Web 平台上,TLS 验证始终强制使用 Web 浏览器的 CA 列表。这是一种安全特性。


TLSOptions client_unsafe ( X509Certificate trusted_chain=null ) static

创建不安全的 TLS 客户端配置,证书验证为可选项。你可以选择提供有效的信任链 trusted_chain,但永远不会对证书的通用名称进行检查。这种配置不推荐用于测试之外的用途。

注意:在 Web 平台上,TLS 验证始终强制使用 Web 浏览器的 CA 列表。这是一种安全特性。


TLSOptions server ( CryptoKey key, X509Certificate certificate ) static

使用提供的密钥 key 和证书 certificate 创建 TLS 服务器配置。

注意:certificate 中应当包含签名 CA 的完整证书链(可以使用通用文本编辑器连接证书文件)。