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


Java Status.OK属性代码示例

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


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

示例1: checkResult

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

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

示例3: wrapEx

private SSLEngineResult wrapEx(byte[] b, int off, int len) throws IOException {
	ByteBuffer srcBB = ByteBuffer.wrap(b, off, len);
	byte[] outNetBytes = null;
	SSLEngineResult result;
	do {
		int packetBBSize = ssle.getSession().getPacketBufferSize();
		if (outNetBytes == null || outNetBytes.length < packetBBSize) {
			outNetBytes = new byte[packetBBSize];
		}
		ByteBuffer outNetBB = ByteBuffer.wrap(outNetBytes);
		result = ssle.wrap(srcBB, outNetBB);
		if (result.getStatus() != Status.OK) {
			throw new IOException();
		}
		super.send(outNetBytes, 0, outNetBB.position());
	} while (srcBB.remaining() > 0);
	return result;
}
 
开发者ID:xqbase,项目名称:tuna,代码行数:18,代码来源:SSLFilter.java

示例4: unwrapRead

final int unwrapRead(ByteBuffer peerAppData) throws IOException {
    // TODO, make sure peerNetData has remaining place
    int read = ((SocketChannel) key.channel()).read(peerNetData), unwrapped = 0;
    if (read > 0) {
        peerNetData.flip();
        SSLEngineResult res;
        while ((res = engine.unwrap(peerNetData, peerAppData)).getStatus() == Status.OK) {
            unwrapped += res.bytesProduced();
            if (!peerNetData.hasRemaining())
                break;
        }
        peerNetData.compact();
        switch (res.getStatus()) {
            case OK:
            case BUFFER_UNDERFLOW: // need more data
                return unwrapped;
            case CLOSED:
                return unwrapped > 0 ? unwrapped : -1;
            case BUFFER_OVERFLOW:
                return -1; // can't => peerAppData is 64k
        }
        return unwrapped;
    } else {
        return read;
    }
}
 
开发者ID:nLight,项目名称:jruby-http-kit,代码行数:26,代码来源:HttpsRequest.java

示例5: unwrap

