(p []byte)
| 458 | } |
| 459 | |
| 460 | func (w *codeTypingWriter) Write(p []byte) (int, error) { |
| 461 | n, _ := w.buf.Write(p) |
| 462 | if strings.Contains(string(p), "Password: ") { |
| 463 | go func() { _, _ = w.pw.Write([]byte(twoFAPassword + "\n")) }() |
| 464 | } |
| 465 | if strings.Contains(string(p), "Code from the app: ") { |
| 466 | w.prompts++ |
| 467 | m := secretLine.FindStringSubmatch(w.buf.String()) |
| 468 | code := "000000" |
| 469 | if m != nil { |
| 470 | if c, err := totp.GenerateCode(m[1], time.Now()); err == nil { |
| 471 | code = c |
| 472 | } |
| 473 | } |
| 474 | if w.prompts <= w.wrongFirst { |
| 475 | code = wrongCode(code) |
| 476 | } |
| 477 | go func() { _, _ = w.pw.Write([]byte(code + "\n")) }() |
| 478 | } |
| 479 | return n, nil |
| 480 | } |
| 481 | |
| 482 | // wrongCode changes a code's first digit, so it can never be the valid one. |
| 483 | func wrongCode(code string) string { |
no test coverage detected