Skip to content

Show trust discrepancies by default #763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 48 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
af8b541
Iniital functionality
egbicker Jan 25, 2023
8ccc93c
Merge remote-tracking branch 'origin/master' into 520-system-trust-di…
egbicker Jan 30, 2023
cf0214e
toggle working correctly
egbicker Jan 30, 2023
40f845c
Initial empty treeview message
egbicker Feb 1, 2023
90add1b
updating toggle functionality
egbicker Feb 2, 2023
3db4b88
Label working
egbicker Feb 7, 2023
13f794f
ATDB label
egbicker Feb 7, 2023
bf69114
Merge remote-tracking branch 'origin/master' into 520-system-trust-di…
egbicker Feb 7, 2023
01d92db
Merge remote-tracking branch 'origin/master' into 520-system-trust-di…
egbicker Feb 15, 2023
a15c051
more merge updates
egbicker Feb 17, 2023
2c628dc
Merge branch 'master' into 520-system-trust-discrepancies
jw3 Feb 19, 2023
82a30a4
Merge remote-tracking branch 'origin/master' into 520-system-trust-di…
egbicker Feb 20, 2023
a4f78fa
test filter
egbicker Feb 20, 2023
dd1db73
trust filter update
egbicker Feb 21, 2023
ebc87fa
toggle working
egbicker Feb 21, 2023
ec880f9
functionality working
egbicker Feb 23, 2023
c290d24
fixing tests
egbicker Feb 23, 2023
bb53613
lint
egbicker Feb 23, 2023
846bf0f
Merge remote-tracking branch 'origin/master' into 520-system-trust-di…
egbicker Feb 23, 2023
228aa1e
ATDB updates
egbicker Feb 24, 2023
16d1abf
PR updates fixing sensitivity
egbicker Mar 6, 2023
a04cecb
Merge remote-tracking branch 'origin/master' into 520-system-trust-di…
egbicker Mar 7, 2023
201bd40
lint
egbicker Mar 7, 2023
648945f
test fix
egbicker Mar 7, 2023
cd5e011
cleanup
egbicker Mar 7, 2023
0e79434
linting
egbicker Mar 7, 2023
1423b09
Merge branch 'master' into 520-system-trust-discrepancies
jw3 Mar 7, 2023
73ac862
test update
egbicker Mar 8, 2023
b132bdb
Merge branch '520-system-trust-discrepancies' of github.com:egbicker/…
egbicker Mar 8, 2023
006c3c5
Merge branch 'master' into 520-system-trust-discrepancies
jw3 Mar 10, 2023
9ac03e5
CI test fix
egbicker Mar 10, 2023
5a2d824
Merge branch '520-system-trust-discrepancies' of github.com:egbicker/…
egbicker Mar 10, 2023
519eebf
CI test commit
egbicker Mar 10, 2023
19a9fb1
Merge remote-tracking branch 'origin/master' into 520-system-trust-di…
egbicker Mar 29, 2023
758faf4
Fixing toggle issues, PR comments, merge updates
egbicker Mar 29, 2023
2931606
removing extra file
egbicker Mar 30, 2023
ec01cf5
Merge remote-tracking branch 'origin/master' into 520-system-trust-di…
egbicker Apr 18, 2023
2a253bb
lint
egbicker Apr 18, 2023
691f11c
merge test updates
egbicker Apr 18, 2023
c56d388
Merge remote-tracking branch 'origin/master' into 520-system-trust-di…
egbicker Apr 20, 2023
29126e1
count update and test fix
egbicker Apr 25, 2023
e24e2b6
initial sensitivity update
egbicker May 5, 2023
5285427
PR fixes
egbicker May 9, 2023
9b7ca54
Merge remote-tracking branch 'origin/master' into 520-system-trust-di…
egbicker May 18, 2023
f41f907
merge and re-extract messages
egbicker May 18, 2023
6d7f4d8
reformat
egbicker May 18, 2023
89024f2
multi-window fix
egbicker May 25, 2023
86e5ad6
Merge branch 'master' into 520-system-trust-discrepancies
jw3 Jun 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fapolicy_analyzer/glade/searchable_list.glade
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkScrolledWindow">
<object class="GtkScrolledWindow" id="viewScroll">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
Expand Down
11 changes: 11 additions & 0 deletions fapolicy_analyzer/tests/test_system_trust_database_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,14 @@ def test_load_trust_w_exception(mock_dispatch, mock_system_feature):
type=ADD_NOTIFICATION,
)
)


