List of usage examples for java.security GeneralSecurityException getMessage
public String getMessage()
From source file:de.thingweb.client.security.Security4NicePlugfest.java
public Security4NicePlugfest() { // Install the all-trusting trust manager // TODO setup trust-manager properly (not meant for production) try {//from www.j a v a2 s . c om SSLContext sc = SSLContext.getInstance("SSL"); TrustManager[] trustAllCerts = new TrustManager[] { new AllTrustingX509TrustManager() }; sc.init(null, trustAllCerts, new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } catch (GeneralSecurityException e) { log.error(e.getMessage()); } }
From source file:de.j4velin.encrypter.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, final Intent data) { if (requestCode == REQUEST_INPUT && resultCode == RESULT_OK && data != null) { Uri uri = data.getData();/*from w w w . jav a2s.c om*/ String inputName = null; int inputSize = -1; String inputType = getContentResolver().getType(uri); try (Cursor cursor = getContentResolver().query(uri, null, null, null, null, null)) { if (cursor != null && cursor.moveToFirst()) { inputName = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); int sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE); if (!cursor.isNull(sizeIndex)) { inputSize = cursor.getInt(sizeIndex); } } } File input = new File(-1, inputName, inputType, uri, inputSize, false); try { CryptoUtil.encrypt(MainActivity.this, input); } catch (GeneralSecurityException e) { Snackbar.make(coordinatorLayout, getString(R.string.error_security, e.getMessage()), Snackbar.LENGTH_LONG).show(); } catch (FileNotFoundException e) { Snackbar.make(coordinatorLayout, R.string.error_file_not_found, Snackbar.LENGTH_LONG).show(); } catch (IOException e) { Snackbar.make(coordinatorLayout, getString(R.string.error_io, e.getMessage()), Snackbar.LENGTH_LONG) .show(); } } else { super.onActivityResult(requestCode, resultCode, data); } }
From source file:mx.openpay.client.core.impl.DefaultHttpServiceClient.java
protected CloseableHttpClient initHttpClient(final boolean requirePoolManager, final int connectionTimeout, final int socketTimeout) { CloseableHttpClient httpClient;/* www. j a v a2 s .c o m*/ HttpClientConnectionManager manager; SSLConnectionSocketFactory sslSocketFactory; SSLContext tlsContext; try { try { tlsContext = new SSLContextBuilder().useProtocol("TLSv1.2").build(); } catch (GeneralSecurityException e) { log.warn("Could not force protocol TLSv1.2: {}", e.getMessage()); tlsContext = new SSLContextBuilder().build(); } sslSocketFactory = new SSLConnectionSocketFactory(tlsContext); } catch (Exception e) { throw new RuntimeException(e); } if (requirePoolManager) { manager = new PoolingHttpClientConnectionManager( RegistryBuilder.<ConnectionSocketFactory>create().register("https", sslSocketFactory).build()); } else { manager = new BasicHttpClientConnectionManager( RegistryBuilder.<ConnectionSocketFactory>create().register("https", sslSocketFactory).build()); } this.requestConfig = RequestConfig.custom().setConnectTimeout(connectionTimeout) .setSocketTimeout(socketTimeout).build(); ConnectionConfig connnectionConfig = ConnectionConfig.custom().setCharset(Charset.forName("UTF-8")).build(); httpClient = HttpClientBuilder.create().setConnectionManager(manager) .setDefaultConnectionConfig(connnectionConfig).setDefaultRequestConfig(this.requestConfig).build(); return httpClient; }
From source file:fr.cls.atoll.motu.library.misc.vfs.provider.gsiftp.ProxyTool.java
/** * Sign./*w ww . j av a 2s .co m*/ */ private void sign() { try { BouncyCastleCertProcessingFactory factory = BouncyCastleCertProcessingFactory.getDefault(); X509ExtensionSet extSet = null; // if (proxyCertInfo != null) { // extSet = new X509ExtensionSet(); // if (CertUtil.isGsi4Proxy(proxyType)) { // // RFC compliant OID // extSet.add(new ProxyCertInfoExtension(proxyCertInfo)); // } else { // // old OID // extSet.add(new GlobusProxyCertInfoExtension(proxyCertInfo)); // } // } proxy = factory.createCredential(certificates, userKey, bits, lifetime, proxyType, extSet); } catch (GeneralSecurityException e) { System.err.println("Failed to create a proxy: " + e.getMessage()); } }
From source file:org.dcache.srm.client.FlexibleCredentialSSLConnectionSocketFactory.java
@Override public Socket createLayeredSocket(final Socket socket, final String target, final int port, final HttpContext context) throws IOException { final X509Credential credential = (X509Credential) context .getAttribute(HttpClientTransport.TRANSPORT_HTTP_CREDENTIALS); if (credential == null) { throw new IOException("Client credentials are missing from context."); }/*from www .ja v a2 s.co m*/ final SSLContext sslContext; try { sslContext = contextProvider.getContext(credential); } catch (GeneralSecurityException e) { throw new IOException("Failed to create SSLContext: " + e.getMessage(), e); } final SSLSocket sslsock = (SSLSocket) sslContext.getSocketFactory().createSocket(socket, target, port, true); if (supportedProtocols != null) { sslsock.setEnabledProtocols(supportedProtocols); } else { // If supported protocols are not explicitly set, remove all SSL protocol versions final String[] allProtocols = sslsock.getEnabledProtocols(); final List<String> enabledProtocols = new ArrayList<String>(allProtocols.length); for (String protocol : allProtocols) { if (!protocol.startsWith("SSL")) { enabledProtocols.add(protocol); } } if (!enabledProtocols.isEmpty()) { sslsock.setEnabledProtocols(enabledProtocols.toArray(new String[enabledProtocols.size()])); } } if (supportedCipherSuites != null) { sslsock.setEnabledCipherSuites(supportedCipherSuites); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Enabled protocols: {}", Arrays.asList(sslsock.getEnabledProtocols())); LOGGER.debug("Enabled cipher suites: {}", Arrays.asList(sslsock.getEnabledCipherSuites())); } prepareSocket(sslsock); LOGGER.debug("Starting handshake"); sslsock.startHandshake(); verifyHostname(sslsock, target); return sslsock; }
From source file:com.streamsets.pipeline.lib.remote.FTPRemoteConnector.java
private void setFtpsUserKeyManagerOrTrustManager(String file, String fileConfigName, CredentialValue password, String passwordConfigName, KeyStoreType keyStoreType, boolean isKeystore, // or truststore List<Stage.ConfigIssue> issues, ConfigIssueContext context, Label group) { if (file != null && !file.isEmpty()) { File keystoreFile = new File(file); String keystorePassword = resolveCredential(password, passwordConfigName, issues, context, group); try {//from w w w .ja v a 2 s .c o m KeyStore keystore = loadKeystore(keystoreFile, keyStoreType.getJavaValue(), keystorePassword); try { if (isKeystore) { FtpsFileSystemConfigBuilder.getInstance().setKeyManager(options, KeyManagerUtils.createClientKeyManager(keystore, null, keystorePassword)); } else { FtpsFileSystemConfigBuilder.getInstance().setTrustManager(options, TrustManagerUtils.getDefaultTrustManager(keystore)); } } catch (GeneralSecurityException e) { issues.add(context.createConfigIssue(group.getLabel(), fileConfigName, Errors.REMOTE_15, isKeystore ? "key" : "trust", e.getMessage(), e)); } } catch (IOException | GeneralSecurityException e) { issues.add(context.createConfigIssue(group.getLabel(), fileConfigName, Errors.REMOTE_14, isKeystore ? "key" : "trust", keystoreFile.getAbsolutePath(), e.getMessage(), e)); } } else { if (isKeystore) { issues.add(context.createConfigIssue(group.getLabel(), fileConfigName, Errors.REMOTE_12)); } else { issues.add(context.createConfigIssue(group.getLabel(), fileConfigName, Errors.REMOTE_13)); } } }
From source file:org.apache.nifi.toolkit.tls.util.TlsHelperTest.java
@Test public void testWriteKeyStoreNoTruncate() throws IOException, GeneralSecurityException { setUnlimitedCrypto(false);//from w w w. j a v a 2s . c o m String testPassword = "testPassword"; IOException ioException = new IOException(TlsHelper.ILLEGAL_KEY_SIZE); doThrow(ioException).when(keyStoreSpi).engineStore(eq(tmpFileOutputStream), AdditionalMatchers.aryEq(testPassword.toCharArray())); try { TlsHelper.writeKeyStore(keyStore, outputStreamFactory, file, testPassword, false); fail("Expected " + GeneralSecurityException.class); } catch (GeneralSecurityException e) { assertTrue("Expected exception to contain " + TlsHelper.JCE_URL, e.getMessage().contains(TlsHelper.JCE_URL)); } }
From source file:org.soapwsj.SoapClient.java
private void configureTls() { SSLSocketFactory factory;//from w ww. j a va2s . c o m int port; try { if (endpointTlsEnabled && proxyTlsEnabled) { factory = SSLUtils.getMergedSocketFactory(endpointProperties, proxyProperties); registerTlsScheme(factory, proxyUri.getPort()); } else if (endpointTlsEnabled) { factory = SSLUtils.getFactory(endpointProperties); port = endpointUri.getPort(); registerTlsScheme(factory, port); } else if (proxyTlsEnabled) { factory = SSLUtils.getFactory(proxyProperties); port = proxyUri.getPort(); registerTlsScheme(factory, port); } } catch (GeneralSecurityException ex) { throw new SoapException(ex.getMessage(), ex); } }
From source file:com.clearcenter.mobile_demo.mdAuthenticatorActivity.java
public void onCreate(Bundle bundle) { Log.i(TAG, "onCreate(" + bundle + ")"); super.onCreate(bundle); setContentView(R.layout.login_activity); account_manager = AccountManager.get(this); Log.i(TAG, "loading data from Intent"); final Intent intent = getIntent(); nickname = intent.getStringExtra(PARAM_NICKNAME); username = intent.getStringExtra(PARAM_USERNAME); hostname = intent.getStringExtra(PARAM_HOSTNAME); request_new_account = nickname == null; confirm_credentials = intent.getBooleanExtra(PARAM_CONFIRM_CREDENTIALS, false); Log.i(TAG, "new account? " + request_new_account + ", confirm credentials? " + confirm_credentials); scroll_view = (ScrollView) findViewById(R.id.scroll_view); message = (TextView) findViewById(R.id.message); nickname_label = (TextView) findViewById(R.id.nickname_label); nickname_edit = (EditText) findViewById(R.id.nickname_edit); nickname_label.setVisibility(request_new_account ? View.VISIBLE : View.GONE); nickname_edit.setVisibility(request_new_account ? View.VISIBLE : View.GONE); if (nickname != null) nickname_edit.setText(nickname); hostname_label = (TextView) findViewById(R.id.hostname_label); hostname_edit = (EditText) findViewById(R.id.hostname_edit); hostname_label.setVisibility(request_new_account ? View.VISIBLE : View.GONE); hostname_edit.setVisibility(request_new_account ? View.VISIBLE : View.GONE); if (hostname != null) hostname_edit.setText(hostname); username_label = (TextView) findViewById(R.id.username_label); username_edit = (EditText) findViewById(R.id.username_edit); username_label.setVisibility(request_new_account ? View.VISIBLE : View.GONE); username_edit.setVisibility(request_new_account ? View.VISIBLE : View.GONE); if (username != null) username_edit.setText(username); password_edit = (EditText) findViewById(R.id.password_edit); if (confirm_credentials) { String ns = Context.NOTIFICATION_SERVICE; NotificationManager notification_manager; notification_manager = (NotificationManager) getApplicationContext().getSystemService(ns); notification_manager.cancelAll(); Log.i(TAG, "TODO: Cancel all notifications?"); }/* w w w . ja v a 2s . c o m*/ if (!TextUtils.isEmpty(nickname)) nickname_edit.setText(nickname); if (request_new_account) message.setText(getText(R.string.login_activity_new_account)); else if (confirm_credentials) { message.setText(getText(R.string.login_activity_confirm_credentials)); } try { mdSSLUtil.DisableSecurity(); } catch (GeneralSecurityException e) { Toast.makeText(getApplicationContext(), e.getMessage(), 4).show(); } }
From source file:com.grendelscan.ui.MainWindow.java
public void regenerateCA() { try {//from w ww . ja v a2 s .c o m CertificateAuthority.regenerateCA(); } catch (GeneralSecurityException e1) { displayMessage("Error", "There was a problem regenerating the CA certificate: " + e1.getMessage(), true); } }