protected Matching createMatching(List<String> lowerSanitizedInputs) { return new Matching(lowerSanitizedInputs); }
protected Matching(Map<String, Map<String, Integer>> rankedDictionaries, List<String> orderedList) { if (rankedDictionaries != null) { this.rankedDictionaries = new HashMap<>(rankedDictionaries); } else { this.rankedDictionaries = new HashMap<>(); } Map<String, Integer> rankedUserInputs; if (orderedList != null && !orderedList.isEmpty()) { rankedUserInputs = buildRankedDict(orderedList); } else { rankedUserInputs = Collections.emptyMap(); } this.rankedDictionaries.put("user_inputs", rankedUserInputs); }
public Strength measure(String password, List<String> sanitizedInputs) { if (password == null) { throw new IllegalArgumentException("Password is null."); } List<String> lowerSanitizedInputs; if (sanitizedInputs != null && !sanitizedInputs.isEmpty()) { lowerSanitizedInputs = new ArrayList<>(sanitizedInputs.size()); for (String sanitizedInput : sanitizedInputs) { lowerSanitizedInputs.add(sanitizedInput.toLowerCase()); } } else { lowerSanitizedInputs = Collections.emptyList(); } long start = time(); Matching matching = createMatching(lowerSanitizedInputs); List<Match> matches = matching.omnimatch(password); Strength strength = Scoring.mostGuessableMatchSequence(password, matches); strength.setCalcTime(time() - start); AttackTimes attackTimes = TimeEstimates.estimateAttackTimes(strength.getGuesses()); strength.setCrackTimeSeconds(attackTimes.getCrackTimeSeconds()); strength.setCrackTimesDisplay(attackTimes.getCrackTimesDisplay()); strength.setScore(attackTimes.getScore()); strength.setFeedback(Feedback.getFeedback(strength.getScore(), strength.getSequence())); return strength; }
public Strength measure(String password, List<String> sanitizedInputs) { if (password == null) { throw new IllegalArgumentException("Password is null."); } List<String> lowerSanitizedInputs; if (sanitizedInputs != null && !sanitizedInputs.isEmpty()) { lowerSanitizedInputs = new ArrayList<>(sanitizedInputs.size()); for (String sanitizedInput : sanitizedInputs) { lowerSanitizedInputs.add(sanitizedInput.toLowerCase()); } } else { lowerSanitizedInputs = Collections.emptyList(); } long start = time(); Matching matching = createMatching(lowerSanitizedInputs); List<Match> matches = matching.omnimatch(password); Strength strength = Scoring.mostGuessableMatchSequence(password, matches); strength.setCalcTime(time() - start); AttackTimes attackTimes = TimeEstimates.estimateAttackTimes(strength.getGuesses()); strength.setCrackTimeSeconds(attackTimes.getCrackTimeSeconds()); strength.setCrackTimesDisplay(attackTimes.getCrackTimesDisplay()); strength.setScore(attackTimes.getScore()); strength.setFeedback(Feedback.getFeedback(strength.getScore(), strength.getSequence())); return strength; }
@Test public void testOmnimatch() throws Exception { assertEquals(0, new Matching(new ArrayList<String>()).omnimatch("").size()); String password = "r0sebudmaelstrom11/20/91aaaa"; List<Match> matches = new Matching(new ArrayList<String>()).omnimatch(password); Map<Pattern, Integer[]> testMatches = new HashMap<>(); testMatches.put(Pattern.Dictionary, new Integer[]{0, 6}); testMatches.put(Pattern.Dictionary, new Integer[]{7, 15}); testMatches.put(Pattern.Date, new Integer[]{16, 23}); testMatches.put(Pattern.Repeat, new Integer[]{24, 27}); for (Map.Entry<Pattern, Integer[]> testMatch : testMatches.entrySet()) { Pattern patternName = testMatch.getKey(); int i = testMatch.getValue()[0]; int j = testMatch.getValue()[1]; boolean included = false; for (Match match : matches) { if (match.i == i && match.j == j && match.pattern == patternName) included = true; } String msg = String.format("for %s, matches a %s token at [%s, %s]", password, patternName.value(), i, j); assertTrue(msg, included); } } }
protected Matching createMatching(List<String> lowerSanitizedInputs) { return new Matching(lowerSanitizedInputs); }
protected Matching(Map<String, Map<String, Integer>> rankedDictionaries, List<String> orderedList) { if (rankedDictionaries != null) { this.rankedDictionaries = new HashMap<>(rankedDictionaries); } else { this.rankedDictionaries = new HashMap<>(); } Map<String, Integer> rankedUserInputs; if (orderedList != null && !orderedList.isEmpty()) { rankedUserInputs = buildRankedDict(orderedList); } else { rankedUserInputs = Collections.emptyMap(); } this.rankedDictionaries.put("user_inputs", rankedUserInputs); }
@Test public void testRepeatGuesses() throws Exception { double baseGuesses = Scoring.mostGuessableMatchSequence( baseToken, new Matching().omnimatch(baseToken)).getGuesses(); Match match = new Match.Builder(Pattern.Repeat, 0, 0, token) .baseToken(baseToken) .baseGuesses(baseGuesses) .repeatCount(repeatCount) .build(); double expectedGuesses = baseGuesses * repeatCount; String msg = String.format("the repeat pattern '%s' has guesses of %s", token, expectedGuesses); assertEquals(msg, expectedGuesses, new RepeatGuess().exec(match), 0.0); }