當前位置: 首頁>>代碼示例>>Golang>>正文


Golang ssh.ClientConfig類代碼示例

本文整理匯總了Golang中code/google/com/p/go/crypto/ssh.ClientConfig的典型用法代碼示例。如果您正苦於以下問題:Golang ClientConfig類的具體用法?Golang ClientConfig怎麽用?Golang ClientConfig使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ClientConfig類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestOpenRetry

func TestOpenRetry(t *testing.T) {
	c := 0
	rand := new(failReader)
	p := &Pool{Dial: func(net, addr string) (net.Conn, error) {
		c++
		conn := dial(t)
		return conn, nil
	}}
	config := new(ssh.ClientConfig)
	*config = *clientConfig
	config.Rand = rand
	_, err := p.Open("net", "addr", config)
	if err != nil {
		t.Fatal("unexpected error:", err)
	}
	conn := p.tab[p.key("net", "addr", config)].c
	*rand = true
	config.Rand = nil
	_, err = p.Open("net", "addr", config)
	if err != nil {
		t.Fatal("unexpected error:", err)
	}
	if c != 2 {
		t.Fatalf("calls = %d want 2", c)
	}
	const errClosing = "use of closed network connection" // from package net
	if err := conn.Close(); err == nil || err.Error() != errClosing {
		t.Fatalf("conn still open, want closed; err = %v", err)
	}
}
開發者ID:kr,項目名稱:sshpool,代碼行數:30,代碼來源:pool_test.go

示例2: TestAuth

func TestAuth(t *testing.T) {
	a, b, err := netPipe()
	if err != nil {
		t.Fatalf("netPipe: %v", err)
	}

	defer a.Close()
	defer b.Close()

	agent, _, cleanup := startAgent(t)
	defer cleanup()

	if err := agent.Add(testPrivateKeys["rsa"], nil, "comment"); err != nil {
		t.Errorf("Add: %v", err)
	}

	serverConf := ssh.ServerConfig{}
	serverConf.AddHostKey(testSigners["rsa"])
	serverConf.PublicKeyCallback = func(c ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) {
		if bytes.Equal(key.Marshal(), testPublicKeys["rsa"].Marshal()) {
			return nil, nil
		}

		return nil, errors.New("pubkey rejected")
	}

	go func() {
		conn, _, _, err := ssh.NewServerConn(a, &serverConf)
		if err != nil {
			t.Fatalf("Server: %v", err)
		}
		conn.Close()
	}()

	conf := ssh.ClientConfig{}
	conf.Auth = append(conf.Auth, ssh.PublicKeysCallback(agent.Signers))
	conn, _, _, err := ssh.NewClientConn(b, "", &conf)
	if err != nil {
		t.Fatalf("NewClientConn: %v", err)
	}
	conn.Close()
}
開發者ID:nota-ja,項目名稱:cli,代碼行數:42,代碼來源:client_test.go

示例3: sshConfig

func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) {
	config := state.Get("config").(config)
	clientConfig := ssh.ClientConfig{User: config.SSHUsername}
	if config.OsSnapshot == "" && config.IpxeUrl == "" {
		// default case where vultr generated the password
		password := state.Get("default_password").(string)
		clientConfig.Auth = []ssh.AuthMethod{ssh.Password(password)}
	} else if config.SSHPassword != "" {
		// special case but we got a password
		clientConfig.Auth = []ssh.AuthMethod{ssh.Password(config.SSHPassword)}
	} else {
		// special case and we got a key
		signer, err := ssh.ParsePrivateKey([]byte(config.SSHPrivateKey))
		if err != nil {
			return nil, fmt.Errorf("Error setting up SSH config: %s", err)
		}
		clientConfig.Auth = []ssh.AuthMethod{ssh.PublicKeys(signer)}
	}
	return &clientConfig, nil
}
開發者ID:stephencheng,項目名稱:packer-builder-vultr,代碼行數:20,代碼來源:ssh.go

示例4: sshClientConfig

func sshClientConfig(user string, checker *HostKeyChecker) (*gossh.ClientConfig, error) {
	agentClient, err := SSHAgentClient()
	if err != nil {
		return nil, err
	}

	signers, err := agentClient.Signers()
	if err != nil {
		return nil, err
	}

	cfg := gossh.ClientConfig{
		User: user,
		Auth: []gossh.AuthMethod{
			gossh.PublicKeys(signers...),
		},
	}

	if checker != nil {
		cfg.HostKeyCallback = checker.Check
	}

	return &cfg, nil
}
開發者ID:gdestuynder,項目名稱:deis,代碼行數:24,代碼來源:ssh.go


注:本文中的code/google/com/p/go/crypto/ssh.ClientConfig類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。