def is_bootloader_active(self):
     time.sleep(0.1)
     print "blQ"
     for i in range(6):
         self.wake()
         time.sleep(0.001)
         self.read(0, 16)
         time.sleep(0.001)
         self.wake()
         time.sleep(0.001)
         devid = self.read_id()
         print binascii.hexify(devid)
         expected_devid = b'\x1f\x84\x01'
         if devid == expected_devid:
             return True
         time.sleep(0.05)
         print "unexpected dev id"
     return False
Exemplo n.º 2
0
    def _handle_removals(self, session, listobj, removals):
        listobj_ref = "{}.{}.{}".format(
            listobj.threatType,
            listobj.threatEntryType,
            listobj.platformType,
        )
        rmcount = 0

        if len(removals['indices']) > 0:
            self.log.debug("processing {} indice removals for {}".format(
                len(removals['indices']), listobj_ref))
            rm_prefixes = []
            for item in removals['indices']:
                prefixobj = session.query(db.SBPrefix)\
                                   .filter(db.SBPrefix.reflist_id == listobj.id)\
                                   .order_by(db.SBPrefix.prefix)\
                                   .limit(1).offset(item).one()
                rm_prefixes.append(prefixobj)
            # we could do these in place since the changes are not
            # reflected until commit but this is probably much safer
            for p in rm_prefixes:
                for h in p.hashes:
                    self.log.debug("rm {} :: {}".format(p.prefix, h.hash))
                    session.delete(h)
                    rmcount += 1
                self.log.debug("rm {}".format(p.prefix, ))
                session.delete(p)
                rmcount += 1

        if len(removals['prefixes']) > 0:
            self.log.debug("processing {} prefix removals for {}".format(
                len(removals['prefixes']), listobj_ref))
            for item in removals['prefixes']:
                self._log_and_raise(
                    "{}: prefixes are unimplemented for handling removals".
                    format(listobj_ref))

                # an idea of how this might work but not necessarily correct, needs to be tested
                prefixobj = session.query(db.SBPrefix)\
                                   .filter(db.SBPrefix.prefix == binascii.hexify(item))\
                                   .one_or_none()
                if not prefixobj:
                    self.log.warning(
                        "failed to locate prefix {} in database for removal".
                        format(item, ))
                    continue
                for h in prefixobj.hashes:
                    self.log.debug("rm {} :: {}".format(prefix, h.hash))
                    session.delete(h)
                    rmcount += 1
                self.log.debug("rm {}".format(prefix, ))
                session.delete(prefixobj)
                rmcount += 1

        self.log.info("removing {} entries from {}".format(
            rmcount, listobj_ref))
Exemplo n.º 3
0
 def verify_json(self, o, e):
     h = objecthash.json_hash(o,
                              (objecthash.commonize, objecthash.redactize))
     self.assertEqual(hexify(h), e)
Exemplo n.º 4
0
 def verify(self, o, e):
     h = objecthash.obj_hash(o)
     self.assertEqual(hexify(h), e)
Exemplo n.º 5
0
def str2bin(message):
    binary = bin(int(binascii.hexify(message), 16))
    return binary[2:]
Exemplo n.º 6
0
 def verify_json(self, o, e):
     h = objecthash.common_redacted_json_hash(o)
     self.assertEqual(hexify(h), e)
Exemplo n.º 7
0
 def verify(self, j, e):
     h = objecthash.python_json_hash(j)
     self.assertEqual(hexify(h), e)
Exemplo n.º 8
0
def redactable_rand():
    r = ''
    for x in range(32):
        r += chr(random.SystemRandom().getrandbits(8))
    return hexify(r)
Exemplo n.º 9
0
 def verify(self, j, e, fns=()):
     h = objecthash.json_hash(j, (objecthash.commonize, ) + fns)
     self.assertEqual(hexify(h), e)
Exemplo n.º 10
0
 def unverify(self, j, e):
     h = objecthash.obj_hash(j)
     self.assertNotEqual(hexify(h), e)
Exemplo n.º 11
0
 def verify(self, j, e):
     # json_hash with no modifiers is Python JSON Hash
     h = objecthash.json_hash(j)
     self.assertEqual(hexify(h), e)
Exemplo n.º 12
0
 def verify(self, j, e, fns=()):
     h = objecthash.json_hash(j, (objecthash.commonize,) + fns)
     self.assertEqual(hexify(h), e)
Exemplo n.º 13
0
 def verify_json(self, o, e):
     h = objecthash.json_hash(o,
                              (objecthash.commonize, objecthash.redactize))
     self.assertEqual(hexify(h), e)
Exemplo n.º 14
0
 def unverify(self, j, e):
     h = objecthash.obj_hash(j)
     self.assertNotEqual(hexify(h), e)
Exemplo n.º 15
0
 def test_redactability(self):
     t = objecthash.redactable(['foo', 'bar'])
     h = hexify(objecthash.obj_hash(t))
     t[1] = objecthash.RedactedObject(t[1])
     self.verify(t, h)
Exemplo n.º 16
0
 def test_redactability(self):
     t = objecthash.redactable(['foo', 'bar'])
     h = hexify(objecthash.obj_hash(t))
     t[1] = objecthash.RedactedObject(t[1])
     self.verify(t, h)
Exemplo n.º 17
0
 def verify(self, o, e):
     h = objecthash.obj_hash(o)
     self.assertEqual(hexify(h), e)
Exemplo n.º 18
0
 def verify(self, j, e):
     # json_hash with no modifiers is Python JSON Hash
     h = objecthash.json_hash(j)
     self.assertEqual(hexify(h), e)
Exemplo n.º 19
0
 def verify(self, j, e):
     h = objecthash.common_json_hash(j)
     self.assertEqual(hexify(h), e)
Exemplo n.º 20
0
def redactable_rand():
    r = ''
    for x in range(32):
        r += chr(random.SystemRandom().getrandbits(8))
    return hexify(r)
Exemplo n.º 21
0
 def verify_json(self, o, e):
     h = objecthash.common_redacted_json_hash(o)
     self.assertEqual(hexify(h), e)