本文整理汇总了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");
}
}
示例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;
}
示例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;
}
示例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");
}
}
示例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());
}
}
示例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");
}
}
示例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;
}
示例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");
}
}
示例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;
}
}
示例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());
}
}
}
}
示例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;
}
示例12: status
@Override HandshakeStatus status()
{
if (state.isReadState())
return HandshakeStatus.NEED_UNWRAP;
if (state.isWriteState())
return HandshakeStatus.NEED_WRAP;
return HandshakeStatus.FINISHED;
}
示例13: updateCipherAndProtocolName
private void updateCipherAndProtocolName(SSLEngineResult result)
{
if (result.getHandshakeStatus() == HandshakeStatus.FINISHED)
{
_cipherName = _sslEngine.getCipherSuite();
_protocolName = _sslEngine.getProtocol();
}
}
示例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;
}
}
}
示例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;
}