From 87544abb7404ff8e63770ce489bad4e7513b4460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix-Antoine=20Fortin?= Date: Wed, 8 May 2024 09:02:27 -0400 Subject: [PATCH] Raise error when public key is invalid --- lib/hiera/backend/eyaml/encryptors/pkcs7.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/hiera/backend/eyaml/encryptors/pkcs7.rb b/lib/hiera/backend/eyaml/encryptors/pkcs7.rb index 95fbf0e..f17e5f9 100644 --- a/lib/hiera/backend/eyaml/encryptors/pkcs7.rb +++ b/lib/hiera/backend/eyaml/encryptors/pkcs7.rb @@ -43,6 +43,8 @@ def self.encrypt(plaintext) public_key_rsa = OpenSSL::PKey::RSA.new(public_key_pem) public_key_x509 = OpenSSL::X509::Certificate.new public_key_x509.public_key = public_key_rsa.public_key + else + raise StandardError, "file #{public_key_pem} cannot be used to encrypt - invalid public key format" end cipher = OpenSSL::Cipher.new('aes-256-cbc')