當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。