Пример #1
0
 def test_encode_decode_pw_trained_grammar(self):
     H, G, tr_pcfg = self.H, self.G, self.tr_pcfg
     for i, pw in enumerate(random.sample(RANDOM_PW_SET, 30)):
         pwprime = tr_pcfg.decode_pw(tr_pcfg.encode_pw(pw))
         self.assertEqual(
             pwprime, pw, "Password encode-decode error!\n"
             "EncodedPw={}, DecodedPw={}".format(pw, pwprime))
Пример #2
0
 def initialize_vault(self, mp):
     vd = VaultDistPCFG()
     if not os.path.exists(self.vault_fl):
         print_production("\nCould not find the vault file @ {}, so, sit tight, " \
                          "creating a dummy vault for you." \
                          "\nShould not take too long...\n".format(self.vault_fl))
         t_s = random.randints(0, MAX_INT,
                               hny_config.HONEY_VAULT_ENCODING_SIZE)
         self.H = t_s[:hny_config.HONEY_VAULT_GRAMMAR_SIZE]
         t_s = t_s[hny_config.HONEY_VAULT_GRAMMAR_SIZE:]
         self.S = [
             t_s[i:i + hny_config.PASSWORD_LENGTH]
             for i in range(0, self.s * hny_config.PASSWORD_LENGTH,
                            hny_config.PASSWORD_LENGTH)
         ]
         assert all(
             len(s) == hny_config.PASSWORD_LENGTH for s in self.S
         ), "All passwords encodings are not of correct length.\n {}".format(
             (len(s), hny_config.PASSWORD_LENGTH) for s in self.S)
         self.machine_pass_set = list('0' * (self.mpass_set_size * 8))
         k = int(math.ceil(hny_config.HONEY_VAULT_STORAGE_SIZE * \
                           hny_config.MACHINE_GENRATED_PASS_PROB / 1000.0))
         for i in random.sample(
                 list(range(hny_config.HONEY_VAULT_STORAGE_SIZE)), k):
             self.machine_pass_set[i] = '1'
         self.salt = os.urandom(8)
         self.save(mp)
     else:
         self.load(mp)
Пример #3
0
 def test_encode_decode_pw(self):
     H = random.randints(0, MAX_INT, hny_config.HONEY_VAULT_GRAMMAR_SIZE)
     tr_pcfg = pcfg.TrainedGrammar()
     G = tr_pcfg.decode_grammar(H)
     for i, pw in enumerate(random.sample(RANDOM_PW_SET, 30)):
         pwprime = G.decode_pw(G.encode_pw(pw))
         self.assertEqual(pwprime, pw, "Password encode-decode error!\n"\
                          "EncodedPw={}, DecodedPw={}".format(pw, pwprime))
Пример #4
0
 def test_encode_decode_pw(self):
     H = random.randints(0, MAX_INT, hny_config.HONEY_VAULT_GRAMMAR_SIZE)
     tr_pcfg = pcfg.TrainedGrammar()
     G = tr_pcfg.decode_grammar(H)
     for i, pw in enumerate(random.sample(RANDOM_PW_SET, 30)):
         pwprime = G.decode_pw(G.encode_pw(pw))
         self.assertEqual(pwprime, pw, "Password encode-decode error!\n"\
                          "EncodedPw={}, DecodedPw={}".format(pw, pwprime))
Пример #5
0
    def test_encode_decode_rule(self):
        H, G, tr_pcfg = self.H, self.G, self.tr_pcfg

        for i, pw in enumerate(random.sample(RANDOM_PW_SET, 10)):
            pt = tr_pcfg.l_parse_tree(pw)
            for p in pt:
                t = tr_pcfg.encode_rule(*p)
                c = tr_pcfg.decode_rule(p[0], t)
                assert p[1] == c, "Decoding {} we got {}. Expecting {}" \
                    .format(t, c, p[1])
