pkgsrc-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS commit: pkgsrc/net/mitmproxy



Module Name:    pkgsrc
Committed By:   leot
Date:           Sun Jul 21 12:16:29 UTC 2019

Modified Files:
        pkgsrc/net/mitmproxy: Makefile distinfo
        pkgsrc/net/mitmproxy/patches:
            patch-mitmproxy_proxy_protocol_websocket.py

Log Message:
mitmproxy: Fix support with newer py-wsproto

Backport upstream commit 106948d996d74bf5ff7e3511f35eefea0a90561f
(except setup.py change) to fix support with py-wsproto 0.13.0 and newer.

PKGREVISION++


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 pkgsrc/net/mitmproxy/Makefile
cvs rdiff -u -r1.16 -r1.17 pkgsrc/net/mitmproxy/distinfo
cvs rdiff -u -r1.1 -r1.2 \
    pkgsrc/net/mitmproxy/patches/patch-mitmproxy_proxy_protocol_websocket.py

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/net/mitmproxy/Makefile
diff -u pkgsrc/net/mitmproxy/Makefile:1.25 pkgsrc/net/mitmproxy/Makefile:1.26
--- pkgsrc/net/mitmproxy/Makefile:1.25  Fri Apr 26 13:14:08 2019
+++ pkgsrc/net/mitmproxy/Makefile       Sun Jul 21 12:16:28 2019
@@ -1,7 +1,7 @@
-# $NetBSD: Makefile,v 1.25 2019/04/26 13:14:08 maya Exp $
+# $NetBSD: Makefile,v 1.26 2019/07/21 12:16:28 leot Exp $
 
 DISTNAME=      mitmproxy-4.0.4
-PKGREVISION=   2
+PKGREVISION=   3
 CATEGORIES=    net
 MASTER_SITES=  ${MASTER_SITE_GITHUB:=mitmproxy/}
 GITHUB_TAG=    v${PKGVERSION_NOREV}

Index: pkgsrc/net/mitmproxy/distinfo
diff -u pkgsrc/net/mitmproxy/distinfo:1.16 pkgsrc/net/mitmproxy/distinfo:1.17
--- pkgsrc/net/mitmproxy/distinfo:1.16  Mon Apr 15 10:19:04 2019
+++ pkgsrc/net/mitmproxy/distinfo       Sun Jul 21 12:16:28 2019
@@ -1,7 +1,7 @@
-$NetBSD: distinfo,v 1.16 2019/04/15 10:19:04 leot Exp $
+$NetBSD: distinfo,v 1.17 2019/07/21 12:16:28 leot Exp $
 
 SHA1 (mitmproxy-4.0.4.tar.gz) = 67871cbf7751d34d254ccc733f5e2cd23fbe8faf
 RMD160 (mitmproxy-4.0.4.tar.gz) = d4935a325081544ef0cc9b5551d5eb976ce21777
 SHA512 (mitmproxy-4.0.4.tar.gz) = e08ea8b1c75a95b822c463625509037bbc8a979161cacaa1f0185f98df8d6d7e5400925365dbbe70d18751251b1005824f739a8cd035c0389f7b4aea562adfb3
 Size (mitmproxy-4.0.4.tar.gz) = 27131713 bytes
-SHA1 (patch-mitmproxy_proxy_protocol_websocket.py) = 83337b732b156707308506fe9378571e0d2711bc
+SHA1 (patch-mitmproxy_proxy_protocol_websocket.py) = 3a3a67daa4190a150070cf44b007f8b97bee9278

Index: pkgsrc/net/mitmproxy/patches/patch-mitmproxy_proxy_protocol_websocket.py
diff -u pkgsrc/net/mitmproxy/patches/patch-mitmproxy_proxy_protocol_websocket.py:1.1 pkgsrc/net/mitmproxy/patches/patch-mitmproxy_proxy_protocol_websocket.py:1.2
--- pkgsrc/net/mitmproxy/patches/patch-mitmproxy_proxy_protocol_websocket.py:1.1        Mon Apr 15 10:19:55 2019
+++ pkgsrc/net/mitmproxy/patches/patch-mitmproxy_proxy_protocol_websocket.py    Sun Jul 21 12:16:28 2019
@@ -1,10 +1,11 @@
-$NetBSD: patch-mitmproxy_proxy_protocol_websocket.py,v 1.1 2019/04/15 10:19:55 leot Exp $
+$NetBSD: patch-mitmproxy_proxy_protocol_websocket.py,v 1.2 2019/07/21 12:16:28 leot Exp $
 
