private ByteBuffer sslDataWrap ( ByteBuffer inBBuff , ByteBuffer outBBuff ) throws GSSException { try { if ( sslEngine . getHandshakeStatus ( ) != SSLEngineResult . HandshakeStatus . NOT_HANDSHAKING ) { throw new Exception ( "SSLEngine handshaking needed! " + "HandshakeStatus: " + sslEngine . getHandshakeStatus ( ) . toString ( ) ) ; } int iter = 0 ; do { logger . debug ( "PROCESSING DATA (WRAP) " + ++ iter + ": " + inBBuff . remaining ( ) ) ; SSLEngineResult result = sslEngine . wrap ( inBBuff , outBBuff ) ; if ( result . getHandshakeStatus ( ) == SSLEngineResult . HandshakeStatus . NEED_TASK ) { runDelegatedTasks ( sslEngine ) ; continue ; } if ( result . getStatus ( ) == SSLEngineResult . Status . BUFFER_OVERFLOW ) { // just increase it to the size needed. int pktSize = sslEngine . getSession ( ) . getPacketBufferSize ( ) ; ByteBuffer b = ByteBuffer . allocate ( pktSize + outBBuff . position ( ) ) ; outBBuff . flip ( ) ; b . put ( outBBuff ) ; outBBuff = b ; continue ; } else if ( result . getStatus ( ) == SSLEngineResult . Status . BUFFER_UNDERFLOW ) { throw new GlobusGSSException ( GSSException . FAILURE , new Exception ( "Unexpected BUFFER_UNDERFLOW;" + " Handshaking status: " + sslEngine . getHandshakeStatus ( ) ) ) ; } if ( result . getStatus ( ) != SSLEngineResult . Status . OK ) { throw new GlobusGSSException ( GSSException . FAILURE , GlobusGSSException . TOKEN_FAIL , result . getStatus ( ) . toString ( ) ) ; } } while ( inBBuff . hasRemaining ( ) ) ; return outBBuff ; } catch ( Exception e ) { throw new GlobusGSSException ( GSSException . FAILURE , e ) ; } }
Meant for non - handshake processing