-
Notifications
You must be signed in to change notification settings - Fork 142
WIP Feat[MQB]: add authentication with basic logic #696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
fe27c7b
74e138c
4b47a41
7f8652e
867f11b
1d94c30
338d9a9
cef4a2d
f750a50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -246,6 +246,14 @@ int SessionUtil::createApplication(SessionImpl* sessionImpl) | |
|
||
static bsls::AtomicInt s_sessionInstanceCount(0); | ||
|
||
// Authentication Message | ||
bmqp_ctrlmsg::AuthenticationMessage authenticationMessage; | ||
bmqp_ctrlmsg::AuthenticateRequest& ar = | ||
authenticationMessage.makeAuthenticateRequest(); | ||
bsl::string str = "username:password"; | ||
ar.mechanism() = "basic"; | ||
ar.data() = bsl::vector<char>(str.begin(), str.end()); // hexBinary | ||
|
||
// Negotiation Message | ||
bmqp_ctrlmsg::NegotiationMessage negotiationMessage; | ||
bmqp_ctrlmsg::ClientIdentity& ci = negotiationMessage.makeClientIdentity(); | ||
|
@@ -311,6 +319,7 @@ int SessionUtil::createApplication(SessionImpl* sessionImpl) | |
sessionImpl->d_application_mp.load( | ||
new (*(sessionImpl->d_allocator_p)) | ||
bmqimp::Application(options, | ||
authenticationMessage, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In its proper form, this probably won't be a concrete object, but rather something user-provided via |
||
negotiationMessage, | ||
eventHandler, | ||
sessionImpl->d_allocator_p), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
// BMQ | ||
#include <bmqex_executionpolicy.h> | ||
#include <bmqex_systemexecutor.h> | ||
#include <bmqimp_initialconnectionchannelfactory.h> | ||
#include <bmqio_channelutil.h> | ||
#include <bmqio_connectoptions.h> | ||
#include <bmqio_status.h> | ||
|
@@ -73,7 +74,7 @@ namespace { | |
// CONSTANTS | ||
const double k_RECONNECT_INTERVAL_MS = 500; | ||
const int k_RECONNECT_COUNT = bsl::numeric_limits<int>::max(); | ||
const bsls::Types::Int64 k_CHANNEL_LOW_WATERMARK = 512 * 1024; | ||
const bsls::Types::Int64 k_CHANNEL_LOW_WATERMARK = 512 * 1024; | ||
const int k_DEFAULT_MAX_MISSED_HEARTBEATS = 10; | ||
const int k_DEFAULT_HEARTBEAT_INTERVAL_MS = 1000; | ||
|
||
|
@@ -385,7 +386,7 @@ bmqt::GenericResult::Enum Application::startChannel() | |
.setAttemptInterval(attemptInterval) | ||
.setAutoReconnect(true); | ||
|
||
d_negotiatedChannelFactory.connect( | ||
d_initialConnectionChannelFactory.connect( | ||
&status, | ||
&d_connectHandle_mp, | ||
options, | ||
|
@@ -550,10 +551,11 @@ Application::stateCb(bmqimp::BrokerSession::State::Enum oldState, | |
} | ||
|
||
Application::Application( | ||
const bmqt::SessionOptions& sessionOptions, | ||
const bmqp_ctrlmsg::NegotiationMessage& negotiationMessage, | ||
const EventQueue::EventHandlerCallback& eventHandlerCB, | ||
bslma::Allocator* allocator) | ||
const bmqt::SessionOptions& sessionOptions, | ||
const bmqp_ctrlmsg::AuthenticationMessage& authenticationMessage, | ||
const bmqp_ctrlmsg::NegotiationMessage& negotiationMessage, | ||
const EventQueue::EventHandlerCallback& eventHandlerCB, | ||
bslma::Allocator* allocator) | ||
: d_allocatorStatContext(bmqst::StatContextConfiguration("Allocators", | ||
allocator), | ||
allocator) | ||
|
@@ -597,12 +599,15 @@ Application::Application( | |
bdlf::PlaceHolders::_2), // handle | ||
allocator), | ||
allocator) | ||
, d_negotiatedChannelFactory( | ||
NegotiatedChannelFactoryConfig(&d_statChannelFactory, | ||
negotiationMessage, | ||
sessionOptions.connectTimeout(), | ||
d_blobSpPool_sp.get(), | ||
allocator), | ||
, d_initialConnectionChannelFactory( | ||
InitialConnectionChannelFactoryConfig( | ||
&d_statChannelFactory, | ||
authenticationMessage, | ||
sessionOptions.connectTimeout(), // TODO: different for authn? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we have a different timeout for authentication? |
||
negotiationMessage, | ||
sessionOptions.connectTimeout(), | ||
d_blobSpPool_sp.get(), | ||
allocator), | ||
allocator) | ||
, d_connectHandle_mp() | ||
, d_brokerSession(&d_scheduler, | ||
|
@@ -761,9 +766,9 @@ Application::createMonitor(const bsl::shared_ptr<bmqio::Channel>& channel) | |
{ | ||
int maxMissedHeartbeats = k_DEFAULT_MAX_MISSED_HEARTBEATS; | ||
|
||
channel->properties().load( | ||
&maxMissedHeartbeats, | ||
NegotiatedChannelFactory::k_CHANNEL_PROPERTY_MAX_MISSED_HEARTBEATS); | ||
channel->properties().load(&maxMissedHeartbeats, | ||
InitialConnectionChannelFactory:: | ||
k_CHANNEL_PROPERTY_MAX_MISSED_HEARTBEATS); | ||
|
||
bsl::shared_ptr<bmqp::HeartbeatMonitor> monitor( | ||
new (d_allocator) bmqp::HeartbeatMonitor(maxMissedHeartbeats), | ||
|
@@ -784,9 +789,9 @@ void Application::startHeartbeat( | |
|
||
int heartbeatIntervalMs = k_DEFAULT_HEARTBEAT_INTERVAL_MS; | ||
|
||
channel->properties().load( | ||
&heartbeatIntervalMs, | ||
NegotiatedChannelFactory::k_CHANNEL_PROPERTY_HEARTBEAT_INTERVAL_MS); | ||
channel->properties().load(&heartbeatIntervalMs, | ||
InitialConnectionChannelFactory:: | ||
k_CHANNEL_PROPERTY_HEARTBEAT_INTERVAL_MS); | ||
|
||
bsls::TimeInterval interval; | ||
interval.addMilliseconds(heartbeatIntervalMs); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ | |
|
||
#include <bmqimp_brokersession.h> | ||
#include <bmqimp_eventqueue.h> | ||
#include <bmqimp_negotiatedchannelfactory.h> | ||
#include <bmqimp_initialconnectionchannelfactory.h> | ||
#include <bmqp_ctrlmsg_messages.h> | ||
#include <bmqp_heartbeatmonitor.h> | ||
#include <bmqt_sessionoptions.h> | ||
|
@@ -81,7 +81,7 @@ namespace bmqimp { | |
class Application { | ||
public: | ||
// PUBLIC TYPES | ||
typedef bmqp::BlobPoolUtil::BlobSpPool BlobSpPool; | ||
typedef bmqp::BlobPoolUtil::BlobSpPool BlobSpPool; | ||
typedef bmqp::BlobPoolUtil::BlobSpPoolSp BlobSpPoolSp; | ||
|
||
private: | ||
|
@@ -134,7 +134,7 @@ class Application { | |
|
||
bmqio::StatChannelFactory d_statChannelFactory; | ||
|
||
NegotiatedChannelFactory d_negotiatedChannelFactory; | ||
InitialConnectionChannelFactory d_initialConnectionChannelFactory; | ||
|
||
ChannelFactoryOpHandleMp d_connectHandle_mp; | ||
|
||
|
@@ -226,7 +226,8 @@ class Application { | |
const bsl::shared_ptr<bmqp::HeartbeatMonitor>& monitor); | ||
bsl::shared_ptr<bmqp::HeartbeatMonitor> | ||
createMonitor(const bsl::shared_ptr<bmqio::Channel>& channel); | ||
void startHeartbeat(const bsl::shared_ptr<bmqio::Channel>& channel, | ||
void | ||
startHeartbeat(const bsl::shared_ptr<bmqio::Channel>& channel, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a formatter bug @dorjesinpo encountered |
||
const bsl::shared_ptr<bmqp::HeartbeatMonitor>& monitor); | ||
void stopHeartbeat(); | ||
|
||
|
@@ -249,10 +250,12 @@ class Application { | |
/// negotiation. The application will use the specified | ||
/// `eventHandlerCB`. Use the specified `allocator` for all memory | ||
/// allocations. | ||
Application(const bmqt::SessionOptions& sessionOptions, | ||
const bmqp_ctrlmsg::NegotiationMessage& negotiationMessage, | ||
const EventQueue::EventHandlerCallback& eventHandlerCB, | ||
bslma::Allocator* allocator); | ||
Application( | ||
const bmqt::SessionOptions& sessionOptions, | ||
const bmqp_ctrlmsg::AuthenticationMessage& authenticationMessage, | ||
const bmqp_ctrlmsg::NegotiationMessage& negotiationMessage, | ||
const EventQueue::EventHandlerCallback& eventHandlerCB, | ||
bslma::Allocator* allocator); | ||
|
||
/// Destructor | ||
~Application(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few notes:
Binary hex introduces
+100%
protocol overhead todata.size()
after encoding.If we use
base64
, we can have+33%
protocol overhead.Probably it's not a problem, because we don't intend to send authn requests too often and don't want to send too much data here.
Should binary hex be enforced? If so, it's worth to add checks in both client library (before sending a request) and on the broker side (when request is received).
This also means that
"username:password"
data provided here will be rejected.Another way to enforce binary hex is to hide it from the library user.
Let the user to just assign
bsl::vector<char> data
to anything, and convert it to binary hex when message is packed.What variations of capital letters does this hex binary support?
abcdef
,ABCDEF
, or bothabcdefABCDEF
?