Compare commits

...

6 Commits

Author SHA1 Message Date
Clemens Schwaighofer
f4ff31721b phpunit test add php 8.3, remove special code for mb_encode_mimeheader
In the past we had a special function to do mb_encode_mimeheader correctly.

Since PHP 8.2 this works perfectly fine, so all the code was removed and
replaced with just the normal "mb_encode_mimeheader" call with the same
settings as before:
- set global encoding to parameter
- run encoding with charset, 'B' for transfer and use the line break given in parameter
- reset the global encoding to previous set
2024-04-17 10:08:12 +09:00
Clemens Schwaighofer
21ac91d2e6 Composer update for Smarty v4.5.2 2024-04-16 18:27:55 +09:00
Clemens Schwaighofer
2d98d26d0b phive update 2024-04-16 16:32:48 +09:00
Clemens Schwaighofer
3fda1bef60 Move Symmetric Encryption Key generation into its own method
Test update for future class based encryption system without static
methods
2024-03-27 11:58:53 +09:00
Clemens Schwaighofer
4f1104c36e phive tools update 2024-03-21 12:38:43 +09:00
Clemens Schwaighofer
db1007ef12 Smarty Update v4.6.1, Bug fixes in DB\Extended\ArrayIO and Form\Generate 2024-03-19 10:43:12 +09:00
26 changed files with 107 additions and 89 deletions

View File

@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpunit" version="^9.6" installed="9.6.17" location="./tools/phpunit" copy="false"/>
<phar name="phpcbf" version="^3.7.2" installed="3.9.0" location="./tools/phpcbf" copy="false"/>
<phar name="phpcs" version="^3.7.2" installed="3.9.0" location="./tools/phpcs" copy="false"/>
<phar name="phpstan" version="^1.10.37" installed="1.10.59" location="./tools/phpstan" copy="false"/>
<phar name="phpunit" version="^9.6" installed="9.6.19" location="./tools/phpunit" copy="false"/>
<phar name="phpcbf" version="^3.7.2" installed="3.9.1" location="./tools/phpcbf" copy="false"/>
<phar name="phpcs" version="^3.7.2" installed="3.9.1" location="./tools/phpcs" copy="false"/>
<phar name="phpstan" version="^1.10.37" installed="1.10.67" location="./tools/phpstan" copy="false"/>
<phar name="phan" version="^5.4.2" installed="5.4.3" location="./tools/phan" copy="false"/>
<phar name="psalm" version="^5.15.0" installed="5.22.2" location="./tools/psalm" copy="false"/>
<phar name="psalm" version="^5.15.0" installed="5.23.1" location="./tools/psalm" copy="false"/>
<phar name="phpdox" version="^0.12.0" installed="0.12.0" location="./tools/phpdox" copy="false"/>
<phar name="phpdocumentor" version="^3.4.2" installed="3.4.3" location="./tools/phpDocumentor" copy="false"/>
<phar name="php-cs-fixer" version="^3.34.1" installed="3.51.0" location="./tools/php-cs-fixer" copy="false"/>
<phar name="php-cs-fixer" version="^3.34.1" installed="3.53.0" location="./tools/php-cs-fixer" copy="false"/>
</phive>

View File

@@ -28,7 +28,7 @@ if [ "${target}" == '' ]; then
# default is admin
TEXTDOMAIN=admin;
fi;
js_folder="layout/${TEXTDOMAIN}/javascript/";
js_folder="${TEXTDOMAIN}/layout/javascript/";
error=0;
# this checks if the TEXTDOMAIN target actually exists

View File

