Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions .github/workflows/fips.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ jobs:
os: [ubuntu-24.04, ubuntu-24.04-arm]
provider: ["3.5.9", "3.1.2"]
include:
- { provider: "3.5.9", cmvp: "5586", mldsa: "offered" }
- { provider: "3.1.2", cmvp: "4985", mldsa: "refused" }
# `pq`: under 3.5.9 (ML-KEM approved) the CNSA 2.0 post-quantum TLS tests must run
# (SecP384r1MLKEM1024, ML-KEM-1024; X25519 is not approved, so X25519MLKEM768 is not
# offered in FIPS mode). Under 3.1.2 OTP still lists the ML-KEM groups but the handshake
# exits; the tests ask by trying and do not run there.
- { provider: "3.5.9", cmvp: "5586", mldsa: "offered", pq: "cnsa" }
- { provider: "3.1.2", cmvp: "4985", mldsa: "refused", pq: "" }
timeout-minutes: 45
env:
# Fixed absolute paths: the rpath, OpenSSL's MODULESDIR and OTP's ROOTDIR are baked in.
Expand Down Expand Up @@ -177,9 +181,19 @@ jobs:
mix deps.get
MIX_ENV=test mix compile

# OpenSSL's own client, for the post-quantum TLS tests' independent check: this job's 3.5.9
# command, through a wrapper so its library path reaches only it.
- name: the OpenSSL command the post-quantum TLS tests use
run: |
printf '#!/bin/sh\nLD_LIBRARY_PATH=%s/lib exec %s/bin/openssl "$@"\n' "$P" "$P" > "$RUNNER_TEMP/openssl"
chmod +x "$RUNNER_TEMP/openssl"
"$RUNNER_TEMP/openssl" version
echo "OPENSSL_CLI=$RUNNER_TEMP/openssl" >> "$GITHUB_ENV"