def test_set_label_view(widget):
widget.set_label_display()
assert (
isinstance(
widget.trust_file_list.get_object("viewScroll").get_child().get_child(),
Gtk.Label,
)
is True
)
17 changes: 11 additions & 6 deletions fapolicy_analyzer/tests/test_trust_file_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
_trust = [
MagicMock(status="u", path="/tmp/bar", actual=MagicMock(last_modified=123456789)),
MagicMock(status="t", path="/tmp/foo", actual=MagicMock(last_modified=123456789)),
MagicMock(
status="u", path="/tmp/foobar", actual=MagicMock(last_modified=123456789)
),
]


Expand All @@ -55,9 +58,9 @@ def test_uses_custom_markup_func(mocker):
)
markup_func = MagicMock(return_value="t")
widget = TrustFileList(trust_func=MagicMock(), markup_func=markup_func)
widget.init_list(2)
widget.init_list(3)
widget.append_trust(_trust)
markup_func.assert_called_with("t")
markup_func.assert_called_with("u")


def test_loads_trust_store(widget, mocker):
Expand All @@ -69,7 +72,8 @@ def test_loads_trust_store(widget, mocker):
"fapolicy_analyzer.ui.trust_file_list.GLib.idle_add",
side_effect=lambda x, args: x(args),
)
widget.init_list(2)
widget.init_list(3)
widget.show_trusted = True
widget.append_trust(_trust)
refresh_gui(delay=0.5)
view = widget.get_object("treeView")
Expand All @@ -83,7 +87,7 @@ def test_cancels_load_trust_store(widget, mocker):
return_value=MagicMock(submit=lambda x: x()),
)
mockIdleAdd = mocker.patch("fapolicy_analyzer.ui.trust_file_list.GLib.idle_add")
widget.init_list(2)
widget.init_list(3)
# trust_file_list._executorCanceled = True
widget.on_destroy()

Expand Down Expand Up @@ -130,7 +134,7 @@ def test_tree_count_full(widget, mocker):
"fapolicy_analyzer.ui.trust_file_list.GLib.idle_add",
side_effect=lambda x, args: x(args),
)
widget.init_list(2)
widget.init_list(3)
widget.append_trust(_trust)
refresh_gui(delay=0.5)
assert widget.treeCount.get_text() == "2 files"
Expand Down Expand Up @@ -160,9 +164,10 @@ def test_tree_count_partial(widget, mocker):
"fapolicy_analyzer.ui.trust_file_list.GLib.idle_add",
side_effect=lambda x, args: x(args),
)
widget.init_list(2)
widget.init_list(3)
widget.append_trust(_trust)
refresh_gui(delay=0.5)
assert widget.treeCount.get_text() == "2 files"
viewFilter = widget.get_object("search")
viewFilter.set_text("foo")
widget.on_search_activate()
Expand Down
36 changes: 31 additions & 5 deletions fapolicy_analyzer/ui/ancillary_trust_database_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ def __init__(self):
self.__loading_percent = -1
self.selectedFiles = None

self.create_trust_file_list()

self.trustFileDetails = TrustFileDetails()
self.get_object("rightBox").pack_start(
self.trustFileDetails.get_ref(), True, True, 0
)
self.show_label = False

def create_trust_file_list(self):
self.trust_file_list = AncillaryTrustFileList(trust_func=self.__load_trust)
self.trust_file_list.trust_selection_changed += self.on_trust_selection_changed
self.trust_file_list.files_added += self.on_files_added
Expand All @@ -57,11 +66,6 @@ def __init__(self):
self.trust_file_list.get_ref(), True, True, 0
)

self.trustFileDetails = TrustFileDetails()
self.get_object("rightBox").pack_start(
self.trustFileDetails.get_ref(), True, True, 0
)

def __load_trust(self):
self.__loading = True
self.__loading_percent = -1
Expand Down Expand Up @@ -163,6 +167,23 @@ def on_untrustBtn_clicked(self, *args):

self.delete_trusted_files(*self.selectedFiles)

def set_label_display(self):
scroll_window = self.trust_file_list.get_object("viewScroll")
scroll_window.remove(scroll_window.get_child())
scroll_window.add(Gtk.Label(label=strings.ANCILLARY_TRUST_NO_ENTRIES))
self.show_label = True
scroll_window.show_all()

