Skip to content

Commit 23969d7

Browse files
committed
feat: add multi-device capabilities, tests, update README and add acknowledgement so we transition to whisper messages
1 parent cc7de3e commit 23969d7

File tree

4 files changed

+229
-15
lines changed

4 files changed

+229
-15
lines changed

README.md

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ This repository serves as a technical demonstration of Signal Protocol implement
88

99
- Complete Signal Protocol implementation
1010
- Key exchange mechanisms
11-
- Session establishment
11+
- Session establishment and proper acknowledgment
1212
- Message encryption/decryption
1313
- Multi-user communication scenarios
14+
- Multi-device support per user
15+
- Group messaging
1416

1517
**Important**: This codebase is designed to be explored through its test suite. The tests serve as living documentation and executable examples of the Signal Protocol implementation.
1618

@@ -43,8 +45,11 @@ The main Signal Protocol implementation featuring:
4345
- Identity key pair generation and management
4446
- PreKey bundle creation and distribution
4547
- Session establishment with other users
48+
- Proper session acknowledgment for Double Ratchet initialization
4649
- Message encryption using the Double Ratchet algorithm
4750
- Message decryption and session management
51+
- Multi-device support through device-specific sessions
52+
- Group messaging with sender key distribution
4853

4954
#### `SignalClientState` (`lib/client/signal_client.freezed.dart`)
5055
Immutable state management using Freezed, containing:
@@ -59,12 +64,15 @@ Immutable state management using Freezed, containing:
5964
#### Data Models
6065
- `UserKeys` (`lib/server/models/user_keys.dart`): Represents a user's PreKey bundle for key exchange
6166
- `Message` (`lib/common/models/message.dart`): Encapsulates encrypted message data
67+
- `GroupMessage` (`lib/common/models/group_message.dart`): Represents encrypted group messages
6268
- `PublicPreKey` & `PublicSignedPreKey` (`lib/server/models/`): Key structures for exchange
6369

6470
#### (Mock) Server Communication (`lib/server/server.dart`)
6571
- PreKey bundle upload and retrieval
6672
- Encrypted message routing
6773
- Message acknowledgment handling
74+
- Multi-device awareness
75+
- Group membership management
6876

