adds basic files and exception classes.

This commit is contained in:
Moisés Guimarães 2016-09-04 18:31:53 -03:00
parent d6a6226c8e
commit f4d6890b51
11 changed files with 418 additions and 0 deletions

@ -0,0 +1,26 @@
[ "$(whoami)" != "root" ] && echo "Sorry, you are not root." && exit 1
rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-6.noarch.rpm
yum update
yum install -y git autoconf libtool
git clone https://github.com/wolfssl/wolfssl.git
[ $? -ne 0 ] && echo "\n\nCouldn't download wolfssl.\n\n" && exit 1
pushd wolfssl
./autogen.sh
./configure
make
make install
echo /usr/local/lib > wolfssl.conf
mv wolfssl.conf /etc/ld.so.conf
ldconfig
popd
rm -rf wolfssl
yum install -y libffi-devel python-devel python-pip
pip install wolfssl
[ $? -ne 0 ] && echo "\n\nCouldn't install wolfssl.\n\n" && exit 1

@ -0,0 +1,23 @@
[ "$(whoami)" != "root" ] && echo "Sorry, you are not root." && exit 1
apt-get update
apt-get install -y git autoconf libtool
git clone https://github.com/wolfssl/wolfssl.git
[ $? -ne 0 ] && echo "\n\nCouldn't download wolfssl.\n\n" && exit 1
pushd wolfssl
./autogen.sh
./configure
make
make install
ldconfig
popd
rm -rf wolfssl
apt-get install -y libffi-dev python-dev python-pip
pip install wolfssl
[ $? -ne 0 ] && echo "\n\nCouldn't install wolfssl.\n\n" && exit 1

@ -0,0 +1,23 @@
Licensing
---------
wolfSSLs software is available under two distinct licensing models:
open source and standard commercial licensing. Please see the relevant
section below for information on each type of license.
Open Source
~~~~~~~~~~~
wolfCrypt and wolfSSL software are free software downloads and may be modified
to the needs of the user as long as the user adheres to version two of the GPL
License. The GPLv2 license can be found on the `gnu.org website
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>`_.
Commercial Licensing
~~~~~~~~~~~~~~~~~~~~
Businesses and enterprises who wish to incorporate wolfSSL products into
proprietary appliances or other commercial software products for
re-distribution must license commercial versions. Licenses are generally
issued for one product and include unlimited royalty-free distribution.
Custom licensing terms are also available at licensing@wolfssl.com.

@ -0,0 +1 @@
include LICENSING.rst

@ -0,0 +1,144 @@
wolfssl: the wolfSSL Inc. SSL/TLS library
=========================================
**wolfssl Python**, a.k.a. ``wolfssl`` is a Python library that encapsulates
**wolfSSL's C SSL/TLS library**.
`wolfssl <https://wolfssl.com/wolfSSL/Products-wolfssl.html>`_ is a
lightweight, portable, C-language-based crypto library
targeted at IoT, embedded, and RTOS environments primarily because of its size,
speed, and feature set. It works seamlessly in desktop, enterprise, and cloud
environments as well. It is the crypto engine behind `wolfSSl's embedded ssl
library <https://wolfssl.com/wolfSSL/Products-wolfssl.html>`_.
Installation
------------
In order to use ``wolfssl``, first you'll need to install ``wolfssl`` C
embedded SSL/TLS library.
Installing ``wolfssl`` C SSL/TLS library:
~~~~~~~~~~~~~~~~~~~~~~~~
**Mac OSX**
.. code-block:: console
brew install wolfssl
or
.. code-block:: console
git clone https://github.com/wolfssl/wolfssl.git
cd wolfssl/
./autogen.sh
./configure --enable-sha512
make
sudo make install
**Ubuntu**
.. code-block:: console
sudo apt-get update
sudo apt-get install -y git autoconf libtool
git clone https://github.com/wolfssl/wolfssl.git
cd wolfssl/
./autogen.sh
./configure --enable-sha512
make
sudo make install
sudo ldconfig
**CentOS**
.. code-block:: console
sudo rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-6.noarch.rpm
sudo yum update
sudo yum install -y git autoconf libtool
git clone git@github.com:wolfssl/wolfssl.git
cd wolfssl
./autogen.sh
./configure --enable-sha512
make
sudo make install
echo /usr/local/lib > wolfssl.conf
sudo mv wolfssl.conf /etc/ld.so.conf
sudo ldconfig
Installing ``wolfssl`` python module:
~~~~~~~~~~~~~~~~~~~~~~~~~~
**Mac OSX**
.. code-block:: console
sudo -H pip install wolfssl
**Ubuntu**
.. code-block:: console
sudo apt-get install -y python-dev python3-dev python-pip libffi-dev
sudo -H pip install wolfssl
**CentOS**
.. code-block:: console
sudo yum install -y python-devel python3-devel python-pip libffi-devel
sudo -H pip install wolfssl
Testing ``wolfssl`` python module:
~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: console
python -c "from wolfssl.hashes import Sha; print Sha().hexdigest()"
expected output: **da39a3ee5e6b4b0d3255bfef95601890afd80709**
Testing ``wolfssl``'s source code with ``tox`` :
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To run the unit tests in the source code, you'll need ``tox`` and a few other
requirements. The source code relies at 'WOLFSSL_DIR/wrapper/python/wolfssl'
where WOLFSSL_DIR is the path of ``wolfssl``'s source code.
1. Make sure that the testing requirements are installed:
.. code-block:: console
$ sudo -H pip install -r requirements-testing.txt
2. Run ``tox``:
.. code-block:: console
$ tox
...
_________________________________ summary _________________________________
py27: commands succeeded
SKIPPED: py34: InterpreterNotFound: python3.4
py35: commands succeeded
congratulations :)
Note: the test is performed using multiple versions of python. If you are
missing a version the test will be skipped with an **InterpreterNotFound
error**.

