@@ -70,7 +70,7 @@ private void init(String pathToStores) {
70
70
protected static void deliver (SSLEngine ssle , SocketChannel sc )
71
71
throws Exception {
72
72
73
- // create buufer .
73
+ // create buffer .
74
74
int appBufferMax = ssle .getSession ().getApplicationBufferSize ();
75
75
int netBufferMax = ssle .getSession ().getPacketBufferSize ();
76
76
int length = appBufferMax * (Integer .SIZE / 8 );
@@ -128,7 +128,7 @@ protected static void deliver(SSLEngine ssle, SocketChannel sc)
128
128
// maybe need to enlarge the local network packet buffer.
129
129
int size = ssle .getSession ().getPacketBufferSize ();
130
130
if (size > localNetData .capacity ()) {
131
- System .out .println ("resize destination buffer upto " +
131
+ System .out .println ("send: resize destination buffer upto " +
132
132
size + " bytes for BUFFER_OVERFLOW" );
133
133
localNetData = enlargeBuffer (localNetData , size );
134
134
}
@@ -143,16 +143,14 @@ protected static void deliver(SSLEngine ssle, SocketChannel sc)
143
143
144
144
145
145
// receive peer application data.
146
- protected static void receive (SSLEngine ssle , SocketChannel sc )
147
- throws Exception {
146
+ protected static void receive (SSLEngine ssle , SocketChannel sc ,
147
+ ByteBuffer peerNetData ) throws Exception {
148
148
149
- // create buufers .
149
+ // create buffer .
150
150
int appBufferMax = ssle .getSession ().getApplicationBufferSize ();
151
- int netBufferMax = ssle .getSession ().getPacketBufferSize ();
152
151
153
- // allocate less in order to check BUFFER_OVERFLOW/BUFFER_UNDERFLOW
152
+ // allocate less in order to check BUFFER_OVERFLOW
154
153
ByteBuffer peerAppData = ByteBuffer .allocate (appBufferMax /2 );
155
- ByteBuffer peerNetData = ByteBuffer .allocate (netBufferMax /2 );
156
154
int received = -1 ;
157
155
158
156
boolean needToReadMore = true ;
@@ -189,8 +187,8 @@ protected static void receive(SSLEngine ssle, SocketChannel sc)
189
187
190
188
System .out .println ("received " + peerAppData .position () +
191
189
" bytes client application data" );
192
- System .out .println ("\t comsumed " + res .bytesConsumed () +
193
- " byes network data" );
190
+ System .out .println ("\t consumed " + res .bytesConsumed () +
191
+ " bytes network data" );
194
192
peerAppData .clear ();
195
193
196
194
received -= res .bytesProduced ();
@@ -209,7 +207,7 @@ protected static void receive(SSLEngine ssle, SocketChannel sc)
209
207
// maybe need to enlarge the peer application data buffer.
210
208
int size = ssle .getSession ().getApplicationBufferSize ();
211
209
if (size > peerAppData .capacity ()) {
212
- System .out .println ("resize destination buffer upto " +
210
+ System .out .println ("recv: resize destination buffer upto " +
213
211
size + " bytes for BUFFER_OVERFLOW" );
214
212
peerAppData = enlargeBuffer (peerAppData , size );
215
213
}
@@ -219,8 +217,8 @@ protected static void receive(SSLEngine ssle, SocketChannel sc)
219
217
// maybe need to enlarge the peer network packet data buffer.
220
218
size = ssle .getSession ().getPacketBufferSize ();
221
219
if (size > peerNetData .capacity ()) {
222
- System .out .println ("resize source buffer upto " + size +
223
- " bytes for BUFFER_UNDERFLOW" );
220
+ System .out .println ("recv: resize source buffer upto " +
221
+ size + " bytes for BUFFER_UNDERFLOW" );
224
222
peerNetData = enlargeBuffer (peerNetData , size );
225
223
}
226
224
@@ -234,15 +232,16 @@ protected static void receive(SSLEngine ssle, SocketChannel sc)
234
232
}
235
233
}
236
234
237
- protected static void handshaking (SSLEngine ssle , SocketChannel sc ,
235
+ protected static ByteBuffer handshaking (SSLEngine ssle , SocketChannel sc ,
238
236
ByteBuffer additional ) throws Exception {
239
237
240
238
int appBufferMax = ssle .getSession ().getApplicationBufferSize ();
241
239
int netBufferMax = ssle .getSession ().getPacketBufferSize ();
242
240
241
+ // zero-byte app buffers - we do not want to exchange app data here
242
+ ByteBuffer localAppData = ByteBuffer .allocate (0 );
243
+ ByteBuffer peerAppData = ByteBuffer .allocate (0 );
243
244
// allocate less in order to check BUFFER_OVERFLOW/BUFFER_UNDERFLOW
244
- ByteBuffer localAppData = ByteBuffer .allocate (appBufferMax /10 );
245
- ByteBuffer peerAppData = ByteBuffer .allocate (appBufferMax /10 );
246
245
ByteBuffer localNetData = ByteBuffer .allocate (netBufferMax /10 );
247
246
ByteBuffer peerNetData = ByteBuffer .allocate (netBufferMax /10 );
248
247
@@ -272,15 +271,15 @@ protected static void handshaking(SSLEngine ssle, SocketChannel sc,
272
271
} else {
273
272
if (sc .read (peerNetData ) < 0 ) {
274
273
ssle .closeInbound ();
275
- return ;
274
+ throw new EOFException () ;
276
275
}
277
276
}
278
277
}
279
278
280
279
if (underflow ) {
281
280
if (sc .read (peerNetData ) < 0 ) {
282
281
ssle .closeInbound ();
283
- return ;
282
+ throw new EOFException () ;
284
283
}
285
284
286
285
underflow = false ;
@@ -298,7 +297,7 @@ protected static void handshaking(SSLEngine ssle, SocketChannel sc,
298
297
// maybe need to enlarge the peer network packet buffer.
299
298
int size = ssle .getSession ().getPacketBufferSize ();
300
299
if (size > peerNetData .capacity ()) {
301
- System .out .println ("resize source buffer upto " +
300
+ System .out .println ("hs recv: resize source buffer upto " +
302
301
size + " bytes for BUFFER_UNDERFLOW" );
303
302
peerNetData = enlargeBuffer (peerNetData , size );
304
303
}
@@ -309,7 +308,7 @@ protected static void handshaking(SSLEngine ssle, SocketChannel sc,
309
308
// maybe need to enlarge the peer application data buffer.
310
309
size = ssle .getSession ().getApplicationBufferSize ();
311
310
if (size > peerAppData .capacity ()) {
312
- System .out .println ("resize destination buffer upto " +
311
+ System .out .println ("hs recv: resize destination buffer upto " +
313
312
size + " bytes for BUFFER_OVERFLOW" );
314
313
peerAppData = enlargeBuffer (peerAppData , size );
315
314
}
@@ -346,7 +345,7 @@ protected static void handshaking(SSLEngine ssle, SocketChannel sc,
346
345
// maybe need to enlarge the local network packet buffer.
347
346
int size = ssle .getSession ().getPacketBufferSize ();
348
347
if (size > localNetData .capacity ()) {
349
- System .out .println ("resize destination buffer upto " +
348
+ System .out .println ("hs send: resize destination buffer upto " +
350
349
size + " bytes for BUFFER_OVERFLOW" );
351
350
localNetData = enlargeBuffer (localNetData , size );
352
351
}
@@ -371,6 +370,7 @@ protected static void handshaking(SSLEngine ssle, SocketChannel sc,
371
370
}
372
371
} while (hs != SSLEngineResult .HandshakeStatus .FINISHED &&
373
372
hs != SSLEngineResult .HandshakeStatus .NOT_HANDSHAKING );
373
+ return peerNetData ;
374
374
}
375
375
376
376
private static ByteBuffer enlargeBuffer (ByteBuffer buffer , int size ) {
0 commit comments