List of usage examples for java.security KeyManagementException getMessage
public String getMessage()
From source file:com.telesign.util.TeleSignRequest.java
/** * Set the TLS protocol to TLSv1.2/*from w w w. j av a2 s. c o m*/ */ private void setTLSProtocol() { SSLContext sslContext; try { // setting ssl instance to TLSv1.x sslContext = SSLContext.getInstance(httpsProtocol); // sslContext initialize sslContext.init(null, null, new SecureRandom()); // typecasting ssl with HttpsUrlConnection and setting sslcontext ((HttpsURLConnection) connection).setSSLSocketFactory(sslContext.getSocketFactory()); } catch (NoSuchAlgorithmException e1) { System.err.println("Received No Such Alogorithm Exception " + e1.getMessage()); } catch (KeyManagementException e) { System.err.println("Key Management Exception received " + e.getMessage()); } }
From source file:com.flexvdi.androidlauncher.LoginActivity.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); mContext = this; try {//from w ww. ja va 2 s.c o m GStreamer.init(mContext); } catch (Exception e) { Log.e(TAG, "Can't initialize GStreamer" + e.getMessage()); finish(); } settings = getSharedPreferences("flexVDI", MODE_PRIVATE); settingsEditor = settings.edit(); /* Uncomment this for clearing preferences (useful when debugging) */ //settingsEditor.clear(); //settingsEditor.apply(); //settingsEditor.commit(); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.activity_login); textUser = (EditText) findViewById(R.id.textUser); textServer = (EditText) findViewById(R.id.textServer); textPassword = (EditText) findViewById(R.id.textPassword); goButton = (Button) findViewById(R.id.buttonGO); goButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ConnectivityManager cm = (ConnectivityManager) mContext .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); if (!isConnected) { Toast.makeText(view.getContext(), getResources().getString(R.string.no_network), Toast.LENGTH_LONG).show(); return; } if (checkBoxGenericSpice.isChecked()) { String userField = textUser.getText().toString(); if (userField.length() == 0 || !userField.contains(":")) { Toast.makeText(view.getContext(), getResources().getString(R.string.invalid_spice_server), Toast.LENGTH_LONG).show(); return; } String spiceAddress = userField.substring(0, userField.indexOf(":")); String spicePort = userField.substring(userField.indexOf(":") + 1); if (spiceAddress.length() == 0 || spicePort.length() == 0) { Toast.makeText(view.getContext(), getResources().getString(R.string.invalid_spice_server), Toast.LENGTH_LONG).show(); return; } String spicePassword = textPassword.getText().toString(); settingsEditor.putBoolean("enableSound", checkBoxEnableSound.isChecked()); settingsEditor.putBoolean("staticResolution", checkBoxStaticResolution.isChecked()); settingsEditor.putBoolean("genericSpice", checkBoxGenericSpice.isChecked()); settingsEditor.putString("flexServerName", textServer.getText().toString()); settingsEditor.putString("spice_address", spiceAddress); settingsEditor.putString("spice_port", spicePort); settingsEditor.putString("spice_password", spicePassword); settingsEditor.putBoolean("use_ws", false); settingsEditor.apply(); settingsEditor.commit(); startMainActivity(); } else { if (textServer.getText().length() == 0) { Toast.makeText(view.getContext(), getResources().getString(R.string.empty_flexvdi_server), Toast.LENGTH_LONG).show(); } else { if (textUser.getText().length() != 0 && textPassword.getText().length() != 0) { new RequestTask().execute("authmode", textServer.getText().toString(), textUser.getText().toString(), textPassword.getText().toString(), ""); } else Toast.makeText(view.getContext(), getResources().getString(R.string.empty_credentials), Toast.LENGTH_LONG).show(); } } } }); // The advanced settings button. checkBoxAdvancedOptions = (CheckBox) findViewById(R.id.checkBoxAdvancedSettings); layoutAdvancedOptions = (LinearLayout) findViewById(R.id.layoutAdvancedOptions2); checkBoxAdvancedOptions.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton arg0, boolean checked) { if (checked) layoutAdvancedOptions.setVisibility(View.VISIBLE); else layoutAdvancedOptions.setVisibility(View.GONE); } }); textServer.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View field, boolean hasFocus) { if (!hasFocus && checkBoxGenericSpice.isChecked()) { if (textUser.getText().toString().length() == 0) { textUser.setText(textServer.getText()); } } } }); checkBoxEnableSound = (CheckBox) findViewById(R.id.checkBoxEnableSound); if (settings.getBoolean("enableSound", true)) { checkBoxEnableSound.setChecked(true); } else { checkBoxEnableSound.setChecked(false); } if (!settings.contains("staticResolution")) { Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); if ((size.x + size.y) > 2340) { /* 2340 = 1440+900 */ settingsEditor.putBoolean("staticResolution", true); } else { settingsEditor.putBoolean("staticResolution", false); } settingsEditor.apply(); settingsEditor.commit(); } checkBoxStaticResolution = (CheckBox) findViewById(R.id.checkBoxStaticResolution); if (settings.getBoolean("staticResolution", true)) { checkBoxStaticResolution.setChecked(true); } else { checkBoxStaticResolution.setChecked(false); } checkBoxGenericSpice = (CheckBox) findViewById(R.id.checkBoxGenericSpice); if (settings.getBoolean("genericSpice", false)) { checkBoxGenericSpice.setChecked(true); checkBoxAdvancedOptions.setChecked(true); layoutAdvancedOptions.setVisibility(View.VISIBLE); if (settings.contains("flexServerName")) { textServer.setText(settings.getString("flexServerName", "")); textUser.setText(settings.getString("flexServerName", "")); textServer.setHint(getResources().getString(R.string.spice_server)); textUser.setHint(getResources().getString(R.string.spice_server_port)); } } else { checkBoxGenericSpice.setChecked(false); if (settings.contains("flexServerName")) { textServer.setText(settings.getString("flexServerName", "")); layoutAdvancedOptions.setVisibility(View.GONE); } else { textServer.setText("manager.flexvdi.com"); checkBoxAdvancedOptions.setChecked(true); } } checkBoxGenericSpice.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton arg0, boolean checked) { if (checked) { textServer.setHint(getResources().getString(R.string.spice_server)); textUser.setHint(getResources().getString(R.string.spice_server_port)); String server = textServer.getText().toString(); if (server.length() != 0) { if (server.contains(":")) { textUser.setText(server); } else { textUser.setText(server + ":5900"); textServer.setText(server + ":5900"); } } } else { textServer.setHint(getResources().getString(R.string.flexvdi_server)); String server = textServer.getText().toString(); if (server.length() != 0 && server.contains(":")) { textServer.setText(server.substring(0, server.indexOf(":"))); } textUser.setText(""); textUser.setHint(getResources().getString(R.string.user)); } } }); deviceID = Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.ANDROID_ID); textViewDeviceID = (TextView) findViewById(R.id.textViewDeviceID); textViewDeviceID.setText("ID: " + deviceID + " (" + BuildConfig.VERSION_NAME + ")"); try { HttpsURLConnection.setDefaultHostnameVerifier(new NullHostNameVerifier()); SSLContext context = SSLContext.getInstance("TLS"); context.init(null, new X509TrustManager[] { new NullX509TrustManager() }, new SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory()); } catch (NoSuchAlgorithmException nsae) { Log.e(TAG, nsae.getMessage()); } catch (KeyManagementException kme) { Log.e(TAG, kme.getMessage()); } }
From source file:com.cloud.hypervisor.hyperv.resource.HypervDirectConnectResource.java
public static String postHttpRequest(final String jsonCmd, final URI agentUri) { // Using Apache's HttpClient for HTTP POST // Java-only approach discussed at on StackOverflow concludes with // comment to use Apache HttpClient // http://stackoverflow.com/a/2793153/939250, but final comment is to // use Apache. String logMessage = StringEscapeUtils.unescapeJava(jsonCmd); logMessage = cleanPassword(logMessage); s_logger.debug("POST request to " + agentUri.toString() + " with contents " + logMessage); // Create request HttpClient httpClient = null;//from w w w . ja va2s.co m final TrustStrategy easyStrategy = new TrustStrategy() { @Override public boolean isTrusted(final X509Certificate[] chain, final String authType) throws CertificateException { return true; } }; try { final SSLSocketFactory sf = new SSLSocketFactory(easyStrategy, new AllowAllHostnameVerifier()); final SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("https", DEFAULT_AGENT_PORT, sf)); final ClientConnectionManager ccm = new BasicClientConnectionManager(registry); httpClient = new DefaultHttpClient(ccm); } catch (final KeyManagementException e) { s_logger.error("failed to initialize http client " + e.getMessage()); } catch (final UnrecoverableKeyException e) { s_logger.error("failed to initialize http client " + e.getMessage()); } catch (final NoSuchAlgorithmException e) { s_logger.error("failed to initialize http client " + e.getMessage()); } catch (final KeyStoreException e) { s_logger.error("failed to initialize http client " + e.getMessage()); } String result = null; // TODO: are there timeout settings and worker thread settings to tweak? try { final HttpPost request = new HttpPost(agentUri); // JSON encode command // Assumes command sits comfortably in a string, i.e. not used for // large data transfers final StringEntity cmdJson = new StringEntity(jsonCmd); request.addHeader("content-type", "application/json"); request.setEntity(cmdJson); s_logger.debug("Sending cmd to " + agentUri.toString() + " cmd data:" + logMessage); final HttpResponse response = httpClient.execute(request); // Unsupported commands will not route. if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) { final String errMsg = "Failed to send : HTTP error code : " + response.getStatusLine().getStatusCode(); s_logger.error(errMsg); final String unsupportMsg = "Unsupported command " + agentUri.getPath() + ". Are you sure you got the right type of" + " server?"; final Answer ans = new UnsupportedAnswer(null, unsupportMsg); s_logger.error(ans); result = s_gson.toJson(new Answer[] { ans }); } else if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { final String errMsg = "Failed send to " + agentUri.toString() + " : HTTP error code : " + response.getStatusLine().getStatusCode(); s_logger.error(errMsg); return null; } else { result = EntityUtils.toString(response.getEntity()); final String logResult = cleanPassword(StringEscapeUtils.unescapeJava(result)); s_logger.debug("POST response is " + logResult); } } catch (final ClientProtocolException protocolEx) { // Problem with HTTP message exchange s_logger.error(protocolEx); } catch (final IOException connEx) { // Problem with underlying communications s_logger.error(connEx); } finally { httpClient.getConnectionManager().shutdown(); } return result; }