From 8415c7d3f2aac53a78aac5980db69caf10c3ff19 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 5 May 2021 10:53:00 +0100 Subject: [PATCH] Show pgp public key --- README_commandline.md | 1 + desktop_client.py | 9 +++++++++ pgp.py | 4 ++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README_commandline.md b/README_commandline.md index a01428ca0..f4a175c05 100644 --- a/README_commandline.md +++ b/README_commandline.md @@ -478,6 +478,7 @@ following [page number] Show accounts that you are following followers [page number] Show accounts that are following you approve [handle] Approve a follow request deny [handle] Deny a follow request +pgp Show your PGP public key ``` If you have a GPG key configured on your local system and are sending a direct message to someone who has a PGP key (the exported key, not just the key ID) set as a tag on their profile then it will try to encrypt the message automatically. So under some conditions end-to-end encryption is possible, such that the instance server only sees ciphertext. Conversely, for arriving direct messages if they are PGP encrypted then the desktop client will try to obtain the relevant public key and decrypt. diff --git a/desktop_client.py b/desktop_client.py index 4d3f94ae4..ebc3730f2 100644 --- a/desktop_client.py +++ b/desktop_client.py @@ -45,6 +45,7 @@ from posts import c2sBoxJson from posts import downloadAnnounce from announce import sendAnnounceViaServer from announce import sendUndoAnnounceViaServer +from pgp import pgpLocalPublicKey from pgp import pgpDecrypt from pgp import hasLocalPGPkey from pgp import pgpEncryptToActor @@ -124,6 +125,8 @@ def _desktopHelp() -> None: 'Approve a follow request') print(indent + 'deny [handle] ' + 'Deny a follow request') + print(indent + 'pgp ' + + 'Show your PGP public key') print('') @@ -2324,6 +2327,12 @@ def runDesktopClient(baseDir: str, proxyType: str, httpPrefix: str, _sayCommand(sayStr, sayStr, originalScreenReader, systemLanguage, espeak) print('') + elif commandStr.startswith('pgp') or commandStr.startswith('gpg'): + if not hasLocalPGPkey(): + print('No PGP public key was found') + else: + print(pgpLocalPublicKey()) + print('') elif commandStr.startswith('h'): _desktopHelp() sayStr = 'Press Enter to continue...' diff --git a/pgp.py b/pgp.py index 19a1d0f42..37444c126 100644 --- a/pgp.py +++ b/pgp.py @@ -423,7 +423,7 @@ def _pgpLocalPublicKeyId() -> str: return result.decode('utf-8').replace('"', '').strip() -def _pgpLocalPublicKey() -> str: +def pgpLocalPublicKey() -> str: """Gets the local pgp public key """ keyId = _pgpLocalPublicKeyId() @@ -457,7 +457,7 @@ def pgpPublicKeyUpload(baseDir: str, session, if not test: if debug: print('Getting PGP public key') - PGPpubKey = _pgpLocalPublicKey() + PGPpubKey = pgpLocalPublicKey() if not PGPpubKey: return None PGPpubKeyId = _pgpLocalPublicKeyId()