private void handle(Exception e, int internalCode) throws StorageException { if (AuthPlugin.DEBUG_LOGIN_FRAMEWORK) e.printStackTrace(); StorageException exception = new StorageException(internalCode, e); throw exception; }
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 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; } }
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; } }
/** * 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 = 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); }
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); }
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);
public void put(String key, String value, boolean encrypt, SecurePreferencesContainer container) throws StorageException { if (key == null) throw new NullPointerException(); checkRemoved(); if (!encrypt || value == null) { CryptoData clearValue = new CryptoData(null, null, StorageUtils.getBytes(value)); internalPut(key, clearValue.toString()); // uses Base64 to encode byte sequences markModified(); return; } PasswordExt passwordExt = getRoot().getPassword(null, container, true); if (passwordExt == null) { boolean storeDecrypted = !CallbacksProvider.getDefault().runningUI() || InternalExchangeUtils.isJUnitApp(); if (storeDecrypted) { // for JUnits and headless runs we store value as clear text and log a error CryptoData clearValue = new CryptoData(null, null, StorageUtils.getBytes(value)); internalPut(key, clearValue.toString()); markModified(); // Make this as visible as possible. Both print out the output and log a error String msg = NLS.bind(SecAuthMessages.storedClearText, key, absolutePath()); System.out.println(msg); AuthPlugin.getDefault().logError(msg, new StorageException(StorageException.NO_PASSWORD, msg)); return; } throw new StorageException(StorageException.NO_PASSWORD, SecAuthMessages.loginNoPassword); } // value must not be null at this point CryptoData encryptedValue = getRoot().getCipher().encrypt(getRoot().getPassword(null, container, true), StorageUtils.getBytes(value)); internalPut(key, encryptedValue.toString()); markModified(); }
public void put(String key, String value, boolean encrypt, SecurePreferencesContainer container) throws StorageException { if (key == null) throw new NullPointerException(); checkRemoved(); if (!encrypt || value == null) { CryptoData clearValue = new CryptoData(null, null, StorageUtils.getBytes(value)); internalPut(key, clearValue.toString()); // uses Base64 to encode byte sequences markModified(); return; } PasswordExt passwordExt = getRoot().getPassword(null, container, true); if (passwordExt == null) { boolean storeDecrypted = !CallbacksProvider.getDefault().runningUI() || InternalExchangeUtils.isJUnitApp(); if (storeDecrypted) { // for JUnits and headless runs we store value as clear text and log a error CryptoData clearValue = new CryptoData(null, null, StorageUtils.getBytes(value)); internalPut(key, clearValue.toString()); markModified(); // Make this as visible as possible. Both print out the output and log a error String msg = NLS.bind(SecAuthMessages.storedClearText, key, absolutePath()); System.out.println(msg); AuthPlugin.getDefault().logError(msg, new StorageException(StorageException.NO_PASSWORD, msg)); return; } throw new StorageException(StorageException.NO_PASSWORD, SecAuthMessages.loginNoPassword); } // value must not be null at this point CryptoData encryptedValue = getRoot().getCipher().encrypt(getRoot().getPassword(null, container, true), StorageUtils.getBytes(value)); internalPut(key, encryptedValue.toString()); markModified(); }
private PasswordExt getModulePassword(String moduleID, IPreferencesContainer container) throws StorageException { if (DEFAULT_PASSWORD_ID.equals(moduleID)) // this should never happen but add this check just in case throw new StorageException(StorageException.NO_PASSWORD, SecAuthMessages.loginNoPassword); throw new StorageException(StorageException.NO_PASSWORD, SecAuthMessages.loginNoPassword); if (setupPasswordRecovery) CallbacksProvider.getDefault().setupChallengeResponse(key, container);
private PasswordExt getModulePassword(String moduleID, IPreferencesContainer container) throws StorageException { if (DEFAULT_PASSWORD_ID.equals(moduleID)) // this should never happen but add this check just in case throw new StorageException(StorageException.NO_PASSWORD, SecAuthMessages.loginNoPassword); throw new StorageException(StorageException.NO_PASSWORD, SecAuthMessages.loginNoPassword); if (setupPasswordRecovery) CallbacksProvider.getDefault().setupChallengeResponse(key, container);