-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: 3.12.11
-
Component/s: None
-
None
-
None
-
Java Drivers
-
None
-
None
-
None
-
None
-
None
-
None
When communicating with KMS for CSFLE, theĀ Crypt.decryptKey wraps bytes read from the KMS TLS stream using:
ByteBuffer.wrap(bytes, 0, bytesRead);
If InputStream.read(...) on the KMS connection returns -1 (EOF), bytesRead is negative and ByteBuffer.wrap(...) throws IndexOutOfBoundsException with no message. This surfaces to users as:
java.lang.IndexOutOfBoundsException: null at java.nio.ByteBuffer.wrap(...) at com.mongodb.client.internal.Crypt.decryptKey(...) ... com.mongodb.MongoClientException: Exception in encryption library: null
Proposed change
Throw a more informative exception, for example: MongoClientException("Unexpected EOF while communicating with KMS")
Acceptance criteria
- When KMS closes the TLS stream unexpectedly (EOF), the driver no longer throws a bare IndexOutOfBoundsException: null.
- The exception surfaced to the user clearly indicates an unexpected EOF / failure while communicating with KMS.
- Existing successful FLE/KMS behavior is unchanged.