# TLS 1.3 SNI, QUIC, HTTP/1.1, HTTP/2, gRPC & WebSocket APIs

> **FrameAssembly v3.2.2** · Anthology 07 (Layer 7 · 13 Recipes) · MIT License · Canonical URL: https://frameassembly-lang.dev/docs/examples/tls-quic-http-apis

Modern web, reverse-proxy, WAF, and service-mesh traffic fixtures: TLS 1.3 `clienthello` SNI/ALPN, `quic` long/short headers, `http` `hosthdr` REST calls, `http2` streams, `grpc` status trails, and `websocket` frames.

## Key Wire & Syntax Takeaways

- Use `hosthdr "<domain>"` on `http` and `ssdp` frames (`host` is reserved for top-level endpoint declarations).
- `tls clienthello` populates SNI and ALPN extensions cleanly over a 3-way TCP handshake so NGFW application-ID rules trigger reliably.
- `http2`, `grpc`, and `websocket` frame binary stream identifiers, length prefixes, and masking bits on top of stateful TCP.

## 07.01 · HTTP/1.1 API Authentication & Rate-Limit Response (429 Too Many Requests) (`http_api_ratelimit_429.frasm`)

Tests WAF and API-gateway rules with repeatable custom header key/value pairs, JSON POST bodies, and HTTP 429 rate-limit replies.

- **Protocols:** `tcp`, `http` (7 Ethernet frames)
- **Wire Behavior:** Uses hosthdr for the HTTP Host header and computes Content-Length automatically from body.
- **Wireshark Filter:** `http`
- **CLI Build:** `frameassembly http_api_ratelimit_429.frasm`

```frameassembly
host api_client { ip 10.42.10.15 }
host waf_edge   { ip 10.42.90.80 }

compile {
    api_client -> waf_edge tcp syn srcport 51080 dstport 80 win 65535 mss 1460 wait 1ms
    api_client <- waf_edge tcp syn ack win 65535 mss 1460 wait 1ms
    api_client -> waf_edge tcp ack wait 1ms
    api_client -> waf_edge http post uri "/v2/tokens" hosthdr "auth.corp.internal" contenttype "application/json" header "X-Request-Id" "req-9012" body "{\"grant\":\"client_credentials\"}" wait 2ms
    api_client <- waf_edge http status 200 reason "OK" contenttype "application/json" body "{\"active\":true}" wait 3ms
    api_client -> waf_edge http post uri "/v2/tokens" hosthdr "auth.corp.internal" contenttype "application/json" header "X-Request-Id" "req-9013" body "{\"grant\":\"client_credentials\"}" wait 2ms
    api_client <- waf_edge http status 429 reason "Too Many Requests" header "Retry-After" "60" body "{\"error\":\"rate_limited\"}"
}
```

## 07.02 · Service-Mesh gRPC Unary Call & Status Code Verification (TCP 50051) (`service_mesh_grpc_check.frasm`)

Establishes a TCP 50051 channel between two Kubernetes pods and exercises a unary gRPC call returning grpcstatus 0 (OK) followed by grpcstatus 14 (UNAVAILABLE).

- **Protocols:** `tcp`, `grpc` (7 Ethernet frames)
- **Wire Behavior:** Builds HTTP/2 HEADERS + length-prefixed gRPC data + trailing grpc-status frames over stateful TCP.
- **Wireshark Filter:** `http2 || grpc || tcp.port == 50051`
- **CLI Build:** `frameassembly service_mesh_grpc_check.frasm`

```frameassembly
host checkout_pod { ip 10.244.1.18 }
host ledger_pod   { ip 10.244.2.44 }

compile {
    checkout_pod -> ledger_pod tcp syn srcport 55051 dstport 50051 win 65535 mss 1460 wait 1ms
    checkout_pod <- ledger_pod tcp syn ack win 65535 mss 1460 wait 1ms
    checkout_pod -> ledger_pod tcp ack wait 1ms
    checkout_pod -> ledger_pod grpc service "ledger.v1.LedgerService" method "ReserveFunds" streamid 1 payload "order-8841" wait 2ms
    checkout_pod <- ledger_pod grpc service "ledger.v1.LedgerService" method "ReserveFunds" streamid 1 grpcstatus 0 wait 4ms
    checkout_pod -> ledger_pod grpc service "ledger.v1.LedgerService" method "CommitBatch" streamid 3 payload "batch-99" wait 2ms
    checkout_pod <- ledger_pod grpc service "ledger.v1.LedgerService" method "CommitBatch" streamid 3 grpcstatus 14
}
```