@@ -19,6 +19,7 @@ if [ ! -z "${1}" ]; then
# "8.0") php_bin="/usr/bin/php8.0 "; ;;
# "8.1") php_bin="/usr/bin/php8.1 "; ;;
"8.2") php_bin="/usr/bin/php8.2 "; ;;
"8.3") php_bin="/usr/bin/php8.4 "; ;;
*) echo "Not support PHP: ${1}"; exit; ;;
esac;
fi;
@@ -29,6 +30,7 @@ if [ ! -z "${2}" ] && [ -z "${php_bin}" ]; then
# "8.0") php_bin="/usr/bin/php8.0 "; ;;
# "8.1") php_bin="/usr/bin/php8.1 "; ;;
"8.2") php_bin="/usr/bin/php8.2 "; ;;
"8.3") php_bin="/usr/bin/php8.3 "; ;;
*) echo "Not support PHP: ${1}"; exit; ;;
esac;
fi;

View File

@@ -33,15 +33,14 @@ final class CoreLibsConvertMimeEncodeTest extends TestCase
'The quick brown fox jumps over the lazy sheep that sleeps in the ravine '
. 'and has no idea what is going on here',
'UTF-8',
'The quick brown fox jumps over the lazy sheep that sleeps in the ravine '
. 'and has no idea what is going on here'
"The quick brown fox jumps over the lazy sheep that sleeps in the ravine and\r\n"
. ' has no idea what is going on here'
],
'standard with special chars UTF-8' => [
'This is ümläßtと漢字もカタカナ!^$%&',
'UTF-8',
'This is =?UTF-8?B?w7xtbMOkw59044Go5ryi5a2X44KC44Kr44K/44Kr44OK77yBIV4k?='
. "\r\n"
. ' =?UTF-8?B?JQ==?=&'
"This is =?UTF-8?B?w7xtbMOkw59044Go5ryi5a2X44KC44Kr44K/44Kr44OK77yBIV4k?=\r\n"
. ' =?UTF-8?B?JSY=?='
],
'35 chars and space at the end UTF-8' => [
'12345678901234567890123456789012345 '
@@ -62,9 +61,8 @@ final class CoreLibsConvertMimeEncodeTest extends TestCase
. 'is there a space?',
'UTF-8',
"=?UTF-8?B?44Kr44K/44Kr44OK44Kr44K/44Kr44OK44GL44Gq44Kr44K/44Kr44OK44Kr?=\r\n"
. " =?UTF-8?B?44K/44Kr44OK?=\r\n"
. " =?UTF-8?B?44GL44Gq44Kr44K/44Kr44OK44Kr44K/44Kr44OK44GL44Gq44Kr44K/44Kr?=\r\n"
. " =?UTF-8?B?44OK44Kr44K/?= is there a =?UTF-8?B?c3BhY2U/?="
. " =?UTF-8?B?44K/44Kr44OK44GL44Gq44Kr44K/44Kr44OK44Kr44K/44Kr44OK44GL44Gq?=\r\n"
. " =?UTF-8?B?44Kr44K/44Kr44OK44Kr44K/IGlzIHRoZXJlIGEgc3BhY2U/?="
]
];
}
@@ -85,16 +83,28 @@ final class CoreLibsConvertMimeEncodeTest extends TestCase
// print "MIME: -" . $encoded . "-\n";
$this->assertEquals(
$expected,
$encoded
$encoded,
"__mbMimeEncode"
);
$decoded = mb_decode_mimeheader($encoded);
// print "INPUT : " . $input . "\n";
// print "DECODED: " . $decoded . "\n";
// print "ENCODED: " . $encoded . "\n";
// print "INPUT : " . $input . " | " . mb_strlen($input) . "\n";
// print "DECODED: " . $decoded . " | " . mb_strlen($decoded) . "\n";
// $test_enc = mb_encode_mimeheader($input, $encoding);
// $test_dec = mb_decode_mimeheader($test_enc);
// print "TEST ENC: " . $test_enc . "\n";
// back compare decoded
$this->assertEquals(
$input,
$decoded
$decoded,
"mb_decode_mimeheader"
);
// $this->assertEquals(
// $input,
// $test_dec,
// 'mb_encode_to_decode'
// );
}
}

View File

@@ -1 +1 @@
/home/clemens/.phive/phars/php-cs-fixer-3.51.0.phar
/home/clemens/.phive/phars/php-cs-fixer-3.53.0.phar

