List of usage examples for org.apache.commons.ssl OpenSSL decrypt
public static InputStream decrypt(String cipher, char[] pwd, InputStream encrypted) throws IOException, GeneralSecurityException
From source file:eu.openanalytics.rsb.security.SecurableMx4JHttpAdaptor.java
public SecurableMx4JHttpAdaptor(final Configuration configuration) throws IOException, GeneralSecurityException { super();/*w w w .j a v a2 s. c o m*/ final JmxConfiguration jmxConfiguration = configuration.getJmxConfiguration(); if (jmxConfiguration != null) { if (StringUtils.isNotBlank(jmxConfiguration.getHttpAuthenticationUsername())) { httpAuthenticationUsername = jmxConfiguration.getHttpAuthenticationUsername(); httpAuthenticationEncryptedPassword = jmxConfiguration.getHttpAuthenticationPassword(); // decrypt the configured password using the username as the decryption password final byte[] decryptedPasswordBytes = OpenSSL.decrypt("des3", httpAuthenticationUsername.toCharArray(), httpAuthenticationEncryptedPassword.getBytes("UTF-8")); addAuthorization(httpAuthenticationUsername, new String(decryptedPasswordBytes, "UTF-8")); setAuthenticationMethod(BASIC_AUTHENTICATION_METHOD); LOGGER.info("Basic authentication active"); return; } } httpAuthenticationUsername = null; httpAuthenticationEncryptedPassword = null; }
From source file:com.eviware.soapui.DefaultSoapUICore.java
protected Settings initSettings(String fileName) { // TODO Why try to load settings from current directory before using root? // This caused a bug in Eclipse: // https://sourceforge.net/tracker/?func=detail&atid=737763&aid=2620284&group_id=136013 File settingsFile = new File(fileName).exists() ? new File(fileName) : null; try {/* w w w . jav a 2s.com*/ if (settingsFile == null) { settingsFile = new File(new File(getRoot()), DEFAULT_SETTINGS_FILE); if (!settingsFile.exists()) { settingsFile = new File(new File(System.getProperty("user.home", ".")), DEFAULT_SETTINGS_FILE); lastSettingsLoad = 0; } } else { settingsFile = new File(fileName); if (!settingsFile.getAbsolutePath().equals(this.settingsFile)) lastSettingsLoad = 0; } if (!settingsFile.exists()) { if (settingsDocument == null) { log.info("Creating new settings at [" + settingsFile.getAbsolutePath() + "]"); settingsDocument = SoapuiSettingsDocumentConfig.Factory.newInstance(); setInitialImport(true); } lastSettingsLoad = System.currentTimeMillis(); } else if (settingsFile.lastModified() > lastSettingsLoad) { settingsDocument = SoapuiSettingsDocumentConfig.Factory.parse(settingsFile); byte[] encryptedContent = settingsDocument.getSoapuiSettings().getEncryptedContent(); if (encryptedContent != null) { char[] password = null; if (this.password == null) { // swing element -!! uh! JPasswordField passwordField = new JPasswordField(); JLabel qLabel = new JLabel("Password"); JOptionPane.showConfirmDialog(null, new Object[] { qLabel, passwordField }, "Global Settings", JOptionPane.OK_CANCEL_OPTION); password = passwordField.getPassword(); } else { password = this.password.toCharArray(); } byte[] data = OpenSSL.decrypt("des3", password, encryptedContent); try { settingsDocument = SoapuiSettingsDocumentConfig.Factory.parse(new String(data, "UTF-8")); } catch (Exception e) { log.warn("Wrong password."); JOptionPane.showMessageDialog(null, "Wrong password, creating backup settings file [ " + settingsFile.getAbsolutePath() + ".bak.xml. ]\nSwitch to default settings.", "Error - Wrong Password", JOptionPane.ERROR_MESSAGE); settingsDocument.save(new File(settingsFile.getAbsolutePath() + ".bak.xml")); throw e; } } log.info("initialized soapui-settings from [" + settingsFile.getAbsolutePath() + "]"); lastSettingsLoad = settingsFile.lastModified(); if (settingsWatcher == null) { settingsWatcher = new SettingsWatcher(); SoapUI.getSoapUITimer().scheduleAtFixedRate(settingsWatcher, 10000, 10000); } } } catch (Exception e) { log.warn("Failed to load settings from [" + e.getMessage() + "], creating new"); settingsDocument = SoapuiSettingsDocumentConfig.Factory.newInstance(); lastSettingsLoad = 0; } if (settingsDocument.getSoapuiSettings() == null) { settingsDocument.addNewSoapuiSettings(); settings = new XmlBeansSettingsImpl(null, null, settingsDocument.getSoapuiSettings()); initDefaultSettings(settings); } else { settings = new XmlBeansSettingsImpl(null, null, settingsDocument.getSoapuiSettings()); } this.settingsFile = settingsFile.getAbsolutePath(); if (!settings.isSet(WsdlSettings.EXCLUDED_TYPES)) { StringList list = new StringList(); list.add("schema@http://www.w3.org/2001/XMLSchema"); settings.setString(WsdlSettings.EXCLUDED_TYPES, list.toXml()); } if (!settings.isSet(WebRecordingSettings.EXCLUDED_HEADERS)) { StringList list = new StringList(); list.add("Cookie"); list.add("Set-Cookie"); list.add("Referer"); list.add("Keep-Alive"); list.add("Connection"); list.add("Proxy-Connection"); list.add("Pragma"); list.add("Cache-Control"); list.add("Transfer-Encoding"); list.add("Date"); settings.setString(WebRecordingSettings.EXCLUDED_HEADERS, list.toXml()); } if (settings.getString(HttpSettings.HTTP_VERSION, HttpSettings.HTTP_VERSION_1_1) .equals(HttpSettings.HTTP_VERSION_0_9)) { settings.setString(HttpSettings.HTTP_VERSION, HttpSettings.HTTP_VERSION_1_1); } setIfNotSet(WsdlSettings.NAME_WITH_BINDING, true); setIfNotSet(WsdlSettings.NAME_WITH_BINDING, 500); setIfNotSet(HttpSettings.HTTP_VERSION, HttpSettings.HTTP_VERSION_1_1); setIfNotSet(HttpSettings.MAX_TOTAL_CONNECTIONS, 2000); setIfNotSet(HttpSettings.RESPONSE_COMPRESSION, true); setIfNotSet(HttpSettings.LEAVE_MOCKENGINE, true); setIfNotSet(UISettings.AUTO_SAVE_PROJECTS_ON_EXIT, true); setIfNotSet(UISettings.SHOW_DESCRIPTIONS, true); setIfNotSet(WsdlSettings.XML_GENERATION_ALWAYS_INCLUDE_OPTIONAL_ELEMENTS, true); setIfNotSet(WsaSettings.USE_DEFAULT_RELATES_TO, true); setIfNotSet(WsaSettings.USE_DEFAULT_RELATIONSHIP_TYPE, true); setIfNotSet(UISettings.SHOW_STARTUP_PAGE, true); setIfNotSet(UISettings.GC_INTERVAL, "60"); setIfNotSet(WsdlSettings.CACHE_WSDLS, true); setIfNotSet(WsdlSettings.PRETTY_PRINT_RESPONSE_MESSAGES, true); setIfNotSet(HttpSettings.RESPONSE_COMPRESSION, true); setIfNotSet(HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN, true); setIfNotSet(HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN, true); setIfNotSet(HttpSettings.LEAVE_MOCKENGINE, true); setIfNotSet(UISettings.AUTO_SAVE_INTERVAL, "0"); setIfNotSet(UISettings.GC_INTERVAL, "60"); setIfNotSet(UISettings.SHOW_STARTUP_PAGE, true); setIfNotSet(WsaSettings.SOAP_ACTION_OVERRIDES_WSA_ACTION, false); setIfNotSet(WsaSettings.USE_DEFAULT_RELATIONSHIP_TYPE, true); setIfNotSet(WsaSettings.USE_DEFAULT_RELATES_TO, true); setIfNotSet(WsaSettings.OVERRIDE_EXISTING_HEADERS, false); setIfNotSet(WsaSettings.ENABLE_FOR_OPTIONAL, false); setIfNotSet(VersionUpdateSettings.AUTO_CHECK_VERSION_UPDATE, true); boolean setWsiDir = false; String wsiLocationString = settings.getString(WSISettings.WSI_LOCATION, null); if (StringUtils.isNullOrEmpty(wsiLocationString)) { setWsiDir = true; } else { File wsiFile = new File(wsiLocationString); if (!wsiFile.exists()) { setWsiDir = true; } } if (setWsiDir) { String wsiDir = System.getProperty("wsi.dir", new File(".").getAbsolutePath()); settings.setString(WSISettings.WSI_LOCATION, wsiDir); } HttpClientSupport.addSSLListener(settings); return settings; }
From source file:com.eviware.soapui.impl.wsdl.WsdlProject.java
/** * Decode encrypted data and restore user/pass * //from w w w . j a v a2s. com * @param soapuiProject * @return 0 - not encrypted, 1 - successfull decryption , -1 error while * decrypting, bad password, no password. * @throws IOException * @throws GeneralSecurityException * @author robert nemet */ protected int checkForEncodedData(ProjectConfig soapuiProject) throws IOException, GeneralSecurityException { byte[] encryptedContent = soapuiProject.getEncryptedContent(); char[] password = null; // no encrypted data then go back if (encryptedContent == null || encryptedContent.length == 0) return 0; String projectPassword = null; if (workspace != null) { projectPassword = workspace.getProjectPassword(soapuiProject.getName()); } else { projectPassword = this.projectPassword; } if (projectPassword == null) { password = UISupport.promptPassword("Enter Password:", soapuiProject.getName()); } else { password = projectPassword.toCharArray(); } byte[] data = null; // no pass go back. if (password == null) { return -1; } try { data = OpenSSL.decrypt("des3", password, encryptedContent); } catch (Exception e) { SoapUI.logError(e); return -1; } String decryptedData = new String(data, "UTF-8"); if (decryptedData != null) { if (decryptedData.length() > 0) { try { // projectDocument.getSoapuiProject().set( // XmlObject.Factory.parse( decryptedData ) ); projectDocument.getSoapuiProject().set(XmlUtils.createXmlObject(decryptedData)); wrongPasswordSupplied = false; } catch (XmlException e) { UISupport.showErrorMessage("Wrong password. Project needs to be reloaded."); wrongPasswordSupplied = true; getWorkspace().clearProjectPassword(soapuiProject.getName()); return -1; } } } else { UISupport.showErrorMessage("Wrong project password"); wrongPasswordSupplied = true; getWorkspace().clearProjectPassword(soapuiProject.getName()); return -1; } projectDocument.getSoapuiProject().setEncryptedContent(null); return 1; }