Ejemplo n.º 1
0
 def test_twoparts(self):
     data = HashedPRNG(b"foobar").get(256)
     for l in range(len(data) + 1):
         prng = HashedPRNG(b"foobar")
         part1 = prng.get(l)
         part2 = prng.get(len(data) - l)
         self.assertEqual(data, part1 + part2)
Ejemplo n.º 2
0
 def test_pattern(self):
     data = HashedPRNG(b"foobar").get(1024)
     self.assertEqual(
         hashlib.md5(data).hexdigest(), "acc988f3788299f2bd603c38902ae0a7")
     data = HashedPRNG(b"barfoo").get(1024)
     self.assertEqual(
         hashlib.md5(data).hexdigest(), "fe06bbd9bf3988af7b3f2d12b20bd583")
Ejemplo n.º 3
0
 def _prepare_file(fp, data):
     fp.truncate(0)
     fp.seek(0)
     prng = HashedPRNG(seed=b"woohoo")
     for element in data:
         if isinstance(element, int):
             fp.write(prng.get(element))
         else:
             fp.write(element)
     fp.flush()
Ejemplo n.º 4
0
 def test_scrape_dir_exists(self):
     with tempfile.TemporaryDirectory() as tempdir, WorkDir(tempdir):
         HashedPRNG(seed=b"foobar").write_file("out.bin", 3000)
         os.mkdir("scrape")
         with open("scrape/foo", "wb"):
             pass
         self._run_x509sak(["scrape", "out.bin"], success_return_codes=[1])
         self.assertTrue(os.path.isfile("scrape/foo"))
         self._run_x509sak(["scrape", "--force", "out.bin"])
         self.assertTrue(os.path.isfile("scrape/foo"))
Ejemplo n.º 5
0
 def test_scrape_der_crt(self):
     with tempfile.TemporaryDirectory() as tempdir, WorkDir(tempdir):
         crt = self._load_crt("ok/johannes-bauer.com")
         for prefix_len in [
                 0, 100, 1000, 1024 * 1024 - 100, 1024 * 1024,
                 1024 * 1024 + 100
         ]:
             HashedPRNG(seed=b"foobar").write_bracketed(
                 "out.bin", prefix_len, crt.der_data, 1000)
             self._run_x509sak(["scrape", "out.bin"])
             found = os.listdir("scrape/")
             self.assertEqual(len(found), 1)
             scraped_crt = X509Certificate.read_pemfile(
                 "scrape/scrape_%07x_crt.pem" % (prefix_len))[0]
             self.assertEqual(crt, scraped_crt)
             shutil.rmtree("scrape")
Ejemplo n.º 6
0
 def test_scrape_random(self):
     with tempfile.TemporaryDirectory() as tempdir, WorkDir(tempdir):
         HashedPRNG(seed=b"foobar").write_file("out.bin", 3 * 1024 * 1024)
         self._run_x509sak(["scrape", "out.bin"])
         found = os.listdir("scrape/")
         self.assertEqual(len(found), 0)
Ejemplo n.º 7
0
 def test_beginning(self):
     data = HashedPRNG(b"foobar").get(1024)
     for l in range(len(data) + 1):
         part = HashedPRNG(b"foobar").get(l)
         self.assertEqual(part, data[:l])
Ejemplo n.º 8
0
 def test_prng(self):
     prng = HashedPRNG(b"foobar")
     first = prng.get(128)
     prng.reset()
     second = prng.get(128)
     self.assertEqual(first, second)