github.com/deis/deis@v1.13.5-0.20170519182049-1d9e59fbdbfc/Godeps/_workspace/src/golang.org/x/crypto/ssh/test/cert_test.go (about)

     1  // Copyright 2014 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // +build darwin dragonfly freebsd linux netbsd openbsd
     6  
     7  package test
     8  
     9  import (
    10  	"crypto/rand"
    11  	"testing"
    12  
    13  	"golang.org/x/crypto/ssh"
    14  )
    15  
    16  func TestCertLogin(t *testing.T) {
    17  	s := newServer(t)
    18  	defer s.Shutdown()
    19  
    20  	// Use a key different from the default.
    21  	clientKey := testSigners["dsa"]
    22  	caAuthKey := testSigners["ecdsa"]
    23  	cert := &ssh.Certificate{
    24  		Key:             clientKey.PublicKey(),
    25  		ValidPrincipals: []string{username()},
    26  		CertType:        ssh.UserCert,
    27  		ValidBefore:     ssh.CertTimeInfinity,
    28  	}
    29  	if err := cert.SignCert(rand.Reader, caAuthKey); err != nil {
    30  		t.Fatalf("SetSignature: %v", err)
    31  	}
    32  
    33  	certSigner, err := ssh.NewCertSigner(cert, clientKey)
    34  	if err != nil {
    35  		t.Fatalf("NewCertSigner: %v", err)
    36  	}
    37  
    38  	conf := &ssh.ClientConfig{
    39  		User: username(),
    40  	}
    41  	conf.Auth = append(conf.Auth, ssh.PublicKeys(certSigner))
    42  	client, err := s.TryDial(conf)
    43  	if err != nil {
    44  		t.Fatalf("TryDial: %v", err)
    45  	}
    46  	client.Close()
    47  }