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


Java HandshakeStatus.NOT_HANDSHAKING属性代码示例

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


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

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

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

示例3: unwrap

/**
 * performs the unwrap operation by unwrapping from {@link #inCrypt} to {@link #inData}
 **/
private synchronized ByteBuffer unwrap() throws SSLException {
	int rem;
	//There are some ssl test suites, which get around the selector.select() call, which cause an infinite unwrap and 100% cpu usage (see #459 and #458)
	if(readEngineResult.getStatus() == Status.CLOSED && sslEngine.getHandshakeStatus() == HandshakeStatus.NOT_HANDSHAKING){
		try {
			close();
		} catch (IOException e) {
			//Not really interesting
		}
	}
	do {
		rem = inData.remaining();
		readEngineResult = sslEngine.unwrap( inCrypt, inData );
	} while ( readEngineResult.getStatus() == Status.OK && ( rem != inData.remaining() || sslEngine.getHandshakeStatus() == HandshakeStatus.NEED_UNWRAP ) );
	inData.flip();
	return inData;
}
 
开发者ID:MundoSK,项目名称:MundoSK,代码行数:20,代码来源:SSLSocketChannel2.java

示例4: getHandshakeStatusInternal

private HandshakeStatus getHandshakeStatusInternal() {
    if (handshakeFinished) {
        return HandshakeStatus.NOT_HANDSHAKING;
    }
    switch (state) {
        case STATE_HANDSHAKE_STARTED:
            return pendingStatus(pendingOutboundEncryptedBytes());
        case STATE_HANDSHAKE_COMPLETED:
            return HandshakeStatus.NEED_WRAP;
        case STATE_NEW:
        case STATE_MODE_SET:
        case STATE_CLOSED:
        case STATE_CLOSED_INBOUND:
        case STATE_CLOSED_OUTBOUND:
        case STATE_READY:
        case STATE_READY_HANDSHAKE_CUT_THROUGH:
            return HandshakeStatus.NOT_HANDSHAKING;
        default:
            break;
    }
    throw new IllegalStateException("Unexpected engine state: " + state);
}
 
开发者ID:google,项目名称:conscrypt,代码行数:22,代码来源:ConscryptEngine.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: unwrap

/**
 * performs the unwrap operation by unwrapping from {@link #inCrypt} to {@link #inData}
 **/
private synchronized ByteBuffer unwrap() throws SSLException {
	int rem;
	//There are some ssl test suites, which get around the selector.select() call, which cause an infinite unwrap and 100% cpu usage (see #459 and #458)
	if(readEngineResult.getStatus() == SSLEngineResult.Status.CLOSED && sslEngine.getHandshakeStatus() == HandshakeStatus.NOT_HANDSHAKING){
		try {
			close();
		} catch (IOException e) {
			//Not really interesting
		}
	}
	do {
		rem = inData.remaining();
		readEngineResult = sslEngine.unwrap( inCrypt, inData );
	} while ( readEngineResult.getStatus() == SSLEngineResult.Status.OK && ( rem != inData.remaining() || sslEngine.getHandshakeStatus() == HandshakeStatus.NEED_UNWRAP ) );
	inData.flip();
	return inData;
}
 
开发者ID:cping,项目名称:RipplePower,代码行数:20,代码来源:SSLSocketChannel2.java

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

示例8: write