## 07.03 · Stateful VLAN 20 HTTPS Permit Check (`fw_vlan20_https_permit.frasm`)

Verifies an inter-VLAN firewall rule permits branch workstations on VLAN 20 to complete a 3-way TCP handshake and TLS 1.3 negotiation to an internal portal on port 443.

- **Protocols:** `vlan`, `tcp`, `tls` (5 Ethernet frames)
- **Wire Behavior:** Stateful firewalls drop lone TLS packets without a prior SYN -> SYN-ACK -> ACK exchange. Specify srcport and dstport once on the opening syn line and FrameAssembly tracks ports and sequence numbers automatically.
- **Wireshark Filter:** `vlan.id == 20 && tcp.port == 443`
- **CLI Build:** `frameassembly fw_vlan20_https_permit.frasm`

```frameassembly
// Devices on Branch VLAN 20 and Internal Portal Subnet
host branch_pc  { ip 10.20.10.25 }
host portal_srv { ip 10.20.90.80 }

compile {
    // 1. Open TCP port 443 with an 802.1Q VLAN 20 tag (0x8100)
    branch_pc -> portal_srv vlan 20 tcp syn srcport 51240 dstport 443 win 65535 mss 1460 wait 1ms
    branch_pc <- portal_srv vlan 20 tcp syn ack win 65535 mss 1460 wait 1ms
    branch_pc -> portal_srv vlan 20 tcp ack wait 1ms

    // 2. Send TLS ClientHello with SNI so NGFW application control can inspect the hostname
    branch_pc -> portal_srv vlan 20 tls clienthello sni "portal.corp.internal" alpn "h2" wait 2ms

    // 3. Server completes TLS 1.3 ServerHello (0x1301 = TLS_AES_128_GCM_SHA256)
    branch_pc <- portal_srv vlan 20 tls serverhello ciphersuite 0x1301
}
```

## 07.04 · Minimal Two-Block HTTP/1.1 (`http`) Quickstart (`http_quickstart.frasm`)

Smallest zero-boilerplate `host` + `compile` capture for Hypertext Transfer Protocol HTTP/1.1 (TCP 80, Dual-Stack IPv4/IPv6).

- **Protocols:** `http` (5 Ethernet frames)
- **Wire Behavior:** Defaults to TCP destination port `80` with `psh ack` flags and advances TCP `seq` by the exact HTTP header + body byte count.
- **Wireshark Filter:** `http`
- **CLI Build:** `frameassembly http_quickstart.frasm`

```frameassembly
host client  { ip 10.10.1.20 }
host web_srv { ip 10.10.1.80 }

compile {
    client -> web_srv tcp syn srcport 52100 dstport 80 wait 1ms
    client <- web_srv tcp syn ack wait 1ms
    client -> web_srv tcp ack wait 1ms
    client -> web_srv http get uri "/healthz" hosthdr "api.corp.internal" useragent "kube-probe/1.30" wait 2ms
    client <- web_srv http status 200 reason "OK" contenttype "application/json" body "{\"status\":\"healthy\"}"
}
```

## 07.05 · Minimal Two-Block HTTP/2 (`http2`) Quickstart (`http2_quickstart.frasm`)

Smallest zero-boilerplate `host` + `compile` capture for Hypertext Transfer Protocol Version 2 Binary Framing (TCP 443, Dual-Stack IPv4/IPv6).

- **Protocols:** `http2` (4 Ethernet frames)
- **Wire Behavior:** Defaults to TCP destination port `443` (`psh ack`) and keeps TCP `seq` / `acknum` synchronized across multiplexed frames.
- **Wireshark Filter:** `http2`
- **CLI Build:** `frameassembly http2_quickstart.frasm`

