當前位置: 首頁>>代碼示例>>Java>>正文


Java SSLEngineResult.getHandshakeStatus方法代碼示例

本文整理匯總了Java中javax.net.ssl.SSLEngineResult.getHandshakeStatus方法的典型用法代碼示例。如果您正苦於以下問題:Java SSLEngineResult.getHandshakeStatus方法的具體用法?Java SSLEngineResult.getHandshakeStatus怎麽用?Java SSLEngineResult.getHandshakeStatus使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.net.ssl.SSLEngineResult的用法示例。


在下文中一共展示了SSLEngineResult.getHandshakeStatus方法的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: 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

示例3: 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

示例4: runDelegatedTasks

import javax.net.ssl.SSLEngineResult; //導入方法依賴的package包/類
private void runDelegatedTasks(SSLEngineResult result) throws IOException {
	if(logger.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
		logger.logDebug("Running delegated task for " + result);
	}

	/*
	 *  Delegated tasks are just invisible steps inside the sslEngine state machine.
	 *  Call them every time they have NEED_TASK otherwise the sslEngine won't make progress
	 */
	if (result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
		Runnable runnable;
		while ((runnable = sslEngine.getDelegatedTask()) != null) {
			runnable.run();
		}
		HandshakeStatus hsStatus = sslEngine.getHandshakeStatus();
		if(logger.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
			logger.logDebug("Handshake status after delegated tasks " + hsStatus);
		}
		if (hsStatus == HandshakeStatus.NEED_TASK) {
			throw new IOException(
					"handshake shouldn't need additional tasks");
		}
	}
}
 
開發者ID:YunlongYang,項目名稱:LightSIP,代碼行數:25,代碼來源:SSLStateMachine.java

示例5: handshakeWrap

import javax.net.ssl.SSLEngineResult; //導入方法依賴的package包/類
/**
 * Performs the WRAP function
 * 
 * @param doWrite
 *            boolean
 * @return SSLEngineResult
 * @throws IOException
 */
protected SSLEngineResult handshakeWrap(boolean doWrite) throws IOException {
	// this should never be called with a network buffer that contains data
	// so we can clear it here.
	netOutBuffer.clear();
	// perform the wrap
	SSLEngineResult result = sslEngine.wrap(bufHandler.getWriteBuffer(), netOutBuffer);
	// prepare the results to be written
	netOutBuffer.flip();
	// set the status
	handshakeStatus = result.getHandshakeStatus();
	// optimization, if we do have a writable channel, write it now
	if (doWrite)
		flush(netOutBuffer);
	return result;
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:24,代碼來源:SecureNioChannel.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: 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:txazo,項目名稱:kafka,代碼行數:26,代碼來源:SslTransportLayer.java

示例8: unwrap

import javax.net.ssl.SSLEngineResult; //導入方法依賴的package包/類
public ByteBuf unwrap(SocketChannel channel, ByteBuf src) throws IOException {
    SSLEngine sslEngine = channel.getSSLEngine();
    ByteBuf dst = getTempDst(sslEngine);
    for (;;) {
        dst.clear();
        SSLEngineResult result = sslEngine.unwrap(src.nioBuffer(), dst.nioBuffer());
        HandshakeStatus handshakeStatus = result.getHandshakeStatus();
        synchByteBuf(result, src, dst);
        if (handshakeStatus != HandshakeStatus.NOT_HANDSHAKING) {
            if (handshakeStatus == HandshakeStatus.NEED_WRAP) {
                channel.doFlush(forgeFuture.duplicate());
                return null;
            } else if (handshakeStatus == HandshakeStatus.NEED_TASK) {
                runDelegatedTasks(sslEngine);
                continue;
            } else if (handshakeStatus == HandshakeStatus.FINISHED) {
                channel.finishHandshake(null);
                return null;
            } else if (handshakeStatus == HandshakeStatus.NEED_UNWRAP) {
                return null;
            }
        }
        return gc(channel, dst.flip());
    }
}
 
開發者ID:generallycloud,項目名稱:baseio,代碼行數:26,代碼來源:SslHandler.java

示例9: runDelegatedTasks

import javax.net.ssl.SSLEngineResult; //導入方法依賴的package包/類
private void runDelegatedTasks(SSLEngineResult result)
{
    if (result.getHandshakeStatus() == HandshakeStatus.NEED_TASK)
    {
        Runnable runnable;
        while ((runnable = _sslEngine.getDelegatedTask()) != null)
        {
            runnable.run();
        }

        HandshakeStatus hsStatus = _sslEngine.getHandshakeStatus();
        if (hsStatus == HandshakeStatus.NEED_TASK)
        {
            throw new RuntimeException("handshake shouldn't need additional tasks");
        }
    }
}
 
開發者ID:apache,項目名稱:qpid-proton-j,代碼行數:18,代碼來源:SimpleSslTransportWrapper.java

示例10: 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:how2j,項目名稱:lazycat,代碼行數:48,代碼來源:SecureNioChannel.java

示例11: 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

示例12: 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

示例13: handshakeWrap

import javax.net.ssl.SSLEngineResult; //導入方法依賴的package包/類
/**
 * Performs the WRAP function
 * @param doWrite boolean
 * @return SSLEngineResult
 * @throws IOException
 */
protected SSLEngineResult handshakeWrap(boolean doWrite) throws IOException {
    //this should never be called with a network buffer that contains data
    //so we can clear it here.
    netOutBuffer.clear();
    //perform the wrap
    SSLEngineResult result = sslEngine.wrap(bufHandler.getWriteBuffer(), netOutBuffer);
    //prepare the results to be written
    netOutBuffer.flip();
    //set the status
    handshakeStatus = result.getHandshakeStatus();
    //optimization, if we do have a writable channel, write it now
    if ( doWrite ) flush(netOutBuffer);
    return result;
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:21,代碼來源:SecureNioChannel.java

示例14: 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

示例15: 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


注:本文中的javax.net.ssl.SSLEngineResult.getHandshakeStatus方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。