|
70 | 70 | import java.util.concurrent.CyclicBarrier; |
71 | 71 | import java.util.concurrent.BrokenBarrierException; |
72 | 72 | import java.util.concurrent.atomic.AtomicIntegerArray; |
| 73 | +import static org.junit.Assert.assertArrayEquals; |
73 | 74 | import static org.junit.Assert.assertEquals; |
74 | 75 | import static org.junit.Assert.assertNotNull; |
75 | 76 | import static org.junit.Assert.fail; |
@@ -3347,5 +3348,76 @@ public void testWrapPartialDrainOffsetUpdate() |
3347 | 3348 | fail("drained output does not match injected queue"); |
3348 | 3349 | } |
3349 | 3350 | } |
| 3351 | + |
| 3352 | + /* Regression: closeOutbound() before handshake must also close |
| 3353 | + * inbound, otherwise isInboundDone() never returns true. */ |
| 3354 | + @Test |
| 3355 | + public void testCloseOutboundBeforeHandshake() throws Exception { |
| 3356 | + this.ctx = tf.createSSLContext("TLS", engineProvider); |
| 3357 | + SSLEngine e = this.ctx.createSSLEngine(); |
| 3358 | + e.setUseClientMode(true); |
| 3359 | + e.closeOutbound(); |
| 3360 | + assertTrue(e.isOutboundDone()); |
| 3361 | + assertTrue(e.isInboundDone()); |
| 3362 | + } |
| 3363 | + |
| 3364 | + /* Regression for wrap(ByteBuffer[], ofst, len, out) when ofst > 0: |
| 3365 | + * pos[]/limit[] OOB and null-check loop bound. */ |
| 3366 | + @Test |
| 3367 | + public void testWrapWithBufferArrayOffset() throws Exception { |
| 3368 | + this.ctx = tf.createSSLContext("TLS", engineProvider); |
| 3369 | + SSLEngine server = this.ctx.createSSLEngine(); |
| 3370 | + SSLEngine client = this.ctx.createSSLEngine("wolfSSL test", 11111); |
| 3371 | + server.setUseClientMode(false); |
| 3372 | + client.setUseClientMode(true); |
| 3373 | + server.beginHandshake(); |
| 3374 | + client.beginHandshake(); |
| 3375 | + assertEquals(0, tf.testConnection(server, client, null, null, "x")); |
| 3376 | + |
| 3377 | + byte[] payload = "real-payload".getBytes(); |
| 3378 | + ByteBuffer[] in = {ByteBuffer.wrap("DECOY".getBytes()), |
| 3379 | + ByteBuffer.wrap(payload)}; |
| 3380 | + ByteBuffer net = ByteBuffer.allocateDirect( |
| 3381 | + client.getSession().getPacketBufferSize()); |
| 3382 | + |
| 3383 | + SSLEngineResult r = client.wrap(in, 1, 1, net); |
| 3384 | + assertEquals(SSLEngineResult.Status.OK, r.getStatus()); |
| 3385 | + assertEquals(0, in[0].position()); |
| 3386 | + assertEquals(payload.length, in[1].position()); |
| 3387 | + |
| 3388 | + net.flip(); |
| 3389 | + ByteBuffer plain = ByteBuffer.allocate( |
| 3390 | + server.getSession().getApplicationBufferSize()); |
| 3391 | + assertEquals(SSLEngineResult.Status.OK, |
| 3392 | + server.unwrap(net, plain).getStatus()); |
| 3393 | + plain.flip(); |
| 3394 | + byte[] got = new byte[plain.remaining()]; |
| 3395 | + plain.get(got); |
| 3396 | + assertArrayEquals(payload, got); |
| 3397 | + } |
| 3398 | + |
| 3399 | + /* Direct regression: wrap() null-check must reach in[ofst+len-1]. */ |
| 3400 | + @Test(expected = SSLException.class) |
| 3401 | + public void testWrapRejectsNullAtOffset() throws Exception { |
| 3402 | + this.ctx = tf.createSSLContext("TLS", engineProvider); |
| 3403 | + SSLEngine c = this.ctx.createSSLEngine("wolfSSL test", 11111); |
| 3404 | + c.setUseClientMode(true); |
| 3405 | + ByteBuffer[] in = {ByteBuffer.wrap("x".getBytes()), null}; |
| 3406 | + c.wrap(in, 1, 1, ByteBuffer.allocateDirect( |
| 3407 | + c.getSession().getPacketBufferSize())); |
| 3408 | + } |
| 3409 | + |
| 3410 | + /* Direct regression: unwrap() readOnly-check must reach |
| 3411 | + * out[ofst+length-1]. */ |
| 3412 | + @Test(expected = java.nio.ReadOnlyBufferException.class) |
| 3413 | + public void testUnwrapRejectsReadOnlyAtOffset() throws Exception { |
| 3414 | + this.ctx = tf.createSSLContext("TLS", engineProvider); |
| 3415 | + SSLEngine s = this.ctx.createSSLEngine(); |
| 3416 | + s.setUseClientMode(false); |
| 3417 | + ByteBuffer[] out = {ByteBuffer.allocate(64), |
| 3418 | + ByteBuffer.allocate(64).asReadOnlyBuffer()}; |
| 3419 | + s.unwrap(ByteBuffer.allocateDirect( |
| 3420 | + s.getSession().getPacketBufferSize()), out, 1, 1); |
| 3421 | + } |
3350 | 3422 | } |
3351 | 3423 |
|
0 commit comments