跳到主要内容

6. Alert Protocol (告警协议)

TLS 提供 Alert content type, 用于指示关闭信息和错误. 与其他 message 一样, alert message 会按照当前 connection state 加密.

alert message 携带 alert description 和一个 legacy field. 在早期 TLS 版本中, 该 legacy field 表示消息严重级别. alert 分为两类: closure alert 和 error alert. 在 TLS 1.3 中, 严重性隐含在所发送的 alert type 中, "level" 字段可以安全忽略. "close_notify" alert 用于表示 connection 某一方向的有序关闭. 收到该 alert 后, TLS 实现 SHOULD 向应用指示 end-of-data.

error alert 表示 connection 的中止关闭. 收到 error alert 后, TLS 实现 SHOULD 向应用指示错误, 并且 MUST NOT 允许在该 connection 上继续发送或接收任何数据. server 和 client MUST 忘记失败 connection 中建立的 secret value 和 key, 与 session ticket 关联的 PSK 除外, 后者如果可能也 SHOULD 丢弃.

第 6.2 节列出的所有 alert MUST 以 AlertLevel=fatal 发送, 并且无论 message 中 AlertLevel 为何, 接收时 MUST 视为 error alert. 未知 Alert type MUST 视为 error alert.

enum { warning(1), fatal(2), (255) } AlertLevel;

enum {
close_notify(0),
unexpected_message(10),
bad_record_mac(20),
record_overflow(22),
handshake_failure(40),
bad_certificate(42),
unsupported_certificate(43),
certificate_revoked(44),
certificate_expired(45),
certificate_unknown(46),
illegal_parameter(47),
unknown_ca(48),
access_denied(49),
decode_error(50),
decrypt_error(51),
protocol_version(70),
insufficient_security(71),
internal_error(80),
inappropriate_fallback(86),
user_canceled(90),
missing_extension(109),
unsupported_extension(110),
unrecognized_name(112),
bad_certificate_status_response(113),
unknown_psk_identity(115),
certificate_required(116),
no_application_protocol(120),
(255)
} AlertDescription;

struct {
AlertLevel level;
AlertDescription description;
} Alert;

6.1. Closure Alerts (关闭告警)

client 和 server 必须共享 connection 正在结束的知识, 以避免 truncation attack.

close_notify: 通知接收方 sender 不会再在该 connection 上发送任何 message. 收到 closure alert 后收到的任何数据 MUST 被忽略.

user_canceled: 通知接收方 sender 因与 protocol failure 无关的原因取消 handshake. 如果用户在 handshake 完成后取消操作, 更合适的方式是发送 "close_notify" 并关闭 connection. 此 alert SHOULD 后跟 "close_notify". 它通常具有 AlertLevel=warning.

任一方 MAY 通过发送 "close_notify" alert 发起关闭 connection 写侧. 每一方在关闭其 connection 写侧之前 MUST 发送 "close_notify" alert, 除非已经发送过某个 error alert. 这不会影响其 connection 读侧.

如果使用 TLS 的应用协议规定 TLS connection 关闭后仍可通过底层 transport 承载数据, TLS 实现 MUST 在向 application layer 指示 end-of-data 之前收到 "close_notify" alert.

6.2. Error Alerts (错误告警)

TLS 中的错误处理很简单. 检测到错误时, 检测方会向 peer 发送消息. 发送或收到 fatal alert message 后, 双方 MUST 立即关闭 connection.

实现遇到 fatal error condition 时, SHOULD 发送适当的 fatal alert, 并且 MUST 关闭 connection, 不再发送或接收任何额外数据. 当本规范使用 "terminate the connection" 和 "abort the handshake" 而未指定 alert 时, 表示实现 SHOULD 发送下述描述所指示的 alert. 当使用 "terminate the connection with an X alert" 或 "abort the handshake with an X alert" 时, 表示实现如果发送 alert, MUST 发送 alert X.

以下 error alert 被定义:

  • unexpected_message: 收到不适当的 message, 例如错误的 handshake message 或过早的 Application Data.
  • bad_record_mac: 收到无法 deprotect 的 record. 由于 AEAD algorithm 组合了解密和验证, 且为避免 side-channel attack, 所有 deprotection failure 都使用此 alert.
  • record_overflow: 收到长度超过 2^14 + 256 byte 的 TLSCiphertext record, 或解密为超过 2^14 byte 的 TLSPlaintext record.
  • handshake_failure: sender 无法在可用选项下协商出可接受的安全参数.
  • bad_certificate: certificate 损坏, 签名验证不正确等.
  • unsupported_certificate: certificate 类型不受支持.
  • certificate_revoked: certificate 已被签发者吊销.
  • certificate_expired: certificate 已过期或当前无效.
  • certificate_unknown: 处理 certificate 时出现其他未指定问题, 使其不可接受.
  • illegal_parameter: handshake 中某字段错误或与其他字段不一致.
  • unknown_ca: 收到有效 certificate chain 或 partial chain, 但无法定位 CA certificate 或无法匹配已知 trust anchor.
  • access_denied: 收到有效 certificate 或 PSK, 但访问控制决定不继续协商.
  • decode_error: message 因字段超出范围或长度不正确而无法解码.
  • decrypt_error: handshake 层密码操作失败, 包括无法验证签名, Finished message 或 PSK binder.
  • protocol_version: peer 尝试协商的 protocol version 可识别但不受支持.
  • insufficient_security: server 因要求比 client 支持项更安全的参数而无法协商时返回.
  • internal_error: 与 peer 或 protocol 正确性无关的内部错误导致无法继续.
  • inappropriate_fallback: server 响应 client 的无效连接重试尝试时发送.
  • missing_extension: endpoint 收到某 handshake message, 但其中缺少对于所提供 TLS version 或其他协商参数必须发送的 extension.
  • unsupported_extension: endpoint 收到某 handshake message, 其中包含在该消息中禁止出现的已知 extension, 或收到未在对应 ClientHello/CertificateRequest 中首先提供的 extension.
  • unrecognized_name: server 无法识别 client 通过 "server_name" extension 提供的名称.
  • bad_certificate_status_response: client 收到 server 通过 "status_request" extension 提供的无效或不可接受 OCSP response.
  • unknown_psk_identity: server 需要 PSK key establishment, 但 client 没有提供可接受的 PSK identity.
  • certificate_required: server 需要 client certificate, 但 client 未提供.
  • no_application_protocol: client 的 "application_layer_protocol_negotiation" extension 只通告 server 不支持的协议.

新的 Alert value 按第 11 节由 IANA 分配.