1
0
mirror of https://github.com/typemill/typemill.git synced 2025-08-06 14:16:46 +02:00

V2.2.0 fix old static license methods

This commit is contained in:
trendschau
2024-02-15 15:21:17 +01:00
parent 0913e4fbb4
commit 8297fa5a00
3 changed files with 4 additions and 111 deletions

View File

@@ -5,8 +5,8 @@ namespace Typemill\Controllers;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Typemill\Models\Validation;
use Typemill\Models\License;
use Typemill\Static\Translations;
use Typemill\Static\License;
class ControllerApiSystemVersions extends Controller
{
@@ -52,7 +52,8 @@ class ControllerApiSystemVersions extends Controller
$url = 'https://themes.typemill.net/api/v1/getthemes?themes=' . urlencode($themeList);
}
$authstring = License::getPublicKeyPem();
$license = new License();
$authstring = $license->getPublicKeyPem();
if(!$authstring)
{
$response->getBody()->write(json_encode([

View File

@@ -270,7 +270,7 @@ class License
}
# we have it in static license, too so use it from static and delete this duplicate.
private function getPublicKeyPem()
public function getPublicKeyPem()
{
$pkeyfile = getcwd() . DIRECTORY_SEPARATOR . 'settings' . DIRECTORY_SEPARATOR . "public_key.pem";

View File

@@ -1,108 +0,0 @@
<?php
namespace Typemill\Static;
use Typemill\Models\StorageWrapper;
use Typemill\Static\Translations;
class License
{
/*
public static function getLicenseData()
{
# returns data for settings page
}
public static function getLicensePlan()
{
# returns plan for plugins
}
# check the local licence file (like pem or pub)
public static function checkLicense()
{
$storage = new StorageWrapper('\Typemill\Models\Storage');
$licensedata = $storage->getYaml('basepath', 'settings', 'license.yaml');
if(!$licensedata)
{
return ['result' => false, 'message' => Translations::translate('no license found')];
}
if(!isset($licensedata['license'],$licensedata['email'],$licensedata['domain'],$licensedata['plan'],$licensedata['payed_until'],$licensedata['signature']))
{
return ['result' => false, 'message' => Translations::translate('License data incomplete')];
}
$licenseStatus = self::validateLicense($licensedata);
unset($licensedata['signature']);
if($licenseStatus === false)
{
return ['result' => false, 'message' => Translations::translate('License data invalid')];
}
elseif($licenseStatus === true)
{
die('Static License licenceStatus is true');
}
else
{
die('error checking signature');
}
}
public static function validateLicense($data)
{
$public_key_pem = self::getPublicKeyPem();
$binary_signature = base64_decode($data['signature']);
$data['email'] = self::hashMail($data['email']);
unset($data['signature']);
# manipulate data
# $data['product'] = 'business';
$data = json_encode($data);
# Check signature
$verified = openssl_verify($data, $binary_signature, $public_key_pem, OPENSSL_ALGO_SHA256);
if ($verified == 1)
{
return true;
}
elseif ($verified == 0)
{
return false;
}
else
{
die("ugly, error checking signature");
}
}
public static function hashMail($mail)
{
return hash('sha256', trim($mail) . 'TYla5xa8JUur');
}
public static function getPublicKeyPem()
{
$pkeyfile = getcwd() . DIRECTORY_SEPARATOR . 'settings' . DIRECTORY_SEPARATOR . "public_key.pem";
if(file_exists($pkeyfile) && is_readable($pkeyfile))
{
# fetch public key from file and ready it
$fp = fopen($pkeyfile, "r");
$public_key_pem = fread($fp, 8192);
fclose($fp);
return $public_key_pem;
}
return false;
}
*/
}