private void handle(Exception e, int internalCode) throws StorageException { if (AuthPlugin.DEBUG_LOGIN_FRAMEWORK) e.printStackTrace(); StorageException exception = new StorageException(internalCode, e); throw exception; }
public ServerConfiguration getConfig() { Builder builder = getConfigBuilderNoCredentials(getHost(), getOrganization()); if (hasAuth()) { try { builder.credentials(ServersManager.getUsername(this), ServersManager.getPassword(this)); } catch (StorageException e) { throw new IllegalStateException("Unable to read server credentials from storage: " + e.getMessage(), e); } } return builder.build(); }
private void loadProxyAuth(IProxyData data) { ISecurePreferences node = getNode(); if (node == null) return; try { data.setUserid(node.get(INFO_PROXY_USER, null)); data.setPassword(node.get(INFO_PROXY_PASS, null)); } catch (StorageException e) { Activator.logError(e.getMessage(), e); } }
private void handle(Exception e, int internalCode) throws StorageException { if (AuthPlugin.DEBUG_LOGIN_FRAMEWORK) e.printStackTrace(); StorageException exception = new StorageException(internalCode, e); throw exception; }
/** * Result: Map: * <String>cipher -> <String>keyFactory */ public HashMap detect() { IUICallbacks callback = CallbacksProvider.getDefault().getCallback(); if (callback == null) return internalDetect(); IStorageTask task = new IStorageTask() { public void execute() { internalDetect(); } }; try { callback.execute(task); } catch (StorageException e) { // should not happen in this path AuthPlugin.getDefault().logError(e.getMessage(), e); } return availableCiphers; }
public CryptoData(String data) throws StorageException { // separate moduleID int pos = data.indexOf(MODULE_ID_SEPARATOR); String encrypted; if (pos == -1) { // invalid data format throw new StorageException(StorageException.DECRYPTION_ERROR, SecAuthMessages.invalidEntryFormat); } else if (pos == 0) { moduleID = null; encrypted = data.substring(1); } else { moduleID = data.substring(0, pos); encrypted = data.substring(pos + 1); } // separate salt and data int saltPos = encrypted.indexOf(SALT_SEPARATOR); if (saltPos != -1) { salt = Base64.decode(encrypted.substring(0, saltPos)); encryptedData = Base64.decode(encrypted.substring(saltPos + 1)); } else { // this is a "null" value if (encrypted.length() != 0) // double check that this is not a broken entry throw new StorageException(StorageException.DECRYPTION_ERROR, SecAuthMessages.invalidEntryFormat); salt = null; encryptedData = null; } }
/** * Result: Map: * <String>cipher -> <String>keyFactory */ public HashMap<String, String> detect() { IUICallbacks callback = CallbacksProvider.getDefault().getCallback(); if (callback == null) return internalDetect(); IStorageTask task = () -> internalDetect(); try { callback.execute(task); } catch (StorageException e) { // should not happen in this path AuthPlugin.getDefault().logError(e.getMessage(), e); } return availableCiphers; }
public CryptoData(String data) throws StorageException { // separate moduleID int pos = data.indexOf(MODULE_ID_SEPARATOR); String encrypted; if (pos == -1) { // invalid data format throw new StorageException(StorageException.DECRYPTION_ERROR, SecAuthMessages.invalidEntryFormat); } else if (pos == 0) { moduleID = null; encrypted = data.substring(1); } else { moduleID = data.substring(0, pos); encrypted = data.substring(pos + 1); } // separate salt and data int saltPos = encrypted.indexOf(SALT_SEPARATOR); if (saltPos != -1) { salt = Base64.decode(encrypted.substring(0, saltPos)); encryptedData = Base64.decode(encrypted.substring(saltPos + 1)); } else { // this is a "null" value if (encrypted.length() != 0) // double check that this is not a broken entry throw new StorageException(StorageException.DECRYPTION_ERROR, SecAuthMessages.invalidEntryFormat); salt = null; encryptedData = null; } }
private void saveProxyAuth(IProxyData data) { ISecurePreferences node= getNode(); if (node == null) return; try { if (data.getUserId() != null) node.put(INFO_PROXY_USER, data.getUserId(), true /* store encrypted */); else node.remove(INFO_PROXY_USER); if (data.getPassword() != null) node.put(INFO_PROXY_PASS, data.getPassword(), true /* store encrypted */); else node.remove(INFO_PROXY_PASS); } catch (StorageException e) { Activator.logError(e.getMessage(), e); return; } // optional: save it right away in case something crashes later try { node.flush(); } catch (IOException e) { Activator.logError(e.getMessage(), e); return; } }
/** * Provides password for a new entry using: * 1) default password, if any * 2a) if options specify usage of specific module, that module is polled to produce password * 2b) otherwise, password provider with highest priority is used to produce password */ public PasswordExt getPassword(String moduleID, IPreferencesContainer container, boolean encryption) throws StorageException { if (encryption) { // provides password for a new entry PasswordExt defaultPassword = getDefaultPassword(container); if (defaultPassword != null) return defaultPassword; moduleID = getDefaultModuleID(container); } else { // provides password for previously encrypted entry using its specified password provider module if (moduleID == null) throw new StorageException(StorageException.NO_SECURE_MODULE, SecAuthMessages.invalidEntryFormat); if (DEFAULT_PASSWORD_ID.equals(moduleID)) { // was default password used? PasswordExt defaultPassword = getDefaultPassword(container); if (defaultPassword != null) return defaultPassword; throw new StorageException(StorageException.NO_SECURE_MODULE, SecAuthMessages.noDefaultPassword); } } return getModulePassword(moduleID, container); }
/** * Provides password for a new entry using: * 1) default password, if any * 2a) if options specify usage of specific module, that module is polled to produce password * 2b) otherwise, password provider with highest priority is used to produce password */ public PasswordExt getPassword(String moduleID, IPreferencesContainer container, boolean encryption) throws StorageException { if (encryption) { // provides password for a new entry PasswordExt defaultPassword = getDefaultPassword(container); if (defaultPassword != null) return defaultPassword; moduleID = getDefaultModuleID(container); } else { // provides password for previously encrypted entry using its specified password provider module if (moduleID == null) throw new StorageException(StorageException.NO_SECURE_MODULE, SecAuthMessages.invalidEntryFormat); if (DEFAULT_PASSWORD_ID.equals(moduleID)) { // was default password used? PasswordExt defaultPassword = getDefaultPassword(container); if (defaultPassword != null) return defaultPassword; throw new StorageException(StorageException.NO_SECURE_MODULE, SecAuthMessages.noDefaultPassword); } } return getModulePassword(moduleID, container); }
else msg = NLS.bind(SecAuthMessages.noSecureStorageModule, expectedID); throw new StorageException(StorageException.NO_SECURE_MODULE, msg);
public void run() { IProgressService progressService = PlatformUI.getWorkbench().getProgressService(); InitWithProgress task = new InitWithProgress(callback); try { progressService.busyCursorWhile(task); } catch (InvocationTargetException e) { exception[0] = new StorageException(StorageException.INTERNAL_ERROR, e); return; } catch (InterruptedException e) { exception[0] = new StorageException(StorageException.INTERNAL_ERROR, SecUIMessages.initCancelled); return; } exception[0] = task.getException(); } });
else msg = NLS.bind(SecAuthMessages.noSecureStorageModule, expectedID); throw new StorageException(StorageException.NO_SECURE_MODULE, msg);
protected void internalInitialize() throws StorageException { if (cipherAlgorithm != null && keyFactoryAlgorithm != null) { if (roundtrip(cipherAlgorithm, keyFactoryAlgorithm)) return; // this is a bad situation - JVM cipher no longer available. Both log and throw an exception String msg = NLS.bind(SecAuthMessages.noAlgorithm, cipherAlgorithm); StorageException e = new StorageException(StorageException.INTERNAL_ERROR, msg); AuthPlugin.getDefault().logError(msg, e); throw e; } if (cipherAlgorithm == null || keyFactoryAlgorithm == null) { IEclipsePreferences eclipseNode = ConfigurationScope.INSTANCE.getNode(AuthPlugin.PI_AUTH); cipherAlgorithm = eclipseNode.get(IStorageConstants.CIPHER_KEY, IStorageConstants.DEFAULT_CIPHER); keyFactoryAlgorithm = eclipseNode.get(IStorageConstants.KEY_FACTORY_KEY, IStorageConstants.DEFAULT_KEY_FACTORY); } if (roundtrip(cipherAlgorithm, keyFactoryAlgorithm)) return; String unavailableCipher = cipherAlgorithm; detect(); if (availableCiphers.size() == 0) throw new StorageException(StorageException.INTERNAL_ERROR, SecAuthMessages.noAlgorithms); // use first available cipherAlgorithm = availableCiphers.keySet().iterator().next(); keyFactoryAlgorithm = availableCiphers.get(cipherAlgorithm); String msg = NLS.bind(SecAuthMessages.usingAlgorithm, unavailableCipher, cipherAlgorithm); AuthPlugin.getDefault().logMessage(msg); }
protected void internalInitialize() throws StorageException { if (cipherAlgorithm != null && keyFactoryAlgorithm != null) { if (roundtrip(cipherAlgorithm, keyFactoryAlgorithm)) return; // this is a bad situation - JVM cipher no longer available. Both log and throw an exception String msg = NLS.bind(SecAuthMessages.noAlgorithm, cipherAlgorithm); StorageException e = new StorageException(StorageException.INTERNAL_ERROR, msg); AuthPlugin.getDefault().logError(msg, e); throw e; } if (cipherAlgorithm == null || keyFactoryAlgorithm == null) { IEclipsePreferences eclipseNode = new ConfigurationScope().getNode(AuthPlugin.PI_AUTH); cipherAlgorithm = eclipseNode.get(IStorageConstants.CIPHER_KEY, IStorageConstants.DEFAULT_CIPHER); keyFactoryAlgorithm = eclipseNode.get(IStorageConstants.KEY_FACTORY_KEY, IStorageConstants.DEFAULT_KEY_FACTORY); } if (roundtrip(cipherAlgorithm, keyFactoryAlgorithm)) return; String unavailableCipher = cipherAlgorithm; detect(); if (availableCiphers.size() == 0) throw new StorageException(StorageException.INTERNAL_ERROR, SecAuthMessages.noAlgorithms); // use first available cipherAlgorithm = (String) availableCiphers.keySet().iterator().next(); keyFactoryAlgorithm = (String) availableCiphers.get(cipherAlgorithm); String msg = NLS.bind(SecAuthMessages.usingAlgorithm, unavailableCipher, cipherAlgorithm); AuthPlugin.getDefault().logMessage(msg); }
progressService.busyCursorWhile(task); } catch (InvocationTargetException e) { exception[0] = new StorageException(StorageException.INTERNAL_ERROR, e); return; } catch (InterruptedException e) { exception[0] = new StorageException(StorageException.INTERNAL_ERROR, SecUIMessages.initCancelled); return; job.join(); } catch (InterruptedException e) { exception[0] = new StorageException(StorageException.INTERNAL_ERROR, SecUIMessages.initCancelled);
public String get(String key, String def, SecurePreferencesContainer container) throws StorageException { checkRemoved(); if (!hasKey(key)) return def; String encryptedValue = internalGet(key); if (encryptedValue == null) return null; CryptoData data = new CryptoData(encryptedValue); String moduleID = data.getModuleID(); if (moduleID == null) { // clear-text value, not encrypted if (data.getData() == null) return null; return StorageUtils.getString(data.getData()); } PasswordExt passwordExt = getRoot().getPassword(moduleID, container, false); if (passwordExt == null) throw new StorageException(StorageException.NO_PASSWORD, SecAuthMessages.loginNoPassword); try { byte[] clearText = getRoot().getCipher().decrypt(passwordExt, data); return StorageUtils.getString(clearText); } catch (IllegalBlockSizeException e) { // invalid password? throw new StorageException(StorageException.DECRYPTION_ERROR, e); } catch (BadPaddingException e) { // invalid password? throw new StorageException(StorageException.DECRYPTION_ERROR, e); } }
public String get(String key, String def, SecurePreferencesContainer container) throws StorageException { checkRemoved(); if (!hasKey(key)) return def; String encryptedValue = internalGet(key); if (encryptedValue == null) return null; CryptoData data = new CryptoData(encryptedValue); String moduleID = data.getModuleID(); if (moduleID == null) { // clear-text value, not encrypted if (data.getData() == null) return null; return StorageUtils.getString(data.getData()); } PasswordExt passwordExt = getRoot().getPassword(moduleID, container, false); if (passwordExt == null) throw new StorageException(StorageException.NO_PASSWORD, SecAuthMessages.loginNoPassword); try { byte[] clearText = getRoot().getCipher().decrypt(passwordExt, data); return StorageUtils.getString(clearText); } catch (IllegalBlockSizeException e) { // invalid password? throw new StorageException(StorageException.DECRYPTION_ERROR, e); } catch (BadPaddingException e) { // invalid password? throw new StorageException(StorageException.DECRYPTION_ERROR, e); } }
progressService.busyCursorWhile(task); } catch (InvocationTargetException e1) { exception[0] = new StorageException(StorageException.INTERNAL_ERROR, e1); return; } catch (InterruptedException e2) { exception[0] = new StorageException(StorageException.INTERNAL_ERROR, SecUIMessages.initCancelled); return; job.join(); } catch (InterruptedException e) { exception[0] = new StorageException(StorageException.INTERNAL_ERROR, SecUIMessages.initCancelled);