LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Package tls partially implements the TLS 1.1 protocol, as specified in RFC | 5 // Package tls partially implements the TLS 1.1 protocol, as specified in RFC |
6 // 4346. | 6 // 4346. |
7 package tls | 7 package tls |
8 | 8 |
9 import ( | 9 import ( |
10 "crypto/rsa" | 10 "crypto/rsa" |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 // Client returns a new TLS client side connection | 27 // Client returns a new TLS client side connection |
28 // using conn as the underlying transport. | 28 // using conn as the underlying transport. |
29 // Client interprets a nil configuration as equivalent to | 29 // Client interprets a nil configuration as equivalent to |
30 // the zero configuration; see the documentation of Config | 30 // the zero configuration; see the documentation of Config |
31 // for the defaults. | 31 // for the defaults. |
32 func Client(conn net.Conn, config *Config) *Conn { | 32 func Client(conn net.Conn, config *Config) *Conn { |
33 return &Conn{conn: conn, config: config, isClient: true} | 33 return &Conn{conn: conn, config: config, isClient: true} |
34 } | 34 } |
35 | 35 |
36 // A Listener implements a network listener (net.Listener) for TLS connections. | 36 // A listener implements a network listener (net.Listener) for TLS connections. |
37 type Listener struct { | 37 type listener struct { |
38 » listener net.Listener | 38 » net.Listener |
39 » config *Config | 39 » config *Config |
40 } | 40 } |
41 | 41 |
42 // Accept waits for and returns the next incoming TLS connection. | 42 // Accept waits for and returns the next incoming TLS connection. |
43 // The returned connection c is a *tls.Conn. | 43 // The returned connection c is a *tls.Conn. |
44 func (l *Listener) Accept() (c net.Conn, err error) { | 44 func (l *listener) Accept() (c net.Conn, err error) { |
45 » c, err = l.listener.Accept() | 45 » c, err = l.Listener.Accept() |
46 if err != nil { | 46 if err != nil { |
47 return | 47 return |
48 } | 48 } |
49 c = Server(c, l.config) | 49 c = Server(c, l.config) |
50 return | 50 return |
51 } | 51 } |
52 | 52 |
53 // Close closes the listener. | |
54 func (l *Listener) Close() error { return l.listener.Close() } | |
55 | |
56 // Addr returns the listener's network address. | |
57 func (l *Listener) Addr() net.Addr { return l.listener.Addr() } | |
58 | |
59 // NewListener creates a Listener which accepts connections from an inner | 53 // NewListener creates a Listener which accepts connections from an inner |
60 // Listener and wraps each connection with Server. | 54 // Listener and wraps each connection with Server. |
61 // The configuration config must be non-nil and must have | 55 // The configuration config must be non-nil and must have |
62 // at least one certificate. | 56 // at least one certificate. |
63 func NewListener(listener net.Listener, config *Config) (l *Listener) { | 57 func NewListener(inner net.Listener, config *Config) net.Listener { |
64 » l = new(Listener) | 58 » l := new(listener) |
65 » l.listener = listener | 59 » l.Listener = inner |
66 l.config = config | 60 l.config = config |
67 » return | 61 » return l |
68 } | 62 } |
69 | 63 |
70 // Listen creates a TLS listener accepting connections on the | 64 // Listen creates a TLS listener accepting connections on the |
71 // given network address using net.Listen. | 65 // given network address using net.Listen. |
72 // The configuration config must be non-nil and must have | 66 // The configuration config must be non-nil and must have |
73 // at least one certificate. | 67 // at least one certificate. |
74 func Listen(network, laddr string, config *Config) (*Listener, error) { | 68 func Listen(network, laddr string, config *Config) (net.Listener, error) { |
75 if config == nil || len(config.Certificates) == 0 { | 69 if config == nil || len(config.Certificates) == 0 { |
76 return nil, errors.New("tls.Listen: no certificates in configura
tion") | 70 return nil, errors.New("tls.Listen: no certificates in configura
tion") |
77 } | 71 } |
78 l, err := net.Listen(network, laddr) | 72 l, err := net.Listen(network, laddr) |
79 if err != nil { | 73 if err != nil { |
80 return nil, err | 74 return nil, err |
81 } | 75 } |
82 return NewListener(l, config), nil | 76 return NewListener(l, config), nil |
83 } | 77 } |
84 | 78 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 return | 177 return |
184 } | 178 } |
185 | 179 |
186 if x509Cert.PublicKeyAlgorithm != x509.RSA || x509Cert.PublicKey.(*rsa.P
ublicKey).N.Cmp(key.PublicKey.N) != 0 { | 180 if x509Cert.PublicKeyAlgorithm != x509.RSA || x509Cert.PublicKey.(*rsa.P
ublicKey).N.Cmp(key.PublicKey.N) != 0 { |
187 err = errors.New("crypto/tls: private key does not match public
key") | 181 err = errors.New("crypto/tls: private key does not match public
key") |
188 return | 182 return |
189 } | 183 } |
190 | 184 |
191 return | 185 return |
192 } | 186 } |
LEFT | RIGHT |