View File

@@ -1 +1 @@
/home/clemens/.phive/phars/phpcbf-3.9.0.phar
/home/clemens/.phive/phars/phpcbf-3.9.1.phar

View File

@@ -1 +1 @@
/home/clemens/.phive/phars/phpcs-3.9.0.phar
/home/clemens/.phive/phars/phpcs-3.9.1.phar

View File

@@ -1 +1 @@
/home/clemens/.phive/phars/phpstan-1.10.59.phar
/home/clemens/.phive/phars/phpstan-1.10.67.phar

View File

@@ -1 +1 @@
/home/clemens/.phive/phars/phpunit-9.6.17.phar
/home/clemens/.phive/phars/phpunit-9.6.19.phar

View File

@@ -1 +1 @@
/home/clemens/.phive/phars/psalm-5.22.2.phar
/home/clemens/.phive/phars/psalm-5.23.1.phar

View File

@@ -92,6 +92,13 @@ try {
print "Error: " . $e->getMessage() . "<br>";
}
// echo "<hr>";
// $key = CreateKey::generateRandomKey();
// $se = new SymmetricEncryption($key);
// $string = "I a some deep secret";
// $encrypted = $se->encrypt($string);
// $decrypted = $se->decrypt($encrypted);
print "</body></html>";
// __END__

8
www/composer.lock generated
View File

