2017-08-06 17:35:52 +00:00
|
|
|
<?php
|
2022-02-17 02:25:59 +00:00
|
|
|
|
2017-08-06 17:35:52 +00:00
|
|
|
/**
|
|
|
|
* @author Jim Wigginton <terrafrost@php.net>
|
|
|
|
* @copyright 2017 Jim Wigginton
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
|
|
*/
|
|
|
|
|
2022-06-04 15:31:21 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-02-23 02:48:51 +00:00
|
|
|
namespace phpseclib3\Tests\Unit\File\X509;
|
|
|
|
|
2022-09-23 20:02:44 +00:00
|
|
|
use phpseclib3\Crypt\RSA;
|
2019-11-07 05:41:40 +00:00
|
|
|
use phpseclib3\File\X509;
|
2022-09-23 20:23:25 +00:00
|
|
|
use phpseclib3\Math\BigInteger;
|
2022-02-23 02:48:51 +00:00
|
|
|
use phpseclib3\Tests\PhpseclibTestCase;
|
2017-08-06 17:35:52 +00:00
|
|
|
|
2022-02-23 02:48:51 +00:00
|
|
|
class CRLTest extends PhpseclibTestCase
|
2017-08-06 17:35:52 +00:00
|
|
|
{
|
2022-06-04 15:31:21 +00:00
|
|
|
public function testLoadCRL(): void
|
2017-08-06 17:35:52 +00:00
|
|
|
{
|
2017-08-08 03:35:29 +00:00
|
|
|
$test = file_get_contents(__DIR__ . '/crl.bin');
|
2017-08-06 17:35:52 +00:00
|
|
|
|
|
|
|
$x509 = new X509();
|
|
|
|
|
|
|
|
$x509->loadCRL($test);
|
|
|
|
|
|
|
|
$reason = $x509->getRevokedCertificateExtension('9048354325167497831898969642461237543', 'id-ce-cRLReasons');
|
|
|
|
|
|
|
|
$this->assertSame('unspecified', $reason);
|
|
|
|
}
|
2022-09-23 20:02:44 +00:00
|
|
|
|
2022-09-23 21:15:43 +00:00
|
|
|
public function testCreateCRL(): void
|
2022-09-23 20:02:44 +00:00
|
|
|
{
|
|
|
|
// create private key / x.509 cert for signing
|
|
|
|
$CAPrivKey = RSA::createKey(1024);
|
|
|
|
$CAPubKey = $CAPrivKey->getPublicKey();
|
|
|
|
|
|
|
|
$CASubject = new X509();
|
|
|
|
$CASubject->setDNProp('id-at-organizationName', 'phpseclib CA cert');
|
|
|
|
$CASubject->setPublicKey($CAPubKey);
|
|
|
|
|
|
|
|
$CAIssuer = new X509();
|
|
|
|
$CAIssuer->setPrivateKey($CAPrivKey);
|
|
|
|
$CAIssuer->setDN($CASubject->getDN());
|
|
|
|
|
|
|
|
$x509 = new X509();
|
|
|
|
$x509->makeCA();
|
|
|
|
$result = $x509->sign($CAIssuer, $CASubject);
|
|
|
|
$CA = $x509->saveX509($result);
|
|
|
|
|
|
|
|
// create CRL
|
|
|
|
$x509 = new X509();
|
|
|
|
$crl = $x509->loadCRL($x509->saveCRL($x509->signCRL($CAIssuer, new X509())));
|
2022-09-23 21:15:43 +00:00
|
|
|
$x509->revoke('zzz', '+1 year');
|
2022-09-23 20:02:44 +00:00
|
|
|
$crl = $x509->saveCRL($x509->signCRL($CAIssuer, $x509));
|
|
|
|
|
|
|
|
// validate newly created CRL
|
|
|
|
$x509 = new X509();
|
|
|
|
$x509->loadCA($CA);
|
|
|
|
$r = $x509->loadCRL($crl);
|
|
|
|
$this->assertArrayHasKey('parameters', $r['signatureAlgorithm']);
|
|
|
|
$this->assertTrue($x509->validateSignature());
|
|
|
|
}
|
2022-09-23 23:48:55 +00:00
|
|
|
|
2022-09-24 03:46:02 +00:00
|
|
|
public function testPSSSigWithPKCS1Cert(): void
|
2022-09-23 23:48:55 +00:00
|
|
|
{
|
|
|
|
$x509 = new X509();
|
|
|
|
$x509->loadCA('-----BEGIN CERTIFICATE-----
|
|
|
|
MIICADCCAWmgAwIBAgIUH+4+TBK2Iq+xTOuixlxSuMbPXPkwDQYJKoZIhvcNAQEL
|
|
|
|
BQAwHDEaMBgGA1UECgwRcGhwc2VjbGliIENBIGNlcnQwHhcNMjIwOTIzMjIyNTE3
|
|
|
|
WhcNMjMwOTIzMjIyNTE3WjAcMRowGAYDVQQK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YQMnBVtpI6be+QcTjrFbsbuB9IonG9
|
|
|
|
uY1UHwoR+HohPes2wPUOV931ds6TufSxxcGgvwdaMacBfj/AD6M2ylxtqXY4EtVc
|
|
|
|
xbyT0osik+w=
|
|
|
|
-----END X509 CRL-----');
|
|
|
|
$this->assertTrue($x509->validateSignature());
|
|
|
|
}
|
2017-08-06 17:35:52 +00:00
|
|
|
}
|