LibCrypto: Prevent exporting invalid DER RSAPrivateKey

This commit is contained in:
devgianlu 2025-02-16 11:55:31 +01:00 committed by Alexander Kalenik
parent 7180c5f13b
commit 3431b3235c
Notes: github-actions[bot] 2025-02-17 23:03:35 +00:00

View file

@ -121,6 +121,10 @@ public:
ErrorOr<ByteBuffer> export_as_der() const
{
if (m_prime_1.is_zero() || m_prime_2.is_zero()) {
return Error::from_string_literal("Cannot export private key without prime factors");
}
ASN1::Encoder encoder;
TRY(encoder.write_constructed(ASN1::Class::Universal, ASN1::Kind::Sequence, [&]() -> ErrorOr<void> {
TRY(encoder.write(0x00u)); // version