mirror of https://gitlab.com/bashrc2/epicyon
Obtain pgp public key from sending actor if possible
parent
9107f7da38
commit
e330a75696
|
@ -486,11 +486,17 @@ def runNotificationsClient(baseDir: str, proxyType: str, httpPrefix: str,
|
||||||
else:
|
else:
|
||||||
messageStr = speakerJson['say'] + '. ' + \
|
messageStr = speakerJson['say'] + '. ' + \
|
||||||
speakerJson['imageDescription']
|
speakerJson['imageDescription']
|
||||||
messageStr = pgpDecrypt(messageStr)
|
if speakerJson.get('id'):
|
||||||
|
messageStr = pgpDecrypt(messageStr,
|
||||||
|
speakerJson['id'])
|
||||||
|
|
||||||
content = messageStr
|
content = messageStr
|
||||||
if speakerJson.get('content'):
|
if speakerJson.get('content'):
|
||||||
content = pgpDecrypt(speakerJson['content'])
|
if speakerJson.get('id'):
|
||||||
|
content = pgpDecrypt(speakerJson['content'],
|
||||||
|
speakerJson['id'])
|
||||||
|
else:
|
||||||
|
content = speakerJson['content']
|
||||||
|
|
||||||
# say the speaker's name
|
# say the speaker's name
|
||||||
_sayCommand(nameStr, nameStr, screenreader,
|
_sayCommand(nameStr, nameStr, screenreader,
|
||||||
|
|
29
pgp.py
29
pgp.py
|
@ -7,6 +7,7 @@ __email__ = "bob@freedombone.net"
|
||||||
__status__ = "Production"
|
__status__ = "Production"
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from person import getActorJson
|
||||||
|
|
||||||
|
|
||||||
def getEmailAddress(actorJson: {}) -> str:
|
def getEmailAddress(actorJson: {}) -> str:
|
||||||
|
@ -320,8 +321,28 @@ def pgpEncrypt(content: str, recipientPubKey: str) -> str:
|
||||||
return encryptResult
|
return encryptResult
|
||||||
|
|
||||||
|
|
||||||
def pgpDecrypt(content: str) -> str:
|
def _getPGPPublicKeyFromActor(handle: str) -> str:
|
||||||
|
"""Searches tags on the actor to see if there is any PGP
|
||||||
|
public key specified
|
||||||
|
"""
|
||||||
|
actorJson = getActorJson(handle, False, False, True)
|
||||||
|
if not actorJson:
|
||||||
|
return None
|
||||||
|
if not actorJson.get('attachment'):
|
||||||
|
return None
|
||||||
|
if not isinstance(actorJson['attachment'], list):
|
||||||
|
return None
|
||||||
|
for tag in actorJson['attachment']:
|
||||||
|
if not tag.get('value'):
|
||||||
|
continue
|
||||||
|
if '--BEGIN PGP PUBLIC KEY BLOCK--' in tag['value']:
|
||||||
|
return tag['value']
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def pgpDecrypt(content: str, fromHandle: str) -> str:
|
||||||
""" Encrypt using your default pgp key to the given recipient
|
""" Encrypt using your default pgp key to the given recipient
|
||||||
|
fromHandle can be a handle or actor url
|
||||||
"""
|
"""
|
||||||
if '--BEGIN PGP MESSAGE--' not in content:
|
if '--BEGIN PGP MESSAGE--' not in content:
|
||||||
return content
|
return content
|
||||||
|
@ -330,8 +351,10 @@ def pgpDecrypt(content: str) -> str:
|
||||||
startBlock = '--BEGIN PGP PUBLIC KEY BLOCK--'
|
startBlock = '--BEGIN PGP PUBLIC KEY BLOCK--'
|
||||||
if startBlock in content:
|
if startBlock in content:
|
||||||
pubKey = extractPGPPublicKey(content)
|
pubKey = extractPGPPublicKey(content)
|
||||||
if pubKey:
|
else:
|
||||||
_pgpImportPubKey(pubKey)
|
pubKey = _getPGPPublicKeyFromActor(content, fromHandle)
|
||||||
|
if pubKey:
|
||||||
|
_pgpImportPubKey(pubKey)
|
||||||
|
|
||||||
cmdDecrypt = \
|
cmdDecrypt = \
|
||||||
'echo "' + content + '" | gpg --decrypt --armor 2> /dev/null'
|
'echo "' + content + '" | gpg --decrypt --armor 2> /dev/null'
|
||||||
|
|
Loading…
Reference in New Issue