Metadata-Version: 2.5
Name: pyssh2age
Version: 1.0.0
Summary: Convert SSH Ed25519 keys to age keys (pure-Python port of ssh-to-age)
Project-URL: Homepage, https://github.com/ivankra/pyssh2age
Project-URL: Source, https://github.com/ivankra/pyssh2age
Project-URL: Issues, https://github.com/ivankra/pyssh2age/issues
Author: Ivan Krasilnikov
License-Expression: MIT
License-File: LICENSE
Keywords: age,ed25519,sops,sops-nix,ssh,x25519
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Intended Audience :: System Administrators
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Security :: Cryptography
Classifier: Topic :: Utilities
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# pyssh2age

Convert SSH Ed25519 keys to [age](https://github.com/FiloSottile/age) keys,
e.g. for [sops](https://github.com/getsops/sops) or [sops-nix](https://github.com/Mic92/sops-nix).

A single-file pure-Python port of [ssh-to-age](https://github.com/Mic92/ssh-to-age) that produces the same keys.
Python 3.9+, using only the standard library and `ssh-keygen` to decrypt passphrase-protected keys.

The conversion is the standard Ed25519 → X25519 mapping
([explained here](https://blog.filippo.io/using-ed25519-keys-for-encryption/)):
the age secret is `sha512(seed)[:32]`, and the age public key is the Montgomery
u-coordinate of the Ed25519 public point, `u = (1 + y) / (1 - y)`.

## Install

```console
$ pipx install pyssh2age    # or: uv tool install pyssh2age
```

This installs the `pyssh2age` command and `ssh-to-age` alias.
Or copy [`src/pyssh2age.py`](https://github.com/ivankra/pyssh2age/blob/main/src/pyssh2age.py) anywhere and run it.

## Usage

```console
$ cat ~/.ssh/id_ed25519.pub | pyssh2age
age17044m9u...

$ pyssh2age -i ~/.ssh/id_ed25519.pub
age17044m9u...

$ ssh-keyscan host1 host2 | pyssh2age    # or authorized_keys, known_hosts
skipped key: got ssh-rsa key type, but only ed25519 keys are supported
age1hjm3au...
age1v8zjc4...

$ pyssh2age --private-key -i ~/.ssh/id_ed25519 -o key.txt    # see Security below
```

Decrypting passphrase-protected private keys needs a Unix-like system;
everything else also works on Windows.

For a passphrase-protected key you're prompted on the terminal. In scripts,
use `--stdinpass` or `SSH_TO_AGE_PASSPHRASE`:

```console
$ systemd-ask-password | pyssh2age --private-key --stdinpass -i ~/.ssh/id_ed25519 -o key.txt
```

The age identity file (`-o`) is created with mode 0600, atomically replacing
any existing file. As in the Go version, options work with one or two dashes.

## Library

```python
import pyssh2age

pyssh2age.ssh_public_key_to_age("ssh-ed25519 AAAA... me@host")    # "age1..."
pyssh2age.ssh_public_keys_to_age(open("authorized_keys").read())  # ["age1...", ...]

key = open("id_ed25519").read()
try:
    identity = pyssh2age.ssh_private_key_to_age(key)              # "AGE-SECRET-KEY-1..."
except pyssh2age.PassphraseRequired:
    identity = pyssh2age.ssh_private_key_to_age(key, passphrase="...")
```

Failures raise `ConvertError`; non-Ed25519 keys raise its subclass
`UnsupportedKeyType`. Lower-level helpers: `ed25519_public_to_x25519`,
`ed25519_seed_to_x25519`, `x25519_public`, `age_recipient`, `age_identity`.

## Security

- **The age key is as powerful as the SSH key.** The original `id_ed25519` file you
  derived it from can't be recovered, but it *is* the Ed25519 signing scalar:
  whoever has it can sign as the SSH key and log in wherever that key is authorized.
- **Output file is written unencrypted** (as in the Go version),
  even if the SSH key has a passphrase. Encrypt it with:
  `pyssh2age --private-key ... | age -p -o key.txt.age`.

## Development

The tests need `ssh-keygen` and `openssl`, and also check results with `age`
if it's installed:

```console
$ python3 tests/test_pyssh2age.py
$ GO_SSH_TO_AGE=/path/to/ssh-to-age python3 tests/test_pyssh2age.py    # also compare with the Go version
```

## License

MIT. Based on [ssh-to-age](https://github.com/Mic92/ssh-to-age) by Jörg Thalheim.
