Improve support for YK5
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
IamTheFij 2021-01-18 21:00:56 -08:00
parent fc3e8a356b
commit f164b3a0af
3 changed files with 455 additions and 106 deletions

View File

@ -6,11 +6,11 @@
<string>com.iamthefij.alfred-yubico-auth</string> <string>com.iamthefij.alfred-yubico-auth</string>
<key>connections</key> <key>connections</key>
<dict> <dict>
<key>2D69982A-0DB6-4ABA-812F-C7F2A73650AE</key> <key>0149DE47-0232-434D-BB9E-B2C0B419A2E3</key>
<array> <array>
<dict> <dict>
<key>destinationuid</key> <key>destinationuid</key>
<string>9F48DDE6-BBE7-42ED-ABE5-C9255C92F1CD</string> <string>55DFD4B6-922A-4259-8625-EC14889FBACD</string>
<key>modifiers</key> <key>modifiers</key>
<integer>0</integer> <integer>0</integer>
<key>modifiersubtext</key> <key>modifiersubtext</key>
@ -18,6 +18,22 @@
<key>vitoclose</key> <key>vitoclose</key>
<false/> <false/>
</dict> </dict>
</array>
<key>27BC434A-1663-44A7-85AF-C4AC6E1BEFB7</key>
<array>
<dict>
<key>destinationuid</key>
<string>2D69982A-0DB6-4ABA-812F-C7F2A73650AE</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
<key>2D69982A-0DB6-4ABA-812F-C7F2A73650AE</key>
<array>
<dict> <dict>
<key>destinationuid</key> <key>destinationuid</key>
<string>A8D2CCAC-5CA4-495E-BB62-5C7F596FA157</string> <string>A8D2CCAC-5CA4-495E-BB62-5C7F596FA157</string>
@ -30,19 +46,44 @@
<key>vitoclose</key> <key>vitoclose</key>
<false/> <false/>
</dict> </dict>
</array>
<key>8486DCAA-AFB7-407D-A0E9-E57E09997B24</key>
<array>
<dict> <dict>
<key>destinationuid</key> <key>destinationuid</key>
<string>FB0DDF80-FF90-439A-BF3F-6EC58C2AA870</string> <string>0149DE47-0232-434D-BB9E-B2C0B419A2E3</string>
<key>modifiers</key> <key>modifiers</key>
<integer>1048576</integer> <integer>0</integer>
<key>modifiersubtext</key> <key>modifiersubtext</key>
<string>Paste token</string> <string></string>
<key>vitoclose</key> <key>vitoclose</key>
<false/> <false/>
</dict> </dict>
</array>
<key>55DFD4B6-922A-4259-8625-EC14889FBACD</key>
<array>
<dict>
<key>destinationuid</key>
<string>AD82ED59-033E-4860-B371-8128574E2FBC</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>sourceoutputuid</key>
<string>94F60406-01FF-4991-A697-2C83147293EB</string>
<key>vitoclose</key>
<false/>
</dict>
<dict>
<key>destinationuid</key>
<string>506787F2-9A61-492C-8C49-30EE04FB70BC</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
<key>8486DCAA-AFB7-407D-A0E9-E57E09997B24</key>
<array>
<dict> <dict>
<key>destinationuid</key> <key>destinationuid</key>
<string>2D69982A-0DB6-4ABA-812F-C7F2A73650AE</string> <string>2D69982A-0DB6-4ABA-812F-C7F2A73650AE</string>
@ -53,6 +94,16 @@
<key>vitoclose</key> <key>vitoclose</key>
<false/> <false/>
</dict> </dict>
<dict>
<key>destinationuid</key>
<string>27BC434A-1663-44A7-85AF-C4AC6E1BEFB7</string>
<key>modifiers</key>
<integer>1048576</integer>
<key>modifiersubtext</key>
<string>Paste code</string>
<key>vitoclose</key>
<false/>
</dict>
</array> </array>
<key>9F48DDE6-BBE7-42ED-ABE5-C9255C92F1CD</key> <key>9F48DDE6-BBE7-42ED-ABE5-C9255C92F1CD</key>
<array> <array>
@ -71,7 +122,32 @@
<array> <array>
<dict> <dict>
<key>destinationuid</key> <key>destinationuid</key>
<string>C252A5EC-1AEE-4EF4-864F-67483EAADCFA</string> <string>DA99BA2E-7234-491D-BD0F-044151FA98E2</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
<key>AD82ED59-033E-4860-B371-8128574E2FBC</key>
<array>
<dict>
<key>destinationuid</key>
<string>FB0DDF80-FF90-439A-BF3F-6EC58C2AA870</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>sourceoutputuid</key>
<string>94F60406-01FF-4991-A697-2C83147293EB</string>
<key>vitoclose</key>
<false/>
</dict>
<dict>
<key>destinationuid</key>
<string>9F48DDE6-BBE7-42ED-ABE5-C9255C92F1CD</string>
<key>modifiers</key> <key>modifiers</key>
<integer>0</integer> <integer>0</integer>
<key>modifiersubtext</key> <key>modifiersubtext</key>
@ -106,6 +182,31 @@
<false/> <false/>
</dict> </dict>
</array> </array>
<key>DA99BA2E-7234-491D-BD0F-044151FA98E2</key>
<array>
<dict>
<key>destinationuid</key>
<string>C252A5EC-1AEE-4EF4-864F-67483EAADCFA</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>sourceoutputuid</key>
<string>94F60406-01FF-4991-A697-2C83147293EB</string>
<key>vitoclose</key>
<false/>
</dict>
<dict>
<key>destinationuid</key>
<string>506787F2-9A61-492C-8C49-30EE04FB70BC</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
<key>E86DC7C1-35C1-4BA9-8B33-A95DE7082F7E</key> <key>E86DC7C1-35C1-4BA9-8B33-A95DE7082F7E</key>
<array> <array>
<dict> <dict>
@ -146,21 +247,46 @@
<dict> <dict>
<key>config</key> <key>config</key>
<dict> <dict>
<key>autopaste</key> <key>lastpathcomponent</key>
<true/>
<key>clipboardtext</key>
<string>{query}</string>
<key>ignoredynamicplaceholders</key>
<false/> <false/>
<key>transient</key> <key>onlyshowifquerypopulated</key>
<true/> <false/>
<key>removeextension</key>
<false/>
<key>text</key>
<string>Password key is now stored in your keychain</string>
<key>title</key>
<string>Password saved</string>
</dict> </dict>
<key>type</key> <key>type</key>
<string>alfred.workflow.output.clipboard</string> <string>alfred.workflow.output.notification</string>
<key>uid</key> <key>uid</key>
<string>FB0DDF80-FF90-439A-BF3F-6EC58C2AA870</string> <string>C252A5EC-1AEE-4EF4-864F-67483EAADCFA</string>
<key>version</key> <key>version</key>
<integer>3</integer> <integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>concurrently</key>
<false/>
<key>escaping</key>
<integer>102</integer>
<key>script</key>
<string>./alfred-yubico-auth -run-script set-password</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>type</key>
<integer>0</integer>
</dict>
<key>type</key>
<string>alfred.workflow.action.script</string>
<key>uid</key>
<string>A8D2CCAC-5CA4-495E-BB62-5C7F596FA157</string>
<key>version</key>
<integer>2</integer>
</dict> </dict>
<dict> <dict>
<key>config</key> <key>config</key>
@ -190,7 +316,7 @@
<key>runningsubtext</key> <key>runningsubtext</key>
<string></string> <string></string>
<key>script</key> <key>script</key>
<string>./alfred-yubico-auth</string> <string>./alfred-yubico-auth list</string>
<key>scriptargtype</key> <key>scriptargtype</key>
<integer>1</integer> <integer>1</integer>
<key>scriptfile</key> <key>scriptfile</key>
@ -211,6 +337,105 @@
<key>version</key> <key>version</key>
<integer>3</integer> <integer>3</integer>
</dict> </dict>
<dict>
<key>config</key>
<dict>
<key>conditions</key>
<array>
<dict>
<key>inputstring</key>
<string>{var:result}</string>
<key>matchcasesensitive</key>
<false/>
<key>matchmode</key>
<integer>0</integer>
<key>matchstring</key>
<string>success</string>
<key>outputlabel</key>
<string>success</string>
<key>uid</key>
<string>94F60406-01FF-4991-A697-2C83147293EB</string>
</dict>
</array>
<key>elselabel</key>
<string>else</string>
</dict>
<key>type</key>
<string>alfred.workflow.utility.conditional</string>
<key>uid</key>
<string>DA99BA2E-7234-491D-BD0F-044151FA98E2</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>conditions</key>
<array>
<dict>
<key>inputstring</key>
<string>{var:action}</string>
<key>matchcasesensitive</key>
<false/>
<key>matchmode</key>
<integer>0</integer>
<key>matchstring</key>
<string>set-password</string>
<key>outputlabel</key>
<string>Set password</string>
<key>uid</key>
<string>94F60406-01FF-4991-A697-2C83147293EB</string>
</dict>
</array>
<key>elselabel</key>
<string>else</string>
</dict>
<key>type</key>
<string>alfred.workflow.utility.conditional</string>
<key>uid</key>
<string>2D69982A-0DB6-4ABA-812F-C7F2A73650AE</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>argument</key>
<string>{query}</string>
<key>passthroughargument</key>
<false/>
<key>variables</key>
<dict>
<key>result_action</key>
<string>paste</string>
</dict>
</dict>
<key>type</key>
<string>alfred.workflow.utility.argument</string>
<key>uid</key>
<string>27BC434A-1663-44A7-85AF-C4AC6E1BEFB7</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>autopaste</key>
<true/>
<key>clipboardtext</key>
<string>{query}</string>
<key>ignoredynamicplaceholders</key>
<false/>
<key>transient</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.output.clipboard</string>
<key>uid</key>
<string>FB0DDF80-FF90-439A-BF3F-6EC58C2AA870</string>
<key>version</key>
<integer>3</integer>
</dict>
<dict> <dict>
<key>config</key> <key>config</key>
<dict> <dict>
@ -264,6 +489,61 @@
<key>version</key> <key>version</key>
<integer>1</integer> <integer>1</integer>
</dict> </dict>
<dict>
<key>config</key>
<dict>
<key>conditions</key>
<array>
<dict>
<key>inputstring</key>
<string>{var:result_action}</string>
<key>matchcasesensitive</key>
<false/>
<key>matchmode</key>
<integer>0</integer>
<key>matchstring</key>
<string>paste</string>
<key>outputlabel</key>
<string>paste</string>
<key>uid</key>
<string>94F60406-01FF-4991-A697-2C83147293EB</string>
</dict>
</array>
<key>elselabel</key>
<string>copy</string>
</dict>
<key>type</key>
<string>alfred.workflow.utility.conditional</string>
<key>uid</key>
<string>AD82ED59-033E-4860-B371-8128574E2FBC</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>concurrently</key>
<false/>
<key>escaping</key>
<integer>102</integer>
<key>script</key>
<string>query=$1
./alfred-yubico-auth -run-script "$query"</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>type</key>
<integer>0</integer>
</dict>
<key>type</key>
<string>alfred.workflow.action.script</string>
<key>uid</key>
<string>0149DE47-0232-434D-BB9E-B2C0B419A2E3</string>
<key>version</key>
<integer>2</integer>
</dict>
<dict> <dict>
<key>config</key> <key>config</key>
<dict> <dict>
@ -311,15 +591,15 @@
<array> <array>
<dict> <dict>
<key>inputstring</key> <key>inputstring</key>
<string>{var:action}</string> <string>{var:result}</string>
<key>matchcasesensitive</key> <key>matchcasesensitive</key>
<false/> <false/>
<key>matchmode</key> <key>matchmode</key>
<integer>0</integer> <integer>0</integer>
<key>matchstring</key> <key>matchstring</key>
<string>set-password</string> <string>success</string>
<key>outputlabel</key> <key>outputlabel</key>
<string>Set password</string> <string>success</string>
<key>uid</key> <key>uid</key>
<string>94F60406-01FF-4991-A697-2C83147293EB</string> <string>94F60406-01FF-4991-A697-2C83147293EB</string>
</dict> </dict>
@ -330,51 +610,28 @@
<key>type</key> <key>type</key>
<string>alfred.workflow.utility.conditional</string> <string>alfred.workflow.utility.conditional</string>
<key>uid</key> <key>uid</key>
<string>2D69982A-0DB6-4ABA-812F-C7F2A73650AE</string> <string>55DFD4B6-922A-4259-8625-EC14889FBACD</string>
<key>version</key> <key>version</key>
<integer>1</integer> <integer>1</integer>
</dict> </dict>
<dict>
<key>config</key>
<dict>
<key>concurrently</key>
<false/>
<key>escaping</key>
<integer>102</integer>
<key>script</key>
<string>./alfred-yubico-auth set-password</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>type</key>
<integer>0</integer>
</dict>
<key>type</key>
<string>alfred.workflow.action.script</string>
<key>uid</key>
<string>A8D2CCAC-5CA4-495E-BB62-5C7F596FA157</string>
<key>version</key>
<integer>2</integer>
</dict>
<dict> <dict>
<key>config</key> <key>config</key>
<dict> <dict>
<key>lastpathcomponent</key> <key>lastpathcomponent</key>
<false/> <false/>
<key>onlyshowifquerypopulated</key> <key>onlyshowifquerypopulated</key>
<false/> <true/>
<key>removeextension</key> <key>removeextension</key>
<false/> <false/>
<key>text</key> <key>text</key>
<string>Password key is now stored in your keychain</string> <string>{query}</string>
<key>title</key> <key>title</key>
<string>Password saved</string> <string>Alfred Yubikey Error</string>
</dict> </dict>
<key>type</key> <key>type</key>
<string>alfred.workflow.output.notification</string> <string>alfred.workflow.output.notification</string>
<key>uid</key> <key>uid</key>
<string>C252A5EC-1AEE-4EF4-864F-67483EAADCFA</string> <string>506787F2-9A61-492C-8C49-30EE04FB70BC</string>
<key>version</key> <key>version</key>
<integer>1</integer> <integer>1</integer>
</dict> </dict>
@ -383,75 +640,117 @@
<string></string> <string></string>
<key>uidata</key> <key>uidata</key>
<dict> <dict>
<key>0149DE47-0232-434D-BB9E-B2C0B419A2E3</key>
<dict>
<key>xpos</key>
<integer>180</integer>
<key>ypos</key>
<integer>305</integer>
</dict>
<key>0718204D-3398-4AEF-A621-DDDE1FC6ED75</key> <key>0718204D-3398-4AEF-A621-DDDE1FC6ED75</key>
<dict> <dict>
<key>xpos</key> <key>xpos</key>
<integer>990</integer> <integer>1245</integer>
<key>ypos</key> <key>ypos</key>
<integer>145</integer> <integer>225</integer>
</dict>
<key>27BC434A-1663-44A7-85AF-C4AC6E1BEFB7</key>
<dict>
<key>xpos</key>
<integer>260</integer>
<key>ypos</key>
<integer>155</integer>
</dict> </dict>
<key>2D69982A-0DB6-4ABA-812F-C7F2A73650AE</key> <key>2D69982A-0DB6-4ABA-812F-C7F2A73650AE</key>
<dict> <dict>
<key>xpos</key> <key>xpos</key>
<integer>270</integer> <integer>365</integer>
<key>ypos</key> <key>ypos</key>
<integer>245</integer> <integer>90</integer>
</dict>
<key>506787F2-9A61-492C-8C49-30EE04FB70BC</key>
<dict>
<key>xpos</key>
<integer>540</integer>
<key>ypos</key>
<integer>455</integer>
</dict>
<key>55DFD4B6-922A-4259-8625-EC14889FBACD</key>
<dict>
<key>xpos</key>
<integer>365</integer>
<key>ypos</key>
<integer>330</integer>
</dict> </dict>
<key>8486DCAA-AFB7-407D-A0E9-E57E09997B24</key> <key>8486DCAA-AFB7-407D-A0E9-E57E09997B24</key>
<dict> <dict>
<key>xpos</key> <key>xpos</key>
<integer>120</integer> <integer>70</integer>
<key>ypos</key> <key>ypos</key>
<integer>140</integer> <integer>65</integer>
</dict> </dict>
<key>9F48DDE6-BBE7-42ED-ABE5-C9255C92F1CD</key> <key>9F48DDE6-BBE7-42ED-ABE5-C9255C92F1CD</key>
<dict> <dict>
<key>xpos</key> <key>xpos</key>
<integer>415</integer> <integer>605</integer>
<key>ypos</key> <key>ypos</key>
<integer>235</integer> <integer>320</integer>
</dict> </dict>
<key>A8D2CCAC-5CA4-495E-BB62-5C7F596FA157</key> <key>A8D2CCAC-5CA4-495E-BB62-5C7F596FA157</key>
<dict> <dict>
<key>xpos</key> <key>xpos</key>
<integer>390</integer> <integer>515</integer>
<key>ypos</key> <key>ypos</key>
<integer>415</integer> <integer>55</integer>
</dict>
<key>AD82ED59-033E-4860-B371-8128574E2FBC</key>
<dict>
<key>xpos</key>
<integer>485</integer>
<key>ypos</key>
<integer>285</integer>
</dict> </dict>
<key>BFB3A122-52BB-4FF1-B5B3-CECD42A730DB</key> <key>BFB3A122-52BB-4FF1-B5B3-CECD42A730DB</key>
<dict> <dict>
<key>xpos</key> <key>xpos</key>
<integer>810</integer> <integer>1065</integer>
<key>ypos</key> <key>ypos</key>
<integer>145</integer> <integer>225</integer>
</dict> </dict>
<key>C252A5EC-1AEE-4EF4-864F-67483EAADCFA</key> <key>C252A5EC-1AEE-4EF4-864F-67483EAADCFA</key>
<dict> <dict>
<key>xpos</key> <key>xpos</key>
<integer>595</integer> <integer>800</integer>
<key>ypos</key> <key>ypos</key>
<integer>420</integer> <integer>45</integer>
</dict> </dict>
<key>DA3E9CE8-7C4F-4B09-BFA5-F8CA83297968</key> <key>DA3E9CE8-7C4F-4B09-BFA5-F8CA83297968</key>
<dict> <dict>
<key>xpos</key> <key>xpos</key>
<integer>590</integer> <integer>780</integer>
<key>ypos</key> <key>ypos</key>
<integer>235</integer> <integer>320</integer>
</dict>
<key>DA99BA2E-7234-491D-BD0F-044151FA98E2</key>
<dict>
<key>xpos</key>
<integer>670</integer>
<key>ypos</key>
<integer>75</integer>
</dict> </dict>
<key>E86DC7C1-35C1-4BA9-8B33-A95DE7082F7E</key> <key>E86DC7C1-35C1-4BA9-8B33-A95DE7082F7E</key>
<dict> <dict>
<key>xpos</key> <key>xpos</key>
<integer>730</integer> <integer>985</integer>
<key>ypos</key> <key>ypos</key>
<integer>175</integer> <integer>255</integer>
</dict> </dict>
<key>FB0DDF80-FF90-439A-BF3F-6EC58C2AA870</key> <key>FB0DDF80-FF90-439A-BF3F-6EC58C2AA870</key>
<dict> <dict>
<key>xpos</key> <key>xpos</key>
<integer>455</integer> <integer>605</integer>
<key>ypos</key> <key>ypos</key>
<integer>60</integer> <integer>185</integer>
</dict> </dict>
</dict> </dict>
<key>version</key> <key>version</key>

