mirror of
https://github.com/danog/phpseclib.git
synced 2024-12-14 01:57:20 +01:00
Merge branch '3.0'
This commit is contained in:
commit
1642985976
@ -670,7 +670,7 @@ class X509
|
||||
*/
|
||||
private function mapOutExtensions(&$root, $path)
|
||||
{
|
||||
$extensions = &$this->subArray($root, $path);
|
||||
$extensions = &$this->subArray($root, $path, !empty($this->extensionValues));
|
||||
|
||||
foreach ($this->extensionValues as $id => $data) {
|
||||
extract($data);
|
||||
@ -679,16 +679,15 @@ class X509
|
||||
'extnValue' => $value,
|
||||
'critical' => $critical
|
||||
];
|
||||
if (!$replace) {
|
||||
$extensions[] = $newext;
|
||||
continue;
|
||||
}
|
||||
foreach ($extensions as $key => $value) {
|
||||
if ($value['extnId'] == $id) {
|
||||
$extensions[$key] = $newext;
|
||||
break;
|
||||
}
|
||||
if ($replace) {
|
||||
foreach ($extensions as $key => $value) {
|
||||
if ($value['extnId'] == $id) {
|
||||
$extensions[$key] = $newext;
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
$extensions[] = $newext;
|
||||
}
|
||||
|
||||
if (is_array($extensions)) {
|
||||
|
@ -5,6 +5,7 @@
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
use phpseclib3\Crypt\EC;
|
||||
use phpseclib3\Crypt\RSA;
|
||||
use phpseclib3\File\ASN1;
|
||||
use phpseclib3\File\X509;
|
||||
@ -114,4 +115,37 @@ class Unit_File_X509_X509ExtensionTest extends PhpseclibTestCase
|
||||
X509::registerExtension('bar', ['type' => ASN1::TYPE_OCTET_STRING]);
|
||||
X509::registerExtension('bar', ['type' => ASN1::TYPE_ANY]);
|
||||
}
|
||||
|
||||
public function testExtensionsAreInitializedIfMissing()
|
||||
{
|
||||
$issuerKey = EC::createKey('ed25519');
|
||||
$subjectKey = EC::createKey('ed25519')->getPublicKey();
|
||||
|
||||
$subject = new X509();
|
||||
$subject->setPublicKey($subjectKey);
|
||||
$subject->setDN(['commonName' => 'subject']);
|
||||
|
||||
$issuer = new X509();
|
||||
$issuer->setPrivateKey($issuerKey);
|
||||
$issuer->setDN(['commonName' => 'issuer']);
|
||||
|
||||
$authority = new X509();
|
||||
|
||||
$authority->setExtensionValue('id-ce-keyUsage', ['digitalSignature']);
|
||||
|
||||
$cert = $authority->saveX509($authority->sign($issuer, $subject));
|
||||
|
||||
$loader = new X509();
|
||||
|
||||
$this->assertSame(
|
||||
[
|
||||
[
|
||||
'extnId' => 'id-ce-keyUsage',
|
||||
'critical' => false,
|
||||
'extnValue' => ['digitalSignature'],
|
||||
],
|
||||
],
|
||||
$loader->loadX509($cert)['tbsCertificate']['extensions']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user