Example usage for java.security GeneralSecurityException printStackTrace

List of usage examples for java.security GeneralSecurityException printStackTrace

Introduction

In this page you can find the example usage for java.security GeneralSecurityException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.mario22gmail.license.nfc_project.NavigationDrawerActivity.java

public void WriteCredentialsOnTagButtonClick(View view) {
    EditText userNameTextBox = (EditText) findViewById(R.id.fragmentAddUserNameTextBox);
    String userName = userNameTextBox.getText().toString();
    Log.i(nfcDebugTag, userName);/*from w  ww. j a  v  a 2  s  .co m*/

    EditText passTextBox = (EditText) findViewById(R.id.fragmentAddWebPasswordTextBox);
    String pass = passTextBox.getText().toString();
    Log.i(nfcDebugTag, pass);

    EditText urlTextBox = (EditText) findViewById(R.id.fragmentAddWebUrlTextBox);
    String url = urlTextBox.getText().toString();
    Log.i(nfcDebugTag, url);

    if (!userName.equals("") && !pass.equals("") && !url.equals("")) {
        if (card != null) {
            try {
                //                    card.authenticate(DESFireEV1.AuthType.Native, 2, (byte) 0, 0,
                //                            (byte) 0, null);
                //                    Log.i(nfcDebugTag, "Applicatie authentificata");
                //                    card.selectApplication(0);
                //                    Log.i(nfcDebugTag, "Applicatia 0 selectata");
                //                    DesFireCreateApplication(card, 11);
                WebsitesCredentials credentials = new WebsitesCredentials();
                credentials.setUrl(url);
                credentials.setUserName(userName);
                credentials.setPassword(pass);
                WriteCredentials(credentials);
                Snackbar.make(view, "Tag Writen", Snackbar.LENGTH_LONG).setAction("Action", null).show();
                Log.i(nfcDebugTag, "fisier scris");
                UpdatePageWithCredentials();

                //                    String textCard = "https://www.facebook.com" + "@@@" + userName + "@@@" + pass;
                //                    byte[] textBytes = textCard.getBytes();
                //
                //                    card.createFile(1, new DESFireFile.StdDataFileSettings(
                //                            DESFireEV1.CommunicationType.Plain, 0, 0, 0, 0, textBytes.length));
                //                    Log.i(nfcDebugTag, "fisier creat");
                //
                //                    // write data to file nr 1
                //                    card.authenticate(DESFireEV1.AuthType.Native, 2, (byte) 0, 0,
                //                            (byte) 0, null);
                //                    Log.i(nfcDebugTag, "Applicatie authentificata");
                //                    card.writeData(1, 0, textBytes);

            } catch (GeneralSecurityException e) {
                e.printStackTrace();
                Log.i(nfcDebugTag, "Create app security error" + e.getMessage());

            } catch (IOException e) {
                e.printStackTrace();
                Log.i(nfcDebugTag, "Create app io error" + e.getMessage());

            } catch (SmartCardException e) {
                e.printStackTrace();
                Log.i(nfcDebugTag, "Create app smart card error" + e.getMessage());

            }

        } else {
            Snackbar.make(view, "Tag not found", Snackbar.LENGTH_LONG).setAction("Action", null).show();
        }

    } else {
        Snackbar.make(view, "Campurile nu pot fi goale", Snackbar.LENGTH_LONG).setAction("Action", null).show();
    }

}

From source file:gov.nih.nci.cadsr.cadsrpasswordchange.core.MainServlet.java