def set_treeview_display(self):
scroll_window = self.trust_file_list.get_object("viewScroll")
scroll_window.remove(scroll_window.get_child())
if self.trust_file_list.treeView is not None:
scroll_window.add(self.trust_file_list.treeView)
else:
self.create_trust_file_list()
self.show_label = False
scroll_window.show_all()

def on_next_system(self, system):
def started_loading(state):
return (
Expand Down Expand Up @@ -197,6 +218,11 @@ def done_loading(state):
self.trust_file_list.set_changesets(self._changesets)
self.__load_trust()

if trust_state.trust_count == 0:
self.set_label_display()
elif self.show_label and trust_state.trust_count > 0:
self.set_treeview_display()

# if there was an error loading show appropriate notification
if trust_state.error and self.__loading:
self.__loading = False
Expand Down
1 change: 1 addition & 0 deletions fapolicy_analyzer/ui/ancillary_trust_file_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(self, trust_func):
addBtn.files_added += self.on_addBtn_files_added

super().__init__(trust_func, self.__status_markup, addBtn.get_ref())
self.show_trusted = True

def __status_markup(self, status):
s = status.lower()
Expand Down
43 changes: 32 additions & 11 deletions fapolicy_analyzer/ui/database_admin_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,67 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import gi
from events import Events
from fapolicy_analyzer.ui.ui_page import UIAction, UIPage

import fapolicy_analyzer.ui.strings as strings
from fapolicy_analyzer.ui.ancillary_trust_database_admin import (
AncillaryTrustDatabaseAdmin,
)
from fapolicy_analyzer.ui.system_trust_database_admin import SystemTrustDatabaseAdmin
from fapolicy_analyzer.ui.ui_page import UIPage
from fapolicy_analyzer.ui.ui_widget import UIWidget

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk # isort: skip


class DatabaseAdminPage(UIWidget, UIPage):
class DatabaseAdminPage(UIWidget, UIPage, Events):
def __init__(self):
notebook = Gtk.Notebook()
UIWidget.__init__(self, notebook)
UIPage.__init__(self)

self.notebook = Gtk.Notebook()
UIWidget.__init__(self, self.notebook)
Events.__init__(self)
actions = {
"toggle": [
UIAction(
name="Toggle",
tooltip="Toggle Displaying Trusted Entries",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs added to the strings.py file.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After your last commit this string still needs moved to the strings.py file.

icon="media-playlist-repeat",
signals={"clicked": self.on_trust_toggle_clicked},
sensitivity_func=self.trust_toggle_sensitivity,
)
],
}
UIPage.__init__(self, actions)
self.ancillaryTrustDbAdmin = AncillaryTrustDatabaseAdmin()
self.systemTrustDbAdmin = SystemTrustDatabaseAdmin()
self.systemTrustDbAdmin.file_added_to_ancillary_trust += (
self.on_added_to_ancillary_trust
)

notebook.append_page(
self.notebook.append_page(
self.systemTrustDbAdmin.get_ref(),
Gtk.Label(label=strings.SYSTEM_TRUST_TAB_LABEL),
)
notebook.append_page(
self.notebook.append_page(
self.ancillaryTrustDbAdmin.get_ref(),
Gtk.Label(label=strings.ANCILLARY_TRUST_TAB_LABEL),
)

notebook.set_current_page(1)
notebook.show_all()
self.notebook.set_current_page(1)
self.notebook.show_all()

def on_added_to_ancillary_trust(self, *files):
self.ancillaryTrustDbAdmin.add_trusted_files(*files)

def on_trust_toggle_clicked(self, *args):
self.systemTrustDbAdmin.trust_file_list.show_trusted ^= True
self.systemTrustDbAdmin.trust_file_list.loading_sensitive ^= True
self.systemTrustDbAdmin.trustFileDetails.clear()
self.systemTrustDbAdmin.trust_file_list.refresh()

def trust_toggle_sensitivity(self):
return self.systemTrustDbAdmin.trust_file_list.loading_sensitive

def _dispose(self):
self.ancillaryTrustDbAdmin.dispose()
self.systemTrustDbAdmin.dispose()
self.notebook.destroy()
7 changes: 4 additions & 3 deletions fapolicy_analyzer/ui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def __unapplied_changes(self):
return response != Gtk.ResponseType.OK

def __pack_main_content(self, page: UIPage):
if self.__page:
if self.__page is not None:
self.__page.dispose()
self.__page = page
self.mainContent.pack_start(page.get_ref(), True, True, 0)
Expand Down Expand Up @@ -205,7 +205,6 @@ def __dirty_changesets(self):

def on_start(self, *args):
logging.info("MainWindow::on_start()")

# On startup check for the existing of a tmp session file
# If detected, alert the user, enable the File|Restore menu item
if sessionManager.detect_previous_session():
Expand Down Expand Up @@ -428,7 +427,9 @@ def activate_file_analyzer(self, file):
self.__pack_main_content(page)

def on_trustDbMenu_activate(self, menuitem, *args):
self.__pack_main_content(router(PAGE_SELECTION.TRUST_DATABASE_ADMIN))
page = router(PAGE_SELECTION.TRUST_DATABASE_ADMIN)
page.systemTrustDbAdmin.trust_file_list.refresh_toolbar += self._refresh_toolbar
self.__pack_main_content(page)

def on_rulesAdminMenu_activate(self, *args, **kwargs):
rulesPage = router(PAGE_SELECTION.RULES_ADMIN)
Expand Down
12 changes: 12 additions & 0 deletions fapolicy_analyzer/ui/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,18 @@
ACCESS_ALLOWED_TOOLTIP = _("File access fully allowed")
ACCESS_PARTIAL_TOOLTIP = _("File access partially allowed")
ACCESS_DENIED_TOOLTIP = _("File access denied")
SYSTEM_TRUST_NO_DISCREPANCIES = _(
"""
No discrepancies found within the System Trust Database.
Click the toggle button on the action bar above to show all trusted files.
"""
)
ANCILLARY_TRUST_NO_ENTRIES = _(
"""
No entries found in the Ancillary Trust Database.
Use the search bar or add untrusted files from the System Trust Database tab.
"""
)
TIME_FORMAT_CONFIG_TITLE = _("Syslog Format Check")
SYSLOG_FORMAT_WARNING = _(
"""
Expand Down
32 changes: 31 additions & 1 deletion fapolicy_analyzer/ui/system_trust_database_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
from fapolicy_analyzer.ui.ui_widget import UIConnectedWidget
from fapolicy_analyzer.util import fs # noqa: F401
from fapolicy_analyzer.util.format import f
import gi

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk # isort: skip


class SystemTrustDatabaseAdmin(UIConnectedWidget, Events):
Expand Down Expand Up @@ -58,6 +62,7 @@ def __init__(self):
self.get_object("rightBox").pack_start(
self.trustFileDetails.get_ref(), True, True, 0
)
self.show_label = False

def __status_markup(self, status):
return (
Expand Down Expand Up @@ -94,7 +99,6 @@ def done_loading(state):
)

trust_state = system.get("system_trust")

if not trust_state.loading and self.__error != trust_state.error:
self.__error = trust_state.error
self.__loading = False
Expand All @@ -110,6 +114,7 @@ def done_loading(state):
trust_state.percent_complete if trust_state.percent_complete >= 0 else 0
)
self.trust_file_list.set_loading(True)
self.set_treeview_display() if self.show_label else None
self.trust_file_list.init_list(trust_state.trust_count)
self.trust_file_list.append_trust(trust_state.trust)
elif still_loading(trust_state):
Expand All @@ -120,6 +125,31 @@ def done_loading(state):
self.__error = None
self.__loading = False
self.__loading_percent = 100
if not self.trust_file_list.show_trusted:
n_entries = len(
[
data
for data in trust_state.trust
if not data.status.lower() == "t"
]
)
self.trust_file_list.total = n_entries
if n_entries == 0:
self.set_label_display()

def set_label_display(self):
scroll_window = self.trust_file_list.get_object("viewScroll")
scroll_window.remove(scroll_window.get_child())
scroll_window.add(Gtk.Label(label=strings.SYSTEM_TRUST_NO_DISCREPANCIES))
self.show_label = True
scroll_window.show_all()

def set_treeview_display(self):
scroll_window = self.trust_file_list.get_object("viewScroll")
scroll_window.remove(scroll_window.get_child())
scroll_window.add(self.trust_file_list.treeView)
self.show_label = False
scroll_window.show_all()

def on_trust_selection_changed(self, trusts):
self.selectedFiles = trusts
Expand Down
Loading