116
main.go
View File

@ -1,20 +1,23 @@
package main package main
import ( import (
"bytes"
"errors"
"flag" "flag"
"fmt"
"git.iamthefij.com/iamthefij/slog" "git.iamthefij.com/iamthefij/slog"
aw "github.com/deanishe/awgo" aw "github.com/deanishe/awgo"
"github.com/deanishe/awgo/util" "github.com/deanishe/awgo/util"
"github.com/yawn/ykoath" "github.com/yawn/ykoath"
"bytes"
) )
var ( var (
wf *aw.Workflow wf *aw.Workflow
oath *ykoath.OATH oath *ykoath.OATH
keychainAccount = "yubico-auth-creds" keychainAccount = "yubico-auth-creds"
errIncorrectPassword = errors.New("incorrect password")
) )
func init() { func init() {
@ -28,102 +31,149 @@ func main() {
func promptPassword() (string, error) { func promptPassword() (string, error) {
out, err := util.Run("./password-prompt.js") out, err := util.Run("./password-prompt.js")
if err != nil { if err != nil {
return "", err return "", fmt.Errorf("error reading password from prompt: %w", err)
} }
out = bytes.TrimRight(out, "\n") out = bytes.TrimRight(out, "\n")
return string(out), nil return string(out), nil
} }
func setPassword(s *ykoath.Select) error { func setPassword(s *ykoath.Select) error {
passphrase, err := promptPassword() passphrase, err := promptPassword()
if err != nil { if err != nil {
slog.Error("failed reading passphrase") return fmt.Errorf("failed reading passphrase: %w", err)
return err
} }
key := s.DeriveKey(passphrase)
// TODO: test key before storing err = validatePassphrase(s, passphrase)
err = wf.Keychain.Set(keychainAccount, string(key))
if err != nil { if err != nil {
slog.Error("failed storing passphrase key in keychain") return fmt.Errorf("failed validating passphrase: %w", err)
return err
} }
err = wf.Keychain.Set(keychainAccount, passphrase)
if err != nil {
return fmt.Errorf("failed storing passphrase in keychain: %w", err)
}
return nil
}
func sendResult(result string, args ...string) error {
results := aw.NewArgVars()
results.Arg(args...)
results.Var("result", result)
return results.Send()
}
func validatePassphrase(s *ykoath.Select, passphrase string) error {
key := s.DeriveKey(passphrase)
// verify password is correct with a validate call
ok, err := oath.Validate(s, key)
if err != nil {
return fmt.Errorf("error in validate: %w", err)
}
if !ok {
return errIncorrectPassword
}
return nil return nil
} }
func run() { func run() {
runScript := flag.Bool("run-script", false, "change output to script output")
wf.Args() wf.Args()
flag.Parse() flag.Parse()
if *runScript {
wf.Configure(aw.TextErrors(true))
}
var err error var err error
oath, err = ykoath.New() oath, err = ykoath.New()
if err != nil { if err != nil {
slog.Error("failed to iniatialize new oath: %v", err) wf.FatalError(fmt.Errorf("failed to iniatialize new oath: %w", err))
wf.FatalError(err)
} }
defer oath.Close() defer oath.Close()
oath.Debug = slog.Debug oath.Debug = slog.Debug
// Select oath to begin // Select oath to begin
s, err := oath.Select() s, err := oath.Select()
if err != nil { if err != nil {
slog.Error("failed to select oath: %v", err) wf.FatalError(fmt.Errorf("failed to select oath: %w", err))
wf.FatalError(err)
} }
// Check to see if we are trying to set a password // Check to see if we are trying to set a password
if flag.Arg(0) == "set-password" { if flag.Arg(0) == "set-password" {
err = setPassword(s) err = setPassword(s)
if err != nil { if err != nil {
wf.FatalError(err) wf.FatalError(fmt.Errorf("failed to set password: %w", err))
} }
if err = sendResult("success"); err != nil {
wf.FatalError(fmt.Errorf("failed to send password set result: %w", err))
}
return return
} }
// If required, authenticate with password from keychain // If required, authenticate with password from keychain
if s.Challenge != nil { if s.Challenge != nil {
key, err := wf.Keychain.Get(keychainAccount) passphrase, err := wf.Keychain.Get(keychainAccount)
if err != nil { if err != nil {
slog.Error("no key found in keychain but password is required") slog.Error("no key found in keychain but password is required")
wf.NewWarningItem("No password set", "↵ to set password"). wf.NewWarningItem("No password set", "↵ to set password").
Var("action", "set-password"). Var("action", "set-password").
Valid(true) Valid(true)
wf.SendFeedback() wf.SendFeedback()
return return
} }
ok, err := oath.Validate(s, []byte(key)) err = validatePassphrase(s, passphrase)
slog.FatalOnErr(err, "validation failed") if err != nil {
if !ok { wf.FatalError(fmt.Errorf("passphrase failed: %w", err))
panic("could not validate")
} }
} }
if flag.Arg(0) == "list" { if flag.Arg(0) == "list" {
// List names only // List names only
names, err := oath.List() names, err := oath.List()
slog.FatalOnErr(err, "failed to list names") if err != nil {
wf.FatalError(fmt.Errorf("failed to list names: %w", err))
}
for _, name := range names { for _, name := range names {
slog.Log(name.Name) slog.Log(name.Name)
wf.NewItem(name.Name). wf.NewItem(name.Name).
Icon(aw.IconAccount).
Subtitle("Copy to clipboard").
Arg(name.Name).
Valid(true) Valid(true)
} }
} else { } else {
// Default execution is to calculate all codes and return them in list name := flag.Arg(0)
creds, err := oath.CalculateAll()
code, err := oath.CalculateOne(name)
if err != nil { if err != nil {
slog.Error("failed to calculate all") // TODO: Check for error "requires-auth" and notify touch
wf.FatalError(err) wf.FatalError(fmt.Errorf("failed to generate code: %w", err))
} }
for cred, code := range creds { slog.Log(code)
slog.Log(cred)
wf.NewItem(cred). if err = sendResult("success", code); err != nil {
Icon(aw.IconAccount). wf.FatalError(fmt.Errorf("failed to send code: %w", err))
Subtitle("Copy to clipboard").
Arg(code).
Copytext(code).
Valid(true)
} }
} }
if !*runScript {
wf.SendFeedback() wf.SendFeedback()
}
} }

2
ykoath

@ -1 +1 @@
Subproject commit 0bb0699e51d3672572cc7869397eeff871bdf45e Subproject commit fd081cb213d030585bfdd03305e03bff4d6e7a09