Beispiel #1
0
    def test_get_random_address(self):
        pgp = openpgp.OpenPGPScheme(self._soledad,
                                    gpgbinary=self.gpg_binary_path)
        rf = RandomRefreshPublicKey(pgp, self._key_manager())
        key = OpenPGPKey(address='*****@*****.**')
        key_another = OpenPGPKey(address='*****@*****.**')

        pgp.get_all_keys = Mock(return_value=defer.succeed([key, key_another]))

        random_key = yield rf._get_random_key()
        self.assertTrue(random_key.address == key.address
                        or random_key.address == key_another.address)
Beispiel #2
0
    def test_key_expired_will_be_deactivatet(self):
        pgp = openpgp.OpenPGPScheme(self._soledad,
                                    gpgbinary=self.gpg_binary_path)
        km = self._key_manager()
        rf = RandomRefreshPublicKey(pgp, km)
        key = OpenPGPKey(address='*****@*****.**', expiry_date=datetime.now())
        self.assertTrue(key.address is '*****@*****.**')
        pgp.unactivate_key = Mock(return_value=defer.succeed(None))

        yield rf._maybe_unactivate_key(key)

        self.assertTrue(key.address is None)
        self.assertFalse(key.is_active())
    def test_put_new_key_in_local_storage(self):
        pgp = openpgp.OpenPGPScheme(self._soledad,
                                    gpgbinary=self.gpg_binary_path)
        km = self._key_manager()

        rf = RandomRefreshPublicKey(pgp, km)
        rf._get_random_key = Mock(
            return_value=defer.succeed(OpenPGPKey(
                fingerprint=KEY_FINGERPRINT)))

        km._nicknym.fetch_key_with_fingerprint = Mock(
            return_value=defer.succeed(OpenPGPKey(fingerprint=ANOTHER_FP)))

        yield rf.maybe_refresh_key()
    def test_fingerprint_missing(self):
        key = OpenPGPKey(MAIL_ADDRESS)
        key.fingerprint = FINGERPRINT
        request = DummyRequest(['/user-settings'])
        when(self.keymanager).get_key(MAIL_ADDRESS).thenReturn(defer.fail(Failure))

        d = self.web.get(request)

        def assert_response(_):
            response = json.loads(request.written[0])
            self.assertEqual(FINGERPRINT_NOT_FOUND, response['fingerprint'])
            self.assertEqual(MAIL_ADDRESS, response['account_email'])

        d.addCallback(assert_response)
        return d
 def _repair_missing_active_docs(self, docs, private_key_fingerprints):
     missing = self._missing_active_docs(docs, private_key_fingerprints)
     for fingerprint in missing:
         emails = self._emails_for_key_fingerprint(docs, fingerprint)
         for email in emails:
             logger.warn('Re-creating active doc for key %s, email %s' % (fingerprint, email))
             yield self._soledad.create_doc_from_json(OpenPGPKey(email, fingerprint=fingerprint, private=False).get_active_json())
    def test_log_error_if_fetch_by_fingerprint_returns_wrong_key(self):
        pgp = openpgp.OpenPGPScheme(self._soledad,
                                    gpgbinary=self.gpg_binary_path)
        km = self._key_manager()

        with patch.object(Logger, 'error') as mock_logger_error:
            rf = RandomRefreshPublicKey(pgp, km)
            rf._get_random_key = \
                Mock(return_value=defer.succeed(OpenPGPKey(
                    fingerprint=KEY_FINGERPRINT)))

            km._nicknym.fetch_key_with_fingerprint = \
                Mock(return_value=defer.succeed(OpenPGPKey(
                    fingerprint=ANOTHER_FP)))

            yield rf.maybe_refresh_key()

            mock_logger_error.assert_called_with(ERROR_UNEQUAL_FINGERPRINTS %
                                                 (KEY_FINGERPRINT, ANOTHER_FP))
Beispiel #7
0
    def test_self_repair_six_active_docs(self):
        pgp = openpgp.OpenPGPScheme(
            self._soledad, gpgbinary=self.gpg_binary_path)

        k1 = OpenPGPKey(ADDRESS, fingerprint="1",
                        refreshed_at=datetime(2005, 1, 1))
        k2 = OpenPGPKey(ADDRESS, fingerprint="2",
                        refreshed_at=datetime(2007, 1, 1))
        k3 = OpenPGPKey(ADDRESS, fingerprint="3",
                        refreshed_at=datetime(2007, 1, 1),
                        encr_used=True, sign_used=True)
        k4 = OpenPGPKey(ADDRESS, fingerprint="4",
                        refreshed_at=datetime(2007, 1, 1),
                        sign_used=True)
        k5 = OpenPGPKey(ADDRESS, fingerprint="5",
                        refreshed_at=datetime(2007, 1, 1),
                        encr_used=True)
        k6 = OpenPGPKey(ADDRESS, fingerprint="6",
                        refreshed_at=datetime(2006, 1, 1),
                        encr_used=True, sign_used=True)
        keys = (k1, k2, k3, k4, k5, k6)
        for key in keys:
            yield self._soledad.create_doc_from_json(key.get_json())
            yield self._soledad.create_doc_from_json(key.get_active_json())

        delete_doc = self._mock_delete_doc()

        key = yield pgp.get_key(ADDRESS, private=False)
        self._soledad.delete_doc = delete_doc
        self.assertEqual(self.count, 5)
        self.assertEqual(key.fingerprint, "3")
def build_gpg_key(key_info, key_data, address=None, gpgbinary=None):
    expiry_date = None
    if key_info['expires']:
        expiry_date = datetime.fromtimestamp(int(key_info['expires']))
    uids = []
    for uid in key_info['uids']:
        uids.append(parse_address(uid))
    if address and address not in uids:
        raise errors.KeyAddressMismatch("UIDs %s found, but expected %s" %
                                        (str(uids), address))

    return OpenPGPKey(address=address,
                      uids=uids,
                      gpgbinary=gpgbinary,
                      fingerprint=key_info['fingerprint'],
                      key_data=key_data,
                      private=True if key_info['type'] == 'sec' else False,
                      length=int(key_info['length']),
                      expiry_date=expiry_date,
                      refreshed_at=datetime.now())
Beispiel #9
0
 def _insert_key_docs(self, refreshed_at):
     for date in refreshed_at:
         key = OpenPGPKey(ADDRESS, fingerprint=KEY_FINGERPRINT,
                          refreshed_at=date)
         yield self._soledad.create_doc_from_json(key.get_json())
     yield self._soledad.create_doc_from_json(key.get_active_json())