23 #ifdef HAVE_SASL_SASL_H
26 #include <boost/shared_ptr.hpp>
27 #include <boost/scoped_ptr.hpp>
29 #include <thrift/transport/TBufferTransports.h>
37 namespace apache {
namespace thrift {
namespace transport {
40 : transport_(transport),
47 boost::shared_ptr<TTransport> transport)
48 : transport_(transport),
49 memBuf_(new TMemoryBuffer()),
68 return sasl_->getUsername();
72 const uint8_t* payload,
const uint32_t length,
bool flush) {
75 if (payload == NULL) {
78 messageHeader[0] = (uint8_t)status;
98 while (!
sasl_->isComplete()) {
104 ss <<
"Expected COMPLETE or OK, got " << status;
107 uint32_t challengeLength;
108 uint8_t* challenge =
sasl_->evaluateChallengeOrResponse(
109 message, resLength, &challengeLength);
111 challenge, challengeLength);
121 ss <<
"Expected COMPLETE or OK, got " << status;
146 return static_cast<uint32_t
>(len);
152 uint32_t read_end =
memBuf_->readEnd();
171 uint32_t read_bytes =
memBuf_->read(buf, len);
173 if (read_bytes > 0) {
187 uint8_t* tmpBuf =
new uint8_t[dataLength];
190 tmpBuf =
sasl_->unwrap(tmpBuf, 0, dataLength, &dataLength);
194 if (len == dataLength) {
195 memcpy(buf, tmpBuf, len);
200 memBuf_->write(tmpBuf, dataLength);
204 uint32_t ret =
memBuf_->read(buf, len);
217 const uint8_t* newBuf;
220 newBuf =
sasl_->wrap((uint8_t*)buf, 0, len, &len);
boost::scoped_array< uint8_t > protoBuf_
Buffer to hold protocol info.
void write(const uint8_t *buf, uint32_t len)
void sendSaslMessage(const NegotiationStatus status, const uint8_t *payload, const uint32_t length, bool flush=true)
void writeLength(uint32_t length)
const int32_t DEFAULT_MEM_BUF_SIZE
bool isClient_
True if this is a client.
uint32_t decodeInt(uint8_t *buf, uint32_t offset)
virtual ~TSaslTransport()
boost::shared_ptr< sasl::TSasl > sasl_
bool shouldWrap_
IF true we wrap data in encryption.
TMemoryBuffer * memBuf_
Buffer for reading and writing.
boost::shared_ptr< TTransport > transport_
Underlying transport.
static const int HEADER_LENGTH
std::string getUsername()
static const int PAYLOAD_LENGTH_BYTES
uint32_t read(uint8_t *buf, uint32_t len)
TSaslTransport(boost::shared_ptr< TTransport > transport)
void encodeInt(uint32_t x, uint8_t *buf, uint32_t offset)
uint8_t * receiveSaslMessage(NegotiationStatus *status, uint32_t *length)
virtual void handleSaslStartMessage()=0
static const int STATUS_BYTES