1
10package org.jstk.ssl;
11
12import java.net.*;
13import java.io.*;
14import java.util.HashMap;
15import javax.net.ssl.SSLSocketFactory;
16import javax.net.ssl.SSLSocket;
17import javax.net.ssl.SSLSession;
18import org.jstk.*;
19
20public class ShowCommand extends JSTKCommandAdapter {
21 private static HashMap defaults = new HashMap();
22 static {
23
24 }
25
26 public String briefDescription(){
27 String briefDesc = "displays the SSL related information";
28 return briefDesc;
29 }
30
31 public String optionsDescription(){
32 String optionsDesc =
33 " -cs : Displays the supported and enabled cipher suites.\n";
34 return optionsDesc;
35 }
36 public String[] useForms(){
37 String[] useForms = {
38 "-cs"
39 };
40 return useForms;
41 }
42 public String[] sampleUses(){
43 String[] sampleUses = {
44 "-cs"
45 };
46 return sampleUses;
47 }
48
49 public Object execute(JSTKArgs args) throws JSTKException{
50 try {
51 args.setDefaults(defaults);
52 boolean cipherSuite = Boolean.valueOf(args.get("cs")).booleanValue();
53 StringBuffer sb = new StringBuffer();
54
55 if (cipherSuite){
56 SSLSocketFactory sf = (SSLSocketFactory)SSLSocketFactory.getDefault();
57 String[] supportedCSuites = sf.getSupportedCipherSuites();
58 String[] enabledCSuites = sf.getDefaultCipherSuites();
59
60 sb.append(" Supported Cipher Suites:\n");
61 for (int i = 0; i < supportedCSuites.length; i++){
62 sb.append(" [" + i + "] " + supportedCSuites[i] + "\n");
63 }
64 sb.append(" Enabled Cipher Suites :\n");
65 for (int i = 0; i < enabledCSuites.length; i++){
66 sb.append(" [" + i + "] " + enabledCSuites[i] + "\n");
67 }
68 }
69 return new JSTKResult(null, true, sb.toString());
70 } catch (Exception exc){
71 throw new JSTKException("ServerCommand execution failed", exc);
72 }
73 }
74
75 public static void main(String[] args) throws Exception {
76 JSTKOptions opts = new JSTKOptions();
77 opts.parse(args, 0);
78 ShowCommand showCmd = new ShowCommand();
79 JSTKResult result = (JSTKResult)showCmd.execute(opts);
80 System.out.println(result.getText());
81 System.exit(result.isSuccess()? 0 : 1);
82 }
83}
84