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
@@ -50,7 +50,12 @@ int main()
|
||||
"level": "verbose",
|
||||
"fileName": "../outside.log",
|
||||
"maxFileSizeBytes": 1,
|
||||
"maxFiles": 0
|
||||
"maxFiles": 0,
|
||||
"format": "xml",
|
||||
"pattern": "",
|
||||
"mode": "parallel",
|
||||
"queueCapacity": 1,
|
||||
"overflowPolicy": "discard"
|
||||
}
|
||||
})");
|
||||
expect(logging.has_value(), "logging configuration parses");
|
||||
@@ -63,12 +68,49 @@ int main()
|
||||
"log size is clamped to a safe minimum");
|
||||
expect(logging->logging.maxFiles == 1,
|
||||
"at least one rolled log is retained");
|
||||
expect(logging->logging.format == "pattern" &&
|
||||
!logging->logging.pattern.empty(),
|
||||
"invalid formatter configuration is normalized");
|
||||
expect(logging->logging.mode == "async" &&
|
||||
logging->logging.queueCapacity == 16 &&
|
||||
logging->logging.overflowPolicy == "block",
|
||||
"invalid dispatch configuration is normalized");
|
||||
}
|
||||
const auto parentLog =
|
||||
ConfigLoader::loadFromJson(R"({"logging":{"fileName":".."}})");
|
||||
expect(parentLog && parentLog->logging.fileName == "echoion.log",
|
||||
"parent-directory logging filename is normalized");
|
||||
|
||||
const auto licensing = ConfigLoader::loadFromJson(R"({
|
||||
"licensing": {
|
||||
"required": true,
|
||||
"serviceUrl": "http://downgrade.example",
|
||||
"productId": "",
|
||||
"activationTokenEnv": "",
|
||||
"refreshInterval": "1m",
|
||||
"retryInterval": "1s",
|
||||
"maximumLeaseLifetime": "72h"
|
||||
}
|
||||
})");
|
||||
expect(licensing.has_value(), "licensing configuration parses");
|
||||
if (licensing) {
|
||||
expect(licensing->licensing.required,
|
||||
"licensing required flag is preserved");
|
||||
expect(licensing->licensing.serviceUrl.empty(),
|
||||
"licensing service cannot downgrade from HTTPS");
|
||||
expect(licensing->licensing.productId == "echoion" &&
|
||||
licensing->licensing.activationTokenEnv ==
|
||||
"ECHOION_LICENSE_TOKEN",
|
||||
"licensing identifiers receive safe defaults");
|
||||
expect(licensing->licensing.refreshInterval ==
|
||||
std::chrono::minutes(15) &&
|
||||
licensing->licensing.retryInterval ==
|
||||
std::chrono::seconds(30) &&
|
||||
licensing->licensing.maximumLeaseLifetime ==
|
||||
std::chrono::hours(24),
|
||||
"licensing cadence and offline lease are bounded");
|
||||
}
|
||||
|
||||
expectShortening("legacy disabled",
|
||||
R"({
|
||||
"youtube": {"enableUrlShortening": false},
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
#include "echoion/core/playback/GaplessHandoff.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace
|
||||
{
|
||||
int failures = 0;
|
||||
|
||||
void expect(bool condition, const char* message)
|
||||
{
|
||||
if (!condition) {
|
||||
std::cerr << "FAILED: " << message << '\n';
|
||||
++failures;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
using Echoion::Core::PlaybackDetail::canFillDeviceFrame;
|
||||
|
||||
expect(canFillDeviceFrame(300, 700, 1000),
|
||||
"outgoing tail and incoming head can exactly fill a frame");
|
||||
expect(canFillDeviceFrame(300, 900, 1000),
|
||||
"extra incoming PCM is retained for the next frame");
|
||||
expect(!canFillDeviceFrame(300, 699, 1000),
|
||||
"handoff waits rather than padding when incoming PCM is short");
|
||||
expect(!canFillDeviceFrame(0, 1000, 1000),
|
||||
"an empty outgoing tail is a normal track-end path");
|
||||
expect(!canFillDeviceFrame(1000, 1000, 1000),
|
||||
"a complete outgoing frame does not need a boundary join");
|
||||
|
||||
return failures == 0 ? 0 : 1;
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
#include "echoion/core/licensing/LicenseVerifier.hpp"
|
||||
|
||||
#include <Void/Text/Base64.hpp>
|
||||
|
||||
#include <openssl/evp.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr std::string_view seedHex =
|
||||
"9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60";
|
||||
constexpr std::string_view publicHex =
|
||||
"d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a";
|
||||
|
||||
std::string hex(std::string_view value)
|
||||
{
|
||||
std::string output;
|
||||
output.reserve(value.size() / 2);
|
||||
for (std::size_t index = 0; index < value.size(); index += 2) {
|
||||
output.push_back(static_cast<char>(
|
||||
std::stoi(std::string{value.substr(index, 2)}, nullptr, 16)));
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
std::string sign(std::string_view message)
|
||||
{
|
||||
using Key = std::unique_ptr<EVP_PKEY, decltype(&EVP_PKEY_free)>;
|
||||
using Context = std::unique_ptr<EVP_MD_CTX, decltype(&EVP_MD_CTX_free)>;
|
||||
const auto seed = hex(seedHex);
|
||||
Key key{EVP_PKEY_new_raw_private_key(
|
||||
EVP_PKEY_ED25519, nullptr,
|
||||
reinterpret_cast<const unsigned char*>(seed.data()),
|
||||
seed.size()),
|
||||
&EVP_PKEY_free};
|
||||
Context context{EVP_MD_CTX_new(), &EVP_MD_CTX_free};
|
||||
if (!key || !context ||
|
||||
EVP_DigestSignInit(context.get(), nullptr, nullptr, nullptr,
|
||||
key.get()) != 1) {
|
||||
return {};
|
||||
}
|
||||
std::string signature(Void::Crypto::Ed25519SignatureSize, '\0');
|
||||
std::size_t size = signature.size();
|
||||
if (EVP_DigestSign(
|
||||
context.get(),
|
||||
reinterpret_cast<unsigned char*>(signature.data()), &size,
|
||||
reinterpret_cast<const unsigned char*>(message.data()),
|
||||
message.size()) != 1) {
|
||||
return {};
|
||||
}
|
||||
signature.resize(size);
|
||||
return signature;
|
||||
}
|
||||
|
||||
std::string envelope(std::string_view payload)
|
||||
{
|
||||
return std::format(
|
||||
"{{\n \"schemaVersion\": 3,\n \"keyId\": \"test-key\",\n"
|
||||
" \"document\": {},\n \"signedPayload\": \"{}\",\n"
|
||||
" \"signature\": \"{}\"\n}}",
|
||||
payload, Void::Encoding::Base64::encode_url(payload),
|
||||
Void::Encoding::Base64::encode_url(sign(payload)));
|
||||
}
|
||||
|
||||
int failures = 0;
|
||||
void expect(bool condition, std::string_view message)
|
||||
{
|
||||
if (!condition) {
|
||||
std::cerr << "FAILED: " << message << '\n';
|
||||
++failures;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace Echoion::Core::Licensing;
|
||||
const auto publicKey = hex(publicHex);
|
||||
const auto encodedKey = Void::Encoding::Base64::encode_url(publicKey);
|
||||
Void::Update::Keyring keys;
|
||||
expect(addPublicKey(keys, "test-key", encodedKey).has_value(),
|
||||
"base64url public key is accepted");
|
||||
expect(!addPublicKey(keys, "broken\nkey", encodedKey),
|
||||
"public key ids reject whitespace and control characters");
|
||||
|
||||
constexpr std::uint64_t now = 1'800'000'000;
|
||||
const auto lease = std::format(
|
||||
R"({{"document":"echoion-license-lease","licenseId":"lic-1","accountId":"account-1","deviceId":"device-1","productId":"echoion","productVersion":"2.0.0","buildSignature":"build-1","challenge":"challenge-1","status":"active","issuedAt":{},"refreshAfter":{},"expiresAt":{},"sequence":42,"revocationSequence":8,"entitlements":["runtime","updates"]}})",
|
||||
now - 10, now + 3600, now + 7200);
|
||||
const auto revocations = std::format(
|
||||
R"({{"document":"echoion-license-revocations","sequence":8,"generatedAt":{},"expiresAt":{},"licenseIds":[],"accountIds":[],"deviceIds":[],"buildSignatures":[],"keyIds":[]}})",
|
||||
now - 10, now + 7200);
|
||||
LeaseContext context{
|
||||
.productId = "echoion",
|
||||
.productVersion = "2.0.0",
|
||||
.deviceId = "device-1",
|
||||
.buildSignature = "build-1",
|
||||
.challenge = "challenge-1",
|
||||
.now = std::chrono::system_clock::time_point{std::chrono::seconds{now}},
|
||||
.maximumLeaseLifetime = std::chrono::hours(24),
|
||||
.minimumSequence = 41};
|
||||
|
||||
auto active =
|
||||
verifyLease(envelope(lease), envelope(revocations), keys, context);
|
||||
expect(active && active->mode == Mode::Active && active->sequence == 42,
|
||||
"matching signed lease enables normal operation");
|
||||
|
||||
context.buildSignature = "pirated-build";
|
||||
expect(!verifyLease(envelope(lease), envelope(revocations), keys, context),
|
||||
"build signature mismatch fails closed");
|
||||
context.buildSignature = "build-1";
|
||||
|
||||
const auto revoked = std::format(
|
||||
R"({{"document":"echoion-license-revocations","sequence":9,"generatedAt":{},"expiresAt":{},"licenseIds":["lic-1"],"accountIds":[],"deviceIds":[],"buildSignatures":[],"keyIds":[]}})",
|
||||
now - 10, now + 7200);
|
||||
expect(!verifyLease(envelope(lease), envelope(revoked), keys, context),
|
||||
"specific license revocation fails closed");
|
||||
|
||||
context.minimumSequence = 43;
|
||||
expect(!verifyLease(envelope(lease), envelope(revocations), keys, context),
|
||||
"older lease sequence cannot be replayed");
|
||||
|
||||
return failures == 0 ? 0 : 1;
|
||||
}
|
||||
Reference in new issue
Block a user