amannm/iocp-https-server

Delete

threat opened this issue · 0 comments

Steps to reproduce:

  1. Start Main.java
  2. Go to https://localhost:1234 in your browser

Output:

HTTPS /127.0.0.1:53553 << New connection
HTTPS /127.0.0.1:53553 << >> TLS handshaking...Starting handshake
NEED UNWRAP
Run Task
NEED WRAP
Produced: 1334
Sending Bytes
NEED UNWRAP
Unwrapping issue: BUFFER_UNDERFLOW
HTTPS << /127.0.0.1:53553 -- SSL handshake failed. Terminating Connection...

HTTPS /127.0.0.1:53554 << New connection
HTTPS /127.0.0.1:53554 << >> TLS handshaking...Starting handshake
NEED UNWRAP
Run Task
NEED WRAP
Produced: 1334
Sending Bytes
NEED UNWRAP
Unwrapping issue: BUFFER_UNDERFLOW
HTTPS << /127.0.0.1:53554 -- SSL handshake failed. Terminating Connection...

I believe you have to resize the buffer and try again. i.e.

private int appBBSize;
private int netBBSize;
private ByteBuffer inNetBB;
private ByteBuffer outNetBB;      

case BUFFER_UNDERFLOW:
netBBSize = sslEngine.getSession().getPacketBufferSize();
    if (netBBSize > inNetBB.capacity()) {
        ByteBuffer bb = ByteBuffer.allocate(netBBSize); //Resize
        inNetBB.flip();
        bb.put(inNetBB);
        inNetBB = bb;
        break; //Try again
    }