def add_password(self, domain_pw_map): #print self.dte.G nG = copy.deepcopy(self.dte.G) nG.update_grammar(*(domain_pw_map.values())) ndte = DTE(nG) if self.dte and (ndte != self.dte): # if new dte is different then 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, p in enumerate(result): self.S[i] = p self.H = self.pcfg.encode_grammar(nG) #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 for d, p in domain_pw_map.items(): i = self.get_domain_index(d) self.S[i] = ndte.encode_pw(p) self.machine_pass_set[i] = '0' self.dte = ndte
def __init__(self, vault_fl, mp): self.pcfg = TrainedGrammar() # Default large trained PCFG domain_hash_map_fl = hny_config.STATIC_DOMAIN_HASH_LIST self.domain_hash_map = json.load(open_(domain_hash_map_fl)) self.vault_fl = vault_fl self.mp = mp self.initialize_vault(mp) self.dte = DTE(self.pcfg.decode_grammar(self.H))
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