Пример #6
0
    def test_encode_decode_rule(self):
        H, G, tr_pcfg = self.H, self.G, self.tr_pcfg

        for i, pw in enumerate(random.sample(RANDOM_PW_SET, 10)):
            pt = tr_pcfg.l_parse_tree(pw)
            for p in pt:
                t = tr_pcfg.encode_rule(*p)
                c = tr_pcfg.decode_rule(p[0], t)
                assert p[1] == c, "Decoding {} we got {}. Expecting {}" \
                    .format(t, c, p[1])
Пример #7
0
    def test_encode_decode_rule(self):
        H = random.randints(0, MAX_INT, hny_config.HONEY_VAULT_GRAMMAR_SIZE)
        tr_pcfg = pcfg.TrainedGrammar()
        G = tr_pcfg.decode_grammar(H)

        for i, pw in enumerate(random.sample(RANDOM_PW_SET, 10)):
            pt = tr_pcfg.l_parse_tree(pw)
            for p in pt:
                t = tr_pcfg.encode_rule(*p)
                c = tr_pcfg.decode_rule(p[0], t)
                assert p[1] == c, "Decoding {} we got {}. Expecting {}"\
                  .format(t, c, p[1])
Пример #8
0
 def test_encode_decode_rule(self):
     H = random.randints(0, MAX_INT, hny_config.HONEY_VAULT_GRAMMAR_SIZE)
     tr_pcfg = pcfg.TrainedGrammar()
     G = tr_pcfg.decode_grammar(H)
     
     for i, pw in enumerate(random.sample(RANDOM_PW_SET, 10)):
         pt = tr_pcfg.l_parse_tree(pw)
         for p in pt:
             t = tr_pcfg.encode_rule(*p)
             c = tr_pcfg.decode_rule(p[0], t)
             assert p[1] == c, "Decoding {} we got {}. Expecting {}"\
               .format(t, c, p[1])
Пример #9
0
 def initialize_vault(self, mp):
     vd = VaultDistPCFG()
     if not os.path.exists(self.vault_fl):
         print_production("\nCould not find the vault file @ {}, so, sit tight, "\
                          "creating a dummy vault for you."\
                          "\nShould not take too long...\n".format(self.vault_fl))
         t_s = random.randints(0, MAX_INT, hny_config.HONEY_VAULT_ENCODING_SIZE)
         self.H = t_s[:hny_config.HONEY_VAULT_GRAMMAR_SIZE]
         t_s = t_s[hny_config.HONEY_VAULT_GRAMMAR_SIZE:]
         self.S = [t_s[i:i+hny_config.PASSWORD_LENGTH]
                   for i in range(0, self.s*hny_config.PASSWORD_LENGTH, hny_config.PASSWORD_LENGTH)]
         assert all(len(s)==hny_config.PASSWORD_LENGTH for s in self.S), "All passwords encodings are not of correct length.\n {}".format((len(s), hny_config.PASSWORD_LENGTH) for   s in self.S)
         self.machine_pass_set = list('0'*(self.mpass_set_size*8))
         k = int(math.ceil(hny_config.HONEY_VAULT_STORAGE_SIZE * \
                               hny_config.MACHINE_GENRATED_PASS_PROB/1000.0))
         for i in random.sample(range(hny_config.HONEY_VAULT_STORAGE_SIZE), k):
             self.machine_pass_set[i] = '1'
         self.salt = os.urandom(8)
         self.save(mp)
     else:
         self.load(mp)
Пример #10
0
 def test_encode_decode_pw_trained_grammar(self):
     H, G, tr_pcfg = self.H, self.G, self.tr_pcfg
     for i, pw in enumerate(random.sample(RANDOM_PW_SET, 30)):
         pwprime = tr_pcfg.decode_pw(tr_pcfg.encode_pw(pw))
         self.assertEqual(pwprime, pw, "Password encode-decode error!\n"
                                       "EncodedPw={}, DecodedPw={}".format(pw, pwprime))