예제 #1
0
def init():
    lg.out(4, "message_keeper.init")
    message.AddIncomingMessageCallback(on_incoming_message)
    message.AddOutgoingMessageCallback(on_outgoing_message)
    if not my_keys.is_key_registered(messages_key_id()):
        my_keys.generate_key(messages_key_id(),
                             key_size=settings.getPrivateKeySize())
예제 #2
0
 def _on_my_keys_synchronized(self, evt):
     from logs import lg
     from main import settings
     from storage import keys_synchronizer
     from crypt import my_keys
     from chat import message_keeper
     if not my_keys.is_key_registered(message_keeper.messages_key_id(
     )) and keys_synchronizer.is_synchronized():
         lg.info(
             'key to store messages was not found but we know that all my keys are in sync, generate a new key: %s'
             % message_keeper.messages_key_id())
         my_keys.generate_key(message_keeper.messages_key_id(),
                              key_size=settings.getPrivateKeySize())
예제 #3
0
 def _on_my_keys_synchronized(self, evt):
     from logs import lg
     from main import settings
     from storage import keys_synchronizer
     from crypt import my_keys
     from userid import my_id
     customer_key_id = my_id.getGlobalID(key_alias='customer')
     if not my_keys.is_key_registered(
             customer_key_id) and keys_synchronizer.is_synchronized():
         lg.info(
             'customer key was not found but we know that all keys are in sync, generate new key: %s'
             % customer_key_id)
         my_keys.generate_key(customer_key_id,
                              key_size=settings.getPrivateKeySize())
예제 #4
0
파일: key.py 프로젝트: hack-bitdust/devel
def GenerateNewKey(keyfilename=None):
    global _MyKeyObject
    global _MyRsaKey
    if keyfilename is None:
        keyfilename = settings.KeyFileName()
    if os.path.exists(keyfilename + '_location'):
        newkeyfilename = bpio.ReadTextFile(keyfilename + '_location').strip()
        if os.path.exists(newkeyfilename):
            keyfilename = newkeyfilename
    lg.out(4, 'key.InitMyKey generate new private key')
    _MyRsaKey = RSA.generate(settings.getPrivateKeySize(), os.urandom)
    _MyKeyObject = keys.Key(_MyRsaKey)
    keystring = _MyKeyObject.toString('openssh')
    bpio.WriteFile(keyfilename, keystring)
    lg.out(4, '    wrote %d bytes to %s' % (len(keystring), keyfilename))
예제 #5
0
def GenerateNewKey(keyfilename=None):
    global _MyPubKey
    global _MyRsaKey
    if keyfilename is None:
        keyfilename = settings.KeyFileName()
    if os.path.exists(keyfilename + '_location'):
        newkeyfilename = bpio.ReadTextFile(keyfilename + '_location').strip()
        if os.path.exists(newkeyfilename):
            keyfilename = newkeyfilename
    lg.out(4, 'key.InitMyKey generate new private key')
    _MyRsaKey = RSA.generate(settings.getPrivateKeySize(), os.urandom)
    _MyPubKey = keys.Key(_MyRsaKey)
    keystring = _MyPubKey.toString('openssh')
    bpio.WriteFile(keyfilename, keystring)
    lg.out(4, '    wrote %d bytes to %s' % (len(keystring), keyfilename))
예제 #6
0
def GenerateNewKey(keyfilename=None):
    global _MyKeyObject
    if keyfilename is None:
        keyfilename = settings.KeyFileName()
    if os.path.exists(keyfilename + '_location'):
        newkeyfilename = bpio.ReadTextFile(keyfilename + '_location').strip()
        if os.path.exists(newkeyfilename):
            keyfilename = newkeyfilename
    if _Debug:
        lg.out(_DebugLevel, 'key.InitMyKey generate new private key')
    _MyKeyObject = rsa_key.RSAKey()
    _MyKeyObject.generate(settings.getPrivateKeySize())
    keystring = _MyKeyObject.toPrivateString()
    bpio.WriteTextFile(keyfilename, keystring)
    if _Debug:
        lg.out(_DebugLevel, '    wrote %d bytes to %s' % (len(keystring), keyfilename))
    del keystring
    gc.collect()
예제 #7
0
 def start(self):
     from contacts import contactsdb
     from crypt import my_keys
     from customer import supplier_connector
     from logs import lg
     from main import settings
     from userid import my_id
     customer_key_id = my_id.getGlobalID(key_alias='customer')
     if not my_keys.is_key_registered(customer_key_id):
         lg.warn('customer key was not found, generate new key: %s' % customer_key_id)
         my_keys.generate_key(customer_key_id, key_size=settings.getPrivateKeySize())
     for pos, supplier_idurl in enumerate(contactsdb.suppliers()):
         if supplier_idurl and not supplier_connector.by_idurl(supplier_idurl, customer_idurl=my_id.getLocalID()):
             supplier_connector.create(
                 supplier_idurl=supplier_idurl,
                 customer_idurl=my_id.getLocalID(),
             )
     # TODO: read from dht and connect to other suppliers - from other customers who shared data to me
     return True
예제 #8
0
 def _register():
     if len(args) <= 2:
         return 2
     pksize = settings.getPrivateKeySize()
     if len(args) > 3:
         try:
             pksize = int(args[3])
         except:
             print_text('incorrect private key size\n')
             return 0
     from automats import automat
     from main import initializer
     from lib import misc
     if not misc.ValidUserName(args[2]):
         return 0
     initializer.A('run-cmd-line-register', {'username': args[2], 'pksize': pksize})
     reactor.run()
     automat.objects().clear()
     if my_id.isLocalIdentityReady():
         print_text('new identity created:')
         print_text(my_id.getLocalIdentity().serialize())
     else:
         print_text('identity creation FAILED')
     return 0