-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add prompt to confirm that the user trusts the origin before download…
…ing (#11)
- Loading branch information
Showing
6 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// HostTrustResult.swift | ||
// Tophat | ||
// | ||
// Created by Lukas Romsicki on 2024-08-26. | ||
// Copyright © 2024 Shopify. All rights reserved. | ||
// | ||
|
||
enum HostTrustResult { | ||
case allow | ||
case block | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// TrustedHostAlert.swift | ||
// Tophat | ||
// | ||
// Created by Lukas Romsicki on 2024-08-26. | ||
// Copyright © 2024 Shopify. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import AppKit | ||
import SwiftUI | ||
|
||
final class TrustedHostAlert { | ||
@CodableAppStorage("TrustedHosts") private var trustedHosts: [String] = [] | ||
|
||
func requestTrust(for host: String) async -> HostTrustResult { | ||
if trustedHosts.contains(host) { | ||
return .allow | ||
} | ||
|
||
let result = await MainActor.run { | ||
NSApp.activate(ignoringOtherApps: true) | ||
|
||
let alert = NSAlert() | ||
alert.alertStyle = .critical | ||
alert.messageText = "The host “\(host)” has not been trusted. Are you sure you want to continue?" | ||
alert.informativeText = "Launching an application containing malicious code can harm your Mac or compromise your privacy. Be sure you trust the origin of this application before continuing." | ||
|
||
let trustButton = alert.addButton(withTitle: "Trust") | ||
trustButton.keyEquivalent = "" | ||
|
||
let cancelButton = alert.addButton(withTitle: "Cancel") | ||
cancelButton.keyEquivalent = "\r" | ||
|
||
return alert.runModal() | ||
} | ||
|
||
switch result { | ||
case .alertFirstButtonReturn: | ||
trustedHosts.append(host) | ||
return .allow | ||
default: | ||
return .block | ||
} | ||
} | ||
} |