List of usage examples for org.apache.commons.ssl OpenSSL encrypt
public static InputStream encrypt(String cipher, char[] pwd, InputStream data) throws IOException, GeneralSecurityException
From source file:com.eviware.soapui.DefaultSoapUICore.java
public String saveSettings() throws Exception { PropertyExpansionUtils.saveGlobalProperties(); SecurityScanUtil.saveGlobalSecuritySettings(); isSavingSettings = true;/*from w ww .j a va 2s. c om*/ try { if (settingsFile == null) settingsFile = getRoot() + File.separatorChar + DEFAULT_SETTINGS_FILE; // Save settings to root or user.home File file = new File(settingsFile); if (!file.canWrite()) { file = new File(new File(System.getProperty("user.home", ".")), DEFAULT_SETTINGS_FILE); } SoapuiSettingsDocumentConfig settingsDocument = (SoapuiSettingsDocumentConfig) this.settingsDocument .copy(); String password = settings.getString(SecuritySettings.SHADOW_PASSWORD, null); if (password != null && password.length() > 0) { try { byte[] data = settingsDocument.xmlText().getBytes(); byte[] encryptedData = OpenSSL.encrypt("des3", password.toCharArray(), data); settingsDocument.setSoapuiSettings(null); settingsDocument.getSoapuiSettings().setEncryptedContent(encryptedData); } catch (UnsupportedEncodingException e) { log.error("Encryption error", e); } catch (IOException e) { log.error("Encryption error", e); } catch (GeneralSecurityException e) { log.error("Encryption error", e); } } FileOutputStream out = new FileOutputStream(file); settingsDocument.save(out); out.flush(); out.close(); log.info("Settings saved to [" + file.getAbsolutePath() + "]"); lastSettingsLoad = file.lastModified(); return file.getAbsolutePath(); } finally { isSavingSettings = false; } }
From source file:com.eviware.soapui.impl.wsdl.WsdlProject.java
public boolean saveIn(File projectFile) throws IOException { long size = 0; beforeSave();/* www .ja v a2s . c om*/ // work with copy beacuse we do not want to change working project while // working with it // if user choose save project, save all etc. SoapuiProjectDocumentConfig projectDocument = (SoapuiProjectDocumentConfig) this.projectDocument.copy(); // check for caching if (!getSettings().getBoolean(WsdlSettings.CACHE_WSDLS)) { // no caching -> create copy and remove definition cachings removeDefinitionCaches(projectDocument); } // remove project root XmlBeansSettingsImpl tempSettings = new XmlBeansSettingsImpl(this, null, projectDocument.getSoapuiProject().getSettings()); tempSettings.clearSetting(ProjectSettings.PROJECT_ROOT); // check for encryption String passwordForEncryption = getSettings().getString(ProjectSettings.SHADOW_PASSWORD, null); // if it has encryptedContend that means it is not decrypted corectly( bad // password, etc ), so do not encrypt it again. if (projectDocument.getSoapuiProject().getEncryptedContent() == null) { if (passwordForEncryption != null) { if (passwordForEncryption.length() > 1) { // we have password so do encryption try { String data = getConfig().xmlText(); byte[] encrypted = OpenSSL.encrypt("des3", passwordForEncryption.toCharArray(), data.getBytes()); projectDocument.getSoapuiProject().setEncryptedContent(encrypted); projectDocument.getSoapuiProject().setInterfaceArray(null); projectDocument.getSoapuiProject().setTestSuiteArray(null); projectDocument.getSoapuiProject().setMockServiceArray(null); projectDocument.getSoapuiProject().unsetWssContainer(); projectDocument.getSoapuiProject().unsetSettings(); projectDocument.getSoapuiProject().unsetProperties(); } catch (GeneralSecurityException e) { UISupport.showErrorMessage("Encryption Error"); } } else { // no password no encryption. projectDocument.getSoapuiProject().setEncryptedContent(null); } } } // end of encryption. XmlOptions options = new XmlOptions(); if (SoapUI.getSettings().getBoolean(WsdlSettings.PRETTY_PRINT_PROJECT_FILES)) options.setSavePrettyPrint(); projectDocument.getSoapuiProject().setSoapuiVersion(SoapUI.SOAPUI_VERSION); try { File tempFile = File.createTempFile("project-temp-", ".xml", projectFile.getParentFile()); // save once to make sure it can be saved FileOutputStream tempOut = new FileOutputStream(tempFile); projectDocument.save(tempOut, options); tempOut.close(); if (getSettings().getBoolean(UISettings.LINEBREAK)) { normalizeLineBreak(projectFile, tempFile); } else { // now save it for real FileOutputStream projectOut = new FileOutputStream(projectFile); projectDocument.save(projectOut, options); projectOut.close(); // delete tempFile here so we have it as backup in case second save // fails if (!tempFile.delete()) { SoapUI.getErrorLog() .warn("Failed to delete temporary project file; " + tempFile.getAbsolutePath()); tempFile.deleteOnExit(); } } // delete tempFile here so we have it as backup in case second save fails if (!tempFile.delete()) { SoapUI.getErrorLog().warn("Failed to delete temporary project file; " + tempFile.getAbsolutePath()); tempFile.deleteOnExit(); } size = projectFile.length(); } catch (Throwable t) { SoapUI.logError(t); UISupport.showErrorMessage("Failed to save project [" + getName() + "]: " + t.toString()); return false; } lastModified = projectFile.lastModified(); log.info( "Saved project [" + getName() + "] to [" + projectFile.getAbsolutePath() + " - " + size + " bytes"); setProjectRoot(getPath()); return true; }