```frameassembly
host app_client { ip 10.20.1.10 }
host api_gw     { ip 10.20.1.44 }

compile {
    app_client -> api_gw http2 preface dstport 8080 wait 1ms
    app_client <- api_gw http2 settings wait 1ms
    app_client -> api_gw http2 headers streamid 1 wait 1ms
    app_client <- api_gw http2 data streamid 1 payload "{\"ok\":true}"
}
```

## 07.06 · Minimal Two-Block TLS 1.2 / 1.3 (`tls`) Quickstart (`tls_quickstart.frasm`)

Smallest zero-boilerplate `host` + `compile` capture for Transport Layer Security Record & Handshake Layer (TCP 443, Dual-Stack IPv4/IPv6).

- **Protocols:** `tls` (5 Ethernet frames)
- **Wire Behavior:** Defaults to TCP destination port `443` (`psh ack`), TLS record version `0x0303` (RFC 8446 compatibility layer), and TLS 1.3 cipher suite `0x1301` (`TLS_AES_128_GCM_SHA256`).
- **Wireshark Filter:** `tls`
- **CLI Build:** `frameassembly tls_quickstart.frasm`

```frameassembly
host workstation { ip 10.10.5.20 }
host https_edge  { ip 198.51.100.44 }

compile {
    workstation -> https_edge tcp syn srcport 53443 dstport 443 wait 1ms
    workstation <- https_edge tcp syn ack wait 1ms
    workstation -> https_edge tcp ack wait 1ms
    workstation -> https_edge tls clienthello sni "portal.corp.internal" ciphersuite 0x1301 alpn "h2" wait 2ms
    workstation <- https_edge tls serverhello ciphersuite 0x1301
}
```

## 07.07 · Minimal Two-Block QUIC (HTTP/3) (`quic`) Quickstart (`quic_quickstart.frasm`)

Smallest zero-boilerplate `host` + `compile` capture for QUIC v1 & v2 Encrypted UDP Transport (UDP 443, Dual-Stack IPv4/IPv6).

- **Protocols:** `quic` (2 Ethernet frames)
- **Wire Behavior:** Defaults to UDP destination port `443`, QUIC v1 (`version 1` `0x00000001`), and sets the mandatory Fixed Bit (`0x40`) in byte 0.
- **Wireshark Filter:** `quic`
- **CLI Build:** `frameassembly quic_quickstart.frasm`

```frameassembly
host browser { ip 10.20.4.15 }
host cdn_vip { ip 198.51.100.44 }

compile {
    browser -> cdn_vip quic initial version 1 dcid 0x1122334455667788 scid 0xaabbccddeeff0011 pktnum 1 wait 2ms
    browser <- cdn_vip quic handshake version 1 dcid 0xaabbccddeeff0011 scid 0x1122334455667788 pktnum 1
}
```

## 07.08 · HTTP/1.1 (`http`): REST API JSON Webhook POST + WAF 403 Block Scenario (`http_api_waf_test.frasm`)

Completes a TCP handshake on port 8080, sends an authenticated JSON `POST` request with custom HTTP headers, and captures a `403 Forbidden` gateway response.

- **Protocols:** `http`, `tcp` (7 Ethernet frames)
- **Wire Behavior:** Defaults to TCP destination port `80` with `psh ack` flags and advances TCP `seq` by the exact HTTP header + body byte count. Computes and inserts `Content-Length: <bytes>` automatically whenever `body` is present, formatting all header lines with standard `
` CRLF terminators.
- **Wireshark Filter:** `http`
- **CLI Build:** `frameassembly show http_api_waf_test.frasm`

