From 74506cfe9fa15d11f3714f93bba21dc6e0a08520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Szcz=C4=99=C5=9Bniak?= Date: Tue, 16 May 2023 11:06:59 +0200 Subject: [PATCH 1/2] Small simplify of the license check code. --- packages/ckeditor5-utils/src/verifylicense.ts | 14 +++++--------- packages/ckeditor5-utils/tests/verifylicense.js | 2 +- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/ckeditor5-utils/src/verifylicense.ts b/packages/ckeditor5-utils/src/verifylicense.ts index 3d2e7b03c3e..923e1a945b5 100644 --- a/packages/ckeditor5-utils/src/verifylicense.ts +++ b/packages/ckeditor5-utils/src/verifylicense.ts @@ -22,7 +22,7 @@ export type VerifiedKeyStatus = 'VALID' | 'INVALID'; */ export default function verifyLicense( token: string | undefined ): VerifiedKeyStatus { function oldTokenCheck( token: string ): VerifiedKeyStatus { - if ( token.match( /^[a-zA-Z0-9+/=$]+$/g ) && ( token.length >= 40 && token.length <= 255 ) ) { + if ( token.length >= 40 && token.length <= 255 ) { return 'VALID'; } else { return 'INVALID'; @@ -30,13 +30,13 @@ export default function verifyLicense( token: string | undefined ): VerifiedKeyS } // TODO: issue ci#3175 - let decryptedData = ''; - let decryptedSecondElement = ''; if ( !token ) { return 'INVALID'; } + let decryptedData = ''; + try { decryptedData = atob( token ); } catch ( e ) { @@ -70,14 +70,10 @@ export default function verifyLicense( token: string | undefined ): VerifiedKeyS return 'INVALID'; } - try { - // Must be a valid format. - atob( firstElement ); - } catch ( e ) { - return 'INVALID'; - } + let decryptedSecondElement = ''; try { + atob( firstElement ); decryptedSecondElement = atob( secondElement ); } catch ( e ) { return 'INVALID'; diff --git a/packages/ckeditor5-utils/tests/verifylicense.js b/packages/ckeditor5-utils/tests/verifylicense.js index b7fd8427409..cefeb66a634 100644 --- a/packages/ckeditor5-utils/tests/verifylicense.js +++ b/packages/ckeditor5-utils/tests/verifylicense.js @@ -19,7 +19,7 @@ describe( 'utils', () => { it( 'when old token format is given', () => { // old // eslint-disable-next-line max-len - const string = 'YWZvb2JkcnphYXJhZWJvb290em9wbWJvbHJ1c21sZnJlYmFzdG1paXN1cm1tZmllenJhb2F0YmFvcmxvb3B6aWJvYWRiZWZzYXJ0bW9ibG8='; + const string = 'K1RHbDJhb0RoYXpRQTI0alZOaUowZE5NTldHM05rc3ovYnRkTVZOR3VnZDBhLzVOa3Z1SUd2N2JEY2JVWk13YkNzUjBleC9tSlJiYSswNHNYTEdHTkRiV0xwR0h0ZkhZU095eEZDWHpZd3ZkQ2huaTA0UmxHQkZEM00wUFVzcXk='; expect( verifyLicense( string ) ).to.be.equal( 'VALID' ); } ); From de9c1157a3c10f519b8b461c670d6f3a6ee12e26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Szcz=C4=99=C5=9Bniak?= Date: Tue, 23 May 2023 18:04:17 +0200 Subject: [PATCH 2/2] Rollback token parameter in test. --- packages/ckeditor5-utils/tests/verifylicense.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ckeditor5-utils/tests/verifylicense.js b/packages/ckeditor5-utils/tests/verifylicense.js index cefeb66a634..b7fd8427409 100644 --- a/packages/ckeditor5-utils/tests/verifylicense.js +++ b/packages/ckeditor5-utils/tests/verifylicense.js @@ -19,7 +19,7 @@ describe( 'utils', () => { it( 'when old token format is given', () => { // old // eslint-disable-next-line max-len - const string = 'K1RHbDJhb0RoYXpRQTI0alZOaUowZE5NTldHM05rc3ovYnRkTVZOR3VnZDBhLzVOa3Z1SUd2N2JEY2JVWk13YkNzUjBleC9tSlJiYSswNHNYTEdHTkRiV0xwR0h0ZkhZU095eEZDWHpZd3ZkQ2huaTA0UmxHQkZEM00wUFVzcXk='; + const string = 'YWZvb2JkcnphYXJhZWJvb290em9wbWJvbHJ1c21sZnJlYmFzdG1paXN1cm1tZmllenJhb2F0YmFvcmxvb3B6aWJvYWRiZWZzYXJ0bW9ibG8='; expect( verifyLicense( string ) ).to.be.equal( 'VALID' ); } );