Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: sdk/lib/io/tls_server_socket.dart

Issue 11414009: Secure server sockets for dart:io. Add TlsServerSocket class, providing SSL server sockets. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add server certificate and key to certificate database. Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 set by
11 * SetCertificate. The bindAddress must be given as a numeric address,
12 * not a host name.
13 */
14 factory TlsServerSocket(String bindAddress, int port, int backlog) =>
15 new _TlsServerSocket(bindAddress, port, backlog);
16
17 /**
18 * Chooses the certificate for the server socket to use when authenticating
19 * itself to a client. The name is the distinguished name (DN) of the
20 * certificate, such as "CN=localhost" or "CN=myserver.mydomain.com".
21 * The certificate is looked up in the NSS certificate database set by
22 * TlsSocket.setCertificateDatabase.
23 */
24 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.
25 }
26
27
28 class _TlsServerSocket implements TlsServerSocket {
29
30 _TlsServerSocket(String bindAddress, int port, int backlog) {
31 _socket = new ServerSocket(bindAddress, port, backlog);
32 _socket.onConnection = this._onConnectionHandler;
33 }
34
35 void setCertificate(String certificate_name) {
36 _certificate_name = certificate_name;
37 }
38
39 void set onConnection(void callback(Socket connection)) {
40 _onConnectionCallback = callback;
41 }
42
43 void set onError(void callback(e)) {
44 _socket.onError = callback;
45 }
46
47 /**
48 * Returns the port used by this socket.
49 */
50 int get port => _socket.port;
51
52 /**
53 * Closes the socket.
54 */
55 void close() {
56 _socket.close();
57 }
58
59 void _onConnectionHandler(Socket connection) {
60 if (_onConnectionCallback == null) {
61 connection.close();
62 throw new SocketIOException(
63 "TlsServerSocket with no onConnection callback connected to");
64 }
65 if (_certificate_name == null) {
66 connection.close();
67 throw new SocketIOException(
68 "TlsServerSocket with server certificate not set connected to");
69 }
70 var secure_connection = new _TlsSocket.server(connection.remoteHost,
71 connection.remotePort,
72 connection,
73 _certificate_name);
74 _onConnectionCallback(secure_connection);
75 }
76
77 ServerSocket _socket;
78 var _onConnectionCallback;
79 String _certificate_name;
80 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698