Two radio buttons, PowerToys 0.100 and earlier (the default) or 0.101 and later, bound straight to MacCipherScheme. Not a draft like the key and the port: one click is already a whole change, with no half-typed state to protect. The note points at it as the fix for the menu's "wrong encryption compatibility setting". Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
110 lines
4.6 KiB
Swift
110 lines
4.6 KiB
Swift
// The Security pane: the shared key every packet is encrypted with, which of the
|
|
// two PowerToys stream layouts to speak, and the port the matrix talks on.
|
|
//
|
|
// "Encryption key" / "Security key" / "To set up, generate the key on one
|
|
// machine, and enter it manually on other machines" / "New key" are the modern
|
|
// page's words (`MouseWithoutBordersPage.xaml:40-77`,
|
|
// `MouseWithoutBorders_SecurityKey.Description`); the grouped display form and
|
|
// the 16-character minimum are `Encryption.cs:65-79, 209-242`.
|
|
//
|
|
// The key and the port are drafts: changing either tears down and rebuilds every
|
|
// connection, so they are saved together on a button press, which is what the
|
|
// Windows form's single "&Apply" does ("Save changes and reconnect to the
|
|
// machines in the matrix", `frmMatrix.Designer.cs:440-441`). The encryption
|
|
// compatibility picker is not a draft — one click is already a whole, deliberate
|
|
// change, and there is no half-typed state to protect against.
|
|
|
|
import Foundation
|
|
import MWBCore
|
|
import SwiftUI
|
|
|
|
/// The key and port editor.
|
|
struct SecurityPane: View {
|
|
@ObservedObject var model: SettingsViewModel
|
|
|
|
var body: some View {
|
|
SettingsPaneLayout {
|
|
SettingsSection(
|
|
"Security key",
|
|
note:
|
|
"To set up, generate the key on one machine, and enter it manually on the "
|
|
+ "other machines. Every machine in the matrix — Windows included — must "
|
|
+ "use the same key, or the connection is refused."
|
|
) {
|
|
HStack(spacing: 8) {
|
|
keyField
|
|
Button(model.showSecurityKey ? "Hide" : "Show") {
|
|
model.showSecurityKey.toggle()
|
|
}
|
|
}
|
|
HStack(spacing: 8) {
|
|
Button("New key") { model.generateKey() }
|
|
Button("Copy") { model.copyKey() }
|
|
Spacer()
|
|
}
|
|
if !model.securityKeyIsValid {
|
|
Text(
|
|
"At least \(SecurityKey.minimumLength) characters; spaces are ignored."
|
|
)
|
|
.font(.callout).foregroundStyle(.red)
|
|
}
|
|
}
|
|
|
|
SettingsSection(
|
|
"Encryption compatibility",
|
|
note:
|
|
"Mouse Without Borders changed how it sets up its encrypted streams in "
|
|
+ "PowerToys 0.101. The two are not compatible and cannot be negotiated, so "
|
|
+ "this has to match the PowerToys version on the other machines. If the "
|
|
+ "menu says a machine has the wrong encryption compatibility setting, the "
|
|
+ "security key is right and this is the switch to change."
|
|
) {
|
|
Picker("Encryption compatibility", selection: model.binding(\.macCipherScheme)) {
|
|
Text("PowerToys 0.100 and earlier").tag(CipherScheme.legacy)
|
|
Text("PowerToys 0.101 and later").tag(CipherScheme.modern)
|
|
}
|
|
.pickerStyle(.radioGroup)
|
|
.labelsHidden()
|
|
}
|
|
|
|
SettingsSection(
|
|
"Port",
|
|
note:
|
|
"The data port. The control channel listens on the next port up, so 15100 "
|
|
+ "also uses 15101. Every machine in the matrix must agree, and both ports "
|
|
+ "have to be open in any firewall."
|
|
) {
|
|
HStack(spacing: 8) {
|
|
TextField("15100", text: $model.portDraft)
|
|
.textFieldStyle(.roundedBorder)
|
|
.frame(width: 100)
|
|
Spacer()
|
|
}
|
|
}
|
|
|
|
HStack(spacing: 8) {
|
|
Button("Save and reconnect") { model.saveConnection() }
|
|
.keyboardShortcut(.defaultAction)
|
|
Button("Revert") { model.refreshDrafts() }
|
|
Spacer()
|
|
}
|
|
|
|
NotYetActive(
|
|
text:
|
|
"The key is stored in the settings file in the clear, as it is on Windows, "
|
|
+ "so the file is written readable by you only.")
|
|
}
|
|
}
|
|
|
|
@ViewBuilder private var keyField: some View {
|
|
if model.showSecurityKey {
|
|
TextField("Security key", text: $model.securityKeyDraft)
|
|
.textFieldStyle(.roundedBorder)
|
|
.font(.system(.body, design: .monospaced))
|
|
} else {
|
|
SecureField("Security key", text: $model.securityKeyDraft)
|
|
.textFieldStyle(.roundedBorder)
|
|
}
|
|
}
|
|
}
|