Re: [Twisted-Python] Aborting a connection attempt when HTTPS client detected on HTTP only server?

2013-02-28 Thread Michael Schlenker
Am 11.02.2013 15:51, schrieb Itamar Turner-Trauring:
> 
> 
> On Mon, Feb 11, 2013 at 9:24 AM, Michael Schlenker  > wrote:
> 
> Is there some pre-made solution, or would i have to hook into the
> connection setup of twisted.web and check the first few bytes for the
> signs of an SSL Handshake signature?
> 
> 
> Subclassing the HTTP protocol class and just adding a check in
> dataReceived is probably the easiest thing to do, yes. Might be worth
> filing a ticket for this as well. My guess is the logic would be
> something like "in dataReceived, if you've not hit first line, and any
> byte is non-ASCII, close connection", which has the nice property of
> being more general than just SSL. Or perhaps check what Apache does exactly.
> 
Okay, solved it like this:

from twisted.web import server, http

class HTTPChannel(http.HTTPChannel):
"""
HTTP Channel that recognizes connection attempts via non-HTTP
and closes the connection in such cases.
"""

def __init__(self):
http.HTTPChannel.__init__(self)
self.__request_line_received = False

def lineReceived(self, line):
self.__request_line_received = True
http.HTTPChannel.lineReceived(self, line)

def dataReceived(self, data):
if not self.__request_line_received:
# check for any binary garbage, e.g. not ASCII
# e.g. ssl connection attempt
try:
data.decode('ascii')
except UnicodeDecodeError:
return self.transport.loseConnection()
http.HTTPChannel.dataReceived(self, data)


class Site(server.Site):
protocol = HTTPChannel


Works fine. Thx for the suggestion to check for ASCII.

Michael

-- 
Michael Schlenker
Software Architect

CONTACT Software GmbH   Tel.:   +49 (421) 20153-80
Wiener Straße 1-3   Fax:+49 (421) 20153-41
28359 Bremen
http://www.contact.de/  E-Mail: m...@contact.de

Sitz der Gesellschaft: Bremen
Geschäftsführer: Karl Heinz Zachries, Ralf Holtgrefe
Eingetragen im Handelsregister des Amtsgerichts Bremen unter HRB 13215

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


[Twisted-Python] How to dispatch message to different servers

2013-02-28 Thread Benjamin BERTRAND
Hi,

I have to replace a piece of software that sniffs the traffic on one interface. 
It gets different messages that are each associated to a specific emitter.
On the same machine, one server is started for each emitter (on a different 
port).
And the application is just supposed to use the proper server to send the 
messages captured (to a client on another machine).

Not sure if it's clear, but basically if I have 2 emitters A and B, I'll start 
2 servers (a and b).
My sniffer will get messages A1, A2, B1, B2, B3...
I have to pass messages A1, A2 to server a, that will just send them to the 
client (if it is connected of course).
And B1, B2, B3 to server b.
I don't need any buffering. If no client is connected, messages captured are 
just discarded.

To sniff the network, I want to use pylibpcap or pcapy.
I found this example to make it work with twisted: 
http://dound.com/2009/09/integrating-twisted-with-a-pcap-based-python-packet-sniffer/

Starting several servers that use the same protocol is not a problem.
But how do I pass the messages captured to the right server?
How do I make the link between the function sniffing the network and the 
servers?

Thanks

Benjamin
___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


[Twisted-Python] Need help regarding Gsoc 2013

2013-02-28 Thread Saurabh Mahindre
I am an undergraduate student and plan to try for a project with
twisted.I went through the gsoc wiki page for twisted and I have picked
up some ideas
I need some help as to how I can follow up on them or get new ones?
I will be thankful for any help or criticism as i am new to this process.
___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python