Java Code Examples for javax.net.ssl.SSLEngineResult.HandshakeStatus#FINISHED
The following examples show how to use
javax.net.ssl.SSLEngineResult.HandshakeStatus#FINISHED .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SSLDelegate.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example 2
Source File: SSLStreams.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
public SSLStreams.WrapperResult sendData(ByteBuffer src) throws IOException { SSLStreams.WrapperResult r = null; while(src.remaining() > 0) { r = this.wrapper.wrapAndSend(src); Status status = r.result.getStatus(); if (status == Status.CLOSED) { this.doClosure(); return r; } HandshakeStatus hs_status = r.result.getHandshakeStatus(); if (hs_status != HandshakeStatus.FINISHED && hs_status != HandshakeStatus.NOT_HANDSHAKING) { this.doHandshake(hs_status); } } return r; }
Example 3
Source File: SSLStreams.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
public SSLStreams.WrapperResult sendData(ByteBuffer src) throws IOException { SSLStreams.WrapperResult r = null; while(src.remaining() > 0) { r = this.wrapper.wrapAndSend(src); Status status = r.result.getStatus(); if (status == Status.CLOSED) { this.doClosure(); return r; } HandshakeStatus hs_status = r.result.getHandshakeStatus(); if (hs_status != HandshakeStatus.FINISHED && hs_status != HandshakeStatus.NOT_HANDSHAKING) { this.doHandshake(hs_status); } } return r; }
Example 4
Source File: SSLStreams.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
public SSLStreams.WrapperResult sendData(ByteBuffer src) throws IOException { SSLStreams.WrapperResult r = null; while(src.remaining() > 0) { r = this.wrapper.wrapAndSend(src); Status status = r.result.getStatus(); if (status == Status.CLOSED) { this.doClosure(); return r; } HandshakeStatus hs_status = r.result.getHandshakeStatus(); if (hs_status != HandshakeStatus.FINISHED && hs_status != HandshakeStatus.NOT_HANDSHAKING) { this.doHandshake(hs_status); } } return r; }
Example 5
Source File: EngineWriter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
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; } }
Example 6
Source File: SqueakSSL.java From trufflesqueak with MIT License | 5 votes |
private static void wrapEagerly(final SqSSL ssl, final ByteBuffer target) throws SSLException { HandshakeStatus status = ssl.engine.getHandshakeStatus(); while (status == HandshakeStatus.NEED_WRAP) { final SSLEngineResult result = wrap(ssl, EMPTY_BUFFER, target); checkStatus("Handshake wrap", result, Status.OK); runTasks(ssl); if (result.getHandshakeStatus() == HandshakeStatus.FINISHED) { handshakeCompleted(ssl); } status = ssl.engine.getHandshakeStatus(); } }
Example 7
Source File: EngineWriter.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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; } }
Example 8
Source File: EngineWriter.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
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; } }
Example 9
Source File: SimpleSslTransportWrapper.java From qpid-proton-j with Apache License 2.0 | 5 votes |
private void updateCipherAndProtocolName(SSLEngineResult result) { if (result.getHandshakeStatus() == HandshakeStatus.FINISHED) { _cipherName = _sslEngine.getCipherSuite(); _protocolName = _sslEngine.getProtocol(); } }
Example 10
Source File: NoDesRC4CiphSuite.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
private static void dumpResult(String str, SSLEngineResult result) { System.err.println("The format of the SSLEngineResult is: \n" + "\t\"getStatus() / getHandshakeStatus()\" +\n" + "\t\"bytesConsumed() / bytesProduced()\"\n"); HandshakeStatus hsStatus = result.getHandshakeStatus(); System.err.println(str + result.getStatus() + "/" + hsStatus + ", " + result.bytesConsumed() + "/" + result.bytesProduced() + " bytes"); if (hsStatus == HandshakeStatus.FINISHED) { System.err.println("\t...ready for application data"); } }
Example 11
Source File: EngineWriter.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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; } }
Example 12
Source File: EngineWriter.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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; } }
Example 13
Source File: TransportContext.java From Bytecoder with Apache License 2.0 | 5 votes |
HandshakeStatus finishHandshake() { if (protocolVersion.useTLS13PlusSpec()) { outputRecord.tc = this; inputRecord.tc = this; cipherSuite = handshakeContext.negotiatedCipherSuite; inputRecord.readCipher.baseSecret = handshakeContext.baseReadSecret; outputRecord.writeCipher.baseSecret = handshakeContext.baseWriteSecret; } handshakeContext = null; outputRecord.handshakeHash.finish(); inputRecord.finishHandshake(); outputRecord.finishHandshake(); isNegotiated = true; // Tell folk about handshake completion, but do it in a separate thread. if (transport instanceof SSLSocket && sslConfig.handshakeListeners != null && !sslConfig.handshakeListeners.isEmpty()) { HandshakeCompletedEvent hce = new HandshakeCompletedEvent((SSLSocket)transport, conSession); Thread thread = new Thread( null, new NotifyHandshake(sslConfig.handshakeListeners, hce), "HandshakeCompletedNotify-Thread", 0, false); thread.start(); } return HandshakeStatus.FINISHED; }
Example 14
Source File: TransportContext.java From openjsse with GNU General Public License v2.0 | 5 votes |
HandshakeStatus finishPostHandshake() { handshakeContext = null; // Note: May need trigger handshake completion even for post-handshake // authentication in the future. return HandshakeStatus.FINISHED; }
Example 15
Source File: TransportContext.java From openjsse with GNU General Public License v2.0 | 5 votes |
HandshakeStatus finishHandshake() { if (protocolVersion.useTLS13PlusSpec()) { outputRecord.tc = this; inputRecord.tc = this; cipherSuite = handshakeContext.negotiatedCipherSuite; inputRecord.readCipher.baseSecret = handshakeContext.baseReadSecret; outputRecord.writeCipher.baseSecret = handshakeContext.baseWriteSecret; } handshakeContext = null; outputRecord.handshakeHash.finish(); inputRecord.finishHandshake(); outputRecord.finishHandshake(); isNegotiated = true; // Tell folk about handshake completion, but do it in a separate thread. if (transport instanceof SSLSocket && sslConfig.handshakeListeners != null && !sslConfig.handshakeListeners.isEmpty()) { HandshakeCompletedEvent hce = new HandshakeCompletedEvent((SSLSocket)transport, conSession); //JDK8 Thread thread = new Thread( null, new NotifyHandshake(sslConfig.handshakeListeners, hce), "HandshakeCompletedNotify-Thread", 0); thread.start(); } return HandshakeStatus.FINISHED; }
Example 16
Source File: SslConnection.java From WebSocket-for-Android with Apache License 2.0 | 4 votes |
private synchronized boolean unwrap(final Buffer buffer) throws IOException { if (!_inbound.hasContent()) return false; ByteBuffer bbuf=extractByteBuffer(buffer); final SSLEngineResult result; int encrypted_consumed = 0; int decrypted_produced = 0; synchronized(bbuf) { ByteBuffer in_buffer=_inbound.getByteBuffer(); synchronized(in_buffer) { try { bbuf.position(buffer.putIndex()); bbuf.limit(buffer.capacity()); int decrypted_position = bbuf.position(); in_buffer.position(_inbound.getIndex()); in_buffer.limit(_inbound.putIndex()); int encrypted_position = in_buffer.position(); result=_engine.unwrap(in_buffer,bbuf); if (_logger.isDebugEnabled()) _logger.debug("{} unwrap {} {} consumed={} produced={}", _session, result.getStatus(), result.getHandshakeStatus(), result.bytesConsumed(), result.bytesProduced()); encrypted_consumed = in_buffer.position() - encrypted_position; _inbound.skip(encrypted_consumed); _inbound.compact(); decrypted_produced = bbuf.position() - decrypted_position; buffer.setPutIndex(buffer.putIndex() + decrypted_produced); } catch(SSLException e) { _logger.debug(String.valueOf(_endp), e); _endp.close(); throw e; } catch (Exception x) { throw new IOException(x); } finally { in_buffer.position(0); in_buffer.limit(in_buffer.capacity()); bbuf.position(0); bbuf.limit(bbuf.capacity()); } } } switch(result.getStatus()) { case BUFFER_UNDERFLOW: if (_endp.isInputShutdown()) _inbound.clear(); break; case BUFFER_OVERFLOW: if (_logger.isDebugEnabled()) _logger.debug("{} unwrap {} {}->{}",_session,result.getStatus(),_inbound.toDetailString(),buffer.toDetailString()); break; case OK: if (result.getHandshakeStatus()==HandshakeStatus.FINISHED) _handshook=true; break; case CLOSED: _logger.debug("unwrap CLOSE {} {}",this,result); if (result.getHandshakeStatus()==HandshakeStatus.FINISHED) _endp.close(); break; default: _logger.debug("{} wrap default {}",_session,result); throw new IOException(result.toString()); } return encrypted_consumed > 0 || decrypted_produced > 0; }
Example 17
Source File: SslConnection.java From IoTgo_Android_App with MIT License | 4 votes |
private synchronized boolean wrap(final Buffer buffer) throws IOException { ByteBuffer bbuf=extractByteBuffer(buffer); final SSLEngineResult result; synchronized(bbuf) { _outbound.compact(); ByteBuffer out_buffer=_outbound.getByteBuffer(); synchronized(out_buffer) { try { bbuf.position(buffer.getIndex()); bbuf.limit(buffer.putIndex()); out_buffer.position(_outbound.putIndex()); out_buffer.limit(out_buffer.capacity()); result=_engine.wrap(bbuf,out_buffer); if (_logger.isDebugEnabled()) _logger.debug("{} wrap {} {} consumed={} produced={}", _session, result.getStatus(), result.getHandshakeStatus(), result.bytesConsumed(), result.bytesProduced()); buffer.skip(result.bytesConsumed()); _outbound.setPutIndex(_outbound.putIndex()+result.bytesProduced()); } catch(SSLException e) { _logger.debug(String.valueOf(_endp), e); _endp.close(); throw e; } finally { out_buffer.position(0); out_buffer.limit(out_buffer.capacity()); bbuf.position(0); bbuf.limit(bbuf.capacity()); } } } switch(result.getStatus()) { case BUFFER_UNDERFLOW: throw new IllegalStateException(); case BUFFER_OVERFLOW: break; case OK: if (result.getHandshakeStatus()==HandshakeStatus.FINISHED) _handshook=true; break; case CLOSED: _logger.debug("wrap CLOSE {} {}",this,result); if (result.getHandshakeStatus()==HandshakeStatus.FINISHED) _endp.close(); break; default: _logger.debug("{} wrap default {}",_session,result); throw new IOException(result.toString()); } return result.bytesConsumed()>0 || result.bytesProduced()>0; }
Example 18
Source File: SSLEngineImpl.java From Bytecoder with Apache License 2.0 | 4 votes |
private Ciphertext encode( ByteBuffer[] srcs, int srcsOffset, int srcsLength, ByteBuffer[] dsts, int dstsOffset, int dstsLength) throws IOException { Ciphertext ciphertext = null; try { ciphertext = conContext.outputRecord.encode( srcs, srcsOffset, srcsLength, dsts, dstsOffset, dstsLength); } catch (SSLHandshakeException she) { // may be record sequence number overflow throw conContext.fatal(Alert.HANDSHAKE_FAILURE, she); } catch (IOException e) { throw conContext.fatal(Alert.UNEXPECTED_MESSAGE, e); } if (ciphertext == null) { return null; } // Is the handshake completed? boolean needRetransmission = conContext.sslContext.isDTLS() && conContext.handshakeContext != null && conContext.handshakeContext.sslConfig.enableRetransmissions; HandshakeStatus hsStatus = tryToFinishHandshake(ciphertext.contentType); if (needRetransmission && hsStatus == HandshakeStatus.FINISHED && conContext.sslContext.isDTLS() && ciphertext.handshakeType == SSLHandshake.FINISHED.id) { // Retransmit the last flight for DTLS. // // The application data transactions may begin immediately // after the last flight. If the last flight get lost, the // application data may be discarded accordingly. As could // be an issue for some applications. This impact can be // mitigated by sending the last fligth twice. if (SSLLogger.isOn && SSLLogger.isOn("ssl,verbose")) { SSLLogger.finest("retransmit the last flight messages"); } conContext.outputRecord.launchRetransmission(); hsStatus = HandshakeStatus.NEED_WRAP; } if (hsStatus == null) { hsStatus = conContext.getHandshakeStatus(); } // Is the sequence number is nearly overflow? if (conContext.outputRecord.seqNumIsHuge() || conContext.outputRecord.writeCipher.atKeyLimit()) { hsStatus = tryKeyUpdate(hsStatus); } // Check if NewSessionTicket PostHandshake message needs to be sent if (conContext.conSession.updateNST && !conContext.sslConfig.isClientMode) { hsStatus = tryNewSessionTicket(hsStatus); } // update context status ciphertext.handshakeStatus = hsStatus; return ciphertext; }
Example 19
Source File: SslConnection.java From IoTgo_Android_App with MIT License | 4 votes |
private synchronized boolean unwrap(final Buffer buffer) throws IOException { if (!_inbound.hasContent()) return false; ByteBuffer bbuf=extractByteBuffer(buffer); final SSLEngineResult result; synchronized(bbuf) { ByteBuffer in_buffer=_inbound.getByteBuffer(); synchronized(in_buffer) { try { bbuf.position(buffer.putIndex()); bbuf.limit(buffer.capacity()); in_buffer.position(_inbound.getIndex()); in_buffer.limit(_inbound.putIndex()); result=_engine.unwrap(in_buffer,bbuf); if (_logger.isDebugEnabled()) _logger.debug("{} unwrap {} {} consumed={} produced={}", _session, result.getStatus(), result.getHandshakeStatus(), result.bytesConsumed(), result.bytesProduced()); _inbound.skip(result.bytesConsumed()); _inbound.compact(); buffer.setPutIndex(buffer.putIndex()+result.bytesProduced()); } catch(SSLException e) { _logger.debug(String.valueOf(_endp), e); _endp.close(); throw e; } finally { in_buffer.position(0); in_buffer.limit(in_buffer.capacity()); bbuf.position(0); bbuf.limit(bbuf.capacity()); } } } switch(result.getStatus()) { case BUFFER_UNDERFLOW: if (_endp.isInputShutdown()) _inbound.clear(); break; case BUFFER_OVERFLOW: if (_logger.isDebugEnabled()) _logger.debug("{} unwrap {} {}->{}",_session,result.getStatus(),_inbound.toDetailString(),buffer.toDetailString()); break; case OK: if (result.getHandshakeStatus()==HandshakeStatus.FINISHED) _handshook=true; break; case CLOSED: _logger.debug("unwrap CLOSE {} {}",this,result); if (result.getHandshakeStatus()==HandshakeStatus.FINISHED) _endp.close(); break; default: _logger.debug("{} wrap default {}",_session,result); throw new IOException(result.toString()); } //if (LOG.isDebugEnabled() && result.bytesProduced()>0) // LOG.debug("{} unwrapped '{}'",_session,buffer); return result.bytesConsumed()>0 || result.bytesProduced()>0; }
Example 20
Source File: SslHandler.java From jane with GNU Lesser General Public License v3.0 | 4 votes |
/** * Perform any handshaking processing. */ void handshake(NextFilter nextFilter) throws Exception { for (;;) { switch (handshakeStatus) { case FINISHED: // LOGGER.debug("{} processing the FINISHED state", SslFilter.getSessionInfo(session)); handshakeComplete = true; // Send the SECURE message only if it's the first SSL handshake if (firstSSLNegociation) { firstSSLNegociation = false; if (session.containsAttribute(SslFilter.USE_NOTIFICATION)) scheduleMessageReceived(nextFilter, SslFilter.SESSION_SECURED); } // if (!isOutboundDone()) { // LOGGER.debug("{} is now secured", SslFilter.getSessionInfo(session)); // } else { // LOGGER.debug("{} is not secured yet", SslFilter.getSessionInfo(session)); // } return; case NEED_TASK: // LOGGER.debug("{} processing the NEED_TASK state", SslFilter.getSessionInfo(session)); handshakeStatus = doTasks(); break; case NEED_UNWRAP: // LOGGER.debug("{} processing the NEED_UNWRAP state", SslFilter.getSessionInfo(session)); // we need more data read if (unwrapHandshake(nextFilter) == Status.BUFFER_UNDERFLOW && handshakeStatus != HandshakeStatus.FINISHED || isInboundDone()) return; // We need more data or the session is closed break; case NEED_WRAP: case NOT_HANDSHAKING: // LOGGER.debug("{} processing the NEED_WRAP state", SslFilter.getSessionInfo(session)); // First make sure that the out buffer is completely empty. // Since we cannot call wrap with data left on the buffer if (outNetBuffer != null && outNetBuffer.hasRemaining()) return; createOutNetBuffer(0); for (;;) { //NOSONAR SSLEngineResult result = sslEngine.wrap(SimpleBufferAllocator.emptyBuffer.buf(), outNetBuffer.buf()); if (result.getStatus() != Status.BUFFER_OVERFLOW) { handshakeStatus = result.getHandshakeStatus(); break; } outNetBuffer = IoBuffer.reallocate(outNetBuffer, outNetBuffer.capacity() << 1); outNetBuffer.limit(outNetBuffer.capacity()); } outNetBuffer.flip(); writeNetBuffer(nextFilter, false); break; default: String msg = "invalid handshaking state" + handshakeStatus + " while processing the handshake for session " + session.getId(); ExceptionMonitor.getInstance().error(msg); throw new IllegalStateException(msg); } } }