Hello! We are running our annual fundraising. Please consider making a donation if you value this freely available service or want to support people around the world working towards liberatory social change. https://riseup.net/donate.

Commit 05f1c48d authored by anarcat's avatar anarcat
Browse files

Merge branch 'feature/check-if-own-key' into '2.x'

Don't attempt to sign a user's own key

Instead, warn.

Fixes #30

See merge request !14
parents faa3126e 98aaf50e
......@@ -858,6 +858,25 @@ class OpenPGPkey():
if i == 4: s += ' '
return s
def __eq__(self, other):
"""
Two keys are equal if their fingerprint matches. If either don't
have a fingerprint, we can't say for sure that they're equal
"""
if isinstance(other, self.__class__):
return (self.fpr and
self.fpr and other.fpr
and self.fpr == other.fpr)
else:
return NotImplemented
def __neq__(self, other):
if isinstance(other, self.__class__):
return not self.__eq__(other)
else:
return NotImplemented
class OpenPGPuid():
def __init__(self, uid, trust, creation = 0, expire = None, uidhash = ''):
self.uid = uid
......
......@@ -288,6 +288,14 @@ this duplicates tests from the gpg code, but is necessary to test later function
self.ui.sign_key()
self.assertGreaterEqual(len(self.ui.signed_keys), 1)
def test_sign_own_key(self):
"""Test that signing a user's own key fails"""
self.ui.pattern = '96F47C6A'
self.test_copy_secrets()
self.ui.sign_key()
self.assertEquals(len(self.ui.signed_keys), 0)
self.ui.pattern = '7B75921E'
def test_gpg_conf(self):
"""test if gpg.conf default-key works"""
# this fails with GnuPG 2.1
......
......@@ -559,7 +559,15 @@ ordering.
assert(keys is not None) # nosec
self.log(_('found %d keys matching your request') % len(keys))
secret_keys = self.keyring.get_keys(self.options.user, True, False)
for key in keys:
# Make sure the user isn't signing their own key
for secret_key in secret_keys.values():
if keys[key] == secret_key:
self.warn(_('That is your own key, so it is already certified'))
return False
alluids = self.yes_no(_("""\
Signing the following key
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment