def init_data(self):
        initial_password = u""
        self.__password_hash = hashlib.sha256(
            utils.get_bytes(initial_password)).digest()
        random_password = Random.get_random_bytes(
            16)  # The actual password used
        self.__encrypted_random_password = crypto_utils.encrypt_block(
            random_password, initial_password)
        self.__random_password = None
        self.set_decrypt_only_selected(True)

        # Ugly hack to get an initial database before load-file functionality is implemented
        old_password = u""
        new_password = u"qwerty"
        if self.validate_password(old_password):
            self.__password_hash = hashlib.sha256(
                utils.get_bytes(new_password)).digest()

            random_password = crypto_utils.decrypt_block(
                self.__encrypted_random_password, old_password)
            self.__encrypted_random_password = crypto_utils.encrypt_block(
                random_password, new_password)
            self.__headers = [u"Website", u"Username", u"Password"]
            self.__table = [
                [
                    EncryptedString(u"gmail.com"),
                    EncryptedString(u"patrik1982"),
                    EncryptedString(u"mypass")
                ],
                [
                    EncryptedString(u"yahoo.com"),
                    EncryptedString(u"pater"),
                    EncryptedString(u"mypass")
                ],
                [
                    EncryptedString(u"facebook.com"),
                    EncryptedString(u"nisse"),
                    EncryptedString(u"my!%p4sS")
                ],
                [
                    EncryptedString(u"amazon.de"),
                    EncryptedString(u"björn"),
                    EncryptedString(u"Lösenård fäm")
                ],
            ]
            for row in self.__table:
                row[-1].encrypt(random_password)
            self.__table[1][0].encrypt(random_password)
            self.__table[2][1].encrypt(random_password)
        self.passwordStateChanged.emit(False)
Esempio n. 2
0
def encrypt(plaintext, password):
    iv = Random.get_random_bytes(16)
    cipher = AES.new(create_aes_password(password), AES.MODE_CBC, IV=iv)
    plain_bytes = utils.get_bytes(plaintext)
    n = 16 - (len(plain_bytes) % 16)
    plain_data = plain_bytes + bytes([n] * n)
    return iv + cipher.encrypt(plain_data)
Esempio n. 3
0
    def __init__(self, data=None, is_encrypted=False, *args, **kwargs):
        super(EncryptedString, self).__init__(*args, **kwargs)

        self.__is_encrypted = is_encrypted
        if is_encrypted:
            self.__data = base64.b64decode(data)
        else:
            self.__data = utils.get_bytes(data)
 def change_password(self, old_password, new_password):
     if self.validate_password(old_password):
         self.__password_hash = hashlib.sha256(
             utils.get_bytes(new_password)).digest()
         random_password = crypto_utils.decrypt_block(
             self.__encrypted_random_password, old_password)
         self.__encrypted_random_password = crypto_utils.encrypt_block(
             random_password, new_password)
         return True
     else:
         return False
Esempio n. 5
0
    def verify_current_password(self, current=u""):
        entered_current_password_hash = hashlib.sha256(
            utils.get_bytes(self.__current_password_input.text())).digest()

        palette = self.__current_password_input.palette()
        password_ok = entered_current_password_hash == self.__current_password_hash
        if password_ok:
            palette.setColor(self.__current_password_input.backgroundRole(),
                             Qt.QColor(220, 255, 220))
        else:
            palette.setColor(self.__current_password_input.backgroundRole(),
                             Qt.QColor(255, 220, 220))
        self.__current_password_input.setPalette(palette)
        return password_ok
Esempio n. 6
0
    def __init__(self, header_bstr, time):
        header = get_bytes(header_bstr)
        self.time = time[0] * 1000 + time[1] * 0.001
        self._eth = header[0x00:0x0e]
        self._ipv4 = header[0x0e:0x22]
        self.data = header[0x22:]

        self.len = self._ipv4[0x02] * 256 + self._ipv4[0x03]
        self.id = self._ipv4[0x04] * 256 + self._ipv4[0x05]
        self.flags = self._ipv4[0x06] & 0xe0
        self.offset = ((self._ipv4[0x06] & 0x1f) * 256 + self._ipv4[0x07]) * 8
        self.ttl = self._ipv4[0x08]
        self.proto = self._ipv4[0x09]
        self.src_ip = self._ipv4[0x0c:0x10]
        self.dest_ip = self._ipv4[0x10:0x14]
Esempio n. 7
0
def convert_to_searchable_pdf():
    document = request.files['document']
    document.save(
        os.path.join(app.config['UPLOAD_FOLDER'],
                     secure_filename(document.filename)))

    convert_to_searchable_pdf_service(document)

    bytes = utils.get_bytes(CONVERTIDO_FOLDER + NOME_ARQUIVO_FINAL + '.pdf')

    response = make_response(bytes)
    response.headers.set('Content-Type', 'application/pdf')
    response.headers.set('Content-Disposition',
                         'attachement',
                         filename=document.filename)

    return response
Esempio n. 8
0
def save_data():
    _, received, transmitted = get_bytes()
    uptime, _ = get_uptime()
    now = DateTimeCol.now()
    boot_time = now - timedelta(seconds=uptime)
    boot_time = boot_time - timedelta(seconds=boot_time.second,
                                      microseconds=boot_time.microsecond)
    bws = Bandwidth.select(Bandwidth.q.booted_at==boot_time)
    for bw in bws:
        dr = received - bw.received
        dt = transmitted - bw.transmitted
        bw.received = received
        bw.transmitted = transmitted
        bw.retrieved_at = now
        break
    else:
        dr, dt = received, transmitted
        Bandwidth(booted_at=boot_time, retrieved_at=now, received=received,
                  transmitted=transmitted)

    return dr, dt
Esempio n. 9
0
def save_data():
    _, received, transmitted = get_bytes()
    uptime, _ = get_uptime()
    now = DateTimeCol.now()
    boot_time = now - timedelta(seconds=uptime)
    boot_time = boot_time - timedelta(seconds=boot_time.second,
                                      microseconds=boot_time.microsecond)
    bws = Bandwidth.select(Bandwidth.q.booted_at == boot_time)
    for bw in bws:
        dr = received - bw.received
        dt = transmitted - bw.transmitted
        bw.received = received
        bw.transmitted = transmitted
        bw.retrieved_at = now
        break
    else:
        dr, dt = received, transmitted
        Bandwidth(booted_at=boot_time,
                  retrieved_at=now,
                  received=received,
                  transmitted=transmitted)

    return dr, dt
 def display_bytes_panel(self):
     bytes_str_length = 16
     bytes_text = utils.get_bytes(self.gif_obj.filebytes, bytes_str_length)
     self.display_info_panel(bytes_text)
Esempio n. 11
0
 def set_text(self, plaintext, password=None):
     self.__data = utils.get_bytes(plaintext)
     self.__is_encrypted = (password is not None)
     if password:
         self.encrypt(password)
Esempio n. 12
0
def create_aes_password(password):
    passhash = hashlib.sha1(utils.get_bytes(password)).digest()
    return passhash[:16]
 def validate_password(self, password):
     return hashlib.sha256(
         utils.get_bytes(password)).digest() == self.__password_hash
