OSTEP:Distributed System Security
OSTEP:Distributed System Security
本篇对应 OSTEP Version 1.10 的 Chapter 57 “Distributed System Security”。核心问题是:当多个 machine 通过不受完全控制的 network 协作时,如何保护跨机器的 operations。
类型与定位
- 笔记类型:正文翻译/知识整理
- 翻译基准:官方 Distributed System Security
- 术语约定:distributed system、authentication、certificate、CA、replay、SSL/TLS、session key、password 等保留英文或中英并列。
- 图件说明:原文主要使用协议流程和文字说明,没有需要单独嵌入的 raster image;通信流程用 Mermaid 重绘。
TL;DR
distributed system 把 trust boundary 从一台 machine 扩展到多台 machine 和 network。远端节点可能冒充 trusted partner,network attacker 可以 forge、copy、replay、alter、destroy 或 delay message。解决方案依赖 authentication、certificate、cryptography、replay protection 和成熟的 SSL/TLS 类 protocol,但不能消除对 endpoint、CA 和 implementation 的信任。
目录
| 章节 | 内容 |
|---|---|
| 新的安全边界 | remote machine 与 hostile network |
| Authentication 的角色 | password 与 private key |
| Certificate 与 public key distribution | CA 建立绑定 |
| Replay 与 session protection | freshness、nonce 与 session key |
| Password authentication | 适用场景与网络传输 |
| SSL/TLS | 从 initial authentication 到 secure channel |
| 局限与工程原则 | trust、endpoint 与实现 |
新的安全边界
单机 OS 可以控制自己的 resource,但 distributed system 还需要信任:
- remote machine 是否正确执行 security policy;
- remote machine 给出的 credential 或 capability 是否有效;
- network 上的消息是否真的来自声称的 sender;
- message 是否被复制、延迟、重排、修改或删除。
可以把 network attacker 的能力抽象为:
flowchart LR
S[Sender] --> N[Untrusted network]
N --> R[Receiver]
A[Attacker] -. forge .-> N
A -. copy/replay .-> N
A -. alter/delay/destroy .-> N
cryptography 是主要工具,但只有在 algorithm、key、identity binding 和 protocol 都正确时才有意义。
Authentication 的角色
远端 authentication 的目标是让 receiver 获得足够证据,判断 incoming bits 是由哪个 principal 产生的。
两种常见方式:
| 方式 | 适合场景 | 依赖 |
|---|---|---|
| password | 大量 user 分别向一个 service 登录 | user 与 service 共享或验证 password |
| public key | 一个 service 向大量 clients 证明自己的 identity | service 保持 private key,clients 获得 public key |
password 证明“发送者知道这个 secret”;public key authentication 则可以让大量验证者相信“只有拥有 matching private key 的那一个主体能生成该证据”。
实际网络通信中,不应把 password 直接通过 untrusted network 发送。至少要先建立 confidentiality,更好的做法是建立保护整个 session 的 secure channel。
Certificate 与 public key distribution
public key 不需要保密,但必须确认它属于正确的 partner。face-to-face 交换可以建立这种绑定,但 Internet 中通常依赖 certificate。
certificate 的验证路径是:
sequenceDiagram
participant CA as Certificate Authority
participant S as Server
participant C as Client
S->>CA: request certificate for public key
CA->>CA: verify server identity and key
CA-->>S: signed certificate
S->>C: certificate
C->>C: verify CA signature and validity
C->>S: authenticated connection
CA 把 server identity、public key 和 metadata 放进 certificate,并用 CA private key 对其 hash 做 digital signature。client 使用 CA public key 验证 signature。
这种机制的信任不是“certificate 自证正确”,而是:
- client 信任 CA public key;
- client 信任 CA 的 identity verification;
- client 确认证书未过期、未撤销且适用于当前 server;
- server 确实持有 certificate 中对应的 private key。
certificate 可以从任意位置取得,因为验证者检查的是 signed contents,而不是下载位置本身;但 certificate lifecycle、CA compromise 和错误的 hostname validation 仍是关键风险。
以 Frobazz Inc. 为例,CA Acmesign 会先确认申请者确实是 Frobazz 的合法代表,再确认提交的 public key K_F 确实是 Frobazz 要使用的 key。CA 对 Frobazz 的 identity、K_F 和其他 metadata 计算 hash H_F,再用 CA private key 产生 digital signature S_F,最后把这些内容、CA identity 与 signature 组合成 certificate C_F。client 收到后,用相同的 hash 算法重新得到 H'_F,再用 Acmesign public key 验证 S_F 得到 H_F;二者一致时,client 才能确认 certificate 中的 key 是 CA 认为属于 Frobazz 的 key。
这里存在一个必须 bootstrap 的 trust chain:client 如何获得 Acmesign 的 public key?通常 browser 或 operating system 在安装时预置多个 trusted CA 的 keys。若建立自己的 distributed system,可以由参与者信任的一台 machine 签发 certificate,并把该 signing machine 的 public key 通过可信方式预先安装。若系统中的 machine 数量固定、public keys 可以手工分发,则可以完全不使用 certificate;certificate 的唯一目的就是可靠分发 public key。
certificate 只证明“trusted CA 曾经把这个 public key 绑定给这个 identity”,不证明发送 certificate 的人现在就拥有 matching private key。因此完成 certificate 检查后,还必须让 remote party 用 private key 证明 possession;同时还要检查 expiration、revocation、hostname 与当前用途。
certificate 只解决 public key 与 identity 的绑定,不自动授予 application permission。即使 client 确认 server 是真正的 server,仍需要判断该 server 是否能读取某个 object、执行某个 operation。相反,secure channel 也不能修复已经被 compromise 的 endpoint:endpoint 仍可能看到 plaintext、窃取 session key 或代表合法 user 发起请求。
Replay 与 session protection
攻击者不一定要理解 message 内容。若可以复制一条曾经有效的 message 并再次发送,就可能重复触发原操作。
防 replay 的核心是让每条 message 包含不应在其他 message 中重复的 freshness information,例如 nonce、counter、timestamp 或 session binding。协议还需规定:
- receiver 如何保存和检查已使用的 nonce;
- counter 是否单调、是否可能回绕;
- timestamp 的时钟偏差容忍范围;
- message 是否绑定到正确的 session、principal 和 operation;
- 失败与重试是否会产生新的 request identity。
不能只把普通 encryption 当成 replay protection。需要使用经过设计的标准 cryptographic protocol。
Password authentication
当一个 user 向 hosting many users 的 site 登录时,password 比为每个 user 配置 public key 更易部署。但密码的安全性要求:
- 传输时具备 confidentiality;
- service 端使用安全的 password storage;
- 防止 online guessing、replay 和 session hijacking;
- 认证后的后续 message 不能仅凭“曾经有一条 message 带着正确 password”就被信任。
典型过程是先用 public-key authentication 认证 site,再协商 session protection,然后在该 protected channel 中传输 user ID 和 password。成熟的协议还会将 initial authentication 绑定到后续 session,而不是每条 message 重新发送 password。
密码认证最适合只有两方需要知道某个 password 的场景:被认证的 user 和负责检查的 site。它不适合让 web site 向 user 证明“我是某个 site”,因为每个 user 都必须拥有能验证该 site 的独立 secret;这种方向更适合 public key。反过来,user 向 hosting many users 的 site 登录时,每个 user 都可以用自己的 password separately authenticate。
密码在 network 上的典型路径是:Alice 把 user ID 与 password 提供给 Frobazz site,但在发送前使用已经验证过的 Frobazz public key(或已经建立的 session protection)加密。仅加密 password 仍需考虑 replay;而且验证 password 的那一条 message 并不能自动认证同一连接上未来的所有 messages,因此 protocol 必须把初始认证与后续 session 绑定。
SSL/TLS
SSL 最初被设计为给 socket 增加 cryptographic protection;TLS 是其后续的标准化方向。抽象地看,secure channel 建立分为:
flowchart LR
A[Client hello] --> B[Server certificate]
B --> C[Verify identity]
C --> D[Key exchange]
D --> E[Session keys]
E --> F[Authenticated encrypted traffic]
public-key cryptography 用于 server authentication 和 key establishment,symmetric cryptography 用于之后的大量 traffic。每个 message 还需要 integrity/authentication protection,避免 attacker 修改或重排数据而不被发现。
SSL/TLS 的历史也说明:协议很难正确设计。应使用当前仍被维护、配置正确且经过广泛审查的 TLS implementation,不自行拼装“加密 socket”。
SSL/TLS 是 protocol,不是某个单独的 software package。不同 implementation 可能共享 protocol-level flaw,也可能只在某一个 implementation 中出现 bug;例如 Heartbleed 影响 OpenSSL 的实现细节,并不自动意味着所有 SSL/TLS implementation 都受影响。遇到安全公告时,应先区分 protocol flaw 与 implementation flaw。
建立新 connection 时,最好为该 connection 创建全新的 symmetric session key,即使同一个 partner 同时拥有多条 connection 也不应复用 key。双方先协商可接受的 cipher、hash、key-exchange 与 authentication 组合;常见结构是 certificate 验证 server、authenticated Diffie–Hellman 建立新 session key,再用 symmetric authenticated encryption 传输 payload。典型 web browsing 中,client 验证 server,server 在 client 提交 password 之前并不知道 client 的 user identity;这并不妨碍 server 先提供 anonymous service。
Diffie–Hellman key exchange
Alice 与 Bob 可以在不安全 channel 上公开大质数 n 和 primitive element g。Alice 随机选择秘密 x,发送 X = g^x mod n;Bob 随机选择秘密 y,发送 Y = g^y mod n。Alice 计算 k = Y^x mod n,Bob 计算 k = X^y mod n;两者都得到 g^(xy) mod n,而监听者只能看到 g、n、X 和 Y。在参数足够大且满足要求时,从 public values 求出 x 或 y 等价于求解 computationally infeasible 的 discrete logarithm。
但 Diffie–Hellman 只保证双方共享一个 key,不保证双方是谁。Mallory 可以分别与 Alice、Bob 建立不同的 key,这就是 man-in-the-middle 的基础;因此实际 protocol 必须用 certificate 或其他 authentication mechanism 对 key exchange 的 message 签名。
常见的安全边界可以分成三层:先用 certificate/public-key mechanism 认证 endpoint,再用 key exchange 建立 session key,最后用 symmetric authenticated encryption 保护 traffic。每一层都要绑定正确的 hostname、session、principal 和 operation;否则攻击者可能把一个合法 message 搬到另一个 session 中重放。
局限与工程原则
distributed security 不能解决所有 trust problem:
- endpoint 已被攻陷时,网络加密不能阻止 endpoint 读取 plaintext;
- CA 或 trust store 被错误配置时,certificate binding 可能失效;
- private key 泄露后,攻击者可以冒充其 owner;
- application authorization 仍需单独设计;
- secure channel 只保护它覆盖的 path,不自动保护服务器内部的复制和存储。
工程上应坚持:
- 使用标准 cryptographic algorithms 和 protocol;
- 明确 threat model、trust anchor 和 key lifecycle;
- 为 message 添加 freshness 与 session binding;
- 区分 authentication、confidentiality、integrity 和 authorization;
- 把失败、撤销、rotation、logging 和 recovery 纳入设计。
Other authentication approaches
Cookie 与持续 session
网站通常不会要求 user 每点击一个 link 都重新输入 password。完成一次 password authentication 后,server 可以创建一个受 cryptography 保护的 web cookie,其中包含 client identity;browser 后续自动把 cookie 放回 request,server 据此恢复 authentication state。cookie 本质上是由 server 签发的 cryptographic capability。
这是一种 usability 与 security 的 trade-off:cookie 可以避免重复输入 password,但被复制的 cookie、共享或无人看管的 computer、以及浏览器退出后仍保留的 session 都会扩大风险。设计者必须明确 cookie 的 expiration、绑定范围、撤销方式与传输保护,不能把“用户曾经正确输入过 password”误认为永久安全。
Challenge/response 与 authentication server
在 challenge/response protocol 中,server 每次发送一个新的 challenge,通常是随机 number;client 用只有双方预先知道的 secret 对 challenge 执行 cryptographic operation,返回 response。由于每次 challenge 不同,复制旧 response 不能直接通过下一次检查,因此 challenge 与 response 本身不一定需要以 plaintext 传送。该机制仍要求 secret 或 hardware token 事先配置。
另一种方式是使用 authentication server:user 与一个信任它的 server 交互,目标 service 也信任该 authentication server;后者以 cryptographic form vouch for user identity。与 CA 这种较 offline 的绑定相比,online authentication server 能更快反映 compromised principal 的撤销状态。Kerberos 是此类方案的经典例子。
Higher-level tools:HTTPS 与 SSH
HTTPS
HTTP 本身没有 security feature。HTTPS 直接把 HTTP 放入 SSL/TLS connection:TLS 负责 certificate-based server authentication、session key 建立,以及后续 message 的 confidentiality 和 integrity。这样,应用开发者不必为 HTTP 重新设计一套 transport security。
HTTPS 的 certificate 只表示 trusted CA 曾为某个 public key 和 identity 背书;它不保证网站是善意的、不保证 private key 仍未泄露,也不保证 CA 在检查时没有被 compromise。经过 authentication 的网站仍可能攻击 client。若 browser 不支持 HTTPS,旧式 server 可能 fallback 到 HTTP,从而完全失去保护;HSTS(HTTP Strict Transport Security) 让 site 拒绝无法或不愿使用 HTTPS 的 client。
SSH 与 man-in-the-middle
SSH(Secure Shell)不是建立在 SSL 之上的另一个独立 implementation。它可以提供 remote shell、X Windows session 和 TCP port forwarding,并处理 remote authentication、key establishment、integrity 与 cipher negotiation。client 常通过 server public key/certificate 验证 server,也可以在此基础上再提交 user ID/password 或使用 Kerberos。
第一次通过 SSH 连接一个此前从未见过的 server 时,client 可能直接询问 server 的 public key 并保存它。若此时存在 man-in-the-middle,攻击者可以丢弃真实 key、替换为自己的 key;之后 client 以为自己在和 server 通信,实际上攻击者可以读取并修改双方 message。SSH 会对这种首次接受未知 key 的风险发出 warning,但用户习惯性点击确认并不能解决 trust bootstrap 问题。更稳妥的做法是通过独立可信 channel 预先核对 host key。
SSH 与 SSL/TLS 的 bug、features 和使用场景相互独立;一个 implementation 中的 flaw 不必然影响另一个。
原文逐段复核补充
Certificate 传输与 trust bootstrap
certificate 可以由 server 直接发送给 client,也可以由 client 通过其他 channel 获取;两者在 certificate 本身正确验证的前提下,安全性并不因传输路径而改变。certificate 的安全性来自其中的 cryptography,而不是来自“它从哪里下载”。真正需要 bootstrap 的是 trusted CA public key:browser 或 OS 往往在安装时预置一组 trusted CA keys;封闭的 distributed system 也可以通过可信方式预先安装某个 signing machine 的 key。如果参与者数量固定、public key 能手工分发,则可以完全不用 certificate,certificate 的核心价值就是可靠地分发 public key。
Diffie–Hellman 的完整边界
在不安全 channel 上,Alice 与 Bob 可以公开大 prime n 和满足要求的 primitive element g。Alice 随机选择秘密 x,发送 X = g^x mod n;Bob 随机选择秘密 y,发送 Y = g^y mod n。Alice 计算 k = Y^x mod n,Bob 计算 k = X^y mod n,二者都得到 g^(xy) mod n。监听者虽然知道 g、n、X 和 Y,却不能轻易求出 x 或 y;在参数足够大时,所需的 discrete logarithm computation 在实践中不可行。
但 Diffie–Hellman 只说明“你和某个持有相应秘密的一方共享了 key”,不说明那一方是谁。Mallory 可以分别与 Alice、Bob 建立两条不同的 secure connection,再转发和修改双方 message,这正是 man-in-the-middle attack。因此 server 通常用 private key 对自己的 Diffie–Hellman messages 签名,client 通过 certificate 验证它连到的是正确 server。常见 web browsing 中,client 通常没有自己的 certificate;SSL connection 建立后 server 已能保护 user ID/password,但在收到并检查 password 之前并不知道 client 的具体 identity,这对提供 anonymous service 并非问题。
原文的参数示例使用约 600 位的 prime 来说明数量级;这里的重点不是照搬某个历史参数,而是:公开的 n、g、X、Y 不应让监听者可行地恢复 shared key,且秘密 x、y 必须真正保密。
Cookie、challenge/response 与 authentication server
web cookie 是一次 password authentication 之后由 server 签发的 cryptographic capability。它让 browser 在后续 request 中自动携带 client identity,而不必每次重新输入 password。这样即使 browser 重启并建立了新的 cryptographic session,server 仍可依据 cookie 延续过去的 authentication state;这显然是 usability 与 security 的 trade-off。复制 cookie 的 network attacker 可以由合适的 cryptographic protection 处理,但使用同一台 browser 的其他人、无人看管的 computer 或 cookie 的过长保存期限,仍可能绕过“重新证明 identity”的要求。
challenge/response 中,server 每次发送新的 challenge(通常是 number),client 使用双方预先共享、只有 legitimate party 知道的 secret 对 challenge 计算 response。challenge 不重复,旧 response 就不能直接在下一次检查中重放,因此 challenge 和 response 本身不一定需要 encryption;但 secret、hardware token 或相关 data 必须事先完成配置和分发。
authentication server 则让 user 与一个 trusted server 交互,目标 service 也信任该 server。authentication server 以 cryptographic form vouch for user identity,目标 service 验证这份证明即可。CA/certificate 可以看作较 offline 的对应物;online authentication server 更容易立即撤销已经 compromise 的 principal。Kerberos 是此类方案的经典例子。
HTTPS、SSH 与“工具的保证范围”
HTTP 本身没有 security feature;HTTPS 的关键价值是直接把现有 HTTP 放入 SSL/TLS secure connection,复用 certificate-based server authentication、session-key establishment 和后续 traffic protection,而不是重新发明一套 web security protocol。HTTPS 主要适合 HTTP application protocol;如果自定义 application 不需要 HTTP 的 headers 和 ASCII-oriented message format,直接使用 SSL/TLS 或 SSH 可能更高效。
HTTPS 的 certificate 即使验证通过,也只说明某个时刻 CA 愿意为“某个 public key 属于某个 party”背书;它不保证该 party 善意、不保证 private key 现在仍保密,也不保证 CA 在签发或验证时没有被 compromise。HTTPS 主要保证 channel authentication,authenticated web site 仍可能攻击 client。HSTS 的作用是拒绝 fallback 到 HTTP 的 client,使该 site 的交互必须使用 HTTPS。
SSH 是独立于 SSL 的实现,而不是建立在 SSL 之上的 software package。它可以提供 remote shell、remote X Windows session、TCP port forwarding,并处理 remote authentication、key establishment、integrity check 和 cipher negotiation。首次连接陌生 host 时若直接接受 host key,攻击者可以在 trust bootstrap 阶段替换 key;SSH 的 warning 只能提示风险,不能替代通过独立可信 channel 核对 host key。
官方章节总结的边界
distributed system security 的核心,是确保连接各 component 的 insecure network 不引入新的 security problem:message 应被 encrypted、authenticated,并保持 privacy/integrity;SSL/TLS、SSH、HTTPS 与 X.509 certificate 让系统复用经过大量实践检验的工具。它们仍只提供有限保证,并不像 OS 在自己直接控制的 hardware 上执行 local operation 那样可靠。即使 authentication 和 encryption 都使用正确,系统设计者仍必须审慎考虑:是否要执行 remote site 请求的 operation,是否要向 remote site 提供 sensitive information,以及 machine boundary 之外发生的事情。
源文档核验记录
- 源文档:OSTEP Version 1.10 官方
security-distributed.pdf。 - 页数:20 页(含正文与 References)。
- 章节范围:Chapter 57 的 distributed-system security 主线,以及 certificate、password authentication、SSL/TLS、cookie、challenge/response、authentication server、HTTPS、SSH 等协议与工具讨论。
- 图件核对:原 PDF 没有需要另存的独立 raster 图片;协议流程已在对应语义位置用 Mermaid 重绘,公式与消息交换用代码块保留。
- 内容核对:已覆盖 certificate/trust bootstrap、Frobazz/Acmesign 示例、session key、replay、Diffie–Hellman、man-in-the-middle、password 与 secure channel、cookie、challenge/response、authentication server、Kerberos、SSL/TLS、HTTPS/HSTS、SSH host-key warning、endpoint/authorization 边界与完整官方 References。
原文 References
- [H14] The Heartbleed Bug,关于 OpenSSL implementation 中 Heartbleed vulnerability 的资料。
- [I12] ITU-T,《Information technology – Open Systems Interconnection – The Directory: Public-key and Attribute Certificate Frameworks》,2012;X.509 certificate 的格式与使用规范。
- [NT94] B. Clifford Neuman、Theodore Ts’o,《Kerberos: An authentication service for computer networks》,IEEE Communications Magazine,Vol. 32,No. 9,1994。
- [P16] The International PGP Home Page,2016。
关键结论
- distributed system 的主要新增风险来自 remote trust 和 untrusted network。
- password 更适合多用户向单一 service 认证;public key 更适合一个 service 向许多 clients 证明自己。
- certificate 依赖 CA 把 identity 与 public key 绑定。
- replay protection 需要 freshness 和 session context,不能只依赖 encryption。
- SSL/TLS 的典型结构是 public-key authentication/key exchange 加 symmetric session protection。
- secure communication 不等于完整 security;endpoint、authorization、CA 和 key management 仍必须可信。
官方总结可以压缩成一条 protocol 链路:先确认 remote endpoint 的 identity,再通过 key exchange 建立短期 session key,随后用 authenticated encryption 保护 traffic,并用 authorization 判断已认证 principal 是否可以执行具体 operation。每一步都只能解决自己的问题;例如 Diffie–Hellman 能建立 shared key 却不能单独证明对方身份,HTTPS 能保护 browser 与 server 之间的 channel 却不能保证 server 内部行为可信。
与已有笔记的关系
- OSTEP:Authentication:本篇将单机 identity verification 扩展到 network。
- OSTEP:Access Control:认证 remote principal 后,仍需执行具体 authorization policy。
- OSTEP:Cryptography:本篇使用 symmetric/public-key cryptography、hash、signature 与 certificate。
- 下一篇:OSTEP:Free-Space Management。
参考资料
评论 (0)