From ff708f86fadd891869a96320f1de499dee1b1046 Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Thu, 4 Jul 2024 17:28:10 +0900 Subject: [PATCH] [ruby/openssl] pkey/ec: use heredoc for invalid key example in test cases test/openssl/fixtures/pkey/p256_too_large.pem and p384_invalid.pem are invalid keys where the encoded public key doesn't match the private key. They are only useful for test cases for OpenSSL::PKey::EC#check_key and will not be reused elsewhere. Let's directly include the PEM encoding as a heredoc for clarity. p384_invalid.pem is dropped because it is redundant. https://github.com/ruby/openssl/commit/2f807ff30f --- test/openssl/fixtures/pkey/p256_too_large.pem | 5 ----- test/openssl/fixtures/pkey/p384_invalid.pem | 6 ------ test/openssl/test_pkey_ec.rb | 12 ++++++++---- 3 files changed, 8 insertions(+), 15 deletions(-) delete mode 100644 test/openssl/fixtures/pkey/p256_too_large.pem delete mode 100644 test/openssl/fixtures/pkey/p384_invalid.pem diff --git a/test/openssl/fixtures/pkey/p256_too_large.pem b/test/openssl/fixtures/pkey/p256_too_large.pem deleted file mode 100644 index a73ac37f87..0000000000 --- a/test/openssl/fixtures/pkey/p256_too_large.pem +++ /dev/null @@ -1,5 +0,0 @@ ------BEGIN EC PRIVATE KEY----- -MHcCAQEEIP+TT0V8Fndsnacji9tyf6hmhHywcOWTee9XkiBeJoVloAoGCCqGSM49 -AwEHoUQDQgAEBkhhJIU/2/YdPSlY2I1k25xjK4trr5OXSgXvBC21PtY0HQ7lor7A -jzT0giJITqmcd81fwGw5+96zLcdxTF1hVQ== ------END EC PRIVATE KEY----- diff --git a/test/openssl/fixtures/pkey/p384_invalid.pem b/test/openssl/fixtures/pkey/p384_invalid.pem deleted file mode 100644 index d5cdc9a3af..0000000000 --- a/test/openssl/fixtures/pkey/p384_invalid.pem +++ /dev/null @@ -1,6 +0,0 @@ ------BEGIN EC PRIVATE KEY----- -MIGkAgEBBDDA1Tm0m7YhkfeVpFuarAJYVlHp2tQj+1fOBiLa10t9E8TiQO/hVfxB -vGaVEQwOheWgBwYFK4EEACKhZANiAASyGqmryZGqdpsq5gEDIfNvgC3AwSJxiBCL -XKHBTFRp+tCezLDOK/6V8KK/vVGBJlGFW6/I7ahyXprxS7xs7hPA9iz5YiuqXlu+ -lbrIpZOz7b73hyQQCkvbBO/Avg+hPAk= ------END EC PRIVATE KEY----- diff --git a/test/openssl/test_pkey_ec.rb b/test/openssl/test_pkey_ec.rb index 2cb8e287ab..5a15c54415 100644 --- a/test/openssl/test_pkey_ec.rb +++ b/test/openssl/test_pkey_ec.rb @@ -88,12 +88,16 @@ class OpenSSL::TestEC < OpenSSL::PKeyTestCase assert_equal(true, key2.check_key) # Behavior of EVP_PKEY_public_check changes between OpenSSL 1.1.1 and 3.0 - key4 = Fixtures.pkey("p256_too_large") + # The public key does not match the private key + key4 = OpenSSL::PKey.read(<<~EOF) + -----BEGIN EC PRIVATE KEY----- + MHcCAQEEIP+TT0V8Fndsnacji9tyf6hmhHywcOWTee9XkiBeJoVloAoGCCqGSM49 + AwEHoUQDQgAEBkhhJIU/2/YdPSlY2I1k25xjK4trr5OXSgXvBC21PtY0HQ7lor7A + jzT0giJITqmcd81fwGw5+96zLcdxTF1hVQ== + -----END EC PRIVATE KEY----- + EOF assert_raise(OpenSSL::PKey::ECError) { key4.check_key } - key5 = Fixtures.pkey("p384_invalid") - assert_raise(OpenSSL::PKey::ECError) { key5.check_key } - # EC#private_key= is deprecated in 3.0 and won't work on OpenSSL 3.0 if !openssl?(3, 0, 0) key2.private_key += 1