本文整理汇总了Golang中golang.org/x/crypto/ssh.ConnMetadata.User方法的典型用法代码示例。如果您正苦于以下问题:Golang ConnMetadata.User方法的具体用法?Golang ConnMetadata.User怎么用?Golang ConnMetadata.User使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类golang.org/x/crypto/ssh.ConnMetadata
的用法示例。
在下文中一共展示了ConnMetadata.User方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Authenticate
func (dpa *DiegoProxyAuthenticator) Authenticate(metadata ssh.ConnMetadata, password []byte) (*ssh.Permissions, error) {
logger := dpa.logger.Session("authenticate")
logger.Info("authentication-starting")
defer logger.Info("authentication-finished")
if !DiegoUserRegex.MatchString(metadata.User()) {
logger.Error("regex-match-fail", InvalidDomainErr)
return nil, InvalidDomainErr
}
if !bytes.Equal(dpa.receptorCreds, password) {
logger.Error("invalid-credentials", InvalidCredentialsErr)
return nil, InvalidCredentialsErr
}
guidAndIndex := DiegoUserRegex.FindStringSubmatch(metadata.User())
processGuid := guidAndIndex[1]
index, err := strconv.Atoi(guidAndIndex[2])
if err != nil {
logger.Error("atoi-failed", err)
return nil, err
}
permissions, err := sshPermissionsFromProcess(processGuid, index, dpa.receptorClient, metadata.RemoteAddr())
if err != nil {
logger.Error("building-ssh-permissions-failed", err)
}
return permissions, err
}
示例2: Authenticate
func (cfa *CFAuthenticator) Authenticate(metadata ssh.ConnMetadata, password []byte) (*ssh.Permissions, error) {
logger := cfa.logger.Session("authenticate")
if !CFRealmRegex.Match([]byte(metadata.User())) {
return nil, InvalidDomainErr
}
principal := CFRealmRegex.FindStringSubmatch(metadata.User())[1]
if !CFPrincipalRegex.Match([]byte(principal)) {
return nil, InvalidCredentialsErr
}
guidAndIndex := CFPrincipalRegex.FindStringSubmatch(principal)
index, err := strconv.Atoi(guidAndIndex[2])
if err != nil {
logger.Error("atoi-failed", err)
return nil, InvalidCredentialsErr
}
appGuid := guidAndIndex[1]
path := fmt.Sprintf("%s/internal/apps/%s/ssh_access", cfa.ccURL, appGuid)
req, err := http.NewRequest("GET", path, nil)
if err != nil {
logger.Error("creating-request-failed", InvalidRequestErr)
return nil, InvalidRequestErr
}
req.Header.Add("Authorization", string(password))
resp, err := cfa.ccClient.Do(req)
if err != nil {
logger.Error("fetching-app-failed", err)
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
logger.Error("fetching-app-failed", FetchAppFailedErr, lager.Data{
"StatusCode": resp.Status,
"ResponseBody": resp.Body,
})
return nil, FetchAppFailedErr
}
var app AppSSHResponse
err = json.NewDecoder(resp.Body).Decode(&app)
if err != nil {
logger.Error("invalid-cc-response", err)
return nil, InvalidCCResponse
}
permissions, err := sshPermissionsFromProcess(app.ProcessGuid, index, cfa.receptorClient, metadata.RemoteAddr())
if err != nil {
logger.Error("building-ssh-permissions-failed", err)
}
return permissions, err
}
示例3: Authenticate
func (a *CompositeAuthenticator) Authenticate(metadata ssh.ConnMetadata, password []byte) (*ssh.Permissions, error) {
if parts := strings.SplitN(metadata.User(), ":", 2); len(parts) == 2 {
authenticator := a.authenticatorMap[parts[0]]
if authenticator != nil {
return authenticator.Authenticate(metadata, password)
}
}
return nil, InvalidCredentialsErr
}
示例4: Authenticate
func (a *CompositeAuthenticator) Authenticate(metadata ssh.ConnMetadata, password []byte) (*ssh.Permissions, error) {
for userRegexp, authenticator := range a.authenticators {
if userRegexp.MatchString(metadata.User()) {
return authenticator.Authenticate(metadata, password)
}
}
return nil, InvalidCredentialsErr
}
示例5: ci
/* ci returns a string containing info from an ssh.ConnMetadata */
func ci(m ssh.ConnMetadata) string {
return fmt.Sprintf(
"Address:%v Target:%v Version:%q User:%q",
m.RemoteAddr(),
victimName(m),
m.ClientVersion(),
m.User(),
)
}
示例6: authPassword
// authPassword records any incoming request trying to auth with a username/password
func authPassword(conn ssh.ConnMetadata, password []byte) (*ssh.Permissions, error) {
log.Printf("sshPass: %s %s %s\n",
conn.RemoteAddr().String(),
conn.User(),
strconv.QuoteToASCII(string(password)))
return nil, errAuthenticationFailed
}
示例7: baseAlertMap
func baseAlertMap(metadata ssh.ConnMetadata) map[string]string {
meta := make(map[string]string)
meta["service"] = "ssh"
meta["user"] = metadata.User()
meta["remote"] = metadata.RemoteAddr().String()
meta["local"] = metadata.LocalAddr().String()
return meta
}
示例8: PublicKeyCallback
func (s *Server) PublicKeyCallback(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) {
s.mu.Lock()
si := s.sessionInfo[string(conn.SessionID())]
si.User = conn.User()
si.Keys = append(si.Keys, key)
s.sessionInfo[string(conn.SessionID())] = si
s.mu.Unlock()
// Never succeed a key, or we might not see the next. See KeyboardInteractiveCallback.
return nil, errors.New("")
}
示例9: logAttempt
/* logAttempt logs an authorization attempt. */
func logAttempt(conn ssh.ConnMetadata, method, cred string, suc bool) {
log.Printf(
"Address:%v Authorization Attempt Version:%q User:%q %v:%q "+
"Successful:%v",
conn.RemoteAddr(),
string(conn.ClientVersion()),
conn.User(),
method,
cred,
suc,
)
}
示例10: Auth
func (s ScriptPassAuth) Auth(conn ssh.ConnMetadata, password []byte) (*ssh.Permissions, error) {
cmd := exec.Command(config.PassAuthLocation, conn.User(), conn.RemoteAddr().String())
passReader := bytes.NewReader(password)
cmd.Stdin = passReader
output, err := cmd.CombinedOutput()
if err != nil {
config.Log.Error("password authentication: %s\n%v", output, err)
return nil, err
}
// nil permissions is success?
return nil, nil
}
示例11: authKey
// authKey records any incoming request trying to auth with an ssh key
func authKey(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) {
h := sha256.New()
h.Write(key.Marshal())
sum := h.Sum(nil)
log.Printf("sshkey: %s %s %s %s\n",
conn.RemoteAddr().String(),
conn.User(),
key.Type(),
base64.StdEncoding.EncodeToString(sum))
return nil, errAuthenticationFailed
}
示例12: passwordCallback
func passwordCallback(conn ssh.ConnMetadata, password []byte) (perm *ssh.Permissions, err error) {
if conn.User() == "jonny.quest" && string(password) == "bandit" {
// Add username to permissions
perm = &ssh.Permissions{
Extensions: map[string]string{
"username": conn.User(),
},
}
} else {
err = fmt.Errorf("Invalid username or password")
}
return
}
示例13: passAuthCallback
func passAuthCallback(conn ssh.ConnMetadata, password []byte) (*ssh.Permissions, error) {
guid := uuid.NewV4()
ip, remotePort := parseIpPortFrom(conn)
login := SshLogin{RemoteAddr: ip,
RemotePort: remotePort,
Username: conn.User(),
Password: string(password),
Guid: guid.String(),
Version: string(conn.ClientVersion()),
LoginType: "password",
}
login.Save()
return &ssh.Permissions{Extensions: map[string]string{"guid": guid.String()}}, nil
}
示例14: authUser
func (s *Server) authUser(c ssh.ConnMetadata, pass []byte) (*ssh.Permissions, error) {
// no auth - allow all
if len(s.Users) == 0 {
return nil, nil
}
// authenticate user
n := c.User()
u, ok := s.Users[n]
if !ok || u.Pass != string(pass) {
s.Debugf("Login failed: %s", n)
return nil, errors.New("Invalid auth")
}
//insert session
s.sessions[string(c.SessionID())] = u
return nil, nil
}
示例15: authPassword
// authPassword records any incoming request trying to auth with a username/password
func authPassword(conn ssh.ConnMetadata, password []byte) (*ssh.Permissions, error) {
r := &AuthEvent{
Time: fmt.Sprintf("%d", time.Now().Unix()),
AuthType: "sshPass",
SrcIP: strings.Split(conn.RemoteAddr().String(), ":")[0],
DestIP: extIP,
User: conn.User(),
TypeData: fmt.Sprintf("client-version: %s", strconv.QuoteToASCII(string(conn.ClientVersion()))),
Credentials: strconv.QuoteToASCII(string(password)),
}
addToBatch(r)
return nil, errAuthenticationFailed
}