/**
* 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,代码行数:43,代码来源:SslTransportLayer.java

示例9: write

@Override public void write(byte[] buf, int off, int len) throws IOException
{
  if (!initialHandshakeDone
      || engine.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING)
    {
      doHandshake();
      if (handshakeException != null)
        throw handshakeException;
    }

  int k = 0;
  while (k < len)
    {
      synchronized (engine)
        {
          int l = Math.min(len-k, getSession().getApplicationBufferSize());
          ByteBuffer in = ByteBuffer.wrap(buf, off+k, l);
          SSLEngineResult result = engine.wrap(in, buffer);
          if (result.getStatus() == Status.CLOSED)
            return;
          if (result.getStatus() != Status.OK)
            throw new SSLException("unexpected SSL state " + result.getStatus());
          buffer.flip();
          out.write(buffer.array(), 0, buffer.limit());
          k += result.bytesConsumed();
          buffer.clear();
        }
    }
}
 
开发者ID:vilie,项目名称:javify,代码行数:29,代码来源:SSLSocketImpl.java

示例10: read

@Override public int read(byte[] buf, int off, int len) throws IOException
{
  if (!initialHandshakeDone ||
      engine.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING)
    {
      doHandshake();
      if (handshakeException != null)
        throw handshakeException;
    }

  if (!appBuffer.hasRemaining())
    {
      int x = in.read();
      if (x == -1)
        return -1;
      inBuffer.clear();
      inBuffer.put((byte) x);
      inBuffer.putInt(in.readInt());
      int reclen = inBuffer.getShort(3) & 0xFFFF;
      in.readFully(inBuffer.array(), 5, reclen);
      inBuffer.position(0).limit(reclen + 5);
      synchronized (engine)
        {
          appBuffer.clear();
          SSLEngineResult result = engine.unwrap(inBuffer, appBuffer);
          Status status = result.getStatus();
          if (status == Status.CLOSED && result.bytesProduced() == 0)
            return -1;
        }
      inBuffer.compact();
      appBuffer.flip();
    }
  int l = Math.min(len, appBuffer.remaining());
  appBuffer.get(buf, off, l);
  return l;
}
 
开发者ID:vilie,项目名称:javify,代码行数:36,代码来源:SSLSocketImpl.java

示例11: getHandshakeStatus

@Override
public HandshakeStatus getHandshakeStatus()
{
  if (handshake == null)
    return HandshakeStatus.NOT_HANDSHAKING;
  return handshake.status();
}
 
开发者ID:vilie,项目名称:javify,代码行数:7,代码来源:SSLEngineImpl.java

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

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

示例14: unwrap

private static SSLEngineResult unwrap(int maxEncryptedContentLength, ByteBuffer sourceBuffer, final ByteBuffer[] targetBuffer, SSLConnection cc)
		throws SSLException {
	SSLEngineResult result;
	int origLimit;
	do {
		///////////////
		//Block needed for limitations of OpenSSL, can only  support small blocks to be decryptded at a time
		///////////////
		origLimit = sourceBuffer.limit();
		int pos = sourceBuffer.position();
		if (origLimit-pos>maxEncryptedContentLength) {
			sourceBuffer.limit(pos+maxEncryptedContentLength);
		}
		/////////////
		
		assert(sourceBuffer.remaining()<=maxEncryptedContentLength);

		result = cc.getEngine().unwrap(sourceBuffer, targetBuffer);//common case where we can unwrap directly from the pipe.

		sourceBuffer.limit(origLimit);//restore the limit so we can keep the remaining data (only critical for openSSL compatibility, see above)
		assert(cc.localRunningBytesProduced>=0);
		cc.localRunningBytesProduced += result.bytesProduced();
		
	
	} while(result.getStatus() == Status.OK && sourceBuffer.hasRemaining() && cc.getEngine().getHandshakeStatus()==HandshakeStatus.NOT_HANDSHAKING);
	return result;
}
 
开发者ID:oci-pronghorn,项目名称:Pronghorn,代码行数:27,代码来源:SSLUtil.java

示例15: connected

public boolean connected(SSLEngine a, SSLEngine b) {
    return (a.getHandshakeStatus() == HandshakeStatus.NOT_HANDSHAKING
            && b.getHandshakeStatus() == HandshakeStatus.NOT_HANDSHAKING
            && a.getSession() != null
            && b.getSession() != null
            && !a.isInboundDone()
            && !b.isInboundDone()
            && !a.isOutboundDone()
            && !b.isOutboundDone());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:10,代码来源:SSLEngineTest.java


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