Open($storeLocation, $storeName, STORE_OPEN_MAXIMUM_ALLOWED); } catch (\Throwable $e) { throw new \Exception(ErrorMessageHelper::getErrorMessage($e, 'Ошибка при открытии хранилища')); } $cadesCertificates = null; $cadesCertificatesCount = 0; try { $cadesCertificates = $cadesStore->get_Certificates(); if ($cadesCertificates) { if ($validOnly === true) { $cadesCertificates = $cadesCertificates->Find(CERTIFICATE_FIND_TIME_VALID); } /** * Не рассматриваются сертификаты, в которых отсутствует закрытый ключ * или не действительны на данный момент */ if ($withPrivateKey === true) { $cadesCertificates = $cadesCertificates->Find(CERTIFICATE_FIND_EXTENDED_PROPERTY, CAPICOM_PROPID_KEY_PROV_INFO); } $cadesCertificatesCount = $cadesCertificates->Count(); } } catch (\Throwable $e) { throw new \Exception(ErrorMessageHelper::getErrorMessage($e, 'Ошибка получения списка сертификатов')); } if (!$cadesCertificatesCount) { throw new \Exception('Нет доступных сертификатов'); } try { while ($cadesCertificatesCount) { $cadesCertificate = $cadesCertificates->Item($cadesCertificatesCount); $certificates[] = new Certificate( $cadesCertificate, CertificateHelper::extractCommonName($cadesCertificate->SubjectName), $cadesCertificate->IssuerName, $cadesCertificate->SubjectName, $cadesCertificate->Thumbprint, $cadesCertificate->ValidFromDate, $cadesCertificate->ValidToDate ); $cadesCertificatesCount--; } } catch (\Throwable $e) { throw new \Exception(ErrorMessageHelper::getErrorMessage($e, 'Ошибка обработки сертификатов')); } $cadesStore->Close(); return $certificates; } protected static function mergeToAvailableCertificates(array &$availableCertificates = [], array $mergedCertificates = []) { if (empty($availableCertificates)) { $availableCertificates = $mergedCertificates; } else { if (!empty($mergedCertificates)) { $mergedCertificatesCount = count($mergedCertificates) - 1; while ($mergedCertificatesCount) { $found = false; $currentCertificate = $mergedCertificates[$mergedCertificatesCount]; foreach ($availableCertificates as $certificate) { if ($certificate->thumbprint === $currentCertificate->thumbprint) { $found = true; break; } } if ($found) { continue; } $availableCertificates[] = $currentCertificate; } } } } }