Skip to content

Commit

Permalink
Clamp features and do not allow invalid serial key (#26)
Browse files Browse the repository at this point in the history
* Update subproject commit reference

* Add feature clamping in LicenseHandler and update subproject reference

* Update subproject commit reference
  • Loading branch information
nbolton authored Jan 21, 2025
1 parent b17db37 commit 9b475e0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion odin
34 changes: 26 additions & 8 deletions src/lib/synergy/gui/license/LicenseHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ bool LicenseHandler::handleStart(QMainWindow *parent, AppConfig *appConfig) {
if (m_license.isValid()) {
qDebug("license is valid, continuing with start");
updateWindowTitle();
clampFeatures();
return true;
}

Expand Down Expand Up @@ -122,8 +123,7 @@ bool LicenseHandler::loadSettings() {
const auto result = setLicense(m_settings.serialKey(), true);
if (result != SetSerialKeyResult::kSuccess) {
qWarning("set serial key failed, showing activation dialog");
showActivationDialog();
return false;
return showActivationDialog();
}
}

Expand All @@ -142,7 +142,8 @@ bool LicenseHandler::showActivationDialog() {
if (result == QDialog::Accepted) {
saveSettings();
updateWindowTitle();
m_appConfig->setTlsEnabled(m_license.isTlsAvailable());
clampFeatures();

qDebug("license activation dialog accepted");
return true;
} else {
Expand Down Expand Up @@ -217,16 +218,16 @@ LicenseHandler::setLicense(const QString &hexString, bool allowExpired) {
qDebug() << "changing serial key to:" << hexString;
auto serialKey = parseSerialKey(hexString);

if (serialKey == m_license.serialKey()) {
qDebug("serial key did not change, ignoring");
return kUnchanged;
}

if (!serialKey.isValid) {
qWarning() << "invalid serial key, ignoring:" << hexString;
return kInvalid;
}

if (serialKey == m_license.serialKey()) {
qDebug("serial key did not change, ignoring");
return kUnchanged;
}

auto license = License(serialKey);
if (m_time.hasTestTime()) {
license.setNowFunc([this]() { return m_time.now(); });
Expand Down Expand Up @@ -268,3 +269,20 @@ void LicenseHandler::validate() {

qDebug("license validation succeeded");
}

void LicenseHandler::clampFeatures() {
if (m_appConfig->tlsEnabled() && !m_license.isTlsAvailable()) {
qWarning("tls not available, disabling tls");
}

if (m_appConfig->invertConnection() &&
!m_license.isInvertConnectionAvailable()) {
qWarning("invert connection not available, disabling invert connection");
}

m_appConfig->setInvertConnection(m_license.isInvertConnectionAvailable());
m_appConfig->setTlsEnabled(m_license.isTlsAvailable());

qDebug("committing default feature settings");
m_appConfig->commit();
}
1 change: 1 addition & 0 deletions src/lib/synergy/gui/license/LicenseHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class LicenseHandler : public QObject {
QString productName() const;
SetSerialKeyResult
setLicense(const QString &hexString, bool allowExpired = false);
void clampFeatures();

private:
void checkTlsCheckBox(
Expand Down

0 comments on commit 9b475e0

Please sign in to comment.