server.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  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. package ssh
  5. import (
  6. "bytes"
  7. "crypto/rand"
  8. "encoding/binary"
  9. "errors"
  10. "fmt"
  11. "io"
  12. "net"
  13. "sync"
  14. _ "crypto/sha1"
  15. )
  16. type ServerConfig struct {
  17. hostKeys []Signer
  18. // Rand provides the source of entropy for key exchange. If Rand is
  19. // nil, the cryptographic random reader in package crypto/rand will
  20. // be used.
  21. Rand io.Reader
  22. // NoClientAuth is true if clients are allowed to connect without
  23. // authenticating.
  24. NoClientAuth bool
  25. // PasswordCallback, if non-nil, is called when a user attempts to
  26. // authenticate using a password. It may be called concurrently from
  27. // several goroutines.
  28. PasswordCallback func(conn *ServerConn, user, password string) bool
  29. // PublicKeyCallback, if non-nil, is called when a client attempts public
  30. // key authentication. It must return true iff the given public key is
  31. // valid for the given user.
  32. PublicKeyCallback func(conn *ServerConn, user, algo string, pubkey []byte) bool
  33. // KeyboardInteractiveCallback, if non-nil, is called when
  34. // keyboard-interactive authentication is selected (RFC
  35. // 4256). The client object's Challenge function should be
  36. // used to query the user. The callback may offer multiple
  37. // Challenge rounds. To avoid information leaks, the client
  38. // should be presented a challenge even if the user is
  39. // unknown.
  40. KeyboardInteractiveCallback func(conn *ServerConn, user string, client ClientKeyboardInteractive) bool
  41. // Cryptographic-related configuration.
  42. Crypto CryptoConfig
  43. }
  44. func (c *ServerConfig) rand() io.Reader {
  45. if c.Rand == nil {
  46. return rand.Reader
  47. }
  48. return c.Rand
  49. }
  50. // AddHostKey adds a private key as a host key. If an existing host
  51. // key exists with the same algorithm, it is overwritten.
  52. func (s *ServerConfig) AddHostKey(key Signer) {
  53. for i, k := range s.hostKeys {
  54. if k.PublicKey().PublicKeyAlgo() == key.PublicKey().PublicKeyAlgo() {
  55. s.hostKeys[i] = key
  56. return
  57. }
  58. }
  59. s.hostKeys = append(s.hostKeys, key)
  60. }
  61. // SetRSAPrivateKey sets the private key for a Server. A Server must have a
  62. // private key configured in order to accept connections. The private key must
  63. // be in the form of a PEM encoded, PKCS#1, RSA private key. The file "id_rsa"
  64. // typically contains such a key.
  65. func (s *ServerConfig) SetRSAPrivateKey(pemBytes []byte) error {
  66. priv, err := ParsePrivateKey(pemBytes)
  67. if err != nil {
  68. return err
  69. }
  70. s.AddHostKey(priv)
  71. return nil
  72. }
  73. // cachedPubKey contains the results of querying whether a public key is
  74. // acceptable for a user. The cache only applies to a single ServerConn.
  75. type cachedPubKey struct {
  76. user, algo string
  77. pubKey []byte
  78. result bool
  79. }
  80. const maxCachedPubKeys = 16
  81. // A ServerConn represents an incoming connection.
  82. type ServerConn struct {
  83. *transport
  84. config *ServerConfig
  85. channels map[uint32]*serverChan
  86. nextChanId uint32
  87. // lock protects err and channels.
  88. lock sync.Mutex
  89. err error
  90. // cachedPubKeys contains the cache results of tests for public keys.
  91. // Since SSH clients will query whether a public key is acceptable
  92. // before attempting to authenticate with it, we end up with duplicate
  93. // queries for public key validity.
  94. cachedPubKeys []cachedPubKey
  95. // User holds the successfully authenticated user name.
  96. // It is empty if no authentication is used. It is populated before
  97. // any authentication callback is called and not assigned to after that.
  98. User string
  99. // ClientVersion is the client's version, populated after
  100. // Handshake is called. It should not be modified.
  101. ClientVersion []byte
  102. // Initial H used for the session ID. Once assigned this must not change
  103. // even during subsequent key exchanges.
  104. sessionId []byte
  105. }
  106. // Server returns a new SSH server connection
  107. // using c as the underlying transport.
  108. func Server(c net.Conn, config *ServerConfig) *ServerConn {
  109. return &ServerConn{
  110. transport: newTransport(c, config.rand()),
  111. channels: make(map[uint32]*serverChan),
  112. config: config,
  113. }
  114. }
  115. // signAndMarshal signs the data with the appropriate algorithm,
  116. // and serializes the result in SSH wire format.
  117. func signAndMarshal(k Signer, rand io.Reader, data []byte) ([]byte, error) {
  118. sig, err := k.Sign(rand, data)
  119. if err != nil {
  120. return nil, err
  121. }
  122. return serializeSignature(k.PublicKey().PrivateKeyAlgo(), sig), nil
  123. }
  124. // serverVersion is the fixed identification string that Server will use.
  125. var serverVersion = []byte("SSH-2.0-Go\r\n")
  126. // Handshake performs an SSH transport and client authentication on the given ServerConn.
  127. func (s *ServerConn) Handshake() (err error) {
  128. if _, err = s.Write(serverVersion); err != nil {
  129. return
  130. }
  131. if err := s.Flush(); err != nil {
  132. return err
  133. }
  134. s.ClientVersion, err = readVersion(s)
  135. if err != nil {
  136. return
  137. }
  138. if err = s.clientInitHandshake(nil, nil); err != nil {
  139. return
  140. }
  141. var packet []byte
  142. if packet, err = s.readPacket(); err != nil {
  143. return
  144. }
  145. var serviceRequest serviceRequestMsg
  146. if err = unmarshal(&serviceRequest, packet, msgServiceRequest); err != nil {
  147. return
  148. }
  149. if serviceRequest.Service != serviceUserAuth {
  150. return errors.New("ssh: requested service '" + serviceRequest.Service + "' before authenticating")
  151. }
  152. serviceAccept := serviceAcceptMsg{
  153. Service: serviceUserAuth,
  154. }
  155. if err = s.writePacket(marshal(msgServiceAccept, serviceAccept)); err != nil {
  156. return
  157. }
  158. if err = s.authenticate(s.sessionId); err != nil {
  159. return
  160. }
  161. return
  162. }
  163. func (s *ServerConn) clientInitHandshake(clientKexInit *kexInitMsg, clientKexInitPacket []byte) (err error) {
  164. serverKexInit := kexInitMsg{
  165. KexAlgos: s.config.Crypto.kexes(),
  166. CiphersClientServer: s.config.Crypto.ciphers(),
  167. CiphersServerClient: s.config.Crypto.ciphers(),
  168. MACsClientServer: s.config.Crypto.macs(),
  169. MACsServerClient: s.config.Crypto.macs(),
  170. CompressionClientServer: supportedCompressions,
  171. CompressionServerClient: supportedCompressions,
  172. }
  173. for _, k := range s.config.hostKeys {
  174. serverKexInit.ServerHostKeyAlgos = append(
  175. serverKexInit.ServerHostKeyAlgos, k.PublicKey().PublicKeyAlgo())
  176. }
  177. serverKexInitPacket := marshal(msgKexInit, serverKexInit)
  178. if err = s.writePacket(serverKexInitPacket); err != nil {
  179. return
  180. }
  181. if clientKexInitPacket == nil {
  182. clientKexInit = new(kexInitMsg)
  183. if clientKexInitPacket, err = s.readPacket(); err != nil {
  184. return
  185. }
  186. if err = unmarshal(clientKexInit, clientKexInitPacket, msgKexInit); err != nil {
  187. return
  188. }
  189. }
  190. kexAlgo, hostKeyAlgo, ok := findAgreedAlgorithms(s.transport, clientKexInit, &serverKexInit)
  191. if !ok {
  192. return errors.New("ssh: no common algorithms")
  193. }
  194. if clientKexInit.FirstKexFollows && kexAlgo != clientKexInit.KexAlgos[0] {
  195. // The client sent a Kex message for the wrong algorithm,
  196. // which we have to ignore.
  197. if _, err = s.readPacket(); err != nil {
  198. return
  199. }
  200. }
  201. var hostKey Signer
  202. for _, k := range s.config.hostKeys {
  203. if hostKeyAlgo == k.PublicKey().PublicKeyAlgo() {
  204. hostKey = k
  205. }
  206. }
  207. kex, ok := kexAlgoMap[kexAlgo]
  208. if !ok {
  209. return fmt.Errorf("ssh: unexpected key exchange algorithm %v", kexAlgo)
  210. }
  211. magics := handshakeMagics{
  212. serverVersion: serverVersion[:len(serverVersion)-2],
  213. clientVersion: s.ClientVersion,
  214. serverKexInit: marshal(msgKexInit, serverKexInit),
  215. clientKexInit: clientKexInitPacket,
  216. }
  217. result, err := kex.Server(s, s.config.rand(), &magics, hostKey)
  218. if err != nil {
  219. return err
  220. }
  221. // sessionId must only be assigned during initial handshake.
  222. if s.sessionId == nil {
  223. s.sessionId = result.H
  224. }
  225. var packet []byte
  226. if err = s.writePacket([]byte{msgNewKeys}); err != nil {
  227. return
  228. }
  229. if err = s.transport.writer.setupKeys(serverKeys, result.K, result.H, s.sessionId, kex.Hash()); err != nil {
  230. return
  231. }
  232. if packet, err = s.readPacket(); err != nil {
  233. return
  234. }
  235. if packet[0] != msgNewKeys {
  236. return UnexpectedMessageError{msgNewKeys, packet[0]}
  237. }
  238. if err = s.transport.reader.setupKeys(clientKeys, result.K, result.H, s.sessionId, kex.Hash()); err != nil {
  239. return
  240. }
  241. return
  242. }
  243. func isAcceptableAlgo(algo string) bool {
  244. switch algo {
  245. case KeyAlgoRSA, KeyAlgoDSA, KeyAlgoECDSA256, KeyAlgoECDSA384, KeyAlgoECDSA521,
  246. CertAlgoRSAv01, CertAlgoDSAv01, CertAlgoECDSA256v01, CertAlgoECDSA384v01, CertAlgoECDSA521v01:
  247. return true
  248. }
  249. return false
  250. }
  251. // testPubKey returns true if the given public key is acceptable for the user.
  252. func (s *ServerConn) testPubKey(user, algo string, pubKey []byte) bool {
  253. if s.config.PublicKeyCallback == nil || !isAcceptableAlgo(algo) {
  254. return false
  255. }
  256. for _, c := range s.cachedPubKeys {
  257. if c.user == user && c.algo == algo && bytes.Equal(c.pubKey, pubKey) {
  258. return c.result
  259. }
  260. }
  261. result := s.config.PublicKeyCallback(s, user, algo, pubKey)
  262. if len(s.cachedPubKeys) < maxCachedPubKeys {
  263. c := cachedPubKey{
  264. user: user,
  265. algo: algo,
  266. pubKey: make([]byte, len(pubKey)),
  267. result: result,
  268. }
  269. copy(c.pubKey, pubKey)
  270. s.cachedPubKeys = append(s.cachedPubKeys, c)
  271. }
  272. return result
  273. }
  274. func (s *ServerConn) authenticate(H []byte) error {
  275. var userAuthReq userAuthRequestMsg
  276. var err error
  277. var packet []byte
  278. userAuthLoop:
  279. for {
  280. if packet, err = s.readPacket(); err != nil {
  281. return err
  282. }
  283. if err = unmarshal(&userAuthReq, packet, msgUserAuthRequest); err != nil {
  284. return err
  285. }
  286. if userAuthReq.Service != serviceSSH {
  287. return errors.New("ssh: client attempted to negotiate for unknown service: " + userAuthReq.Service)
  288. }
  289. switch userAuthReq.Method {
  290. case "none":
  291. if s.config.NoClientAuth {
  292. break userAuthLoop
  293. }
  294. case "password":
  295. if s.config.PasswordCallback == nil {
  296. break
  297. }
  298. payload := userAuthReq.Payload
  299. if len(payload) < 1 || payload[0] != 0 {
  300. return ParseError{msgUserAuthRequest}
  301. }
  302. payload = payload[1:]
  303. password, payload, ok := parseString(payload)
  304. if !ok || len(payload) > 0 {
  305. return ParseError{msgUserAuthRequest}
  306. }
  307. s.User = userAuthReq.User
  308. if s.config.PasswordCallback(s, userAuthReq.User, string(password)) {
  309. break userAuthLoop
  310. }
  311. case "keyboard-interactive":
  312. if s.config.KeyboardInteractiveCallback == nil {
  313. break
  314. }
  315. s.User = userAuthReq.User
  316. if s.config.KeyboardInteractiveCallback(s, s.User, &sshClientKeyboardInteractive{s}) {
  317. break userAuthLoop
  318. }
  319. case "publickey":
  320. if s.config.PublicKeyCallback == nil {
  321. break
  322. }
  323. payload := userAuthReq.Payload
  324. if len(payload) < 1 {
  325. return ParseError{msgUserAuthRequest}
  326. }
  327. isQuery := payload[0] == 0
  328. payload = payload[1:]
  329. algoBytes, payload, ok := parseString(payload)
  330. if !ok {
  331. return ParseError{msgUserAuthRequest}
  332. }
  333. algo := string(algoBytes)
  334. pubKey, payload, ok := parseString(payload)
  335. if !ok {
  336. return ParseError{msgUserAuthRequest}
  337. }
  338. if isQuery {
  339. // The client can query if the given public key
  340. // would be ok.
  341. if len(payload) > 0 {
  342. return ParseError{msgUserAuthRequest}
  343. }
  344. if s.testPubKey(userAuthReq.User, algo, pubKey) {
  345. okMsg := userAuthPubKeyOkMsg{
  346. Algo: algo,
  347. PubKey: string(pubKey),
  348. }
  349. if err = s.writePacket(marshal(msgUserAuthPubKeyOk, okMsg)); err != nil {
  350. return err
  351. }
  352. continue userAuthLoop
  353. }
  354. } else {
  355. sig, payload, ok := parseSignature(payload)
  356. if !ok || len(payload) > 0 {
  357. return ParseError{msgUserAuthRequest}
  358. }
  359. // Ensure the public key algo and signature algo
  360. // are supported. Compare the private key
  361. // algorithm name that corresponds to algo with
  362. // sig.Format. This is usually the same, but
  363. // for certs, the names differ.
  364. if !isAcceptableAlgo(algo) || !isAcceptableAlgo(sig.Format) || pubAlgoToPrivAlgo(algo) != sig.Format {
  365. break
  366. }
  367. signedData := buildDataSignedForAuth(H, userAuthReq, algoBytes, pubKey)
  368. key, _, ok := parsePubKey(pubKey)
  369. if !ok {
  370. return ParseError{msgUserAuthRequest}
  371. }
  372. if !key.Verify(signedData, sig.Blob) {
  373. return ParseError{msgUserAuthRequest}
  374. }
  375. // TODO(jmpittman): Implement full validation for certificates.
  376. s.User = userAuthReq.User
  377. if s.testPubKey(userAuthReq.User, algo, pubKey) {
  378. break userAuthLoop
  379. }
  380. }
  381. }
  382. var failureMsg userAuthFailureMsg
  383. if s.config.PasswordCallback != nil {
  384. failureMsg.Methods = append(failureMsg.Methods, "password")
  385. }
  386. if s.config.PublicKeyCallback != nil {
  387. failureMsg.Methods = append(failureMsg.Methods, "publickey")
  388. }
  389. if s.config.KeyboardInteractiveCallback != nil {
  390. failureMsg.Methods = append(failureMsg.Methods, "keyboard-interactive")
  391. }
  392. if len(failureMsg.Methods) == 0 {
  393. return errors.New("ssh: no authentication methods configured but NoClientAuth is also false")
  394. }
  395. if err = s.writePacket(marshal(msgUserAuthFailure, failureMsg)); err != nil {
  396. return err
  397. }
  398. }
  399. packet = []byte{msgUserAuthSuccess}
  400. if err = s.writePacket(packet); err != nil {
  401. return err
  402. }
  403. return nil
  404. }
  405. // sshClientKeyboardInteractive implements a ClientKeyboardInteractive by
  406. // asking the client on the other side of a ServerConn.
  407. type sshClientKeyboardInteractive struct {
  408. *ServerConn
  409. }
  410. func (c *sshClientKeyboardInteractive) Challenge(user, instruction string, questions []string, echos []bool) (answers []string, err error) {
  411. if len(questions) != len(echos) {
  412. return nil, errors.New("ssh: echos and questions must have equal length")
  413. }
  414. var prompts []byte
  415. for i := range questions {
  416. prompts = appendString(prompts, questions[i])
  417. prompts = appendBool(prompts, echos[i])
  418. }
  419. if err := c.writePacket(marshal(msgUserAuthInfoRequest, userAuthInfoRequestMsg{
  420. Instruction: instruction,
  421. NumPrompts: uint32(len(questions)),
  422. Prompts: prompts,
  423. })); err != nil {
  424. return nil, err
  425. }
  426. packet, err := c.readPacket()
  427. if err != nil {
  428. return nil, err
  429. }
  430. if packet[0] != msgUserAuthInfoResponse {
  431. return nil, UnexpectedMessageError{msgUserAuthInfoResponse, packet[0]}
  432. }
  433. packet = packet[1:]
  434. n, packet, ok := parseUint32(packet)
  435. if !ok || int(n) != len(questions) {
  436. return nil, &ParseError{msgUserAuthInfoResponse}
  437. }
  438. for i := uint32(0); i < n; i++ {
  439. ans, rest, ok := parseString(packet)
  440. if !ok {
  441. return nil, &ParseError{msgUserAuthInfoResponse}
  442. }
  443. answers = append(answers, string(ans))
  444. packet = rest
  445. }
  446. if len(packet) != 0 {
  447. return nil, errors.New("ssh: junk at end of message")
  448. }
  449. return answers, nil
  450. }
  451. const defaultWindowSize = 32768
  452. // Accept reads and processes messages on a ServerConn. It must be called
  453. // in order to demultiplex messages to any resulting Channels.
  454. func (s *ServerConn) Accept() (Channel, error) {
  455. // TODO(dfc) s.lock is not held here so visibility of s.err is not guaranteed.
  456. if s.err != nil {
  457. return nil, s.err
  458. }
  459. for {
  460. packet, err := s.readPacket()
  461. if err != nil {
  462. s.lock.Lock()
  463. s.err = err
  464. s.lock.Unlock()
  465. // TODO(dfc) s.lock protects s.channels but isn't being held here.
  466. for _, c := range s.channels {
  467. c.setDead()
  468. c.handleData(nil)
  469. }
  470. return nil, err
  471. }
  472. switch packet[0] {
  473. case msgChannelData:
  474. if len(packet) < 9 {
  475. // malformed data packet
  476. return nil, ParseError{msgChannelData}
  477. }
  478. remoteId := binary.BigEndian.Uint32(packet[1:5])
  479. s.lock.Lock()
  480. c, ok := s.channels[remoteId]
  481. if !ok {
  482. s.lock.Unlock()
  483. continue
  484. }
  485. if length := binary.BigEndian.Uint32(packet[5:9]); length > 0 {
  486. packet = packet[9:]
  487. c.handleData(packet[:length])
  488. }
  489. s.lock.Unlock()
  490. default:
  491. decoded, err := decode(packet)
  492. if err != nil {
  493. return nil, err
  494. }
  495. switch msg := decoded.(type) {
  496. case *channelOpenMsg:
  497. if msg.MaxPacketSize < minPacketLength || msg.MaxPacketSize > 1<<31 {
  498. return nil, errors.New("ssh: invalid MaxPacketSize from peer")
  499. }
  500. c := &serverChan{
  501. channel: channel{
  502. packetConn: s,
  503. remoteId: msg.PeersId,
  504. remoteWin: window{Cond: newCond()},
  505. maxPacket: msg.MaxPacketSize,
  506. },
  507. chanType: msg.ChanType,
  508. extraData: msg.TypeSpecificData,
  509. myWindow: defaultWindowSize,
  510. serverConn: s,
  511. cond: newCond(),
  512. pendingData: make([]byte, defaultWindowSize),
  513. }
  514. c.remoteWin.add(msg.PeersWindow)
  515. s.lock.Lock()
  516. c.localId = s.nextChanId
  517. s.nextChanId++
  518. s.channels[c.localId] = c
  519. s.lock.Unlock()
  520. return c, nil
  521. case *channelRequestMsg:
  522. s.lock.Lock()
  523. c, ok := s.channels[msg.PeersId]
  524. if !ok {
  525. s.lock.Unlock()
  526. continue
  527. }
  528. c.handlePacket(msg)
  529. s.lock.Unlock()
  530. case *windowAdjustMsg:
  531. s.lock.Lock()
  532. c, ok := s.channels[msg.PeersId]
  533. if !ok {
  534. s.lock.Unlock()
  535. continue
  536. }
  537. c.handlePacket(msg)
  538. s.lock.Unlock()
  539. case *channelEOFMsg:
  540. s.lock.Lock()
  541. c, ok := s.channels[msg.PeersId]
  542. if !ok {
  543. s.lock.Unlock()
  544. continue
  545. }
  546. c.handlePacket(msg)
  547. s.lock.Unlock()
  548. case *channelCloseMsg:
  549. s.lock.Lock()
  550. c, ok := s.channels[msg.PeersId]
  551. if !ok {
  552. s.lock.Unlock()
  553. continue
  554. }
  555. c.handlePacket(msg)
  556. s.lock.Unlock()
  557. case *globalRequestMsg:
  558. if msg.WantReply {
  559. if err := s.writePacket([]byte{msgRequestFailure}); err != nil {
  560. return nil, err
  561. }
  562. }
  563. case *kexInitMsg:
  564. s.lock.Lock()
  565. if err := s.clientInitHandshake(msg, packet); err != nil {
  566. s.lock.Unlock()
  567. return nil, err
  568. }
  569. s.lock.Unlock()
  570. case *disconnectMsg:
  571. return nil, io.EOF
  572. default:
  573. // Unknown message. Ignore.
  574. }
  575. }
  576. }
  577. panic("unreachable")
  578. }
  579. // A Listener implements a network listener (net.Listener) for SSH connections.
  580. type Listener struct {
  581. listener net.Listener
  582. config *ServerConfig
  583. }
  584. // Addr returns the listener's network address.
  585. func (l *Listener) Addr() net.Addr {
  586. return l.listener.Addr()
  587. }
  588. // Close closes the listener.
  589. func (l *Listener) Close() error {
  590. return l.listener.Close()
  591. }
  592. // Accept waits for and returns the next incoming SSH connection.
  593. // The receiver should call Handshake() in another goroutine
  594. // to avoid blocking the accepter.
  595. func (l *Listener) Accept() (*ServerConn, error) {
  596. c, err := l.listener.Accept()
  597. if err != nil {
  598. return nil, err
  599. }
  600. return Server(c, l.config), nil
  601. }
  602. // Listen creates an SSH listener accepting connections on
  603. // the given network address using net.Listen.
  604. func Listen(network, addr string, config *ServerConfig) (*Listener, error) {
  605. l, err := net.Listen(network, addr)
  606. if err != nil {
  607. return nil, err
  608. }
  609. return &Listener{
  610. l,
  611. config,
  612. }, nil
  613. }