Esempio n. 1
0
def check_expiration_date(store):

    all_rcvs = store.find(Receiver)

    keylist = []
    keytrack = {}

    for sr in all_rcvs:
        if sr.gpg_key_status == Receiver._gpg_types[1]: # Enabled
            keylist.append(sr.gpg_key_armor)

            if keytrack.has_key(sr.gpg_key_fingerprint):
                log.err("[!?] Duplicated key fingerprint between %s and %s" %
                        (sr.user.username, keytrack[sr.gpg_key_fingerprint]))

            keytrack.update({sr.gpg_key_fingerprint : sr.user.username })

    if not keytrack:
        log.debug("PGP/GPG key expiration check: no keys configured in this node")
        return dict({}), dict({}), dict({})

    dates = get_expirations(keylist)

    today_dt = datetime.date.today()
    lowurgency = datetime.timedelta(weeks=2)
    highurgency = datetime.timedelta(days=3)

    # the return values
    expiring_keys_3d = {}
    expiring_keys_2w = {}
    expired_keys = {}

    for keyid, sincepoch in dates.iteritems():

        expiration_dt = datetime.datetime.utcfromtimestamp(int(sincepoch)).date()

        # simply, all the keys here are expired
        if expiration_dt < today_dt:
            continue

        key_timetolife = (expiration_dt - today_dt)

        if key_timetolife < highurgency:

            expiring_keys_3d.update({ keytrack[keyid]: sincepoch})
        elif key_timetolife < lowurgency:
            expiring_keys_2w.update({ keytrack[keyid]: sincepoch})
        else:
            expired_keys.update({ keytrack[keyid]: sincepoch })

    return expiring_keys_2w, expiring_keys_3d, expired_keys
Esempio n. 2
0
    def test_expiration_checks(self):

        keylist = [ HermesGlobaleaksKey.__doc__, VALID_PGP_KEY, ExpiredKey.__doc__ ]

        expiration_list = get_expirations(keylist)

        today_dt = datetime.date.today()

        for keyid, sincepoch in expiration_list.iteritems():

            expiration_dt = datetime.datetime.utcfromtimestamp(int(sincepoch)).date()

            # simply, all the keys here are expired
            self.assertTrue(expiration_dt < today_dt)
Esempio n. 3
0
    def test_expiration_checks(self):

        keylist = [
            HermesGlobaleaksKey.__doc__, VALID_PGP_KEY, ExpiredKey.__doc__
        ]

        expiration_list = get_expirations(keylist)

        today_dt = datetime.date.today()

        for keyid, sincepoch in expiration_list.iteritems():

            expiration_dt = datetime.datetime.utcfromtimestamp(
                int(sincepoch)).date()

            # simply, all the keys here are expired
            self.assertTrue(expiration_dt < today_dt)
Esempio n. 4
0
    def test_expiration_checks(self):

        keylist = [ HermesGlobaleaksKey.__doc__, DeveloperKey.__doc__, ExpiredKey.__doc__ ]

        expiration_list = get_expirations(keylist)

        today_dt = datetime.date.today()

        for keyid, sincepoch in expiration_list.iteritems():

            expiration_dt = datetime.datetime.utcfromtimestamp(int(sincepoch)).date()

            # simply, all the keys here are expired
            if expiration_dt < today_dt:
                continue

            self.assertTrue(False)
        self.assertTrue(True)