-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ExtendedKeyUsage for x509 cert
- Loading branch information
Showing
9 changed files
with
247 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/vendor/ | ||
.idea/ | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
require_once __DIR__.'/../vendor/autoload.php'; | ||
|
||
$t1 = microtime(true); | ||
$crl = \Adapik\CMS\CertificateRevocationList::createFromContent(file_get_contents('php://stdin')); | ||
$t2 = microtime(true); | ||
|
||
echo 'Parsed in: ' . ($t2 - $t1) . 's'; | ||
echo "\n"; | ||
|
||
echo 'Issuer: ' . (string) $crl->getIssuer(); | ||
echo "\n"; | ||
echo 'This Update: ' . (string) $crl->getThisUpdate(); | ||
echo "\n"; | ||
echo 'Next Update: ' . (string) $crl->getNextUpdate(); | ||
echo "\n"; | ||
echo 'Revoked Certificates Count: ' . count($crl->getSerialNumbers()); | ||
echo "\n"; | ||
|
||
$t3 = microtime(true); | ||
echo 'Total: ' . ($t3 - $t1) . 's'; | ||
echo "\n"; | ||
echo 'Memory Usage: ' . memory_get_peak_usage(true) . ' bytes'; | ||
echo "\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Adapik\CMS; | ||
|
||
use Adapik\CMS\Exception\FormatException; | ||
use FG\ASN1; | ||
use FG\ASN1\Mapper\Mapper; | ||
use FG\ASN1\Universal\Sequence; | ||
|
||
/** | ||
* Certificate Revocation List (CRL) | ||
*/ | ||
class CertificateRevocationList | ||
{ | ||
/** | ||
* @var Sequence | ||
*/ | ||
private $sequence; | ||
|
||
/** | ||
* Certificate constructor. | ||
* | ||
* @param Sequence $object | ||
*/ | ||
public function __construct(Sequence $object) | ||
{ | ||
$this->sequence = $object; | ||
} | ||
|
||
private function getTBSCertList() | ||
{ | ||
return $this->sequence->getChildren()[0]; | ||
} | ||
|
||
public function getSignatureAlgorithm() | ||
{ | ||
return (string) $this->sequence->getChildren()[1]->getChildren()[0]; | ||
} | ||
|
||
public function getSignatureValue() | ||
{ | ||
return (string) $this->sequence->getChildren()[2]; | ||
} | ||
|
||
public function getIssuer() | ||
{ | ||
$name = $this->getTBSCertList()->findChildrenByType(\FG\ASN1\Universal\Sequence::class)[1]; | ||
|
||
return new Name($name); | ||
} | ||
|
||
public function getThisUpdate() | ||
{ | ||
$time = $this->getTBSCertList()->findChildrenByType(\FG\ASN1\AbstractTime::class)[0]; | ||
|
||
return (string) $time; | ||
} | ||
|
||
public function getNextUpdate() | ||
{ | ||
$time = $this->getTBSCertList()->findChildrenByType(\FG\ASN1\AbstractTime::class)[1]; | ||
|
||
return (string) $time; | ||
} | ||
|
||
public function getSerialNumbers() | ||
{ | ||
$revokedCerts = $this->getTBSCertList()->findChildrenByType(\FG\ASN1\Universal\Sequence::class)[2]; | ||
|
||
$numbers = array_map(function(Sequence $revokedCert) { | ||
return gmp_strval((string) $revokedCert->getChildren()[0], 16); | ||
}, $revokedCerts->getChildren()); | ||
|
||
return $numbers; | ||
} | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param $content | ||
* | ||
* @return self | ||
* | ||
* @throws FormatException | ||
*/ | ||
public static function createFromContent($content) | ||
{ | ||
$sequence = ASN1\ASN1Object::fromFile($content); | ||
|
||
if (!$sequence instanceof Sequence) { | ||
throw new FormatException('CRL must be type of Sequence'); | ||
} | ||
|
||
$map = (new Mapper())->map($sequence, Maps\CertificateList::MAP); | ||
|
||
if ($map === null) { | ||
throw new FormatException('CRL invalid format'); | ||
} | ||
|
||
return new self($sequence); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CMS; | ||
|
||
use Adapik\CMS\CertificateRevocationList; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Test CertificateRevocationList class | ||
*/ | ||
class CertificateRevocationListTest extends TestCase | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $crl; | ||
|
||
protected function setUp() | ||
{ | ||
$this->crl = base64_decode(file_get_contents(__DIR__ . '/../fixtures/crl.crl')); | ||
} | ||
|
||
protected function tearDown() | ||
{ | ||
$this->crl = null; | ||
} | ||
|
||
public function testCreateFromContent() | ||
{ | ||
$crl = CertificateRevocationList::createFromContent($this->crl); | ||
$this->assertInstanceOf(CertificateRevocationList::class, $crl); | ||
} | ||
|
||
public function testGetIssuer() | ||
{ | ||
$crl = CertificateRevocationList::createFromContent($this->crl); | ||
$this->assertSame( | ||
'1.2.840.113549.1.9.1: [email protected]; 2.5.4.6: RU; 2.5.4.8: 77 г. Москва; 2.5.4.7: Москва; 2.5.4.9: 125375 г. Москва, ул. Тверская, д. 7; 2.5.4.10: Минкомсвязь России; 1.2.643.100.1: 1047702026701; 1.2.643.3.131.1.1: 007710474375; 2.5.4.3: Головной удостоверяющий центр', | ||
(string) $crl->getIssuer() | ||
); | ||
} | ||
|
||
public function testGetNextUpdate() | ||
{ | ||
$crl = CertificateRevocationList::createFromContent($this->crl); | ||
$this->assertSame('2018-04-06T08:33:56+00:00', $crl->getNextUpdate()); | ||
} | ||
|
||
public function testGetThisUpdate() | ||
{ | ||
$crl = CertificateRevocationList::createFromContent($this->crl); | ||
$this->assertSame('2018-03-07T08:33:56+00:00', $crl->getThisUpdate()); | ||
} | ||
|
||
public function testGetSerialNumbers() | ||
{ | ||
$crl = CertificateRevocationList::createFromContent($this->crl); | ||
$this->assertCount(27, $crl->getSerialNumbers()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters