Skip to content

Commit 7704e3c

Browse files
authored
Merge pull request #29 from aripalo/fix/yubikey-without-password
Fix: Yubikey without Password
2 parents 6ba4b7c + 285b782 commit 7704e3c

File tree

9 files changed

+29
-21
lines changed

9 files changed

+29
-21
lines changed

internal/app/assume.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (a *App) Assume(flags AssumeFlags) error {
5858
// Catch timeout error and return a cleaner error message.
5959
if err != nil {
6060
if errors.Is(err, context.DeadlineExceeded) {
61-
msg.Fatal(fmt.Sprintf("Operation Timeout"))
61+
msg.Fatal("Operation Timeout")
6262
}
6363
msg.Fatal(fmt.Sprintf("Credentials: STS: %s", err))
6464
}

internal/app/version_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestVersion(t *testing.T) {
3838
a := &App{dest: &output}
3939
err := a.Version(test.input)
4040
require.NoError(t, err)
41-
actual := string(output.Bytes())
41+
actual := output.String()
4242
assert.Equal(t, test.expected, actual)
4343
})
4444
}

internal/credentials/cache.go

-10
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,3 @@ func (c *Credentials) readFromCache() error {
6565

6666
return nil
6767
}
68-
69-
// DeleteFromCache deletes the cached response cache database
70-
func (c *Credentials) deleteFromCache() error {
71-
key, err := resolveKey(c.cfg.ProfileName, c.cfg.Checksum)
72-
if err != nil {
73-
return err
74-
}
75-
76-
return c.repo.Delete(key)
77-
}

internal/multinput/multinput.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package multinput
22

33
import (
44
"context"
5-
"time"
65
)
76

87
// Identifier for a single resolver.
@@ -17,7 +16,6 @@ type Result struct {
1716

1817
// Multinput models the configuration/state.
1918
type Multinput struct {
20-
timeout time.Duration
2119
results chan *Result
2220
resolvers []InputResolver
2321
}
@@ -33,8 +31,8 @@ func New(resolvers []InputResolver) Multinput {
3331
}
3432
}
3533

36-
// Provide runs the given resolvers and will keep waitig for first
37-
// non-empty value until timeout reached.
34+
// Provide runs the given resolvers and will keep waiting for first
35+
// non-empty value until timeout (defined by ctx) reached.
3836
func (m *Multinput) Provide(ctx context.Context) (*Result, error) {
3937

4038
// loop through all given resolvers, run them as goroutines and

internal/tmpl/write_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func TestWrite(t *testing.T) {
6363
t.Run(name, func(t *testing.T) {
6464
var output bytes.Buffer
6565
err := Write(&output, "test", test.template, test.input)
66-
actual := string(output.Bytes())
66+
actual := output.String()
6767
assert.Equal(t, test.err, err)
6868
assert.Equal(t, test.expected, actual)
6969
})

internal/totp/message.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ func formatInputMessage(enableGui bool, enableYubikey bool) string {
2626
if err != nil {
2727
msg.Fatal(err.Error())
2828
}
29-
return string(message.Bytes())
29+
return message.String()
3030
}

internal/totp/totp.go

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ func GetCode(ctx context.Context, options Options) (string, error) {
6060

6161
code := result.Value
6262

63+
msg.Debug("ℹ️", fmt.Sprintf("MFA: Token received: \"%s\"", result.Value))
64+
6365
if !isValidToken(code) {
6466
return code, errors.New("invalid mfa code") // TODO
6567
}

internal/yubikey/setup/setup.go

+15
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ func Setup(options Options, store PasswordStore) error {
3939
ctx, cancel := context.WithCancel(context.Background())
4040
defer cancel()
4141

42+
msg.Debug("🔧", fmt.Sprintf("Yubikey: Device Serial: %s", options.Device))
43+
msg.Debug("🔧", fmt.Sprintf("Yubikey: OATH Account: %s", options.Account))
44+
4245
oathAccounts, err := ykmangoath.New(ctx, options.Device)
4346
if err != nil {
4447
return fmt.Errorf("ykmangoat init: %w", err)
@@ -135,6 +138,16 @@ func stateMachine(state State, op Operation) State {
135138
}
136139
}
137140
msg.Debug("🔓", "Yubikey: OATH application not password protected")
141+
142+
err := op.SetPassword("")
143+
if err != nil {
144+
msg.Warn("⚠️", fmt.Sprintf("Yubikey: Could not configure empty password: %s", err))
145+
return State{
146+
Name: ERROR,
147+
Error: errors.New("yubikey: could not configure empty password"),
148+
}
149+
}
150+
138151
return State{
139152
Name: CHECK_DEVICE_HAS_ACCOUNT,
140153
}
@@ -258,6 +271,7 @@ func stateMachine(state State, op Operation) State {
258271
case CHECK_DEVICE_HAS_ACCOUNT:
259272
has, err := op.HasAccount()
260273
if err != nil {
274+
msg.Debug("ℹ️", fmt.Sprintf("Yubikey: Failed to acquire account: %s", err))
261275
return State{
262276
Name: ERROR,
263277
Error: errors.New("yubikey: could not read accounts"),
@@ -270,6 +284,7 @@ func stateMachine(state State, op Operation) State {
270284
Error: errors.New("yubikey: account not found"),
271285
}
272286
}
287+
msg.Debug("ℹ️", "Yubikey: Account found")
273288
return State{
274289
Name: DONE,
275290
}

internal/yubikey/setup/setup_test.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,12 @@ func TestStateMachine(t *testing.T) {
4444
expected: State{Name: CHECK_DEVICE_PASSWORD_PROTECTED},
4545
},
4646
{
47-
name: "device not password protected",
48-
input: State{Name: CHECK_DEVICE_PASSWORD_PROTECTED},
49-
op: Operation{IsPasswordProtected: func() bool { return false }},
47+
name: "device not password protected",
48+
input: State{Name: CHECK_DEVICE_PASSWORD_PROTECTED},
49+
op: Operation{
50+
IsPasswordProtected: func() bool { return false },
51+
SetPassword: func(string) error { return nil },
52+
},
5053
expected: State{Name: CHECK_DEVICE_HAS_ACCOUNT},
5154
},
5255
{

0 commit comments

Comments
 (0)