Skip to content

Commit 030b4a0

Browse files
committed
check if certificate is expired.
1 parent cbeb77c commit 030b4a0

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/Sign/JSignService.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ private function validation(JSignParam $params)
5959
$this->throwIf(empty($params->getCertificate()), 'Certificate is Empty or Invalid.');
6060
$this->throwIf(empty($params->getPassword()), 'Certificate Password is Empty.');
6161
$this->throwIf(!$this->isPasswordCertificateValid($params->getCertificate(), $params->getPassword()), 'Certificate Password Invalid.');
62+
$this->throwIf($this->isExpiredCertificate($params->getCertificate(), $params->getPassword()), 'Certificate expired.');
6263
if ($params->isUseJavaInstalled()) {
6364
$javaVersion = exec("java -version 2>&1");
6465
$hasJavaVersion = strpos($javaVersion, 'not found') === false;
@@ -112,4 +113,12 @@ private function isPasswordCertificateValid($certificate, $password)
112113
{
113114
return openssl_pkcs12_read($certificate, $certInfo, $password);
114115
}
116+
117+
private function isExpiredCertificate($certificate, $password)
118+
{
119+
openssl_pkcs12_read($certificate, $certInfo, $password);
120+
$certificate = openssl_x509_parse($certInfo['cert']);
121+
$dateCert = date_create()->setTimestamp($certificate['validTo_time_t']);
122+
return $dateCert <= date_create();
123+
}
115124
}

0 commit comments

Comments
 (0)