List of usage examples for java.security GeneralSecurityException printStackTrace
public void printStackTrace()
From source file:org.rhq.enterprise.server.plugins.rhnhosted.xmlrpc.RhnSSLTransport.java
@Override protected URLConnection newURLConnection(URL url) throws IOException { URLConnection c = super.newURLConnection(url); if (c instanceof HttpsURLConnection) { try {/*w w w .ja v a 2 s . co m*/ ((HttpsURLConnection) c).setSSLSocketFactory(RHNSSLSocketFactory.getSSLSocketFactory(sslCertPath)); } catch (GeneralSecurityException e) { e.printStackTrace(); log.error(e); throw new IOException(e.getMessage()); } log.debug("SSLSocketFactory has been set with a custom version using cert path: " + sslCertPath); } return c; }
From source file:pl.kotcrab.crypto.RSAEncrypter.java
/** Encrypts some data using RSA * @param data data to be encrypted/*from w w w . j a v a 2 s .co m*/ * @return encrypted data or null if exceptions occurred during encryption. Use {@link RSAEncrypter#encryptSafe(byte[])} if you * want to catch exceptions */ public byte[] encrypt(byte[] data) { try { return encrypter.doFinal(data); } catch (GeneralSecurityException e) { e.printStackTrace(); } return null; }
From source file:pl.kotcrab.crypto.RSAEncrypter.java
/** Constructs RSAEcnrypted from the key spec itself * @param publicKeySpec key spec */ public RSAEncrypter(X509EncodedKeySpec publicKeySpec) { try {/*ww w . j a va 2s . c o m*/ KeyFactory keyFactory = KeyFactory.getInstance("RSA", "BC"); publicKey = keyFactory.generatePublic(publicKeySpec); setupCiphers(); } catch (GeneralSecurityException e) { e.printStackTrace(); } }
From source file:org.jvnet.hudson.update_center.Signing.java
/** * Loads a certificate chain and makes sure it's valid. *///from w w w. j a v a 2 s. co m private List<X509Certificate> getCertificateChain() throws FileNotFoundException, GeneralSecurityException { CertificateFactory cf = CertificateFactory.getInstance("X509"); List<X509Certificate> certs = new ArrayList<X509Certificate>(); for (File f : certificates) { X509Certificate c = (X509Certificate) cf.generateCertificate(new FileInputStream(f)); c.checkValidity(); certs.add(c); } Set<TrustAnchor> rootCAs = CertificateUtil.getDefaultRootCAs(); rootCAs.add(new TrustAnchor( (X509Certificate) cf.generateCertificate(getClass().getResourceAsStream("/hudson-community.cert")), null)); try { CertificateUtil.validatePath(certs, rootCAs); } catch (GeneralSecurityException e) { e.printStackTrace(); } return certs; }
From source file:eu.siacs.conversations.ui.ServiceBrowserFragment.java
public static boolean exists(String URLName) { X509TrustManager trustManager = new X509TrustManager() { @Override/*from www .j a v a2 s .c o m*/ public X509Certificate[] getAcceptedIssuers() { return null; } @Override public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // NOTE : This is where we can calculate the certificate's fingerprint, // show it to the user and throw an exception in case he doesn't like it } @Override public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { } }; // Create a trust manager that does not validate certificate chains X509TrustManager[] trustAllCerts = new X509TrustManager[] { trustManager }; // Install the all-trusting trust manager SSLSocketFactory noSSLv3Factory = null; try { SSLContext sc = SSLContext.getInstance("TLS"); sc.init(null, trustAllCerts, new java.security.SecureRandom()); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { noSSLv3Factory = new TLSSocketFactory(trustAllCerts, new SecureRandom()); } else { noSSLv3Factory = sc.getSocketFactory(); } HttpsURLConnection.setDefaultSSLSocketFactory(noSSLv3Factory); } catch (GeneralSecurityException e) { } try { HttpsURLConnection.setFollowRedirects(false); // note : you may also need // HttpURLConnection.setInstanceFollowRedirects(false) URL url = new URL(URLName); HttpsURLConnection con = (HttpsURLConnection) url.openConnection(); con.setSSLSocketFactory(noSSLv3Factory); con.setRequestProperty("Accept-Encoding", ""); //HttpsURLConnection.setDefaultHostnameVerifier(new NullHostNameVerifier()); con.setHostnameVerifier(new NullHostNameVerifier(url.getHost())); con.setRequestMethod("HEAD"); return (con.getResponseCode() == HttpsURLConnection.HTTP_OK); } catch (Exception e) { e.printStackTrace(); return false; } }
From source file:org.jasig.cas.adaptors.x509.authentication.handler.support.AbstractCRLRevocationCheckerTests.java
/** * Test method for {@link AbstractCRLRevocationChecker#check(X509Certificate)}. *//* w ww. j a va2 s . c o m*/ @Test public void testCheck() { try { for (X509Certificate cert : this.certificates) { getChecker().check(cert); } if (this.expected != null) { Assert.fail("Expected exception of type " + this.expected.getClass()); } } catch (final GeneralSecurityException e) { if (this.expected == null) { e.printStackTrace(); Assert.fail("Revocation check failed unexpectedly with exception: " + e); } else { final Class<?> expectedClass = this.expected.getClass(); final Class<?> actualClass = e.getClass(); Assert.assertTrue( String.format("Expected exception of type %s but got %s", expectedClass, actualClass), expectedClass.isAssignableFrom(actualClass)); } } }
From source file:com.ikon.servlet.ValidateLicenseServlet.java
@Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { logger.info("Validating License"); LicenseManager licenseManager = null; HttpSession httpSession = request.getSession(); /*if(LICENSE_PATH.isFile()){ if(remainingDays()>0){// www . j a va 2 s . co m request.setAttribute("DAYS_LEFT", "Trial Days Left : " + remainingDays()); request.getRequestDispatcher("./login.jsp").forward(request, response); } else { LICENSE_PATH.delete(); } }*/ try { if (licenseManager == null) { licenseManager = LicenseManager.getInstance(); } if (licenseManager.isValid()) { //checks for unauthorized license modifications if (licenseManager.getFeature("MAC Address").equals(getMacAddress()) || licenseManager.getFeature("MAC Address").equals(SKIP_MACID_CHECK)) { if (licenseManager.daysLeft() > 0) { HttpSessionManager.getInstance().add(request); List<HttpSessionInfo> httpSessionInfos = HttpSessionManager.getInstance().getSessions(); logger.info("Number of users online : " + httpSessionInfos.size()); if (httpSessionInfos.size() > Integer .parseInt(licenseManager.getFeature("Number of Users"))) { logger.info("Max users Logged in"); httpSession.invalidate(); throw new LicenseException("Max users have logged in. Please wait."); } else { httpSession.setAttribute("DAYS_LEFT", "Days Left : " + String.valueOf(licenseManager.daysLeft())); request.getRequestDispatcher("./index.jsp").forward(request, response); } } else { logger.info("License is expired"); throw new LicenseException("License is expired."); } } else { logger.info("Mac Id mismatch"); throw new LicenseException("MacId of the server seems to be changed."); } } else { logger.info("License had been modified"); throw new LicenseException("License could not be read/expired."); } } catch (LicenseException exception) { request.setAttribute("ERROR", exception.getMessage()); request.setAttribute("SUPPORT", "Please contact support@writercorporation.com"); request.getRequestDispatcher("./info.jsp").forward(request, response); } catch (RuntimeException exception) { request.setAttribute("ERROR", "License could not be found"); request.setAttribute("SUPPORT", "Please contact support@writercorporation.com"); request.getRequestDispatcher("./info.jsp").forward(request, response); } catch (GeneralSecurityException e) { e.printStackTrace(); } }
From source file:org.fedoraproject.eclipse.packager.FedoraSSL.java
/** * Determine FAS username from fedora cert file. * //from www . j a v a 2 s .c o m * @return Username if retrieval is successful. * {@link FedoraSSL#UNKNOWN_USER} otherwise. */ public String getUsernameFromCert() { if (fedoraCert.exists()) { KeyMaterial kmat; try { kmat = new KeyMaterial(fedoraCert, fedoraCert, new char[0]); List<?> chains = kmat.getAssociatedCertificateChains(); Iterator<?> it = chains.iterator(); ArrayList<String> cns = new ArrayList<String>(); while (it.hasNext()) { X509Certificate[] certs = (X509Certificate[]) it.next(); if (certs != null) { for (int i = 0; i < certs.length; i++) { cns.add(Certificates.getCN(certs[i])); } } } return cns.get(0); } catch (GeneralSecurityException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } return UNKNOWN_USER; }
From source file:org.mitre.jwt.signer.service.impl.KeyStoreTest.java
@Test public void storeRsaKeyPair() throws GeneralSecurityException, IOException { java.security.KeyStore ks = null; try {//from w ww .java2s . c o m ks = KeyStoreTest.generateKeyPair(keystore, RsaSigner.KEYPAIR_ALGORITHM, 2048, "SHA256WithRSAEncryption", "OpenID Connect Server", "rsa", RsaSigner.DEFAULT_PASSWORD, 30, 365); } catch (GeneralSecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } assertThat(ks, not(nullValue())); }