protected char[] getMasterPassword(String encryptedPassword) throws PasswordResolverException { synchronized (masterPasswordLock) { init(); if (masterPassword == null) { if (masterPwdCallback == null) { throw new PasswordResolverException("masterPasswordCallback is not initialized"); } this.masterPassword = masterPwdCallback.getPassword("Please enter the master password", encryptedPassword); } return masterPassword; } }
@Override public String protectPassword(char[] password) throws PasswordResolverException { final int iterationCount = 2000; return PBEPasswordService.encryptPassword(PBEAlgo.PBEWithHmacSHA256AndAES_256, iterationCount, getMasterPassword(null), password); }
@Override public char[] resolvePassword(String passwordHint) throws PasswordResolverException { return PBEPasswordService.decryptPassword(getMasterPassword(passwordHint), passwordHint); }
pwdCallback = new PasswordCallback.File(); } else if ("GUI".equalsIgnoreCase(type)) { pwdCallback = new PasswordCallback.Gui(); } else if ("PBE-GUI".equalsIgnoreCase(type)) { pwdCallback = new PasswordCallback.PBEGui(); } else if ("OBF".equalsIgnoreCase(type)) { pwdCallback = new PasswordCallback.OBF(); if (conf != null && !StringUtil.startsWithIgnoreCase(conf, "OBF:")) { conf = "OBF:" + conf; pwdCallback.init(conf); } catch (PasswordResolverException ex) { throw new IllegalArgumentException("invalid masterPasswordCallback configuration " + masterPasswordCallback + ", " + ex.getClass().getName() + ": " + ex.getMessage());
public List<char[]> getPasswords(PasswordResolver passwordResolver) throws PasswordResolverException { if (passwords == null) { return null; } List<char[]> ret = new ArrayList<char[]>(passwords.size()); for (String password : passwords) { if (passwordResolver == null) { ret.add(password.toCharArray()); } else { ret.add(passwordResolver.resolvePassword(password)); } } return ret; }
@Override public char[] getPassword(String prompt, String testToken) throws PasswordResolverException { String tmpPrompt = prompt; if (StringUtil.isBlank(tmpPrompt)) { tmpPrompt = "Password required"; } for (int i = 0; i < tries; i++) { char[] password; if (quorum == 1) { password = SecurePasswordInputPanel.readPassword(tmpPrompt); if (password == null) { throw new PasswordResolverException("user has cancelled"); } } else { char[][] passwordParts = new char[quorum][]; for (int j = 0; j < quorum; j++) { String promptPart = tmpPrompt + " (part " + (j + 1) + "/" + quorum + ")"; passwordParts[j] = SecurePasswordInputPanel.readPassword(promptPart); if (passwordParts[j] == null) { throw new PasswordResolverException("user has cancelled"); } } password = StringUtil.merge(passwordParts); } if (isPasswordValid(password, testToken)) { return password; } } throw new PasswordResolverException("Could not get the password after " + tries + " tries"); }
protected char[] readPassword(final String prompt) throws IOException { String tmpPrompt = (prompt == null) ? "Password:" : prompt.trim(); if (!tmpPrompt.endsWith(":")) { tmpPrompt += ":"; } String passwordUi = System.getProperty("org.xipki.console.passwordui"); return "gui".equalsIgnoreCase(passwordUi) ? SecurePasswordInputPanel.readPassword(tmpPrompt) : readLine(tmpPrompt, '*').toCharArray(); }
@Override public String protectPassword(String protocol, char[] password) throws PasswordResolverException { Objects.requireNonNull(protocol, "protocol may not be null"); Objects.requireNonNull(password, "password may not be null"); for (SinglePasswordResolver resolver : resolvers) { if (resolver.canResolveProtocol(protocol)) { return resolver.protectPassword(password); } } throw new PasswordResolverException("could not find password resolver to protect password " + "of protocol '" + protocol + "'"); }
public void init() { if (initialized) { return; } resolvers.add(new SinglePasswordResolver.OBF()); SinglePasswordResolver.PBE pbe = new SinglePasswordResolver.PBE(); if (masterPasswordCallback != null) { pbe.setMasterPasswordCallback(masterPasswordCallback); } resolvers.add(pbe); initialized = true; }
@Override public char[] resolvePassword(String passwordHint) throws PasswordResolverException { Objects.requireNonNull(passwordHint, "passwordHint may not be null"); int index = passwordHint.indexOf(':'); if (index == -1) { return passwordHint.toCharArray(); } String protocol = passwordHint.substring(0, index); for (SinglePasswordResolver resolver : resolvers) { if (resolver.canResolveProtocol(protocol)) { return resolver.resolvePassword(passwordHint); } } throw new PasswordResolverException("could not find password resolver to resolve password " + "of protocol '" + protocol + "'"); }
@Override public char[] resolvePassword(String passwordHint) throws PasswordResolverException { return OBFPasswordService.deobfuscate(passwordHint).toCharArray(); }
@Override protected Set<String> getEnums() { return new HashSet<>(PasswordProducer.getNames()); }
@Override public String protectPassword(char[] password) throws PasswordResolverException { return OBFPasswordService.obfuscate(new String(password)); }
@Override protected boolean isPasswordValid(char[] password, String testToken) { if (StringUtil.isBlank(testToken)) { return true; } try { PBEPasswordService.decryptPassword(password, testToken); return true; } catch (PasswordResolverException ex) { return false; } }
@Override public char[] getPassword(String prompt, String testToken) throws PasswordResolverException { if (password == null) { throw new PasswordResolverException("please initialize me first"); } return password; }
public static PBEAlgo forCode(int code) { for (PBEAlgo value : values()) { if (value.code == code) { return value; } } return null; }
protected char[] readPassword(String prompt) throws IOException { String tmpPrompt = (prompt == null) ? "Password:" : prompt.trim(); if (!tmpPrompt.endsWith(":")) { tmpPrompt += ":"; } String passwordUi = System.getProperty("org.xipki.console.passwordui"); return "gui".equalsIgnoreCase(passwordUi) ? SecurePasswordInputPanel.readPassword(tmpPrompt) : readLine(tmpPrompt, '*').toCharArray(); }
@Override public void init(String conf) throws PasswordResolverException { Args.notBlank(conf, "conf"); this.password = OBFPasswordService.deobfuscate(conf).toCharArray(); }
@Override protected Set<String> getEnums() { return new HashSet<>(PasswordProducer.getNames()); }
protected char[] readPassword(String prompt) throws IOException { String tmpPrompt = (prompt == null) ? "Password:" : prompt.trim(); if (!tmpPrompt.endsWith(":")) { tmpPrompt += ":"; } String passwordUi = System.getProperty("org.xipki.console.passwordui"); return "gui".equalsIgnoreCase(passwordUi) ? SecurePasswordInputPanel.readPassword(tmpPrompt) : readLine(tmpPrompt, '*').toCharArray(); }