@@ -164,7 +164,7 @@ public function isComplete(): bool
164164 $ this ->domain !== null &&
165165 $ this ->email !== null &&
166166 $ this ->order !== null &&
167- ( $ this ->signature !== null || $ this -> isFreeAndLocal ()) &&
167+ $ this ->signature !== null &&
168168 $ this ->hasValidEmailAddress () === true &&
169169 $ this ->type () !== LicenseType::Invalid
170170 ) {
@@ -272,22 +272,21 @@ public function isOnCorrectDomain(): bool
272272 */
273273 public function isSigned (): bool
274274 {
275- // locally self-signed licenses do not need a signature
276- if ($ this ->isFreeAndLocal () === true ) {
277- return true ;
278- }
279-
280275 if ($ this ->signature === null ) {
281276 return false ;
282277 }
283278
279+ $ data = json_encode ($ this ->signatureData ());
280+ $ signature = hex2bin ($ this ->signature );
281+
282+ if ($ this ->isFreeAndLocal () === true ) {
283+ return hash ('sha256 ' , $ data ) === $ signature ;
284+ }
285+
284286 // get the public key
285287 $ pubKey = F::read ($ this ->kirby ->root ('kirby ' ) . '/kirby.pub ' );
286288
287289 // verify the license signature
288- $ data = json_encode ($ this ->signatureData ());
289- $ signature = hex2bin ($ this ->signature );
290-
291290 return openssl_verify ($ data , $ signature , $ pubKey , 'RSA-SHA256 ' ) === 1 ;
292291 }
293292
@@ -406,14 +405,14 @@ public function register(): static
406405 }
407406
408407 if ($ this ->isFreeAndLocal () === true ) {
409- $ response = [
408+ $ response = $ this -> selfsign ( [
410409 'activation ' => date ('Y-m-d H:i:s ' ),
410+ 'code ' => $ this ->code ,
411411 'date ' => date ('Y-m-d H:i:s ' ),
412412 'domain ' => $ this ->domain ,
413- 'code ' => $ this ->code ,
413+ 'email ' => hash ( ' sha256 ' , $ this ->email . static :: SALT ) ,
414414 'order ' => '12345678 ' ,
415- 'email ' => $ this ->email
416- ];
415+ ]);
417416 }
418417
419418 // @codeCoverageIgnoreStart
@@ -496,6 +495,19 @@ public function save(): bool
496495 );
497496 }
498497
498+ /**
499+ * Self-signs a license file where registration
500+ * will not communicate with the license hub
501+ */
502+ protected function selfsign (array $ payload ): array
503+ {
504+ return [
505+ ...$ payload ,
506+ 'email ' => $ payload ['email ' ],
507+ 'signature ' => bin2hex (hash ('sha256 ' , json_encode ($ payload )))
508+ ];
509+ }
510+
499511 /**
500512 * Returns the signature if available
501513 */
0 commit comments