Basilisk developer guide

Basilisk runs on your own computer and has no HTTP API. Its developer surface is the plugin API (version 1): commands and event hooks written in Python.

Add a command

A plugin is one Python file with a register(api) function. api.register_command(name, help, func, configure=None) adds basilisk <name>. func(args) gets the argparse namespace and may return an exit code. configure(subparser) adds the command's own arguments.

hello.py

def hello(args):
    print("Hello, %s." % args.name)
    return 0


def configure_hello(parser):
    parser.add_argument("--name", default="world", help="Who to greet.")


def on_encrypt(event):
    # event is a read-only mapping: status, fingerprints, filename, signed, armored ...
    print("encrypt %s for %d recipient(s)" % (event["status"], len(event.get("fingerprints", ()))))


def register(api):
    api.register_command("hello", "Print a greeting.", hello, configure=configure_hello)
    api.on_encrypt(on_encrypt)

Rules

  • Command names are lowercase letters, digits and hyphens, up to 32 characters, starting with a letter.
  • Built-in names (plugins, encrypt, decrypt, sign, verify, help, version and other reserved names) and names another plugin already took are refused with PluginError.
  • Registration is only allowed while register(api) runs.
  • api.name, api.api_version (currently 1) and api.events are read-only.

React to events

api.on(event, handler) calls handler(event) with a read-only mapping. Shortcuts: api.on_startup, on_encrypt, on_decrypt, on_sign, on_verify.

EventWhenTypical fields
on_startupThe desktop window is createdversion, plugins
on_encryptAfter text or a file is encryptedstatus, fingerprints, signed, armored, filename
on_decryptAfter a decrypt attemptstatus, key_fingerprint, signed, signature_valid, filename
on_signAfter signingstatus, key_fingerprint, mode, filename
on_verifyAfter a verify attemptstatus, signature_valid, signer_fingerprint

Events only ever hold non-secret fields: event, status (ok or failed), version, plugins, fingerprints, key_fingerprint, signer_fingerprint, signer_fingerprints, filename (base name only), mode, armored, signed, signature_valid. Handlers run after the operation, cannot change its result, and an exception in a handler is logged by plugin name and ignored.

Turn plugins on

Plugins are off by default. Run Basilisk with --plugins, or set enabled = true in plugins.toml.

plugins.toml

enabled = true
# Optional pin list. When present, only files with these SHA-256 hashes are loaded.
allow_sha256 = ["<64 hex characters>"]

Locations

  • Plugin folder: %APPDATA%\Basilisk\plugins on Windows, ~/.config/basilisk/plugins elsewhere ($XDG_CONFIG_HOME/basilisk/plugins if set). Override with BASILISK_PLUGIN_DIR.
  • plugins.toml sits next to the plugin folder. Override with BASILISK_PLUGIN_CONFIG.
  • basilisk plugins list shows each loaded plugin with its SHA-256 and what it registered, and each skipped plugin with the reason.

What plugins can and cannot see

The plugin API has no vault, keyring or key access. Plaintext, passphrases, private keys and authenticator seeds are never passed to a handler.

  • A plugin is ordinary Python running inside Basilisk. It is not sandboxed: it can read files or open network connections like any script you run. Only use code you wrote or trust, and pin it with allow_sha256.
  • The hash is taken from the exact bytes that are then executed, and no bytecode is written next to the plugin.
  • A plugin that fails to load (syntax error, exception, missing register, hash not allowed, bad name) is logged by file name with the error type and skipped. Basilisk keeps running.
  • Files starting with _ or ., sub-folders and symbolic links are ignored. A broken plugins.toml disables plugins rather than loading everything.