当前位置: 首页>>代码示例>>Java>>正文


Java SSLEngineResult.getStatus方法代码示例

本文整理汇总了Java中javax.net.ssl.SSLEngineResult.getStatus方法的典型用法代码示例。如果您正苦于以下问题:Java SSLEngineResult.getStatus方法的具体用法?Java SSLEngineResult.getStatus怎么用?Java SSLEngineResult.getStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.net.ssl.SSLEngineResult的用法示例。


在下文中一共展示了SSLEngineResult.getStatus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: if

import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
/**
 * Encrypt provided buffer. Encrypted data returned by getOutNetBuffer().
 * 
 * @param src
 *            data to encrypt
 * @throws SSLException
 *             on errors
 */
/* no qualifier */void encrypt(ByteBuffer src) throws SSLException {
    if (!handshakeComplete) {
        throw new IllegalStateException();
    }

    if (!src.hasRemaining()) {
        if (outNetBuffer == null) {
            outNetBuffer = emptyBuffer;
        }
        return;
    }

    createOutNetBuffer(src.remaining());

    // Loop until there is no more data in src
    while (src.hasRemaining()) {

        SSLEngineResult result = sslEngine.wrap(src, outNetBuffer.buf());
        if (result.getStatus() == SSLEngineResult.Status.OK) {
            if (result.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NEED_TASK) {
                doTasks();
            }
        } else if (result.getStatus() == SSLEngineResult.Status.BUFFER_OVERFLOW) {
            outNetBuffer.capacity(outNetBuffer.capacity() << 1);
            outNetBuffer.limit(outNetBuffer.capacity());
        } else {
            throw new SSLException("SSLEngine error during encrypt: " + result.getStatus() + " src: " + src
                    + "outNetBuffer: " + outNetBuffer);
        }
    }

    outNetBuffer.flip();
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:42,代码来源:SslHandler.java

示例2: checkStatus

import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
/**
 * @param res
 * @throws SSLException
 */
private void checkStatus(SSLEngineResult res) throws SSLException {

    SSLEngineResult.Status status = res.getStatus();

    /*
     * The status may be:
     * OK - Normal operation
     * OVERFLOW - Should never happen since the application buffer is sized to hold the maximum
     * packet size.
     * UNDERFLOW - Need to read more data from the socket. It's normal.
     * CLOSED - The other peer closed the socket. Also normal.
     */
    if (status == SSLEngineResult.Status.BUFFER_OVERFLOW) {
        throw new SSLException("SSLEngine error during decrypt: " + status + " inNetBuffer: " + inNetBuffer
                + "appBuffer: " + appBuffer);
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:22,代码来源:SslHandler.java

示例3: checkResult

import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
private void checkResult(SSLEngineResult result, boolean wrap)
        throws SSLException {

    handshakeStatus = result.getHandshakeStatus();
    resultStatus = result.getStatus();

    if (resultStatus != Status.OK &&
            (wrap || resultStatus != Status.BUFFER_UNDERFLOW)) {
        throw new SSLException("TODO");
    }
    if (wrap && result.bytesConsumed() != 0) {
        throw new SSLException("TODO");
    }
    if (!wrap && result.bytesProduced() != 0) {
        throw new SSLException("TODO");
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:18,代码来源:AsyncChannelWrapperSecure.java

示例4: close

import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
/**
 * Sends a SSL close message, will not physically close the connection here.<br>
 * To close the connection, you could do something like
 * <pre><code>
 *   close();
 *   while (isOpen() && !myTimeoutFunction()) Thread.sleep(25);
 *   if ( isOpen() ) close(true); //forces a close if you timed out
 * </code></pre>
 * @throws IOException if an I/O error occurs
 * @throws IOException if there is data on the outgoing network buffer and we are unable to flush it
 * TODO Implement this java.io.Closeable method
 */
@Override
public void close() throws IOException {
    if (closing) return;
    closing = true;
    sslEngine.closeOutbound();

    if (!flush(netOutBuffer)) {
        throw new IOException("Remaining data in the network buffer, can't send SSL close message, force a close with close(true) instead");
    }
    //prep the buffer for the close message
    netOutBuffer.clear();
    //perform the close, since we called sslEngine.closeOutbound
    SSLEngineResult handshake = sslEngine.wrap(getEmptyBuf(), netOutBuffer);
    //we should be in a close state
    if (handshake.getStatus() != SSLEngineResult.Status.CLOSED) {
        throw new IOException("Invalid close state, will not send network data.");
    }
    //prepare the buffer for writing
    netOutBuffer.flip();
    //if there is data to be written
    flush(netOutBuffer);

    //is the channel closed?
    closed = (!netOutBuffer.hasRemaining() && (handshake.getHandshakeStatus() != HandshakeStatus.NEED_WRAP));
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:38,代码来源:SecureNioChannel.java

示例5: handshakeWrap

import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
/**
* Performs the WRAP function
* @param doWrite boolean
* @return SSLEngineResult
* @throws IOException
*/
private SSLEngineResult handshakeWrap(boolean doWrite) throws IOException {
    log.trace("SSLHandshake handshakeWrap {}", channelId);
    if (netWriteBuffer.hasRemaining())
        throw new IllegalStateException("handshakeWrap called with netWriteBuffer not empty");
    //this should never be called with a network buffer that contains data
    //so we can clear it here.
    netWriteBuffer.clear();
    SSLEngineResult result = sslEngine.wrap(emptyBuf, netWriteBuffer);
    //prepare the results to be written
    netWriteBuffer.flip();
    handshakeStatus = result.getHandshakeStatus();
    if (result.getStatus() == SSLEngineResult.Status.OK &&
        result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
        handshakeStatus = runDelegatedTasks();
    }

    if (doWrite) flush(netWriteBuffer);
    return result;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:26,代码来源:SslTransportLayer.java

示例6: handshakeUnwrap

import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
/**
* Perform handshake unwrap
* @param doRead boolean
* @return SSLEngineResult
* @throws IOException
*/
private SSLEngineResult handshakeUnwrap(boolean doRead) throws IOException {
    log.trace("SSLHandshake handshakeUnwrap {}", channelId);
    SSLEngineResult result;
    if (doRead)  {
        int read = socketChannel.read(netReadBuffer);
        if (read == -1) throw new EOFException("EOF during handshake.");
    }
    boolean cont;
    do {
        //prepare the buffer with the incoming data
        netReadBuffer.flip();
        result = sslEngine.unwrap(netReadBuffer, appReadBuffer);
        netReadBuffer.compact();
        handshakeStatus = result.getHandshakeStatus();
        if (result.getStatus() == SSLEngineResult.Status.OK &&
            result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
            handshakeStatus = runDelegatedTasks();
        }
        cont = result.getStatus() == SSLEngineResult.Status.OK &&
            handshakeStatus == HandshakeStatus.NEED_UNWRAP;
        log.trace("SSLHandshake handshakeUnwrap: handshakeStatus {} status {}", handshakeStatus, result.getStatus());
    } while (netReadBuffer.position() != 0 && cont);

    return result;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:32,代码来源:SslTransportLayer.java

示例7: checkResult

import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
private void checkResult(SSLEngineResult result, boolean wrap) throws SSLException {

			handshakeStatus = result.getHandshakeStatus();
			resultStatus = result.getStatus();

			if (resultStatus != Status.OK && (wrap || resultStatus != Status.BUFFER_UNDERFLOW)) {
				throw new SSLException("TODO");
			}
			if (wrap && result.bytesConsumed() != 0) {
				throw new SSLException("TODO");
			}
			if (!wrap && result.bytesProduced() != 0) {
				throw new SSLException("TODO");
			}
		}
 
开发者ID:how2j,项目名称:lazycat,代码行数:16,代码来源:AsyncChannelWrapperSecure.java

示例8: renegotiateIfNeeded

import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
private void renegotiateIfNeeded(NextFilter nextFilter, SSLEngineResult res) throws SSLException {
    if ((res.getStatus() != SSLEngineResult.Status.CLOSED)
            && (res.getStatus() != SSLEngineResult.Status.BUFFER_UNDERFLOW)
            && (res.getHandshakeStatus() != SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING)) {
        // Renegotiation required.
        handshakeComplete = false;
        handshakeStatus = res.getHandshakeStatus();
        handshake(nextFilter);
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:11,代码来源:SslHandler.java

示例9: checkResult

import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
/**
 * Checks that status of result {@code r} is {@code wantedStatus}.
 *
 * @param r            - Result.
 * @param wantedStatus - Wanted status of the result.
 * @throws AssertionError - if status or {@code r} is not
 *                        {@code wantedStatus}.
 */
public static void checkResult(SSLEngineResult r,
                               SSLEngineResult.Status wantedStatus) {
    SSLEngineResult.Status rs = r.getStatus();
    if (!rs.equals(wantedStatus)) {
        throw new AssertionError("Unexpected status " + rs.name()
                + ", should be " + wantedStatus.name());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:SSLEngineTestCase.java

示例10: handshakeUnwrap

import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
/**
 * Perform handshake unwrap
 * @param doread boolean
 * @return SSLEngineResult
 * @throws IOException
 */
protected SSLEngineResult handshakeUnwrap(boolean doread) throws IOException {

    if (netInBuffer.position() == netInBuffer.limit()) {
        //clear the buffer if we have emptied it out on data
        netInBuffer.clear();
    }
    if ( doread )  {
        //if we have data to read, read it
        int read = sc.read(netInBuffer);
        if (read == -1) throw new IOException("EOF encountered during handshake.");
    }
    SSLEngineResult result;
    boolean cont = false;
    //loop while we can perform pure SSLEngine data
    do {
        //prepare the buffer with the incoming data
        netInBuffer.flip();
        //call unwrap
        result = sslEngine.unwrap(netInBuffer, bufHandler.getReadBuffer());
        //compact the buffer, this is an optional method, wonder what would happen if we didn't
        netInBuffer.compact();
        //read in the status
        handshakeStatus = result.getHandshakeStatus();
        if ( result.getStatus() == SSLEngineResult.Status.OK &&
             result.getHandshakeStatus() == HandshakeStatus.NEED_TASK ) {
            //execute tasks if we need to
            handshakeStatus = tasks();
        }
        //perform another unwrap?
        cont = result.getStatus() == SSLEngineResult.Status.OK &&
               handshakeStatus == HandshakeStatus.NEED_UNWRAP;
    }while ( cont );
    return result;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:41,代码来源:SecureNioChannel.java

示例11: shutdown

import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
public void shutdown() throws IOException {

		//if (!shutdown) {
		//            sslEngine.closeOutbound();
		//  shutdown = true;
		//}

		if (outNetBB.hasRemaining() && tryFlush(outNetBB)) {
			//return false;
		}

		/*
		 * By RFC 2616, we can "fire and forget" our close_notify
		 * message, so that's what we'll do here.
		 */
		for(int i = 0; i<3 && !engine.isInboundDone(); i++){ //3 retry

			engine.closeOutbound();
			outNetBB.clear();
			SSLEngineResult result = engine.wrap(hsBB, outNetBB);
			if (result.getStatus() != Status.CLOSED) {
				throw new SSLException("Improper close state");
			}
			outNetBB.flip();

			/*
			 * We won't wait for a select here, but if this doesn't work,
			 * we'll cycle back through on the next select.
			 */
			if (outNetBB.hasRemaining()) {
				tryFlush(outNetBB);
			}
		}
		conn.setTLS(null);

	}
 
开发者ID:Anoncheg1,项目名称:dibd,代码行数:37,代码来源:TLS.java

示例12: handshakeUnwrap

import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
/**
 * Perform handshake unwrap
 * 
 * @param doread
 *            boolean
 * @return SSLEngineResult
 * @throws IOException
 */
protected SSLEngineResult handshakeUnwrap(boolean doread) throws IOException {

	if (netInBuffer.position() == netInBuffer.limit()) {
		// clear the buffer if we have emptied it out on data
		netInBuffer.clear();
	}
	if (doread) {
		// if we have data to read, read it
		int read = sc.read(netInBuffer);
		if (read == -1)
			throw new IOException("EOF encountered during handshake.");
	}
	SSLEngineResult result;
	boolean cont = false;
	// loop while we can perform pure SSLEngine data
	do {
		// prepare the buffer with the incoming data
		netInBuffer.flip();
		// call unwrap
		result = sslEngine.unwrap(netInBuffer, bufHandler.getReadBuffer());
		// compact the buffer, this is an optional method, wonder what would
		// happen if we didn't
		netInBuffer.compact();
		// read in the status
		handshakeStatus = result.getHandshakeStatus();
		if (result.getStatus() == SSLEngineResult.Status.OK
				&& result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
			// execute tasks if we need to
			handshakeStatus = tasks();
		}
		// perform another unwrap?
		cont = result.getStatus() == SSLEngineResult.Status.OK && handshakeStatus == HandshakeStatus.NEED_UNWRAP;
	} while (cont);
	return result;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:44,代码来源:SecureNioChannel.java

示例13: close

import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
/**
* Sends a SSL close message and closes socketChannel.
*/
@Override
public void close() throws IOException {
    if (closing) return;
    closing = true;
    sslEngine.closeOutbound();
    try {
        if (isConnected()) {
            if (!flush(netWriteBuffer)) {
                throw new IOException("Remaining data in the network buffer, can't send SSL close message.");
            }
            //prep the buffer for the close message
            netWriteBuffer.clear();
            //perform the close, since we called sslEngine.closeOutbound
            SSLEngineResult wrapResult = sslEngine.wrap(emptyBuf, netWriteBuffer);
            //we should be in a close state
            if (wrapResult.getStatus() != SSLEngineResult.Status.CLOSED) {
                throw new IOException("Unexpected status returned by SSLEngine.wrap, expected CLOSED, received " +
                        wrapResult.getStatus() + ". Will not send close message to peer.");
            }
            netWriteBuffer.flip();
            flush(netWriteBuffer);
        }
    } catch (IOException ie) {
        log.warn("Failed to send SSL Close message ", ie);
    } finally {
        try {
            socketChannel.socket().close();
            socketChannel.close();
        } finally {
            key.attach(null);
            key.cancel();
        }
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:38,代码来源:SslTransportLayer.java

示例14: write

import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
/**
* Writes a sequence of bytes to this channel from the given buffer.
*
* @param src The buffer from which bytes are to be retrieved
* @return The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream
* @throws IOException If some other I/O error occurs
*/
@Override
public int write(ByteBuffer src) throws IOException {
    int written = 0;
    if (closing) throw new IllegalStateException("Channel is in closing state");
    if (!handshakeComplete) return written;

    if (!flush(netWriteBuffer))
        return written;

    netWriteBuffer.clear();
    SSLEngineResult wrapResult = sslEngine.wrap(src, netWriteBuffer);
    netWriteBuffer.flip();

    //handle ssl renegotiation
    if (wrapResult.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING && wrapResult.getStatus() == Status.OK) {
        renegotiate();
        return written;
    }

    if (wrapResult.getStatus() == Status.OK) {
        written = wrapResult.bytesConsumed();
        flush(netWriteBuffer);
    } else if (wrapResult.getStatus() == Status.BUFFER_OVERFLOW) {
        int currentNetWriteBufferSize = netWriteBufferSize();
        netWriteBuffer.compact();
        netWriteBuffer = Utils.ensureCapacity(netWriteBuffer, currentNetWriteBufferSize);
        netWriteBuffer.flip();
        if (netWriteBuffer.limit() >= currentNetWriteBufferSize)
            throw new IllegalStateException("SSL BUFFER_OVERFLOW when available data size (" + netWriteBuffer.limit() + ") >= network buffer size (" + currentNetWriteBufferSize + ")");
    } else if (wrapResult.getStatus() == Status.BUFFER_UNDERFLOW) {
        throw new IllegalStateException("SSL BUFFER_UNDERFLOW during write");
    } else if (wrapResult.getStatus() == Status.CLOSED) {
        throw new EOFException();
    }
    return written;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:44,代码来源:SslTransportLayer.java

示例15: handshakeUnwrap

import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
/**
* Perform handshake unwrap
* @param doRead boolean
* @return SSLEngineResult
* @throws IOException
*/
private SSLEngineResult handshakeUnwrap(boolean doRead) throws IOException {
    log.trace("SSLHandshake handshakeUnwrap {}", channelId);
    SSLEngineResult result;
    boolean cont = false;
    int read = 0;
    if (doRead)  {
        read = socketChannel.read(netReadBuffer);
        if (read == -1) throw new EOFException("EOF during handshake.");
    }
    do {
        //prepare the buffer with the incoming data
        netReadBuffer.flip();
        result = sslEngine.unwrap(netReadBuffer, appReadBuffer);
        netReadBuffer.compact();
        handshakeStatus = result.getHandshakeStatus();
        if (result.getStatus() == SSLEngineResult.Status.OK &&
            result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
            handshakeStatus = runDelegatedTasks();
        }
        cont = result.getStatus() == SSLEngineResult.Status.OK &&
            handshakeStatus == HandshakeStatus.NEED_UNWRAP;
        log.trace("SSLHandshake handshakeUnwrap: handshakeStatus {} status {}", handshakeStatus, result.getStatus());
    } while (netReadBuffer.position() != 0 && cont);

    return result;
}
 
开发者ID:txazo,项目名称:kafka,代码行数:33,代码来源:SslTransportLayer.java


注:本文中的javax.net.ssl.SSLEngineResult.getStatus方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。