1 /*
2  * @(#) $Id: ShowCommand.java,v 1.3 2003/07/08 08:13:53 pankaj Exp $
3  *
4  * Copyright (c) 2002-03 by Pankaj Kumar (http://www.pankaj-k.net). 
5  * All rights reserved.
6  *
7  * The license governing the use of this file can be found in the 
8  * root directory of the containing software.
9  */
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