diff options
| author | Endi S. Dewata <edewata@redhat.com> | 2017-06-13 21:02:34 +0200 |
|---|---|---|
| committer | Endi S. Dewata <edewata@redhat.com> | 2017-06-13 21:31:14 +0200 |
| commit | 22e97396e3f5e5024b4fee3f816ca319857126df (patch) | |
| tree | fb72a60f1abf84c8c60f6becb6af8108d96d8857 /base/console/src/com/netscape/admin | |
| parent | bd82be4999b066bdf2fd91683432de6f7bdcf667 (diff) | |
| download | pki-22e97396e3f5e5024b4fee3f816ca319857126df.tar.gz pki-22e97396e3f5e5024b4fee3f816ca319857126df.tar.xz pki-22e97396e3f5e5024b4fee3f816ca319857126df.zip | |
Added verbose option for PKI console.
The PKI console has been modified to provide a verbose option to
help troubleshooting.
https://pagure.io/dogtagpki/issue/2671
Change-Id: Ib231a278a8d000bdbe43513149331bb0ea1f2752
Diffstat (limited to 'base/console/src/com/netscape/admin')
| -rw-r--r-- | base/console/src/com/netscape/admin/certsrv/Console.java | 45 | ||||
| -rw-r--r-- | base/console/src/com/netscape/admin/certsrv/connection/JSSConnection.java | 41 |
2 files changed, 84 insertions, 2 deletions
diff --git a/base/console/src/com/netscape/admin/certsrv/Console.java b/base/console/src/com/netscape/admin/certsrv/Console.java index 6bb8a3449..2c4f59438 100644 --- a/base/console/src/com/netscape/admin/certsrv/Console.java +++ b/base/console/src/com/netscape/admin/certsrv/Console.java @@ -43,12 +43,14 @@ import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.UIManager; +import javax.ws.rs.ProcessingException; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; +import org.apache.commons.cli.UnrecognizedOptionException; import org.dogtagpki.common.Info; import org.dogtagpki.common.InfoClient; @@ -126,6 +128,7 @@ public class Console implements CommClient { // // global values // + public static boolean verbose; public static Preferences _preferences; public static ConsoleInfo _info; public static String _consoleAdminURL; @@ -1575,6 +1578,7 @@ public class Console implements CommClient { System.out.println(" -f <file> Capture stderr and stdout to file."); System.out.println(" -D <options> Debug options."); System.out.println(" -x <options> Extra options (javalaf, nowinpos, nologo)."); + System.out.println(" -v,--verbose Run in verbose mode."); System.out.println(" -h,--help Show help message."); System.out.println(); System.out.println("Example: pkiconsole https://hostname:8443/ca"); @@ -1587,7 +1591,7 @@ public class Console implements CommClient { * @param parameters list */ - static public void main(String argv[]) throws Exception { + public static void mainImpl(String argv[]) throws Exception { Options options = new Options(); @@ -1603,6 +1607,7 @@ public class Console implements CommClient { option.setArgName("options"); options.addOption(option); + options.addOption("v", "verbose", false, "Run in verbose mode."); options.addOption("h", "help", false, "Show help message."); CommandLineParser parser = new DefaultParser(); @@ -1610,6 +1615,8 @@ public class Console implements CommClient { String[] cmdArgs = cmd.getArgs(); + verbose = cmd.hasOption("verbose"); + String outFile = cmd.getOptionValue("f"); if (outFile != null) { try { @@ -1783,7 +1790,41 @@ public class Console implements CommClient { /* _console = new Console(sAdminURL, localAdminURL, sLang, host, uid, password); */ - return; + } + + public static void handleException(Throwable t) { + + if (verbose) { + t.printStackTrace(System.err); + + } else if (t.getClass() == Exception.class) { + // display a generic error + System.err.println("Error: " + t.getMessage()); + + } else if (t.getClass() == UnrecognizedOptionException.class) { + // display only the error message + System.err.println(t.getMessage()); + + } else if (t instanceof ProcessingException) { + // display the cause of the exception + t = t.getCause(); + System.err.println(t.getClass().getSimpleName() + ": " + t.getMessage()); + + } else { + // display the actual Exception + System.err.println(t.getClass().getSimpleName() + ": " + t.getMessage()); + } + } + + public static void main(String args[]) { + + try { + mainImpl(args); + + } catch (Throwable t) { + handleException(t); + System.exit(-1); + } } } diff --git a/base/console/src/com/netscape/admin/certsrv/connection/JSSConnection.java b/base/console/src/com/netscape/admin/certsrv/connection/JSSConnection.java index 8fbc2b768..f1b1df3f0 100644 --- a/base/console/src/com/netscape/admin/certsrv/connection/JSSConnection.java +++ b/base/console/src/com/netscape/admin/certsrv/connection/JSSConnection.java @@ -40,9 +40,14 @@ import javax.swing.JLabel; import org.mozilla.jss.CryptoManager; import org.mozilla.jss.crypto.CryptoToken; import org.mozilla.jss.crypto.InternalCertificate; +import org.mozilla.jss.ssl.SSLAlertDescription; +import org.mozilla.jss.ssl.SSLAlertEvent; +import org.mozilla.jss.ssl.SSLAlertLevel; import org.mozilla.jss.ssl.SSLCertificateApprovalCallback; import org.mozilla.jss.ssl.SSLClientCertificateSelectionCallback; +import org.mozilla.jss.ssl.SSLHandshakeCompletedEvent; import org.mozilla.jss.ssl.SSLSocket; +import org.mozilla.jss.ssl.SSLSocketListener; import org.mozilla.jss.util.Password; import org.mozilla.jss.util.PasswordCallback; import org.mozilla.jss.util.PasswordCallbackInfo; @@ -125,6 +130,42 @@ public class JSSConnection implements IConnection, SSLCertificateApprovalCallbac s = new SSLSocket(host, port, null, 0, this, this); + s.addSocketListener(new SSLSocketListener() { + + @Override + public void alertReceived(SSLAlertEvent event) { + + int intLevel = event.getLevel(); + SSLAlertLevel level = SSLAlertLevel.valueOf(intLevel); + + int intDescription = event.getDescription(); + SSLAlertDescription description = SSLAlertDescription.valueOf(intDescription); + + if (level == SSLAlertLevel.FATAL) { + System.err.println(level + ": SSL alert received: " + description); + } + } + + @Override + public void alertSent(SSLAlertEvent event) { + + int intLevel = event.getLevel(); + SSLAlertLevel level = SSLAlertLevel.valueOf(intLevel); + + int intDescription = event.getDescription(); + SSLAlertDescription description = SSLAlertDescription.valueOf(intDescription); + + if (level == SSLAlertLevel.FATAL) { + System.err.println(level + ": SSL alert sent: " + description); + } + } + + @Override + public void handshakeCompleted(SSLHandshakeCompletedEvent event) { + } + + }); + // Initialze Http Input and Output Streams httpIn = s.getInputStream(); httpOut = s.getOutputStream(); |
