2507 #ˆl–äY>”ËmJq@µq·.å1hßÉ ƒyÑ ÈÂË"############################################################################ # Copyright (C) Internet Systems Consortium, Inc. ("ISC") # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, you can obtain one at https://mozilla.org/MPL/2.0/. # # See the COPYRIGHT file distributed with this work for additional # information regarding copyright ownership. ############################################################################ from collections import defaultdict from .dnskey import * from .keydict import * from .keyevent import * from .policy import * import time class keyseries: _K = defaultdict(lambda: defaultdict(list)) _Z = defaultdict(lambda: defaultdict(list)) _zones = set() _kdict = None _context = None def __init__(self, kdict, now=time.time(), context=None): self._kdict = kdict self._context = context self._zones = set(kdict.missing()) for zone in kdict.zones(): self._zones.add(zone) for alg, keys in kdict[zone].items(): for k in keys.values(): if k.sep: if not (k.delete() and k.delete() < now): self._K[zone][alg].append(k) else: if not (k.delete() and k.delete() < now): self._Z[zone][alg].append(k) self._K[zone][alg].sort() self._Z[zone][alg].sort() def __iter__(self): for zone in self._zones: for collection in [self._K, self._Z]: if zone not in collection: continue for alg, keys in collection[zone].items(): for key in keys: yield key def dump(self): for k in self: print("%s" % repr(k)) def fixseries(self, keys, policy, now, **kwargs): force = kwargs.get('force', False) if not keys: return # handle the first key key = keys[0] if key.sep: rp = policy.ksk_rollperiod prepub = policy.ksk_prepublish or (30 * 86400) postpub = policy.ksk_postpublish or (30 * 86400) else: rp = policy.zsk_rollperiod prepub = policy.zsk_prepublish or (30 * 86400) postpub = policy.zsk_postpublish or (30 * 86400) # the first key should be published and active p = key.publish() a = key.activate() if not p or p > now: key.setpublish(now) p = now if not a or a > now: key.setactivate(now) a = now i = key.inactive() fudge = 300 if not rp: key.setinactive(None, **kwargs) key.setdelete(None, **kwargs) elif not i or a + rp != i: if not i and a + rp > now + prepub + fudge: key.setinactive(a + rp, **kwargs) key.setdelete(a + rp + postpub, **kwargs) elif not i: key.setinactive(now + prepub + fudge, **kwargs) key.setdelete(now + prepub + postpub + fudge, **kwargs) elif i < now: pass elif a + rp > i: key.setinactive(a + rp, **kwargs) key.setdelete(a + rp + postpub, **kwargs) elif a + rp > now + prepub + fudge: key.setinactive(a + rp, **kwargs) key.setdelete(a + rp + postpub, **kwargs) else: key.setinactive(now + prepub + fudge, **kwargs) key.setdelete(now + prepub + postpub + fudge, **kwargs) else: d = key.delete() if not d or i + postpub > now + fudge: key.setdelete(i + postpub, **kwargs) elif not d: key.setdelete(now + postpub + fudge, **kwargs) elif d < now + fudge: