From ac6118d2b08dd35791c570c97a7102b224d48837 Mon Sep 17 00:00:00 2001 From: Artem Vasilev Date: Tue, 15 Nov 2022 12:10:43 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D1=8B=20=D0=BF=D0=BE=D0=BB=D1=83?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B8=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D0=BA=D0=B8=20=D0=B8=D0=BD=D1=84=D0=BE=D1=80?= =?UTF-8?q?=D0=BC=D0=B0=D1=86=D0=B8=D0=B8=20=D0=BE=20CSP=20=D0=B8=20=D0=BF?= =?UTF-8?q?=D0=BB=D0=B0=D0=B3=D0=B8=D0=BD=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/CryptoPro.php | 87 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 2 deletions(-) diff --git a/src/CryptoPro.php b/src/CryptoPro.php index 9d90cb1..5786d40 100755 --- a/src/CryptoPro.php +++ b/src/CryptoPro.php @@ -634,12 +634,95 @@ class CryptoPro } /** - * возвращает информацию о CSP и плагине + * Возвращает информацию о CSP и плагине * - * @return void + * @throws \Exception + * @return array */ public static function getSystemInfo() { + try + { + $about = new \About(); + } + catch (\Throwable $e) + { + throw new \Exception(ErrorMessageHelper::getErrorMessage($e, 'Ошибка при получении информации о системе')); + } + + try + { + $cadesVersion = $about->PluginVersion(); + + if ($cadesVersion instanceof \Version) + { + $cadesVersion = $cadesVersion->toString(); + } + + if (!$cadesVersion) + { + $cadesVersion = $about->get_Version(); + } + } + catch (\Throwable $e) + { + throw new \Exception(ErrorMessageHelper::getErrorMessage($e, 'Ошибка при получении информации о плагине')); + } + + try + { + $cspVersion = $about->CSPVersion(); + $cspVersion = $cspVersion->toString(); + } + catch (\Throwable $e) + { + throw new \Exception(ErrorMessageHelper::getErrorMessage($e, 'Ошибка при получении информации о CSP')); + } + + return [ + 'cadesVersion' => $cadesVersion, + 'cspVersion' => $cspVersion, + ]; + } + + /** + * Проверяет корректность настроек средств ЭП + * + * @throws \Exception + * @return true + */ + public static function isValidSystemSetup() + { + $systemInfo = static::getSystemInfo(); + + $extractedCadesVersion = []; + + if (!preg_match('/(\d+)\.(\d+)\.(\d+)/', $systemInfo['cadesVersion'], $extractedCadesVersion)) + { + throw new \Exception('Ошибка чтеня версии плагина'); + } + + list(, $cadesVersionMajor, $cadesVersionMinor, $cadesVersionPatch) = $extractedCadesVersion; + + if ((int) $cadesVersionMajor < 2 + || ((int) $cadesVersionMajor === 2 && (int) $cadesVersionMinor === 0 && (int) $cadesVersionPatch < 12438)) + { + throw new \Exception('Не поддерживаемая версия плагина'); + } + + if (!preg_match('/(\d+)\.(\d+)\.(\d+)/', $systemInfo['cspVersion'], $extractedCSPVersion)) + { + throw new \Exception('Ошибка чтеня версии CSP'); + } + + list(, $cspVersionMajor, $cspVersionMinor, $cspVersionPatch) = $extractedCSPVersion; + + if ((int) $cspVersionMajor < 4) + { + throw new \Exception('Не поддерживаемая версия CSP'); + } + + return true; } /**