]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix #12835: prevent use of the unencrypted sendmsg/recvmsg APIs on SSL wrapped socket...
authorNick Coghlan <ncoghlan@gmail.com>
Sat, 27 Aug 2011 14:00:27 +0000 (00:00 +1000)
committerNick Coghlan <ncoghlan@gmail.com>
Sat, 27 Aug 2011 14:00:27 +0000 (00:00 +1000)
Lib/ssl.py
Lib/test/test_ssl.py
Misc/NEWS

index 914e749928f307dd4e3fff1ec169c6eee7620065..39cef2c699b3f61aa07aa56026277eaa915cf64c 100644 (file)
@@ -355,6 +355,12 @@ class SSLSocket(socket):
         else:
             return socket.sendto(self, data, flags_or_addr, addr)
 
+    def sendmsg(self, *args, **kwargs):
+        # Ensure programs don't send data unencrypted if they try to
+        # use this method.
+        raise NotImplementedError("sendmsg not allowed on instances of %s" %
+                                  self.__class__)
+
     def sendall(self, data, flags=0):
         self._checkClosed()
         if self._sslobj:
@@ -413,6 +419,14 @@ class SSLSocket(socket):
         else:
             return socket.recvfrom_into(self, buffer, nbytes, flags)
 
+    def recvmsg(self, *args, **kwargs):
+        raise NotImplementedError("recvmsg not allowed on instances of %s" %
+                                  self.__class__)
+
+    def recvmsg_into(self, *args, **kwargs):
+        raise NotImplementedError("recvmsg_into not allowed on instances of "
+                                  "%s" % self.__class__)
+
     def pending(self):
         self._checkClosed()
         if self._sslobj:
index a4c177357fcb41423cb2760c4063c7987d546eed..e386325341d0d271a600937dd78a2a19e5dd87a7 100644 (file)
@@ -1651,6 +1651,14 @@ else:
                         # consume data
                         s.read()
 
+                # Make sure sendmsg et al are disallowed to avoid
+                # inadvertent disclosure of data and/or corruption
+                # of the encrypted data stream
+                self.assertRaises(NotImplementedError, s.sendmsg, [b"data"])
+                self.assertRaises(NotImplementedError, s.recvmsg, 100)
+                self.assertRaises(NotImplementedError,
+                                  s.recvmsg_into, bytearray(100))
+
                 s.write(b"over\n")
                 s.close()
             finally:
index e48902953db42a5d0f51dae9efd0df7e6d51652f..c0fa159adacc0f72caad9b2c2ce4a1c6db4c0e00 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -268,6 +268,10 @@ Core and Builtins
 Library
 -------
 
+- Issue #12835: Follow up to #6560 that unconditionally prevents use of the
+  unencrypted sendmsg/recvmsg APIs on SSL wrapped sockets. Patch by David
+  Watson.
+
 - Issue #12803: SSLContext.load_cert_chain() now accepts a password argument
   to be used if the private key is encrypted.  Patch by Adam Simpkins.