Exemplo n.º 1
0
    def connect(self):
        self.unbind_external_drop()
        if self.encrypted_password and not self.password:
            # noinspection PyBroadException
            try:
                decrypted_password = decrypt(self.encrypted_password,
                                             self.ids.main_password.text)
            except Exception as ex:
                self.message = f'Failed to decrypt password {type(ex)}'
                ex_log(self.message)

            else:
                if decrypted_password:
                    self.password = decrypted_password.decode()
                else:
                    return

        if not self.validate():
            return

        if self.originator:
            self.originator.dismiss()
        else:
            self.on_dismiss()
        App.get_running_app().root.connect(self.popup, self.password)
Exemplo n.º 2
0
def retrieve(username, hashed_pwd):
    # to keep check of status
    flag = 0

    # finding the account
    for check in config['DATA'].keys():
        search = re.search('\\b' + username + '\\b', check)
        if search:
            pyperclip.copy(
                unpad(bytes.decode(decrypt(config['DATA'][check],
                                           hashed_pwd))))
            print('Password for ' + check + ' copied to clipboard.')
            flag = 1

    # If account not found
    if flag == 0:
        print("Account not found!")
        count = 0
        for find in config['DATA'].keys():
            search = re.search(username, find)
            if search:
                if count == 0:
                    print("Did you mean?")
                print("=> " + find)
                count = count + 1
Exemplo n.º 3
0
 def decrypt_password(self, encrypted):
     # noinspection PyBroadException
     try:
         decrypted = decrypt(encrypted, self.ids.main_password.text)
     except Exception as ex:
         ex_log('Could not decrypt password', type(ex))
         return None
     else:
         return decrypted
Exemplo n.º 4
0
def main():
    filename = os.path.dirname(os.path.abspath(inspect.stack()[0][1]))
    config.read(filename + '/data.ini')

    if int(config['SETUP']['first_time']) == 1:
        setup.setup()
        exit()

    # authenticating the user
    hashed_pwd = hashed_pass(getpass.getpass(prompt='Password for script: '))
    if unpad(bytes.decode(decrypt(config['SETUP']['check'],
                                  hashed_pwd))) == "dictionary_check":

        # if less than one argument
        if len(sys.argv) <= 1:
            sys.argv.append('--help')

        # Main script
        parser = argparse.ArgumentParser(
            description='A Command line password manager')
        parser.set_defaults(func=lambda x: parser.print_usage())
        parser.add_argument(
            '-a',
            '--add',
            nargs='?',
            action='store',
            help=
            'Add a new account. Just provide the unique account-name along with it'
        )
        parser.add_argument(
            '-g',
            '--get',
            nargs='?',
            action='store',
            help=
            'Copies the password of username passed as argument to your clipboard'
        )
        parser.add_argument('-l',
                            '--list',
                            nargs='?',
                            default='all',
                            const='all',
                            help='List usernames of accounts already added')
        args = parser.parse_args()

        # calling functions
        if args.add:
            add_user(args.add, hashed_pwd)
        elif args.get:
            retrieve(args.get, hashed_pwd)
        elif args.list:
            list_all()

    else:
        print("Wrong password!!")
Exemplo n.º 5
0
 def on_read(self, sock):
     try:
         data = sock.recv(BUF_SIZE)
     except Exception as e:
         print e
         self.destroy()
         return
     if not data:
         self.destroy()
         return
     if self.stage == STAGE_RELAYING:
         if sock == self.local_sock:
             data = decrypt(data)
             print '->', len(data)
             self.send(data, self.remote_sock)
         elif sock == self.remote_sock:
             print '<-', len(data)
             data = encrypt(data)
             self.send(data, self.local_sock)
     elif self.stage == STAGE_WAIT_COMMAND:
         cmd = decrypt(data)
         try:
             request_addr = parse_request_addr(cmd)
             self.send(encrypt('\x05\x00'), self.local_sock)
             sock = socket.socket()
             self.remote_sock = sock
             sock.setblocking(0)
             ws.add(sock)
             sock2handler[sock] = self
             sock.connect_ex(request_addr)
             self.stage = STAGE_CONNECTING
             print 'connecting to remote', request_addr
         except Exception as e:
             print e
             self.destroy()
     elif self.stage == STAGE_CONNECTING:
         data = decrypt(data)
         self.data_to_remote.append(data)
