-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v0.4.0 update - new sign(key=True) kwarg & code cleanups
- Loading branch information
Showing
9 changed files
with
132 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
tiny_gnupg.egg-info | ||
.pytest_cache | ||
__pycache__ | ||
openpgp-revocs.d | ||
private-keys-v1.d | ||
pubring.kbx | ||
openpgp-revocs.d | ||
pubring.kbx~ | ||
pubring.kbx | ||
random_seed | ||
trustdb.gpg | ||
sshcontrol | ||
tofu.db | ||
venv | ||
env | ||
build | ||
dist | ||
venv | ||
env | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
This file is part of tiny_gnupg, a small-as-possible solution for | ||
handling GnuPG ECC keys. | ||
|
||
Licensed under the GPLv3: http://www.gnu.org/licenses/gpl-3.0.html | ||
Copyright © 2019-2020 Gonzo Investigatory Journalism Agency, LLC | ||
<[email protected]> | ||
© 2019-2020 Richard Machado <[email protected]> | ||
All rights reserved. | ||
|
||
|
||
GNU GENERAL PUBLIC LICENSE | ||
Version 3, 29 June 2007 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,10 @@ Networking Example | |
# Check your ip address for fun -> | ||
ip_addr = run(read_url("https://icanhazip.com/")) | ||
# There's a convenience function built into the class that | ||
# basically mimics read_url() -> | ||
ip_addr = run(gpg.get("https://icanhazip.com/")) | ||
# POST requests can also be sent with the network_post() method. | ||
# Let's use a POST request to send the keyserver a new key we | ||
|
@@ -135,6 +139,11 @@ Networking Example | |
url = gpg.keyserver_export_api | ||
payload = {"keytext": gpg.text_export(gpg.fingerprint)} | ||
api_token_json = run(post(gpg, url, payload)) | ||
# There's also a convenience function built into the class that | ||
# mimics post() -> | ||
api_token_json = run(gpg.post(url, json=payload)) | ||
# And there we have it, it's super simple. And these requests have | ||
# the added benefit of being completely routed through tor. The | ||
# keyserver here also has a v3 onion address which we use to query, | ||
|
@@ -166,6 +175,9 @@ Extras | |
# encrypting -> | ||
signed_data = gpg.sign("maybe a hash of a file?") | ||
# Or sign a key in the package's keyring -> | ||
gpg.sign("[email protected]", key=True) | ||
# And verify data as well -> | ||
gpg.verify(signed_data) # throws if invalid | ||
|
@@ -177,14 +189,14 @@ Extras | |
path_to_file = "/home/user/keyfiles/" | ||
run(gpg.file_import(path=path_to_file + "alices_key.asc")) | ||
# And exporting -> | ||
# As well as exporting public keys -> | ||
run(gpg.file_export(path=path_to_file, uid=gpg.email)) | ||
# And secret keys, but really, keep those safe! -> | ||
run(gpg.file_export(path=path_to_file, uid=gpg.email, secret=True)) | ||
# When a user is done with a key, it can be deleted from the package | ||
# keyring like this -> | ||
gpg.delete("[email protected]") # You'll have to manually click | ||
# the confirm button, though. | ||
gpg.delete("[email protected]") | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,8 @@ | |
from pathlib import Path | ||
from aiohttp import ClientSession | ||
from aiohttp_socks import SocksConnector | ||
from multiprocessing import Process | ||
|
||
PACKAGE_PATH = str(Path(__file__).parent.parent) | ||
PACKAGE_PATH = str(Path(__file__).absolute().parent.parent) | ||
sys.path.append(PACKAGE_PATH) | ||
run = asyncio.get_event_loop().run_until_complete | ||
new_task = asyncio.get_event_loop().create_task | ||
|
@@ -31,7 +30,7 @@ def gpg(): | |
username = "testing_user" | ||
email = "[email protected]" | ||
passphrase = "test_passphrase" | ||
relative_gpg_path = PACKAGE_PATH + "/tiny_gnupg/gpghome" | ||
relative_gpg_path = str(Path(PACKAGE_PATH).absolute() / "tiny_gnupg/gpghome") | ||
gpg = GnuPG(username, email, passphrase) | ||
gpg.set_homedir(relative_gpg_path) | ||
gpg.reset_daemon() | ||
|
@@ -123,8 +122,8 @@ def test_cipher(gpg): | |
|
||
|
||
def test_file_io(gpg): | ||
path = gpg.home | ||
file_path = f"{path}/{gpg.fingerprint}.asc" | ||
path = Path(gpg.home).absolute() | ||
file_path = str(path / f"{gpg.fingerprint}.asc") | ||
key = gpg.text_export(gpg.fingerprint) | ||
run(gpg.file_export(path, gpg.fingerprint)) | ||
run(gpg.file_import(file_path)) | ||
|
@@ -208,7 +207,21 @@ async def looper(gpg, uid): | |
assert url == link | ||
|
||
|
||
def test_key_signing(gpg): | ||
dev_email = "[email protected]" | ||
dev_fingerprint = "31FDCC4F9961AFAC522A9D41AE2B47FA1EF44F0A" | ||
command = gpg.command("--check-sigs") | ||
keyring = gpg.read_output(command) | ||
gpg.sign(dev_fingerprint, key=True) | ||
signed_keying = gpg.read_output(command) | ||
assert keyring != signed_keying | ||
condensed_keyring = signed_keying.replace(" ", "") | ||
fingerprint = gpg.fingerprint[-16:] | ||
assert f"<{dev_email}>\nsig!{fingerprint}" in condensed_keyring | ||
|
||
|
||
def test_delete(gpg): | ||
dev_email = "[email protected]" | ||
email = "[email protected]" | ||
amount_of_test_keys = 0 | ||
for key_email in gpg.list_keys().values(): | ||
|
@@ -220,3 +233,4 @@ def test_delete(gpg): | |
if key_email == email: | ||
amount_of_test_keys_after_delete += 1 | ||
assert amount_of_test_keys - 1 == amount_of_test_keys_after_delete | ||
gpg.delete(dev_email) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,6 @@ | |
# All rights reserved. | ||
# | ||
|
||
__version__ = "0.3.9" | ||
__version__ = "0.4.0" | ||
|
||
from .tiny_gnupg import GnuPG, __all__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters