跳到正文
Skillpedia
安全8.0k · #12726

crypto-protocol-diagram

它能做什么

这项技能读取安全通信协议的源代码、标准文档或形式化模型,并将其转换为消息流程图。适合需要理解握手或密钥交换的工程师和安全审查人员。

适用场景

  • ✓你需要绘制握手、密钥交换或其他多方加密流程时。
  • ✓你有一份描述协议的 RFC 或论文,想绘制其消息顺序时。
  • ✓你有一个 ProVerif 或 Tamarin 模型,想要一张易读的图时。

技能链接

https://github.com/trailofbits/skills/blob/main/plugins/trailmark/skills/crypto-protocol-diagram/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/trailofbits/skills/blob/main/plugins/trailmark/skills/crypto-protocol-diagram/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“你能画出这段密钥交换代码中的消息步骤图吗?”

每周 5 个新技能,1 分钟读完。

工作原理

它会找出谁向谁发送什么消息,以及每一步发生了哪种加密或签名操作,然后编写一个 Mermaid 时序图和一份纯文本版本。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Crypto Protocol Diagram

Produces a Mermaid sequenceDiagram (written to file) and an ASCII sequence diagram (printed inline) from either:

  • Source code implementing a cryptographic protocol, or
  • A specification — RFC, academic paper, pseudocode, informal prose, ProVerif (.pv), or Tamarin (.spthy) model.

Tools used: Read, Write, Grep, Glob, Bash, WebFetch (for URL specs).

Unlike the diagramming-code skill (which visualizes code structure), this skill extracts protocol semantics: who sends what to whom, what cryptographic transformations occur at each step, and what protocol phases exist.

For call graphs, class hierarchies, or module dependency maps, use the diagramming-code skill instead.

When to Use

  • User asks to diagram, visualize, or extract a cryptographic protocol
  • Input is source code implementing a handshake, key exchange, or multi-party protocol
  • Input is an RFC, academic paper, pseudocode, or formal model (ProVerif/Tamarin)
  • User names a specific protocol (TLS, Noise, Signal, X3DH, FROST)

When NOT to Use

  • User wants a call graph, class hierarchy, or module dependency map — use diagramming-code
  • User wants to formally verify a protocol — use mermaid-to-proverif (after generating the diagram)
  • Input has no cryptographic protocol semantics (no parties, no message exchange)

Rationalizations to Reject

Rationalization Why It's Wrong Required Action
"The protocol is simple, I can diagram from memory" Memory-based diagrams miss steps and invert arrows Read the source or spec systematically
"I'll skip the spec path since code exists" Code may diverge from the spec — both paths catch different bugs When both exist, run spec workflow first, then annotate code divergences
"Crypto annotations are optional decoration" Without crypto annotations, the diagram is just a message flow — useless for security review Annotate every cryptographic operation
"The abort path is obvious, no need for alt blocks" Implicit abort handling hides missing error checks Show every abort/error path with alt blocks
"I don't need to check the examples first" The examples define the expected output quality bar Study the relevant example before working on unfamiliar input
"ProVerif/Tamarin models are code, not specs" Formal models are specifications — they describe intended behavior, not implementation Use the spec workflow (S1–S5) for .pv and .spthy files

Workflow

Protocol Diagram Progress:
- [ ] Step 0: Determine input type (code / spec / both)
- [ ] Step 1 (code) or S1–S5 (spec): Extract protocol structure
- [ ] Step 6: Generate sequenceDiagram
- [ ] Step 7: Verify and deliver

Step 0: Determine Input Type

Before doing anything else, classify the input:

Signal Input type
Source file extensions (.py, .rs, .go, .ts, .js, .cpp, .c) Code
Function/class definitions, import statements Code
RFC-style section headers (§, Section X.Y, MUST/SHALL keywords) Spec
Algorithm/Protocol/Figure labels, mathematical notation Spec
ProVerif file (.pv) with process, let, in/out Spec
Tamarin file (.spthy) with rule, --[...]-> Spec
Plain prose or numbered steps describing a protocol Spec
Both source files and a spec document Both (annotate divergences with ⚠️)
  • Code only → skip to Step 1 below
  • Spec only → skip to Spec Workflow (S1–S5) below
  • Both → run Spec Workflow first, then use the code-reading steps to verify the implementation against the spec diagram and annotate any divergences with ⚠️
  • Ambiguous → ask the user: "Is this a source code file, a specification document, or both?"

Step 1: Locate Protocol Entry Points

Grep for function names, type names, and comments that reveal the protocol:

# Find handshake, session, round, phase entry points
rg -l "handshake|session_init|round[_0-9]|setup|keygen|send_msg|recv_msg" {targetDir}

# Find crypto primitives in use
rg "sign|verify|encrypt|decrypt|dh|ecdh|kdf|hkdf|hmac|hash|commit|reveal|share" \
    {targetDir} --type-add 'src:*.{py,rs,go,ts,js,cpp,c}' -t src -l

Start reading from the highest-level orchestration function — the one that calls into handshake phases or the main protocol loop.

Step 2: Identify Par

常见问题

支持哪些输入格式?

源代码、RFC、学术论文、伪代码、纯文字描述,以及 ProVerif 或 Tamarin 模型文件都可以使用。

图中会同时显示加密步骤和消息吗?

会。每个步骤都可以包含加密操作,例如签名或密钥派生。

这和代码结构图是一样的吗?

不一样。它展示的是协议消息,而不是函数调用或类的结构。

详情

作者的原始描述

Extracts protocol message flow from source code, RFCs, academic papers, pseudocode, informal prose, ProVerif (.pv), or Tamarin (.spthy) models and generates Mermaid sequenceDiagrams with cryptographic annotations. Use when diagramming a crypto protocol, visualizing a handshake or key exchange flow, extracting message flow from a spec or RFC, diagramming a ProVerif or Tamarin model, or drawing sequence diagrams for TLS, Noise, Signal, X3DH, Double Ratchet, FROST, DH, or ECDH protocols.

repo: trailofbits/skills

热度

GitHub 星标
8.0k
排名
#12726
许可证
CC-BY-SA-4.0
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能