1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44:
45: import ;
46: import ;
47:
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53:
54: import ;
55: import ;
56: import ;
57: import ;
58: import ;
59: import ;
60:
61: public class SessionImpl extends Session
62: {
63: static final long serialVersionUID = 8932976607588442485L;
64: CipherSuite suite;
65: ProtocolVersion version;
66: byte[] privateDataSalt;
67: SealedObject sealedPrivateData;
68: MaxFragmentLength maxLength;
69:
70: transient PrivateData privateData;
71:
72: public SessionImpl()
73: {
74: super();
75: privateData = new PrivateData();
76: }
77:
78: SecureRandom random ()
79: {
80: return random;
81: }
82:
83: public String getProtocol()
84: {
85: return version.toString();
86: }
87:
88: public void prepare(char[] passwd) throws SSLException
89: {
90: try
91: {
92: privateDataSalt = new byte[32];
93: random.nextBytes(privateDataSalt);
94: GnuPBEKey key = new GnuPBEKey(passwd, privateDataSalt, 1000);
95: Cipher cipher = Cipher.getInstance("PBEWithHMacSHA256AndAES/OFB/PKCS7Padding");
96: cipher.init(Cipher.ENCRYPT_MODE, key);
97: sealedPrivateData = new SealedObject(privateData, cipher);
98: }
99: catch (IllegalBlockSizeException ibse)
100: {
101: throw new SSLException(ibse);
102: }
103: catch (InvalidKeyException ike)
104: {
105: throw new SSLException(ike);
106: }
107: catch (IOException ioe)
108: {
109: throw new SSLException(ioe);
110: }
111: catch (NoSuchAlgorithmException nsae)
112: {
113: throw new SSLException(nsae);
114: }
115: catch (NoSuchPaddingException nspe)
116: {
117: throw new SSLException(nspe);
118: }
119: }
120:
121: public void repair(char[] passwd) throws SSLException
122: {
123: try
124: {
125: GnuPBEKey key = new GnuPBEKey(passwd, privateDataSalt, 1000);
126: privateData = (PrivateData) sealedPrivateData.getObject(key);
127: }
128: catch (ClassNotFoundException cnfe)
129: {
130: throw new SSLException(cnfe);
131: }
132: catch (InvalidKeyException ike)
133: {
134: throw new SSLException(ike);
135: }
136: catch (IOException ioe)
137: {
138: throw new SSLException(ioe);
139: }
140: catch (NoSuchAlgorithmException nsae)
141: {
142: throw new SSLException(nsae);
143: }
144: }
145:
146: public SealedObject privateData() throws SSLException
147: {
148: if (privateData == null)
149: throw new SSLException("this session has not been prepared");
150: return sealedPrivateData;
151: }
152:
153: public void setPrivateData(SealedObject so) throws SSLException
154: {
155: this.sealedPrivateData = so;
156: }
157:
158: void setApplicationBufferSize(int size)
159: {
160: applicationBufferSize = size;
161: }
162:
163: void setRandom(SecureRandom random)
164: {
165: this.random = random;
166: }
167:
168: void setTruncatedMac(boolean truncatedMac)
169: {
170: this.truncatedMac = truncatedMac;
171: }
172:
173: void setId(Session.ID id)
174: {
175: this.sessionId = id;
176: }
177:
178: void setLocalCertificates(java.security.cert.Certificate[] chain)
179: {
180: this.localCerts = chain;
181: }
182:
183: void setPeerCertificates(java.security.cert.Certificate[] chain)
184: {
185: this.peerCerts = chain;
186: }
187:
188: void setPeerVerified(boolean peerVerified)
189: {
190: this.peerVerified = peerVerified;
191: }
192:
193: static class PrivateData implements Serializable
194: {
195: static final long serialVersionUID = -8040597659545984581L;
196: byte[] masterSecret;
197: }
198: }