private synchronized ByteBuffer unwrap() throws SSLException {
    while (true) {
        int rem = this.inData.remaining();
        this.engineResult = this.sslEngine.unwrap(this.inCrypt, this.inData);
        this.engineStatus = this.engineResult.getStatus();
        if (this.engineStatus != Status.OK || (rem == this.inData.remaining() && this.engineResult.getHandshakeStatus() != HandshakeStatus.NEED_UNWRAP)) {
            this.inData.flip();
        }
    }
    this.inData.flip();
    return this.inData;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:12,代码来源:SSLSocketChannel2.java

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

示例7: checkResult

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

示例8: readMessage

private void readMessage() throws IOException {
    int totalProduced = 0;
    while (!stopping) {
        SSLEngineResult result = unwrap();
        if (result.getStatus() != Status.OK) {
            throw new RuntimeException("Failed reading message: " + result);
        }
        totalProduced += result.bytesProduced();
        if (totalProduced == MESSAGE_LENGTH) {
            return;
        }
    }
}
 
开发者ID:google,项目名称:conscrypt,代码行数:13,代码来源:RenegotiationTest.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: handshakeWrapLogic

public static void handshakeWrapLogic(SSLConnection cc, Pipe<NetPayloadSchema> target, ByteBuffer buffer, boolean isServer, long arrivalTime) {
    
	try {

		do {
			if (!Pipe.hasRoomForWrite(target)) {
				return; //unable to complete, try again later
			}
			
			final ByteBuffer[] targetBuffers = Pipe.wrappedWritingBuffers(Pipe.storeBlobWorkingHeadPosition(target), target);
			final Status status = SSLUtil.wrapResultStatusState(target, buffer, cc, noDatas, targetBuffers, isServer, arrivalTime);
			
			if (Status.OK == status) {
				
				Pipe.confirmLowLevelWrite(target, Pipe.sizeOf(target, NetPayloadSchema.MSG_ENCRYPTED_200));
				Pipe.publishWrites(target);
				
			} else {
				//connection was closed before handshake completed 
				//already closed, NOTE we should release this from reserved pipe pools
				//no need to cancel wrapped buffer it was already done by wrapResultStatusState
				cc.close();
			    if (Status.CLOSED != status) {
			    	//not expected case so log this
			    	logger.warn("HANDSHAKE unable to wrap {} {} {} ",status, cc.getClass().getSimpleName(), cc.getEngine(), new Exception());	
			    }
			    return;
			}
		} while(cc.getEngine().getHandshakeStatus() == HandshakeStatus.NEED_WRAP); 
		
				
	} catch (SSLException e) {
		//logger.error("unable to wrap ", e);
		
		Pipe.unstoreBlobWorkingHeadPosition(target);
	}	
    
}
 
开发者ID:oci-pronghorn,项目名称:Pronghorn,代码行数:38,代码来源:SSLUtil.java

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

示例12: warpData

/**
 * 打包并发送数据
 *
 * @param buffer 需要的数据缓冲区
 * @return 返回成功执行的最后一个或者失败的那个 SSLEnginResult
 * @throws IOException IO 异常
 */
public synchronized SSLEngineResult warpData(ByteBuffer buffer) throws IOException {
	if (session.isConnected()) {
		SSLEngineResult engineResult = null;

		do {
			synchronized (netData) {
				if(!TByteBuffer.isReleased(netData)) {
					netData.clear();
					engineResult = engine.wrap(buffer, netData);

					netData.flip();
					if (session.isConnected() && engineResult.bytesProduced() > 0 && netData.limit() > 0) {
						session.send0(netData);
					}
					netData.clear();
				} else {
					return null;
				}
			}
		} while (engineResult.getStatus() == Status.OK && buffer.hasRemaining());

		return engineResult;
	} else {
		return null;
	}
}
 
开发者ID:helyho,项目名称:Voovan,代码行数:33,代码来源:SSLParser.java

示例13: encrypt

/**
 * Encrypt provided buffer. Encrypted data returned by getOutNetBuffer().
 *
 * @param src data to encrypt
 * @throws SSLException on errors
 */
void encrypt(ByteBuffer src) throws SSLException {
	if (!handshakeComplete) {
		throw new IllegalStateException();
	}

	if (!src.hasRemaining()) {
		if (outNetBuffer == null) {
			outNetBuffer = IoBuffer.allocate(0);
		}
		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() == Status.OK) {
			if (result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
				doTasks();
			}
		} else if (result.getStatus() == Status.BUFFER_OVERFLOW) {
			outNetBuffer = IoBuffer.reallocate(outNetBuffer, outNetBuffer.capacity() << 1);
			outNetBuffer.limit(outNetBuffer.capacity());
		} else {
			throw new SSLException("SSLEngine error during encrypt: " + result.getStatus() + " src: " + src + "outNetBuffer: " + outNetBuffer);
		}
	}

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

示例14: wrapRequest

private void wrapRequest() throws SSLException {
    myNetData.clear();
    SSLEngineResult res = engine.wrap(request, myNetData);
    if (res.getStatus() != Status.OK) {
        // TODO larger buffer, uberflow?
    }
    myNetData.flip();
}
 
开发者ID:nLight,项目名称:jruby-http-kit,代码行数:8,代码来源:HttpsRequest.java

示例15: run

@Override
public void run() {
    long written = 0;

    try {
        for (int i = offset; i < offset + length; i++) {
            ByteBuffer src = srcs[i];
            while (src.hasRemaining()) {
                socketWriteBuffer.clear();

                // Encrypt the data
                SSLEngineResult r = sslEngine.wrap(src, socketWriteBuffer);
                written += r.bytesConsumed();
                Status s = r.getStatus();

                if (s == Status.OK || s == Status.BUFFER_OVERFLOW) {
                    // Need to write out the bytes and may need to read from
                    // the source again to empty it
                } else {
                    // Status.BUFFER_UNDERFLOW - only happens on unwrap
                    // Status.CLOSED - unexpected
                    throw new IllegalStateException(sm.getString(
                            "asyncChannelWrapperSecure.statusWrap"));
                }

                // Check for tasks
                if (r.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
                    Runnable runnable = sslEngine.getDelegatedTask();
                    while (runnable != null) {
                        runnable.run();
                        runnable = sslEngine.getDelegatedTask();
                    }
                }

                socketWriteBuffer.flip();

                // Do the write
                int toWrite = r.bytesProduced();
                while (toWrite > 0) {
                    Future<Integer> f =
                            socketChannel.write(socketWriteBuffer);
                    Integer socketWrite = f.get();
                    toWrite -= socketWrite.intValue();
                }
            }
        }


        if (writing.compareAndSet(true, false)) {
            future.complete(Long.valueOf(written));
        } else {
            future.fail(new IllegalStateException(sm.getString(
                    "asyncChannelWrapperSecure.wrongStateWrite")));
        }
    } catch (Exception e) {
        future.fail(e);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:58,代码来源:AsyncChannelWrapperSecure.java


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