Skip to content

Commit

Permalink
Merge pull request #16 from unreality/updated-config-settings
Browse files Browse the repository at this point in the history
add notifications toggle, dont take focus when a key has no password,…
  • Loading branch information
unreality authored Feb 4, 2024
2 parents eecebca + 5ed23d6 commit e0b4e64
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 28 deletions.
65 changes: 43 additions & 22 deletions keyman/keymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,18 @@ type KeyConfig struct {
Algorithm string `json:"algorithm,omitempty"`
Length int `json:"length,omitempty"`
VerifyRequired bool `json:"verifyRequired,omitempty"`
NoPin bool `json:"noPin,omitempty"`
}

type KeyManagerConfig struct {
Keys []*KeyConfig `json:"keys,omitempty"`
PinTimeout int `json:"pinTimeout,omitempty"`
PageantEnabled bool `json:"pageant"`
VSockEnabled bool `json:"vsock"`
NamedPipeEnabled bool `json:"namedpipe"`
CygwinEnabled bool `json:"cygwin"`
Keys []*KeyConfig `json:"keys,omitempty"`
PinTimeout int `json:"pinTimeout,omitempty"`
PageantEnabled bool `json:"pageant"`
VSockEnabled bool `json:"vsock"`
NamedPipeEnabled bool `json:"namedpipe"`
CygwinEnabled bool `json:"cygwin"`
DisableNotifications bool `json:"disableNotifications,omitempty"`
USBEvents bool `json:"usbEvents,omitempty"`
}