Esempio n. 14
0
    def tryEncode(self, kw):
        if 'raw' in kw:
            packet = kw['raw']
        else:
            if 'flip' in kw:
                self.flip = int(kw['flip'])
            else:
                self.flip = 0 if self.flip else 1

            if 'addr' in kw:
                addr = int(kw['addr'], 16)
            else:
                addr = self.addr

            fmt = 0
            args = []

            cmd = int(kw['cmd'])

            if 'args' in kw:
                try:
                    args_str = kw['args'].split(';')
                    args = [int(arg) for arg in args_str]
                except:
                    pass

            if cmd == NooliteCommands.SetLevel:
                if args:
                    # set level
                    args.append(0)
                    fmt = 3
                else:
                    fmt = 1
                    args = [int(kw['arg'])]
            elif cmd == NooliteCommands.ShadowSetBright:
                args = [int(kw['arg'])]
                fmt = 5
            elif cmd == NooliteCommands.TemporaryOn:
                timeout = int(kw['arg'])
                if (timeout < 0) or (timeout > 65535):
                    return

                if timeout > 255:
                    args = [timeout % 256, timeout / 256]
                    fmt = 6
                else:
                    args = [timeout]
                    fmt = 5

            elif cmd in (NooliteCommands.SwitchMode,
                         NooliteCommands.SwitchColor):
                fmt = 4

            if 'crc' in kw:
                crc = int(kw['crc'])
            else:
                crc = self.calcChecksum(self.flip, cmd, addr, fmt, args)

            addr_hi = addr >> 8
            addr_lo = addr & 0x00ff

            args_data = ''
            cmd_data = ''

            if fmt in (0, 1, 3):
                cmd_data = bin(cmd)[2:].zfill(4)[::-1]
            else:
                cmd_data = bin(cmd)[2:].zfill(8)[::-1]

            if fmt in (1, 5):
                args_data = bin(args[0])[2:].zfill(8)[::-1]
            elif fmt == 3:
                assert len(args) == 4
                args_data = "".join(
                    bin(args[i])[2:].zfill(8)[::-1] for i in xrange(4))

            packet = "".join(
                ('1', str(self.flip),
                 cmd_data, args_data, bin(addr_lo)[2:].zfill(8)[::-1],
                 bin(addr_hi)[2:].zfill(8)[::-1], bin(fmt)[2:].zfill(8)[::-1],
                 bin(crc)[2:].zfill(8)[::-1]))

        enc_packet = utils.manchester_encode(packet)
        bitstream = "".join((utils.manchester_encode('0' * 41), '00',
                             enc_packet, '000', enc_packet))

        data = utils.get_bytes(bitstream)
        #~ print data

        #~ print "decode:"
        #~ print self.tryDecode(data)

        return data
Esempio n. 15
0
    def tryEncode(self, kw):
        if 'raw' in kw:
            packet = kw['raw']
        else:
            if 'flip' in kw:
                self.flip = int(kw['flip'])
            else:
                self.flip = 0 if self.flip else 1

            if 'addr' in kw:
                addr = int(kw['addr'], 16)
            else:
                addr = self.addr

            fmt = 0
            args = []

            cmd = int(kw['cmd'])

            if 'args' in kw:
                try:
                    args_str = kw['args'].split(';')
                    args = [int(arg) for arg in args_str]
                except:
                    pass

            if cmd == NooliteCommands.SetLevel:
                if args:
                    # set level
                    args.append(0)
                    fmt = 3
                else:
                    fmt = 1
                    args = [ int(kw['arg']) ]
            elif cmd == NooliteCommands.ShadowSetBright:
                args = [ int(kw['arg']) ]
                fmt = 5
            elif cmd == NooliteCommands.TemporaryOn:
                timeout = int(kw['arg'])
                if (timeout < 0) or (timeout > 65535):
                    return

                if timeout > 255:
                    args = [timeout % 256, timeout / 256]
                    fmt = 6
                else:
                    args = [timeout]
                    fmt = 5

            elif cmd in (NooliteCommands.SwitchMode,NooliteCommands.SwitchColor):
                fmt = 4




            if 'crc' in kw:
                crc = int(kw['crc'])
            else:
                crc = self.calcChecksum(self.flip, cmd, addr, fmt, args)

            addr_hi = addr >> 8
            addr_lo = addr & 0x00ff

            args_data = ''
            cmd_data = ''

            if fmt in (0, 1, 3):
                cmd_data = bin(cmd)[2:].zfill(4)[::-1]
            else:
                cmd_data = bin(cmd)[2:].zfill(8)[::-1]


            if fmt in (1, 5):
                args_data = bin(args[0])[2:].zfill(8)[::-1]
            elif fmt == 3:
                assert len(args) == 4
                args_data = "".join(bin(args[i])[2:].zfill(8)[::-1] for i in xrange(4))

            packet = "".join(( '1',
                                str(self.flip),
                                cmd_data,
                                args_data,
                                bin(addr_lo)[2:].zfill(8)[::-1],
                                bin(addr_hi)[2:].zfill(8)[::-1],
                                bin(fmt)[2:].zfill(8)[::-1],
                                bin(crc)[2:].zfill(8)[::-1] ))





        enc_packet = utils.manchester_encode(packet)
        bitstream = "".join((utils.manchester_encode('0'*41),
                            '00',
                             enc_packet,
                             '000',
                             enc_packet))



        data = utils.get_bytes(bitstream)
        #~ print data

        #~ print "decode:"
        #~ print self.tryDecode(data)


        return data