Skip to content

Commit

Permalink
Add support for null cipher
Browse files Browse the repository at this point in the history
  • Loading branch information
RichLogan committed Jun 28, 2024
1 parent 37ad520 commit 8bfb209
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 83 deletions.
11 changes: 9 additions & 2 deletions include/qmedia/QController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@

#include <mutex>
#include <thread>
#include <optional>
#include <sframe/sframe.h>

using json = nlohmann::json;
using SourceId = std::string;

namespace qmedia
{

constexpr sframe::CipherSuite Default_Cipher_Suite = sframe::CipherSuite::AES_GCM_128_SHA256;

class QController
{
public:
Expand All @@ -30,7 +34,8 @@ class QController
QController(std::shared_ptr<QSubscriberDelegate> subscriberDelegate,
std::shared_ptr<QPublisherDelegate> publisherDelegate,
const cantina::LoggerPointer& logger,
const bool debugging = false);
const bool debugging = false,
const std::optional<sframe::CipherSuite> cipherSuite = Default_Cipher_Suite);

~QController();

Expand Down Expand Up @@ -97,7 +102,8 @@ class QController
const quicr::TransportMode transportMode,
const std::string& authToken,
quicr::bytes&& e2eToken,
std::shared_ptr<qmedia::QSubscriptionDelegate> delegate);
std::shared_ptr<qmedia::QSubscriptionDelegate> delegate,
const std::optional<sframe::CipherSuite> cipherSuite);

std::shared_ptr<PublicationDelegate> findQuicrPublicationDelegate(const quicr::Namespace& quicrNamespace);

Expand Down Expand Up @@ -166,6 +172,7 @@ class QController
bool closed;
bool is_singleordered_subscription = true;
bool is_singleordered_publication = false;
std::optional<sframe::CipherSuite> cipher_suite;
};

} // namespace qmedia
1 change: 1 addition & 0 deletions include/qmedia/QSFrameContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class QSFrameContext
{
public:
QSFrameContext(sframe::CipherSuite cipher_suite);
QSFrameContext(QSFrameContext& other);

void addEpoch(uint64_t epoch_id, const quicr::bytes& epoch_secret);
void enableEpoch(uint64_t epoch_id);
Expand Down
17 changes: 11 additions & 6 deletions include/qmedia/QuicrDelegates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <quicr/quicr_common.h>
#include <quicr/quicr_client.h>

#include <optional>
#include <string>

namespace qmedia
Expand All @@ -24,7 +25,8 @@ class SubscriptionDelegate : public quicr::SubscriberDelegate, public std::enabl
const std::string& authToken,
quicr::bytes e2eToken,
std::shared_ptr<qmedia::QSubscriptionDelegate> qDelegate,
const cantina::LoggerPointer& logger);
const cantina::LoggerPointer& logger,
const std::optional<sframe::CipherSuite> cipherSuite);

public:
[[nodiscard]] static std::shared_ptr<SubscriptionDelegate>
Expand All @@ -36,7 +38,8 @@ class SubscriptionDelegate : public quicr::SubscriberDelegate, public std::enabl
const std::string& authToken,
quicr::bytes e2eToken,
std::shared_ptr<qmedia::QSubscriptionDelegate> qDelegate,
const cantina::LoggerPointer& logger);
const cantina::LoggerPointer& logger,
const std::optional<sframe::CipherSuite> cipherSuite);

std::shared_ptr<SubscriptionDelegate> getptr() { return shared_from_this(); }

Expand Down Expand Up @@ -86,7 +89,7 @@ class SubscriptionDelegate : public quicr::SubscriberDelegate, public std::enabl
std::uint32_t currentGroupId;
std::uint16_t currentObjectId;

QSFrameContext sframe_context;
std::optional<QSFrameContext> sframe_context;
};

class PublicationDelegate : public quicr::PublisherDelegate, public std::enable_shared_from_this<PublicationDelegate>
Expand All @@ -100,7 +103,8 @@ class PublicationDelegate : public quicr::PublisherDelegate, public std::enable_
quicr::bytes&& payload,
const std::vector<std::uint8_t>& priority,
const std::vector<std::uint16_t>& expiry,
const cantina::LoggerPointer& logger);
const cantina::LoggerPointer& logger,
const std::optional<sframe::CipherSuite> cipherSuite);

