Skip to content

Commit cff3a8d

Browse files
Joseph Ibrahimclaude
andcommitted
feat(messaging): add Matrix bot with PQ secure channel
Implements mobile messaging interface for OTTO OS via Matrix protocol: Matrix Bot (matrix_bot.py): - E2E encryption via Olm/Megolm (when matrix-nio installed) - Mock client for testing without homeserver - Command handling with auth/encryption requirements - State persistence across restarts PQ Secure Channel (secure_channel.py): - Additional encryption layer using hybrid X25519+ML-KEM - Key exchange with forward secrecy - Replay attack prevention (nonce tracking, timestamp validation) - Threshold signature integration for critical operations OTTO Commands (commands.py): - !health, !info, !status - System monitoring - !secure status|list|rotate - Channel management - !threshold sign|approve - N-of-M signing - !admin users|rooms|config - Administration Security layers (defense in depth): 1. Matrix Olm/Megolm (transport) 2. OTTO PQ crypto (payload, quantum-resistant) 3. Threshold signatures (critical ops) 35 tests covering bot, commands, secure channel, key exchange. [He2025] Compliant: Fixed algorithms, deterministic key derivation. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 1646534 commit cff3a8d

5 files changed

Lines changed: 2716 additions & 0 deletions

File tree

src/otto/messaging/__init__.py

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
"""
2+
OTTO OS Messaging Module
3+
========================
4+
5+
Secure mobile messaging for OTTO OS via Matrix protocol.
6+
7+
Features:
8+
- Matrix bot with E2E encryption (Olm/Megolm)
9+
- Additional PQ crypto layer (X25519 + ML-KEM-768)
10+
- Threshold signature support for critical operations
11+
- Command handling for OTTO operations
12+
13+
Components:
14+
- matrix_bot: Core Matrix client and bot logic
15+
- secure_channel: PQ crypto overlay
16+
- commands: OTTO-specific command handlers
17+
18+
Quick Start:
19+
from otto.messaging import create_bot, register_otto_commands
20+
21+
# Create bot
22+
bot = create_bot(
23+
homeserver="https://matrix.example.org",
24+
user_id="@otto:example.org",
25+
)
26+
27+
# Register OTTO commands
28+
register_otto_commands(bot)
29+
30+
# Login and run
31+
await bot.login(password="...")
32+
await bot.run()
33+
34+
Dependencies:
35+
- matrix-nio[e2e]: For Matrix protocol support (optional, has mock)
36+
- otto.crypto: For PQ cryptography
37+
38+
Security Model:
39+
- Layer 1: Matrix Olm/Megolm (E2E encryption)
40+
- Layer 2: OTTO PQ crypto (quantum-resistant payload encryption)
41+
- Layer 3: Threshold signatures (N-of-M approval for critical ops)
42+
"""
43+
44+
from .matrix_bot import (
45+
# Core bot
46+
OTTOMatrixBot,
47+
create_bot,
48+
# Config
49+
BotConfig,
50+
BotState,
51+
# Messages
52+
MatrixMessage,
53+
MessageType,
54+
# Commands
55+
Command,
56+
CommandHandler,
57+
# Clients
58+
MatrixClientProtocol,
59+
MockMatrixClient,
60+
NioMatrixClient,
61+
# Exceptions
62+
MatrixBotError,
63+
ConnectionError,
64+
AuthenticationError,
65+
EncryptionError,
66+
)
67+
68+
from .secure_channel import (
69+
# Core
70+
SecureChannel,
71+
ThresholdSecureChannel,
72+
create_secure_channel,
73+
# Data types
74+
SecurePayload,
75+
KeyExchangeMessage,
76+
ChannelState,
77+
ChannelInfo,
78+
# Exceptions
79+
SecureChannelError,
80+
KeyExchangeError,
81+
DecryptionError,
82+
SignatureError,
83+
ReplayError,
84+
)
85+
86+
from .commands import (
87+
OTTOCommands,
88+
register_otto_commands,
89+
otto_command,
90+
)
91+
92+
__all__ = [
93+
# Matrix Bot
94+
"OTTOMatrixBot",
95+
"create_bot",
96+
"BotConfig",
97+
"BotState",
98+
"MatrixMessage",
99+
"MessageType",
100+
"Command",
101+
"CommandHandler",
102+
"MatrixClientProtocol",
103+
"MockMatrixClient",
104+
"NioMatrixClient",
105+
"MatrixBotError",
106+
"ConnectionError",
107+
"AuthenticationError",
108+
"EncryptionError",
109+
# Secure Channel
110+
"SecureChannel",
111+
"ThresholdSecureChannel",
112+
"create_secure_channel",
113+
"SecurePayload",
114+
"KeyExchangeMessage",
115+
"ChannelState",
116+
"ChannelInfo",
117+
"SecureChannelError",
118+
"KeyExchangeError",
119+
"DecryptionError",
120+
"SignatureError",
121+
"ReplayError",
122+
# Commands
123+
"OTTOCommands",
124+
"register_otto_commands",
125+
"otto_command",
126+
]

0 commit comments

Comments
 (0)