Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify end of stream behaviour #24

Merged
merged 5 commits into from
Feb 8, 2024
Merged
Changes from 2 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
19 changes: 16 additions & 3 deletions handshake.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Cable Handshake

Version: 1.0-draft6
Version: 1.0-draft7

Published: January 2024
Published: February 2024

Author: Kira Oakley

Expand All @@ -26,6 +26,7 @@ Author: Kira Oakley
+ [5.2 Fragmentation](#52-fragmentation)
+ [5.3 Message encoding](#53-message-encoding)
+ [5.4 Message decoding](#54-message-decoding)
+ [5.5 End of stream](#55-end-of-stream)
* [6. Security considerations](#6-security-considerations)
+ [6.1 Out-of-scope attacks](#61-out-of-scope-attacks)
+ [6.2 In-scope attacks](#62-in-scope-attacks)
Expand Down Expand Up @@ -371,7 +372,7 @@ Noise for encryption, and then prefixed with an encrypted length indicator.
Incoming Cable Wire Protocol messages will also be length-prefixed, and the
message bodies will be encrypted as *ciphertext*s, and must be run through
Noise for decryption. There are additional steps to handle message
fragmentation, described in the next subsection.
fragmentation and end of stream markers, described in the next subsection.
hackergrrl marked this conversation as resolved.
Show resolved Hide resolved

The Noise function `Split()`, run at the end of the Noise Handshake, returns a
pair of `CipherState` objects `(c1, c2)` to be used as follows:
Expand Down Expand Up @@ -460,13 +461,18 @@ these steps:

3. `WriteMsg(plaintext)`

4. `WriteBytes(0)`
mycognosist marked this conversation as resolved.
Show resolved Hide resolved

If, for example, a `plaintext` of length 90200 were to be encoded & written,
the first 65519 bytes would first be encrypted and written, followed by the
remaining 24681 bytes being encrypted and written. Since each ciphertext has an
extra 16 bytes added of authentication data, and there are two segments
written, the total written length would be `65519 + 24681 + 16 * 2 = 90232`
bytes.

The fourth step is described in the [End of stream](#55-end-of-stream)
subsection.

mycognosist marked this conversation as resolved.
Show resolved Hide resolved
### 5.4 Message decoding
This subsection defines pseudocode function `plaintext = ReadMsg(len)` that
reads a ciphertext message of length `len`, performing de-fragmentation and
Expand Down Expand Up @@ -496,6 +502,13 @@ Reading a Cable Wire Protocol message MUST follow these steps:
3. The resulting bytes `plaintext` may then be parsed as a Cable Wire Protocol
message.

### 5.5 End of stream
After a complete Cable Wire Protocol message is sent, regardless of whether
it consists of one or several fragments, the sender MUST write a message of
`length=0`. This final message serves as an end of stream marker for the
mycognosist marked this conversation as resolved.
Show resolved Hide resolved
receiving peer and enables the peer to differentiate between an intentionally
terminated stream and a dropped connection.
mycognosist marked this conversation as resolved.
Show resolved Hide resolved

## 6. Security considerations
### 6.1 Out-of-scope attacks
Attacks on the inner Cable Wire Protocol are not considered here. See the
Expand Down