Metadata-Version: 2.4
Name: encrypted-keyring
Version: 0.1.0
Summary: Encrypted file-based keyring storage with a small command line interface.
License:                                  Apache License
                                   Version 2.0, January 2004
                                http://www.apache.org/licenses/
        
           TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
           1. Definitions.
        
              "License" shall mean the terms and conditions for use, reproduction,
              and distribution as defined by Sections 1 through 9 of this document.
        
              "Licensor" shall mean the copyright owner or entity authorized by
              the copyright owner that is granting the License.
        
              "Legal Entity" shall mean the union of the acting entity and all
              other entities that control, are controlled by, or are under common
              control with that entity. For the purposes of this definition,
              "control" means (i) the power, direct or indirect, to cause the
              direction or management of such entity, whether by contract or
              otherwise, or (ii) ownership of fifty percent (50%) or more of the
              outstanding shares, or (iii) beneficial ownership of such entity.
        
              "You" (or "Your") shall mean an individual or Legal Entity
              exercising permissions granted by this License.
        
              "Source" form shall mean the preferred form for making modifications,
              including but not limited to software source code, documentation
              source, and configuration files.
        
              "Object" form shall mean any form resulting from mechanical
              transformation or translation of a Source form, including but
              not limited to compiled object code, generated documentation,
              and conversions to other media types.
        
              "Work" shall mean the work of authorship, whether in Source or
              Object form, made available under the License, as indicated by a
              copyright notice that is included in or attached to the work
              (an example is provided in the Appendix below).
        
              "Derivative Works" shall mean any work, whether in Source or Object
              form, that is based on (or derived from) the Work and for which the
              editorial revisions, annotations, elaborations, or other modifications
              represent, as a whole, an original work of authorship. For the purposes
              of this License, Derivative Works shall not include works that remain
              separable from, or merely link (or bind by name) to the interfaces of,
              the Work and Derivative Works thereof.
        
              "Contribution" shall mean any work of authorship, including
              the original version of the Work and any modifications or additions
              to that Work or Derivative Works thereof, that is intentionally
              submitted to Licensor for inclusion in the Work by the copyright owner
              or by an individual or Legal Entity authorized to submit on behalf of
              the copyright owner. For the purposes of this definition, "submitted"
              means any form of electronic, verbal, or written communication sent
              to the Licensor or its representatives, including but not limited to
              communication on electronic mailing lists, source code control systems,
              and issue tracking systems that are managed by, or on behalf of, the
              Licensor for the purpose of discussing and improving the Work, but
              excluding communication that is conspicuously marked or otherwise
              designated in writing by the copyright owner as "Not a Contribution."
        
              "Contributor" shall mean Licensor and any individual or Legal Entity
              on behalf of whom a Contribution has been received by Licensor and
              subsequently incorporated within the Work.
        
           2. Grant of Copyright License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              copyright license to reproduce, prepare Derivative Works of,
              publicly display, publicly perform, sublicense, and distribute the
              Work and such Derivative Works in Source or Object form.
        
           3. Grant of Patent License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              (except as stated in this section) patent license to make, have made,
              use, offer to sell, sell, import, and otherwise transfer the Work,
              where such license applies only to those patent claims licensable
              by such Contributor that are necessarily infringed by their
              Contribution(s) alone or by combination of their Contribution(s)
              with the Work to which such Contribution(s) was submitted. If You
              institute patent litigation against any entity (including a
              cross-claim or counterclaim in a lawsuit) alleging that the Work
              or a Contribution incorporated within the Work constitutes direct
              or contributory patent infringement, then any patent licenses
              granted to You under this License for that Work shall terminate
              as of the date such litigation is filed.
        
           4. Redistribution. You may reproduce and distribute copies of the
              Work or Derivative Works thereof in any medium, with or without
              modifications, and in Source or Object form, provided that You
              meet the following conditions:
        
              (a) You must give any other recipients of the Work or
                  Derivative Works a copy of this License; and
        
              (b) You must cause any modified files to carry prominent notices
                  stating that You changed the files; and
        
              (c) You must retain, in the Source form of any Derivative Works
                  that You distribute, all copyright, patent, trademark, and
                  attribution notices from the Source form of the Work,
                  excluding those notices that do not pertain to any part of
                  the Derivative Works; and
        
              (d) If the Work includes a "NOTICE" text file as part of its
                  distribution, then any Derivative Works that You distribute must
                  include a readable copy of the attribution notices contained
                  within such NOTICE file, excluding those notices that do not
                  pertain to any part of the Derivative Works, in at least one
                  of the following places: within a NOTICE text file distributed
                  as part of the Derivative Works; within the Source form or
                  documentation, if provided along with the Derivative Works; or,
                  within a display generated by the Derivative Works, if and
                  wherever such third-party notices normally appear. The contents
                  of the NOTICE file are for informational purposes only and
                  do not modify the License. You may add Your own attribution
                  notices within Derivative Works that You distribute, alongside
                  or as an addendum to the NOTICE text from the Work, provided
                  that such additional attribution notices cannot be construed
                  as modifying the License.
        
              You may add Your own copyright statement to Your modifications and
              may provide additional or different license terms and conditions
              for use, reproduction, or distribution of Your modifications, or
              for any such Derivative Works as a whole, provided Your use,
              reproduction, and distribution of the Work otherwise complies with
              the conditions stated in this License.
        
           5. Submission of Contributions. Unless You explicitly state otherwise,
              any Contribution intentionally submitted for inclusion in the Work
              by You to the Licensor shall be under the terms and conditions of
              this License, without any additional terms or conditions.
              Notwithstanding the above, nothing herein shall supersede or modify
              the terms of any separate license agreement you may have executed
              with Licensor regarding such Contributions.
        
           6. Trademarks. This License does not grant permission to use the trade
              names, trademarks, service marks, or product names of the Licensor,
              except as required for reasonable and customary use in describing the
              origin of the Work and reproducing the content of the NOTICE file.
        
           7. Disclaimer of Warranty. Unless required by applicable law or
              agreed to in writing, Licensor provides the Work (and each
              Contributor provides its Contributions) on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
              implied, including, without limitation, any warranties or conditions
              of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
              PARTICULAR PURPOSE. You are solely responsible for determining the
              appropriateness of using or redistributing the Work and assume any
              risks associated with Your exercise of permissions under this License.
        
           8. Limitation of Liability. In no event and under no legal theory,
              whether in tort (including negligence), contract, or otherwise,
              unless required by applicable law (such as deliberate and grossly
              negligent acts) or agreed to in writing, shall any Contributor be
              liable to You for damages, including any direct, indirect, special,
              incidental, or consequential damages of any character arising as a
              result of this License or out of the use or inability to use the
              Work (including but not limited to damages for loss of goodwill,
              work stoppage, computer failure or malfunction, or any and all
              other commercial damages or losses), even if such Contributor
              has been advised of the possibility of such damages.
        
           9. Accepting Warranty or Additional Liability. While redistributing
              the Work or Derivative Works thereof, You may choose to offer,
              and charge a fee for, acceptance of support, warranty, indemnity,
              or other liability obligations and/or rights consistent with this
              License. However, in accepting such obligations, You may act only
              on Your own behalf and on Your sole responsibility, not on behalf
              of any other Contributor, and only if You agree to indemnify,
              defend, and hold each Contributor harmless for any liability
              incurred by, or claims asserted against, such Contributor by reason
              of your accepting any such warranty or additional liability.
        
           END OF TERMS AND CONDITIONS
        
           APPENDIX: How to apply the Apache License to your work.
        
              To apply the Apache License to your work, attach the following
              boilerplate notice, with the fields enclosed by brackets "[]"
              replaced with your own identifying information. (Don't include
              the brackets!)  The text should be enclosed in the appropriate
              comment syntax for the file format. We also recommend that a
              file or class name and description of purpose be included on the
              same "printed page" as the copyright notice for easier
              identification within third-party archives.
        
           Copyright [yyyy] [name of copyright owner]
        
           Licensed under the Apache License, Version 2.0 (the "License");
           you may not use this file except in compliance with the License.
           You may obtain a copy of the License at
        
               http://www.apache.org/licenses/LICENSE-2.0
        
           Unless required by applicable law or agreed to in writing, software
           distributed under the License is distributed on an "AS IS" BASIS,
           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           See the License for the specific language governing permissions and
           limitations under the License.
        
