Skip to content

Commit 94c1504

Browse files
committed
update and fix implementation for eyaml
1 parent 3d0dc42 commit 94c1504

2 files changed

Lines changed: 24 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
- Fix incorrect exit code `0` when `octocatalog` detects catalog compilation failure.
33
- Avoid mutation of and optimize Rubocop argument interfacing.
44
- Fix existing module install check when using Puppet Forge source for RSpec.
5+
- Upgrade EYAML validation functionality from beta to release candidate.
56

67
### 2.5.1
78
- Fix explicit `fail_on_warnings` default value assignment.

lib/puppet-check/data_parser.rb

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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(/\AENC\[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(/\AENC\[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

Comments
 (0)