| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 | |
| 6 abstract class TlsServerSocket implements ServerSocket { | |
| 7 /** | |
| 8 * Constructs a new secure server socket, binds it to a given address | |
| 9 * and port, and listens on it. Incoming client connections are | |
| 10 * promoted to secure connections, using the server certificate given by | |
| 11 * certificate_name. The bindAddress must be given as a numeric address, | |
| 12 * not a host name. The certificate name is the distinguished name (DN) of | |
| 13 * the certificate, such as "CN=localhost" or "CN=myserver.mydomain.com". | |
| 14 * The certificate is looked up in the NSS certificate database set by | |
| 15 * TlsSocket.setCertificateDatabase. | |
| 16 */ | |
| 17 factory TlsServerSocket(String bindAddress, | |
| 18 int port, | |
| 19 int backlog, | |
| 20 String certificate_name) => | |
| 21 new _TlsServerSocket(bindAddress, port, backlog, certificate_name); | |
| 22 } | |
| 23 | |
| 24 | |
| 25 class _TlsServerSocket implements TlsServerSocket { | |
| 26 | |
| 27 _TlsServerSocket(String bindAddress, | |
| 28 int port, | |
| 29 int backlog, | |
| 30 String certificate_name) { | |
| 31 _socket = new ServerSocket(bindAddress, port, backlog); | |
| 32 _socket.onConnection = this._onConnectionHandler; | |
| 33 _certificate_name = certificate_name; | |
| 34 } | |
| 35 | |
| 36 void set onConnection(void callback(Socket connection)) { | |
| 37 _onConnectionCallback = callback; | |
| 38 } | |
| 39 | |
| 40 void set onError(void callback(e)) { | |
| 41 _socket.onError = callback; | |
| 42 } | |
| 43 | |
| 44 /** | |
| 45 * Returns the port used by this socket. | |
| 46 */ | |
| 47 int get port => _socket.port; | |
| 48 | |
| 49 /** | |
| 50 * Closes the socket. | |
| 51 */ | |
| 52 void close() { | |
| 53 _socket.close(); | |
| 54 } | |
| 55 | |
| 56 void _onConnectionHandler(Socket connection) { | |
| 57 if (_onConnectionCallback == null) { | |
| 58 connection.close(); | |
| 59 throw new SocketIOException( | |
| 60 "TlsServerSocket with no onConnection callback connected to"); | |
| 61 } | |
| 62 if (_certificate_name == null) { | |
| 63 connection.close(); | |
| 64 throw new SocketIOException( | |
| 65 "TlsServerSocket with server certificate not set connected to"); | |
| 66 } | |
| 67 var secure_connection = new _TlsSocket.server(connection.remoteHost, | |
| 68 connection.remotePort, | |
| 69 connection, | |
| 70 _certificate_name); | |
| 71 _onConnectionCallback(secure_connection); | |
| 72 } | |
| 73 | |
| 74 ServerSocket _socket; | |
| 75 var _onConnectionCallback; | |
| 76 String _certificate_name; | |
| 77 } | |
| OLD | NEW |