Skip to content

Commit 401468b

Browse files
committed
docs: Add Coldwire protocol specification
1 parent 29a7a3f commit 401468b

File tree

1 file changed

+218
-0
lines changed

1 file changed

+218
-0
lines changed

COLDWIRE_PROTOCOL.md

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
# Coldwire Protocol Specification
2+
Version: **`1.0`**
3+
4+
Date: **`2025-09-09`**
5+
6+
Author(s): **`ChadSec1`** (**`Freedom Club Sec`**)
7+
8+
Contact: github.com/Freedom-Club-Sec
9+
10+
Status: **`Draft`**
11+
12+
Intended Audience: Security engineers, cryptographers, protocol implementers
13+
14+
### 0. Overview
15+
16+
The *`Coldwire`* Protocol is a federated, metadata-resistant, censorship-resistant chat protocol, built on top of HTTP protocol. The purpose of the protocol is to simply relay messages between users and or other servers running *Coldwire*, in a way that does not include any metadata except "ciphertext in", "ciphertext out", and a random "mailbox" user identifier
17+
18+
*`Coldwire`* protocol is designed to evade censorship, and usage detection, by network adversaries (LAN Router-controlling adversaries, ISP adversaries, etc) by blending in with regular browser traffic. It's also designed so that a malicious server, cannot replay nor tamper with requests, and cannot learn any metadata beyond the sender and receiver `User-IDs`.
19+
20+
The protocol incorporates the `Strandlock` protocol, which is an end-to-end encrypted protocol. It handles confidentity, integrity, and authenticity in a user-to-user manner, making our protocol simple because we do not have to implement replay nor tampering protection ourselves, it is handled by the users.
21+
22+
### 1. Terminology
23+
24+
For clarity, the following terms are used consistently throughout this specification:
25+
26+
#### Request (`message`, `ciphertext`)
27+
A generic protocol message sent from one party to another, via sending it to a Coldwire server to relay it.
28+
29+
#### Response (`message`, `ciphertext`)
30+
The reply to a Request, carrying the necessary protocol data to complete or continue a Strandlock operation.
31+
We use term "Response" and "Request" interchangably. A response is a request that's given to a party by `Coldwire` server.
32+
33+
#### User-ID (`identifier`)
34+
A long-term, randomly generated identifier which consists of a 16 digits string. It is generated on the server when a user first "registers" on a `Coldwire` server.
35+
36+
#### User federation ID (`federation identifier`)
37+
A `user-ID` with the URL of the `Coldwire` server appended at the end of it, separated by a `@` (i.e. `[email protected]`).
38+
39+
#### User Public-Key (`signing public-key`)
40+
A `ML-DSA-87` public-key, saved on the `Coldwire` server, tied to a specific `User-ID`
41+
42+
#### User Private-Key (`signing private key`, `signing key`)
43+
A `ML-DSA-87` private-key, private key is stored on the user's device locally, and the public-key is stored on the `Coldwire` server as the `signing public-key`.
44+
45+
#### Client Implementation
46+
Refers to a user-client implementation of the `Coldwire protocol`.
47+
48+
#### Server implementation
49+
Refers to a server implementation of the `Coldwire protocol`.
50+
51+
52+
### 2. HTTP Requests
53+
#### 2.1. Client Headers
54+
`Coldwire` client implementations *must* mimick mainstream, popular browsers headers.
55+
56+
All `Coldwire` client implementations *must* adhere to the following requirements for `HTTP` requests:
57+
- *All* `HTTP` field headers name **must** be lower-case, for compatiability with `HTTP/2` servers.
58+
The HTTP specification requires it, needed incase a Coldwire server implementation is behind another server.
59+
60+
- *All* header fields must be sent in the same exact order that the browser in question orders them.
61+
Helps against network requests fingerprinting.
62+
- Implementations **must** randomly pick a single browser and mimic its headers, and use them for the duration of the session
63+
If you rotate header sets between different requests, that creates a unique fingerprint to network adversaries, so avoid.
64+
65+
66+
67+
#### 2.2. Federated servers headers
68+
`Coldwire` server implementations *must* adhere to the following requirements for `HTTP` requests:
69+
- You **must not** include any headers that may indicate to a server you're intending to receive compressed (gzip, etc) response!
70+
71+
- *All* `HTTP` field headers name **must** be lower-case, for compatiability with `HTTP/2` servers.
72+
The HTTP specification requires it, needed incase a Coldwire server implementation is behind another server.
73+
74+
75+
76+
### 3. Authentication
77+
In `Coldwire` there is no concept of `registration` or `login`, instead, a user generates their `ML-DSA-87` keypair, sends the `public_key` to server, then authenticates by signing the given challenge.
78+
79+
The request payload **must** be in `JSON`, and the response will also be in `JSON`.
80+
**note** that `JSON` requests and responses only applies for the *authentication API* endpoints.
81+
82+
#### 3.1. Authentication Initialization (`Alice`)
83+
`Alice` sends an HTTP `POST` request to the endpoint running `Coldwire`
84+
```
85+
URL: example.com/authenticate/init
86+
```
87+
88+
**If** its `Alice's` first time authenticating to the server, she must not bundle a `user_id` field, only a *base64-encoded* `public_key` field, `JSON` payload:
89+
```json
90+
{
91+
"public_key": "base64_encoded_public_key"
92+
}
93+
```
94+
95+
96+
**If** `Alice` authenticated at least once before, she **must not** bundle a `public_key` field, only a `user_id` field:
97+
```json
98+
{
99+
"user_id": "1234567890123456"
100+
}
101+
```
102+
103+
104+
Server responds with a `JSON` response containing a `challenge`, which is a random `64-byte` *base64-encoded* string:
105+
```json
106+
{
107+
"challenge": "base64_encoded_challenge"
108+
}
109+
```
110+
111+
#### 3.2. Authentication Verification (`Alice`)
112+
113+
`Alice` must decode the `challenge` given to her in `2.1. Initialization` step, and sign it with her `ML-DSA-87` private key, and *base64-encode* the signature, and send it to the server, alongside the challenge string:
114+
115+
```json
116+
{
117+
"signature": "base64_encoded_signature",
118+
"challenge": "base64_encoded_challenge"
119+
}
120+
```
121+
122+
123+
After that is done, the server returns a `JSON` response with the `JWT token`, and his user's `User-ID` inside:
124+
```json
125+
{
126+
"user_id": "1234567890123456",
127+
"token": "User's JWT Token"
128+
}
129+
```
130+
131+
There is no expiration timestamp in the `JWT token`, the user simply keeps using the same `JWT token` token indefientely, until a server operator decides to rotate their `JWT` secret.
132+
133+
Even though there are no expiration timestamp, client implementations must always authenticate on application startup.
134+
135+
#### 3.3. Authentication Notes
136+
The reason we do include an expiration timestamp in the `JWT token` is to help reduce metadata emitting from both server, and client.
137+
138+
*Coldwire* server operators are recommended to rotate their `JWT secret` every month for cryptographic hyiegene, if you can rotate it more frequently, that is acceptable. The protocol does not enforce any `JWT secret` rotations.
139+
140+
Additionally, even if a user's `JWT token` is compromised, no catastrophic security issues arise, except potential denial-of-service risks for the user.
141+
Old messages cannot be retrieved and new messages cannot be read, contact list cannot be recovered, etc.
142+
New contacts can't be verified because the attacker wouldn't know a contact's `SMP` answer, only the real user does.
143+
144+
145+
If a server `JWT secret` is compromised, no catastrophic security issues arise, except potential denial-of-service risks for the server and its users.
146+
147+
The reason old and new messages cannot be read, is because we utilize the `Strandlock protocol` for true end-to-end encryption.
148+
149+
Messages are not just computationally safe, but in some scenarios, the message become uncrackable even with infinite computing power (to an adversary who only has access to a message's ciphertext, and not KEM's ciphertext, in which case OTP security inherits the algorithms in question security properties).
150+
151+
In real world, both a server's `JWT secret` and a user's `JWT token` are highly unlikely to be leaked, unless an endpoint compromise occurs.
152+
153+
`JWT secrets` are highly recommended to be (at least) `128 bytes`. But there are no protocol enforcements regarding this, you can make it as long as you wish.
154+
155+
### 4. Data
156+
`Coldwire`, when `Alice` talks to `Bob`, all the server(s) sees is `Alice's` & `Bob's` `User-ID`, and a ciphertext `blob`.
157+
158+
All requests sent are `HTTP Forms`, with `metadata` as a `Form Field`, and `blob` as a `File Upload`.
159+
160+
All requests sent must bundle an "authorization" header, containing the user's `JWT token`.
161+
162+
#### 4.1. Sending Data (`Alice` -> `Server`)
163+
`Alice` sends data to `Bob` by sending a `POST` request to the `Coldwire` server:
164+
```json
165+
URL: example.com/data/send
166+
```
167+
With `Form` payload:
168+
```json
169+
metadata: {
170+
"recipient": "Bobs User_ID"
171+
}
172+
```
173+
and bundled within the same request, is a `File Upload` with name `blob`, containing raw bytes (ciphertext, etc)
174+
175+
#### 4.2. Data processor (`Server`)
176+
`Coldwire` server receives data request, verifies the `Alice's` `JWT token`, and checks if the `recipient` is all digits:
177+
if not, checks if `recipient` format is correct (i.e. "[email protected]") and sends a request to the target `Coldwire` server.
178+
179+
If `recipient` is all digits, the server checks if they exist in the local database, if not, they return a 400 error.
180+
If they exist, the `Coldwire` server then processes the `blob`, rejecting it if it's empty.
181+
182+
If the sender or `recipient` contain a "@", request is rejected.
183+
184+
The `Coldwire` server then process the request by constructing a payload which consists of:
185+
```
186+
payload = user_id_utf_8 + \x0 + blob
187+
```
188+
Then the length of the `payload` is calculated, and a `length` prefix of size `3 bytes` in `big-endian` format is inserted at the start of the payload:
189+
```
190+
payload = length_prefix + payload
191+
```
192+
193+
And the data is saved to the `recipient` inbox (any saving medium, can be Redis, SQL database, etc).
194+
195+
#### 4.3. Receiving Data (`Bob` <- `Server`)
196+
`Bob` sends a `GET` request that longpolls the `Coldwire` endpoint:
197+
```
198+
URL: example.com/data/longpoll
199+
```
200+
201+
The `Coldewire` server sends a response of either empty bytes, or many `message_payloads` continunesly concatenated together.
202+
After `Coldwire` server sends a response to `Bob`, it deletes all the previously saved data payloads queue.
203+
204+
`Bob` client parses the response, by using the `length_prefix` at start of each message, `Bob` can separate each message.
205+
`Bob` then further parses it, by separating a message sender, from the blob, by splitting on the first NULL byte (`\0`)
206+
`Bob` client verifies the format of the `sender` identifier is correct, simply dismissing message if not.
207+
`Bob` then processes the `blob` using the `Strandlock protocol`
208+
209+
210+
#### 4.4. Notes
211+
Replay protection, tampering protection, authentication, MiTM protection, etc, are all handled by the `Strandlock protocol`.
212+
213+
The reason we send request in `Form` and `File Uploads`, and receive back response as `raw bytes`, is to save bandwidth. The `Strandlock protocol` can be quite heavy (some ciphertext reaching MBs in size).
214+
215+
216+
217+
218+

0 commit comments

Comments
 (0)