diff --git a/README.md b/README.md index 9b8c867..028e4bc 100644 --- a/README.md +++ b/README.md @@ -143,9 +143,9 @@ Use the -l parameter to pass in a label for the encrypted value, ### Decryption -To decrypt something, you need the public_key and the private_key. +To decrypt something, you need the private_key. -To test decryption you can also use the eyaml tool if you have both keys +To test decryption you can use the eyaml tool $ eyaml decrypt -f filename # Decrypt a file $ eyaml decrypt -s 'ENC[PKCS7,.....]' # Decrypt a string diff --git a/lib/hiera/backend/eyaml/encryptors/pkcs7.rb b/lib/hiera/backend/eyaml/encryptors/pkcs7.rb index becaafd..eb1580d 100644 --- a/lib/hiera/backend/eyaml/encryptors/pkcs7.rb +++ b/lib/hiera/backend/eyaml/encryptors/pkcs7.rb @@ -51,10 +51,13 @@ def self.decrypt(ciphertext) private_key_pem = load_private_key_pem private_key_rsa = OpenSSL::PKey::RSA.new(private_key_pem) - public_key_pem = load_public_key_pem - public_key_x509 = OpenSSL::X509::Certificate.new(public_key_pem) - pkcs7 = OpenSSL::PKCS7.new(ciphertext) + + public_key_x509 = OpenSSL::X509::Certificate.new + public_key_x509.serial = pkcs7.recipients[0].serial + public_key_x509.issuer = pkcs7.recipients[0].issuer + public_key_x509.public_key = private_key_rsa.public_key + pkcs7.decrypt(private_key_rsa, public_key_x509) end