blob: bc83e4f5df4589cb3d4053d732259461dc0f97cb [file] [log] [blame]
Adam Langleyfa50e742014-04-09 13:57:52 -07001// 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
Mikio Haraf8eacb92014-05-05 12:10:24 -07005// +build darwin dragonfly freebsd linux netbsd openbsd
Adam Langleyfa50e742014-04-09 13:57:52 -07006
7package test
8
9import (
10 "crypto/rand"
11 "testing"
12
Andrew Gerranda73c6bb2014-11-10 08:50:25 +110013 "golang.org/x/crypto/ssh"
Adam Langleyfa50e742014-04-09 13:57:52 -070014)
15
16func 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{
Han-Wen Nienhuyse4e27992017-03-29 19:21:25 +020039 User: username(),
40 HostKeyCallback: ssh.InsecureIgnoreHostKey(),
Adam Langleyfa50e742014-04-09 13:57:52 -070041 }
42 conf.Auth = append(conf.Auth, ssh.PublicKeys(certSigner))
43 client, err := s.TryDial(conf)
44 if err != nil {
45 t.Fatalf("TryDial: %v", err)
46 }
47 client.Close()
48}