Keywords: keyring,encrypted,cryptography,passwords,cli
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Security :: Cryptography
Classifier: Topic :: Utilities
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: cryptography
Provides-Extra: dev
Requires-Dist: build; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: twine; extra == "dev"
Dynamic: license-file

# keyring

[![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue)](https://www.python.org/)
[![Status Alpha](https://img.shields.io/badge/status-alpha-orange)](#)
[![Tests](https://img.shields.io/badge/tests-pytest-success)](#tests)
[![Distribution](https://img.shields.io/badge/pypi-encrypted--keyring-blueviolet)](https://pypi.org/project/encrypted-keyring/)

Python-Paket für verschlüsselte Keyring-Dateien mit kleiner CLI und installierbarem Konsolenbefehl.

Das Projekt wird auf PyPI als `encrypted-keyring` veröffentlicht. Der Python-Import bleibt `keyring`.

## Status

Der aktuelle Stand des Repos ist:

- als Python-Paket importierbar
- als CLI über `python3 -m keyring` nutzbar
- als installierter Befehl `encrypted-keyring` verfügbar
- über `shell-alias.sh` zusätzlich als `keyring` aliasierbar
- mit automatisierten Tests unter `tests/` abgesichert
- auf PyPI vorbereitet über [pyproject.toml](pyproject.toml)

Kurz gesagt: Die Grundlage für eine veröffentlichte, installierbare Python-Bibliothek ist vorhanden, der Code ist als kleines Werkzeug direkt verwendbar, und die wichtigsten Pfade sind dokumentiert und getestet.

## Was das Paket macht

Dieses Repository stellt eine einfache, dateibasierte Geheimnisverwaltung bereit:

- Ein `Keyring`-Objekt zum Speichern, Lesen, Aktualisieren und Löschen von Einträgen
- Eine Kryptoschicht für die Ableitung von Schlüsseln und die Verschlüsselung der gespeicherten Daten
- Eine kleine Kommandozeilenanwendung für direkte Nutzung ohne eigenes Skript
- Eine Paketkonfiguration über `pyproject.toml`, damit das Projekt als echtes Python-Paket gebaut und veröffentlicht werden kann

Die Daten werden lokal in einer Datei gespeichert, verschlüsselt abgelegt und mit einem Master-Passwort geöffnet.

## Paket- und Importnamen

Wichtig ist die Unterscheidung zwischen Distribution und Import:

- PyPI-Name / Distribution: `encrypted-keyring`
- Python-Import: `keyring`
- Installierter CLI-Befehl: `encrypted-keyring`
- Optionaler Shell-Alias aus diesem Repo: `keyring`

Das ist absichtlich so gewählt, weil der Name `keyring` auf PyPI bereits stark belegt ist.

## Voraussetzungen

Das Projekt benötigt:

- Python 3.10 oder neuer
- `cryptography` zur Schlüsselableitung und Verschlüsselung

Die Laufzeitabhängigkeit ist in [pyproject.toml](pyproject.toml) beschrieben. Zusätzlich liegt [requirements.txt](requirements.txt) als einfache manuelle Liste im Repo.

## Installation

### Aus dem Repository für Entwicklung

Für eine lokale Entwicklungsumgebung:

```bash
python3 -m venv .venv
source .venv/bin/activate
pip install -e '.[dev]'
```

Das installiert:

- das Paket im Editable-Modus
- die Laufzeitabhängigkeit `cryptography`
- die Entwicklungswerkzeuge aus dem `dev`-Extra

### Als reguläre Installation

Wenn das Paket später von PyPI installiert wird:

```bash
pip install encrypted-keyring
```

## Schnellstart

Ein einfaches Beispiel für die Nutzung als Modul:

```python
from pathlib import Path

from keyring import Keyring

ring = Keyring(path=Path("keyring.dat"), password="mein-master-passwort")
ring.put(
    "github",
    user="alice",
    password="geheim",
    description="Privates Konto",
)

print(ring.names())
print(ring.get("github"))
```

Ausgabe und Verhalten hängen natürlich von deinem Inhalt ab, aber der typische Ablauf ist:

1. Keyring-Datei öffnen oder anlegen
2. Eintrag speichern
3. Eintrag wieder lesen
4. Einträge bei Bedarf löschen

## Nutzung als Modul

`keyring` exportiert die zentrale Klasse `Keyring` direkt auf Paket-Ebene:

```python
from keyring import Keyring
```

### API-Übersicht

- `Keyring(path, password)` öffnet oder erstellt eine Keyring-Datei
- `names()` liefert eine Liste aller gespeicherten Eintragsnamen
- `get(name)` liest einen Eintrag als `dict` oder gibt `None` zurück
- `put(name, user=None, password=None, description=None, overwrite=False)` speichert einen Eintrag
- `delete(name)` entfernt einen Eintrag

### Typisches Muster

```python
from pathlib import Path

from keyring import Keyring

ring = Keyring(path=Path("keyring.dat"), password="master")

if "github" not in ring.names():
    ring.put(
        "github",
        user="alice",
        password="geheim",
        description="Privates Konto",
    )

entry = ring.get("github")
if entry is not None:
    print(entry["user"])
    print(entry["password"])
    print(entry["description"])
```

### Verhalten von `put`

Beim Speichern eines neuen Eintrags:

- wird ein zufälliger interner Schlüssel erzeugt
- werden `user`, `password` und `description` jeweils separat verschlüsselt
- wird der interne Schlüssel selbst mit dem Master-Passwort verschlüsselt und separat abgelegt

Das bedeutet: Der eigentliche Inhalt eines Eintrags ist nicht direkt mit demselben Schlüssel wie die Datei selbst verschlüsselt.

## Kleine Anwendung

Die CLI ist für direkte Benutzung gedacht und arbeitet mit derselben Keyring-Datei wie das Modul.

Der Einstieg läuft über:

```bash
python3 -m keyring --help
```

Standardmäßig verwendet die CLI die Datei `keyring.dat` im aktuellen Arbeitsverzeichnis.

### Globale Optionen

- `-f`, `--file`: Pfad zur Keyring-Datei
- `-p`, `--password`: Master-Passwort für die Datei

Wenn `--password` fehlt, wird es interaktiv abgefragt.

### Befehle

#### `list`

Listet alle gespeicherten Einträge auf.

```bash
python3 -m keyring -p "mein-master-passwort" list
```

#### `show`

Zeigt einen einzelnen Eintrag an.

```bash
python3 -m keyring -p "mein-master-passwort" show github
```

#### `add`

Legt einen Eintrag an oder ersetzt ihn mit `--overwrite`.

```bash
python3 -m keyring -p "mein-master-passwort" add github --user "alice" --entry-password "geheim" --description "Privates Konto"
```

Wenn der Eintrag bereits existiert und nicht überschrieben werden soll, bricht die CLI mit einer Fehlermeldung ab.

#### `delete`

Löscht einen gespeicherten Eintrag.

```bash
python3 -m keyring -p "mein-master-passwort" delete github
```

### Beispielablauf

```bash
python3 -m keyring -p "master" add demo --user alice --entry-password secret --description test
python3 -m keyring -p "master" list
python3 -m keyring -p "master" show demo
python3 -m keyring -p "master" delete demo
```

## Shell-Alias

Wenn du den installierten CLI-Befehl lieber als `keyring` aufrufen möchtest, kannst du das beiliegende Alias-Snippet laden:

```bash
source ./shell-alias.sh
```

Die Datei [shell-alias.sh](shell-alias.sh) enthält:

```bash
alias keyring='encrypted-keyring'
```

Hinweis:

- Das ist ein Shell-Alias, kein Python-Import.
- Der Alias betrifft nur deine aktuelle Shell-Sitzung, solange du ihn nicht dauerhaft in deiner Shell-Startdatei einträgst.
- In einer dauerhaften Konfiguration kannst du denselben Alias zum Beispiel in `~/.bashrc` oder `~/.zshrc` hinterlegen.

## Tests

Für das Projekt existiert eine `pytest`-Suite unter [tests/](tests):

- [tests/test_crypto.py](tests/test_crypto.py)
- [tests/test_keyring.py](tests/test_keyring.py)
- [tests/test_cli.py](tests/test_cli.py)

Die Tests decken ab:

- Verschlüsselung und Entschlüsselung mit `str`- und `bytes`-Passwörtern
- Erzeugen zufälliger Eintrags-Schlüssel
- Speichern, Laden, Löschen und Auflisten von Einträgen
- CLI-Verhalten über den `main()`-Einstiegspunkt

Zusätzlich sind folgende Szenarien abgedeckt:

- Erzeugen und erneutes Laden einer leeren Keyring-Datei
- Fehlverhalten bei falschem Master-Passwort
- `get()` und `delete()` bei nicht vorhandenen Einträgen
- Überschreiben und Nicht-Überschreiben bestehender Einträge
- CLI-Fehlerfälle für `show`, `add` ohne `--overwrite` und `delete`
- CLI-Hilfe über `--help`

### Tests ausführen

```bash
python3 -m pytest -q
```

Falls dein System-Python extern verwaltet ist, empfiehlt sich ein virtuelles Umfeld:

```bash
python3 -m venv .venv
source .venv/bin/activate
pip install -e '.[dev]'
python3 -m pytest -q
```

## Packaging und Veröffentlichung

Die Paketdefinition liegt vollständig in [pyproject.toml](pyproject.toml).

Wichtige Punkte daraus:

- Build-Backend: `setuptools`
- Distribution-Name: `encrypted-keyring`
- Konsolenbefehl: `encrypted-keyring`
- Python-Version: `>=3.10`
- Laufzeitabhängigkeit: `cryptography`
- Entwicklungsabhängigkeiten: `build`, `pytest`, `twine`

### Lokales Builden

```bash
python3 -m build
```

Das erzeugt typischerweise:

- ein Source Distribution Archiv
- ein Wheel

### Veröffentlichungsprüfung

Vor einem Upload ist ein Trockenlauf sinnvoll:

```bash
python3 -m twine check dist/*
```

### Upload auf PyPI

Wenn du veröffentlichen willst:

```bash
python3 -m twine upload dist/*
```

## Datenformat und Verhalten

- Die Keyring-Datei wird verschlüsselt gespeichert.
- Beim Schreiben wird eine temporäre Datei verwendet und anschließend atomar ersetzt.
- Nach dem Schreiben wird die Datei mit Berechtigung `600` versehen, damit nur der Besitzer lesen und schreiben kann.
- Die interne Struktur trennt die eigentlichen Eintragsdaten von den verschlüsselten Eintrags-Schlüsseln.
- Die Kryptoschicht akzeptiert Passwortwerte als `str` oder als `bytes`.
- Zufällige Eintrags-Schlüssel werden intern als Bytes erzeugt und verschlüsselt abgelegt.
- Die Datei `keyring.dat` ist eine Laufzeitdatei und gehört nicht ins Git-Repository.

## Projektstruktur

- `keyring/__init__.py` - Paket-Exports für `Keyring` und `Crypto`
- `keyring/__main__.py` - CLI-Einstiegspunkt
- `keyring/crypto.py` - Schlüsselableitung, Verschlüsselung und Entschlüsselung
- `keyring/keyring.py` - Laden, Speichern und Verwalten der Keyring-Daten
- `pyproject.toml` - Build-, Packaging- und Test-Konfiguration
- `requirements.txt` - manuelle Liste der Laufzeitabhängigkeiten
- `shell-alias.sh` - Shell-Alias für den CLI-Befehl
- `tests/` - automatisierte Tests

## Veröffentlichung und Nutzung

Ein typischer Ablauf für die Weiterentwicklung ist:

1. Code ändern
2. Tests ergänzen oder anpassen
3. `python3 -m pytest -q` ausführen
4. `python3 -m build` ausführen
5. `python3 -m twine check dist/*` prüfen
6. Paket auf PyPI hochladen

## Hinweise

- Der Python-Import bleibt `keyring`, auch wenn die Distribution `encrypted-keyring` heißt.
- Die CLI ist separat installierbar und kann über den Shell-Alias bequem auf `keyring` gelegt werden.
- Wenn du neue Funktionen ergänzt, sollten dazu passende Tests und eine kurze Dokumentation dazukommen.
