[openpgp] Generate keys without protection
This commit is contained in:
@@ -33,14 +33,13 @@ KeyringItem = namedtuple('KeyringItem', 'jid keyid fingerprint')
|
|||||||
|
|
||||||
class PythonGnuPG(gnupg.GPG):
|
class PythonGnuPG(gnupg.GPG):
|
||||||
def __init__(self, jid, gnupghome):
|
def __init__(self, jid, gnupghome):
|
||||||
gnupg.GPG.__init__(
|
gnupg.GPG.__init__(self, gpgbinary='gpg', gnupghome=str(gnupghome))
|
||||||
self, gpgbinary='gpg', gnupghome=str(gnupghome))
|
|
||||||
|
|
||||||
self._passphrase = 'gajimopenpgppassphrase'
|
|
||||||
self._jid = jid.getBare()
|
self._jid = jid.getBare()
|
||||||
self._own_fingerprint = None
|
self._own_fingerprint = None
|
||||||
|
|
||||||
def _get_key_params(self, jid, passphrase):
|
@staticmethod
|
||||||
|
def _get_key_params(jid):
|
||||||
'''
|
'''
|
||||||
Generate --gen-key input
|
Generate --gen-key input
|
||||||
'''
|
'''
|
||||||
@@ -49,17 +48,17 @@ class PythonGnuPG(gnupg.GPG):
|
|||||||
'Key-Type': 'RSA',
|
'Key-Type': 'RSA',
|
||||||
'Key-Length': 2048,
|
'Key-Length': 2048,
|
||||||
'Name-Real': 'xmpp:%s' % jid,
|
'Name-Real': 'xmpp:%s' % jid,
|
||||||
'Passphrase': passphrase,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out = "Key-Type: %s\n" % params.pop('Key-Type')
|
out = 'Key-Type: %s\n' % params.pop('Key-Type')
|
||||||
for key, val in list(params.items()):
|
for key, val in list(params.items()):
|
||||||
out += "%s: %s\n" % (key, val)
|
out += '%s: %s\n' % (key, val)
|
||||||
out += "%commit\n"
|
out += '%no-protection\n'
|
||||||
|
out += '%commit\n'
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def generate_key(self):
|
def generate_key(self):
|
||||||
super().gen_key(self._get_key_params(self._jid, self._passphrase))
|
super().gen_key(self._get_key_params(self._jid))
|
||||||
|
|
||||||
def encrypt(self, payload, keys):
|
def encrypt(self, payload, keys):
|
||||||
recipients = [key.fingerprint for key in keys]
|
recipients = [key.fingerprint for key in keys]
|
||||||
@@ -71,8 +70,7 @@ class PythonGnuPG(gnupg.GPG):
|
|||||||
recipients,
|
recipients,
|
||||||
armor=False,
|
armor=False,
|
||||||
sign=self._own_fingerprint,
|
sign=self._own_fingerprint,
|
||||||
always_trust=True,
|
always_trust=True)
|
||||||
passphrase=self._passphrase)
|
|
||||||
|
|
||||||
if result.ok:
|
if result.ok:
|
||||||
error = ''
|
error = ''
|
||||||
@@ -82,9 +80,7 @@ class PythonGnuPG(gnupg.GPG):
|
|||||||
return result.data, error
|
return result.data, error
|
||||||
|
|
||||||
def decrypt(self, payload):
|
def decrypt(self, payload):
|
||||||
result = super().decrypt(payload,
|
result = super().decrypt(payload, always_trust=True)
|
||||||
always_trust=True,
|
|
||||||
passphrase=self._passphrase)
|
|
||||||
if not result.ok:
|
if not result.ok:
|
||||||
raise DecryptionFailed(result.status)
|
raise DecryptionFailed(result.status)
|
||||||
|
|
||||||
@@ -134,6 +130,7 @@ class PythonGnuPG(gnupg.GPG):
|
|||||||
|
|
||||||
result = self.scan_keys(temppath)
|
result = self.scan_keys(temppath)
|
||||||
if result:
|
if result:
|
||||||
|
key_found = False
|
||||||
for uid in result.uids:
|
for uid in result.uids:
|
||||||
if uid.startswith('xmpp:'):
|
if uid.startswith('xmpp:'):
|
||||||
if uid[5:] == jid:
|
if uid[5:] == jid:
|
||||||
@@ -174,10 +171,9 @@ class PythonGnuPG(gnupg.GPG):
|
|||||||
|
|
||||||
def export_key(self, fingerprint):
|
def export_key(self, fingerprint):
|
||||||
key = super().export_keys(
|
key = super().export_keys(
|
||||||
fingerprint, secret=False, armor=False, minimal=False,
|
fingerprint, secret=False, armor=False, minimal=True)
|
||||||
passphrase=self._passphrase)
|
|
||||||
return key
|
return key
|
||||||
|
|
||||||
def delete_key(self, fingerprint):
|
def delete_key(self, fingerprint):
|
||||||
log.info('Delete Key: %s', fingerprint)
|
log.info('Delete Key: %s', fingerprint)
|
||||||
super().delete_keys(fingerprint, passphrase=self._passphrase)
|
super().delete_keys(fingerprint)
|
||||||
|
|||||||
Reference in New Issue
Block a user