本文整理汇总了Golang中golang.org/x/crypto/ssh.ConnMetadata.RemoteAddr方法的典型用法代码示例。如果您正苦于以下问题:Golang ConnMetadata.RemoteAddr方法的具体用法?Golang ConnMetadata.RemoteAddr怎么用?Golang ConnMetadata.RemoteAddr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类golang.org/x/crypto/ssh.ConnMetadata
的用法示例。
在下文中一共展示了ConnMetadata.RemoteAddr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: pubkeyAuthCallback
func pubkeyAuthCallback(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) {
keyring.RLock()
defer keyring.RUnlock()
if keyring.Keys == nil {
log.Println("rejecting authentication due to missing keyring")
return nil, errors.New("no keyring available")
}
var keyFound *BenutzerDBKeyHandle
for _, k := range *keyring.Keys {
if k.ParsedPublicKey == nil {
continue
} else if bytes.Compare(key.Marshal(), k.ParsedPublicKey.Marshal()) == 0 {
keyFound = &k
break
}
}
if keyFound == nil {
log.Println("could not authenticate", conn.RemoteAddr().String(), " no key found")
return nil, errors.New("invalid authentication")
}
log.Println("accepted key for user:", keyFound.Handle)
return &ssh.Permissions{Extensions: map[string]string{"user_id": keyFound.Handle}}, nil
}
示例2: keyAuth
func keyAuth(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) {
log.Printf("(keyAuth) >> New client conn from '%s' authenticating with '%s'\n", conn.RemoteAddr(), key.Type())
// Check if the user is allowed to connect at all (meaning: the must be a subdirectory in the 'data' dir
// matching the provided SSH username).
authorizedPubKey, err := getPubKeyForUser(conn.User())
if err != nil {
return nil, fmt.Errorf("(keyAuth) >> No pub key for user '%s' found / user not allowed to connect.", conn.User())
}
fpProvidedPubKey, err := pubKeyFingerprint(key)
if err != nil {
log.Printf("(keyAuth) >> Error: Unable to create fingerprint for provided PubKey: %s\n", err.Error())
}
log.Printf("(keyAuth) >> Fingerprint of provided PubKey : %s\n", fpProvidedPubKey)
fpAuthorizedPubKey, err := pubKeyFingerprint(authorizedPubKey)
if err != nil {
log.Printf("(keyAuth) >> Error: Unable to create fingerprint for authorized PubKey: %s\n", err.Error())
}
log.Printf("(keyAuth) >> Fingerprint of authorized PubKey: %s\n", fpAuthorizedPubKey)
// Check if username and Public Key combination is allowed to establish a connection.
if theseTwoPublicKeysAreEqual(key, authorizedPubKey) {
log.Printf("(keyAuth) >> Correct username '%s' and public key provided.", conn.User())
// Signaling success / authentication passed.
return nil, nil
}
log.Printf("(keyAuth) >> Wrong username '%s' and/or public key provided.", conn.User())
return nil, fmt.Errorf("Wrong username and/or public key.")
}
示例3: closeConn
func closeConn(conn ssh.ConnMetadata) error {
Lock.Lock()
defer Lock.Unlock()
defer delete(MetaData, conn.RemoteAddr())
logs.Debug("Clean sessions")
return nil
}
示例4: getClient
func getClient(conn ssh.ConnMetadata) (*ssh.Client, error) {
Lock.RLock()
defer Lock.RUnlock()
meta := MetaData[conn.RemoteAddr()]
logs.Debug("Connection accepted from", conn.RemoteAddr())
return meta.Client, nil
}
示例5: parseIpPortFrom
func parseIpPortFrom(conn ssh.ConnMetadata) (string, int) {
remote := strings.Split(conn.RemoteAddr().String(), ":")
port, err := strconv.Atoi(remote[1])
if err != nil {
port = 0
}
return remote[0], port
}
示例6: 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
}
示例7: 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(),
)
}
示例8: 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
}
示例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: 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
}
示例11: 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
}
示例12: authLogCallback
func (sshClient *sshClient) authLogCallback(conn ssh.ConnMetadata, method string, err error) {
if err != nil {
if sshClient.sshServer.config.UseFail2Ban() {
clientIPAddress := psiphon.IPAddressFromAddr(conn.RemoteAddr())
if clientIPAddress != "" {
LogFail2Ban(clientIPAddress)
}
}
log.WithContextFields(LogFields{"error": err, "method": method}).Warning("authentication failed")
} else {
log.WithContextFields(LogFields{"error": err, "method": method}).Info("authentication success")
}
}
示例13: AuthSCPPassword
// SCP Password authentication check
func (a authDB) AuthSCPPassword(cmd ssh.ConnMetadata, pass []byte) (*ssh.Permissions, error) {
// Get the client
c := a.findClient(cmd.RemoteAddr().String())
if c == nil {
return nil, fmt.Errorf("Unknown host %s", cmd.RemoteAddr().String())
}
// Check Password
if string(pass) == c.Protocols.SCP.Password {
return nil, nil
}
return nil, fmt.Errorf("Authencation failed")
}
示例14: 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
}
示例15: keyAuth
func keyAuth(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) {
log.Println(conn.RemoteAddr(), "authenticate with", key.Type(), "for user", conn.User())
log.Println(base64.StdEncoding.EncodeToString(key.Marshal()))
if isValidToken(conn.User()) {
authRequestMap.Lock()
authRequestMap.matches[conn.User()] = key.Type() + " " + base64.StdEncoding.EncodeToString(key.Marshal())
authRequestMap.timestamps[conn.User()] = time.Now()
authRequestMap.Unlock()
return nil, nil
}
//Causes "Permission denied (publickey)." for openssh. How can this bubble up to the user?
return nil, errors.New("Invalid token/username.")
}