From 316ae871668d331e9106d5b17c68b4f8e3b3f825 Mon Sep 17 00:00:00 2001 From: Artem Vasilev Date: Thu, 3 Nov 2022 20:03:32 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D1=81=D0=B5=D1=80=D1=82=D0=B8=D1=84=D0=B8=D0=BA=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/CryptoPro.php | 71 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 22 deletions(-) diff --git a/src/CryptoPro.php b/src/CryptoPro.php index a4f8d13..36e460e 100755 --- a/src/CryptoPro.php +++ b/src/CryptoPro.php @@ -2,9 +2,13 @@ namespace Webmasterskaya\CryptoPro; +use Webmasterskaya\CryptoPro\Constants\CAPICOM_CERTIFICATE_FIND_TYPE; +use Webmasterskaya\CryptoPro\Constants\CAPICOM_PROPID; use Webmasterskaya\CryptoPro\Helpers\CertificateHelper; use Webmasterskaya\CryptoPro\Helpers\ErrorMessageHelper; +const CONTAINER_STORE = 100; + class CryptoPro { protected const CP_MY_STORE = 'My'; @@ -41,7 +45,7 @@ class CryptoPro static $certificates; if ($resetCache === true || !isset($certificates)) { - $certificates = self::getCertificatesFromStore(CURRENT_USER_STORE, self::CP_MY_STORE, false, false); + $certificates = self::getCertificatesFromStore(CURRENT_USER_STORE, self::CP_MY_STORE, false); } return $certificates; @@ -79,7 +83,7 @@ class CryptoPro static $certificates; if ($resetCache === true || !isset($certificates)) { - $certificates = self::getCertificatesFromStore(CONTAINER_STORE, self::CP_MY_STORE, false, false); + $certificates = self::getCertificatesFromStore(CONTAINER_STORE, self::CP_MY_STORE, false); } return $certificates; @@ -625,9 +629,33 @@ class CryptoPro { } - protected static function getCertificatesFromStore( - int $storeLocation, string $storeName = 'My', bool $validOnly = true, bool $withPrivateKey = true - ) + /** + * @param int $storeLocation + * @param string $storeName + * @param bool $validOnly Логическое значение , указывающее, возвращаются ли только действительные сертификаты. + * Если значение равно true, поиск не вернет следующие типы сертификатов: + * + * + * @throws \Exception + * @return array + */ + protected static function getCertificatesFromStore(int $storeLocation, string $storeName = 'My', bool $validOnly = true) { $certificates = []; @@ -653,20 +681,19 @@ class CryptoPro { $cadesCertificates = $cadesStore->get_Certificates(); - /** - * Не рассматриваются сертификаты не действительны на данный момент - */ if ($validOnly === true) { - $cadesCertificates = $cadesCertificates->Find(CERTIFICATE_FIND_TIME_VALID); - } + $cadesCertificates = $cadesCertificates->Find( + CAPICOM_CERTIFICATE_FIND_TYPE::TIME_VALID, + '', + true + ); - /** - * Не рассматриваются сертификаты, в которых отсутствует закрытый ключ - */ - if ($withPrivateKey === true) - { - $cadesCertificates = $cadesCertificates->Find(CERTIFICATE_FIND_EXTENDED_PROPERTY, CAPICOM_PROPID_KEY_PROV_INFO); + $cadesCertificates = $cadesCertificates->Find( + CAPICOM_CERTIFICATE_FIND_TYPE::EXTENDED_PROPERTY, + CAPICOM_PROPID::KEY_PROV_INFO, + true + ); } $cadesCertificatesCount = $cadesCertificates->Count(); @@ -689,12 +716,12 @@ class CryptoPro $certificates[] = new Certificate( $cadesCertificate, - CertificateHelper::extractCommonName($cadesCertificate->SubjectName), - $cadesCertificate->IssuerName, - $cadesCertificate->SubjectName, - $cadesCertificate->Thumbprint, - $cadesCertificate->ValidFromDate, - $cadesCertificate->ValidToDate + CertificateHelper::extractCommonName($cadesCertificate->get_SubjectName()), + $cadesCertificate->get_IssuerName(), + $cadesCertificate->get_SubjectName(), + $cadesCertificate->get_Thumbprint(), + $cadesCertificate->get_ValidFromDate(), + $cadesCertificate->get_ValidToDate() ); $cadesCertificatesCount--;