class KeyGenerator(service.MultiService, foolscap.Referenceable):
implements(RIKeyGenerator)
- DEFAULT_KEY_SIZE = 2048
pool_size = 16 # no. keys to keep on hand in the pool
pool_refresh_delay = 6 # no. sec to wait after a fetch before generating new keys
verbose = False
- def __init__(self):
+ def __init__(self, default_key_size=2048):
service.MultiService.__init__(self)
self.keypool = []
self.last_fetch = 0
+ self.default_key_size = default_key_size
def startService(self):
self.timer = reactor.callLater(0, self.maybe_refill_pool)
if self.last_fetch + self.pool_refresh_delay < now:
self.vlog('%s refilling pool' % (self,))
while len(self.keypool) < self.pool_size:
- self.keypool.append(self.gen_key(self.DEFAULT_KEY_SIZE))
+ self.keypool.append(self.gen_key(self.default_key_size))
else:
self.vlog('%s not refilling pool' % (self,))
reactor.callLater(1, self.maybe_refill_pool)
def remote_get_rsa_key_pair(self, key_size):
self.vlog('%s remote_get_key' % (self,))
- if key_size != self.DEFAULT_KEY_SIZE or not self.keypool:
+ if key_size != self.default_key_size or not self.keypool:
key = self.gen_key(key_size)
self.reset_timer()
return key
class KeyGeneratorService(service.MultiService):
furl_file = 'key_generator.furl'
- def __init__(self, basedir='.', display_furl=True):
+ def __init__(self, basedir='.', display_furl=True, default_key_size=2048):
service.MultiService.__init__(self)
self.basedir = basedir
self.tub = foolscap.Tub(certFile=os.path.join(self.basedir, 'key_generator.pem'))
self.tub.setServiceParent(self)
- self.key_generator = KeyGenerator()
+ self.key_generator = KeyGenerator(default_key_size=default_key_size)
self.key_generator.setServiceParent(self)
portnum = self.get_portnum()
from allmydata import key_generator
from twisted.application import service
-k = key_generator.KeyGeneratorService()
+k = key_generator.KeyGeneratorService(2048)
#k.key_generator.verbose = False
-#k.key_generator.DEFAULT_KEY_SIZE = 2048
#k.key_generator.pool_size = 16
#k.key_generator.pool_refresh_delay = 6
return junk
#print 'starting key generator service'
- kgs = key_generator.KeyGeneratorService(display_furl=False)
+ keysize = 522
+ kgs = key_generator.KeyGeneratorService(display_furl=False, default_key_size=keysize)
kgs.key_generator.verbose = True
kgs.setServiceParent(self.parent)
kgs.key_generator.pool_size = 8
- keysize = kgs.key_generator.DEFAULT_KEY_SIZE
def keypool_full():
return len(kgs.key_generator.keypool) == kgs.key_generator.pool_size