fix
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { LicenseInfo, LicenseCheckResult } from '@/types/license';
|
||||
import type { LicenseInfo, LicenseCheckResult, SavedLicense } from '@/types/license';
|
||||
import i18n from '@/i18n';
|
||||
import { LicenseStorage } from '@/utils/license-storage';
|
||||
import { PermissionService } from '@/utils/permissions';
|
||||
@@ -46,21 +46,20 @@ export class LicenseService {
|
||||
* 检查许可证是否有效
|
||||
* 参数是解码后的JWT结构,验证签名和payload进行原有检查
|
||||
*/
|
||||
static checkLicenseAvailable(jwtString: string, decodedJWT: KJUR.jws.JWS.JWSResult): boolean {
|
||||
static checkLicenseAvailable(savedLicense: SavedLicense): boolean {
|
||||
try {
|
||||
// 验证完整的JWT
|
||||
const result = KJUR.jws.JWS.verifyJWT(jwtString, rsaPublicKey.trim(), {alg: ['RS256']});
|
||||
const result = KJUR.jws.JWS.verifyJWT(savedLicense.jwt, rsaPublicKey.trim(), {alg: ['RS256']});
|
||||
if (!result) {
|
||||
console.warn('JWT signature verification failed');
|
||||
return false;
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('JWT verification or parsing failed:', error);
|
||||
return false;
|
||||
}
|
||||
// JWT验证通过,从payloadPP解析license进行原有检查
|
||||
const license: LicenseInfo = JSON.parse(decodedJWT.payloadPP);
|
||||
|
||||
const license = savedLicense.licenseInfo;
|
||||
|
||||
const domain = this.getDomain()
|
||||
const pluginId = this.getPluginId()
|
||||
@@ -127,18 +126,21 @@ export class LicenseService {
|
||||
|
||||
const jwt = response.jwt;
|
||||
|
||||
// 保存 JWT 到本地存储,获取解码后的结构
|
||||
const decodedJWT = LicenseStorage.saveLicense(jwt);
|
||||
// 保存 JWT 到本地存储,获取保存的许可证结构
|
||||
const savedLicense = LicenseStorage.saveLicense(jwt);
|
||||
if (!savedLicense) {
|
||||
return {
|
||||
isLicenseValid: false,
|
||||
isRemote: true,
|
||||
};
|
||||
}
|
||||
|
||||
// 从解码后的JWT提取许可证信息
|
||||
const license: LicenseInfo = JSON.parse(decodedJWT.payloadPP);
|
||||
|
||||
// 使用解码后的JWT进行验证
|
||||
const isValid = this.checkLicenseAvailable(jwt, decodedJWT);
|
||||
// 使用解析后的JWT进行验证
|
||||
const isValid = this.checkLicenseAvailable(savedLicense);
|
||||
|
||||
return {
|
||||
isLicenseValid: isValid,
|
||||
license,
|
||||
license: savedLicense.licenseInfo,
|
||||
isRemote: true,
|
||||
};
|
||||
|
||||
@@ -270,15 +272,10 @@ export class LicenseService {
|
||||
* 获取许可证信息(用于显示)
|
||||
*/
|
||||
static getLocalLicenseInfo(): LicenseInfo | null {
|
||||
const decodedJWT = LicenseStorage.getLicense(this.getPluginId());
|
||||
if (!decodedJWT) return null;
|
||||
const savedLicense = LicenseStorage.getLicense(this.getPluginId());
|
||||
if (!savedLicense) return null;
|
||||
|
||||
try {
|
||||
return JSON.parse(decodedJWT.payloadPP) as LicenseInfo;
|
||||
} catch (error) {
|
||||
console.error('Failed to parse payloadPP from decoded JWT:', error);
|
||||
return null;
|
||||
}
|
||||
return savedLicense.licenseInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -341,11 +338,6 @@ export class LicenseService {
|
||||
const license = this.mockCreateTrialLicense();
|
||||
const jwt = this.generateJWT(license);
|
||||
|
||||
// 模拟有时创建失败的情况(1%概率)
|
||||
if (Math.random() < 0.01) {
|
||||
return { success: false };
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
jwt,
|
||||
|
||||
Reference in New Issue
Block a user