forked from Versent/saml2aws
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
318cba2
commit 60bea10
Showing
11 changed files
with
1,141 additions
and
1,146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,64 @@ | ||
module github.com/aliyun/saml2alibabacloud | ||
|
||
go 1.13 | ||
go 1.21.0 | ||
|
||
toolchain go1.22.3 | ||
|
||
require ( | ||
github.com/99designs/keyring v0.0.0-20190110203331-82da6802f65f | ||
github.com/AlecAivazis/survey/v2 v2.2.2 | ||
github.com/Azure/go-ntlmssp v0.0.0-20180416175057-4b934ac9dad3 | ||
github.com/PuerkitoBio/goquery v1.5.1 | ||
github.com/99designs/keyring v1.2.2 | ||
github.com/AlecAivazis/survey/v2 v2.3.7 | ||
github.com/Azure/go-ntlmssp v0.0.0-20211209120228-48547f28849e | ||
github.com/PuerkitoBio/goquery v1.9.2 | ||
github.com/alecthomas/kingpin v2.2.6+incompatible | ||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect | ||
github.com/alecthomas/units v0.0.0-20190910110746-680d30ca3117 // indirect | ||
github.com/aliyun/alibaba-cloud-sdk-go v1.61.681 | ||
github.com/aliyun/aliyun-cli v3.0.25+incompatible | ||
github.com/aulanov/go.dbus v0.0.0-20150729231527-25c3068a42a0 // indirect | ||
github.com/avast/retry-go v2.6.0+incompatible | ||
github.com/beevik/etree v1.0.1 | ||
github.com/danieljoos/wincred v1.0.1 | ||
github.com/dvsekhvalnov/jose2go v0.0.0-20170216131308-f21a8cedbbae // indirect | ||
github.com/godbus/dbus v4.1.0+incompatible // indirect | ||
github.com/danieljoos/wincred v1.1.2 | ||
github.com/google/uuid v1.1.1 | ||
github.com/marshallbrekka/go-u2fhost v0.0.0-20200107013215-ad5fdc1986ac | ||
github.com/mitchellh/go-homedir v1.0.0 | ||
github.com/pkg/errors v0.9.1 | ||
github.com/sirupsen/logrus v1.9.3 | ||
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 | ||
github.com/stretchr/testify v1.8.4 | ||
github.com/tidwall/gjson v1.1.1 | ||
golang.org/x/net v0.24.0 | ||
gopkg.in/ini.v1 v1.57.0 | ||
) | ||
|
||
require ( | ||
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect | ||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect | ||
github.com/alecthomas/units v0.0.0-20190910110746-680d30ca3117 // indirect | ||
github.com/andybalholm/cascadia v1.3.2 // indirect | ||
github.com/creack/pty v1.1.20 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/dvsekhvalnov/jose2go v1.5.0 // indirect | ||
github.com/godbus/dbus v4.1.0+incompatible // indirect | ||
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect | ||
github.com/jmespath/go-jmespath v0.4.0 // indirect | ||
github.com/json-iterator/go v1.1.5 // indirect | ||
github.com/karalabe/hid v1.0.0 // indirect | ||
github.com/keybase/go-keychain v0.0.0-20181011010623-f1daa725cce4 // indirect | ||
github.com/kr/pretty v0.1.0 // indirect | ||
github.com/marshallbrekka/go-u2fhost v0.0.0-20200107013215-ad5fdc1986ac | ||
github.com/mitchellh/go-homedir v1.0.0 | ||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect | ||
github.com/kr/text v0.2.0 // indirect | ||
github.com/mattn/go-colorable v0.1.13 // indirect | ||
github.com/mattn/go-isatty v0.0.20 // indirect | ||
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect | ||
github.com/mtibben/percent v0.2.1 // indirect | ||
github.com/onsi/ginkgo v1.14.2 // indirect | ||
github.com/onsi/gomega v1.10.3 // indirect | ||
github.com/pkg/errors v0.9.1 | ||
github.com/sirupsen/logrus v1.6.0 | ||
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 // indirect | ||
github.com/stretchr/objx v0.2.0 // indirect | ||
github.com/stretchr/testify v1.5.1 | ||
github.com/tidwall/gjson v1.1.1 | ||
github.com/stretchr/objx v0.5.0 // indirect | ||
github.com/tidwall/match v1.0.0 // indirect | ||
golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0 | ||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect | ||
gopkg.in/ini.v1 v1.57.0 | ||
golang.org/x/crypto v0.22.0 // indirect | ||
golang.org/x/sys v0.21.0 // indirect | ||
golang.org/x/term v0.19.0 // indirect | ||
golang.org/x/text v0.14.0 // indirect | ||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package prompter | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"io" | ||
"os/exec" | ||
"strings" | ||
"sync" | ||
) | ||
|
||
const ( | ||
defaultPinentryDialog string = "Security token [%s]" | ||
) | ||
|
||
// PinentryRunner is the interface for pinentry to run itself | ||
type PinentryRunner interface { | ||
Run(string) (string, error) | ||
} | ||
|
||
// RealPinentryRunner is the concrete implementation of PinentryRunner | ||
type RealPinentryRunner struct { | ||
PinentryBin string | ||
} | ||
|
||
// PinentryPrompter is a concrete implementation of the Prompter interface. | ||
// It uses the default Cli under the hood, except for RequestSecurityCode, where | ||
// it uses any _pinentry_ binary to capture the security code. | ||
// Its purpose is mainly to capture the TOTP code outside of the TTY, and thus | ||
// making it possible to use TOTP with the credential process. | ||
// https://github.com/Versent/saml2aws#using-saml2aws-as-credential-process | ||
type PinentryPrompter struct { | ||
Runner PinentryRunner | ||
DefaultPrompter Prompter | ||
} | ||
|
||
// NewPinentryPrompter is a factory for PinentryPrompter | ||
func NewPinentryPrompter(bin string) *PinentryPrompter { | ||
return &PinentryPrompter{Runner: NewRealPinentryRunner(bin), DefaultPrompter: NewCli()} | ||
} | ||
|
||
// NewRealPinentryRunner is a factory for RealPinentryRunner | ||
func NewRealPinentryRunner(bin string) *RealPinentryRunner { | ||
return &RealPinentryRunner{PinentryBin: bin} | ||
} | ||
|
||
// RequestSecurityCode for PinentryPrompter is creating a query for pinentry | ||
// and sends it to the pinentry bin. | ||
func (p *PinentryPrompter) RequestSecurityCode(pattern string) (output string) { | ||
commandTemplate := "SETPROMPT %s\nGETPIN\n" | ||
prompt := fmt.Sprintf(defaultPinentryDialog, pattern) | ||
command := fmt.Sprintf(commandTemplate, prompt) | ||
if output, err := p.Runner.Run(command); err != nil { | ||
return "" | ||
} else { | ||
return output | ||
} | ||
} | ||
|
||
// ChooseWithDefault is running the default CLI ChooseWithDefault | ||
func (p *PinentryPrompter) ChooseWithDefault(prompt string, def string, choices []string) (string, error) { | ||
return p.DefaultPrompter.ChooseWithDefault(prompt, def, choices) | ||
} | ||
|
||
// Choose is running the default CLI Choose | ||
func (p *PinentryPrompter) Choose(pr string, options []string) int { | ||
return p.DefaultPrompter.Choose(pr, options) | ||
} | ||
|
||
// StringRequired is runniner the default Cli StringRequired | ||
func (p *PinentryPrompter) StringRequired(pr string) string { | ||
return p.DefaultPrompter.StringRequired(pr) | ||
} | ||
|
||
// String is runniner the default Cli String | ||
func (p *PinentryPrompter) String(pr string, defaultValue string) string { | ||
return p.DefaultPrompter.String(pr, defaultValue) | ||
} | ||
|
||
// Password is runniner the default Cli Password | ||
func (p *PinentryPrompter) Password(pr string) string { | ||
return p.DefaultPrompter.Password(pr) | ||
} | ||
|
||
// Display is runniner the default Cli Display | ||
func (p *PinentryPrompter) Display(pr string) { | ||
p.DefaultPrompter.Display(pr) | ||
} | ||
|
||
// Run wraps a pinentry run. It sends the query to pinentry via stdin and | ||
// reads its stdout to determine the user PIN. | ||
// Pinentry uses an Assuan protocol | ||
func (r *RealPinentryRunner) Run(command string) (output string, err error) { | ||
cmd := exec.Command(r.PinentryBin, "--ttyname", "/dev/tty") | ||
cmd.Stdin = strings.NewReader(command) | ||
out, _ := cmd.StdoutPipe() | ||
|
||
wg := sync.WaitGroup{} | ||
wg.Add(1) | ||
go func() { | ||
err = cmd.Run() | ||
// fmt.Println(err) | ||
wg.Done() | ||
}() | ||
|
||
output, err = ParseResults(out) | ||
wg.Wait() | ||
return output, err | ||
} | ||
|
||
// ParseResults parses the standard output of the pinentry command and determine the | ||
// user input, or wheter the program yielded any error | ||
func ParseResults(pinEntryOutput io.Reader) (output string, err error) { | ||
scanner := bufio.NewScanner(pinEntryOutput) | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
// fmt.Println(line) | ||
if strings.HasPrefix(line, "D ") { | ||
output = line[2:] | ||
} | ||
if strings.HasPrefix(line, "ERR ") { | ||
return "", fmt.Errorf("Error while running pinentry: %s", line[4:]) | ||
} | ||
} | ||
|
||
return output, err | ||
} |
Oops, something went wrong.