public void open() throws TTransportException { LOGGER.debug("opening transport {}", this); if (sasl != null && sasl.isComplete()) throw new TTransportException("SASL transport already open"); while (!sasl.isComplete()) { message = receiveSaslMessage(); if (message.status != NegotiationStatus.COMPLETE && byte[] challenge = sasl.evaluateChallengeOrResponse(message.payload); sendSaslMessage(sasl.isComplete() ? NegotiationStatus.COMPLETE : NegotiationStatus.OK, challenge); assert sasl.isComplete(); String qop = (String) sasl.getNegotiatedProperty(Sasl.QOP); if (qop != null && !qop.equalsIgnoreCase("auth")) shouldWrap = true;
/** * Read a single frame of data from the underlying transport, unwrapping if * necessary. * * @throws TTransportException * Thrown if there's an error reading from the underlying transport. * @throws SaslException * Thrown if there's an error unwrapping the data. */ private void readFrame() throws TTransportException, SaslException { int dataLength = readLength(); if (dataLength < 0) throw new TTransportException("Read a negative frame size (" + dataLength + ")!"); byte[] buff = new byte[dataLength]; LOGGER.debug("{}: reading data length: {}", getRole(), dataLength); underlyingTransport.readAll(buff, 0, dataLength); if (shouldWrap) { buff = sasl.unwrap(buff, 0, buff.length); LOGGER.debug("data length after unwrap: {}", buff.length); } readBuffer.reset(buff); }
/** * Flushes to the underlying transport. Wraps the contents if a QOP was * negotiated during the SASL handshake. */ @Override public void flush() throws TTransportException { byte[] buf = writeBuffer.get(); int dataLength = writeBuffer.len(); writeBuffer.reset(); if (shouldWrap) { LOGGER.debug("data length before wrap: {}", dataLength); try { buf = sasl.wrap(buf, 0, dataLength); } catch (SaslException e) { throw new TTransportException(e); } dataLength = buf.length; } LOGGER.debug("writing data length: {}", dataLength); writeLength(dataLength); underlyingTransport.write(buf, 0, dataLength); underlyingTransport.flush(); }
public void open() throws TTransportException { LOGGER.debug("opening transport {}", this); if (sasl != null && sasl.isComplete()) throw new TTransportException("SASL transport already open"); while (!sasl.isComplete()) { message = receiveSaslMessage(); if (message.status != NegotiationStatus.COMPLETE && byte[] challenge = sasl.evaluateChallengeOrResponse(message.payload); sendSaslMessage(sasl.isComplete() ? NegotiationStatus.COMPLETE : NegotiationStatus.OK, challenge); assert sasl.isComplete(); String qop = (String) sasl.getNegotiatedProperty(Sasl.QOP); if (qop != null && !qop.equalsIgnoreCase("auth")) shouldWrap = true;
/** * Read a single frame of data from the underlying transport, unwrapping if * necessary. * * @throws TTransportException * Thrown if there's an error reading from the underlying transport. * @throws SaslException * Thrown if there's an error unwrapping the data. */ private void readFrame() throws TTransportException, SaslException { int dataLength = readLength(); if (dataLength < 0) throw new TTransportException("Read a negative frame size (" + dataLength + ")!"); byte[] buff = new byte[dataLength]; LOGGER.debug("{}: reading data length: {}", getRole(), dataLength); underlyingTransport.readAll(buff, 0, dataLength); if (shouldWrap) { buff = sasl.unwrap(buff, 0, buff.length); LOGGER.debug("data length after unwrap: {}", buff.length); } readBuffer.reset(buff); }
/** * Flushes to the underlying transport. Wraps the contents if a QOP was * negotiated during the SASL handshake. */ @Override public void flush() throws TTransportException { byte[] buf = writeBuffer.get(); int dataLength = writeBuffer.len(); writeBuffer.reset(); if (shouldWrap) { LOGGER.debug("data length before wrap: {}", dataLength); try { buf = sasl.wrap(buf, 0, dataLength); } catch (SaslException e) { throw new TTransportException(e); } dataLength = buf.length; } LOGGER.debug("writing data length: {}", dataLength); writeLength(dataLength); underlyingTransport.write(buf, 0, dataLength); underlyingTransport.flush(); }
protected void setSaslServer(SaslServer saslServer) { sasl = new SaslParticipant(saslServer); }
/** * Closes the underlying transport and disposes of the SASL implementation * underlying this transport. */ @Override public void close() { underlyingTransport.close(); try { sasl.dispose(); } catch (SaslException e) { // Not much we can do here. } }
/** * Closes the underlying transport and disposes of the SASL implementation * underlying this transport. */ @Override public void close() { underlyingTransport.close(); try { sasl.dispose(); } catch (SaslException e) { // Not much we can do here. } }
protected void setSaslServer(SaslServer saslServer) { sasl = new SaslParticipant(saslServer); }
/** * Create a TSaslTransport which acts as a client. * * @param saslClient * The <code>SaslClient</code> which this transport will use for SASL * negotiation. * @param underlyingTransport * The thrift transport which this transport is wrapping. */ protected TSaslTransport(SaslClient saslClient, TTransport underlyingTransport) { sasl = new SaslParticipant(saslClient); this.underlyingTransport = underlyingTransport; }
/** * True if the underlying transport is open and the SASL handshake is * complete. */ @Override public boolean isOpen() { return underlyingTransport.isOpen() && sasl != null && sasl.isComplete(); }
/** * Create a TSaslTransport which acts as a client. * * @param saslClient * The <code>SaslClient</code> which this transport will use for SASL * negotiation. * @param underlyingTransport * The thrift transport which this transport is wrapping. */ protected TSaslTransport(SaslClient saslClient, TTransport underlyingTransport) { sasl = new SaslParticipant(saslClient); this.underlyingTransport = underlyingTransport; }
/** * True if the underlying transport is open and the SASL handshake is * complete. */ @Override public boolean isOpen() { return underlyingTransport.isOpen() && sasl != null && sasl.isComplete(); }