Search in sources :

Example 56 with SSLEngineResult

use of javax.net.ssl.SSLEngineResult in project ignite by apache.

the class GridNioSslHandler method unwrapHandshake.

/**
     * Unwraps handshake data and processes it.
     *
     * @return Status.
     * @throws SSLException If SSL exception occurred while unwrapping.
     * @throws GridNioException If failed to pass event to the next filter.
     */
private Status unwrapHandshake() throws SSLException, IgniteCheckedException {
    // Flip input buffer so we can read the collected data.
    inNetBuf.flip();
    SSLEngineResult res = unwrap0();
    handshakeStatus = res.getHandshakeStatus();
    checkStatus(res);
    // try to unwrap more
    if (handshakeStatus == FINISHED && res.getStatus() == Status.OK && inNetBuf.hasRemaining()) {
        res = unwrap0();
        handshakeStatus = res.getHandshakeStatus();
        // prepare to be written again
        inNetBuf.compact();
        renegotiateIfNeeded(res);
    } else
        // prepare to be written again
        inNetBuf.compact();
    return res.getStatus();
}
Also used : SSLEngineResult(javax.net.ssl.SSLEngineResult)

Example 57 with SSLEngineResult

use of javax.net.ssl.SSLEngineResult in project ignite by apache.

the class GridNioSslHandler method unwrapData.

/**
     * Unwraps user data to the application buffer.
     *
     * @throws SSLException If failed to process SSL data.
     * @throws GridNioException If failed to pass events to the next filter.
     */
private void unwrapData() throws IgniteCheckedException, SSLException {
    if (log.isDebugEnabled())
        log.debug("Unwrapping received data: " + ses);
    // Flip buffer so we can read it.
    inNetBuf.flip();
    SSLEngineResult res = unwrap0();
    // prepare to be written again
    inNetBuf.compact();
    checkStatus(res);
    renegotiateIfNeeded(res);
}
Also used : SSLEngineResult(javax.net.ssl.SSLEngineResult)

Example 58 with SSLEngineResult

use of javax.net.ssl.SSLEngineResult in project ignite by apache.

the class BlockingSslHandler method unwrapData.

/**
     * Unwraps user data to the application buffer.
     *
     * @throws SSLException If failed to process SSL data.
     * @throws GridNioException If failed to pass events to the next filter.
     */
private void unwrapData() throws IgniteCheckedException, SSLException {
    if (log.isDebugEnabled())
        log.debug("Unwrapping received data.");
    // Flip buffer so we can read it.
    inNetBuf.flip();
    SSLEngineResult res = unwrap0();
    // prepare to be written again
    inNetBuf.compact();
    checkStatus(res);
    renegotiateIfNeeded(res);
}
Also used : SSLEngineResult(javax.net.ssl.SSLEngineResult)

Example 59 with SSLEngineResult

use of javax.net.ssl.SSLEngineResult in project ignite by apache.

the class BlockingSslHandler method unwrapHandshake.

/**
     * Unwraps handshake data and processes it.
     *
     * @return Status.
     * @throws SSLException If SSL exception occurred while unwrapping.
     * @throws GridNioException If failed to pass event to the next filter.
     */
private Status unwrapHandshake() throws SSLException, IgniteCheckedException {
    // Flip input buffer so we can read the collected data.
    readFromNet();
    inNetBuf.flip();
    SSLEngineResult res = unwrap0();
    handshakeStatus = res.getHandshakeStatus();
    checkStatus(res);
    // try to unwrap more
    if (handshakeStatus == FINISHED && res.getStatus() == OK && inNetBuf.hasRemaining()) {
        res = unwrap0();
        handshakeStatus = res.getHandshakeStatus();
        // prepare to be written again
        inNetBuf.compact();
        renegotiateIfNeeded(res);
    } else if (res.getStatus() == BUFFER_UNDERFLOW) {
        inNetBuf.compact();
        inNetBuf = expandBuffer(inNetBuf, inNetBuf.capacity() * 2);
    } else
        // prepare to be written again
        inNetBuf.compact();
    return res.getStatus();
}
Also used : SSLEngineResult(javax.net.ssl.SSLEngineResult)

Example 60 with SSLEngineResult

use of javax.net.ssl.SSLEngineResult in project ignite by apache.

the class GridNioSslHandler method closeOutbound.

/**
     * Writes close_notify message to the network output buffer.
     *
     * @throws SSLException If wrap failed or SSL engine does not get closed
     * after wrap.
     * @return {@code True} if <tt>close_notify</tt> message was encoded, {@code false} if outbound
     *      stream was already closed.
     */
boolean closeOutbound() throws SSLException {
    assert isHeldByCurrentThread();
    if (!sslEngine.isOutboundDone()) {
        sslEngine.closeOutbound();
        outNetBuf.clear();
        SSLEngineResult res = sslEngine.wrap(handshakeBuf, outNetBuf);
        if (res.getStatus() != CLOSED)
            throw new SSLException("Incorrect SSL engine status after closeOutbound call [status=" + res.getStatus() + ", handshakeStatus=" + res.getHandshakeStatus() + ", ses=" + ses + ']');
        outNetBuf.flip();
        return true;
    }
    return false;
}
Also used : SSLEngineResult(javax.net.ssl.SSLEngineResult) SSLException(javax.net.ssl.SSLException)

Aggregations

SSLEngineResult (javax.net.ssl.SSLEngineResult)131 ByteBuffer (java.nio.ByteBuffer)53 IOException (java.io.IOException)31 SSLException (javax.net.ssl.SSLException)29 SSLEngine (javax.net.ssl.SSLEngine)23 Test (org.junit.Test)13 ReadOnlyBufferException (java.nio.ReadOnlyBufferException)12 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)10 EOFException (java.io.EOFException)7 HandshakeStatus (javax.net.ssl.SSLEngineResult.HandshakeStatus)7 ByteBuf (io.netty.buffer.ByteBuf)6 SSLSession (javax.net.ssl.SSLSession)6 WritePendingException (java.nio.channels.WritePendingException)5 KeyManagementException (java.security.KeyManagementException)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 ExecutionException (java.util.concurrent.ExecutionException)5 TimeoutException (java.util.concurrent.TimeoutException)5 CompositeByteBuf (io.netty.buffer.CompositeByteBuf)4 Status (javax.net.ssl.SSLEngineResult.Status)4 BufferUnderflowException (java.nio.BufferUnderflowException)3