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)
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)
def add_password(self, domain_pw_map): #print self.dte.G nG = copy.deepcopy(self.dte.G) print_production("Updating the grammar with new passwords..") nG.update_grammar(*(domain_pw_map.values())) ndte = DTE(nG) # TODO: fix this, currently its a hack to way around my shitty # parsing. A password can be generated in a different way than it is parsed in most probably # way. The code is supposed to pick one parse tree at random. Currently picking the most # probable one. Need to fix for security reason. Will add a ticket. new_encoding_of_old_pw = [] current_passwords = ['' for _ in xrange(hny_config.HONEY_VAULT_STORAGE_SIZE)] if self.dte and (ndte != self.dte): # if new dte is different then copy the existing human chosen passwords. # Machine generated passwords are not necessary to reencode. As their grammar # does not change. NEED TO CHECK SECURITY. print_production("Some new rules found, so adding them to the new grammar. "\ "Should not take too long...\n") data = [(self.dte, ndte, i, p) for i,p in enumerate(self.S) if self.machine_pass_set[i] == '0'] result = ProcessParallel(copy_from_old_parallel, data, func_load=100) for i,pw, pw_encodings in result: if isinstance(pw_encodings, basestring): new_encoding_of_old_pw.append((i, pw_encodings)) current_passwords[i] = pw self.S[i] = pw_encodings # print_err(self.H[:10]) # G_ = self.pcfg.decode_grammar(self.H) # print_err("-"*50) # print_err("Original: ", nG, '\n', '='*50) # print_err("After Decoding:", G_) # assert G_ == nG print_production("\nAdding new passowrds..\n") for domain, pw in domain_pw_map.items(): i = self.get_domain_index(domain) print ">>", i, pw, domain current_passwords[i] = pw self.S[i] = ndte.encode_pw(pw) self.machine_pass_set[i] = '0' # Cleaning the mess because of missed passwords # Because some password might have failed in copy_from_old_function, They need to be # re-encoded if new_encoding_of_old_pw: print_err("\n<<<<<<\nFixing Mess!!\n{}>>>>>>>".format(new_encoding_of_old_pw)) nG.update_grammar(*[p for i,p in new_encoding_of_old_pw]) for i,p in new_encoding_of_old_pw: self.S[i] = ndte.encode_pw(p) self.machine_pass_set[i] = '0' if hny_config.DEBUG: for i,pw_encodings in enumerate(self.S): if self.machine_pass_set[i] == '0': tpw = ndte.decode_pw(pw_encodings) tpwold = current_passwords[i] assert len(tpwold)<=0 or tpw == tpwold,\ "The re-encoding is faulty. Expecting: '{}' at {}. Got '{}'.".format(tpwold, i, tpw) self.H = self.pcfg.encode_grammar(nG) self.dte = ndte