OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 /** | 7 /** |
8 * A high-level class for communicating securely over a TCP socket, using | 8 * A high-level class for communicating securely over a TCP socket, using |
9 * TLS and SSL. The [SecureSocket] exposes both a [Stream] and an | 9 * TLS and SSL. The [SecureSocket] exposes both a [Stream] and an |
10 * [IOSink] interface, making it ideal for using together with | 10 * [IOSink] interface, making it ideal for using together with |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
455 Timer.run(_closeHandler); | 455 Timer.run(_closeHandler); |
456 } | 456 } |
457 } | 457 } |
458 | 458 |
459 return result; | 459 return result; |
460 } | 460 } |
461 | 461 |
462 // Write the data to the socket, and flush it as much as possible | 462 // Write the data to the socket, and flush it as much as possible |
463 // until it would block. If the write would block, _writeEncryptedData sets | 463 // until it would block. If the write would block, _writeEncryptedData sets |
464 // up handlers to flush the pipeline when possible. | 464 // up handlers to flush the pipeline when possible. |
465 int write(List<int> data, [int offset, int bytes]) { | 465 int write(List<int> data, [int offset, int bytes]) { |
Lasse Reichstein Nielsen
2013/04/11 06:11:55
This code doesn't seem to handle the case where of
floitsch
2013/04/12 23:35:42
Done.
| |
466 if (_closedWrite) { | 466 if (_closedWrite) { |
467 _controller.addError(new AsyncError(new SocketIOException( | 467 _controller.addError(new AsyncError(new SocketIOException( |
468 "Writing to a closed socket"))); | 468 "Writing to a closed socket"))); |
469 return 0; | 469 return 0; |
470 } | 470 } |
471 if (_status != CONNECTED) return 0; | 471 if (_status != CONNECTED) return 0; |
472 var buffer = _secureFilter.buffers[WRITE_PLAINTEXT]; | 472 var buffer = _secureFilter.buffers[WRITE_PLAINTEXT]; |
473 if (bytes > buffer.free) { | 473 if (bytes > buffer.free) { |
474 bytes = buffer.free; | 474 bytes = buffer.free; |
475 } | 475 } |
476 if (bytes > 0) { | 476 if (bytes > 0) { |
477 buffer.data.setRange(buffer.start + buffer.length, bytes, data, offset); | 477 int startIndex = buffer.start + buffer.length; |
478 buffer.data.setRange(startIndex, startIndex + bytes, data, offset); | |
478 buffer.length += bytes; | 479 buffer.length += bytes; |
479 } | 480 } |
480 _writeEncryptedData(); // Tries to flush all pipeline stages. | 481 _writeEncryptedData(); // Tries to flush all pipeline stages. |
481 return bytes; | 482 return bytes; |
482 } | 483 } |
483 | 484 |
484 X509Certificate get peerCertificate => _secureFilter.peerCertificate; | 485 X509Certificate get peerCertificate => _secureFilter.peerCertificate; |
485 | 486 |
486 bool setOption(SocketOption option, bool enabled) { | 487 bool setOption(SocketOption option, bool enabled) { |
487 if (_socket == null) return false; | 488 if (_socket == null) return false; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
653 int bytes = _secureFilter.processBuffer(READ_ENCRYPTED); | 654 int bytes = _secureFilter.processBuffer(READ_ENCRYPTED); |
654 if (bytes > 0) { | 655 if (bytes > 0) { |
655 encrypted.advanceStart(bytes); | 656 encrypted.advanceStart(bytes); |
656 progress = true; | 657 progress = true; |
657 } | 658 } |
658 } | 659 } |
659 if (!_socketClosedRead && encrypted.free > 0) { | 660 if (!_socketClosedRead && encrypted.free > 0) { |
660 List<int> data = _socket.read(encrypted.free); | 661 List<int> data = _socket.read(encrypted.free); |
661 if (data != null) { | 662 if (data != null) { |
662 int bytes = data.length; | 663 int bytes = data.length; |
663 encrypted.data.setRange(encrypted.start + encrypted.length, | 664 int startIndex = encrypted.start + encrypted.length; |
664 bytes, | 665 encrypted.data.setRange(startIndex, startIndex + bytes, data); |
665 data); | |
666 encrypted.length += bytes; | 666 encrypted.length += bytes; |
667 progress = true; | 667 progress = true; |
668 } | 668 } |
669 } | 669 } |
670 } | 670 } |
671 // If there is any data in any stages of the filter, there should | 671 // If there is any data in any stages of the filter, there should |
672 // be data in the plaintext buffer after this process. | 672 // be data in the plaintext buffer after this process. |
673 // TODO(whesse): Verify that this is true, and there can be no | 673 // TODO(whesse): Verify that this is true, and there can be no |
674 // partial encrypted block stuck in the secureFilter. | 674 // partial encrypted block stuck in the secureFilter. |
675 _filterReadEmpty = (plaintext.length == 0); | 675 _filterReadEmpty = (plaintext.length == 0); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
753 void destroy(); | 753 void destroy(); |
754 void handshake(); | 754 void handshake(); |
755 void init(); | 755 void init(); |
756 X509Certificate get peerCertificate; | 756 X509Certificate get peerCertificate; |
757 int processBuffer(int bufferIndex); | 757 int processBuffer(int bufferIndex); |
758 void registerBadCertificateCallback(Function callback); | 758 void registerBadCertificateCallback(Function callback); |
759 void registerHandshakeCompleteCallback(Function handshakeCompleteHandler); | 759 void registerHandshakeCompleteCallback(Function handshakeCompleteHandler); |
760 | 760 |
761 List<_ExternalBuffer> get buffers; | 761 List<_ExternalBuffer> get buffers; |
762 } | 762 } |
OLD | NEW |