diff options
author | Ng Pheng Siong <ngps@netmemetic.com> | 2002-12-23 05:29:56 +0000 |
---|---|---|
committer | Ng Pheng Siong <ngps@netmemetic.com> | 2002-12-23 05:29:56 +0000 |
commit | 4c181a24ff5a234d28857d6592d2090705b3b8f6 (patch) | |
tree | d3f8cebe71dbbafb9d9134f32bdc02144d3ca451 /contrib | |
parent | 3f7d9ae75837b3f792da27979f41ca4a775298fb (diff) | |
download | m2crypto-4c181a24ff5a234d28857d6592d2090705b3b8f6.tar.gz |
*** empty log message ***
git-svn-id: http://svn.osafoundation.org/m2crypto/trunk@142 2715db39-9adf-0310-9c64-84f055769b4b
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/README | 13 | ||||
-rw-r--r-- | contrib/dispatcher.README | 30 | ||||
-rw-r--r-- | contrib/dispatcher.py | 191 | ||||
-rw-r--r-- | contrib/m2crypto.spec | 46 |
4 files changed, 280 insertions, 0 deletions
diff --git a/contrib/README b/contrib/README new file mode 100644 index 0000000..956d0cc --- /dev/null +++ b/contrib/README @@ -0,0 +1,13 @@ +------------- + 03 Jun 2001 +------------- + +This directory contains contributions by users of M2Crypto. Some of these +may get folded into the main distribution in time. + + +- dispatcher.py by Ilya Etingof <ilya@glas.net>. + +- m2crypto.spec by Sean Reifschneider <jafo-rpms@tummy.com>. + + diff --git a/contrib/dispatcher.README b/contrib/dispatcher.README new file mode 100644 index 0000000..3049a5e --- /dev/null +++ b/contrib/dispatcher.README @@ -0,0 +1,30 @@ +Date: Thu, 31 May 2001 17:11:45 +0400 (MSD) +From: Ilya Etingof <ilya@glas.net> +To: ngps@post1.com +Cc: Ilya Etingof <ilya@glas.net> +Subject: Another kind of non-blocking SSL dispatcher + +--1922505501-409592217-991314705=:1995 +Content-Type: TEXT/PLAIN; charset=US-ASCII + + +Hi, + +Thanks for writing M2Crypto! + +I've been trying to use the ssl_dispatcher.py though I felt like the +bundled version is not absolutely non-blocking. Precisely, it looks +like the Connection.connect() method does not handle the case when +socket.connect() returns the WOULDBLOCK error. Another suspicious thing +is that there seems to be no SSL "want read" and "want write" error +return codes of SSL read and write functions. + +The attached [quick and dirty] code hopefully fixes these two +problems. Please, let me know if I'm missing some important clue about all +this. + +Thanks, +ilya + +--1922505501-409592217-991314705=:1995 + diff --git a/contrib/dispatcher.py b/contrib/dispatcher.py new file mode 100644 index 0000000..6e7302d --- /dev/null +++ b/contrib/dispatcher.py @@ -0,0 +1,191 @@ +#!/usr/local/bin/python -O
+"""
+ Implements a [hopefully] non-blocking SSL dispatcher on top of
+ M2Crypto package.
+
+ Written by Ilya Etingof <ilya@glas.net>, 05/2001
+"""
+import asyncore, socket
+
+# M2Crypto
+from M2Crypto import SSL
+
+class _nb_connection (SSL.Connection):
+ """Functional equivalent of SSL.Connection class. Facilitates
+ possibly delayed socket.connect() and socket.accept()
+ termination.
+ """
+ def __init__ (self, ctx, sock):
+ SSL.Connection.__init__ (self, ctx, sock)
+
+ def connect(self, addr):
+ self._setup_ssl(addr)
+ return self._check_ssl_return(SSL.m2.ssl_connect(self.ssl))
+
+ def accept(self, addr):
+ self._setup_ssl(addr)
+ self.accept_ssl()
+
+class dispatcher(asyncore.dispatcher_with_send):
+ """A non-blocking SSL dispatcher that mimics the
+ asyncode.dispatcher API.
+ """
+ def __init__ (self, cert, key, sock=None, serving=None):
+ asyncore.dispatcher_with_send.__init__ (self)
+
+ self.__serving = serving
+
+ # XXX
+ if sock:
+ if self.__serving:
+ self.set_socket(sock)
+ else:
+ self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
+
+ self.ctx = SSL.Context('sslv23')
+ self.ctx.set_verify(SSL.verify_none, 10)
+ self.ctx.load_cert(cert, key)
+ self.ctx.set_info_callback()
+
+ self.ssl = _nb_connection(self.ctx, self.socket)
+
+ self.__output = ''
+ self.__want_write = 1
+
+ #
+ # The following are asyncore overloaded methods
+ #
+
+ def handle_connect (self):
+ """Initiate SSL connection negotiation
+ """
+ if self.__serving:
+ self.ssl.accept (self.addr)
+
+ self.peer = self.ssl.get_peer_cert()
+
+ self.handle_ssl_accept()
+
+ else:
+ self.ssl.connect (self.addr)
+
+ self.handle_ssl_connect()
+
+ def handle_read(self):
+ """Read user and/or SSL protocol data from SSL connection
+ """
+ ret = self.ssl._read_nbio()
+
+ if ret:
+ self.handle_ssl_read(ret)
+ else:
+ # Assume write is wanted
+ self.__want_write = 1
+
+ def handle_write(self):
+ """Write pending user and/or SSL protocol data down to SSL
+ connection
+ """
+ self.__want_write = 0
+
+ ret = self.ssl._write_nbio(self.__output)
+
+ if ret < 0:
+ try:
+ err = SSL.m2.ssl_get_error(self.ssl.ssl, ret)
+
+ except SSL.SSLError:
+ return
+
+ if err == SSL.m2.ssl_error_want_write:
+ self.__want_write = 1
+ else:
+ self.__output = self.__output[ret:]
+
+ def writable (self):
+ """Indicate that write is desired if here're some
+ user and/or SSL protocol data.
+ """
+ if self.__output or self.__want_write:
+ return 1
+
+ return self.ssl_writable()
+
+ def handle_close (self):
+ """Shutdown SSL connection.
+ """
+ self.ssl = None
+
+ self.ctx = None
+ self.close ()
+
+ self.handle_ssl_close()
+
+ def handle_error (self, *info):
+ """A trap for asyncore errors
+ """
+ self.handle_ssl_error(info)
+
+ #
+ # The following are ssl.dispatcher API
+ #
+
+ def ssl_connect(self, server):
+ """Initiate SSL connection
+ """
+ self.connect(server)
+
+ def ssl_write(self, data):
+ """Write data to SSL connection
+ """
+ self.__output = self.__output + data
+
+ def ssl_close(self):
+ """Close SSL connection
+ """
+ self.handle_close()
+
+ def handle_ssl_connect(self):
+ """Invoked on SSL connection establishment (whilst
+ in client mode)
+ """
+ print 'Unhandled handle_ssl_connect()'
+
+ def handle_ssl_accept(self):
+ """Invoked on SSL connection establishment (whilst
+ in server mode)
+ """
+ print 'Unhandled handle_ssl_accept()'
+
+ def handle_ssl_read(self, data):
+ """Invoked on new data arrival to SSL connection
+ """
+ print 'Unhandled handle_ssl_read event'
+
+ def handle_ssl_close(self):
+ """Invoked on SSL connection termination
+ """
+ pass
+
+ def ssl_writable(self):
+ """Invoked prior to every select() call
+ """
+ return 0
+
+if __name__=='__main__':
+ """Give it a test run
+ """
+ class client(dispatcher):
+ """SSL client class
+ """
+ def __init__ (self, cert, key):
+ dispatcher.__init__(self, cert, key)
+
+ def handle_ssl_read(self, data):
+ print data
+ self.ssl_write('test write')
+
+ ssl = client('test.cert', 'test.key')
+ ssl.ssl_connect(('localhost', 7777))
+
+ asyncore.loop()
diff --git a/contrib/m2crypto.spec b/contrib/m2crypto.spec new file mode 100644 index 0000000..f80cddb --- /dev/null +++ b/contrib/m2crypto.spec @@ -0,0 +1,46 @@ +%define name m2crypto +%define version 0.06 +%define snap snap5 +%define release %{snap}.1 +%define prefix %{_prefix} + +Summary: Python crypto library +Name: %{name} +Version: %{version} +Release: %{release} +Copyright: tummy.com, ltd. +Group: Applications/Crypto +Source: %{name}-%{version}-%{snap}.zip +Packager: Sean Reifschneider <jafo-rpms@tummy.com> +BuildRoot: /var/tmp/%{name}-root +Requires: openssl >= 0.9.6a +Patch0: m2crypto-makefile.patch +BuildPrereq: openssl-devel >= 0.9.6a +BuildPrereq: swig >= 1.1p5 + +%description +M2Crypto makes available to the Python programmer the following: + + RSA, DH, DSA, HMACs, message digests, symmetric ciphers. + SSL functionality to implement clients and servers. + HTTPS extensions to Python's httplib, urllib, and the eff-bot's xmlrpclib. + S/MIME v2. + +%prep +%setup -n %{name}-%{version}-%{snap} +%patch0 -p1 +%build +( cd swig; make -f Makefile.py1 ) + +%install +[ -n "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != / ] && rm -rf "$RPM_BUILD_ROOT" +mkdir -p "$RPM_BUILD_ROOT"/usr/lib/python1.5/site-packages +cp -a M2Crypto "$RPM_BUILD_ROOT"/usr/lib/python1.5/site-packages + +%clean +[ -n "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != / ] && rm -rf "$RPM_BUILD_ROOT" + +%files +%defattr(755,root,root) +%doc BUGS CHANGES INSTALL LICENCE README STORIES doc demo tests patches +/usr/lib/python1.5/site-packages |