- name: the suite, in FIPS mode, asserted in the same VM before any test runs
env:
ELIXIR_ERL_OPTIONS: "-crypto fips_mode true"
PQ_TLS_REQUIRED: ${{ matrix.pq }}
run: >
elixir
-e 'Application.load(:crypto)'
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/flake-hunt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ jobs:
fail-fast: false
matrix:
include:
- { leg: floor, otp: "27", elixir: "1.17", os: ubuntu-24.04, version-type: loose }
- { leg: pinned, otp: "28", elixir: "1.18", os: ubuntu-24.04, version-type: loose }
- { leg: head, otp: "29", elixir: "1.20", os: ubuntu-24.04, version-type: loose }
- { leg: box, otp: "28.5.0.9", elixir: "1.20.4", os: ubuntu-26.04-arm, version-type: strict }
# The gate's four pairs, `pq` included (gate.yml says what it requires of each leg).
- { leg: floor, otp: "27", elixir: "1.17", os: ubuntu-24.04, version-type: loose, pq: "" }
- { leg: pinned, otp: "28", elixir: "1.18", os: ubuntu-24.04, version-type: loose, pq: "" }
- { leg: head, otp: "29", elixir: "1.20", os: ubuntu-24.04, version-type: loose, pq: "" }
- { leg: box, otp: "28.5.0.9", elixir: "1.20.4", os: ubuntu-26.04-arm, version-type: strict, pq: "all" }
env:
# Through the environment, never inline in a script: the input is the dispatcher's text,
# and tools/flake_hunt.sh refuses anything but a positive integer.
RUNS: ${{ inputs.runs || '10' }}
PQ_TLS_REQUIRED: ${{ matrix.pq }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: erlef/setup-beam@54075bcc5e249e4758d363f27d099f55d843f124 # v1.24.1
Expand Down
14 changes: 9 additions & 5 deletions .github/workflows/gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ jobs:
fail-fast: false
matrix:
include:
- { leg: floor, otp: "27", elixir: "1.17", os: ubuntu-24.04, version-type: loose }
- { leg: pinned, otp: "28", elixir: "1.18", os: ubuntu-24.04, version-type: loose }
- { leg: head, otp: "29", elixir: "1.20", os: ubuntu-24.04, version-type: loose }
- { leg: box, otp: "28.5.0.9", elixir: "1.20.4", os: ubuntu-26.04-arm, version-type: strict }
# `pq`: the post-quantum TLS tests this leg must run (test_helper.exs, PQ_TLS_REQUIRED).
# The 24.04 legs' OTP links OpenSSL 3.0.13, which has no ML-KEM; the box leg's links the
# image's OpenSSL 3.5, so it must complete X25519MLKEM768, SecP384r1MLKEM1024 and
# ML-KEM-1024 handshakes and have OpenSSL's own client name each group.
- { leg: floor, otp: "27", elixir: "1.17", os: ubuntu-24.04, version-type: loose, pq: "" }
- { leg: pinned, otp: "28", elixir: "1.18", os: ubuntu-24.04, version-type: loose, pq: "" }
- { leg: head, otp: "29", elixir: "1.20", os: ubuntu-24.04, version-type: loose, pq: "" }
- { leg: box, otp: "28.5.0.9", elixir: "1.20.4", os: ubuntu-26.04-arm, version-type: strict, pq: "all" }
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
Expand Down Expand Up @@ -91,7 +95,7 @@ jobs:
# local thresholds, never enforced -- the draw overlaps the ceiling there (tools/gate.sh).
# GATE_AUDIT=require: the dependency audit must reach the registry here; an answer from
# hex's cache is a failure in CI, where a stale pass would be taken for a fresh one.
- run: GATE_LEG=${{ matrix.leg }} GATE_BENCH=record GATE_AUDIT=require ./tools/gate.sh
- run: PQ_TLS_REQUIRED=${{ matrix.pq }} GATE_LEG=${{ matrix.leg }} GATE_BENCH=record GATE_AUDIT=require ./tools/gate.sh

# The pull-request body, read from the event and held to the same terms as the commit
# messages (tools/text_terms.sh) -- the one public surface a person writes last, which no
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ All notable changes to this project are documented here. The format follows

## [Unreleased]

### Added: post-quantum TLS, measured (tests and pages; no public entry)

- `test/beam_mcp/transport/pq_tls_test.exs` serves the HTTP transport from `Bandit` over HTTPS and
completes TLS 1.3 handshakes in which both sides allow only one post-quantum key exchange:
X25519MLKEM768, SecP384r1MLKEM1024 and ML-KEM-1024. It answers an MCP request over each, has a
classical-only server refuse each, and has OpenSSL's `s_client` name the negotiated group. The
groups are found by a real handshake, not `ssl:groups/0`, which in FIPS mode under provider
3.1.2 lists ML-KEM groups whose handshake then exits. CI's box leg must run all of them; the
FIPS leg's 3.5.9 rows must run the two ML-KEM-1024 groups (in FIPS mode X25519MLKEM768 is not
offered). The README's "Post-quantum TLS, measured" says what a host configures.
- `docs/crypto-posture.md` says the post-quantum signature exists (`beam_mcp_signer` `0.3.0`,
KMS-held keys in `0.4.0`); `docs/fips.md` gains the FIPS-mode measurement.

## [0.12.0] - 2026-11-30

### Documented: running on a platform the provider's certificate does not name, and a No-CUI notice
Expand Down
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,39 @@ because HTTP is the carrier that stamps every request modern; stdio's dual-era r
and connection limits (your HTTP server's settings, not this Plug's), and authentication:
`authorize/1` is where you put it, and it is required precisely so the decision is yours.

**Post-quantum TLS, measured.** TLS is your listener's, through OTP's `ssl`, but this repository
measures what it gives. `test/beam_mcp/transport/pq_tls_test.exs` serves this Plug from `Bandit`
over HTTPS and completes real TLS 1.3 handshakes in which client and server each allow only a
post-quantum key exchange, then answers an MCP request over the connection:

