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


Java HandshakeStatus.FINISHED属性代码示例

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


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

示例1: handshakeFinished

/**
 * Checks if the handshake status is finished
 * Sets the interestOps for the selectionKey.
 */
private void handshakeFinished() throws IOException {
    // SSLEngine.getHandshakeStatus is transient and it doesn't record FINISHED status properly.
    // It can move from FINISHED status to NOT_HANDSHAKING after the handshake is completed.
    // Hence we also need to check handshakeResult.getHandshakeStatus() if the handshake finished or not
    if (handshakeResult.getHandshakeStatus() == HandshakeStatus.FINISHED) {
        //we are complete if we have delivered the last package
        handshakeComplete = !netWriteBuffer.hasRemaining();
        //remove OP_WRITE if we are complete, otherwise we still have data to write
        if (!handshakeComplete)
            key.interestOps(key.interestOps() | SelectionKey.OP_WRITE);
        else {
            key.interestOps(key.interestOps() & ~SelectionKey.OP_WRITE);
            SSLSession session = sslEngine.getSession();
            log.debug("SSL handshake completed successfully with peerHost '{}' peerPort {} peerPrincipal '{}' cipherSuite '{}'",
                    session.getPeerHost(), session.getPeerPort(), peerPrincipal(), session.getCipherSuite());
        }

        log.trace("SSLHandshake FINISHED channelId {}, appReadBuffer pos {}, netReadBuffer pos {}, netWriteBuffer pos {} ",
                  channelId, appReadBuffer.position(), netReadBuffer.position(), netWriteBuffer.position());
    } else {
        throw new IOException("NOT_HANDSHAKING during handshake");
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:27,代码来源:SslTransportLayer.java

示例2: sendData

/**
 * send the data in the given ByteBuffer. If a handshake is needed
 * then this is handled within this method. When this call returns,
 * all of the given user data has been sent and any handshake has been
 * completed. Caller should check if engine has been closed.
 */
WrapperResult sendData (ByteBuffer[] src, int offset, int len) throws IOException {
    WrapperResult r = WrapperResult.createOK();
    while (countBytes(src, offset, len) > 0) {
        r = wrapper.wrapAndSend(src, offset, len, false);
        Status status = r.result.getStatus();
        if (status == Status.CLOSED) {
            doClosure ();
            return r;
        }
        HandshakeStatus hs_status = r.result.getHandshakeStatus();
        if (hs_status != HandshakeStatus.FINISHED &&
            hs_status != HandshakeStatus.NOT_HANDSHAKING)
        {
            doHandshake(hs_status);
        }
    }
    return r;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:SSLDelegate.java

示例3: recvData

/**
 * read data thru the engine into the given ByteBuffer. If the
 * given buffer was not large enough, a new one is allocated
 * and returned. This call handles handshaking automatically.
 * Caller should check if engine has been closed.
 */
WrapperResult recvData (ByteBuffer dst) throws IOException {
    /* we wait until some user data arrives */
    int mark = dst.position();
    WrapperResult r = null;
    int pos = dst.position();
    while (dst.position() == pos) {
        r = wrapper.recvAndUnwrap (dst);
        dst = (r.buf != dst) ? r.buf: dst;
        Status status = r.result.getStatus();
        if (status == Status.CLOSED) {
            doClosure ();
            return r;
        }

        HandshakeStatus hs_status = r.result.getHandshakeStatus();
        if (hs_status != HandshakeStatus.FINISHED &&
            hs_status != HandshakeStatus.NOT_HANDSHAKING)
        {
            doHandshake (hs_status);
        }
    }
    Utils.flipToMark(dst, mark);
    return r;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:SSLDelegate.java

示例4: handshakeFinished

/**
 * Checks if the handshake status is finished
 * Sets the interestOps for the selectionKey.
 */
private void handshakeFinished() throws IOException {
    // SSLEngine.getHandshakeStatus is transient and it doesn't record FINISHED status properly.
    // It can move from FINISHED status to NOT_HANDSHAKING after the handshake is completed.
    // Hence we also need to check handshakeResult.getHandshakeStatus() if the handshake finished or not
    if (handshakeResult.getHandshakeStatus() == HandshakeStatus.FINISHED) {
        //we are complete if we have delivered the last package
        handshakeComplete = !netWriteBuffer.hasRemaining();
        //remove OP_WRITE if we are complete, otherwise we still have data to write
        if (!handshakeComplete)
            key.interestOps(key.interestOps() | SelectionKey.OP_WRITE);
        else
            key.interestOps(key.interestOps() & ~SelectionKey.OP_WRITE);

        log.trace("SSLHandshake FINISHED channelId {}, appReadBuffer pos {}, netReadBuffer pos {}, netWriteBuffer pos {} ",
                  channelId, appReadBuffer.position(), netReadBuffer.position(), netWriteBuffer.position());
    } else {
        throw new IOException("NOT_HANDSHAKING during handshake");
    }
}
 
开发者ID:txazo,项目名称:kafka,代码行数:23,代码来源:SslTransportLayer.java

示例5: unwrap

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,代码行数:25,代码来源:SslHandler.java

示例6: log

private static void log(String str, SSLEngineResult result) {
	if (!logging) {
		return;
	}
	if (resultOnce) {
		resultOnce = false;
		Logger.simple("The format of the SSLEngineResult is: \n"
				+ "\t\"getStatus() / getHandshakeStatus()\" +\n"
				+ "\t\"bytesConsumed() / bytesProduced()\"\n");
	}
	HandshakeStatus hsStatus = result.getHandshakeStatus();
	log(str + result.getStatus() + "/" + hsStatus + ", "
			+ result.bytesConsumed() + "/" + result.bytesProduced()
			+ " bytes");
	if (hsStatus == HandshakeStatus.FINISHED) {
		log("\t...ready for application data");
	}
}
 
开发者ID:helyho,项目名称:Voovan,代码行数:18,代码来源:SSLEngineSimpleDemo.java

示例7: doHandshake

boolean doHandshake() throws InterruptedException {
    Thread clientThread = new Thread(clientEngine);
    clientThread.start();

    Thread serverThread = new Thread(serverEngine);
    serverThread.start();

    int i = 0;
    while (clientThread.isAlive() && serverThread.isAlive() && i < 20) {
        Thread.sleep(500);
        i++;
    }

    if (clientThread.isAlive()) {
        clientThread.interrupt();
    }

    if (serverThread.isAlive()) {
        serverThread.interrupt();
    }

    return clientEngine.getStatus() == HandshakeStatus.FINISHED && serverEngine.getStatus() == HandshakeStatus.FINISHED;
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:23,代码来源:SSLEngineTest.java

示例8: log

private void log(String str, SSLEngineResult result) {
    if (!logging) {
        return;
    }
    if (resultOnce) {
        resultOnce = false;
        Log.info("The format of the SSLEngineResult is: \n"
                + "\t\"getStatus() / getHandshakeStatus()\" +\n"
                + "\t\"bytesConsumed() / bytesProduced()\"\n");
    }
    HandshakeStatus hsStatus = result.getHandshakeStatus();
    Log.info(str + result.getStatus() + "/" + hsStatus + ", " + result.bytesConsumed() + "/"
            + result.bytesProduced() + " bytes");
    if (hsStatus == HandshakeStatus.FINISHED) {
        Log.info("\t...ready for application data");
    }
}
 
开发者ID:idwanglu2010,项目名称:openfire,代码行数:17,代码来源:TLSWrapper.java

示例9: getOutboundData

private HandshakeStatus getOutboundData(ByteBuffer dstBB) {

        Object msg = outboundList.removeFirst();
        assert(msg instanceof ByteBuffer);

        ByteBuffer bbIn = (ByteBuffer) msg;
        assert(dstBB.remaining() >= bbIn.remaining());

        dstBB.put(bbIn);

        /*
         * If we have more data in the queue, it's either
         * a finished message, or an indication that we need
         * to call wrap again.
         */
        if (hasOutboundDataInternal()) {
            msg = outboundList.getFirst();
            if (msg == HandshakeStatus.FINISHED) {
                outboundList.removeFirst();     // consume the message
                return HandshakeStatus.FINISHED;
            } else {
                return HandshakeStatus.NEED_WRAP;
            }
        } else {
            return null;
        }
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:EngineWriter.java

示例10: processHandshake

private synchronized void processHandshake() throws IOException {
    if (this.engineResult.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING) {
        if (!this.tasks.isEmpty()) {
            Iterator<Future<?>> it = this.tasks.iterator();
            while (it.hasNext()) {
                Future<?> f = (Future) it.next();
                if (f.isDone()) {
                    it.remove();
                } else if (isBlocking()) {
                    consumeFutureUninterruptible(f);
                }
            }
        }
        if (this.engineResult.getHandshakeStatus() == HandshakeStatus.NEED_UNWRAP) {
            if (!isBlocking() || this.engineStatus == Status.BUFFER_UNDERFLOW) {
                this.inCrypt.compact();
                if (this.socketChannel.read(this.inCrypt) == -1) {
                    throw new IOException("connection closed unexpectedly by peer");
                }
                this.inCrypt.flip();
            }
            this.inData.compact();
            unwrap();
            if (this.engineResult.getHandshakeStatus() == HandshakeStatus.FINISHED) {
                createBuffers(this.sslEngine.getSession());
            }
        }
        consumeDelegatedTasks();
        if (!$assertionsDisabled && this.engineResult.getHandshakeStatus() == HandshakeStatus.NOT_HANDSHAKING) {
            throw new AssertionError();
        } else if (this.tasks.isEmpty() || this.engineResult.getHandshakeStatus() == HandshakeStatus.NEED_WRAP) {
            this.socketChannel.write(wrap(emptybuffer));
            if (this.engineResult.getHandshakeStatus() == HandshakeStatus.FINISHED) {
                createBuffers(this.sslEngine.getSession());
            }
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:38,代码来源:SSLSocketChannel2.java

示例11: status

@Override HandshakeStatus status()
{
  if (!tasks.isEmpty())
    return HandshakeStatus.NEED_TASK;
  if (state.isReadState())
    return HandshakeStatus.NEED_UNWRAP;
  if (state.isWriteState())
    return HandshakeStatus.NEED_WRAP;

  return HandshakeStatus.FINISHED;
}
 
开发者ID:vilie,项目名称:javify,代码行数:11,代码来源:ServerHandshake.java

示例12: status

@Override HandshakeStatus status()
{
  if (state.isReadState())
    return HandshakeStatus.NEED_UNWRAP;
  if (state.isWriteState())
    return HandshakeStatus.NEED_WRAP;
  return HandshakeStatus.FINISHED;
}
 
开发者ID:vilie,项目名称:javify,代码行数:8,代码来源:ClientHandshake.java

示例13: updateCipherAndProtocolName

private void updateCipherAndProtocolName(SSLEngineResult result)
{
    if (result.getHandshakeStatus() == HandshakeStatus.FINISHED)
    {
        _cipherName = _sslEngine.getCipherSuite();
        _protocolName = _sslEngine.getProtocol();
    }
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:8,代码来源:SimpleSslTransportWrapper.java

示例14: handshake

private void handshake()
	throws IOException, SSLException
{
	if ( firstTime ) {
		init();
		sslEngine.beginHandshake();
		firstTime = false;
	}

	Runnable runnable;
	while (
		sslEngine.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING
		&& sslEngine.getHandshakeStatus() != HandshakeStatus.FINISHED
	) {
		switch ( sslEngine.getHandshakeStatus() ) {
		case NEED_TASK:
			while ( (runnable = sslEngine.getDelegatedTask()) != null ) {
				runnable.run();
			}
			break;
		case NEED_WRAP:
			wrap( ByteBuffer.allocate( INITIAL_BUFFER_SIZE ) );
			break;
		case NEED_UNWRAP:
			unwrap( null );
			break;
		}
	}
}
 
开发者ID:jolie,项目名称:jolie,代码行数:29,代码来源:SSLProtocol.java

示例15: handShakeWrapIfNeeded

public static boolean handShakeWrapIfNeeded(SSLConnection cc, Pipe<NetPayloadSchema> target, ByteBuffer buffer, boolean isServer, long arrivalTime) {
					
	 HandshakeStatus handshakeStatus = cc.getEngine().getHandshakeStatus();

	 boolean didShake = false;
	 while (HandshakeStatus.NOT_HANDSHAKING != handshakeStatus && HandshakeStatus.FINISHED != handshakeStatus	 ) {

		 didShake = true;
		 if (HandshakeStatus.NEED_UNWRAP == handshakeStatus) {				 
			 if (cc.durationWaitingForNetwork() > HANDSHAKE_TIMEOUT) {
				
				 logger.warn("Handshake wrap abanonded for {} due to timeout of {} ms waiting for unwrap done by reading stage.",cc,HANDSHAKE_TIMEOUT/1000000);
				 cc.close();	
			 }
			 return true;//done by the other stage.
		 }
		 
		 if (HandshakeStatus.NEED_WRAP == handshakeStatus) {				 
			 SSLUtil.handshakeWrapLogic(cc, target, buffer, isServer, arrivalTime);
			 handshakeStatus = cc.getEngine().getHandshakeStatus();				
		 }
		 
		 if (HandshakeStatus.NEED_TASK == handshakeStatus) {
             Runnable task;
             while ((task = cc.getEngine().getDelegatedTask()) != null) {
                	task.run(); //NOTE: could be run in parallel but we only have 1 thread now
             }
             handshakeStatus = cc.getEngine().getHandshakeStatus();
                
            //return (HandshakeStatus.NOT_HANDSHAKING != handshakeStatus) && (HandshakeStatus.FINISHED != handshakeStatus);
		 }
	 }
	 cc.clearWaitingForNetwork();
	
	 // logger.info("server {} wrap status is now {} for id {} ",isServer,handshakeStatus, cc.getId());
	 
	 return didShake;
 
}
 
开发者ID:oci-pronghorn,项目名称:Pronghorn,代码行数:39,代码来源:SSLUtil.java


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