Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SSLEngine usage issue: handshake done, but unwrap returns 8 bytes from 32

KarelGardasNov 19 2010 — edited Nov 19 2010
Hello,
I'm trying to use SSLEngine API in order to secure Java/NIO based 3th party middle-ware platform. So far I've succeed with writing correct handshake code and on both server and client I get handshake successfully done, the problem starts when client sends server its message. It is 32 bytes long encrypted on the client side to 37 bytes. On the server side I see (while using -Djavax.net.debug=all) that during the SSLEngine.unwrap call the bytes are correctly decrypted into exact byte sequence as on the client side. However, the problem is that from SSLEngine.unwrap I get just 8 bytes instead of those 32. The debug messages looks:

[Raw read (bb)]: length = 37
0000: 17 03 01 00 20 56 68 6E 1F 56 C1 41 6E CD C0 A4 .... Vhn.V.An...
0010: F0 84 6A E9 C8 4F A9 AE 29 AF 87 D9 EA 61 09 15 ..j..O..)....a..
0020: EC 08 28 1E 60 ..(.`
Padded plaintext after DECRYPTION: len = 32
0000: 02 00 01 00 03 63 64 6F E3 06 78 5A D6 9C D4 D0 .....cdo..xZ....
0010: 68 B1 F7 B1 7F 34 88 AC 36 1C 7A 72 03 03 03 03 h....4..6.zr....
*** SERVER: peerNetBuf after unwrap: java.nio.HeapByteBuffer[pos=37 lim=37 cap=16665]
*** SERVER: res: Status = OK HandshakeStatus = NOT_HANDSHAKING
bytesConsumed = 37 bytesProduced = 8

Messages starting with *** SERVER are of my application. Everything other is emitted by Java while using -Djavax.net.debug=all. As you can see all data from peerNetBuf which is a buffer holding encrypted data got from network, so all those data are consumed well -- so I don't need to call unwrap second time like it sometimes happen during the handshake phase...

Now, my question is: how to convince SSLEngine.unwrap to correctly return me all those 32 bytes which I expect?

Thanks,
Karel
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 17 2010
Added on Nov 19 2010
1 comment
376 views