Chromium Code Reviews| Index: sdk/lib/io/tls_server_socket.dart |
| diff --git a/sdk/lib/io/tls_server_socket.dart b/sdk/lib/io/tls_server_socket.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c21fb1c06b50d5e771d28679590dcec1577f5f95 |
| --- /dev/null |
| +++ b/sdk/lib/io/tls_server_socket.dart |
| @@ -0,0 +1,80 @@ |
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| + |
| +abstract class TlsServerSocket implements ServerSocket { |
| + /** |
| + * Constructs a new secure server socket, binds it to a given address |
| + * and port, and listens on it. Incoming client connections are |
| + * promoted to secure connections, using the server certificate set by |
| + * SetCertificate. The bindAddress must be given as a numeric address, |
| + * not a host name. |
| + */ |
| + factory TlsServerSocket(String bindAddress, int port, int backlog) => |
| + new _TlsServerSocket(bindAddress, port, backlog); |
| + |
| + /** |
| + * Chooses the certificate for the server socket to use when authenticating |
| + * itself to a client. The name is the distinguished name (DN) of the |
| + * certificate, such as "CN=localhost" or "CN=myserver.mydomain.com". |
| + * The certificate is looked up in the NSS certificate database set by |
| + * TlsSocket.setCertificateDatabase. |
| + */ |
| + void setCertificate(String certificate_name); |
|
Mads Ager (google)
2012/11/20 14:59:45
Since this is per instance, can we make it an argu
Bill Hesse
2012/11/20 17:46:55
Done.
|
| +} |
| + |
| + |
| +class _TlsServerSocket implements TlsServerSocket { |
| + |
| + _TlsServerSocket(String bindAddress, int port, int backlog) { |
| + _socket = new ServerSocket(bindAddress, port, backlog); |
| + _socket.onConnection = this._onConnectionHandler; |
| + } |
| + |
| + void setCertificate(String certificate_name) { |
| + _certificate_name = certificate_name; |
| + } |
| + |
| + void set onConnection(void callback(Socket connection)) { |
| + _onConnectionCallback = callback; |
| + } |
| + |
| + void set onError(void callback(e)) { |
| + _socket.onError = callback; |
| + } |
| + |
| + /** |
| + * Returns the port used by this socket. |
| + */ |
| + int get port => _socket.port; |
| + |
| + /** |
| + * Closes the socket. |
| + */ |
| + void close() { |
| + _socket.close(); |
| + } |
| + |
| + void _onConnectionHandler(Socket connection) { |
| + if (_onConnectionCallback == null) { |
| + connection.close(); |
| + throw new SocketIOException( |
| + "TlsServerSocket with no onConnection callback connected to"); |
| + } |
| + if (_certificate_name == null) { |
| + connection.close(); |
| + throw new SocketIOException( |
| + "TlsServerSocket with server certificate not set connected to"); |
| + } |
| + var secure_connection = new _TlsSocket.server(connection.remoteHost, |
| + connection.remotePort, |
| + connection, |
| + _certificate_name); |
| + _onConnectionCallback(secure_connection); |
| + } |
| + |
| + ServerSocket _socket; |
| + var _onConnectionCallback; |
| + String _certificate_name; |
| +} |