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

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

Issue 11415290: Add a callback to SecureSocket for certificates that fail to be authenticated. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
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 * SecureSocket provides a secure (SSL or TLS) client connection to a server. 6 * SecureSocket provides a secure (SSL or TLS) client connection to a server.
7 * The certificate provided by the server is checked 7 * The certificate provided by the server is checked
8 * using the certificate database provided in setCertificateDatabase. 8 * using the certificate database provided in setCertificateDatabase.
9 */ 9 */
10 abstract class SecureSocket implements Socket { 10 abstract class SecureSocket implements Socket {
11 /** 11 /**
12 * Constructs a new secure client socket and connect it to the given 12 * Constructs a new secure client socket and connect it to the given
13 * host on the given port. The returned socket is not yet connected 13 * host on the given port. The returned socket is not yet connected
14 * but ready for registration of callbacks. 14 * but ready for registration of callbacks.
15 */ 15 */
16 factory SecureSocket(String host, int port) => new _SecureSocket(host, port); 16 factory SecureSocket(String host, int port) => new _SecureSocket(host, port);
17 17 /**
Mads Ager (google) 2012/12/05 07:30:53 Please add a blank line between members.
Bill Hesse 2012/12/05 12:35:38 Done.
18 * Install a handler for unverifiable certificates. The handler can inspect
19 * the certificate, and decide (or let the user decide) whether to accept
20 * the connection or not. The callback should return true
21 * to continue the SecureSocket connection.
22 */
23 void set onBadCertificate(bool callback(X509Certificate certificate));
18 /** 24 /**
Mads Ager (google) 2012/12/05 07:30:53 Ditto.
19 * Initializes the NSS library with the path to a certificate database 25 * Initializes the NSS library with the path to a certificate database
20 * containing root certificates for verifying certificate paths on 26 * containing root certificates for verifying certificate paths on
21 * client connections, and server certificates to provide on server 27 * client connections, and server certificates to provide on server
22 * connections. The password argument should be used when creating 28 * connections. The password argument should be used when creating
23 * secure server sockets, to allow the private key of the server 29 * secure server sockets, to allow the private key of the server
24 * certificate to be fetched. If useBuiltinRoots is true (the default), 30 * certificate to be fetched. If useBuiltinRoots is true (the default),
25 * then a built-in set of root certificates for trusted certificate 31 * then a built-in set of root certificates for trusted certificate
26 * authorities is merged with the certificates in the database. 32 * authorities is merged with the certificates in the database.
27 * 33 *
28 * Examples: 34 * Examples:
(...skipping 13 matching lines...) Expand all
42 * containing a cert9.db file, not a cert8.db file. This version of 48 * containing a cert9.db file, not a cert8.db file. This version of
43 * the database can be created using the NSS certutil tool with "sql:" in 49 * the database can be created using the NSS certutil tool with "sql:" in
44 * front of the absolute path of the database directory, or setting the 50 * front of the absolute path of the database directory, or setting the
45 * environment variable NSS_DEFAULT_DB_TYPE to "sql". 51 * environment variable NSS_DEFAULT_DB_TYPE to "sql".
46 */ 52 */
47 external static void initialize({String database, 53 external static void initialize({String database,
48 String password, 54 String password,
49 bool useBuiltinRoots: true}); 55 bool useBuiltinRoots: true});
50 } 56 }
51 57
58 /**
59 * X509Certificate represents an SSL certificate, with accessors to
60 * get the fields of the certificate.
61 */
62 abstract class X509Certificate {
Mads Ager (google) 2012/12/05 07:30:53 I think we should just remove the abstract class.
Bill Hesse 2012/12/05 12:35:38 Done.
63 String get subject;
64 String get issuer;
65 Date get startValidity;
66 Date get endValidity;
67 }
68
69
70 class _X509Certificate implements X509Certificate {
71 _X509Certificate(this.subject,
72 this.issuer,
73 this.startValidity,
74 this.endValidity);
75 final String subject;
76 final String issuer;
77 final Date startValidity;
78 final Date endValidity;
79 }
80
52 81
53 class _SecureSocket implements SecureSocket { 82 class _SecureSocket implements SecureSocket {
54 // Status states 83 // Status states
55 static final int NOT_CONNECTED = 200; 84 static final int NOT_CONNECTED = 200;
56 static final int HANDSHAKE = 201; 85 static final int HANDSHAKE = 201;
57 static final int CONNECTED = 202; 86 static final int CONNECTED = 202;
58 static final int CLOSED = 203; 87 static final int CLOSED = 203;
59 88
60 // Buffer identifiers. 89 // Buffer identifiers.
61 // These must agree with those in the native C++ implementation. 90 // These must agree with those in the native C++ implementation.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 181 }
153 _onWrite = callback; 182 _onWrite = callback;
154 } 183 }
155 184
156 void set _onWrite(void callback()) { 185 void set _onWrite(void callback()) {
157 _socketWriteHandler = callback; 186 _socketWriteHandler = callback;
158 // Reset the one-shot onWrite handler. 187 // Reset the one-shot onWrite handler.
159 _socket.onWrite = _secureWriteHandler; 188 _socket.onWrite = _secureWriteHandler;
160 } 189 }
161 190
191 void set onBadCertificate(bool callback(X509Certificate certificate)) {
192 if (callback is! Function && callback != null) {
Mads Ager (google) 2012/12/05 07:30:53 Remove extra space before '&&'
193 throw new SocketIOException(
194 "Callback provided to onBadCertificate is not a function or null");
195 }
196 _secureFilter.registerBadCertificateCallback(callback);
197 }
198
162 InputStream get inputStream { 199 InputStream get inputStream {
163 if (_inputStream == null) { 200 if (_inputStream == null) {
164 if (_socketDataHandler != null || _socketCloseHandler != null) { 201 if (_socketDataHandler != null || _socketCloseHandler != null) {
165 throw new StreamException( 202 throw new StreamException(
166 "Cannot get input stream when socket handlers are used"); 203 "Cannot get input stream when socket handlers are used");
167 } 204 }
168 _inputStream = new _SocketInputStream(this); 205 _inputStream = new _SocketInputStream(this);
169 } 206 }
170 return _inputStream; 207 return _inputStream;
171 } 208 }
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 external factory _SecureFilter(); 614 external factory _SecureFilter();
578 615
579 void connect(String hostName, 616 void connect(String hostName,
580 int port, 617 int port,
581 bool is_server, 618 bool is_server,
582 String certificateName); 619 String certificateName);
583 void destroy(); 620 void destroy();
584 void handshake(); 621 void handshake();
585 void init(); 622 void init();
586 int processBuffer(int bufferIndex); 623 int processBuffer(int bufferIndex);
624 void registerBadCertificateCallback(Function callback);
587 void registerHandshakeCompleteCallback(Function handshakeCompleteHandler); 625 void registerHandshakeCompleteCallback(Function handshakeCompleteHandler);
588 626
589 List<_ExternalBuffer> get buffers; 627 List<_ExternalBuffer> get buffers;
590 } 628 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698