Skip to main content

OpenSSH-based signer for Swarmauri

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_signing_ssh


swarmauri_signing_ssh

An OpenSSH-based signer implementing the ISigning interface for detached signatures over raw bytes and canonicalized envelopes.

Features:

  • Detached signatures powered by OpenSSH ssh-keygen -Y for Ed25519, RSA and ECDSA keys.
  • Accepts private keys from filesystem paths or in-memory PEM blobs.
  • JSON canonicalization built in with optional CBOR canonicalization via cbor2.
  • Envelope helpers for canonicalized signing and verification workflows.

Requirements

  • OpenSSH ssh-keygen (v8.2 or newer with -Y support) must be available on PATH.
  • Install the optional cbor extra (swarmauri_signing_ssh[cbor]) to enable CBOR canonicalization.

Installation

pip

pip install swarmauri_signing_ssh

Enable CBOR canonicalization when desired:

pip install "swarmauri_signing_ssh[cbor]"

uv

uv add swarmauri_signing_ssh
uv add "swarmauri_signing_ssh[cbor]"

Poetry

poetry add swarmauri_signing_ssh
poetry add swarmauri_signing_ssh -E cbor

Usage

Supported key references

Provide the signer with a KeyRef dictionary:

  • {"kind": "path", "priv": "/path/to/id_ed25519", "identity": "optional"} references a private key on disk.
  • {"kind": "pem", "priv": "-----BEGIN OPENSSH PRIVATE KEY-----..."} accepts an OpenSSH private key as text/bytes. The key material is written to a secure temporary file for signing.

The signer derives the corresponding public key line, fingerprint (kid) and algorithm token automatically.

Verification options

  • Pass one or more OpenSSH public key lines via opts["pubkeys"] when calling verify_bytes or verify_envelope. Verification fails immediately when the list is missing or empty.
  • Override the namespace used by ssh-keygen -Y through opts["namespace"] (defaults to "file").
  • Supply the expected signer identity with opts["identity"]. Identities default to signer{i} based on index order.
  • Restrict acceptable signatures via the require mapping. Supported keys are "algs", "kids" and "min_signers".

README example: sign and verify an SSH signature

import asyncio
import subprocess
import tempfile
from pathlib import Path

from swarmauri_signing_ssh import SshEnvelopeSigner


async def main() -> bool:
    signer = SshEnvelopeSigner()

    with tempfile.TemporaryDirectory() as tmpdir:
        tmpdir_path = Path(tmpdir)
        priv_path = tmpdir_path / "id_ed25519"
        subprocess.run(
            ["ssh-keygen", "-t", "ed25519", "-N", "", "-f", str(priv_path)],
            check=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        pubkey_line = priv_path.with_suffix(".pub").read_text(encoding="utf-8").strip()

        key = {"kind": "path", "priv": str(priv_path), "identity": "readme-demo"}
        payload = b"hello ssh signatures"

        signatures = await signer.sign_bytes(key, payload)
        return await signer.verify_bytes(
            payload,
            signatures,
            opts={"pubkeys": [pubkey_line], "identity": "readme-demo"},
        )


if __name__ == "__main__":  # pragma: no cover - README execution path
    print(asyncio.run(main()))

Running the script prints True once verification succeeds.

Envelope workflows

Use sign_envelope / verify_envelope alongside canonicalize_envelope to operate on structured payloads. JSON canonicalization is always available; enable the cbor extra to emit canonical CBOR bytes.

RSA keys default to sha256 hashing but accept hashalg="sha512" via either the key reference or opts. All signatures are detached (features include "detached_only"), and multiple signatures can be verified in a single call.

Entry Point

The signer registers under the swarmauri.signings entry point as SshEnvelopeSigner.

Want to help?

If you want to contribute to swarmauri-sdk, read up on our guidelines for contributing that will help you get started.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

swarmauri_signing_ssh-0.3.0.dev45.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

swarmauri_signing_ssh-0.3.0.dev45-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file swarmauri_signing_ssh-0.3.0.dev45.tar.gz.

File metadata

  • Download URL: swarmauri_signing_ssh-0.3.0.dev45.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_signing_ssh-0.3.0.dev45.tar.gz
Algorithm Hash digest
SHA256 bf62f96c2fa147b714e483795eaa55ed3ed8717bf3b7863642dc3f8c577dd397
MD5 4a5995199422f597454821378b6cc285
BLAKE2b-256 cf22cba5409c115e64f4590c271635958862753e2c8512fd37c56ddf7805986b

See more details on using hashes here.

File details

Details for the file swarmauri_signing_ssh-0.3.0.dev45-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_signing_ssh-0.3.0.dev45-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_signing_ssh-0.3.0.dev45-py3-none-any.whl
Algorithm Hash digest
SHA256 391ac6690df09ca9152f3b1f6ccab30b95219eb5cf39474f60850a3a0694b789
MD5 a6abb3d79469459f42b916ea4050b421
BLAKE2b-256 77ee7f0c2742a05567ca8576abf8be38f1c3e71c9e15692a722025acf8f88262

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page