mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-14 00:26:51 +08:00
refactor(server): decrypt license with provided aes key (#12570)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for a new AES key for license management, improving license encryption and decryption processes. - **Bug Fixes** - Improved error messages and handling when activating expired or invalid licenses. - **Refactor** - Updated license decryption logic to use a fixed AES key instead of deriving one from the workspace ID. - Added validation for environment variable values to prevent invalid configurations. - **Tests** - Enhanced license-related tests to cover new key usage and updated error messages. - Updated environment variable validation tests with clearer error messages. - **Chores** - Updated environment variable handling for improved consistency. - Set production environment variable explicitly in build configuration. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -17,7 +17,10 @@ import {
|
||||
verify as verifyPassword,
|
||||
} from '@node-rs/argon2';
|
||||
|
||||
import { AFFINE_PRO_PUBLIC_KEY } from '../../native';
|
||||
import {
|
||||
AFFINE_PRO_LICENSE_AES_KEY,
|
||||
AFFINE_PRO_PUBLIC_KEY,
|
||||
} from '../../native';
|
||||
import { Config } from '../config';
|
||||
import { OnEvent } from '../event';
|
||||
|
||||
@@ -59,10 +62,12 @@ export class CryptoHelper implements OnModuleInit {
|
||||
};
|
||||
|
||||
AFFiNEProPublicKey: Buffer | null = null;
|
||||
AFFiNEProLicenseAESKey: Buffer | null = null;
|
||||
|
||||
onModuleInit() {
|
||||
if (env.selfhosted) {
|
||||
this.AFFiNEProPublicKey = this.loadAFFiNEProPublicKey();
|
||||
this.AFFiNEProLicenseAESKey = this.loadAFFiNEProLicenseAESKey();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,4 +202,20 @@ export class CryptoHelper implements OnModuleInit {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private loadAFFiNEProLicenseAESKey() {
|
||||
if (AFFINE_PRO_LICENSE_AES_KEY) {
|
||||
return this.sha256(AFFINE_PRO_LICENSE_AES_KEY);
|
||||
} else {
|
||||
this.logger.warn(
|
||||
'AFFINE_PRO_LICENSE_AES_KEY is not set at compile time.'
|
||||
);
|
||||
}
|
||||
|
||||
if (!env.prod && process.env.AFFiNE_PRO_LICENSE_AES_KEY) {
|
||||
return this.sha256(process.env.AFFiNE_PRO_LICENSE_AES_KEY);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user