type Key struct {
Expand Down Expand Up @@ -116,7 +119,7 @@ type Key struct {
}

func (k *Key) TakeFocus() bool {
if k.hwnd != 0 {
if !k.config.NoPin && k.hwnd != 0 {
if k.Type == "NCRYPT" && k.signer != nil {
if ncryptSigner, ok := (*k.signer).(*Signer); ok {
if ncryptSigner.timeractive {
Expand All @@ -143,13 +146,15 @@ func (k *Key) TakeFocus() bool {
}

func (k *Key) ReturnFocus() {
win.ShowWindow(win.HWND(k.hwnd), win.SW_HIDE)
win.AttachThreadInput(int32(k.focusData.myID), int32(k.focusData.victimID), true)
win.ShowWindow(k.focusData.victimHWND, win.SW_NORMAL)
win.SetForegroundWindow(k.focusData.victimHWND)
win.SetFocus(k.focusData.victimHWND)
win.SetActiveWindow(k.focusData.victimHWND)
win.AttachThreadInput(int32(k.focusData.myID), int32(k.focusData.victimID), false)
if !k.config.NoPin {
win.ShowWindow(win.HWND(k.hwnd), win.SW_HIDE)
win.AttachThreadInput(int32(k.focusData.myID), int32(k.focusData.victimID), true)
win.ShowWindow(k.focusData.victimHWND, win.SW_SHOW)
win.SetForegroundWindow(k.focusData.victimHWND)
win.SetFocus(k.focusData.victimHWND)
win.SetActiveWindow(k.focusData.victimHWND)
win.AttachThreadInput(int32(k.focusData.myID), int32(k.focusData.victimID), false)
}
}

func (k *Key) AlgorithmReadable() string {
Expand Down Expand Up @@ -497,12 +502,14 @@ func NewKeyManager(configPath string) (*KeyManager, error) {
log.Printf("Using default config\n")
// create a default config
kmc = KeyManagerConfig{
Keys: nil,
PinTimeout: 5,
CygwinEnabled: true,
PageantEnabled: true,
VSockEnabled: true,
NamedPipeEnabled: true,
Keys: nil,
PinTimeout: 5,
CygwinEnabled: true,
PageantEnabled: true,
VSockEnabled: true,
NamedPipeEnabled: true,
DisableNotifications: true,
USBEvents: false,
}
} else {
//log.Printf("Loading %s\n", configPath)
Expand Down Expand Up @@ -898,6 +905,7 @@ func (km *KeyManager) CreateNewNCryptKey(keyName string, containerName string, p
ProviderName: providerName,
Length: bits,
Algorithm: algorithm,
NoPin: password == "",
}

k := Key{
Expand Down Expand Up @@ -1159,6 +1167,7 @@ func (km *KeyManager) CreateNewWebAuthNKey(keyName string, application string, c
Algorithm: "",
Length: 0,
VerifyRequired: verifyRequired,
NoPin: false,
},
handle: 0,
signer: nil,
Expand Down Expand Up @@ -1260,6 +1269,12 @@ func (km *KeyManager) SetPinTimeout(timeout int) {
func (km *KeyManager) GetPinTimeout() int {
return km.config.PinTimeout
}
func (km *KeyManager) GetUSBEventsEnabled() bool {
return km.config.USBEvents
}
func (km *KeyManager) GetNotificationsEnabled() bool {
return !km.config.DisableNotifications
}

func (km *KeyManager) EnableListener(listenerType string, enabled bool) {

Expand Down Expand Up @@ -1355,8 +1370,10 @@ func (km *KeyManager) SetNotifyChan(c chan NotifyMsg) {
}

func (km *KeyManager) Notify(n NotifyMsg) {
if km.notifyChan != nil {
km.notifyChan <- n
if km.GetNotificationsEnabled() {
if km.notifyChan != nil {
km.notifyChan <- n
}
}
}

Expand Down Expand Up @@ -1397,3 +1414,7 @@ func (km *KeyManager) LoadWebAuthNKey(kc *KeyConfig) (*Key, error) {

return &k, nil
}

func (km *KeyManager) SetNotificationsEnabled(enabled bool) {
km.config.DisableNotifications = !enabled
}
22 changes: 20 additions & 2 deletions ui/configview.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
type GlobalConfView struct {
*walk.GroupBox

PinTimeoutEdit *walk.LineEdit
PinTimeoutEdit *walk.LineEdit
NotificationsEdit *walk.CheckBox
}

func NewGlobalConfView(parent walk.Container) (*GlobalConfView, error) {
Expand All @@ -30,7 +31,7 @@ func NewGlobalConfView(parent walk.Container) (*GlobalConfView, error) {
layout.SetMargins(walk.Margins{10, 10, 10, 10})
layout.SetColumnStretchFactor(1, 3)

//Setup the name
//Setup PIN Timeout
pinTimeoutLabel, err := walk.NewTextLabel(gcv)
if err != nil {
return nil, err
Expand All @@ -47,6 +48,23 @@ func NewGlobalConfView(parent walk.Container) (*GlobalConfView, error) {
gcv.PinTimeoutEdit.SetText("0")
gcv.PinTimeoutEdit.SetAlignment(walk.AlignHFarVFar)

//Setup the notifications checkbox
notificationLabel, err := walk.NewTextLabel(gcv)
if err != nil {
return nil, err
}
layout.SetRange(notificationLabel, walk.Rectangle{0, 1, 1, 1})
notificationLabel.SetTextAlignment(walk.AlignHNearVCenter)
notificationLabel.SetText(fmt.Sprintf("&Show Notifications:"))
notificationLabel.SetToolTipText("Show toast notifications when a key operation succeeds or fails.")

if gcv.NotificationsEdit, err = walk.NewCheckBox(gcv); err != nil {
return nil, err
}
layout.SetRange(gcv.NotificationsEdit, walk.Rectangle{1, 1, 1, 1})
gcv.NotificationsEdit.SetChecked(true)
gcv.NotificationsEdit.SetAlignment(walk.AlignHFarVFar)

if err := walk.InitWrapperWindow(gcv); err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions ui/confpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func (cp *ConfPage) onSaveConfigClicked() {
cp.keyManager.SetPinTimeout(intVal)
}

cp.keyManager.SetNotificationsEnabled(cp.confPageView.globalConfView.NotificationsEdit.Checked())
cp.keyManager.EnableListener(listeners.TYPE_PAGEANT, cp.confPageView.pageantConfView.ListenerEnabled.Checked())
cp.keyManager.EnableListener(listeners.TYPE_NAMED_PIPE, cp.confPageView.namedPipeConfView.ListenerEnabled.Checked())
cp.keyManager.EnableListener(listeners.TYPE_VSOCK, cp.confPageView.vsockConfView.ListenerEnabled.Checked())
Expand Down
10 changes: 6 additions & 4 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,12 @@ func RunUI() {

km.SetNotifyChan(notifyChan)

// register for usb insert/remove events
err = deviceevents.RegisterDeviceNotification(windows.HWND(mkw.Handle()))
if err != nil {
showErrorCustom(nil, "Unable to register for USB events KeyManager", fmt.Sprintf("Inserting/Removing USB will not update available keys: %s", err))
if km.GetUSBEventsEnabled() {
// register for usb insert/remove events
err = deviceevents.RegisterDeviceNotification(windows.HWND(mkw.Handle()))
if err != nil {
showErrorCustom(nil, "Unable to register for USB events KeyManager", fmt.Sprintf("Inserting/Removing USB will not update available keys: %s", err))
}
}

mkw.Run()
Expand Down

0 comments on commit e0b4e64

Please sign in to comment.