6977
#### Utilities
7078
- `Logger` (`lib/utils/logger.dart`): Logging utility for debugging
@@ -91,14 +99,16 @@ lib/
9199
92100
test/
93101
├── signal_protocol_test.dart # Comprehensive test scenarios
94-
└── key_reuse_test.dart # Tests for key reuse prevention
102+
├── key_reuse_test.dart # Tests for key reuse prevention
103+
└── multi_device_test.dart # Tests for multi-device support
95104
```
96105

97106
## 🧪 Understanding the Implementation Through Tests
98107

99108
The test suites serve as the primary documentation for this PoC. Each test file demonstrates specific aspects of the Signal Protocol:
100109
- `test/signal_protocol_test.dart`: Core protocol implementation scenarios
101110
- `test/key_reuse_test.dart`: Security tests for preventing key reuse attacks
111+
- `test/multi_device_test.dart`: Tests for multi-device support
102112

103113
### Running the Test Suite
104114

@@ -129,18 +139,31 @@ flutter test --name "should establish session and exchange messages"
129139
- Illustrates initial session creation
130140
- Shows the X3DH key agreement protocol
131141
- Demonstrates session caching
142+
- Properly acknowledges and transitions session states
132143

133144
4. **Message Exchange**
134145
- Shows complete message encryption flow
135146
- Demonstrates the Double Ratchet algorithm
147+
- Illustrates proper message type transitions (prekey → whisper)
136148
- Illustrates message decryption
137149

138150
5. **Multi-User Scenarios**
139151
- Complex interactions between multiple users
140152
- Concurrent session management
141153
- Message ordering and delivery
142154

143-
6. **Key Reuse Prevention** (in `key_reuse_test.dart`)
155+
6. **Multi-Device Support**
156+
- Multiple devices for a single user
157+
- Proper message routing to all user devices
158+
- Independent session management per device
159+
160+
7. **Group Messaging**
161+
- Sender key distribution for groups
162+
- Group membership management
163+
- Encrypted group communication
164+
- Handling members joining existing groups
165+
166+
8. **Key Reuse Prevention** (in `key_reuse_test.dart`)
144167
- Ensures one-time PreKeys are not reused
145168
- Validates security against key reuse attacks
146169
- Tests proper key rotation mechanisms
@@ -158,6 +181,9 @@ The implementation follows the Signal Protocol specification:
158181
3. **One-Time PreKeys**: Ephemeral keys for perfect forward secrecy
159182
4. **Sessions**: Established using X3DH (Extended Triple Diffie-Hellman)
160183
5. **Double Ratchet**: Provides forward secrecy and break-in recovery
184+
6. **Session Acknowledgment**: Ensures proper state transitions for the ratchet
185+
7. **Multi-Device Support**: Manages separate cryptographic sessions for each device
186+
8. **Group Messaging**: Uses sender keys for efficient group communication
161187

162188
### State Management
163189

@@ -170,7 +196,8 @@ Uses Freezed for immutable state management:
170196

171197
The implementation requires a compatible server that:
172198
- Stores and serves PreKey bundles
173-
- Routes encrypted messages between users
199+
- Routes encrypted messages between users and devices
200+
- Manages group membership
174201
- Never has access to plaintext content
175202

176203
## 🔒 Security Considerations
@@ -181,14 +208,18 @@ This PoC demonstrates the following security properties:
181208
- **Perfect Forward Secrecy**: Compromised keys don't affect past communications
182209
- **Break-in Recovery**: Compromised keys don't affect future communications
183210
- **Deniable Authentication**: Messages can be authenticated by the recipient but anyone could have forged messages after the conversation - protecting users from being cryptographically proven to have sent a message
211+
- **Multi-Device Security**: Each device maintains its own cryptographic session, preventing compromise of all devices if one is breached
184212

185213
## 🚦 What This PoC Demonstrates
186214

187215
✅ Complete Signal Protocol implementation in Dart
188216
✅ Proper key management and rotation
189217
✅ Session establishment between users
218+
✅ Session acknowledgment and state management
190219
✅ Message encryption and decryption
191220
✅ Multi-user communication patterns
221+
✅ Multi-device support per user
222+
✅ Group messaging with sender keys
192223
✅ Server integration for key exchange
193224

194225
## 🚫 What This PoC Doesn't Include
@@ -197,8 +228,8 @@ This PoC demonstrates the following security properties:
197228
❌ Persistent storage of keys and sessions
198229
❌ Production-ready error handling
199230
❌ Message delivery guarantees
200-
❌ Group messaging
201231
❌ Media/file encryption
232+
❌ Comprehensive cryptographic auditing
202233

203234
## 📚 Learning from the Code
204235

@@ -207,17 +238,45 @@ To understand the Signal Protocol implementation:
207238
1. Start with the main test file: `test/signal_protocol_test.dart`
208239
2. Follow the test scenarios in order
209240
3. Review security tests in `test/key_reuse_test.dart`
210-
4. Examine the `SignalClient` implementation in `lib/client/signal_client.dart`
211-
5. Review the state management in `SignalClientState`
212-
6. Understand the server interactions in `lib/server/server.dart`
213-
7. Explore the data models in `lib/common/models/` and `lib/server/models/`
241+
4. Explore multi-device capabilities in `test/multi_device_test.dart`
242+
5. Examine the `SignalClient` implementation in `lib/client/signal_client.dart`
243+
6. Review the state management in `SignalClientState`
244+
7. Understand the server interactions in `lib/server/server.dart`
245+
8. Explore the data models in `lib/common/models/` and `lib/server/models/`
246+
247+
## Key Signal Protocol Features Explained
248+
249+
### Session Acknowledgment
250+
251+
The PoC implements proper session acknowledgment, which is crucial for the Double Ratchet algorithm:
252+
- Initial messages use PreKey messages (containing X3DH materials)
253+
- After session establishment, a cryptographic acknowledgment occurs
254+
- Subsequent messages use the more efficient "whisper" message type
255+
- This follows the Signal Protocol's security design for session establishment
256+
257+
### Multi-Device Support
258+
259+
The implementation demonstrates how Signal handles multiple devices for a single user:
260+
- Each device has its own identity and cryptographic material
261+
- Messages sent to a user are delivered to all their devices
262+
- Each device maintains independent sessions with other users' devices
263+
- This models Signal's approach to multi-device support
264+
265+
### Group Messaging
266+
267+
Group messaging is implemented using sender keys:
268+
- Each member distributes their sender key to the group
269+
- Messages are efficiently encrypted once and distributed to all members
270+
- New members can join existing groups
271+
- This matches Signal's efficient approach to group communication
214272

215273
## 🔗 References
216274

217275
- [Signal Protocol Documentation](https://signal.org/docs/)
218276
- [libsignal_protocol_dart](https://pub.dev/packages/libsignal_protocol_dart)
219277
- [The X3DH Key Agreement Protocol](https://signal.org/docs/specifications/x3dh/)
220278
- [The Double Ratchet Algorithm](https://signal.org/docs/specifications/doubleratchet/)
279+
- [Sender Keys for Group Messaging](https://signal.org/docs/specifications/group-sessions/)
221280

222281
## 🤝 Contributing
223282

@@ -240,4 +299,4 @@ The GPL-3.0 license ensures that:
240299

241300
---
242301

243-
This proof-of-concept demonstrates how the Signal Protocol can be implemented in Flutter/Dart. Explore the test suite to understand the implementation details.
302+
This proof-of-concept demonstrates how the Signal Protocol can be implemented in Flutter/Dart. Explore the test suite to understand the implementation details.

0 commit comments

Comments
 (0)