Skip to content

Commit

Permalink
Merge pull request #157 from eayin2/patch-1
Browse files Browse the repository at this point in the history
Create tunnel_tls_through_tor_client.py
  • Loading branch information
meejah committed Feb 11, 2016
2 parents 99eb0d4 + 69ca40f commit 4f4a0f0
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions examples/tunnel_tls_through_tor_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

from twisted.internet.task import react
from twisted.internet.defer import inlineCallbacks
from twisted.internet.endpoints import TCP4ClientEndpoint
from twisted.python.filepath import FilePath
from twisted.internet import ssl, task, protocol, endpoints, defer
from twisted.python.modules import getModule
from txsocksx.tls import TLSWrapClientEndpoint
import txtorcon

import other_proto


@defer.inlineCallbacks
def main(reactor):
factory = protocol.Factory.forProtocol(other_proto.DecisionProtocol)
ca_data = FilePath(b'ca_cert.pem').getContent()
client_data = FilePath(b'a.client.pem').getContent()
ca_cert = ssl.Certificate.loadPEM(ca_data)
client_key = ssl.PrivateCertificate.loadPEM(client_data)
options = ssl.optionsForClientTLS(u'the-authority', ca_cert, client_key)
exampleEndpoint = txtorcon.TorClientEndpoint(ip, 8966, socks_hostname="127.0.0.1")
tlsEndpoint = TLSWrapClientEndpoint(options, exampleEndpoint)
deferred = yield tlsEndpoint.connect(factory)
done = defer.Deferred()
deferred.connectionLost = lambda reason: done.callback(None)
yield done


task.react(main)

0 comments on commit 4f4a0f0

Please sign in to comment.