14
wrapper/python/wolfssl/Vagrantfile vendored Normal file

@ -0,0 +1,14 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
BOX = "ubuntu"
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
if BOX == "ubuntu"
config.vm.box = "ubuntu/trusty64"
config.vm.provision "shell", path: ".ubuntu-provisioner.sh"
else
config.vm.box = "moisesguimaraes/centos72-64"
config.vm.provision "shell", path: ".centos-provisioner.sh"
end
end

@ -0,0 +1,3 @@
pytest>=2.9.1
cffi>=1.6.0
tox>=2.3.1

55
wrapper/python/wolfssl/setup.py Executable file

@ -0,0 +1,55 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2006-2016 wolfSSL Inc.
#
# This file is part of wolfSSL. (formerly known as CyaSSL)
#
# wolfSSL 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 2 of the License, or
# (at your option) any later version.
#
# wolfSSL 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
# Python 2.7 Standard Library
from __future__ import absolute_import
import os
import sys
from wolfssl.__about__ import metadata
from setuptools import setup, find_packages
os.chdir(os.path.dirname(sys.argv[0]) or ".")
long_description = open("README.rst", "rt").read().replace(
".. include:: LICENSING.rst\n",
open("LICENSING.rst", "rt").read()
)
info = dict(
metadata = {k[2:-2]: metadata[k] for k in metadata},
contents = {
"long_description": long_description,
"package_data": {"": ["*.txt"]},
"packages": find_packages(),
"cffi_modules": ["./wolfssl/build_ffi.py:ffi"],
},
requirements = {
"setup_requires": ["cffi>=1.6.0"],
"install_requires": ["cffi>=1.6.0"],
},
scripts = {},
plugins = {},
tests = {},
)
if __name__ == "__main__":
kwargs = {k:v for dct in info.values() for (k,v) in dct.items()}
setup(**kwargs)

@ -0,0 +1,7 @@
[tox]
envlist=py27,py34,py35
skip_missing_interpreters=true
[testenv]
deps=-rrequirements-testing.txt
commands=py.test test/

@ -0,0 +1,45 @@
# __about__.py
#
# Copyright (C) 2006-2016 wolfSSL Inc.
#
# This file is part of wolfSSL. (formerly known as CyaSSL)
#
# wolfSSL 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 2 of the License, or
# (at your option) any later version.
#
# wolfSSL 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
metadata = dict(
__name__ = "wolfssl",
__version__ = "0.1.0",
__license__ = "GPLv2 or Commercial License",
__author__ = "wolfSSL Inc.",
__author_email__ = "info@wolfssl.com",
__url__ = "https://wolfssl.github.io/wolfssl-py",
__description__ = \
u"A Python module that encapsulates wolfSSL's C SSL/TLS library.",
__keywords__ = "security, cryptography, ssl, embedded, embedded ssl",
__classifiers__ = [
u"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
u"License :: Other/Proprietary License",
u"Operating System :: OS Independent",
u"Programming Language :: Python :: 2.7",
u"Programming Language :: Python :: 3.5",
u"Topic :: Security",
u"Topic :: Security :: Cryptography",
u"Topic :: Software Development"
]
)
globals().update(metadata)
__all__ = list(metadata.keys())

@ -0,0 +1,77 @@
# _exceptions.py
#
# Copyright (C) 2006-2016 wolfSSL Inc.
#
# This file is part of wolfSSL. (formerly known as CyaSSL)
#
# wolfSSL 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 2 of the License, or
# (at your option) any later version.
#
# wolfSSL 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
from socket import error as socket_error
class SSLError(socket_error):
'''
Raised to signal an error from the wolfSSL's SSL/TLS library. This signifies
some problem in the higher-level encryption and authentication layer thats
superimposed on the underlying network connection. This error is a subtype
of socket.error, which in turn is a subtype of IOError. The error code and
message of SSLError instances are provided by the wolfSSL library.
'''
pass
class SSLZeroReturnError(SSLError):
'''
A subclass of SSLError raised when trying to read or write and the SSL
connection has been closed cleanly. Note that this doesnt mean that the
underlying transport (read TCP) has been closed.
'''
pass
class SSLWantReadError(SSLError):
'''
A subclass of SSLError raised by a non-blocking SSL socket when trying to
read or write data, but more data needs to be received on the underlying TCP
transport before the request can be fulfilled.
'''
pass
class SSLWantWriteError(SSLError):
'''
A subclass of SSLError raised by a non-blocking SSL socket when trying to
read or write data, but more data needs to be sent on the underlying TCP
transport before the request can be fulfilled.
'''
pass
class SSLSyscallError(SSLError):
'''
A subclass of SSLError raised when a system error was encountered while
trying to fulfill an operation on a SSL socket. Unfortunately, there is no
easy way to inspect the original errno number.
'''
pass
class SSLEOFError(SSLError):
'''
A subclass of SSLError raised when the SSL connection has been terminated
abruptly. Generally, you shouldnt try to reuse the underlying transport
when this error is encountered.
'''
pass