From 162ebffe48e9239778353d2acedeb193b82062cc Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 9 Feb 2024 14:28:06 +0100 Subject: [PATCH 1/5] Skip self-check if device is offline --- compat/module.go | 4 ++++ compat/selfcheck.go | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/compat/module.go b/compat/module.go index ea5fcd69f..c159d02f7 100644 --- a/compat/module.go +++ b/compat/module.go @@ -2,6 +2,7 @@ package compat import ( "context" + "errors" "time" "github.com/tevino/abool" @@ -92,6 +93,9 @@ func selfcheckTaskFunc(ctx context.Context, task *modules.Task) error { case err == nil: // Successful. tracer.Debugf("compat: self-check successful") + case errors.Is(err, errSelfcheckSkipped): + // Skipped. + tracer.Debugf("compat: %s", err) case issue == nil: // Internal error. tracer.Warningf("compat: %s", err) diff --git a/compat/selfcheck.go b/compat/selfcheck.go index fd4a22bc2..e26c1ed54 100644 --- a/compat/selfcheck.go +++ b/compat/selfcheck.go @@ -3,6 +3,7 @@ package compat import ( "context" "encoding/hex" + "errors" "fmt" "net" "strings" @@ -11,6 +12,7 @@ import ( "github.com/safing/portbase/log" "github.com/safing/portbase/rng" + "github.com/safing/portmaster/netenv" "github.com/safing/portmaster/network/packet" "github.com/safing/portmaster/resolver" ) @@ -36,12 +38,19 @@ var ( dnsCheckWaitDuration = 45 * time.Second dnsCheckAnswerLock sync.Mutex dnsCheckAnswer net.IP + + errSelfcheckSkipped = errors.New("self-check skipped") ) func selfcheck(ctx context.Context) (issue *systemIssue, err error) { selfcheckLock.Lock() defer selfcheckLock.Unlock() + // Step 0: Check if self-check makes sense. + if !netenv.Online() { + return nil, fmt.Errorf("%w: device is offline or in limited network", errSelfcheckSkipped) + } + // Step 1: Check if the system integration sees a packet. // Empty recv channel. From 677ea177ee1a112d185ef32226422f67e67e48a1 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 9 Feb 2024 14:28:23 +0100 Subject: [PATCH 2/5] Add ping.archlinux.org to connectivity check domains --- netenv/online-status.go | 1 + 1 file changed, 1 insertion(+) diff --git a/netenv/online-status.go b/netenv/online-status.go index 8be03a592..7da51a13a 100644 --- a/netenv/online-status.go +++ b/netenv/online-status.go @@ -77,6 +77,7 @@ var ( "network-test.debian.org.", // Debian "204.pop-os.org.", // Pop OS "conncheck.opensuse.org.", // OpenSUSE + "ping.archlinux.org", // Arch // There are probably a lot more domains for all the Linux Distro/DE Variants. Please raise issues and/or submit PRs! // https://github.com/solus-project/budgie-desktop/issues/807 // https://www.lguruprasad.in/blog/2015/07/21/enabling-captive-portal-detection-in-gnome-3-14-on-debian-jessie/ From 4e2553c36d8809a50b5e5f44c7edba972c72a942 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 9 Feb 2024 14:28:56 +0100 Subject: [PATCH 3/5] Stop using dashes for port names, as they collide with port range dashes --- network/reference/ports.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/network/reference/ports.go b/network/reference/ports.go index 3c24826d9..6f6873f50 100644 --- a/network/reference/ports.go +++ b/network/reference/ports.go @@ -14,8 +14,8 @@ var ( 25: "SMTP", 43: "WHOIS", 53: "DNS", - 67: "DHCP-SERVER", - 68: "DHCP-CLIENT", + 67: "DHCP_SERVER", + 68: "DHCP_CLIENT", 69: "TFTP", 80: "HTTP", 110: "POP3", @@ -27,10 +27,10 @@ var ( 389: "LDAP", 443: "HTTPS", 445: "SMB", - 587: "SMTP-ALT", - 465: "SMTP-SSL", - 993: "IMAP-SSL", - 995: "POP3-SSL", + 587: "SMTP_ALT", + 465: "SMTP_SSL", + 993: "IMAP_SSL", + 995: "POP3_SSL", } portNumbers = map[string]uint16{ @@ -42,7 +42,9 @@ var ( "WHOIS": 43, "DNS": 53, "DHCP-SERVER": 67, + "DHCP_SERVER": 67, "DHCP-CLIENT": 68, + "DHCP_CLIENT": 68, "TFTP": 69, "HTTP": 80, "POP3": 110, @@ -55,9 +57,13 @@ var ( "HTTPS": 443, "SMB": 445, "SMTP-ALT": 587, + "SMTP_ALT": 587, "SMTP-SSL": 465, + "SMTP_SSL": 465, "IMAP-SSL": 993, + "IMAP_SSL": 993, "POP3-SSL": 995, + "POP3_SSL": 995, } ) From 5def16e5427fcb027566d86df28be6f8407682d2 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 9 Feb 2024 14:29:12 +0100 Subject: [PATCH 4/5] Improve finding windows exe icon --- profile/binmeta/find_windows.go | 49 +++++++++++++++++---------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/profile/binmeta/find_windows.go b/profile/binmeta/find_windows.go index b00cb1666..deeeb2357 100644 --- a/profile/binmeta/find_windows.go +++ b/profile/binmeta/find_windows.go @@ -63,29 +63,6 @@ func getIconAndNamefromRSS(ctx context.Context, binPath string) (png []byte, nam // return true // }) - // Get first icon. - var ( - icon *winres.Icon - iconErr error - ) - rss.WalkType(winres.RT_GROUP_ICON, func(resID winres.Identifier, langID uint16, _ []byte) bool { - icon, iconErr = rss.GetIconTranslation(resID, langID) - return iconErr != nil - }) - if iconErr != nil { - return nil, "", fmt.Errorf("failed to get icon: %w", err) - } - // Convert icon. - icoBuf := &bytes.Buffer{} - err = icon.SaveICO(icoBuf) - if err != nil { - return nil, "", fmt.Errorf("failed to save ico: %w", err) - } - png, err = ConvertICOtoPNG(icoBuf.Bytes()) - if err != nil { - return nil, "", fmt.Errorf("failed to convert ico to png: %w", err) - } - // Get name from version record. var ( versionInfo *version.Info @@ -111,5 +88,31 @@ func getIconAndNamefromRSS(ctx context.Context, binPath string) (png []byte, nam }) name = cleanFileDescription(name) + // Get first icon. + var ( + icon *winres.Icon + iconErr error + ) + rss.WalkType(winres.RT_GROUP_ICON, func(resID winres.Identifier, langID uint16, _ []byte) bool { + icon, iconErr = rss.GetIconTranslation(resID, langID) + return iconErr != nil + }) + if iconErr != nil { + return nil, name, fmt.Errorf("failed to get icon: %w", err) + } + if icon == nil { + return nil, name, errors.New("no icon in resources") + } + // Convert icon, if it exists. + icoBuf := &bytes.Buffer{} + err = icon.SaveICO(icoBuf) + if err != nil { + return nil, name, fmt.Errorf("failed to save ico: %w", err) + } + png, err = ConvertICOtoPNG(icoBuf.Bytes()) + if err != nil { + return nil, name, fmt.Errorf("failed to convert ico to png: %w", err) + } + return png, name, nil } From 0ebe494c6cc46777696c3fec0d310b5c6e46dbc4 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 5 Mar 2024 11:45:00 +0100 Subject: [PATCH 5/5] Improve logging --- netenv/online-status.go | 2 +- profile/binmeta/find_linux.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/netenv/online-status.go b/netenv/online-status.go index 7da51a13a..7ec4a3f49 100644 --- a/netenv/online-status.go +++ b/netenv/online-status.go @@ -435,7 +435,7 @@ func checkOnlineStatus(ctx context.Context) { ipv4, ipv6, err := GetAssignedAddresses() if err != nil { - log.Warningf("network: failed to get assigned network addresses: %s", err) + log.Warningf("netenv: failed to get assigned network addresses: %s", err) } else { var lan bool diff --git a/profile/binmeta/find_linux.go b/profile/binmeta/find_linux.go index bf4357d7c..b6e7816af 100644 --- a/profile/binmeta/find_linux.go +++ b/profile/binmeta/find_linux.go @@ -77,7 +77,8 @@ func searchDirectory(directory string, binPath string) (iconPath string, err err } return "", fmt.Errorf("failed to read directory %s: %w", directory, err) } - fmt.Println(directory) + // DEBUG: + // fmt.Println(directory) var ( bestMatch string