How dkg/monkeysphere works
Project type and purpose
• Monkeysphere is an open-source security tool / framework (not a web app) that extends the OpenPGP “web of trust” to SSH. It provides a suite of CLI utilities, scripts, and configuration files to manage SSH known_hosts and authorized_keys via GnuPG keys.
File structure
• Top-level directories:
• etc – default configuration files (monkeysphere.conf, host/authentication configs, cron job)
• src – the C binaries and shell/PERL scripts that implement Monkeysphere commands
• src/share – library of helper scripts (m, ma, mh subcommands) called by the main binaries
• tests – automated test fixtures for configs, keyrings, SSH setups
• utils – packaging and release-prep scripts
• man – manpages for each command
• examples – sample configuration and usage snippets
• Build & deploy: Makefile, packaging/ (macports, slackware)
• Transitions: contains upgrade scripts for database/migration logic.
Key insights from README
• Core flow: CLI commands invoke GnuPG (via Crypt::OpenSSL::RSA or gpg2), verify keys, then update SSH files.
• Dependencies: GnuPG ≥2.1.11, Perl, Bash, OpenSSH ssh-keygen, lockfile tools.
• Intended use cases: ad-hoc CLI, cron-driven periodic updates.
a. Main components:
• User/Admin – invokes Monkeysphere commands or cron
• Monkeysphere CLI Layer – C programs (agent-transfer, monkeysphere, openpgp2ssh, pem2openpgp, host/authentication subcommands)
• Script Library – share/m*, share/ma*, share/mh* helper scripts
• Configuration – etc/*.conf, ~/.monkeysphere/
• GnuPG Service – GPG keyrings, gpg2 daemon or process
• OpenSSH Tools – ssh-keygen, known_hosts, authorized_keys
• File System – clients’ ~/.ssh and /etc/ssh files
• Cron Daemon – runs scheduled updates in etc/cron.hourly
• Test Harness – automated tests invoking the above in a sandbox
b. Relationships & interactions:
1. Admin/User or cron invokes a Monkeysphere CLI binary
2. CLI binary loads configuration from etc/ or ~/.monkeysphere
3. It calls out to GnuPG (gpg2) or Crypt::OpenSSL::RSA to fetch/verify OpenPGP keys
4. It invokes share scripts (m, ma, mh) to perform key lookups, trust calculations, and file transformations
5. It calls ssh-keygen or directly writes to known_hosts/authorized_keys
6. Lockfile is used to serialize concurrent writes
7. SSH connections subsequently use the managed key files
c. Architectural patterns & principles:
• Modular CLI: each binary does one job (Unix philosophy)
• Shared script library: DRY helper functions in src/share
• Layered external integration: clearly separated GPG layer and SSH layer
• Migration/versioning: transitions directory holds upgrade scripts
d. Technologies & frameworks:
• C for high-performance CLI clients
• Bash / Perl scripts for logic in src/share/*
• GnuPG (gpg2), Crypt::OpenSSL::RSA
• OpenSSH’s ssh-keygen
• lockfile-progs or procmail lockfile