diff options
author | k clair <kclair@riseup.net> | 2012-10-09 12:14:18 -0700 |
---|---|---|
committer | k clair <kclair@riseup.net> | 2012-10-09 12:14:18 -0700 |
commit | 115994cef3e454c2a197a28e02b19bf343aafc16 (patch) | |
tree | e3a8c3e2fbc0f3c9f2e74f62cae25b4df6237ed3 /gnutls-1.1.9/examples/twisted-client.py | |
parent | 7ebbbaaeef0ded0f39b8bf863ee7fd324b19c9f9 (diff) |
add already generated debian policy files and debian package files
Diffstat (limited to 'gnutls-1.1.9/examples/twisted-client.py')
-rwxr-xr-x | gnutls-1.1.9/examples/twisted-client.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/gnutls-1.1.9/examples/twisted-client.py b/gnutls-1.1.9/examples/twisted-client.py new file mode 100755 index 0000000..0bcb8ca --- /dev/null +++ b/gnutls-1.1.9/examples/twisted-client.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python + +"""Asynchronous client using Twisted with GNUTLS""" + +import sys +import os + +from twisted.internet.protocol import ClientFactory +from twisted.protocols.basic import LineOnlyReceiver +from twisted.internet import reactor + +from gnutls.constants import * +from gnutls.crypto import * +from gnutls.errors import * +from gnutls.interfaces.twisted import X509Credentials + +class EchoProtocol(LineOnlyReceiver): + + def connectionMade(self): + self.sendLine('echo') + + def lineReceived(self, line): + print 'received: ', line + self.transport.loseConnection() + + def connectionLost(self, reason): + reactor.stop() + +class EchoFactory(ClientFactory): + protocol = EchoProtocol + + def clientConnectionFailed(self, connector, err): + print err.value + reactor.stop() + + +script_path = os.path.realpath(os.path.dirname(sys.argv[0])) +certs_path = os.path.join(script_path, 'certs') + +cert = X509Certificate(open(certs_path + '/valid.crt').read()) +key = X509PrivateKey(open(certs_path + '/valid.key').read()) +ca = X509Certificate(open(certs_path + '/ca.pem').read()) +crl = X509CRL(open(certs_path + '/crl.pem').read()) +cred = X509Credentials(cert, key, [ca]) +cred.verify_peer = True + +reactor.connectTLS('localhost', 10000, EchoFactory(), cred) +reactor.run() + |