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 patch class SecureSocket { | 5 patch class SecureSocket { |
| 6 /* patch */ factory SecureSocket._(RawSecureSocket rawSocket) => | 6 /* patch */ factory SecureSocket._(RawSecureSocket rawSocket) => |
| 7 new _SecureSocket(rawSocket); | 7 new _SecureSocket(rawSocket); |
| 8 | 8 |
| 9 /* patch */ static void initialize({String database, | 9 /* patch */ static void initialize({String database, |
| 10 String password, | 10 String password, |
| 11 bool useBuiltinRoots: true}) | 11 bool useBuiltinRoots: true}) |
| 12 native "SecureSocket_InitializeLibrary"; | 12 native "SecureSocket_InitializeLibrary"; |
| 13 } | 13 } |
| 14 | 14 |
| 15 | 15 |
| 16 patch class _SecureFilter { | 16 patch class _SecureFilter { |
| 17 /* patch */ factory _SecureFilter() => new _SecureFilterImpl(); | 17 /* patch */ factory _SecureFilter() => new _SecureFilterImpl(); |
| 18 | |
| 19 /* patch */ static SendPort _newServicePort() | |
| 20 native "SecureSocket_NewServicePort"; | |
| 18 } | 21 } |
| 19 | 22 |
| 20 | 23 |
| 21 class _SecureSocket extends _Socket implements SecureSocket { | 24 class _SecureSocket extends _Socket implements SecureSocket { |
| 22 _SecureSocket(RawSecureSocket raw) : super(raw); | 25 _SecureSocket(RawSecureSocket raw) : super(raw); |
| 23 | 26 |
| 24 void set onBadCertificate(bool callback(X509Certificate certificate)) { | 27 void set onBadCertificate(bool callback(X509Certificate certificate)) { |
| 25 if (_raw == null) { | 28 if (_raw == null) { |
| 26 throw new StateError("onBadCertificate called on destroyed SecureSocket"); | 29 throw new StateError("onBadCertificate called on destroyed SecureSocket"); |
| 27 } | 30 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 42 * over an encrypted socket. The filter also handles the handshaking | 45 * over an encrypted socket. The filter also handles the handshaking |
| 43 * and certificate verification. | 46 * and certificate verification. |
| 44 * | 47 * |
| 45 * The filter exposes its input and output buffers as Dart objects that | 48 * The filter exposes its input and output buffers as Dart objects that |
| 46 * are backed by an external C array of bytes, so that both Dart code and | 49 * are backed by an external C array of bytes, so that both Dart code and |
| 47 * native code can access the same data. | 50 * native code can access the same data. |
| 48 */ | 51 */ |
| 49 class _SecureFilterImpl | 52 class _SecureFilterImpl |
| 50 extends NativeFieldWrapperClass1 | 53 extends NativeFieldWrapperClass1 |
| 51 implements _SecureFilter { | 54 implements _SecureFilter { |
| 55 // Performance is improved if a full buffer of plaintext fits | |
| 56 // in the encrypted buffer, when encrypted. | |
| 57 static final int SIZE = 8 * 1024; | |
| 58 static final int ENCRYPTED_SIZE = 10 * 1024; | |
| 59 | |
| 52 _SecureFilterImpl() { | 60 _SecureFilterImpl() { |
| 53 buffers = new List<_ExternalBuffer>(_RawSecureSocket.NUM_BUFFERS); | 61 buffers = new List<_ExternalBuffer>(_RawSecureSocket.NUM_BUFFERS); |
| 54 for (int i = 0; i < _RawSecureSocket.NUM_BUFFERS; ++i) { | 62 for (int i = 0; i < _RawSecureSocket.NUM_BUFFERS; ++i) { |
| 55 buffers[i] = new _ExternalBuffer(); | 63 buffers[i] = new _ExternalBuffer(_RawSecureSocket.isEncrypted(i) ? |
| 64 ENCRYPTED_SIZE : | |
| 65 SIZE); | |
| 56 } | 66 } |
| 57 } | 67 } |
| 58 | 68 |
| 59 void connect(String hostName, | 69 void connect(String hostName, |
| 60 int port, | 70 int port, |
| 61 bool is_server, | 71 bool is_server, |
| 62 String certificateName, | 72 String certificateName, |
| 63 bool requestClientCertificate, | 73 bool requestClientCertificate, |
| 64 bool requireClientCertificate, | 74 bool requireClientCertificate, |
| 65 bool sendClientCertificate) native "SecureSocket_Connect"; | 75 bool sendClientCertificate) native "SecureSocket_Connect"; |
| 66 | 76 |
| 67 void destroy() { | 77 void destroy() { |
| 68 buffers = null; | 78 buffers = null; |
| 69 _destroy(); | 79 _destroy(); |
| 70 } | 80 } |
| 71 | 81 |
| 72 void _destroy() native "SecureSocket_Destroy"; | 82 void _destroy() native "SecureSocket_Destroy"; |
| 73 | 83 |
| 74 void handshake() native "SecureSocket_Handshake"; | 84 void handshake() native "SecureSocket_Handshake"; |
| 75 | 85 |
| 76 void init() native "SecureSocket_Init"; | 86 void init() native "SecureSocket_Init"; |
| 77 | 87 |
| 78 X509Certificate get peerCertificate native "SecureSocket_PeerCertificate"; | 88 X509Certificate get peerCertificate native "SecureSocket_PeerCertificate"; |
| 79 | 89 |
| 80 int processBuffer(int bufferIndex) native "SecureSocket_ProcessBuffer"; | |
| 81 | |
| 82 void registerBadCertificateCallback(Function callback) | 90 void registerBadCertificateCallback(Function callback) |
| 83 native "SecureSocket_RegisterBadCertificateCallback"; | 91 native "SecureSocket_RegisterBadCertificateCallback"; |
| 84 | 92 |
| 85 void registerHandshakeCompleteCallback(Function handshakeCompleteHandler) | 93 void registerHandshakeCompleteCallback(Function handshakeCompleteHandler) |
| 86 native "SecureSocket_RegisterHandshakeCompleteCallback"; | 94 native "SecureSocket_RegisterHandshakeCompleteCallback"; |
| 87 | 95 |
| 96 int _pointer() native "SecureSocket_FilterPointer"; | |
|
Anders Johnsen
2013/06/14 06:54:41
Add comment that this is a security issue, as mirr
Bill Hesse
2013/06/14 08:55:02
Done.
| |
| 97 | |
| 88 List<_ExternalBuffer> buffers; | 98 List<_ExternalBuffer> buffers; |
| 89 } | 99 } |
| OLD | NEW |