Ejemplo n.º 1
0
 def generateKeys(self):
     '''
     Generate new RSA-2048 keys for this client (accurate off)
     '''
     Display.log('Generating new keys...')
     self.crypto.generate()
     self.saveKeys()
     Display.log('Done.\n')
Ejemplo n.º 2
0
 def do_roll(self, roll_string):
     '''
     Takes a roll string (e.g. '2d4') rolls, then returns the result as
     an integer.
     '''
     if 'd' not in roll_string:
         return 'is failing to roll anything coherent'
     num_dice, suffix = roll_string.split('d')
     die_type, modifier = self.get_modifier(suffix)
     rolls = [r.randint(1, int(die_type)) for i in range(int(num_dice))]
     total = sum(rolls) + int(modifier)
     Display.log('You rolled a {0} and got a {1}'.format(roll_string, total))
     return 'rolls {0} and gets {1}'.format(roll_string, total)
Ejemplo n.º 3
0
    def password_loop(self, filename):
        '''Loops until the correct password is entered'''
        attempts = 0
        while attempts < 3:
            password = input('Please enter password to unlock ({0} attempts remaining):  '.format(3-attempts))
            try:
                with open(filename,'rb') as enc_data:
                    encrypted = pickle.load(enc_data)
                    data = self.keyloader.unlock_with_password(password, encrypted)
                    self.crypto.load(data['privateKey'])
                    Display.log('User settings loaded.')
                    return
            except:
                Display.warn('Wrong password')
                attempts += 1

        Display.error('You have exceeded the number of attempts to log in as this user.')
        sys.exit(1)
Ejemplo n.º 4
0
    cipher = AES.new(hashed, AES.MODE_CBC, aes_iv[:AES.block_size])

    return cipher.encrypt(pad(locked_content))

def unlockWithPassword(passkey, encrypted):
    passkey = hashPhrase(passkey.encode('utf-8'), hashlib.sha256)
    aes_iv = hashPhrase(passkey, hashlib.sha1)
    aes = AES.new(passkey,AES.MODE_CBC, aes_iv[:AES.block_size])
    
    decrypted = aes.decrypt(encrypted).decode('utf-8')
    end_of_json = decrypted.rfind('}')

    return json.loads(decrypted[:(1+end_of_json)].strip())

while True:
    password = input('Please enter a short password:  '******'{"message": "contents which are not readable"}')
        break
    except Exception as msg:
        Display.warn('This password is too long. Please try again.  {0}'.format(msg))

while True:
    passkey = input('Please verify your password:  '******'Correct password. \nContents are "{0}"\n'.format(data['message']))
        break
    except:
        Display.warn('Incorrect password.\n')
Ejemplo n.º 5
0
import os, json
from pyna.base.Display import Display

Display.log('Clean begin.')

# Clean Json files
json_files = [f for f in os.listdir() if '.json' in f]
if len(json_files) > 0:
    Display.warn('Purging {0} JSON files'.format(len(json_files)))
    for f in json_files:
        os.remove(f)

# Remove keys
json_files = [f for f in os.listdir('config/keys/') if '.pyna' in f]
if len(json_files) > 0:
    Display.warn('Purging {0} Pyna Key files'.format(len(json_files)))
    for f in json_files:
        os.remove('config/keys/{0}'.format(f))

# Clean node list
Display.warn('Cleaning nodes.json')
with open('config/nodes.json','w') as nodelistconfig:
	json.dump({"nodes": []}, nodelistconfig)

# Clean users list
Display.warn('Cleaning users.json')
with open('config/users.json','w') as users:
	json.dump({}, users)

# Clean log
Display.warn('Cleaning log file')