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._isBufferEncrypted(i) ? |
| 64 ENCRYPTED_SIZE : |
| 65 SIZE); |
56 } | 66 } |
57 } | 67 } |
58 | 68 |
59 void connect(String hostName, | 69 void connect(String hostName, |
60 Uint8List sockaddrStorage, | 70 Uint8List sockaddrStorage, |
61 int port, | 71 int port, |
62 bool is_server, | 72 bool is_server, |
63 String certificateName, | 73 String certificateName, |
64 bool requestClientCertificate, | 74 bool requestClientCertificate, |
65 bool requireClientCertificate, | 75 bool requireClientCertificate, |
66 bool sendClientCertificate) native "SecureSocket_Connect"; | 76 bool sendClientCertificate) native "SecureSocket_Connect"; |
67 | 77 |
68 void destroy() { | 78 void destroy() { |
69 buffers = null; | 79 buffers = null; |
70 _destroy(); | 80 _destroy(); |
71 } | 81 } |
72 | 82 |
73 void _destroy() native "SecureSocket_Destroy"; | 83 void _destroy() native "SecureSocket_Destroy"; |
74 | 84 |
75 void handshake() native "SecureSocket_Handshake"; | 85 void handshake() native "SecureSocket_Handshake"; |
76 | 86 |
77 void init() native "SecureSocket_Init"; | 87 void init() native "SecureSocket_Init"; |
78 | 88 |
79 X509Certificate get peerCertificate native "SecureSocket_PeerCertificate"; | 89 X509Certificate get peerCertificate native "SecureSocket_PeerCertificate"; |
80 | 90 |
81 int processBuffer(int bufferIndex) native "SecureSocket_ProcessBuffer"; | |
82 | |
83 void registerBadCertificateCallback(Function callback) | 91 void registerBadCertificateCallback(Function callback) |
84 native "SecureSocket_RegisterBadCertificateCallback"; | 92 native "SecureSocket_RegisterBadCertificateCallback"; |
85 | 93 |
86 void registerHandshakeCompleteCallback(Function handshakeCompleteHandler) | 94 void registerHandshakeCompleteCallback(Function handshakeCompleteHandler) |
87 native "SecureSocket_RegisterHandshakeCompleteCallback"; | 95 native "SecureSocket_RegisterHandshakeCompleteCallback"; |
88 | 96 |
| 97 // This is a security issue, as it exposes a raw pointer to Dart code. |
| 98 int _pointer() native "SecureSocket_FilterPointer"; |
| 99 |
89 List<_ExternalBuffer> buffers; | 100 List<_ExternalBuffer> buffers; |
90 } | 101 } |
OLD | NEW |