encrypted-keyring 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- encrypted_keyring-0.1.0.dist-info/METADATA +587 -0
- encrypted_keyring-0.1.0.dist-info/RECORD +10 -0
- encrypted_keyring-0.1.0.dist-info/WHEEL +5 -0
- encrypted_keyring-0.1.0.dist-info/entry_points.txt +2 -0
- encrypted_keyring-0.1.0.dist-info/licenses/LICENSE +201 -0
- encrypted_keyring-0.1.0.dist-info/top_level.txt +1 -0
- keyring/__init__.py +6 -0
- keyring/__main__.py +156 -0
- keyring/crypto.py +33 -0
- keyring/keyring.py +93 -0
|
@@ -0,0 +1,587 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: encrypted-keyring
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Encrypted file-based keyring storage with a small command line interface.
|
|
5
|
+
License: Apache License
|
|
6
|
+
Version 2.0, January 2004
|
|
7
|
+
http://www.apache.org/licenses/
|
|
8
|
+
|
|
9
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
10
|
+
|
|
11
|
+
1. Definitions.
|
|
12
|
+
|
|
13
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
14
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
15
|
+
|
|
16
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
17
|
+
the copyright owner that is granting the License.
|
|
18
|
+
|
|
19
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
20
|
+
other entities that control, are controlled by, or are under common
|
|
21
|
+
control with that entity. For the purposes of this definition,
|
|
22
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
23
|
+
direction or management of such entity, whether by contract or
|
|
24
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
25
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
26
|
+
|
|
27
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
28
|
+
exercising permissions granted by this License.
|
|
29
|
+
|
|
30
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
31
|
+
including but not limited to software source code, documentation
|
|
32
|
+
source, and configuration files.
|
|
33
|
+
|
|
34
|
+
"Object" form shall mean any form resulting from mechanical
|
|
35
|
+
transformation or translation of a Source form, including but
|
|
36
|
+
not limited to compiled object code, generated documentation,
|
|
37
|
+
and conversions to other media types.
|
|
38
|
+
|
|
39
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
40
|
+
Object form, made available under the License, as indicated by a
|
|
41
|
+
copyright notice that is included in or attached to the work
|
|
42
|
+
(an example is provided in the Appendix below).
|
|
43
|
+
|
|
44
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
45
|
+
form, that is based on (or derived from) the Work and for which the
|
|
46
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
47
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
48
|
+
of this License, Derivative Works shall not include works that remain
|
|
49
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
50
|
+
the Work and Derivative Works thereof.
|
|
51
|
+
|
|
52
|
+
"Contribution" shall mean any work of authorship, including
|
|
53
|
+
the original version of the Work and any modifications or additions
|
|
54
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
55
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
56
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
57
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
58
|
+
means any form of electronic, verbal, or written communication sent
|
|
59
|
+
to the Licensor or its representatives, including but not limited to
|
|
60
|
+
communication on electronic mailing lists, source code control systems,
|
|
61
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
62
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
63
|
+
excluding communication that is conspicuously marked or otherwise
|
|
64
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
65
|
+
|
|
66
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
67
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
68
|
+
subsequently incorporated within the Work.
|
|
69
|
+
|
|
70
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
71
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
72
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
73
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
74
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
75
|
+
Work and such Derivative Works in Source or Object form.
|
|
76
|
+
|
|
77
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
78
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
79
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
80
|
+
(except as stated in this section) patent license to make, have made,
|
|
81
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
82
|
+
where such license applies only to those patent claims licensable
|
|
83
|
+
by such Contributor that are necessarily infringed by their
|
|
84
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
85
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
86
|
+
institute patent litigation against any entity (including a
|
|
87
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
88
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
89
|
+
or contributory patent infringement, then any patent licenses
|
|
90
|
+
granted to You under this License for that Work shall terminate
|
|
91
|
+
as of the date such litigation is filed.
|
|
92
|
+
|
|
93
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
94
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
95
|
+
modifications, and in Source or Object form, provided that You
|
|
96
|
+
meet the following conditions:
|
|
97
|
+
|
|
98
|
+
(a) You must give any other recipients of the Work or
|
|
99
|
+
Derivative Works a copy of this License; and
|
|
100
|
+
|
|
101
|
+
(b) You must cause any modified files to carry prominent notices
|
|
102
|
+
stating that You changed the files; and
|
|
103
|
+
|
|
104
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
105
|
+
that You distribute, all copyright, patent, trademark, and
|
|
106
|
+
attribution notices from the Source form of the Work,
|
|
107
|
+
excluding those notices that do not pertain to any part of
|
|
108
|
+
the Derivative Works; and
|
|
109
|
+
|
|
110
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
111
|
+
distribution, then any Derivative Works that You distribute must
|
|
112
|
+
include a readable copy of the attribution notices contained
|
|
113
|
+
within such NOTICE file, excluding those notices that do not
|
|
114
|
+
pertain to any part of the Derivative Works, in at least one
|
|
115
|
+
of the following places: within a NOTICE text file distributed
|
|
116
|
+
as part of the Derivative Works; within the Source form or
|
|
117
|
+
documentation, if provided along with the Derivative Works; or,
|
|
118
|
+
within a display generated by the Derivative Works, if and
|
|
119
|
+
wherever such third-party notices normally appear. The contents
|
|
120
|
+
of the NOTICE file are for informational purposes only and
|
|
121
|
+
do not modify the License. You may add Your own attribution
|
|
122
|
+
notices within Derivative Works that You distribute, alongside
|
|
123
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
124
|
+
that such additional attribution notices cannot be construed
|
|
125
|
+
as modifying the License.
|
|
126
|
+
|
|
127
|
+
You may add Your own copyright statement to Your modifications and
|
|
128
|
+
may provide additional or different license terms and conditions
|
|
129
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
130
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
131
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
132
|
+
the conditions stated in this License.
|
|
133
|
+
|
|
134
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
135
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
136
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
137
|
+
this License, without any additional terms or conditions.
|
|
138
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
139
|
+
the terms of any separate license agreement you may have executed
|
|
140
|
+
with Licensor regarding such Contributions.
|
|
141
|
+
|
|
142
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
143
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
144
|
+
except as required for reasonable and customary use in describing the
|
|
145
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
146
|
+
|
|
147
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
148
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
149
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
150
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
151
|
+
implied, including, without limitation, any warranties or conditions
|
|
152
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
153
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
154
|
+
appropriateness of using or redistributing the Work and assume any
|
|
155
|
+
risks associated with Your exercise of permissions under this License.
|
|
156
|
+
|
|
157
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
158
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
159
|
+
unless required by applicable law (such as deliberate and grossly
|
|
160
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
161
|
+
liable to You for damages, including any direct, indirect, special,
|
|
162
|
+
incidental, or consequential damages of any character arising as a
|
|
163
|
+
result of this License or out of the use or inability to use the
|
|
164
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
165
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
166
|
+
other commercial damages or losses), even if such Contributor
|
|
167
|
+
has been advised of the possibility of such damages.
|
|
168
|
+
|
|
169
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
170
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
171
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
172
|
+
or other liability obligations and/or rights consistent with this
|
|
173
|
+
License. However, in accepting such obligations, You may act only
|
|
174
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
175
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
176
|
+
defend, and hold each Contributor harmless for any liability
|
|
177
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
178
|
+
of your accepting any such warranty or additional liability.
|
|
179
|
+
|
|
180
|
+
END OF TERMS AND CONDITIONS
|
|
181
|
+
|
|
182
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
183
|
+
|
|
184
|
+
To apply the Apache License to your work, attach the following
|
|
185
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
186
|
+
replaced with your own identifying information. (Don't include
|
|
187
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
188
|
+
comment syntax for the file format. We also recommend that a
|
|
189
|
+
file or class name and description of purpose be included on the
|
|
190
|
+
same "printed page" as the copyright notice for easier
|
|
191
|
+
identification within third-party archives.
|
|
192
|
+
|
|
193
|
+
Copyright [yyyy] [name of copyright owner]
|
|
194
|
+
|
|
195
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
196
|
+
you may not use this file except in compliance with the License.
|
|
197
|
+
You may obtain a copy of the License at
|
|
198
|
+
|
|
199
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
200
|
+
|
|
201
|
+
Unless required by applicable law or agreed to in writing, software
|
|
202
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
203
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
204
|
+
See the License for the specific language governing permissions and
|
|
205
|
+
limitations under the License.
|
|
206
|
+
|
|
207
|
+
Keywords: keyring,encrypted,cryptography,passwords,cli
|
|
208
|
+
Classifier: Development Status :: 3 - Alpha
|
|
209
|
+
Classifier: Intended Audience :: Developers
|
|
210
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
211
|
+
Classifier: Operating System :: OS Independent
|
|
212
|
+
Classifier: Programming Language :: Python :: 3
|
|
213
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
214
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
215
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
216
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
217
|
+
Classifier: Topic :: Security :: Cryptography
|
|
218
|
+
Classifier: Topic :: Utilities
|
|
219
|
+
Requires-Python: >=3.10
|
|
220
|
+
Description-Content-Type: text/markdown
|
|
221
|
+
License-File: LICENSE
|
|
222
|
+
Requires-Dist: cryptography
|
|
223
|
+
Provides-Extra: dev
|
|
224
|
+
Requires-Dist: build; extra == "dev"
|
|
225
|
+
Requires-Dist: pytest; extra == "dev"
|
|
226
|
+
Requires-Dist: twine; extra == "dev"
|
|
227
|
+
Dynamic: license-file
|
|
228
|
+
|
|
229
|
+
# keyring
|
|
230
|
+
|
|
231
|
+
[](https://www.python.org/)
|
|
232
|
+
[](#)
|
|
233
|
+
[](#tests)
|
|
234
|
+
[](https://pypi.org/project/encrypted-keyring/)
|
|
235
|
+
|
|
236
|
+
Python-Paket für verschlüsselte Keyring-Dateien mit kleiner CLI und installierbarem Konsolenbefehl.
|
|
237
|
+
|
|
238
|
+
Das Projekt wird auf PyPI als `encrypted-keyring` veröffentlicht. Der Python-Import bleibt `keyring`.
|
|
239
|
+
|
|
240
|
+
## Status
|
|
241
|
+
|
|
242
|
+
Der aktuelle Stand des Repos ist:
|
|
243
|
+
|
|
244
|
+
- als Python-Paket importierbar
|
|
245
|
+
- als CLI über `python3 -m keyring` nutzbar
|
|
246
|
+
- als installierter Befehl `encrypted-keyring` verfügbar
|
|
247
|
+
- über `shell-alias.sh` zusätzlich als `keyring` aliasierbar
|
|
248
|
+
- mit automatisierten Tests unter `tests/` abgesichert
|
|
249
|
+
- auf PyPI vorbereitet über [pyproject.toml](pyproject.toml)
|
|
250
|
+
|
|
251
|
+
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.
|
|
252
|
+
|
|
253
|
+
## Was das Paket macht
|
|
254
|
+
|
|
255
|
+
Dieses Repository stellt eine einfache, dateibasierte Geheimnisverwaltung bereit:
|
|
256
|
+
|
|
257
|
+
- Ein `Keyring`-Objekt zum Speichern, Lesen, Aktualisieren und Löschen von Einträgen
|
|
258
|
+
- Eine Kryptoschicht für die Ableitung von Schlüsseln und die Verschlüsselung der gespeicherten Daten
|
|
259
|
+
- Eine kleine Kommandozeilenanwendung für direkte Nutzung ohne eigenes Skript
|
|
260
|
+
- Eine Paketkonfiguration über `pyproject.toml`, damit das Projekt als echtes Python-Paket gebaut und veröffentlicht werden kann
|
|
261
|
+
|
|
262
|
+
Die Daten werden lokal in einer Datei gespeichert, verschlüsselt abgelegt und mit einem Master-Passwort geöffnet.
|
|
263
|
+
|
|
264
|
+
## Paket- und Importnamen
|
|
265
|
+
|
|
266
|
+
Wichtig ist die Unterscheidung zwischen Distribution und Import:
|
|
267
|
+
|
|
268
|
+
- PyPI-Name / Distribution: `encrypted-keyring`
|
|
269
|
+
- Python-Import: `keyring`
|
|
270
|
+
- Installierter CLI-Befehl: `encrypted-keyring`
|
|
271
|
+
- Optionaler Shell-Alias aus diesem Repo: `keyring`
|
|
272
|
+
|
|
273
|
+
Das ist absichtlich so gewählt, weil der Name `keyring` auf PyPI bereits stark belegt ist.
|
|
274
|
+
|
|
275
|
+
## Voraussetzungen
|
|
276
|
+
|
|
277
|
+
Das Projekt benötigt:
|
|
278
|
+
|
|
279
|
+
- Python 3.10 oder neuer
|
|
280
|
+
- `cryptography` zur Schlüsselableitung und Verschlüsselung
|
|
281
|
+
|
|
282
|
+
Die Laufzeitabhängigkeit ist in [pyproject.toml](pyproject.toml) beschrieben. Zusätzlich liegt [requirements.txt](requirements.txt) als einfache manuelle Liste im Repo.
|
|
283
|
+
|
|
284
|
+
## Installation
|
|
285
|
+
|
|
286
|
+
### Aus dem Repository für Entwicklung
|
|
287
|
+
|
|
288
|
+
Für eine lokale Entwicklungsumgebung:
|
|
289
|
+
|
|
290
|
+
```bash
|
|
291
|
+
python3 -m venv .venv
|
|
292
|
+
source .venv/bin/activate
|
|
293
|
+
pip install -e '.[dev]'
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
Das installiert:
|
|
297
|
+
|
|
298
|
+
- das Paket im Editable-Modus
|
|
299
|
+
- die Laufzeitabhängigkeit `cryptography`
|
|
300
|
+
- die Entwicklungswerkzeuge aus dem `dev`-Extra
|
|
301
|
+
|
|
302
|
+
### Als reguläre Installation
|
|
303
|
+
|
|
304
|
+
Wenn das Paket später von PyPI installiert wird:
|
|
305
|
+
|
|
306
|
+
```bash
|
|
307
|
+
pip install encrypted-keyring
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
## Schnellstart
|
|
311
|
+
|
|
312
|
+
Ein einfaches Beispiel für die Nutzung als Modul:
|
|
313
|
+
|
|
314
|
+
```python
|
|
315
|
+
from pathlib import Path
|
|
316
|
+
|
|
317
|
+
from keyring import Keyring
|
|
318
|
+
|
|
319
|
+
ring = Keyring(path=Path("keyring.dat"), password="mein-master-passwort")
|
|
320
|
+
ring.put(
|
|
321
|
+
"github",
|
|
322
|
+
user="alice",
|
|
323
|
+
password="geheim",
|
|
324
|
+
description="Privates Konto",
|
|
325
|
+
)
|
|
326
|
+
|
|
327
|
+
print(ring.names())
|
|
328
|
+
print(ring.get("github"))
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
Ausgabe und Verhalten hängen natürlich von deinem Inhalt ab, aber der typische Ablauf ist:
|
|
332
|
+
|
|
333
|
+
1. Keyring-Datei öffnen oder anlegen
|
|
334
|
+
2. Eintrag speichern
|
|
335
|
+
3. Eintrag wieder lesen
|
|
336
|
+
4. Einträge bei Bedarf löschen
|
|
337
|
+
|
|
338
|
+
## Nutzung als Modul
|
|
339
|
+
|
|
340
|
+
`keyring` exportiert die zentrale Klasse `Keyring` direkt auf Paket-Ebene:
|
|
341
|
+
|
|
342
|
+
```python
|
|
343
|
+
from keyring import Keyring
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
### API-Übersicht
|
|
347
|
+
|
|
348
|
+
- `Keyring(path, password)` öffnet oder erstellt eine Keyring-Datei
|
|
349
|
+
- `names()` liefert eine Liste aller gespeicherten Eintragsnamen
|
|
350
|
+
- `get(name)` liest einen Eintrag als `dict` oder gibt `None` zurück
|
|
351
|
+
- `put(name, user=None, password=None, description=None, overwrite=False)` speichert einen Eintrag
|
|
352
|
+
- `delete(name)` entfernt einen Eintrag
|
|
353
|
+
|
|
354
|
+
### Typisches Muster
|
|
355
|
+
|
|
356
|
+
```python
|
|
357
|
+
from pathlib import Path
|
|
358
|
+
|
|
359
|
+
from keyring import Keyring
|
|
360
|
+
|
|
361
|
+
ring = Keyring(path=Path("keyring.dat"), password="master")
|
|
362
|
+
|
|
363
|
+
if "github" not in ring.names():
|
|
364
|
+
ring.put(
|
|
365
|
+
"github",
|
|
366
|
+
user="alice",
|
|
367
|
+
password="geheim",
|
|
368
|
+
description="Privates Konto",
|
|
369
|
+
)
|
|
370
|
+
|
|
371
|
+
entry = ring.get("github")
|
|
372
|
+
if entry is not None:
|
|
373
|
+
print(entry["user"])
|
|
374
|
+
print(entry["password"])
|
|
375
|
+
print(entry["description"])
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
### Verhalten von `put`
|
|
379
|
+
|
|
380
|
+
Beim Speichern eines neuen Eintrags:
|
|
381
|
+
|
|
382
|
+
- wird ein zufälliger interner Schlüssel erzeugt
|
|
383
|
+
- werden `user`, `password` und `description` jeweils separat verschlüsselt
|
|
384
|
+
- wird der interne Schlüssel selbst mit dem Master-Passwort verschlüsselt und separat abgelegt
|
|
385
|
+
|
|
386
|
+
Das bedeutet: Der eigentliche Inhalt eines Eintrags ist nicht direkt mit demselben Schlüssel wie die Datei selbst verschlüsselt.
|
|
387
|
+
|
|
388
|
+
## Kleine Anwendung
|
|
389
|
+
|
|
390
|
+
Die CLI ist für direkte Benutzung gedacht und arbeitet mit derselben Keyring-Datei wie das Modul.
|
|
391
|
+
|
|
392
|
+
Der Einstieg läuft über:
|
|
393
|
+
|
|
394
|
+
```bash
|
|
395
|
+
python3 -m keyring --help
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
Standardmäßig verwendet die CLI die Datei `keyring.dat` im aktuellen Arbeitsverzeichnis.
|
|
399
|
+
|
|
400
|
+
### Globale Optionen
|
|
401
|
+
|
|
402
|
+
- `-f`, `--file`: Pfad zur Keyring-Datei
|
|
403
|
+
- `-p`, `--password`: Master-Passwort für die Datei
|
|
404
|
+
|
|
405
|
+
Wenn `--password` fehlt, wird es interaktiv abgefragt.
|
|
406
|
+
|
|
407
|
+
### Befehle
|
|
408
|
+
|
|
409
|
+
#### `list`
|
|
410
|
+
|
|
411
|
+
Listet alle gespeicherten Einträge auf.
|
|
412
|
+
|
|
413
|
+
```bash
|
|
414
|
+
python3 -m keyring -p "mein-master-passwort" list
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
#### `show`
|
|
418
|
+
|
|
419
|
+
Zeigt einen einzelnen Eintrag an.
|
|
420
|
+
|
|
421
|
+
```bash
|
|
422
|
+
python3 -m keyring -p "mein-master-passwort" show github
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
#### `add`
|
|
426
|
+
|
|
427
|
+
Legt einen Eintrag an oder ersetzt ihn mit `--overwrite`.
|
|
428
|
+
|
|
429
|
+
```bash
|
|
430
|
+
python3 -m keyring -p "mein-master-passwort" add github --user "alice" --entry-password "geheim" --description "Privates Konto"
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
Wenn der Eintrag bereits existiert und nicht überschrieben werden soll, bricht die CLI mit einer Fehlermeldung ab.
|
|
434
|
+
|
|
435
|
+
#### `delete`
|
|
436
|
+
|
|
437
|
+
Löscht einen gespeicherten Eintrag.
|
|
438
|
+
|
|
439
|
+
```bash
|
|
440
|
+
python3 -m keyring -p "mein-master-passwort" delete github
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
### Beispielablauf
|
|
444
|
+
|
|
445
|
+
```bash
|
|
446
|
+
python3 -m keyring -p "master" add demo --user alice --entry-password secret --description test
|
|
447
|
+
python3 -m keyring -p "master" list
|
|
448
|
+
python3 -m keyring -p "master" show demo
|
|
449
|
+
python3 -m keyring -p "master" delete demo
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
## Shell-Alias
|
|
453
|
+
|
|
454
|
+
Wenn du den installierten CLI-Befehl lieber als `keyring` aufrufen möchtest, kannst du das beiliegende Alias-Snippet laden:
|
|
455
|
+
|
|
456
|
+
```bash
|
|
457
|
+
source ./shell-alias.sh
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
Die Datei [shell-alias.sh](shell-alias.sh) enthält:
|
|
461
|
+
|
|
462
|
+
```bash
|
|
463
|
+
alias keyring='encrypted-keyring'
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
Hinweis:
|
|
467
|
+
|
|
468
|
+
- Das ist ein Shell-Alias, kein Python-Import.
|
|
469
|
+
- Der Alias betrifft nur deine aktuelle Shell-Sitzung, solange du ihn nicht dauerhaft in deiner Shell-Startdatei einträgst.
|
|
470
|
+
- In einer dauerhaften Konfiguration kannst du denselben Alias zum Beispiel in `~/.bashrc` oder `~/.zshrc` hinterlegen.
|
|
471
|
+
|
|
472
|
+
## Tests
|
|
473
|
+
|
|
474
|
+
Für das Projekt existiert eine `pytest`-Suite unter [tests/](tests):
|
|
475
|
+
|
|
476
|
+
- [tests/test_crypto.py](tests/test_crypto.py)
|
|
477
|
+
- [tests/test_keyring.py](tests/test_keyring.py)
|
|
478
|
+
- [tests/test_cli.py](tests/test_cli.py)
|
|
479
|
+
|
|
480
|
+
Die Tests decken ab:
|
|
481
|
+
|
|
482
|
+
- Verschlüsselung und Entschlüsselung mit `str`- und `bytes`-Passwörtern
|
|
483
|
+
- Erzeugen zufälliger Eintrags-Schlüssel
|
|
484
|
+
- Speichern, Laden, Löschen und Auflisten von Einträgen
|
|
485
|
+
- CLI-Verhalten über den `main()`-Einstiegspunkt
|
|
486
|
+
|
|
487
|
+
Zusätzlich sind folgende Szenarien abgedeckt:
|
|
488
|
+
|
|
489
|
+
- Erzeugen und erneutes Laden einer leeren Keyring-Datei
|
|
490
|
+
- Fehlverhalten bei falschem Master-Passwort
|
|
491
|
+
- `get()` und `delete()` bei nicht vorhandenen Einträgen
|
|
492
|
+
- Überschreiben und Nicht-Überschreiben bestehender Einträge
|
|
493
|
+
- CLI-Fehlerfälle für `show`, `add` ohne `--overwrite` und `delete`
|
|
494
|
+
- CLI-Hilfe über `--help`
|
|
495
|
+
|
|
496
|
+
### Tests ausführen
|
|
497
|
+
|
|
498
|
+
```bash
|
|
499
|
+
python3 -m pytest -q
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
Falls dein System-Python extern verwaltet ist, empfiehlt sich ein virtuelles Umfeld:
|
|
503
|
+
|
|
504
|
+
```bash
|
|
505
|
+
python3 -m venv .venv
|
|
506
|
+
source .venv/bin/activate
|
|
507
|
+
pip install -e '.[dev]'
|
|
508
|
+
python3 -m pytest -q
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
## Packaging und Veröffentlichung
|
|
512
|
+
|
|
513
|
+
Die Paketdefinition liegt vollständig in [pyproject.toml](pyproject.toml).
|
|
514
|
+
|
|
515
|
+
Wichtige Punkte daraus:
|
|
516
|
+
|
|
517
|
+
- Build-Backend: `setuptools`
|
|
518
|
+
- Distribution-Name: `encrypted-keyring`
|
|
519
|
+
- Konsolenbefehl: `encrypted-keyring`
|
|
520
|
+
- Python-Version: `>=3.10`
|
|
521
|
+
- Laufzeitabhängigkeit: `cryptography`
|
|
522
|
+
- Entwicklungsabhängigkeiten: `build`, `pytest`, `twine`
|
|
523
|
+
|
|
524
|
+
### Lokales Builden
|
|
525
|
+
|
|
526
|
+
```bash
|
|
527
|
+
python3 -m build
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
Das erzeugt typischerweise:
|
|
531
|
+
|
|
532
|
+
- ein Source Distribution Archiv
|
|
533
|
+
- ein Wheel
|
|
534
|
+
|
|
535
|
+
### Veröffentlichungsprüfung
|
|
536
|
+
|
|
537
|
+
Vor einem Upload ist ein Trockenlauf sinnvoll:
|
|
538
|
+
|
|
539
|
+
```bash
|
|
540
|
+
python3 -m twine check dist/*
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
### Upload auf PyPI
|
|
544
|
+
|
|
545
|
+
Wenn du veröffentlichen willst:
|
|
546
|
+
|
|
547
|
+
```bash
|
|
548
|
+
python3 -m twine upload dist/*
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
## Datenformat und Verhalten
|
|
552
|
+
|
|
553
|
+
- Die Keyring-Datei wird verschlüsselt gespeichert.
|
|
554
|
+
- Beim Schreiben wird eine temporäre Datei verwendet und anschließend atomar ersetzt.
|
|
555
|
+
- Nach dem Schreiben wird die Datei mit Berechtigung `600` versehen, damit nur der Besitzer lesen und schreiben kann.
|
|
556
|
+
- Die interne Struktur trennt die eigentlichen Eintragsdaten von den verschlüsselten Eintrags-Schlüsseln.
|
|
557
|
+
- Die Kryptoschicht akzeptiert Passwortwerte als `str` oder als `bytes`.
|
|
558
|
+
- Zufällige Eintrags-Schlüssel werden intern als Bytes erzeugt und verschlüsselt abgelegt.
|
|
559
|
+
- Die Datei `keyring.dat` ist eine Laufzeitdatei und gehört nicht ins Git-Repository.
|
|
560
|
+
|
|
561
|
+
## Projektstruktur
|
|
562
|
+
|
|
563
|
+
- `keyring/__init__.py` - Paket-Exports für `Keyring` und `Crypto`
|
|
564
|
+
- `keyring/__main__.py` - CLI-Einstiegspunkt
|
|
565
|
+
- `keyring/crypto.py` - Schlüsselableitung, Verschlüsselung und Entschlüsselung
|
|
566
|
+
- `keyring/keyring.py` - Laden, Speichern und Verwalten der Keyring-Daten
|
|
567
|
+
- `pyproject.toml` - Build-, Packaging- und Test-Konfiguration
|
|
568
|
+
- `requirements.txt` - manuelle Liste der Laufzeitabhängigkeiten
|
|
569
|
+
- `shell-alias.sh` - Shell-Alias für den CLI-Befehl
|
|
570
|
+
- `tests/` - automatisierte Tests
|
|
571
|
+
|
|
572
|
+
## Veröffentlichung und Nutzung
|
|
573
|
+
|
|
574
|
+
Ein typischer Ablauf für die Weiterentwicklung ist:
|
|
575
|
+
|
|
576
|
+
1. Code ändern
|
|
577
|
+
2. Tests ergänzen oder anpassen
|
|
578
|
+
3. `python3 -m pytest -q` ausführen
|
|
579
|
+
4. `python3 -m build` ausführen
|
|
580
|
+
5. `python3 -m twine check dist/*` prüfen
|
|
581
|
+
6. Paket auf PyPI hochladen
|
|
582
|
+
|
|
583
|
+
## Hinweise
|
|
584
|
+
|
|
585
|
+
- Der Python-Import bleibt `keyring`, auch wenn die Distribution `encrypted-keyring` heißt.
|
|
586
|
+
- Die CLI ist separat installierbar und kann über den Shell-Alias bequem auf `keyring` gelegt werden.
|
|
587
|
+
- Wenn du neue Funktionen ergänzt, sollten dazu passende Tests und eine kurze Dokumentation dazukommen.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
encrypted_keyring-0.1.0.dist-info/licenses/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
|
|
2
|
+
keyring/__init__.py,sha256=0Fd1mEg1Yz9ZAhIQvsmNSg_BrOhh4y38XVEOssNYv7o,128
|
|
3
|
+
keyring/__main__.py,sha256=MzUm-roViseCqD6wlqhcojkkguVf8uMfDYPzvZYuljs,4283
|
|
4
|
+
keyring/crypto.py,sha256=BO4iLbkeK4xWPUmcQspUnKIxK_vuOVnGEtx2DDLVu0A,1099
|
|
5
|
+
keyring/keyring.py,sha256=QgBpbYh_iPASdF8XQxW-ki3WV9t4IYK9z9mq5zlwwXk,4021
|
|
6
|
+
encrypted_keyring-0.1.0.dist-info/METADATA,sha256=zHZoUGsPVa4xOlrFYRdpLu4ixKaaUfeaQoPxjG0tJJQ,24368
|
|
7
|
+
encrypted_keyring-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
8
|
+
encrypted_keyring-0.1.0.dist-info/entry_points.txt,sha256=4BW9tURqO41GSWn4SdMYP8VTW0NwDdOI3SkHujTIXkQ,60
|
|
9
|
+
encrypted_keyring-0.1.0.dist-info/top_level.txt,sha256=ohh1dke28_NdSNkZ6nkVSwIKkLJTOwIfEwnXKva3pkg,8
|
|
10
|
+
encrypted_keyring-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
keyring
|
keyring/__init__.py
ADDED
keyring/__main__.py
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
from getpass import getpass
|
|
5
|
+
import sys
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from .keyring import Keyring
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
DEFAULT_KEYRING_FILE = Path("keyring.dat")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
15
|
+
parser = argparse.ArgumentParser(
|
|
16
|
+
prog="keyring",
|
|
17
|
+
description="Kleine CLI für den verschlüsselten Keyring.",
|
|
18
|
+
)
|
|
19
|
+
parser.add_argument(
|
|
20
|
+
"-f",
|
|
21
|
+
"--file",
|
|
22
|
+
type=Path,
|
|
23
|
+
default=DEFAULT_KEYRING_FILE,
|
|
24
|
+
help=f"Pfad zur Keyring-Datei (Standard: {DEFAULT_KEYRING_FILE})",
|
|
25
|
+
)
|
|
26
|
+
parser.add_argument(
|
|
27
|
+
"-p",
|
|
28
|
+
"--password",
|
|
29
|
+
help="Master-Passwort für die Keyring-Datei. Wenn es fehlt, wird es abgefragt.",
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
subparsers = parser.add_subparsers(dest="command", required=True)
|
|
33
|
+
|
|
34
|
+
subparsers.add_parser("list", help="Alle Einträge auflisten")
|
|
35
|
+
|
|
36
|
+
show_parser = subparsers.add_parser("show", help="Einen Eintrag anzeigen")
|
|
37
|
+
show_parser.add_argument("name")
|
|
38
|
+
|
|
39
|
+
add_parser = subparsers.add_parser("add", help="Einen Eintrag anlegen oder ersetzen")
|
|
40
|
+
add_parser.add_argument("name")
|
|
41
|
+
add_parser.add_argument("--user")
|
|
42
|
+
add_parser.add_argument("--entry-password", dest="entry_password")
|
|
43
|
+
add_parser.add_argument("--description")
|
|
44
|
+
add_parser.add_argument("--overwrite", action="store_true", help="Vorhandenen Eintrag überschreiben")
|
|
45
|
+
|
|
46
|
+
delete_parser = subparsers.add_parser("delete", help="Einen Eintrag löschen")
|
|
47
|
+
delete_parser.add_argument("name")
|
|
48
|
+
|
|
49
|
+
return parser
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def resolve_master_password(provided: str | None) -> str:
|
|
53
|
+
if provided is not None:
|
|
54
|
+
return provided
|
|
55
|
+
return getpass("Master-Passwort: ")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def resolve_entry_password(provided: str | None) -> str:
|
|
59
|
+
if provided is not None:
|
|
60
|
+
return provided
|
|
61
|
+
return getpass("Eintrags-Passwort: ")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def open_keyring(path: Path, password: str) -> Keyring:
|
|
65
|
+
return Keyring(path=path, password=password)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def handle_list(keyring: Keyring) -> int:
|
|
69
|
+
names = keyring.names()
|
|
70
|
+
if not names:
|
|
71
|
+
print("Keine Einträge vorhanden.")
|
|
72
|
+
return 0
|
|
73
|
+
|
|
74
|
+
for name in names:
|
|
75
|
+
print(name)
|
|
76
|
+
return 0
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def handle_show(keyring: Keyring, name: str) -> int:
|
|
80
|
+
data = keyring.get(name)
|
|
81
|
+
if data is None:
|
|
82
|
+
print(f"Eintrag '{name}' wurde nicht gefunden.", file=sys.stderr)
|
|
83
|
+
return 1
|
|
84
|
+
|
|
85
|
+
print(f"Name: {name}")
|
|
86
|
+
print(f"Benutzer: {data.get('user', '')}")
|
|
87
|
+
print(f"Passwort: {data.get('password', '')}")
|
|
88
|
+
print(f"Beschreibung: {data.get('description', '')}")
|
|
89
|
+
return 0
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def handle_add(
|
|
93
|
+
keyring: Keyring,
|
|
94
|
+
name: str,
|
|
95
|
+
user: str | None,
|
|
96
|
+
entry_password: str | None,
|
|
97
|
+
description: str | None,
|
|
98
|
+
overwrite: bool,
|
|
99
|
+
) -> int:
|
|
100
|
+
if keyring.get(name) is not None and not overwrite:
|
|
101
|
+
print(f"Eintrag '{name}' existiert bereits. Nutze --overwrite.", file=sys.stderr)
|
|
102
|
+
return 1
|
|
103
|
+
|
|
104
|
+
keyring.put(
|
|
105
|
+
name,
|
|
106
|
+
user=user,
|
|
107
|
+
password=resolve_entry_password(entry_password),
|
|
108
|
+
description=description,
|
|
109
|
+
overwrite=overwrite,
|
|
110
|
+
)
|
|
111
|
+
print(f"Eintrag '{name}' gespeichert.")
|
|
112
|
+
return 0
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def handle_delete(keyring: Keyring, name: str) -> int:
|
|
116
|
+
if keyring.get(name) is None:
|
|
117
|
+
print(f"Eintrag '{name}' wurde nicht gefunden.", file=sys.stderr)
|
|
118
|
+
return 1
|
|
119
|
+
|
|
120
|
+
keyring.delete(name)
|
|
121
|
+
print(f"Eintrag '{name}' gelöscht.")
|
|
122
|
+
return 0
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def main(argv: list[str] | None = None) -> int:
|
|
126
|
+
parser = build_parser()
|
|
127
|
+
args = parser.parse_args(argv)
|
|
128
|
+
|
|
129
|
+
try:
|
|
130
|
+
keyring = open_keyring(args.file, resolve_master_password(args.password))
|
|
131
|
+
|
|
132
|
+
if args.command == "list":
|
|
133
|
+
return handle_list(keyring)
|
|
134
|
+
if args.command == "show":
|
|
135
|
+
return handle_show(keyring, args.name)
|
|
136
|
+
if args.command == "add":
|
|
137
|
+
return handle_add(
|
|
138
|
+
keyring,
|
|
139
|
+
args.name,
|
|
140
|
+
args.user,
|
|
141
|
+
args.entry_password,
|
|
142
|
+
args.description,
|
|
143
|
+
args.overwrite,
|
|
144
|
+
)
|
|
145
|
+
if args.command == "delete":
|
|
146
|
+
return handle_delete(keyring, args.name)
|
|
147
|
+
|
|
148
|
+
parser.error("Unbekannter Befehl.")
|
|
149
|
+
return 2
|
|
150
|
+
except Exception as exc:
|
|
151
|
+
print(str(exc), file=sys.stderr)
|
|
152
|
+
return 1
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
if __name__ == "__main__":
|
|
156
|
+
raise SystemExit(main())
|
keyring/crypto.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import os, base64
|
|
2
|
+
from cryptography.fernet import Fernet
|
|
3
|
+
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
|
|
4
|
+
from cryptography.hazmat.primitives import hashes
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Crypto:
|
|
8
|
+
|
|
9
|
+
def __init__(self) -> None:
|
|
10
|
+
pass
|
|
11
|
+
|
|
12
|
+
def _key(self, password: bytes | str, salt: bytes) -> bytes:
|
|
13
|
+
if isinstance(password, str):
|
|
14
|
+
password = password.encode('utf-8')
|
|
15
|
+
kdf = PBKDF2HMAC(
|
|
16
|
+
algorithm=hashes.SHA256(),
|
|
17
|
+
length=32,
|
|
18
|
+
salt=salt,
|
|
19
|
+
iterations=480_000,
|
|
20
|
+
)
|
|
21
|
+
return base64.urlsafe_b64encode(kdf.derive(password))
|
|
22
|
+
|
|
23
|
+
def encrypt(self, password: bytes | str, data: bytes) -> bytes:
|
|
24
|
+
salt = os.urandom(16)
|
|
25
|
+
token = Fernet(self._key(password, salt)).encrypt(data)
|
|
26
|
+
return salt + token
|
|
27
|
+
|
|
28
|
+
def decrypt(self, password: bytes | str, blob: bytes) -> bytes:
|
|
29
|
+
salt, token = blob[:16], blob[16:]
|
|
30
|
+
return Fernet(self._key(password, salt)).decrypt(token)
|
|
31
|
+
|
|
32
|
+
def create_password(self, size: int = 16) -> bytes:
|
|
33
|
+
return os.urandom(size)
|
keyring/keyring.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from .crypto import Crypto
|
|
3
|
+
import pickle
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
class Keyring:
|
|
7
|
+
|
|
8
|
+
crypto: Crypto = Crypto()
|
|
9
|
+
|
|
10
|
+
def __init__(self, path: Path, password: str) -> None:
|
|
11
|
+
self._data: dict = dict()
|
|
12
|
+
self._path: Path = path
|
|
13
|
+
self._password: str = password
|
|
14
|
+
if not self._path.exists():
|
|
15
|
+
self.create()
|
|
16
|
+
self.load()
|
|
17
|
+
|
|
18
|
+
def create(self) -> None:
|
|
19
|
+
self._data['_keys'] = {}
|
|
20
|
+
self.save()
|
|
21
|
+
|
|
22
|
+
def load(self) -> None:
|
|
23
|
+
try:
|
|
24
|
+
with open(file=self._path.as_posix(), mode='rb') as input_file:
|
|
25
|
+
data_blob: bytes = input_file.read()
|
|
26
|
+
data: bytes = self.crypto.decrypt(password=self._password, blob=data_blob)
|
|
27
|
+
self._data: dict = pickle.loads(data)
|
|
28
|
+
except Exception as e:
|
|
29
|
+
raise Exception('KeyRing Datei konnte nicht geladen werden') from e
|
|
30
|
+
|
|
31
|
+
def save(self) -> None:
|
|
32
|
+
data: bytes = pickle.dumps(self._data)
|
|
33
|
+
data_blob: bytes = self.crypto.encrypt(password=self._password, data=data)
|
|
34
|
+
tmp_file: Path = Path(f'{self._path.as_posix()}.tmp')
|
|
35
|
+
try:
|
|
36
|
+
with open(file=tmp_file.as_posix(), mode='wb') as output_file:
|
|
37
|
+
output_file.write(data_blob)
|
|
38
|
+
output_file.flush()
|
|
39
|
+
os.fsync(output_file.fileno())
|
|
40
|
+
os.replace(tmp_file.as_posix(), self._path.as_posix())
|
|
41
|
+
os.chmod(self._path.as_posix(), 0o600)
|
|
42
|
+
except Exception as e:
|
|
43
|
+
tmp_file.unlink(missing_ok=True)
|
|
44
|
+
raise Exception('Keyringfile konnte nicht geschrieben werden') from e
|
|
45
|
+
|
|
46
|
+
def get(self, name: str) -> dict | None:
|
|
47
|
+
if name not in ['_keys',]:
|
|
48
|
+
if name in self._data:
|
|
49
|
+
ring_password: bytes = self.crypto.decrypt(password=self._password, blob=self._data['_keys'][name])
|
|
50
|
+
temp: dict = dict()
|
|
51
|
+
for k in self._data[name]:
|
|
52
|
+
temp[k] = self.crypto.decrypt(password=ring_password, blob=self._data[name][k]).decode(encoding='utf-8')
|
|
53
|
+
return temp
|
|
54
|
+
return None
|
|
55
|
+
|
|
56
|
+
def put(self, name: str, user: str | None = None, password: str | None = None, description: str | None = None, overwrite: bool = False) -> None:
|
|
57
|
+
if name not in ['_keys',]:
|
|
58
|
+
data: dict = dict()
|
|
59
|
+
if name in self._data and overwrite == True:
|
|
60
|
+
current: dict = self.get(name=name)
|
|
61
|
+
data: dict = {
|
|
62
|
+
'user': user if user is not None else current['user'],
|
|
63
|
+
'password': password if password is not None else current['password'],
|
|
64
|
+
'description': description if description is not None else current['description']
|
|
65
|
+
}
|
|
66
|
+
if name not in self._data:
|
|
67
|
+
data: dict = {
|
|
68
|
+
'user': user if user is not None else str(),
|
|
69
|
+
'password': password if password is not None else str(),
|
|
70
|
+
'description': description if description is not None else str()
|
|
71
|
+
}
|
|
72
|
+
if len(data) > 0:
|
|
73
|
+
ring_password: bytes = self.crypto.create_password()
|
|
74
|
+
for k in data:
|
|
75
|
+
data[k] = self.crypto.encrypt(password=ring_password, data=data[k].encode(encoding='utf-8'))
|
|
76
|
+
|
|
77
|
+
self._data[name] = data
|
|
78
|
+
self._data['_keys'][name] = self.crypto.encrypt(password=self._password, data=ring_password)
|
|
79
|
+
self.save()
|
|
80
|
+
|
|
81
|
+
def delete(self, name: str) -> None:
|
|
82
|
+
if name not in ['_keys',]:
|
|
83
|
+
if name in self._data:
|
|
84
|
+
self._data.pop(name)
|
|
85
|
+
self._data['_keys'].pop(name)
|
|
86
|
+
self.save()
|
|
87
|
+
|
|
88
|
+
def names(self) -> list[str]:
|
|
89
|
+
result: list = list()
|
|
90
|
+
for k in self._data:
|
|
91
|
+
if k not in ['_keys',]:
|
|
92
|
+
result.append(str(k))
|
|
93
|
+
return result
|