KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > security > srp > SRPParameters


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.security.srp;
23
24 import java.io.Serializable JavaDoc;
25 import java.util.Arrays JavaDoc;
26
27 import org.jboss.security.Util;
28
29 /** The RFC2945 algorithm session parameters that the client and server
30 agree to use. In addition to the base RFC2945 parameters, one can choose an
31 alternate hash algorithm for the private session key.
32
33 @author Scott.Stark@jboss.org
34 @version $Revision: 40096 $
35 */

36 public class SRPParameters implements Cloneable JavaDoc, Serializable JavaDoc
37 {
38    /** The serial version ID.
39     * @since 1.2.4.1
40     */

41    private static final long serialVersionUID = 6438772808805276693L;
42
43    /** The algorithm safe-prime modulus */
44    public final byte[] N;
45    /** The algorithm primitive generator */
46    public final byte[] g;
47    /** The random password salt originally used to verify the password */
48    public final byte[] s;
49    /** The algorithm to hash the session key to produce K. To be consistent
50     with the RFC2945 description this must be SHA_Interleave as implemented
51     by the JBossSX security provider. For compatibility with earlier JBossSX
52     SRP releases the algorithm must be SHA_ReverseInterleave. This name is
53     passed to java.security.MessageDigest.getInstance(). */

54    public final String JavaDoc hashAlgorithm;
55    /** The algorithm to use for any encryption of data.
56     */

57    public final String JavaDoc cipherAlgorithm;
58    /** The cipher intialization vector bytes
59     */

60    public byte[] cipherIV;
61
62    /** Creates a new instance of SRPParameters */
63    public SRPParameters(byte[] N, byte[] g, byte[] s)
64    {
65       this(N, g, s, "SHA_Interleave", null);
66    }
67    public SRPParameters(byte[] N, byte[] g, byte[] s, String JavaDoc hashAlgorithm)
68    {
69       this(N, g, s, hashAlgorithm, null);
70    }
71    public SRPParameters(byte[] N, byte[] g, byte[] s, String JavaDoc hashAlgorithm,
72       String JavaDoc cipherAlgorithm)
73    {
74       this(N, g, s, hashAlgorithm, cipherAlgorithm, null);
75    }
76    public SRPParameters(byte[] N, byte[] g, byte[] s, String JavaDoc hashAlgorithm,
77       String JavaDoc cipherAlgorithm, byte[] cipherIV)
78    {
79       this.N = N;
80       this.g = g;
81       this.s = s;
82       if( hashAlgorithm == null )
83          hashAlgorithm = "SHA_Interleave";
84       this.hashAlgorithm = hashAlgorithm;
85       this.cipherAlgorithm = cipherAlgorithm;
86       this.cipherIV = cipherIV;
87    }
88
89    public Object JavaDoc clone()
90    {
91       Object JavaDoc clone = null;
92       try
93       {
94           clone = super.clone();
95       }
96       catch(CloneNotSupportedException JavaDoc e)
97       {
98       }
99       return clone;
100    }
101
102    public int hashCode()
103    {
104       int hashCode = hashAlgorithm.hashCode();
105       for(int i = 0; i < N.length; i ++)
106          hashCode += N[i];
107       for(int i = 0; i < g.length; i ++)
108          hashCode += g[i];
109       for(int i = 0; i < s.length; i ++)
110          hashCode += s[i];
111       return hashCode;
112    }
113
114    public boolean equals(Object JavaDoc obj)
115    {
116       boolean equals = false;
117       if( obj instanceof SRPParameters )
118       {
119          SRPParameters p = (SRPParameters) obj;
120          equals = hashAlgorithm.equals(p.hashAlgorithm);
121          if( equals == true )
122             equals = Arrays.equals(N, p.N);
123          if( equals == true )
124             equals = Arrays.equals(g, p.g);
125          if( equals == true )
126             equals = Arrays.equals(s, p.s);
127       }
128       return equals;
129    }
130
131    public String JavaDoc toString()
132    {
133       StringBuffer JavaDoc tmp = new StringBuffer JavaDoc(super.toString());
134       tmp.append('{');
135       tmp.append("N: ");
136       tmp.append(Util.encodeBase64(N));
137       tmp.append("|g: ");
138       tmp.append(Util.encodeBase64(g));
139       tmp.append("|s: ");
140       tmp.append(Util.encodeBase64(s));
141       tmp.append("|hashAlgorithm: ");
142       tmp.append(hashAlgorithm);
143       tmp.append("|cipherAlgorithm: ");
144       tmp.append(cipherAlgorithm);
145       tmp.append("|cipherIV: ");
146       tmp.append(cipherIV);
147       tmp.append('}');
148       return tmp.toString();
149    }
150 }
151
Popular Tags