- **X25519MLKEM768**, the hybrid most clients offer, on OTP 28 linked to OpenSSL 3.5 or later,
outside FIPS mode. OTP's default groups accept it.
- **SecP384r1MLKEM1024 and ML-KEM-1024**, the ML-KEM parameter set CNSA 2.0 names, outside FIPS
mode and in FIPS mode under OpenSSL FIPS provider 3.5.9 (CMVP #5586). In FIPS mode
X25519MLKEM768 is not offered: X25519 is not an approved algorithm.

Each is held from both sides. A server that allows only a classical group refuses the same
client, and OpenSSL's own `s_client` reports `Negotiated TLS1.3 group:` with the group's name. CI
runs them on the box leg (aarch64, the image's OpenSSL 3.5) and in the FIPS leg under 3.5.9, and
those legs fail rather than skip if they do not run. An OTP linked to OpenSSL 3.0 has no ML-KEM
group. To require post-quantum key exchange, list only those groups in your listener's options:

```elixir
{Bandit,
plug: {BeamMCP.Transport.HTTP, opts},
scheme: :https,
thousand_island_options: [
transport_options: [
versions: [:"tlsv1.3"],
supported_groups: [:secp384r1mlkem1024, :mlkem1024],
certfile: "...", keyfile: "..."
]
]}
```

Under FIPS provider 3.1.2 (CMVP #4985, no ML-KEM), OTP still lists the ML-KEM groups, and a
handshake with one exits instead of alerting. Do not configure them there.

## What it speaks

Newline-delimited JSON-RPC over stdio, **dual-era**: it serves both the current revision and
Expand Down
8 changes: 5 additions & 3 deletions docs/crypto-posture.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ the one site that calls it, over the bytes `encode/2` produces, returning the si
them and moving no byte. The one implementation here, `BeamMCP.Signer.None`, signs nothing;
the reference implementation that does, Ed25519 through OTP's `:crypto` with a key the host
hands in under `opts[:private_key]`, is the separate package `beam_mcp_signer`, which a host
attaches; it is never a dependency of this one. A
post-quantum signature (ML-DSA) would be another module behind the same callback and change
nothing here, since the envelope already names its digest.
attaches; it is never a dependency of this one. The post-quantum signature is another module
behind the same callback, as this page said it would be, and changed nothing here: ML-DSA-87
(FIPS 204, RFC 9964's COSE form) since `beam_mcp_signer` `0.3.0`, with ECDSA P-384 and keys held
in AWS KMS since `0.4.0`. Transport encryption is the host's listener's; what its TLS gives,
post-quantum key exchange included, is measured in the README's "Post-quantum TLS, measured".

**It performs no cryptography on a request.** The HTTP transport's `:authorize_body` hook
hands the host the body exactly as received so the host can verify a signature over it; the
Expand Down
6 changes: 6 additions & 0 deletions docs/fips.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,9 @@ A host under CNSA 2.0 (US National Security Systems) asks for `algorithm: :sha38
`:sha512`: CNSA 2.0 specifies SHA-384 or SHA-512, and the package's default is `:sha256`,
which is unchanged. Signatures, their algorithm and where their keys are held belong to the
signer behind `BeamMCP.Signer`, not to this package.

A host's TLS in FIPS mode under provider 3.5.9 completes TLS 1.3 handshakes whose only key
exchange is SecP384r1MLKEM1024 or ML-KEM-1024 (CNSA 2.0's ML-KEM parameter set), measured with
this package's HTTP transport behind `Bandit` (`test/beam_mcp/transport/pq_tls_test.exs`, run by
the FIPS leg). Under 3.1.2 OTP lists those groups too, and a handshake with one exits: configure
them only under a provider that serves ML-KEM.
170 changes: 170 additions & 0 deletions test/beam_mcp/transport/pq_tls_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
# SPDX-FileCopyrightText: 2026 Sudo Apt Holdings LLC
# SPDX-License-Identifier: Apache-2.0

defmodule BeamMCP.Transport.PQTLSTest do
@moduledoc """
The transport over TLS 1.3 with a post-quantum key exchange, on a real listener: Bandit
serving `BeamMCP.Transport.HTTP` over HTTPS, and a real handshake to it.

This package does no TLS itself; the host's listener does, through OTP's `ssl`. These tests
measure what that gives, for each key-exchange group the runtime really completes a handshake
with (test_helper.exs asks by trying one):

* `:pq_tls`: X25519MLKEM768, the hybrid most clients offer (OTP 28 linked to OpenSSL 3.5 or
later, outside FIPS mode);
* `:pq_tls_cnsa`: SecP384r1MLKEM1024 and ML-KEM-1024, the ML-KEM parameter set CNSA 2.0
names, which also work in FIPS mode under OpenSSL FIPS provider 3.5.9.

For each group:

* a TLS 1.3 handshake in which client and server each allow ONLY that group completes, and
an MCP request is answered over it. OTP's `ssl` does not report the negotiated TLS 1.3
group, so the proof is by construction: the key share is drawn from the groups both sides
allow, and that set is the one group;
* the negative control: the same client against a server that allows only a classical group
(X25519, or P-384 for the CNSA groups) is refused, so the first test cannot pass by a
handshake that ignores the groups;
* an independent client, OpenSSL's `s_client` (an OpenSSL 3.5 or later command; tagged
`:openssl_cli`), reports "Negotiated TLS1.3 group: <the group>" against a server that
allows that group.
"""
use ExUnit.Case, async: false

alias BeamMCP.Test.PQTLS
alias BeamMCP.Transport.HTTP

@modern "2026-07-28"

defmodule Catalog do
@behaviour BeamMCP.Catalog
@impl true
def capabilities do
%{
tools: [
%BeamMCP.ToolSpec{
name: :echo,
command_class: :observe,
mode: :read_only,
description: "Echo.",
input_schema: %{
"type" => "object",
"properties" => %{},
"additionalProperties" => true
}
}
],
resources: [],
prompts: []
}
end
end

setup_all do
{:ok, _} = Application.ensure_all_started(:ssl)
PQTLS.certs()
end

# A Bandit HTTPS listener on the loopback, TLS 1.3 only, allowing `groups`.
defp listen(server_tls, groups) do
transport = [versions: [:"tlsv1.3"], supported_groups: groups] ++ server_tls

plug_opts = [
catalog: Catalog,
dispatch: fn _n, a, _o -> {:ok, a} end,
authorize: fn _conn -> :ok end,
allowed_origins: :any
]

spec =
Supervisor.child_spec(
{Bandit,
plug: {HTTP, plug_opts},
scheme: :https,
port: 0,
ip: :loopback,
startup_log: false,
thousand_island_options: [transport_options: transport]},
id: {Bandit, make_ref()}
)

pid = start_supervised!(spec)
{:ok, {_address, port}} = ThousandIsland.listener_info(pid)
port
end

defp connect(port, cacerts, groups),
do: :ssl.connect(~c"127.0.0.1", port, PQTLS.client_opts(cacerts, groups), 5_000)

# One MCP request over the TLS socket, HTTP/1.1, and the response read to its close.
defp tools_list(socket) do
body =
~s({"jsonrpc":"2.0","id":1,"method":"tools/list","params":{"_meta":) <>
~s({"io.modelcontextprotocol/protocolVersion":"#{@modern}",) <>
~s("io.modelcontextprotocol/clientCapabilities":{}}}})

request =
"POST / HTTP/1.1\r\nhost: 127.0.0.1\r\ncontent-type: application/json\r\n" <>
"accept: application/json, text/event-stream\r\nmcp-protocol-version: #{@modern}\r\n" <>
"mcp-method: tools/list\r\nconnection: close\r\ncontent-length: #{byte_size(body)}\r\n\r\n" <>
body

:ok = :ssl.send(socket, request)
read_all(socket, "")
end

defp read_all(socket, acc) do
case :ssl.recv(socket, 0, 5_000) do
{:ok, data} -> read_all(socket, acc <> data)
{:error, :closed} -> acc
end
end

# {tag, the group, OpenSSL's name for it, a classical group for the negative control}
for {tag, group, openssl_name, classical} <- [
{:pq_tls, :x25519mlkem768, "X25519MLKEM768", :x25519},
{:pq_tls_cnsa, :secp384r1mlkem1024, "SecP384r1MLKEM1024", :secp384r1},
{:pq_tls_cnsa, :mlkem1024, "MLKEM1024", :secp384r1}
] do
describe "#{openssl_name}" do
@describetag tag

test "both sides allow only #{openssl_name}: TLS 1.3 completes, and MCP is served over it",
%{server: server, cacerts: cacerts} do
port = listen(server, [unquote(group)])
assert {:ok, socket} = connect(port, cacerts, [unquote(group)])
assert {:ok, [protocol: :"tlsv1.3"]} = :ssl.connection_information(socket, [:protocol])

response = tools_list(socket)
assert response =~ ~r{\AHTTP/1\.1 200 }, response
assert response =~ ~s("name":"echo")
end

test "the negative control: a server that allows only #{classical} refuses a client offering only #{openssl_name}",
%{server: server, cacerts: cacerts} do
port = listen(server, [unquote(classical)])
assert {:error, _alert} = connect(port, cacerts, [unquote(group)])
end

@tag :openssl_cli
test "an independent client, OpenSSL's s_client, negotiates #{openssl_name}",
%{server: server} do
port = listen(server, [unquote(group)])
openssl = System.get_env("OPENSSL_CLI") || System.find_executable("openssl")

# stdin from /dev/null, so s_client completes the handshake, prints it, and exits.
{out, _status} =
System.cmd(
"sh",
[
"-c",
~s("$0" s_client -connect 127.0.0.1:#{port} -tls1_3 -groups #{unquote(openssl_name)} -brief </dev/null),
openssl
],
stderr_to_stdout: true
)

assert out =~ "Negotiated TLS1.3 group: #{unquote(openssl_name)}", out
end
end
end
end
Loading