```frameassembly
host ext_client { ip 198.51.100.45 }
host waf_proxy  { ip 172.16.20.80 }

compile {
    // 1. Complete TCP 3-way handshake on port 8080 (so Suricata stream engine tracks state)
    ext_client -> waf_proxy tcp syn srcport 54320 dstport 8080 win 65535 mss 1460 wait 1ms
    ext_client <- waf_proxy tcp syn ack win 65535 mss 1460 wait 1ms
    ext_client -> waf_proxy tcp ack wait 1ms
    // 2. HTTP POST with custom headers and JSON body
    ext_client -> waf_proxy http post uri "/v1/login" hosthdr "portal.example.com" useragent "Mozilla/5.0" contenttype "application/json" header "X-Request-ID" "req-9041" header "X-Forwarded-For" "203.0.113.9" body "{\"user\":\"admin\"}" wait 3ms
    // 3. WAF blocks request with HTTP 403 Forbidden + TCP FIN
    ext_client <- waf_proxy http status 403 reason "Forbidden" contenttype "application/json" body "{\"error\":\"blocked_by_policy\"}" wait 1ms
    ext_client <- waf_proxy tcp fin ack wait 1ms
    ext_client -> waf_proxy tcp ack
}
```

## 07.09 · HTTP/2 (`http2`): Cleartext h2c Connection Preface, Stream 1 Request, PING & Graceful GOAWAY (`http2_multiplexed_session.frasm`)

Establishes a TCP port 8080 connection, exchanges HTTP/2 connection prefaces, serves a Stream 1 request/data exchange, tests liveness with `ping`, and closes cleanly via `goaway`.

- **Protocols:** `http2`, `tcp` (11 Ethernet frames)
- **Wire Behavior:** Defaults to TCP destination port `443` (`psh ack`) and keeps TCP `seq` / `acknum` synchronized across multiplexed frames. Enforces RFC 9113 frame size rules automatically: 24-byte magic string + `SETTINGS` on `preface`, 8-byte payload on `ping` (`streamid 0`), 4-byte window increment on `windowupdate`, and 8-byte `last_stream_id + error_code` on `goaway`.
- **Wireshark Filter:** `http2`
- **CLI Build:** `frameassembly show http2_multiplexed_session.frasm`

```frameassembly
host mesh_sidecar { ip 172.16.30.11 }
host upstream_svc { ip 172.16.30.80 }

compile {
    mesh_sidecar -> upstream_svc tcp syn srcport 53080 dstport 8080 win 65535 mss 1460 wait 1ms
    mesh_sidecar <- upstream_svc tcp syn ack win 65535 mss 1460 wait 1ms
    mesh_sidecar -> upstream_svc tcp ack wait 1ms
    // 1. Client magic preface + server SETTINGS
    mesh_sidecar -> upstream_svc http2 preface wait 1ms
    mesh_sidecar <- upstream_svc http2 settings wait 1ms
    // 2. Stream 1 request headers + response data + flow-control window update
    mesh_sidecar -> upstream_svc http2 headers streamid 1 wait 2ms
    mesh_sidecar <- upstream_svc http2 headers streamid 1 wait 1ms
    mesh_sidecar <- upstream_svc http2 data streamid 1 payload "{\"items\":[]}" wait 1ms
    mesh_sidecar -> upstream_svc http2 windowupdate streamid 0 wait 5ms
    // 3. Keepalive PING & graceful connection drain (GOAWAY on stream 0)
    mesh_sidecar -> upstream_svc http2 ping streamid 0 wait 2ms
    mesh_sidecar <- upstream_svc http2 goaway streamid 0
}
```

## 07.10 · gRPC (`grpc`): gNMI Router Telemetry Subscription + Backend UNAVAILABLE Failover (`grpc_service_mesh_lab.frasm`)

Opens a TCP 50051 connection, invokes a `telemetry.Collector/Export` RPC succeeding with `grpcstatus 0`, and captures a second call returning `grpcstatus 14` (`UNAVAILABLE`).

- **Protocols:** `grpc`, `tcp` (7 Ethernet frames)
- **Wire Behavior:** Defaults to TCP destination port `50051` (`psh ack`) and formats HTTP/2 `HEADERS` (`:method POST`, `:path /<service>/<method>`, `content-type: application/grpc`). Wraps request payloads in the 5-byte gRPC Length-Prefixed-Message header (`Compressed-Flag = 0` + 32-bit big-endian message length).
- **Wireshark Filter:** `grpc || http2`
- **CLI Build:** `frameassembly show grpc_service_mesh_lab.frasm`

