Update Go library to last weekly.
[platform/upstream/gcc.git] / libgo / go / exp / ssh / doc.go
1 // Copyright 2011 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 /*
6 Package ssh implements an SSH server.
7
8 SSH is a transport security protocol, an authentication protocol and a
9 family of application protocols. The most typical application level
10 protocol is a remote shell and this is specifically implemented.  However,
11 the multiplexed nature of SSH is exposed to users that wish to support
12 others.
13
14 An SSH server is represented by a Server, which manages a number of
15 ServerConnections and handles authentication.
16
17         var s Server
18         s.PubKeyCallback = pubKeyAuth
19         s.PasswordCallback = passwordAuth
20
21         pemBytes, err := ioutil.ReadFile("id_rsa")
22         if err != nil {
23                 panic("Failed to load private key")
24         }
25         err = s.SetRSAPrivateKey(pemBytes)
26         if err != nil {
27                 panic("Failed to parse private key")
28         }
29
30 Once a Server has been set up, connections can be attached.
31
32         var sConn ServerConnection
33         sConn.Server = &s
34         err = sConn.Handshake(conn)
35         if err != nil {
36                 panic("failed to handshake")
37         }
38
39 An SSH connection multiplexes several channels, which must be accepted themselves:
40
41
42         for {
43                 channel, err := sConn.Accept()
44                 if err != nil {
45                         panic("error from Accept")
46                 }
47
48                 ...
49         }
50
51 Accept reads from the connection, demultiplexes packets to their corresponding
52 channels and returns when a new channel request is seen. Some goroutine must
53 always be calling Accept; otherwise no messages will be forwarded to the
54 channels.
55
56 Channels have a type, depending on the application level protocol intended. In
57 the case of a shell, the type is "session" and ServerShell may be used to
58 present a simple terminal interface.
59
60         if channel.ChannelType() != "session" {
61                 c.Reject(UnknownChannelType, "unknown channel type")
62                 return
63         }
64         channel.Accept()
65
66         shell := NewServerShell(channel, "> ")
67         go func() {
68                 defer channel.Close()
69                 for {
70                         line, err := shell.ReadLine()
71                         if err != nil {
72                                 break
73                         }
74                         println(line)
75                 }
76                 return
77         }()
78 */
79 package ssh