Firefly v4.6.3 is released

04 Dec 2017, Alvin Qiu

Firefly v4.6.3 is a patch release. It fixes the Conscrypt(1.0.0.RC13) compatibility problems. When I call the Conscrypt(1.0.0.RC13) sslEngine.unwrap(src, dst) method and the destination buffer remaining is 0, I encounter an EORException.

// if the dst.remaining() return 0, sslEngine will throw the EORException.
SSLEngineResult result = sslEngine.unwrap(src, receivedAppBuf);

In this case, the jdk default SSL engine provider will return the status is BUFFER_OVERFLOW. I only need to resize the destination buffer capacity. Such as:

while(true) {
  SSLEngineResult result = sslEngine.unwrap(src, receivedAppBuf);
  switch (result.getStatus()) {
    case BUFFER_OVERFLOW: {
      resizeAppBuffer();
      // retry the operation.
    }
    break;
  }
}

The resizeAppBuffer method:

protected void resizeAppBuffer() {
    int applicationBufferSize = sslEngine.getSession().getApplicationBufferSize();
    ByteBuffer b = newBuffer(receivedAppBuf.position() + applicationBufferSize);
    receivedAppBuf.flip();
    b.put(receivedAppBuf);
    receivedAppBuf = b;
}

If we want to adapt the Conscrypt(1.0.0.RC13), we need call resizeAppBuffer method before the unwrap method. Such as:

while(true) {
  if (!receivedAppBuf.hasRemaining()) { // for Conscrypt compatibility
      resizeAppBuffer();
  }
  SSLEngineResult result = sslEngine.unwrap(src, receivedAppBuf);
  switch (result.getStatus()) {
    case BUFFER_OVERFLOW: {
      resizeAppBuffer();
      // retry the operation.
    }
    break;
  }
}