Tests/X509: add testRSACertWithECSDASig unit test

This commit is contained in:
terrafrost 2024-12-04 07:17:56 -06:00
parent ad709d815f
commit 2914a15d04

View File

@ -1404,4 +1404,78 @@ JYhGgW6KsKViE0hzQB8dSAcNcfwQPSKzOd02crXdJ7uYvZZK9prN83Oe1iDaizeA
$this->expectException(\RuntimeException::class);
$x509->getPublicKey();
}
/**
* @group github2051
*/
public function testRSACertWithECSDASig()
{
// a secp256r1 key
$CAPrivKey = PublicKeyLoader::load('-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgYZs/Y9XurjuN8SQ5
7Fyy1mTgHjFsdt0/3mOH7pfUbh6hRANCAASnmS1cmSu9dHOYrBg9aJRBs3PLPK62
u0s8T1gmnGIpKMyrHC3Sh6V2UczDODqpMXYiAsP6iPhiaq/3MmuhA0UA
-----END PRIVATE KEY-----');
$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->setEndDate('lifetime');
$x509->makeCA();
$result = $x509->sign($CAIssuer, $CASubject);
// a 2048-bit private key
$privKey = PublicKeyLoader::load('-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDCgThSXWv0segP
h6PkuQOp8Hl7vB/M6KBrpY+igKOG5IbXO6Fkhw/1nmgswa4tUu9b8Co9/HPDX/0X
owHoZuriLQluPdFAl9TJsiL4Etjui/vCzmvtAHlC6N8MjhpXJj/1gdX3sEwhTfnw
zAqQrR7SxIcoX4zHxHfQxsbR9my6x4HYSKVOEmJtDcTenaDXVqrHfzsc7FIAouSd
UL2TxrgalyrKZce50iF/1SoXLvD0XxXgJZhVkMzcsycNMf4a5+xDQOaAl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C4e4KCBtL+8IIIKf6rRkPJDCE8
lBzCxDOYWwbQFvqdaocuiCxX3/hkBRCLd1xOMIFhAoGAanaZkg7wogxseU0CDQWr
ek+8xhvMsVmSs20JhR0WWUxNxZblKCJOMTzDnNxTajl8OeGfHLJER20aubB08/Fh
3XTCUzLk69tfwhvGTVorZ+bQTAM1X18nzD89J03g/IaHxxR/nyB39Yq8yqNvuP0D
Zf+6b317dHQhk60gz+CIt8s=
-----END PRIVATE KEY-----');
$privKey = $privKey->withPadding(RSA::SIGNATURE_PKCS1);
$pubKey = $privKey->getPublicKey();
$subject = new X509;
$subject->setDomain('whatever.com');
$subject->setPublicKey($pubKey);
$x509 = new X509;
$x509->setEndDate('lifetime');
$result = $x509->sign($CAIssuer, $subject);
$cert = $x509->saveX509($result);
$x509 = new X509;
$cert = $x509->loadX509($cert);
$this->assertFalse(isset($cert['signatureAlgorithm']['parameters']));
$this->assertFalse(isset($cert['tbsCertificate']['signature']['parameters']));
}
}