in aws_signing_helper/signer.go [164:252]
func PasswordPrompt(passwordPromptInput PasswordPromptProps) (string, interface{}, error) {
var (
err error
ttyReadPath string
ttyWritePath string
ttyReadFile *os.File
ttyWriteFile *os.File
parseErrMsg string
prompt string
reprompt string
password string
incorrectPasswordMsg string
checkPasswordAuthorizationErrorMsg string
checkPassword func(string) (interface{}, error)
checkPasswordResult interface{}
noPassword bool
)
password = passwordPromptInput.InitialPassword
noPassword = passwordPromptInput.NoPassword
incorrectPasswordMsg = passwordPromptInput.IncorrectPasswordMsg
prompt = passwordPromptInput.Prompt
reprompt = passwordPromptInput.Reprompt
parseErrMsg = passwordPromptInput.ParseErrMsg
checkPassword = passwordPromptInput.CheckPassword
checkPasswordAuthorizationErrorMsg = passwordPromptInput.CheckPasswordAuthorizationErrorMsg
ttyReadPath = "/dev/tty"
ttyWritePath = ttyReadPath
if runtime.GOOS == "windows" {
ttyReadPath = "CONIN$"
ttyWritePath = "CONOUT$"
}
// If no password is required
if noPassword {
checkPasswordResult, err = checkPassword("")
if err != nil {
return "", nil, err
}
return "", checkPasswordResult, nil
}
// If the password was provided explicitly, beforehand
if password != "" {
checkPasswordResult, err = checkPassword(password)
if err != nil {
return "", nil, errors.New(incorrectPasswordMsg)
}
return password, checkPasswordResult, nil
}
ttyReadFile, err = os.OpenFile(ttyReadPath, os.O_RDWR, 0)
if err != nil {
return "", nil, errors.New(parseErrMsg)
}
defer ttyReadFile.Close()
ttyWriteFile, err = os.OpenFile(ttyWritePath, os.O_WRONLY, 0)
if err != nil {
return "", nil, errors.New(parseErrMsg)
}
defer ttyWriteFile.Close()
// The key has a password, so prompt for it
password, err = GetPassword(ttyReadFile, ttyWriteFile, prompt, parseErrMsg)
if err != nil {
return "", nil, err
}
checkPasswordResult, err = checkPassword(password)
for true {
// If we've found the right password, return both it and the result of `checkPassword`
if err == nil {
return password, checkPasswordResult, nil
}
// Otherwise, if the password was incorrect, prompt for it again
if strings.Contains(err.Error(), checkPasswordAuthorizationErrorMsg) {
password, err = GetPassword(ttyReadFile, ttyWriteFile, reprompt, parseErrMsg)
if err != nil {
return "", nil, err
}
checkPasswordResult, err = checkPassword(password)
continue
}
return "", nil, err
}
return "", nil, err
}