```frameassembly
host edge_agent { ip 172.16.40.12 }
host mesh_gw    { ip 172.16.40.50 }

compile {
    edge_agent -> mesh_gw tcp syn srcport 55051 dstport 50051 win 65535 mss 1460 wait 1ms
    edge_agent <- mesh_gw tcp syn ack win 65535 mss 1460 wait 1ms
    edge_agent -> mesh_gw tcp ack wait 1ms
    // 1. Healthy gRPC Export call -> OK (0)
    edge_agent -> mesh_gw grpc service "telemetry.Collector" method "Export" wait 2ms
    edge_agent <- mesh_gw grpc grpcstatus 0 wait 4ms
    // 2. Upstream maintenance -> UNAVAILABLE (14)
    edge_agent -> mesh_gw grpc service "auth.TokenVerifier" method "Validate" wait 2ms
    edge_agent <- mesh_gw grpc grpcstatus 14
}
```

## 07.11 · WebSocket (`websocket`): Full HTTP 101 Upgrade Handshake Into Masked WebSocket Stream & Close (`websocket_upgrade_session.frasm`)

Performs a TCP handshake + HTTP `101 Switching Protocols` WebSocket upgrade so Wireshark and Suricata track the protocol switch, then exchanges masked client JSON, server events, `ping`/`pong`, and `close`.

- **Protocols:** `websocket`, `tcp` (10 Ethernet frames)
- **Wire Behavior:** Defaults to TCP destination port `80` (`psh ack`), `text` frame (`opcode 0x1`), and `finbit 1` (complete unfragmented message). Encodes RFC 6455 extended 16-bit (`126`) or 64-bit (`127`) payload lengths automatically when payloads exceed 125 bytes.
- **Wireshark Filter:** `websocket`
- **CLI Build:** `frameassembly show websocket_upgrade_session.frasm`

```frameassembly
host dashboard_ui { ip 172.16.10.25 }
host realtime_gw  { ip 172.16.10.80 }

compile {
    // 1. TCP 3-way handshake + HTTP 101 WebSocket Upgrade
    dashboard_ui -> realtime_gw tcp syn srcport 52800 dstport 80 win 65535 mss 1460 wait 1ms
    dashboard_ui <- realtime_gw tcp syn ack win 65535 mss 1460 wait 1ms
    dashboard_ui -> realtime_gw tcp ack wait 1ms
    dashboard_ui -> realtime_gw http get uri "/ws" hosthdr "noc.corp.internal" header "Upgrade" "websocket" header "Connection" "Upgrade" header "Sec-WebSocket-Version" "13" header "Sec-WebSocket-Key" "dGhlIHNhbXBsZSBub25jZQ==" wait 2ms
    dashboard_ui <- realtime_gw http status 101 reason "Switching Protocols" header "Upgrade" "websocket" header "Connection" "Upgrade" wait 2ms
    // 2. Masked client text frame + unmasked server push + Ping/Pong + Close
    dashboard_ui -> realtime_gw websocket text maskkey 0x12345678 payload "{\"op\":\"subscribe\",\"channel\":\"bgp\"}" wait 2ms
    dashboard_ui <- realtime_gw websocket text payload "{\"peer\":\"10.0.0.2\",\"state\":\"Established\"}" wait 10ms
    dashboard_ui <- realtime_gw websocket ping payload "hb" wait 1ms
    dashboard_ui -> realtime_gw websocket pong maskkey 0xabcdef01 payload "hb" wait 5ms
    dashboard_ui -> realtime_gw websocket close maskkey 0x11223344
}
```

## 07.12 · TLS 1.2 / 1.3 (`tls`): Full TLS 1.3 Handshake (`sni` + `alpn "h2"`), Encrypted AppData & Alert Teardown (`tls13_sni_handshake.frasm`)

Completes a TCP 443 handshake, negotiates `TLS_CHACHA20_POLY1305_SHA256` (`0x1303`) with SNI and ALPN, exchanges encrypted Application Data records, and closes with a TLS `alert`.

