Fragment and send message through socket
(self, msg, randomizeFirstBlock=True, update_hashes=True)
| 910 | self.sock.buffer_writes = False |
| 911 | |
| 912 | def _sendMsg(self, msg, randomizeFirstBlock=True, update_hashes=True): |
| 913 | """Fragment and send message through socket""" |
| 914 | #Whenever we're connected and asked to send an app data message, |
| 915 | #we first send the first byte of the message. This prevents |
| 916 | #an attacker from launching a chosen-plaintext attack based on |
| 917 | #knowing the next IV (a la BEAST). |
| 918 | if randomizeFirstBlock and self.version <= (3, 1) \ |
| 919 | and self._recordLayer.isCBCMode() \ |
| 920 | and msg.contentType == ContentType.application_data: |
| 921 | msgFirstByte = msg.splitFirstByte() |
| 922 | for result in self._sendMsgThroughSocket(msgFirstByte): |
| 923 | yield result |
| 924 | if len(msg.write()) == 0: |
| 925 | return |
| 926 | |
| 927 | buf = msg.write() |
| 928 | contentType = msg.contentType |
| 929 | #Update handshake hashes |
| 930 | if update_hashes and contentType == ContentType.handshake: |
| 931 | self._handshake_hash.update(buf) |
| 932 | |
| 933 | #Fragment big messages |
| 934 | while len(buf) > self.recordSize: |
| 935 | newB = buf[:self.recordSize] |
| 936 | buf = buf[self.recordSize:] |
| 937 | |
| 938 | msgFragment = Message(contentType, newB) |
| 939 | for result in self._sendMsgThroughSocket(msgFragment): |
| 940 | yield result |
| 941 | |
| 942 | msgFragment = Message(contentType, buf) |
| 943 | for result in self._sendMsgThroughSocket(msgFragment): |
| 944 | yield result |
| 945 | |
| 946 | def _queue_message(self, msg): |
| 947 | """Just queue message for sending, for record layer coalescing.""" |
no test coverage detected