-
Notifications
You must be signed in to change notification settings - Fork 25
Overview
MockSSH is built on top of the Twisted networking engine, specifically using the Conch SSH implementation. It provides a high-level abstraction for simulating SSH servers and interactive shells.
The core of the library manages the SSH transport layer, authentication, and session handling.
-
SSHRealm: Manages the "realm" of the server, mapping authenticated users to theirAvatar. -
SSHAvatar: Represents the user session once authenticated. It provides theSSHUserwith a shell or a subsystem. -
SSHProtocol: Handles the terminal interaction, line buffering, and command dispatching.
MockSSH uses a pluggable command system. Every command is a class that inherits from SSHCommand.
-
SSHCommand: The base class for all commands. It provides methods likewriteln()andexit(). -
PromptingCommand: A specialized command for multi-step interactions (e.g., password prompts). -
ArgumentValidatingCommand: A command that validates its arguments before execution.
The shell acts as the primary interface for users. It matches input strings against registered commands and handles the "fallback" behavior for unknown commands.
For users who prefer a declarative configuration style, MockSSH provides a DSL written in Hy (a LISP on Python). This allows defining complex server behaviors in a format that looks more like configuration than code.
-
Protocol State: The
SSHProtocolinstance maintains the current prompt and session-wide state. -
Command State: Individual commands can maintain their own state during their lifecycle (from
start()toexit()).
MockSSH implements modern SSH security standards:
- Host Keys: Supports Ed25519 and ECDSA by default.
- Ciphers: Restricted to modern CTR mode ciphers.
-
Authentication: Uses
twisted.credfor robust, pluggable authentication.