private void saveUserStoredQna(String username, Map<String, String> userQuestions,
        Map<String, String> userAnswers) throws Exception {
    UserSecurityQuestion qna = new UserSecurityQuestion();
    logger.debug("entering saveUserStoredQna ...");
    try {/*from  www  .ja  va  2  s  .com*/
        qna.setUaName(username);
        qna.setQuestion1((String) userQuestions.get(Constants.Q1));
        qna.setAnswer1(CommonUtil.encode((String) userAnswers.get(Constants.A1)));
        qna.setQuestion2((String) userQuestions.get(Constants.Q2));
        qna.setAnswer2(CommonUtil.encode((String) userAnswers.get(Constants.A2)));
        qna.setQuestion3((String) userQuestions.get(Constants.Q3));
        qna.setAnswer3(CommonUtil.encode((String) userAnswers.get(Constants.A3)));
        logger.info("saveUserStoredQna:qna object saved ...");
    } catch (GeneralSecurityException e1) {
        e1.printStackTrace();
    }

    try {
        logger.debug("saveUserStoredQna:connecting to the db ...");
        connect();
        logger.info("saveUserStoredQna:connected 1");
        PasswordChangeDAO dao = new PasswordChangeDAO(datasource);
        UserSecurityQuestion oldQna = dao.findByUaName(username);
        if (oldQna != null) {
            logger.debug("saveUserStoredQna:dao.findByUaName(" + username + "' queried ...");
            logger.debug("saveUserStoredQna:oldQna.getAttemptedCount() = '" + oldQna.getAttemptedCount() + "'");
            qna.setAttemptedCount(oldQna.getAttemptedCount());
            logger.debug("saveUserStoredQna:qna.getAttemptedCount() = '" + qna.getAttemptedCount() + "'");
            logger.debug("saveUserStoredQna:oldQna.getDateModified() = '" + oldQna.getDateModified() + "'");
            qna.setDateModified(oldQna.getDateModified());
            logger.debug("saveUserStoredQna:qna.getDateModified() = '" + qna.getDateModified() + "'");
        }
        connect();
        logger.info("saveUserStoredQna:connected 2");
        PasswordChangeDAO dao1 = new PasswordChangeDAO(datasource);
        if (oldQna == null) {
            dao1.insert(qna);
            logger.debug("saveUserStoredQna:inserted qna [" + qna.toString() + "]");
        } else {
            dao1.update(username, qna);
            logger.debug("saveUserStoredQna:updated username [" + username + "] qna [" + qna.toString() + "]");
        }
        //showUserSecurityQuestionList();   //just for debug
        disconnect();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.netscape.cms.logging.LogFile.java

/**
 * This method actually does the logging, and is not overridden
 * by subclasses, so you can call it and know that it will do exactly
 * what you see below./*w w  w  . j  av a 2 s .  co m*/
 */
private synchronized void doLog(ILogEvent event, boolean noFlush) throws ELogException {

    String entry = logEvt2String(event);

    if (mLogWriter == null) {
        String[] params = { mFileName, entry };

        if (mLogSigning) {
            ConsoleError.send(new SystemEvent(CMS.getUserMessage("CMS_LOG_LOGFILE_CLOSED", params)));
            // Failed to write to audit log, shut down CMS
            shutdownCMS();
        }
        throw new ELogException(CMS.getUserMessage("CMS_LOG_LOGFILE_CLOSED", params));
    } else {
        try {
            mLogWriter.write(entry, 0/*offset*/, entry.length());

            if (mLogSigning == true) {
                if (mSignature != null) {
                    // include newline for calculating MAC
                    mSignature.update(entry.getBytes("UTF-8"));
                } else {
                    CMS.debug("LogFile: mSignature is not yet ready... null in log()");
                }
            }
            if (mTrace) {
                CharArrayWriter cw = new CharArrayWriter(200);
                PrintWriter pw = new PrintWriter(cw);
                Exception e = new Exception();
                e.printStackTrace(pw);
                char[] c = cw.toCharArray();
                cw.close();
                pw.close();

                CharArrayReader cr = new CharArrayReader(c);
                LineNumberReader lr = new LineNumberReader(cr);

                String text = null;
                String method = null;
                String fileAndLine = null;
                if (lr.ready()) {
                    text = lr.readLine();
                    do {
                        text = lr.readLine();
                    } while (text.indexOf("logging") != -1);
                    int p = text.indexOf("(");
                    fileAndLine = text.substring(p);

                    String classandmethod = text.substring(0, p);
                    int q = classandmethod.lastIndexOf(".");
                    method = classandmethod.substring(q + 1);
                    mLogWriter.write(fileAndLine, 0/*offset*/, fileAndLine.length());
                    mLogWriter.write(" ", 0/*offset*/, " ".length());
                    mLogWriter.write(method, 0/*offset*/, method.length());
                }
            }
            mLogWriter.newLine();

            if (mLogSigning == true) {
                if (mSignature != null) {
                    mSignature.update(LINE_SEP_BYTE);
                } else {
                    CMS.debug("LogFile: mSignature is null in log() 2");
                }
            }
        } catch (IOException e) {
            ConsoleError.send(new SystemEvent(
                    CMS.getUserMessage("CMS_LOG_WRITE_FAILED", mFileName, entry, e.toString())));
            if (mLogSigning) {
                // Failed to write to audit log, shut down CMS
                e.printStackTrace();
                shutdownCMS();
            }
        } catch (IllegalStateException e) {
            CMS.debug("LogFile: exception thrown in log(): " + e.toString());
            ConsoleError
                    .send(new SignedAuditEvent(CMS.getLogMessage(LOG_SIGNED_AUDIT_EXCEPTION, e.toString())));
        } catch (GeneralSecurityException gse) {
            // DJN: handle error
            CMS.debug("LogFile: exception thrown in log(): " + gse.toString());
            gse.printStackTrace();
            ConsoleError
                    .send(new SignedAuditEvent(CMS.getLogMessage(LOG_SIGNED_AUDIT_EXCEPTION, gse.toString())));
        } catch (Exception ee) { // Make darn sure we got everything
            ConsoleError
                    .send(new SignedAuditEvent(CMS.getLogMessage(LOG_SIGNED_AUDIT_EXCEPTION, ee.toString())));
            if (mLogSigning) {
                // Failed to write to audit log, shut down CMS
                ee.printStackTrace();
                shutdownCMS();
            }

        }

        // XXX
        // Although length will be in Unicode dual-bytes, the PrintWriter
        // will only print out 1 byte per character.  I suppose this could
        // be dependent on the encoding of your log file, but it ain't that
        // smart yet.  Also, add one for the newline. (hmm, on NT, CR+LF)
        int nBytes = entry.length() + 1;

        mBytesWritten += nBytes;
        mBytesUnflushed += nBytes;

        if (mBufferSize > 0 && mBytesUnflushed > mBufferSize && !noFlush) {
            flush();
        }
    }
}

From source file:com.netscape.cms.logging.LogFile.java

/**
 * Open the log file. This creates the buffered FileWriter
 *
 *//*from w w  w  . ja v  a2  s  .com*/
protected synchronized void open() throws IOException {
    RandomAccessFile out;

    try {
        out = new RandomAccessFile(mFile, "rw");
        out.seek(out.length());
        //XXX int or long?
        mBytesWritten = (int) out.length();
        if (!Utils.isNT()) {
            try {
                Utils.exec("chmod 00640 " + mFile.getCanonicalPath());
            } catch (IOException e) {
                CMS.debug("Unable to change file permissions on " + mFile.toString());
            }
        }
        mLogWriter = new BufferedWriter(new FileWriter(out.getFD()), mBufferSize);

        // The first time we open, mSignature will not have been
        // initialized yet. That's ok, we will push our first signature
        // in setupSigning().
        if (mLogSigning && (mSignature != null)) {
            try {
                pushSignature();
            } catch (ELogException le) {
                ConsoleError.send(new SystemEvent(CMS.getUserMessage("CMS_LOG_ILLEGALARGUMENT", mFileName)));
            }
        }
    } catch (IllegalArgumentException iae) {
        ConsoleError.send(new SystemEvent(CMS.getUserMessage("CMS_LOG_ILLEGALARGUMENT", mFileName)));
    } catch (GeneralSecurityException gse) {
        // error with signed audit log, shutdown CMS
        ConsoleError
                .send(new SystemEvent(CMS.getUserMessage("CMS_LOG_OPEN_FAILED", mFileName, gse.toString())));
        gse.printStackTrace();
        shutdownCMS();
    }

    mBytesUnflushed = 0;
}

From source file:com.netscape.cms.logging.LogFile.java

/**
 * Flush the log file. Also update the MAC for hash protected logs
 *
 *//*w w w .ja va 2s .  com*/
public synchronized void flush() {
    try {
        if (mLogSigning) {
            try {
                pushSignature();
            } catch (ELogException le) {
                ConsoleError.send(new SystemEvent(
                        CMS.getUserMessage("CMS_LOG_FLUSH_LOG_FAILED", mFileName, le.toString())));
                le.printStackTrace();
                shutdownCMS();
            }
        }

        if (mLogWriter != null) {
            mLogWriter.flush();
        }
    } catch (IOException e) {
        ConsoleError
                .send(new SystemEvent(CMS.getUserMessage("CMS_LOG_FLUSH_LOG_FAILED", mFileName, e.toString())));
        if (mLogSigning) {
            //error in writing to signed audit log, shut down CMS
            e.printStackTrace();
            shutdownCMS();
        }
    } catch (GeneralSecurityException gse) {
        // error with signed audit log, shutdown CMS
        ConsoleError.send(
                new SystemEvent(CMS.getUserMessage("CMS_LOG_FLUSH_LOG_FAILED", mFileName, gse.toString())));
        gse.printStackTrace();
        shutdownCMS();
    } catch (Exception ee) {
        ConsoleError.send(
                new SystemEvent(CMS.getUserMessage("CMS_LOG_FLUSH_LOG_FAILED", mFileName, ee.toString())));
        if (mLogSigning) {
            ee.printStackTrace();
            shutdownCMS();
        }
    }

    mBytesUnflushed = 0;
}

From source file:org.appspot.apprtc.util.AsyncHttpURLConnection.java

private void sendHttpMessage() {
    if (mIsBitmap) {
        Bitmap bitmap = ThumbnailsCacheManager.getBitmapFromDiskCache(url);

        if (bitmap != null) {
            events.onHttpComplete(bitmap);
            return;
        }//from ww w . j a  va2 s .com
    }

    X509TrustManager trustManager = new X509TrustManager() {

        @Override
        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 {
        }
    };

    //HttpsURLConnection.setDefaultHostnameVerifier(new NullHostNameVerifier());
    // 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) {
    }

    HttpsURLConnection connection = null;
    try {
        URL urlObj = new URL(url);
        connection = (HttpsURLConnection) urlObj.openConnection();
        connection.setSSLSocketFactory(noSSLv3Factory);

        HttpsURLConnection.setDefaultHostnameVerifier(new NullHostNameVerifier(urlObj.getHost()));
        connection.setHostnameVerifier(new NullHostNameVerifier(urlObj.getHost()));
        byte[] postData = new byte[0];
        if (message != null) {
            postData = message.getBytes("UTF-8");
        }

        if (msCookieManager.getCookieStore().getCookies().size() > 0) {
            // While joining the Cookies, use ',' or ';' as needed. Most of the servers are using ';'
            connection.setRequestProperty("Cookie",
                    TextUtils.join(";", msCookieManager.getCookieStore().getCookies()));
        }

        /*if (method.equals("PATCH")) {
          connection.setRequestProperty("X-HTTP-Method-Override", "PATCH");
          connection.setRequestMethod("POST");
        }
        else {*/
        connection.setRequestMethod(method);
        //}

        if (authorization.length() != 0) {
            connection.setRequestProperty("Authorization", authorization);
        }
        connection.setUseCaches(false);
        connection.setDoInput(true);
        connection.setConnectTimeout(HTTP_TIMEOUT_MS);
        connection.setReadTimeout(HTTP_TIMEOUT_MS);
        // TODO(glaznev) - query request origin from pref_room_server_url_key preferences.
        //connection.addRequestProperty("origin", HTTP_ORIGIN);
        boolean doOutput = false;
        if (method.equals("POST") || method.equals("PATCH")) {
            doOutput = true;
            connection.setDoOutput(true);
            connection.setFixedLengthStreamingMode(postData.length);
        }
        if (contentType == null) {
            connection.setRequestProperty("Content-Type", "text/plain; charset=utf-8");
        } else {
            connection.setRequestProperty("Content-Type", contentType);
        }

        // Send POST request.
        if (doOutput && postData.length > 0) {
            OutputStream outStream = connection.getOutputStream();
            outStream.write(postData);
            outStream.close();
        }

        // Get response.
        int responseCode = 200;
        try {
            connection.getResponseCode();
        } catch (IOException e) {

        }
        getCookies(connection);
        InputStream responseStream;

        if (responseCode > 400) {
            responseStream = connection.getErrorStream();
        } else {
            responseStream = connection.getInputStream();
        }

        String responseType = connection.getContentType();
        if (responseType.startsWith("image/")) {
            Bitmap bitmap = BitmapFactory.decodeStream(responseStream);
            if (mIsBitmap && bitmap != null) {
                ThumbnailsCacheManager.addBitmapToCache(url, bitmap);
            }
            events.onHttpComplete(bitmap);
        } else {
            String response = drainStream(responseStream);
            events.onHttpComplete(response);
        }
        responseStream.close();
        connection.disconnect();
    } catch (SocketTimeoutException e) {
        events.onHttpError("HTTP " + method + " to " + url + " timeout");
    } catch (IOException e) {
        if (connection != null) {
            connection.disconnect();
        }
        events.onHttpError("HTTP " + method + " to " + url + " error: " + e.getMessage());
    } catch (ClassCastException e) {
        e.printStackTrace();
    }
}