Exemple #1
0
 def check_checksum(self,checksum):
     password = util.getpassword(self.dbconn, Settings.ident)
     if not password:
         print '***No password in database'
         return True
     check = hashlib.sha1(password.upper()).hexdigest()
     if check != checksum:
         chkprint('***Checksum does not match:')
         chkprint('\tCalculated:\t %s' % check)
         chkprint('\tReceived:\t %s' % checksum)
         return False
     return True
Exemple #2
0
def process_monitor_directive(line):
    """takes directive and returns command if response is needed"""
    global cookie
    global mycipher
    global authcomplete
    global passwordchanged
    global transfer_args
    
    directive, args = [i.strip() for i in line.split(':', 1)]
    if directive == 'WAITING' and authcomplete and Settings.mode == 'manual':
        if transfer_args:
            command = encrypt('TRANSFER_REQUEST %s %s FROM %s\n' % transfer_args)
            transfer_args = ()
            return command
        else:
            command = raw_input('Enter command: ') + '\n'
            return mycipher.encrypt(command) if mycipher else command
    elif directive == 'REQUIRE':
        if args == 'IDENT':
            if Settings.encrypt:
                return 'IDENT %s %s\n' % (Settings.ident, util.base32(mysession.public_key))
            else:
                return 'IDENT %s\n' % Settings.ident
        elif args == 'PASSWORD':
            password = util.getpassword(dbconn, Settings.ident)
            if not password:
                password = util.genpassword()
                util.updatepassword(dbconn, Settings.ident, password)
            return encrypt('PASSWORD %s\n' % password)
        elif args == 'HOST_PORT':
            return encrypt('HOST_PORT %s %s\n' % (Settings.server, Settings.server_port))
        elif args == 'ALIVE':
            return encrypt('ALIVE %s\n' % util.getcookie(dbconn, Settings.ident))
        elif args == 'PUBLIC_KEY':
            return encrypt('PUBLIC_KEY %d %d\n' % (prover.v, prover.n))
        elif args == 'AUTHORIZE_SET':
            return encrypt('AUTHORIZE_SET %s\n' %  ' '.join(str(s) for s in prover.authorize_iter()))
        elif args == 'SUBSET_J':
            return encrypt('SUBSET_J %s\n' % ' '.join(str(s) for s in prover.subset_j_iter()))
        elif args == 'SUBSET_K':
            return encrypt('SUBSET_K %s\n' % ' '.join(str(s) for s in prover.subset_k_iter()))
    elif directive == 'RESULT':
        if args == 'ALIVE Identity has been verified.' or args == 'HOST_PORT LOCALHOST %s' % Settings.server_port:
            authcomplete = True
            return
        args = args.split()
        if args[0] == 'PASSWORD' or args[0] == 'CHANGE_PASSWORD':
            cookie = args[1]
            util.updatecookie(dbconn, Settings.ident, cookie)
        elif args[0] == 'IDENT' and Settings.encrypt:
            mysession.set_monitor_key(int(args[1], 32))
            mycipher = karn.Cipher(mysession.shared_secret)
        elif args[0] == 'ROUNDS':
            prover.rounds = int(args[1])
        elif args[0] == 'SUBSET_A':
            prover.subset_a = tuple(int(i) for i in args[1:])
    elif directive == 'WAITING' and authcomplete:
        if not passwordchanged:
            oldpass = util.getpassword(dbconn, Settings.ident)
            newpass = util.genpassword()
            util.updatepassword(dbconn, Settings.ident, newpass)
            passwordchanged = True
            return encrypt('CHANGE_PASSWORD %s %s\n' % (oldpass, newpass))
        if transfer_args:
            command = encrypt('TRANSFER_REQUEST %s %s FROM %s\n' % transfer_args)
            transfer_args = ()
            return command
        if Settings.mode == 'manual':
            return encrypt(raw_input('Enter server command: ') + '\n')