Skip to content

Commit 3d2d7c4

Browse files
authored
Merge pull request #9 from xprazak2/tailoring
Add basic implementation for tailoring
2 parents 85ff163 + 3f23e9d commit 3d2d7c4

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed

lib/openscap/xccdf/tailoring.rb

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#
2+
# Copyright (c) 2016 Red Hat Inc.
3+
#
4+
# This software is licensed to you under the GNU General Public License,
5+
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
6+
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
7+
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
8+
# along with this software; if not, see
9+
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
10+
#
11+
12+
require 'openscap/source'
13+
require 'openscap/xccdf/profile'
14+
15+
module OpenSCAP
16+
module Xccdf
17+
class Tailoring
18+
attr_reader :raw
19+
20+
def initialize(source, benchmark)
21+
case source
22+
when OpenSCAP::Source
23+
@raw = OpenSCAP.xccdf_tailoring_import_source source.raw, benchmark
24+
else
25+
fail OpenSCAP::OpenSCAPError, "Cannot initialize OpenSCAP::Xccdf::Tailoring with '#{source}'"
26+
end
27+
OpenSCAP.raise! if @raw.null?
28+
end
29+
30+
def profiles
31+
@profiles ||= profiles_init
32+
end
33+
34+
def destroy
35+
OpenSCAP.xccdf_tailoring_free @raw
36+
@raw = nil
37+
end
38+
39+
private
40+
41+
def profiles_init
42+
profiles = {}
43+
profit = OpenSCAP.xccdf_tailoring_get_profiles raw
44+
while OpenSCAP.xccdf_profile_iterator_has_more profit
45+
profile_p = OpenSCAP.xccdf_profile_iterator_next profit
46+
profile = OpenSCAP::Xccdf::Profile.new profile_p
47+
profiles[profile.id] = profile
48+
end
49+
OpenSCAP.xccdf_profile_iterator_free profit
50+
profiles
51+
end
52+
end
53+
end
54+
55+
attach_function :xccdf_tailoring_import_source, [:pointer, :pointer], :pointer
56+
attach_function :xccdf_tailoring_free, [:pointer], :void
57+
58+
attach_function :xccdf_tailoring_get_profiles, [:pointer], :pointer
59+
attach_function :xccdf_profile_iterator_has_more, [:pointer], :bool
60+
attach_function :xccdf_profile_iterator_next, [:pointer], :pointer
61+
attach_function :xccdf_profile_iterator_free, [:pointer], :void
62+
end

test/data/tailoring.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xccdf:Tailoring xmlns:xccdf="http://checklists.nist.gov/xccdf/1.2" id="xccdf_scap-workbench_tailoring_default">
3+
<xccdf:benchmark href="/usr/share/xml/scap/ssg/content/ssg-firefox-ds.xml"/>
4+
<xccdf:version time="2016-11-10T11:24:26">1</xccdf:version>
5+
<xccdf:Profile id="xccdf_org.ssgproject.content_profile_stig-firefox-upstream_customized" extends="xccdf_org.ssgproject.content_profile_stig-firefox-upstream">
6+
<xccdf:title xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en-US">Upstream Firefox STIG [CUSTOMIZED]</xccdf:title>
7+
<xccdf:description xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en-US">This profile is developed under the DoD consensus model and DISA FSO Vendor STIG process,
8+
serving as the upstream development environment for the Firefox STIG.
9+
10+
As a result of the upstream/downstream relationship between the SCAP Security Guide project
11+
and the official DISA FSO STIG baseline, users should expect variance between SSG and DISA FSO content.
12+
For official DISA FSO STIG content, refer to http://iase.disa.mil/stigs/app-security/browser-guidance/Pages/index.aspx.
13+
14+
While this profile is packaged by Red Hat as part of the SCAP Security Guide package, please note
15+
that commercial support of this SCAP content is NOT available. This profile is provided as example
16+
SCAP content with no endorsement for suitability or production readiness. Support for this
17+
profile is provided by the upstream SCAP Security Guide community on a best-effort basis. The
18+
upstream project homepage is https://fedorahosted.org/scap-security-guide/.
19+
</xccdf:description>
20+
<xccdf:select idref="xccdf_org.ssgproject.content_rule_firefox_preferences-non-secure_page_warning" selected="true"/>
21+
<xccdf:select idref="xccdf_org.ssgproject.content_rule_firefox_preferences-javascript_status_bar_text" selected="true"/>
22+
<xccdf:select idref="xccdf_org.ssgproject.content_rule_firefox_preferences-javascript_context_menus" selected="true"/>
23+
<xccdf:select idref="xccdf_org.ssgproject.content_rule_firefox_preferences-javascript_status_bar_changes" selected="true"/>
24+
<xccdf:select idref="xccdf_org.ssgproject.content_rule_firefox_preferences-javascript_window_resizing" selected="true"/>
25+
<xccdf:select idref="xccdf_org.ssgproject.content_rule_firefox_preferences-javascript_window_changes" selected="true"/>
26+
<xccdf:select idref="xccdf_org.ssgproject.content_rule_firefox_preferences-auto-update_of_firefox" selected="false"/>
27+
<xccdf:select idref="xccdf_org.ssgproject.content_rule_firefox_preferences-autofill_passwords" selected="false"/>
28+
<xccdf:select idref="xccdf_org.ssgproject.content_rule_firefox_preferences-autofill_forms" selected="false"/>
29+
<xccdf:select idref="xccdf_org.ssgproject.content_rule_firefox_preferences-addons_plugin_updates" selected="false"/>
30+
</xccdf:Profile>
31+
</xccdf:Tailoring>

test/xccdf/tailoring_test.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#
2+
# Copyright (c) 2014--2016 Red Hat Inc.
3+
#
4+
# This software is licensed to you under the GNU General Public License,
5+
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
6+
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
7+
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
8+
# along with this software; if not, see
9+
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
10+
#
11+
12+
require 'openscap'
13+
require 'openscap/source'
14+
require 'openscap/xccdf/tailoring'
15+
require 'common/testcase'
16+
17+
class TailoringTest < OpenSCAP::TestCase
18+
def test_new_from_file
19+
tailoring = tailoring_from_file
20+
tailoring.destroy
21+
refute tailoring.raw
22+
end
23+
24+
def test_profiles
25+
profiles = tailoring_from_file.profiles
26+
assert_equal 1, profiles.length
27+
assert profiles.values.first.is_a?(OpenSCAP::Xccdf::Profile)
28+
end
29+
30+
private
31+
32+
def tailoring_from_file
33+
source = OpenSCAP::Source.new '../data/tailoring.xml'
34+
tailoring = OpenSCAP::Xccdf::Tailoring.new source, nil
35+
source.destroy
36+
assert tailoring
37+
tailoring
38+
end
39+
end

0 commit comments

Comments
 (0)