Enforce signed licenses and seamless track handoff
Independent component release / publish (push) Failing after 11s
Independent component release / publish (push) Failing after 11s
This commit is contained in:
15 files changed
+1367
-98
No files matched your search
@@ -6,6 +6,7 @@
|
||||
#include "MusicManager.hpp"
|
||||
#include "NetworkClient.hpp"
|
||||
#include "RpcServer.hpp"
|
||||
#include "licensing/LicenseManager.hpp"
|
||||
#ifdef ECHOION_WITH_WEB
|
||||
#include "echoion/web/HttpServer.hpp"
|
||||
#endif
|
||||
@@ -192,9 +193,12 @@ namespace Echoion::Core
|
||||
|
||||
// Guard helper: ok if initialized, else a ServiceUnavailable error.
|
||||
[[nodiscard]] Api::Result<void> requireInitialized() const noexcept;
|
||||
// Normal bot operations are denied while licensing is update-only.
|
||||
[[nodiscard]] Api::Result<void> requireOperational() const noexcept;
|
||||
|
||||
// Components
|
||||
std::shared_ptr<NetworkClient> networkClient_;
|
||||
std::unique_ptr<Licensing::LicenseManager> licenseManager_;
|
||||
std::shared_ptr<LyricsService> lyricsService_;
|
||||
std::shared_ptr<MusicManager> musicManager_;
|
||||
std::unique_ptr<CommandManager> commandManager_;
|
||||
|
||||
@@ -25,19 +25,25 @@ namespace Echoion::Core
|
||||
NetworkClient();
|
||||
~NetworkClient() override;
|
||||
|
||||
Api::Result<void> initialize(
|
||||
const std::optional<Void::Net::ProxyConfig>& proxy =
|
||||
std::nullopt) override;
|
||||
Api::Result<void>
|
||||
initialize(const std::optional<Void::Net::ProxyConfig>& proxy =
|
||||
std::nullopt) override;
|
||||
void shutdown() override;
|
||||
|
||||
// Synchronous requests
|
||||
[[nodiscard]] Api::Result<Void::Net::Response>
|
||||
get(std::string_view url,
|
||||
const std::vector<Void::Net::Header>& headers = {}) override;
|
||||
[[nodiscard]] Api::Result<Void::Net::Response>
|
||||
post(std::string_view url, std::string_view body,
|
||||
const std::vector<Void::Net::Header>& headers = {})
|
||||
override;
|
||||
[[nodiscard]] Api::Result<Void::Net::Response> get(
|
||||
std::string_view url,
|
||||
const std::vector<Void::Net::Header>& headers = {}) override;
|
||||
[[nodiscard]] Api::Result<Void::Net::Response> post(
|
||||
std::string_view url, std::string_view body,
|
||||
const std::vector<Void::Net::Header>& headers = {}) override;
|
||||
// Security-sensitive HTTPS request. Unlike legacy media scraping
|
||||
// requests, this always verifies the peer certificate and follows
|
||||
// no redirects so credentials cannot be forwarded to another
|
||||
// origin.
|
||||
[[nodiscard]] Api::Result<Void::Net::Response> postVerifiedTls(
|
||||
std::string_view url, std::string_view body,
|
||||
const std::vector<Void::Net::Header>& headers = {});
|
||||
[[nodiscard]] Api::Result<Void::Net::Response>
|
||||
request(const Void::Net::Request& req) override;
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
|
||||
#include "echoion/core/NetworkClient.hpp"
|
||||
#include "echoion/core/licensing/LicenseVerifier.hpp"
|
||||
|
||||
#include <ConfigTypes.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
namespace Echoion::Core::Licensing
|
||||
{
|
||||
class LicenseManager
|
||||
{
|
||||
public:
|
||||
|
||||
LicenseManager(Api::LicensingConfig config,
|
||||
std::shared_ptr<NetworkClient>
|
||||
network,
|
||||
std::filesystem::path stateDirectory);
|
||||
~LicenseManager();
|
||||
|
||||
LicenseManager(const LicenseManager&) = delete;
|
||||
LicenseManager& operator=(const LicenseManager&) = delete;
|
||||
|
||||
/// Load a still-valid cached lease and then attempt an online
|
||||
/// refresh. A failed refresh retains a valid cache; otherwise
|
||||
/// operation remains update-only.
|
||||
void initialize();
|
||||
void shutdown();
|
||||
void refreshNow();
|
||||
|
||||
[[nodiscard]] bool canOperate() const noexcept;
|
||||
[[nodiscard]] LeaseStatus status() const;
|
||||
[[nodiscard]] std::string deviceId() const;
|
||||
|
||||
private:
|
||||
|
||||
[[nodiscard]] Void::Result::Result<LeaseStatus>
|
||||
verifyBundle(std::string_view bundle,
|
||||
std::string_view expectedChallenge);
|
||||
[[nodiscard]] std::string loadOrCreateDeviceId();
|
||||
void installStatus(LeaseStatus status);
|
||||
void installFailure(std::string reason,
|
||||
bool retainValidLease = true);
|
||||
void run(std::stop_token stopToken);
|
||||
|
||||
Api::LicensingConfig config_;
|
||||
std::shared_ptr<NetworkClient> network_;
|
||||
std::filesystem::path stateDirectory_;
|
||||
Void::Update::Keyring rootKeys_;
|
||||
std::string deviceId_;
|
||||
std::atomic<bool> operational_{false};
|
||||
std::atomic<std::int64_t> operationalUntilUnix_{0};
|
||||
mutable std::mutex mutex_;
|
||||
LeaseStatus status_;
|
||||
std::jthread refreshThread_;
|
||||
std::uint64_t minimumSequence_{0};
|
||||
};
|
||||
} // namespace Echoion::Core::Licensing
|
||||
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/Functional/Result.hpp>
|
||||
#include <Void/Update/Feed.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace Echoion::Core::Licensing
|
||||
{
|
||||
enum class Mode { Active, UpdateOnly };
|
||||
|
||||
struct LeaseContext {
|
||||
std::string productId;
|
||||
std::string productVersion;
|
||||
std::string deviceId;
|
||||
std::string buildSignature;
|
||||
std::string challenge;
|
||||
std::chrono::system_clock::time_point now;
|
||||
std::chrono::milliseconds maximumLeaseLifetime{
|
||||
std::chrono::hours(24)};
|
||||
std::uint64_t minimumSequence{0};
|
||||
};
|
||||
|
||||
struct LeaseStatus {
|
||||
Mode mode{Mode::UpdateOnly};
|
||||
std::string reason;
|
||||
std::string licenseId;
|
||||
std::uint64_t sequence{0};
|
||||
std::chrono::system_clock::time_point refreshAfter;
|
||||
std::chrono::system_clock::time_point expiresAt;
|
||||
std::vector<std::string> entitlements;
|
||||
};
|
||||
|
||||
/// Decode a base64/base64url Ed25519 public key and add it to a keyring.
|
||||
[[nodiscard]] Void::Result::Result<void>
|
||||
addPublicKey(Void::Update::Keyring& keyring, std::string_view keyId,
|
||||
std::string_view encodedKey);
|
||||
|
||||
/// Verify a root-signed keyset and append currently valid, non-revoked
|
||||
/// lease signing keys. The pinned root itself remains in the returned
|
||||
/// keyring so a direct emergency root-signed lease can still be accepted.
|
||||
[[nodiscard]] Void::Result::Result<Void::Update::Keyring>
|
||||
verifyKeyset(std::string_view envelopeJson,
|
||||
const Void::Update::Keyring& rootKeys,
|
||||
std::chrono::system_clock::time_point now);
|
||||
|
||||
/// Verify the signed lease and signed revocation snapshot as one decision.
|
||||
/// Any malformed, expired, replayed, mismatched, or revoked input fails
|
||||
/// closed into UpdateOnly through the returned error.
|
||||
[[nodiscard]] Void::Result::Result<LeaseStatus>
|
||||
verifyLease(std::string_view leaseEnvelopeJson,
|
||||
std::string_view revocationEnvelopeJson,
|
||||
const Void::Update::Keyring& leaseKeys,
|
||||
const LeaseContext& context);
|
||||
} // namespace Echoion::Core::Licensing
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace Echoion::Core::PlaybackDetail
|
||||
{
|
||||
/// A boundary can be emitted without padding when the outgoing tail and
|
||||
/// already-decoded incoming PCM together fill one device frame.
|
||||
[[nodiscard]] constexpr bool
|
||||
canFillDeviceFrame(std::size_t outgoingSamples,
|
||||
std::size_t incomingSamples,
|
||||
std::size_t frameSamples) noexcept
|
||||
{
|
||||
return frameSamples > 0 && outgoingSamples > 0 &&
|
||||
outgoingSamples < frameSamples &&
|
||||
incomingSamples >= frameSamples - outgoingSamples;
|
||||
}
|
||||
} // namespace Echoion::Core::PlaybackDetail
|
||||
Reference in new issue
Block a user