Skip to content

Commit dbcc98c

Browse files
authored
Remove legacy V and SV identifiers from the CCI tags in xccdf2inspec (#221)
* Remove legacy V and SV identifiers from the CCI tags in xccdf2inspec * Add xccdf example with legacy and cci identifiers
1 parent 2a363f9 commit dbcc98c

File tree

4 files changed

+4311
-4
lines changed

4 files changed

+4311
-4
lines changed

examples/xccdf2inspec/data/U_CAN_Ubuntu_18-04_STIG-xccdf.xml

Lines changed: 4288 additions & 0 deletions
Large diffs are not rendered by default.

lib/happy_mapper_tools/stig_attributes.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ class ReferenceInfo
7777
element :dc_identifier, String, tag: 'identifier', namespace: 'dc'
7878
end
7979

80+
class Ident
81+
include HappyMapper
82+
attr_accessor :legacy
83+
attr_accessor :cci
84+
tag 'ident'
85+
attribute :system, String, tag: 'system'
86+
content :ident, String
87+
end
88+
8089
class Rule
8190
include HappyMapper
8291
tag 'Rule'
@@ -87,7 +96,7 @@ class Rule
8796
element :title, String, tag: 'title'
8897
has_one :description, Description, tag: 'description'
8998
element :reference, ReferenceInfo, tag: 'reference'
90-
has_many :idents, String, tag: 'ident'
99+
has_many :idents, Ident, tag: 'ident'
91100
element :fixtext, String, tag: 'fixtext'
92101
has_one :fix, Fix, tag: 'fix'
93102
has_one :check, Check, tag: 'check'

lib/inspec_tools/xccdf.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def initialize(xccdf, replace_tags = nil)
1717
@xccdf = replace_tags_in_xccdf(replace_tags, @xccdf) unless replace_tags.nil?
1818
cci_list_path = File.join(File.dirname(__FILE__), '../data/U_CCI_List.xml')
1919
@cci_items = HappyMapperTools::CCIAttributes::CCI_List.parse(File.read(cci_list_path))
20-
# @cci_items = HappyMapperTools::CCIAttributes::CCI_List.parse(File.read('./data/U_CCI_List.xml'))
20+
register_after_parse_callbacks
2121
@benchmark = HappyMapperTools::StigAttributes::Benchmark.parse(@xccdf)
2222
end
2323

@@ -89,6 +89,14 @@ def inject_metadata(metadata = '{}')
8989

9090
private
9191

92+
def register_after_parse_callbacks
93+
# Determine if the parsed Ident is refrencing a legacy ID number.
94+
HappyMapperTools::StigAttributes::Ident.after_parse do |object|
95+
object.cci = object.system.eql?('http://cyber.mil/cci')
96+
object.legacy = !object.cci
97+
end
98+
end
99+
92100
def replace_tags_in_xccdf(replace_tags, xccdf_xml)
93101
replace_tags.each do |tag|
94102
xccdf_xml = xccdf_xml.gsub(/(&lt;|<)#{tag}(&gt;|>)/, "$#{tag}")
@@ -133,8 +141,9 @@ def insert_controls
133141
control['tags']['rid'] = group.rule.id
134142
control['tags']['stig_id'] = group.rule.version
135143
control['tags']['fix_id'] = group.rule.fix.id
136-
control['tags']['cci'] = group.rule.idents
137-
control['tags']['nist'] = @cci_items.fetch_nists(group.rule.idents)
144+
control['tags']['cci'] = group.rule.idents.select { |i| i.cci }.map { |i| i.ident }
145+
control['tags']['legacy'] = group.rule.idents.select { |i| i.legacy}.map { |i| i.ident }
146+
control['tags']['nist'] = @cci_items.fetch_nists(control['tags']['cci'])
138147
control['tags']['false_negatives'] = group.rule.description.false_negatives if group.rule.description.false_negatives != ''
139148
control['tags']['false_positives'] = group.rule.description.false_positives if group.rule.description.false_positives != ''
140149
control['tags']['documentable'] = group.rule.description.documentable if group.rule.description.documentable != ''

lib/utilities/inspec_util.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ def self.unpack_inspec_json(directory, inspec_json, separated, output_format)
246246
control.add_tag(::Inspec::Object::Tag.new('stig_id', json_control['tags']['stig_id']))
247247
control.add_tag(::Inspec::Object::Tag.new('fix_id', json_control['tags']['fix_id']))
248248
control.add_tag(::Inspec::Object::Tag.new('cci', json_control['tags']['cci']))
249+
control.add_tag(::Inspec::Object::Tag.new('legacy', json_control['tags']['legacy']))
249250
control.add_tag(::Inspec::Object::Tag.new('nist', json_control['tags']['nist']))
250251
control.add_tag(::Inspec::Object::Tag.new('cis_level', json_control['tags']['cis_level'])) unless json_control['tags']['cis_level'].blank?
251252
control.add_tag(::Inspec::Object::Tag.new('cis_controls', json_control['tags']['cis_controls'])) unless json_control['tags']['cis_controls'].blank?

0 commit comments

Comments
 (0)