@@ -8,11 +8,11 @@
"packages": [
{
"name": "egrajp/smarty-extended",
"version": "4.4.1",
"version": "4.5.2",
"dist": {
"type": "zip",
"url": "https://git.egplusww.jp/api/packages/Composer/composer/files/egrajp%2Fsmarty-extended/4.4.1/egrajp-smarty-extended.4.4.1.zip",
"shasum": "edd7a0960e49bfcc709e0a525729aaaf9ed0db75"
"url": "https://git.egplusww.jp/api/packages/Composer/composer/files/egrajp%2Fsmarty-extended/4.5.2/egrajp-smarty-extended.4.5.2.zip",
"shasum": "a2c67a5047aad349a2cfa54240a44da449df9c4c"
},
"type": "library",
"autoload": {
@@ -34,7 +34,7 @@
"keywords": [
"templating"
],
"time": "2024-03-06T18:43:44+09:00"
"time": "2024-04-16T18:25:27+09:00"
},
{
"name": "gullevek/dotenv",

View File

@@ -15,6 +15,7 @@ class MimeEncode
/**
* wrapper function for mb mime convert
* for correct conversion with long strings
* NOTE: This is only a wrapper for mb_encode_mimeheader to stay compatible
*
* @param string $string string to encode
* @param string $encoding target encoding
@@ -29,38 +30,9 @@ class MimeEncode
$current_internal_encoding = mb_internal_encoding();
// set internal encoding, so the mimeheader encode works correctly
mb_internal_encoding($encoding);
// if a subject, make a work around for the broken mb_mimencode
$pos = 0;
// after 36 single bytes characters,
// if then comes MB, it is broken
// has to 2 x 36 < 74 so the mb_encode_mimeheader
// 74 hardcoded split does not get triggered
$split = 36;
$_string = '';
while ($pos < mb_strlen($string, $encoding)) {
$output = mb_strimwidth($string, $pos, $split, "", $encoding);
$pos += mb_strlen($output, $encoding);
// if the strinlen is 0 here, get out of the loop
if (!mb_strlen($output, $encoding)) {
$pos += mb_strlen($string, $encoding);
}
$_string_encoded = mb_encode_mimeheader($output, $encoding);
// only make linebreaks if we have mime encoded code inside
// the space only belongs in the second line
if ($_string && preg_match("/^=\?/", $_string_encoded)) {
$_string .= $line_break . " ";
} elseif (
// hack for plain text with space at the end
mb_strlen($output, $encoding) == $split &&
mb_substr($output, -1, 1, $encoding) == " "
) {
// if output ends with space, add one more
$_string_encoded .= " ";
}
$_string .= $_string_encoded;
}
// strip out any spaces BEFORE a line break
$string = str_replace(" " . $line_break, $line_break, $_string);
// use the internal convert to mime header
// it works from PHP 8.2 on
$string = mb_encode_mimeheader($string, $encoding, 'B', $line_break);
// before we end, reset internal encoding
mb_internal_encoding($current_internal_encoding);
// return mime encoded string

View File

@@ -236,7 +236,7 @@ class ArrayIO extends \CoreLibs\DB\IO
*/
public function getPkId(): int|string|null
{
return $this->pk_id;
return $this->pk_id ?? null;
}
/**

View File

@@ -1507,7 +1507,7 @@ class Generate
}
if (
!empty($this->reference_array[$key]['mandatory']) &&
!$this->reference_array[$key]['selected'][0]
empty($this->reference_array[$key]['selected'][0])
) {
$this->msg .= sprintf(
$this->l->__('Please select at least one Element from field <b>%s</b>!<br>'),

View File

@@ -53,6 +53,7 @@ class EditPages implements Interface\TableArraysInterface
'value' => $_POST['name'] ?? '',
'output_name' => 'Page name',
'mandatory' => 1,
'error_check' => 'unique',
'type' => 'text'
],
'order_number' => [

View File

@@ -22,15 +22,12 @@ use SodiumException;
class SymmetricEncryption
{
/**
* Encrypt a message
* create key and check validity
*
* @param string $message Message to encrypt
* @param string $key Encryption key (as hex string)
* @return string
* @throws \Exception
* @throws \RangeException
* @param string $key The key from which the binary key will be created
* @return string Binary key string
*/
public static function encrypt(string $message, string $key): string
public static function createKey(string $key): string
{
try {
$key = CreateKey::hex2bin($key);
@@ -43,6 +40,21 @@ class SymmetricEncryption
. 'SODIUM_CRYPTO_SECRETBOX_KEYBYTES bytes long).'
);
}
return $key;
}
/**
* Encrypt a message
*
* @param string $message Message to encrypt
* @param string $key Encryption key (as hex string)
* @return string
* @throws \Exception
* @throws \RangeException
*/
public static function encrypt(string $message, string $key): string
{
$key = self::createKey($key);
$nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
$cipher = base64_encode(
@@ -68,11 +80,7 @@ class SymmetricEncryption
*/
public static function decrypt(string $encrypted, string $key): string
{
try {
$key = CreateKey::hex2bin($key);
} catch (SodiumException $e) {
throw new \Exception('Invalid hex key');
}
$key = self::createKey($key);
$decoded = base64_decode($encrypted);
$nonce = mb_substr($decoded, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, '8bit');
$ciphertext = mb_substr($decoded, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit');

View File

@@ -2,14 +2,14 @@
"packages": [
{
"name": "egrajp/smarty-extended",
"version": "4.4.1",
"version_normalized": "4.4.1.0",
"version": "4.5.2",
"version_normalized": "4.5.2.0",
"dist": {
"type": "zip",
"url": "https://git.egplusww.jp/api/packages/Composer/composer/files/egrajp%2Fsmarty-extended/4.4.1/egrajp-smarty-extended.4.4.1.zip",
"shasum": "edd7a0960e49bfcc709e0a525729aaaf9ed0db75"
"url": "https://git.egplusww.jp/api/packages/Composer/composer/files/egrajp%2Fsmarty-extended/4.5.2/egrajp-smarty-extended.4.5.2.zip",
"shasum": "a2c67a5047aad349a2cfa54240a44da449df9c4c"
},
"time": "2024-03-06T18:43:44+09:00",
"time": "2024-04-16T18:25:27+09:00",
"type": "library",
"installation-source": "dist",
"autoload": {

View File

@@ -20,8 +20,8 @@
'dev_requirement' => false,
),
'egrajp/smarty-extended' => array(
'pretty_version' => '4.4.1',
'version' => '4.4.1.0',
'pretty_version' => '4.5.2',
'version' => '4.5.2.0',
'reference' => null,
'type' => 'library',
'install_path' => __DIR__ . '/../egrajp/smarty-extended',

View File

@@ -1 +1 @@
4.3.4
4.5.1

View File

@@ -49,6 +49,7 @@ if [ "${go_flag}" != "go" ]; then
fi;
echo "[START]";
# gitea
if [ ! -z "${GITEA_UPLOAD_FILENAME}" ] &&
[ ! -z "${GITEA_URL_DL}" ] && [ ! -z "${GITEA_URL_PUSH}" ] &&
@@ -82,6 +83,7 @@ if [ ! -z "${GITLAB_URL}" ] && [ ! -z "${GITLAB_DEPLOY_TOKEN}" ]; then
else
echo "Missing GITLAB_DEPLOY_TOKEN environment variable";
fi;
echo "";
echo "[DONE]";

View File

@@ -107,7 +107,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* smarty version
*/
const SMARTY_VERSION = '4.4.1';
const SMARTY_VERSION = '4.5.1';
/**
* define variable scopes
*/

View File

@@ -109,9 +109,11 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
if (!is_object($compiler->smarty->security_policy)
|| $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)
) {
trigger_error('Using php-function "' . $modifier . '" as a modifier is deprecated and will be ' .
'removed in a future release. Use Smarty::registerPlugin to explicitly register ' .
'a custom modifier.', E_USER_DEPRECATED);
if (!in_array($modifier, ['time', 'join', 'is_array', 'in_array'])) {
trigger_error('Using unregistered function "' . $modifier . '" in a template is deprecated and will be ' .
'removed in a future release. Use Smarty::registerPlugin to explicitly register ' .
'a custom modifier.', E_USER_DEPRECATED);
}
$output = "{$modifier}({$params})";
}
$compiler->known_modifier_type[ $modifier ] = $type;

View File

@@ -640,7 +640,18 @@ abstract class Smarty_Internal_TemplateCompilerBase
return $func_name . '(' . $parameter[ 0 ] . ')';
}
} else {
return $name . '(' . implode(',', $parameter) . ')';
if (
!$this->smarty->loadPlugin('smarty_modifiercompiler_' . $name)
&& !isset($this->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$name])
&& !in_array($name, ['time', 'join', 'is_array', 'in_array'])
) {
trigger_error('Using unregistered function "' . $name . '" in a template is deprecated and will be ' .
'removed in a future release. Use Smarty::registerPlugin to explicitly register ' .
'a custom modifier.', E_USER_DEPRECATED);
}
return $name . '(' . implode(',', $parameter) . ')';
}
} else {
$this->trigger_template_error("unknown function '{$name}'");

View File

@@ -2425,6 +2425,9 @@ public static $yy_action = array(
if (isset($this->smarty->registered_classes[$this->yystack[$this->yyidx + -2]->minor])) {
$this->_retvalue = $this->smarty->registered_classes[$this->yystack[$this->yyidx + -2]->minor].'::'.$this->yystack[$this->yyidx + 0]->minor[0].$this->yystack[$this->yyidx + 0]->minor[1];
} else {
trigger_error('Using unregistered static method "' . $this->yystack[$this->yyidx + -2]->minor.'::'.$this->yystack[$this->yyidx + 0]->minor[0] . '" in a template is deprecated and will be ' .
'removed in a future release. Use Smarty::registerClass to explicitly register ' .
'a class for access.', E_USER_DEPRECATED);
$this->_retvalue = $this->yystack[$this->yyidx + -2]->minor.'::'.$this->yystack[$this->yyidx + 0]->minor[0].$this->yystack[$this->yyidx + 0]->minor[1];
}
} else {

View File

@@ -253,7 +253,7 @@ class Smarty_Security
*
* @param string $function_name
* @param object $compiler compiler object
*
* @deprecated
* @return boolean true if function is trusted
*/
public function isTrustedPhpFunction($function_name, $compiler)