-Adjust for py-wsproto 0.13.0.
+Backport upstream commit 106948d996d74bf5ff7e3511f35eefea0a90561f
+(minus setup.py change) to fix support with py-wsproto 0.13.0.
 
 --- mitmproxy/proxy/protocol/websocket.py.orig 2018-07-31 12:01:45.000000000 +0000
 +++ mitmproxy/proxy/protocol/websocket.py
-@@ -4,8 +4,8 @@ from OpenSSL import SSL
+@@ -4,8 +4,9 @@ from OpenSSL import SSL
  
  
  import wsproto
@@ -12,6 +13,156 @@ Adjust for py-wsproto 0.13.0.
 -from wsproto.connection import ConnectionType, WSConnection
 +from wsproto import events, WSConnection
 +from wsproto.connection import ConnectionType
++from wsproto.events import AcceptConnection, CloseConnection, Message, Ping, Request
  from wsproto.extensions import PerMessageDeflate
  
  from mitmproxy import exceptions
+@@ -56,47 +57,44 @@ class WebSocketLayer(base.Layer):
+         if 'Sec-WebSocket-Extensions' in handshake_flow.response.headers:
+             if PerMessageDeflate.name in handshake_flow.response.headers['Sec-WebSocket-Extensions']:
+                 extensions = [PerMessageDeflate()]
+-        self.connections[self.client_conn] = WSConnection(ConnectionType.SERVER,
+-                                                          extensions=extensions)
+-        self.connections[self.server_conn] = WSConnection(ConnectionType.CLIENT,
+-                                                          host=handshake_flow.request.host,
+-                                                          resource=handshake_flow.request.path,
+-                                                          extensions=extensions)
++        self.connections[self.client_conn] = WSConnection(ConnectionType.SERVER)
++        self.connections[self.server_conn] = WSConnection(ConnectionType.CLIENT)
++
+         if extensions:
+-            for conn in self.connections.values():
+-                conn.extensions[0].finalize(conn, handshake_flow.response.headers['Sec-WebSocket-Extensions'])
++            extensions[0].finalize(handshake_flow.response.headers['Sec-WebSocket-Extensions'])
+ 
+-        data = self.connections[self.server_conn].bytes_to_send()
+-        self.connections[self.client_conn].receive_bytes(data)
++        request = Request(extensions = extensions, host = handshake_flow.request.host, target = handshake_flow.request.path)
++        data = self.connections[self.server_conn].send(request)
++        self.connections[self.client_conn].receive_data(data)
+ 
+         event = next(self.connections[self.client_conn].events())
+-        assert isinstance(event, events.ConnectionRequested)
++        assert isinstance(event, events.Request)
+ 
+-        self.connections[self.client_conn].accept(event)
+-        self.connections[self.server_conn].receive_bytes(self.connections[self.client_conn].bytes_to_send())
+-        assert isinstance(next(self.connections[self.server_conn].events()), events.ConnectionEstablished)
++        data = self.connections[self.client_conn].send(AcceptConnection(extensions=extensions))
++        self.connections[self.server_conn].receive_data(data)
++        assert isinstance(next(self.connections[self.server_conn].events()), events.AcceptConnection)
+ 
+     def _handle_event(self, event, source_conn, other_conn, is_server):
+-        if isinstance(event, events.DataReceived):
+-            return self._handle_data_received(event, source_conn, other_conn, is_server)
+-        elif isinstance(event, events.PingReceived):
+-            return self._handle_ping_received(event, source_conn, other_conn, is_server)
+-        elif isinstance(event, events.PongReceived):
+-            return self._handle_pong_received(event, source_conn, other_conn, is_server)
+-        elif isinstance(event, events.ConnectionClosed):
+-            return self._handle_connection_closed(event, source_conn, other_conn, is_server)
++        if isinstance(event, events.Message):
++            return self._handle_message(event, source_conn, other_conn, is_server)
++        elif isinstance(event, events.Ping):
++            return self._handle_ping(event, source_conn, other_conn, is_server)
++        elif isinstance(event, events.Pong):
++            return self._handle_pong(event, source_conn, other_conn, is_server)
++        elif isinstance(event, events.CloseConnection):
++            return self._handle_close_connection(event, source_conn, other_conn, is_server)
+ 
+         # fail-safe for unhandled events
+         return True  # pragma: no cover
+ 
+-    def _handle_data_received(self, event, source_conn, other_conn, is_server):
++    def _handle_message(self, event, source_conn, other_conn, is_server):
+         fb = self.server_frame_buffer if is_server else self.client_frame_buffer
+         fb.append(event.data)
+ 
+         if event.message_finished:
+             original_chunk_sizes = [len(f) for f in fb]
+ 
+-            if isinstance(event, events.TextReceived):
++            if isinstance(event, events.TextMessage):
+                 message_type = wsproto.frame_protocol.Opcode.TEXT
+                 payload = ''.join(fb)
+             else:
+@@ -127,19 +125,20 @@ class WebSocketLayer(base.Layer):
+                             yield (payload[i:i + chunk_size], True if i + chunk_size >= len(payload) else False)
+ 
+                 for chunk, final in get_chunk(websocket_message.content):
+-                    self.connections[other_conn].send_data(chunk, final)
+-                    other_conn.send(self.connections[other_conn].bytes_to_send())
++                    data = self.connections[other_conn].send(Message(data = chunk, message_finished = final))
++                    other_conn.send(data)
+ 
+         if self.flow.stream:
+-            self.connections[other_conn].send_data(event.data, event.message_finished)
+-            other_conn.send(self.connections[other_conn].bytes_to_send())
++            data = self.connections[other_conn].send(Message(data = event.data, message_finished = event.message_finished))
++            other_conn.send(data)
+         return True
+ 
+-    def _handle_ping_received(self, event, source_conn, other_conn, is_server):
+-        # PING is automatically answered with a PONG by wsproto
+-        self.connections[other_conn].ping()
+-        other_conn.send(self.connections[other_conn].bytes_to_send())
+-        source_conn.send(self.connections[source_conn].bytes_to_send())
++    def _handle_ping(self, event, source_conn, other_conn, is_server):
++        # Use event.response to create the approprate Pong response
++        data = self.connections[other_conn].send(Ping())
++        other_conn.send(data)
++        data = self.connections[source_conn].send(event.response())
++        source_conn.send(data)
+         self.log(
+             "Ping Received from {}".format("server" if is_server else "client"),
+             "info",
+@@ -147,7 +146,7 @@ class WebSocketLayer(base.Layer):
+         )
+         return True
+ 
+-    def _handle_pong_received(self, event, source_conn, other_conn, is_server):
++    def _handle_pong(self, event, source_conn, other_conn, is_server):
+         self.log(
+             "Pong Received from {}".format("server" if is_server else "client"),
+             "info",
+@@ -155,14 +154,15 @@ class WebSocketLayer(base.Layer):
+         )
+         return True
+ 
+-    def _handle_connection_closed(self, event, source_conn, other_conn, is_server):
++    def _handle_close_connection(self, event, source_conn, other_conn, is_server):
+         self.flow.close_sender = "server" if is_server else "client"
+         self.flow.close_code = event.code
+         self.flow.close_reason = event.reason
+ 
+-        self.connections[other_conn].close(event.code, event.reason)
+-        other_conn.send(self.connections[other_conn].bytes_to_send())
+-        source_conn.send(self.connections[source_conn].bytes_to_send())
++        data = self.connections[other_conn].send(CloseConnection(code=event.code, reason=event.reason))
++        other_conn.send(data)
++        data = self.connections[source_conn].send(event.response())
++        source_conn.send(data)
+ 
+         return False
+ 
+@@ -170,8 +170,7 @@ class WebSocketLayer(base.Layer):
+         while True:
+             try:
+                 payload = message_queue.get_nowait()
+-                self.connections[endpoint].send_data(payload, final=True)
+-                data = self.connections[endpoint].bytes_to_send()
++                data = self.connections[endpoint].send(Message(data = payload, message_finished = True))
+                 endpoint.send(data)
+             except queue.Empty:
+                 break
+@@ -197,8 +196,8 @@ class WebSocketLayer(base.Layer):
+                     is_server = (source_conn == self.server_conn)
+ 
+                     frame = websockets.Frame.from_file(source_conn.rfile)
+-                    self.connections[source_conn].receive_bytes(bytes(frame))
+-                    source_conn.send(self.connections[source_conn].bytes_to_send())
++                    data = self.connections[source_conn].receive_data(bytes(frame))
++                    source_conn.send(data)
+ 
+                     if close_received:
+                         return



Home | Main Index | Thread Index | Old Index