devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
282 lines (276 loc) • 8.2 kB
JavaScript
/**
* DevExtreme (esm/__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/
*/
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["customerId", "maxVersionAllowed", "format", "internalUsageId"];
import config from "../../../core/config";
import errors from "../../../core/errors";
import {
fullVersion
} from "../../../core/version";
import {
assertedVersionsCompatible,
getPreviousMajorVersion,
parseVersion
} from "../../utils/version";
import {
base64ToBytes
} from "./byte_utils";
import {
BUY_NOW_LINK,
FORMAT,
KEY_SPLITTER,
LICENSE_KEY_PLACEHOLDER,
LICENSING_DOC_LINK,
RTM_MIN_PATCH_VERSION,
SUBSCRIPTION_NAMES
} from "./const";
import {
INTERNAL_USAGE_ID,
PUBLIC_KEY
} from "./key";
import {
isProductOnlyLicense,
parseDevExpressProductKey
} from "./lcp_key_validation/lcp_key_validator";
import {
logLicenseWarning
} from "./license_warnings";
import {
pad
} from "./pkcs1";
import {
compareSignatures
} from "./rsa_bigint";
import {
sha1
} from "./sha1";
import {
showTrialPanel
} from "./trial_panel";
import {
DECODING_ERROR,
DESERIALIZATION_ERROR,
GENERAL_ERROR,
PAYLOAD_ERROR,
TokenKind,
VERIFICATION_ERROR,
VERSION_ERROR
} from "./types";
let validationPerformed = false;
function verifySignature(_ref) {
let {
text: text,
signature: encodedSignature
} = _ref;
return compareSignatures({
key: PUBLIC_KEY,
signature: base64ToBytes(encodedSignature),
actual: pad(sha1(text))
})
}
export function parseLicenseKey(encodedKey) {
if (void 0 === encodedKey) {
return GENERAL_ERROR
}
if (isProductOnlyLicense(encodedKey)) {
return parseDevExpressProductKey(encodedKey)
}
const parts = encodedKey.split(KEY_SPLITTER);
if (2 !== parts.length || 0 === parts[0].length || 0 === parts[1].length) {
return GENERAL_ERROR
}
if (!verifySignature({
text: parts[0],
signature: parts[1]
})) {
return VERIFICATION_ERROR
}
let decodedPayload = "";
try {
decodedPayload = atob(parts[0])
} catch {
return DECODING_ERROR
}
let payload = {};
try {
payload = JSON.parse(decodedPayload)
} catch {
return DESERIALIZATION_ERROR
}
const {
customerId: customerId,
maxVersionAllowed: maxVersionAllowed,
format: format,
internalUsageId: internalUsageId
} = payload, rest = _objectWithoutPropertiesLoose(payload, _excluded);
if (void 0 !== internalUsageId) {
return {
kind: TokenKind.internal,
internalUsageId: internalUsageId
}
}
if (void 0 === customerId || void 0 === maxVersionAllowed || void 0 === format) {
return PAYLOAD_ERROR
}
if (format !== FORMAT) {
return VERSION_ERROR
}
return {
kind: TokenKind.verified,
payload: Object.assign({
customerId: customerId,
maxVersionAllowed: maxVersionAllowed
}, rest)
}
}
function isPreview(patch) {
return isNaN(patch) || patch < RTM_MIN_PATCH_VERSION
}
function hasLicensePrefix(licenseKey, prefix) {
return licenseKey.trim().startsWith(prefix)
}
export function isUnsupportedKeyFormat(licenseKey) {
if (!licenseKey) {
return false
}
if (hasLicensePrefix(licenseKey, "LCXv1")) {
errors.log("W0000", "config", "licenseKey", "LCXv1 is specified in the license key");
return true
}
return false
}
function displayTrialPanel() {
const buyNowLink = config().buyNowLink ?? BUY_NOW_LINK;
const licensingDocLink = config().licensingDocLink ?? LICENSING_DOC_LINK;
showTrialPanel(buyNowLink, licensingDocLink, fullVersion, 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 ? getPreviousMajorVersion(version) : version;
if (!licenseKey || licenseKey === 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 === 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 === TokenKind.internal) {
return {
preview: preview,
internal: true,
error: license.internalUsageId === 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"
}
}
}
export function validateLicense(licenseKey) {
let versionStr = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : fullVersion;
if (validationPerformed) {
return
}
validationPerformed = true;
const version = parseVersion(versionStr);
const versionsCompatible = 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;
logLicenseWarning(warningType, versionStr, versionInfo)
} else {
errors.log(error)
}
}
}
export function peekValidationPerformed() {
return validationPerformed
}
export function setLicenseCheckSkipCondition() {}
export default {
validateLicense: validateLicense
};