65 lines
3.4 KiB
Markdown
65 lines
3.4 KiB
Markdown
# XtendR
|
|

|
|
|
|
A very basic Python 3.12 friendly plugin system based on the K.I.S.S principle.
|
|
|
|
I was in need of a new plugin system, which should meet these requirements:
|
|
:heavy_plus_sign: Simple to use
|
|
:heavy_plus_sign: Work well with Python 3.12
|
|
:heavy_plus_sign: Maintainable - Don't expect to see new releases every month. __If it ain't broken, don't fix it!!!__
|
|
|
|
I previously used yapsy, but it doesn't meet the requirements anymore.
|
|
:x: No longer simple, and simple to use (Simplicity in use has been sacrificed for more complexity. It has become bloated)
|
|
:x: Not workink with Python 3.12
|
|
:x: No longer maintained (Hasn't been maintained for a few years)
|
|
|
|
I didn't find anything that suited my needs, so I decided to make my own plugin system.
|
|
It simply contains 2 classes, one for the plugin system and one abstraction base class for the plugins themselves.
|
|
|
|
At the moment only 4 functions are available:
|
|
|
|
- Attach - including call to pre-load data in plugin.
|
|
- Run
|
|
- Stop
|
|
- Detach
|
|
|
|
Attach and Detach are used for registrering/unregistrering a module on the system.
|
|
The Run and Stop functions are mandatory in the plugin modules.
|
|
|
|
The system expects a folder called 'plugins', placed at the root, along side your main python file.
|
|
Each plugin should be placed in subfolders, named as the plugin, inside the 'plugins' folder.
|
|
|
|
The example.py along with the plugins/example_plugin/example_plugin.py and plugins/example_plugin/example_plugin.json shows the workings of this plugin system.
|
|
|
|
## Security
|
|
|
|
Plugins are Python code that runs with the host's full rights, so XtendR only runs a plugin whose
|
|
manifest (`<name>.json`) and module (`<module>.py`) match an Ed25519-signed whitelist entry.
|
|
Unsigned or tampered plugins are listed but never executed. Since 0.5.4 XtendR reads each file
|
|
exactly once, checks the signature over those bytes and runs those same bytes: no second read from
|
|
disk, no `__pycache__` bytecode, no symlinked files.
|
|
|
|
Signing proves a plugin is unchanged since it was signed, not that it is safe. Keep the private key
|
|
off shared machines and pin the public key in the host application.
|
|
|
|
## Testing
|
|
|
|
python3 -m pytest tests -v
|
|
|
|
## Changes
|
|
|
|
- **0.5.4** — Plugins run exactly the code that was verified.
|
|
- *Fixed:* a `__pycache__/<module>.cpython-*.pyc` carrying the signed source's mtime and size
|
|
ran instead of the verified `.py` (the import machinery preferred the cache). `attach()` now
|
|
compiles and executes the verified bytes itself and never consults or writes bytecode.
|
|
- *Fixed:* files were read once to verify and again to import, and the manifest was parsed
|
|
before it was hashed. A file swapped in between could run unverified code or point the import
|
|
at another module. Each file is now read once (`O_NOFOLLOW`, regular files only, size-capped),
|
|
and the manifest's `module`/`class` must equal the signed entry's.
|
|
- New `signing.hash_plugin_bytes()` and `verify_plugin_bytes()`; the digest is unchanged, so
|
|
existing whitelists stay valid. `generate_keypair()` creates the private key 0600 from the
|
|
start; `Whitelist.save()` writes atomically and keeps the file's permissions.
|
|
- `setup.py` declares `cryptography>=42`; `__version__` reports 0.5.4 (was a stale 0.5.1).
|
|
- New `tests/test_integrity.py` (real keys; fails on 0.5.3 for the bypasses above). The
|
|
`XtendRBase` doctest example implements `pre_load` so it runs again.
|