KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > security > CipherInfo


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.security;
24
25 import java.util.HashMap JavaDoc;
26
27 /**
28  * This class represents the information associated to ciphers.
29  * It also maintains a HashMap from configName to CipherInfo.
30  * @author Shing Wai Chan
31  */

32 public class CipherInfo {
33     private static final short SSL2 = 0x1;
34     private static final short SSL3 = 0x2;
35     private static final short TLS = 0x4;
36
37     // The old names mapped to the standard names as existed in the http path
38
private static final String JavaDoc[][] OLD_HTTP_CIPHER_MAPPING = {
39             {"rsa_rc4_128_md5", "SSL_RSA_WITH_RC4_128_MD5"},
40             {"rsa_3des_sha" , "SSL_RSA_WITH_3DES_EDE_CBC_SHA"},
41             {"rsa_des_sha" , "SSL_RSA_WITH_DES_CBC_SHA"},
42             {"rsa_rc4_40_md5" , "SSL_RSA_EXPORT_WITH_RC4_40_MD5"},
43             {"rsa_null_md5" , "SSL_RSA_WITH_NULL_MD5"},
44             {"rsa_des_56_sha" , "SSL_RSA_WITH_DES_CBC_SHA"},
45             {"rsa_rc4_56_sha" , "SSL_RSA_WITH_RC4_128_SHA"}
46         };
47
48     // The old names mapped to the standard names as existed in this class before
49
// The ones that have been commented out are covered in OLD_HTTP_CIPHER_MAPPING
50
private static final String JavaDoc[][] OLD_CIPHER_MAPPING = {
51             //{"rsa_rc4_128_md5", "SSL_RSA_WITH_RC4_128_MD5"},
52
//{"rsa_rc4_40_md5" , "SSL_RSA_EXPORT_WITH_RC4_40_MD5"},
53
//{"rsa_null_md5" , "SSL_RSA_WITH_NULL_MD5"},
54
//{"rsa_3des_sha" , "SSL_RSA_WITH_3DES_EDE_CBC_SHA"},
55
{"rsa_rc4_128_sha", "SSL_RSA_WITH_RC4_128_SHA"},
56             {"fips_des_sha" , "SSL_RSA_WITH_DES_CBC_SHA"},
57             {"rsa_null_sha" , "SSL_RSA_WITH_NULL_SHA"}
58         };
59
60     // The current set of cipher names that can be configured by the
61
// user. Eventually we'd like to expand this list to something
62
// like1. SSL_RSA_WITH_RC4_128_MD5 SSL_RSA_WITH_RC4_128_SHA
63
// TLS_RSA_WITH_AES_128_CBC_SHA TLS_DHE_RSA_WITH_AES_128_CBC_SHA
64
// SSL_RSA_WITH_3DES_EDE_CBC_SHA SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA
65
// SSL_RSA_WITH_DES_CBC_SHA SSL_DHE_RSA_WITH_DES_CBC_SHA
66
// SSL_RSA_EXPORT_WITH_RC4_40_MD5 SSL_RSA_EXPORT_WITH_DES40_CBC_SHA
67
// SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA TLS_DHE_DSS_WITH_AES_128_CBC_SHA
68
// SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA SSL_DHE_DSS_WITH_DES_CBC_SHA
69
// SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA
70
private static final String JavaDoc[] USER_CONFIGURABLE_CIPHERS = {
71         "SSL_RSA_WITH_RC4_128_MD5",
72         "SSL_RSA_WITH_3DES_EDE_CBC_SHA",
73         "SSL_RSA_WITH_DES_CBC_SHA",
74         "SSL_RSA_EXPORT_WITH_RC4_40_MD5",
75         "SSL_RSA_WITH_NULL_MD5",
76         "SSL_RSA_WITH_RC4_128_SHA",
77         "SSL_RSA_WITH_NULL_SHA" };
78
79     private static HashMap JavaDoc ciphers = new HashMap JavaDoc();
80
81     private String JavaDoc configName;
82     private String JavaDoc cipherName;
83     private short protocolVersion;
84
85
86     static {
87         //The following ciphers name are from JSSE in JDK 1.4.
88
//Commented out ciphers will be uncommented once their configNames are finalized.
89

90         int len = USER_CONFIGURABLE_CIPHERS.length;
91         for(int i=0; i<len; i++) {
92             String JavaDoc s = USER_CONFIGURABLE_CIPHERS[i];
93             ciphers.put(s, new CipherInfo(s, s, (short)(SSL3|TLS)) );
94         }
95
96         len = OLD_HTTP_CIPHER_MAPPING.length;
97         for(int i=0; i<len; i++) {
98             String JavaDoc nonStdName = OLD_HTTP_CIPHER_MAPPING[i][0];
99             String JavaDoc stdName = OLD_HTTP_CIPHER_MAPPING[i][1];
100             ciphers.put(nonStdName,
101                 new CipherInfo(nonStdName, stdName, (short)(SSL3|TLS)) );
102         }
103
104         len = OLD_CIPHER_MAPPING.length;
105         for(int i=0; i<len; i++) {
106             String JavaDoc nonStdName = OLD_CIPHER_MAPPING[i][0];
107             String JavaDoc stdName = OLD_CIPHER_MAPPING[i][1];
108             ciphers.put(nonStdName,
109                 new CipherInfo(nonStdName, stdName, (short)(SSL3|TLS)) );
110         }
111     }
112
113     /**
114      * @param configName name used in domain.xml, sun-acc.xml
115      * @param cipherName name that may depends on backend
116      * @param protocolVersion
117      */

118     private CipherInfo(String JavaDoc configName, String JavaDoc cipherName,
119             short protocolVersion) {
120         this.configName = configName;
121         this.cipherName = cipherName;
122         this.protocolVersion = protocolVersion;
123     }
124
125     public static CipherInfo getCipherInfo(String JavaDoc configName) {
126         return (CipherInfo)ciphers.get(configName);
127     }
128
129     public String JavaDoc getConfigName() {
130         return configName;
131     }
132
133     public String JavaDoc getCipherName() {
134         return cipherName;
135     }
136
137     public boolean isSSL2() {
138         return (protocolVersion & SSL2) == SSL2;
139     }
140
141     public boolean isSSL3() {
142         return (protocolVersion & SSL3) == SSL3;
143     }
144
145     public boolean isTLS() {
146         return (protocolVersion & TLS) == TLS;
147     }
148 }
149
Popular Tags