Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 | 5 |
| 6 abstract class SecureServerSocket implements ServerSocket { | 6 abstract class SecureServerSocket implements ServerSocket { |
| 7 /** | 7 /** |
| 8 * Constructs a new secure server socket, binds it to a given address | 8 * Constructs a new secure server socket, binds it to a given address |
| 9 * and port, and listens on it. Incoming client connections are | 9 * and port, and listens on it. Incoming client connections are |
| 10 * promoted to secure connections, using the server certificate given by | 10 * promoted to secure connections, using the server certificate given by |
| 11 * certificate_name. The bindAddress must be given as a numeric address, | 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 | 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". | 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 | 14 * The certificate is looked up in the NSS certificate database set by |
| 15 * SecureSocket.setCertificateDatabase. | 15 * SecureSocket.setCertificateDatabase. |
| 16 * | |
| 17 * To request or require that clients authenticate by providing an SSL (TLS) | |
| 18 * client certificate, set the optional parameters requestClientCertificate or | |
| 19 * requireClientCertificate to true. Require implies request, so one doesn't | |
| 20 * need to specify both. To check whether a client certificate was received, | |
| 21 * check SecureSocket.peerCertificate after connecting. If no certificate | |
| 22 * was received, the result will be null. | |
| 16 */ | 23 */ |
| 17 factory SecureServerSocket(String bindAddress, | 24 factory SecureServerSocket(String bindAddress, |
| 18 int port, | 25 int port, |
| 19 int backlog, | 26 int backlog, |
| 20 String certificate_name) => | 27 String certificate_name, |
| 21 new _SecureServerSocket(bindAddress, port, backlog, certificate_name); | 28 {bool requestClientCertificate: false, |
|
Søren Gjesse
2012/12/07 13:00:23
How about using an "enum" here with the following
Bill Hesse
2012/12/10 15:15:48
I strongly feel that for the user of the API, choo
| |
| 29 bool requireClientCertificate: false}) { | |
| 30 return new _SecureServerSocket(bindAddress, | |
| 31 port, | |
| 32 backlog, | |
| 33 certificate_name, | |
| 34 requestClientCertificate, | |
| 35 requireClientCertificate); | |
| 36 } | |
| 22 } | 37 } |
| 23 | 38 |
| 24 | 39 |
| 25 class _SecureServerSocket implements SecureServerSocket { | 40 class _SecureServerSocket implements SecureServerSocket { |
| 26 | 41 |
| 27 _SecureServerSocket(String bindAddress, | 42 _SecureServerSocket(String bindAddress, |
| 28 int port, | 43 int port, |
| 29 int backlog, | 44 int backlog, |
| 30 String certificate_name) { | 45 String certificate_name, |
| 46 bool requestClientCertificate, | |
| 47 bool requireClientCertificate) | |
| 48 : _certificate_name = certificate_name, | |
| 49 _requestClientCertificate = requestClientCertificate, | |
| 50 _requireClientCertificate = requireClientCertificate { | |
| 31 _socket = new ServerSocket(bindAddress, port, backlog); | 51 _socket = new ServerSocket(bindAddress, port, backlog); |
| 32 _socket.onConnection = this._onConnectionHandler; | 52 _socket.onConnection = this._onConnectionHandler; |
| 33 _certificate_name = certificate_name; | |
| 34 } | 53 } |
| 35 | 54 |
| 36 void set onConnection(void callback(Socket connection)) { | 55 void set onConnection(void callback(Socket connection)) { |
| 37 _onConnectionCallback = callback; | 56 _onConnectionCallback = callback; |
| 38 } | 57 } |
| 39 | 58 |
| 40 void set onError(void callback(e)) { | 59 void set onError(void callback(e)) { |
| 41 _socket.onError = callback; | 60 _socket.onError = callback; |
| 42 } | 61 } |
| 43 | 62 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 58 connection.close(); | 77 connection.close(); |
| 59 throw new SocketIOException( | 78 throw new SocketIOException( |
| 60 "SecureServerSocket with no onConnection callback connected to"); | 79 "SecureServerSocket with no onConnection callback connected to"); |
| 61 } | 80 } |
| 62 if (_certificate_name == null) { | 81 if (_certificate_name == null) { |
| 63 connection.close(); | 82 connection.close(); |
| 64 throw new SocketIOException( | 83 throw new SocketIOException( |
| 65 "SecureServerSocket with server certificate not set connected to"); | 84 "SecureServerSocket with server certificate not set connected to"); |
| 66 } | 85 } |
| 67 var secure_connection = new _SecureSocket.server(connection.remoteHost, | 86 var secure_connection = new _SecureSocket.server(connection.remoteHost, |
| 68 connection.remotePort, | 87 connection.remotePort, |
| 69 connection, | 88 connection, |
| 70 _certificate_name); | 89 _certificate_name, |
| 90 _requestClientCertificate, | |
| 91 _requireClientCertificate); | |
| 71 _onConnectionCallback(secure_connection); | 92 _onConnectionCallback(secure_connection); |
| 72 } | 93 } |
| 73 | 94 |
| 74 ServerSocket _socket; | 95 ServerSocket _socket; |
| 75 var _onConnectionCallback; | 96 var _onConnectionCallback; |
| 76 String _certificate_name; | 97 final String _certificate_name; |
| 77 } | 98 final bool _requestClientCertificate; |
| 99 final bool _requireClientCertificate;} | |
| OLD | NEW |