Exemplo n.º 6
0
 def main_password_is_correct(self):
     if self.encrypted_password:
         # noinspection PyBroadException
         try:
             old_key = self.ids.old_main_password_inp.text
             decrypted = decrypt(self.encrypted_password, old_key)
         except Exception:
             self.ids.old_main_password_err.text = 'Old key is not correct.'
             return False
         else:
             self.password = decrypted
             return True
     else:
         return True
Exemplo n.º 7
0
 def on_read(self, sock):
     try:
         data = sock.recv(BUF_SIZE)
     except Exception as e:
         print e
         self.destroy()
         return
     if not data:
         self.destroy()
         return
     if sock == self.local_sock:
         if self.state == STATE_WAIT_GREETING:
             print 'got greeting from {}: {}'.format(
                 sock.getpeername(), len(data))
             self.send('\x05\x00', self.local_sock)
             self.state = STATE_WAIT_COMMAND
         elif self.state == STATE_WAIT_COMMAND:
             self.on_command(data)
         elif self.state == STATE_CONNECTING:
             self.data_to_remote.append(data)
             print 'data from app while connecting:', len(data)
         elif self.state == STATE_RELAYING:
             print '->', len(data)
             self.send(encrypt(data), self.remote_sock)
         else:
             raise NotImplementedError('other state')
     elif sock == self.remote_sock:
         if self.state == STATE_CONNECTING:
             self.state = STATE_RELAYING
             if self.data_to_remote:
                 data = ''.join(self.data_to_remote)
                 self.data_to_remote = []
                 data = encrypt(data)
                 self.send(data, sock)
         elif self.state == STATE_RELAYING:
             data = decrypt(data)
             self.send(data, self.local_sock)
         else:
             raise NotImplementedError('oops')
     else:
         raise Exception('oops')
Exemplo n.º 8
0
 def send(self, data, sock):
     n_total = len(data)
     try:
         n_sent = sock.send(data)
     except socket.error as e:
         self.destroy()
         return
     data = data[:n_sent][:70]
     if sock == self.remote_sock:
         data = decrypt(data)
     print 'sent to {}: {}'.format(
         sock.getpeername(), len(data))
     if n_sent < n_total:
         if sock == self.local_sock:
             self.data_to_local.append(data[n_sent:])
         elif sock == self.remote_sock:
             self.data_to_remote.append(data[n_sent:])
         else:
             raise Exception('oops')
         ws.add(sock)
     else:
         ws.discard(sock)
Exemplo n.º 9
0
def decrypt(ciphertext: bytes, key: bytes) -> Union[str, bytes]:
    return common.decrypt(ciphertext, key, ecb_decryption, ecb=True)
Exemplo n.º 10
0
def decrypt(ciphertext: bytes, key: bytes) -> Union[str, bytes]:
    return common.decrypt(ciphertext, key, cbc_decryption)
Exemplo n.º 11
0
 def decryptMessage(self, message):
     return common.decrypt(self.sessionkey, message)
Exemplo n.º 12
0
 def computeSessionKey(self, nonceReceived):
     nonceReceivedDec = common.decrypt(self.DHKey, nonceReceived)
     combinedNonces = common.xorNonces(self.myNonce, nonceReceivedDec)
     self.sessionkey = common.generateKey(combinedNonces)
Exemplo n.º 13
0
from common import decrypt

# set up server socket
print 'initializing'
HOST = ''
PORT = 1234
if len(sys.argv) == 2:
    if (int(sys.argv[1]) < 65535 and int(sys.argv[1]) > 0):
        PORT = int(sys.argv[1])
    else:
        print "The port provided is invalid, ports must be 0-65535. The program will now exit."
        sys.exit(1)
else:
    print "Invalid number of paramters, default PORT ({0}) will be used.".format(PORT)
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((HOST, PORT))
server.listen(5)
print 'listening on port', PORT

# accept client connection and receive message
client, address = server.accept()
print 'client accepted from', address
ciphertext = client.recv(1024)
print 'received ciphertext', ciphertext

# decrypt received ciphertext and terminate
message = decrypt(ciphertext)
print 'decrypted message', message
print 'terminating'
server.close()