@@ -48,24 +48,8 @@ def self.eyaml(files, public, private)
4848 # load the file
4949 parsed = YAML . safe_load_file ( file , permitted_classes : [ Symbol ] , permitted_symbols : [ ] , aliases : true )
5050
51- # recursively decrypts ENC[PKCS7,...] leaf values in a parsed eyaml structure
52- decoded = case parsed
53- when Hash
54- # recurse into hash values and keys are never encrypted
55- parsed . transform_values { |v | decrypt_eyaml ( v , rsa , x509 ) }
56- when Array
57- # recurse into array elements
58- parsed . map { |v | decrypt_eyaml ( v , rsa , x509 ) }
59- when String
60- # leave plain (non-ENC) strings untouched
61- match = parsed . match ( /\A ENC\[ PKCS7,(.+)\] \z /m )
62- return parsed unless match
63-
64- # decode the base64 payload to DER and decrypt
65- OpenSSL ::PKCS7 . new ( Base64 . decode64 ( match [ 1 ] ) ) . decrypt ( rsa , x509 )
66- else
67- parsed
68- end
51+ # decrypt any ENC[PKCS7,...] leaf values found in the parsed structure
52+ decoded = decrypt_eyaml ( parsed , rsa , x509 )
6953 rescue StandardError => err
7054 PuppetCheck . files [ :errors ] [ file ] = err . to_s . gsub ( "(#{ file } ): " , '' ) . split ( "\n " )
7155 else
@@ -79,6 +63,27 @@ def self.eyaml(files, public, private)
7963 end
8064 end
8165
66+ # recursively decrypts ENC[PKCS7,...] leaf values in a parsed eyaml structure
67+ private_class_method def self . decrypt_eyaml ( data , rsa , x509 )
68+ case data
69+ when Hash
70+ # recurse into hash values, keys are never encrypted
71+ data . transform_values { |v | decrypt_eyaml ( v , rsa , x509 ) }
72+ when Array
73+ # recurse into array elements
74+ data . map { |v | decrypt_eyaml ( v , rsa , x509 ) }
75+ when String
76+ # leave plain (non-ENC) strings untouched
77+ match = data . match ( /\A ENC\[ PKCS7,(.+)\] \z /m )
78+ return data unless match
79+
80+ # decode the base64 payload to DER and decrypt
81+ OpenSSL ::PKCS7 . new ( Base64 . decode64 ( match [ 1 ] ) ) . decrypt ( rsa , x509 )
82+ else
83+ data
84+ end
85+ end
86+
8287 # metadata consts
8388 REQUIRED_KEYS = %w[ name version author license summary source dependencies ] . freeze
8489 REQ_DEP_KEYS = %w[ requirements dependencies ] . freeze
0 commit comments