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