devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
278 lines (265 loc) • 8.84 kB
JavaScript
/**
* DevExtreme (cjs/__internal/core/license/license_validation.js)
* Version: 25.2.7
* Build date: Tue May 05 2026
*
* Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
exports.isUnsupportedKeyFormat = isUnsupportedKeyFormat;
exports.parseLicenseKey = parseLicenseKey;
exports.peekValidationPerformed = peekValidationPerformed;
exports.setLicenseCheckSkipCondition = setLicenseCheckSkipCondition;
exports.validateLicense = validateLicense;
var _config = _interopRequireDefault(require("../../../core/config"));
var _errors = _interopRequireDefault(require("../../../core/errors"));
var _version = require("../../../core/version");
var _version2 = require("../../utils/version");
var _byte_utils = require("./byte_utils");
var _const = require("./const");
var _key = require("./key");
var _lcp_key_validator = require("./lcp_key_validation/lcp_key_validator");
var _license_warnings = require("./license_warnings");
var _pkcs = require("./pkcs1");
var _rsa_bigint = require("./rsa_bigint");
var _sha = require("./sha1");
var _trial_panel = require("./trial_panel");
var _types = require("./types");
const _excluded = ["customerId", "maxVersionAllowed", "format", "internalUsageId"];
function _interopRequireDefault(e) {
return e && e.__esModule ? e : {
default: e
}
}
function _objectWithoutPropertiesLoose(r, e) {
if (null == r) {
return {}
}
var t = {};
for (var n in r) {
if ({}.hasOwnProperty.call(r, n)) {
if (-1 !== e.indexOf(n)) {
continue
}
t[n] = r[n]
}
}
return t
}
let validationPerformed = false;
function verifySignature(_ref) {
let {
text: text,
signature: encodedSignature
} = _ref;
return (0, _rsa_bigint.compareSignatures)({
key: _key.PUBLIC_KEY,
signature: (0, _byte_utils.base64ToBytes)(encodedSignature),
actual: (0, _pkcs.pad)((0, _sha.sha1)(text))
})
}
function parseLicenseKey(encodedKey) {
if (void 0 === encodedKey) {
return _types.GENERAL_ERROR
}
if ((0, _lcp_key_validator.isProductOnlyLicense)(encodedKey)) {
return (0, _lcp_key_validator.parseDevExpressProductKey)(encodedKey)
}
const parts = encodedKey.split(_const.KEY_SPLITTER);
if (2 !== parts.length || 0 === parts[0].length || 0 === parts[1].length) {
return _types.GENERAL_ERROR
}
if (!verifySignature({
text: parts[0],
signature: parts[1]
})) {
return _types.VERIFICATION_ERROR
}
let decodedPayload = "";
try {
decodedPayload = atob(parts[0])
} catch {
return _types.DECODING_ERROR
}
let payload = {};
try {
payload = JSON.parse(decodedPayload)
} catch {
return _types.DESERIALIZATION_ERROR
}
const {
customerId: customerId,
maxVersionAllowed: maxVersionAllowed,
format: format,
internalUsageId: internalUsageId
} = payload, rest = _objectWithoutPropertiesLoose(payload, _excluded);
if (void 0 !== internalUsageId) {
return {
kind: _types.TokenKind.internal,
internalUsageId: internalUsageId
}
}
if (void 0 === customerId || void 0 === maxVersionAllowed || void 0 === format) {
return _types.PAYLOAD_ERROR
}
if (format !== _const.FORMAT) {
return _types.VERSION_ERROR
}
return {
kind: _types.TokenKind.verified,
payload: Object.assign({
customerId: customerId,
maxVersionAllowed: maxVersionAllowed
}, rest)
}
}
function isPreview(patch) {
return isNaN(patch) || patch < _const.RTM_MIN_PATCH_VERSION
}
function hasLicensePrefix(licenseKey, prefix) {
return licenseKey.trim().startsWith(prefix)
}
function isUnsupportedKeyFormat(licenseKey) {
if (!licenseKey) {
return false
}
if (hasLicensePrefix(licenseKey, "LCXv1")) {
_errors.default.log("W0000", "config", "licenseKey", "LCXv1 is specified in the license key");
return true
}
return false
}
function displayTrialPanel() {
const buyNowLink = (0, _config.default)().buyNowLink ?? _const.BUY_NOW_LINK;
const licensingDocLink = (0, _config.default)().licensingDocLink ?? _const.LICENSING_DOC_LINK;
(0, _trial_panel.showTrialPanel)(buyNowLink, licensingDocLink, _version.fullVersion, _const.SUBSCRIPTION_NAMES)
}
function getLicenseCheckParams(_ref2) {
let {
licenseKey: licenseKey,
version: version
} = _ref2;
let preview = false;
try {
preview = isPreview(version.patch);
const {
major: major,
minor: minor
} = preview ? (0, _version2.getPreviousMajorVersion)(version) : version;
if (!licenseKey || licenseKey === _const.LICENSE_KEY_PLACEHOLDER) {
return {
preview: preview,
error: "W0019",
warningType: "no-key"
}
}
if (hasLicensePrefix(licenseKey, "LCX")) {
return {
preview: preview,
error: "W0021",
warningType: "lcx-used"
}
}
const license = parseLicenseKey(licenseKey);
if (license.kind === _types.TokenKind.corrupted) {
if ("product-kind" === license.error) {
return {
preview: preview,
error: "W0021",
warningType: "no-devextreme-license"
}
}
if ("trial-expired" === license.error) {
return {
preview: preview,
error: "W0020",
warningType: "trial-expired"
}
}
return {
preview: preview,
error: "W0021",
warningType: "invalid-key"
}
}
if (license.kind === _types.TokenKind.internal) {
return {
preview: preview,
internal: true,
error: license.internalUsageId === _key.INTERNAL_USAGE_ID ? void 0 : "W0020"
}
}
if (!(major && minor)) {
return {
preview: preview,
error: "W0021",
warningType: "invalid-key"
}
}
if (10 * major + minor > license.payload.maxVersionAllowed) {
return {
preview: preview,
error: "W0020",
warningType: "version-mismatch",
maxVersionAllowed: license.payload.maxVersionAllowed
}
}
return {
preview: preview,
error: void 0
}
} catch {
return {
preview: preview,
error: "W0021",
warningType: "invalid-key"
}
}
}
function validateLicense(licenseKey) {
let versionStr = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : _version.fullVersion;
if (validationPerformed) {
return
}
validationPerformed = true;
const version = (0, _version2.parseVersion)(versionStr);
const versionsCompatible = (0, _version2.assertedVersionsCompatible)(version);
const {
internal: internal,
error: error,
warningType: warningType,
maxVersionAllowed: maxVersionAllowed
} = getLicenseCheckParams({
licenseKey: licenseKey,
version: version
});
if (!versionsCompatible && internal) {
return
}
if (error && !internal) {
displayTrialPanel()
}
if (error) {
if (warningType) {
const versionInfo = "version-mismatch" === warningType && void 0 !== maxVersionAllowed ? {
keyVersion: `${Math.floor(maxVersionAllowed/10)}.${maxVersionAllowed%10}`,
requiredVersion: `${version.major}.${version.minor}`
} : void 0;
(0, _license_warnings.logLicenseWarning)(warningType, versionStr, versionInfo)
} else {
_errors.default.log(error)
}
}
}
function peekValidationPerformed() {
return validationPerformed
}
function setLicenseCheckSkipCondition() {}
var _default = exports.default = {
validateLicense: validateLicense
};