Skip to content

Commit

Permalink
chore: set license public key v3 with v2 (#30548)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo authored Oct 2, 2023
1 parent 6d4cb42 commit 8e03a0c
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions ee/packages/license/src/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { verify, sign, getPairs } from '@rocket.chat/jwt';

import type { ILicenseV3 } from './definition/ILicenseV3';

const PUBLIC_KEY_V2 =
const PUBLIC_LICENSE_KEY_V2 =
'LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQ0lqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FnOEFNSUlDQ2dLQ0FnRUFxV1Nza2Q5LzZ6Ung4a3lQY2ljcwpiMzJ3Mnd4VnV3N3lCVDk2clEvOEQreU1lQ01POXdTU3BIYS85bkZ5d293RXRpZ3B0L3dyb1BOK1ZHU3didHdQCkZYQmVxRWxCbmRHRkFsODZlNStFbGlIOEt6L2hHbkNtSk5tWHB4RUsyUkUwM1g0SXhzWVg3RERCN010eC9pcXMKY2pCL091dlNCa2ppU2xlUzdibE5JVC9kQTdLNC9DSjNvaXUwMmJMNEV4Y2xDSGVwenFOTWVQM3dVWmdweE9uZgpOT3VkOElYWUs3M3pTY3VFOEUxNTdZd3B6Q0twVmFIWDdaSmY4UXVOc09PNVcvYUlqS2wzTDYyNjkrZUlPRXJHCndPTm1hSG56Zmc5RkxwSmh6Z3BPMzhhVm43NnZENUtLakJhaldza1krNGEyZ1NRbUtOZUZxYXFPb3p5RUZNMGUKY0ZXWlZWWjNMZWg0dkVNb1lWUHlJeng5Nng4ZjIveW1QbmhJdXZRdjV3TjRmeWVwYTdFWTVVQ2NwNzF6OGtmUAo0RmNVelBBMElEV3lNaWhYUi9HNlhnUVFaNEdiL3FCQmh2cnZpSkNGemZZRGNKZ0w3RmVnRllIUDNQR0wwN1FnCnZMZXZNSytpUVpQcnhyYnh5U3FkUE9rZ3VyS2pWclhUVXI0QTlUZ2lMeUlYNVVsSnEzRS9SVjdtZk9xWm5MVGEKU0NWWEhCaHVQbG5DR1pSMDFUb1RDZktoTUcxdTBDRm5MMisxNWhDOWZxT21XdjlRa2U0M3FsSjBQZ0YzVkovWAp1eC9tVHBuazlnbmJHOUpIK21mSDM5Um9GdlROaW5Zd1NNdll6dXRWT242OXNPemR3aERsYTkwbDNBQ2g0eENWCks3Sk9YK3VIa29OdTNnMmlWeGlaVU0wQ0F3RUFBUT09Ci0tLS0tRU5EIFBVQkxJQyBLRVktLS0tLQo=';

const PUBLIC_KEY_V3 = '';
const PUBLIC_LICENSE_KEY_V3 = process.env.PUBLIC_LICENSE_KEY_V3 || PUBLIC_LICENSE_KEY_V2;

let TEST_KEYS: [string, string] | undefined = undefined;

Expand All @@ -19,7 +19,7 @@ export async function decrypt(encrypted: string): Promise<string> {
TEST_KEYS = TEST_KEYS ?? (await getPairs());

if (!TEST_KEYS) {
throw new Error('Missing LICENSE_PUBLIC_KEY_V3');
throw new Error('Missing PUBLIC_LICENSE_KEY_V3');
}

const [spki] = TEST_KEYS;
Expand All @@ -32,12 +32,12 @@ export async function decrypt(encrypted: string): Promise<string> {
// handle V3
if (encrypted.startsWith('RCV3_')) {
const jwt = encrypted.substring(5);
const [payload] = await verify(jwt, PUBLIC_KEY_V3);
const [payload] = await verify(jwt, PUBLIC_LICENSE_KEY_V3);

return JSON.stringify(payload);
}

const decrypted = crypto.publicDecrypt(Buffer.from(PUBLIC_KEY_V2, 'base64').toString('utf-8'), Buffer.from(encrypted, 'base64'));
const decrypted = crypto.publicDecrypt(Buffer.from(PUBLIC_LICENSE_KEY_V2, 'base64').toString('utf-8'), Buffer.from(encrypted, 'base64'));

return decrypted.toString('utf-8');
}
Expand All @@ -49,10 +49,6 @@ export async function encrypt(license: ILicenseV3): Promise<string> {

TEST_KEYS = TEST_KEYS ?? (await getPairs());

if (!TEST_KEYS) {
throw new Error('Missing LICENSE_PUBLIC_KEY_V3');
}

const [, pkcs8] = TEST_KEYS;

return `RCV3_${await sign(license, pkcs8)}`;
Expand Down

0 comments on commit 8e03a0c

Please sign in to comment.