[Openlanhouse-development] SF.net SVN: openlanhouse:[290] trunk/openlh-core/src/OpenlhCore/net
Status: Pre-Alpha
Brought to you by:
n3rd3x
|
From: <n3...@us...> - 2008-10-11 17:29:20
|
Revision: 290
http://openlanhouse.svn.sourceforge.net/openlanhouse/?rev=290&view=rev
Author: n3rd3x
Date: 2008-10-11 17:29:12 +0000 (Sat, 11 Oct 2008)
Log Message:
-----------
Added Paths:
-----------
trunk/openlh-core/src/OpenlhCore/net/backends/
trunk/openlh-core/src/OpenlhCore/net/backends/__init__.py
trunk/openlh-core/src/OpenlhCore/net/backends/gnutls_backend.py
trunk/openlh-core/src/OpenlhCore/net/backends/openssl_backend.py
trunk/openlh-core/src/OpenlhCore/net/certgen/
trunk/openlh-core/src/OpenlhCore/net/certgen/__init__.py
trunk/openlh-core/src/OpenlhCore/net/certgen/base.py
trunk/openlh-core/src/OpenlhCore/net/certgen/gnutls_certgen.py
trunk/openlh-core/src/OpenlhCore/net/certgen/openssl_certgen.py
Added: trunk/openlh-core/src/OpenlhCore/net/backends/__init__.py
===================================================================
--- trunk/openlh-core/src/OpenlhCore/net/backends/__init__.py (rev 0)
+++ trunk/openlh-core/src/OpenlhCore/net/backends/__init__.py 2008-10-11 17:29:12 UTC (rev 290)
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2008 Wilson Pinto Júnior <wi...@op...>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+__all__ = ("gnutls_backend", "openssl_backend")
\ No newline at end of file
Added: trunk/openlh-core/src/OpenlhCore/net/backends/gnutls_backend.py
===================================================================
--- trunk/openlh-core/src/OpenlhCore/net/backends/gnutls_backend.py (rev 0)
+++ trunk/openlh-core/src/OpenlhCore/net/backends/gnutls_backend.py 2008-10-11 17:29:12 UTC (rev 290)
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2008 Wilson Pinto Júnior <wi...@op...>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import socket
+
+import gnutls
+import gnutls.crypto
+import gnutls.connection
+from gnutls import __version__ as GNUTLS_VERSION
+
+class ServerSession:
+ def __init__(self, session):
+ self.session = session
+
+ def __getattr__(self, name):
+ ## Generic wrapper for the underlying socket methods and attributes
+ return getattr(self.session, name)
+
+class ServerSessionFactory:
+
+ address_family = socket.AF_INET
+ socket_type = socket.SOCK_STREAM
+
+ def __init__(self, privkey_path, selfsigned_path):
+
+ self.cert = gnutls.crypto.X509Certificate(open(selfsigned_path).read())
+ self.key = gnutls.crypto.X509PrivateKey(open(privkey_path).read())
+
+ self.cred = gnutls.connection.X509Credentials(self.cert, self.key)
+
+ self.socket = socket.socket(self.address_family, self.socket_type)
+ self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+
+ self.session = gnutls.connection.ServerSessionFactory(self.socket,
+ self.cred)
+
+ def __getattr__(self, name):
+ ## Generic wrapper for the underlying socket methods and attributes
+ return getattr(self.session, name)
+
+ def accept(self):
+ new_session, address = self.session.accept()
+ session = ServerSession(new_session)
+ return (session, address)
\ No newline at end of file
Added: trunk/openlh-core/src/OpenlhCore/net/backends/openssl_backend.py
===================================================================
--- trunk/openlh-core/src/OpenlhCore/net/backends/openssl_backend.py (rev 0)
+++ trunk/openlh-core/src/OpenlhCore/net/backends/openssl_backend.py 2008-10-11 17:29:12 UTC (rev 290)
@@ -0,0 +1,65 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2008 Wilson Pinto Júnior <wi...@op...>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import socket
+
+from OpenSSL import SSL
+
+class ServerSession:
+ def __init__(self, session):
+ self.session = session
+
+ def __getattr__(self, name):
+ print 'ServerSession: getattr', name
+ ## Generic wrapper for the underlying socket methods and attributes
+ if hasattr(self.session, name):
+ return getattr(self.session, name)
+ else:
+ print "not found %s" % name
+
+ def makefile(self, *args):
+ pass
+
+ def handshake(self, *args):
+ pass
+
+class ServerSessionFactory:
+
+ address_family = socket.AF_INET
+ socket_type = socket.SOCK_STREAM
+
+ def __init__(self, privkey_path, selfsigned_path):
+
+ self.ctx = SSL.Context(SSL.TLSv1_METHOD)
+ self.ctx.use_privatekey_file (privkey_path)
+ self.ctx.use_certificate_file(selfsigned_path)
+
+ self.socket = socket.socket(self.address_family, self.socket_type)
+ self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+
+ self.session = SSL.Connection(self.ctx, self.socket)
+
+ def __getattr__(self, name):
+ ## Generic wrapper for the underlying socket methods and attributes
+ print 'ServerSessionFactory: getattr', name
+ return getattr(self.session, name)
+
+ def accept(self):
+ new_session, address = self.session.accept()
+ session = ServerSession(new_session)
+ return (session, address)
\ No newline at end of file
Added: trunk/openlh-core/src/OpenlhCore/net/certgen/__init__.py
===================================================================
--- trunk/openlh-core/src/OpenlhCore/net/certgen/__init__.py (rev 0)
+++ trunk/openlh-core/src/OpenlhCore/net/certgen/__init__.py 2008-10-11 17:29:12 UTC (rev 290)
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2008 Wilson Pinto J\xFAnior <wi...@op...>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+__all__ = ()
\ No newline at end of file
Added: trunk/openlh-core/src/OpenlhCore/net/certgen/base.py
===================================================================
--- trunk/openlh-core/src/OpenlhCore/net/certgen/base.py (rev 0)
+++ trunk/openlh-core/src/OpenlhCore/net/certgen/base.py 2008-10-11 17:29:12 UTC (rev 290)
@@ -0,0 +1,17 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2008 Wilson Pinto J\xFAnior <wi...@op...>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
\ No newline at end of file
Added: trunk/openlh-core/src/OpenlhCore/net/certgen/gnutls_certgen.py
===================================================================
--- trunk/openlh-core/src/OpenlhCore/net/certgen/gnutls_certgen.py (rev 0)
+++ trunk/openlh-core/src/OpenlhCore/net/certgen/gnutls_certgen.py 2008-10-11 17:29:12 UTC (rev 290)
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2008 Wilson Pinto Júnior <wi...@op...>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from OpenlhServer.utils import execute_command, is_in_path
+from OpenlhServer.globals import _
+
+CERTTOOL_PATH = is_in_path("certtool")
+
+def generate_keys(privkey_path, selfsigned_path, template_path,
+ bits, data):
+
+ if not CERTTOOL_PATH:
+ raise SystemError(_("certtool is not installed, please install it"))
+
+ cmd = [CERTTOOL_PATH, "--generate-privkey", "--bits", str(bits)]
+
+ (stdout, stderr, retval) = execute_command(cmd)
+
+ if retval != 0:
+ raise SystemError(stderr)
+ else:
+ print stdout, stderr, retval
+
+ print "Certtool:%s\nPrivkey:%s\nSelfSigned:%s\nTemplate:%s\nBits:%d\n" % (CERTTOOL_PATH, privkey_path,
+ selfsigned_path,
+ template_path,
+ bits)
\ No newline at end of file
Added: trunk/openlh-core/src/OpenlhCore/net/certgen/openssl_certgen.py
===================================================================
--- trunk/openlh-core/src/OpenlhCore/net/certgen/openssl_certgen.py (rev 0)
+++ trunk/openlh-core/src/OpenlhCore/net/certgen/openssl_certgen.py 2008-10-11 17:29:12 UTC (rev 290)
@@ -0,0 +1,17 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2008 Wilson Pinto J\xFAnior <wi...@op...>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|