- **Protocols:** `tls`, `tcp` (11 Ethernet frames)
- **Wire Behavior:** Defaults to TCP destination port `443` (`psh ack`), TLS record version `0x0303` (RFC 8446 compatibility layer), and TLS 1.3 cipher suite `0x1301` (`TLS_AES_128_GCM_SHA256`). Automatically encodes Extension `0x0000` (`server_name` when `sni` is set), Extension `0x002b` (`supported_versions` advertising TLS 1.3 `0x0304` + TLS 1.2 `0x0303`), and Extension `0x0010` (`alpn` when `alpn` is set).
- **Wireshark Filter:** `tls`
- **CLI Build:** `frameassembly show tls13_sni_handshake.frasm`

```frameassembly
host branch_pc { ip 172.16.12.34 }
host saas_gw   { ip 203.0.113.100 }

compile {
    branch_pc -> saas_gw tcp syn srcport 54443 dstport 443 win 65535 mss 1460 sackperm wait 1ms
    branch_pc <- saas_gw tcp syn ack win 65535 mss 1460 sackperm wait 1ms
    branch_pc -> saas_gw tcp ack wait 1ms
    // 1. TLS 1.3 ClientHello + ServerHello + Encrypted Handshake / AppData
    branch_pc -> saas_gw tls clienthello sni "api.saas-vendor.example" ciphersuite 0x1303 alpn "h2" wait 2ms
    branch_pc <- saas_gw tls serverhello ciphersuite 0x1303 wait 1ms
    branch_pc <- saas_gw tls certificate wait 1ms
    branch_pc <- saas_gw tls finished wait 1ms
    branch_pc -> saas_gw tls finished wait 2ms
    // 2. Encrypted TLS Record Type 23 (Application Data) + Record Type 21 (Alert)
    branch_pc -> saas_gw tls appdata hexpayload "9f4a1c880021bc773310aa55" wait 3ms
    branch_pc <- saas_gw tls appdata hexpayload "41e82209ff12008ac491bb02" wait 5ms
    branch_pc -> saas_gw tls alert
}
```

## 07.13 · QUIC (HTTP/3) (`quic`): QUIC v1 Retry Token Challenge, Handshake & 1-RTT Connection Migration (`quic_connection_migration.frasm`)

Shows a server challenging an initial client packet with `retry`, completing the QUIC handshake, and maintaining the same `dcid` across a NAT source-port rebind on `short` packets.

- **Protocols:** `quic` (6 Ethernet frames)
- **Wire Behavior:** Defaults to UDP destination port `443`, QUIC v1 (`version 1` `0x00000001`), and sets the mandatory Fixed Bit (`0x40`) in byte 0. Encodes 8-byte `dcid` and `scid` Connection IDs plus RFC 9000 variable-length integer payload lengths automatically on Long Header packets.
- **Wireshark Filter:** `quic`
- **CLI Build:** `frameassembly show quic_connection_migration.frasm`

```frameassembly
host mobile_app { ip 198.51.100.70 }
host edge_pop   { ip 203.0.113.44 }

compile {
    // 1. Initial attempt -> Server sends stateless Retry token
    mobile_app -> edge_pop quic initial srcport 51443 dcid 0x0102030405060708 scid 0x1111222233334444 pktnum 0 wait 2ms
    mobile_app <- edge_pop quic retry dcid 0x1111222233334444 scid 0x9999888877776666 token "addr-verified-tok" wait 2ms
    // 2. Client resends Initial with token + Handshake completion
    mobile_app -> edge_pop quic initial dcid 0x9999888877776666 scid 0x1111222233334444 token "addr-verified-tok" pktnum 1 wait 2ms
    mobile_app <- edge_pop quic handshake dcid 0x1111222233334444 scid 0x9999888877776666 pktnum 1 wait 3ms
    // 3. 1-RTT Short Header packets (client migrates from srcport 51443 -> 60222 keeping dcid)
    mobile_app -> edge_pop quic short dcid 0x9999888877776666 pktnum 2 payload "h3-stream-frame-1" wait 5ms
    mobile_app -> edge_pop quic short srcport 60222 dstport 443 dcid 0x9999888877776666 pktnum 3 payload "h3-migrated-port"
}
```