public:
[[nodiscard]] static std::shared_ptr<PublicationDelegate>
Expand All @@ -113,7 +117,8 @@ class PublicationDelegate : public quicr::PublisherDelegate, public std::enable_
quicr::bytes&& payload,
const std::vector<std::uint8_t>& priority,
const std::vector<std::uint16_t>& expiry,
const cantina::LoggerPointer& logger);
const cantina::LoggerPointer& logger,
const std::optional<sframe::CipherSuite> cipherSuite);

std::shared_ptr<PublicationDelegate> getptr() { return shared_from_this(); }

Expand Down Expand Up @@ -156,6 +161,6 @@ class PublicationDelegate : public quicr::PublisherDelegate, public std::enable_
std::shared_ptr<qmedia::QPublicationDelegate> qDelegate;
const cantina::LoggerPointer logger;

QSFrameContext sframe_context;
std::optional<QSFrameContext> sframe_context;
};
} // namespace qmedia
18 changes: 12 additions & 6 deletions src/QController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ namespace qmedia
QController::QController(std::shared_ptr<QSubscriberDelegate> qSubscriberDelegate,
std::shared_ptr<QPublisherDelegate> qPublisherDelegate,
const cantina::LoggerPointer& logger,
const bool debugging) :
const bool debugging,
const std::optional<sframe::CipherSuite> cipher_suite) :
logger(std::make_shared<cantina::Logger>("QCTRL", logger)),
qSubscriberDelegate(std::move(qSubscriberDelegate)),
qPublisherDelegate(std::move(qPublisherDelegate)),
stop(false),
closed(false)
closed(false),
cipher_suite(cipher_suite)
{
// If there's a parent logger, its log level will be used.
// Otherwise, query the debugging flag.
Expand Down Expand Up @@ -179,7 +181,8 @@ QController::createQuicrSubscriptionDelegate(const std::string& sourceId,
const quicr::TransportMode transportMode,
const std::string& authToken,
quicr::bytes&& e2eToken,
std::shared_ptr<qmedia::QSubscriptionDelegate> qDelegate)
std::shared_ptr<qmedia::QSubscriptionDelegate> qDelegate,
const std::optional<sframe::CipherSuite> cipherSuite)
{
std::lock_guard<std::mutex> _(subsMutex);
if (quicrSubscriptionsMap.contains(quicrNamespace))
Expand All @@ -196,7 +199,8 @@ QController::createQuicrSubscriptionDelegate(const std::string& sourceId,
authToken,
std::move(e2eToken),
std::move(qDelegate),
logger);
logger,
cipherSuite);
return quicrSubscriptionsMap[quicrNamespace];
}

Expand Down Expand Up @@ -239,7 +243,8 @@ QController::createQuicrPublicationDelegate(std::shared_ptr<qmedia::QPublication
std::move(payload),
priority,
expiry,
logger)
logger,
cipher_suite)
};

return quicrPublicationsMap[quicrNamespace].delegate->getptr();
Expand Down Expand Up @@ -308,7 +313,8 @@ int QController::startSubscription(std::shared_ptr<qmedia::QSubscriptionDelegate
transportMode,
authToken,
std::move(e2eToken),
std::move(qDelegate));
std::move(qDelegate),
cipher_suite);
}

if (!sub_delegate)
Expand Down
9 changes: 9 additions & 0 deletions src/QSFrameContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ QSFrameContext::QSFrameContext(sframe::CipherSuite cipher_suite) : cipher_suite(
// Nothing more to do
}

QSFrameContext::QSFrameContext(QSFrameContext& other)
{
std::lock_guard<std::mutex> lock(other.context_mutex);
cipher_suite = other.cipher_suite;
current_epoch = other.current_epoch;
epoch_secrets = other.epoch_secrets;
ns_contexts = other.ns_contexts;
}

void QSFrameContext::addEpoch(uint64_t epoch_id, const quicr::bytes& epoch_secret)
{
std::lock_guard<std::mutex> lock(context_mutex);
Expand Down
Loading

0 comments on commit 8bfb209

Please sign in to comment.