KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mortbay > jetty > servlet > ServletSSL


1 // ========================================================================
2
// $Id: ServletSSL.java,v 1.4 2004/12/21 06:31:34 janb Exp $
3
// Copyright 2001-2004 Mort Bay Consulting Pty. Ltd.
4
// ------------------------------------------------------------------------
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
// ========================================================================
15

16 package org.mortbay.jetty.servlet;
17
18 /* --------------------------------------------------------------------- */
19 /** Jetty Servlet SSL support utilities.
20  * <p> A collection of utilities required to support the SSL
21  * requirements of the Servlet 2.2 and 2.3 specs.
22  *
23  * <p> Used by the SSL listener classes.
24  *
25  * @version $Id: ServletSSL.java,v 1.4 2004/12/21 06:31:34 janb Exp $
26  * @author Brett Sealey
27  */

28 public class ServletSSL
29 {
30     /* ------------------------------------------------------------ */
31     /**
32      * Given the name of a TLS/SSL cipher suite, return an int
33      * representing it effective stream cipher key strength.
34      * i.e. How much entropy material is in the key material being fed
35      * into the encryption routines.
36
37      * <p> This is based on the information on effective key lengths
38      * in RFC 2246 - The TLS Protocol Version 1.0,
39      * Appendix C. CipherSuite definitions:
40      *
41      * <pre>
42      * Effective
43      * Cipher Type Key Bits
44      *
45      * NULL * Stream 0
46      * IDEA_CBC Block 128
47      * RC2_CBC_40 * Block 40
48      * RC4_40 * Stream 40
49      * RC4_128 Stream 128
50      * DES40_CBC * Block 40
51      * DES_CBC Block 56
52      * 3DES_EDE_CBC Block 168
53      * </pre>
54      * @param cipherSuite String name of the TLS cipher suite.
55      * @return int indicating the effective key entropy bit-length.
56      */

57     public static final int deduceKeyLength(String JavaDoc cipherSuite)
58     {
59     // Roughly ordered from most common to least common.
60
if (cipherSuite == null)
61         return 0;
62     else if (cipherSuite.indexOf("WITH_RC4_128_") >= 0)
63         return 128;
64     else if (cipherSuite.indexOf("WITH_AES_128_") >= 0)
65             return 128;
66     else if (cipherSuite.indexOf("WITH_RC4_40_") >= 0)
67         return 40;
68     else if (cipherSuite.indexOf("WITH_3DES_EDE_CBC_") >= 0)
69         return 168;
70     else if (cipherSuite.indexOf("WITH_IDEA_CBC_") >= 0)
71         return 128;
72     else if (cipherSuite.indexOf("WITH_RC2_CBC_40_") >= 0)
73         return 40;
74     else if (cipherSuite.indexOf("WITH_DES40_CBC_") >= 0)
75         return 40;
76     else if (cipherSuite.indexOf("WITH_DES_CBC_") >= 0)
77         return 56;
78     else
79         return 0;
80     }
81 }
82
Popular Tags