Skip to content

Commit

Permalink
Remove legacy V and SV identifiers from the CCI tags in xccdf2inspec (#…
Browse files Browse the repository at this point in the history
…221)

* Remove legacy V and SV identifiers from the CCI tags in xccdf2inspec

* Add xccdf example with legacy and cci identifiers
  • Loading branch information
Bialogs authored Mar 24, 2021
1 parent 2a363f9 commit dbcc98c
Show file tree
Hide file tree
Showing 4 changed files with 4,311 additions and 4 deletions.
4,288 changes: 4,288 additions & 0 deletions examples/xccdf2inspec/data/U_CAN_Ubuntu_18-04_STIG-xccdf.xml

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion lib/happy_mapper_tools/stig_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ class ReferenceInfo
element :dc_identifier, String, tag: 'identifier', namespace: 'dc'
end

class Ident
include HappyMapper
attr_accessor :legacy
attr_accessor :cci
tag 'ident'
attribute :system, String, tag: 'system'
content :ident, String
end

class Rule
include HappyMapper
tag 'Rule'
Expand All @@ -87,7 +96,7 @@ class Rule
element :title, String, tag: 'title'
has_one :description, Description, tag: 'description'
element :reference, ReferenceInfo, tag: 'reference'
has_many :idents, String, tag: 'ident'
has_many :idents, Ident, tag: 'ident'
element :fixtext, String, tag: 'fixtext'
has_one :fix, Fix, tag: 'fix'
has_one :check, Check, tag: 'check'
Expand Down
15 changes: 12 additions & 3 deletions lib/inspec_tools/xccdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def initialize(xccdf, replace_tags = nil)
@xccdf = replace_tags_in_xccdf(replace_tags, @xccdf) unless replace_tags.nil?
cci_list_path = File.join(File.dirname(__FILE__), '../data/U_CCI_List.xml')
@cci_items = HappyMapperTools::CCIAttributes::CCI_List.parse(File.read(cci_list_path))
# @cci_items = HappyMapperTools::CCIAttributes::CCI_List.parse(File.read('./data/U_CCI_List.xml'))
register_after_parse_callbacks
@benchmark = HappyMapperTools::StigAttributes::Benchmark.parse(@xccdf)
end

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

private

def register_after_parse_callbacks
# Determine if the parsed Ident is refrencing a legacy ID number.
HappyMapperTools::StigAttributes::Ident.after_parse do |object|
object.cci = object.system.eql?('http://cyber.mil/cci')
object.legacy = !object.cci
end
end

def replace_tags_in_xccdf(replace_tags, xccdf_xml)
replace_tags.each do |tag|
xccdf_xml = xccdf_xml.gsub(/(&lt;|<)#{tag}(&gt;|>)/, "$#{tag}")
Expand Down Expand Up @@ -133,8 +141,9 @@ def insert_controls
control['tags']['rid'] = group.rule.id
control['tags']['stig_id'] = group.rule.version
control['tags']['fix_id'] = group.rule.fix.id
control['tags']['cci'] = group.rule.idents
control['tags']['nist'] = @cci_items.fetch_nists(group.rule.idents)
control['tags']['cci'] = group.rule.idents.select { |i| i.cci }.map { |i| i.ident }
control['tags']['legacy'] = group.rule.idents.select { |i| i.legacy}.map { |i| i.ident }
control['tags']['nist'] = @cci_items.fetch_nists(control['tags']['cci'])
control['tags']['false_negatives'] = group.rule.description.false_negatives if group.rule.description.false_negatives != ''
control['tags']['false_positives'] = group.rule.description.false_positives if group.rule.description.false_positives != ''
control['tags']['documentable'] = group.rule.description.documentable if group.rule.description.documentable != ''
Expand Down
1 change: 1 addition & 0 deletions lib/utilities/inspec_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def self.unpack_inspec_json(directory, inspec_json, separated, output_format)
control.add_tag(::Inspec::Object::Tag.new('stig_id', json_control['tags']['stig_id']))
control.add_tag(::Inspec::Object::Tag.new('fix_id', json_control['tags']['fix_id']))
control.add_tag(::Inspec::Object::Tag.new('cci', json_control['tags']['cci']))
control.add_tag(::Inspec::Object::Tag.new('legacy', json_control['tags']['legacy']))
control.add_tag(::Inspec::Object::Tag.new('nist', json_control['tags']['nist']))
control.add_tag(::Inspec::Object::Tag.new('cis_level', json_control['tags']['cis_level'])) unless json_control['tags']['cis_level'].blank?
control.add_tag(::Inspec::Object::Tag.new('cis_controls', json_control['tags']['cis_controls'])) unless json_control['tags']['cis_controls'].blank?
Expand Down

0 comments on commit dbcc98c

Please sign in to comment.