From 0df897d4b9291de76be8afcce81aafaa6edf1672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moise=CC=81s=20Guimara=CC=83es?= Date: Tue, 13 Sep 2016 00:55:05 -0300 Subject: [PATCH] adds methods --- wrapper/python/wolfssl/.gitignore | 15 +++++++ wrapper/python/wolfssl/wolfssl/_methods.py | 47 +++++++++++++++++++++ wrapper/python/wolfssl/wolfssl/build_ffi.py | 13 +++--- 3 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 wrapper/python/wolfssl/.gitignore create mode 100644 wrapper/python/wolfssl/wolfssl/_methods.py diff --git a/wrapper/python/wolfssl/.gitignore b/wrapper/python/wolfssl/.gitignore new file mode 100644 index 000000000..421703396 --- /dev/null +++ b/wrapper/python/wolfssl/.gitignore @@ -0,0 +1,15 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# Distribution +build/ +dist/ +.eggs/ +*.egg-info/ + +# Unit test +.tox/ +# Sphinx documentation +docs/_build/ diff --git a/wrapper/python/wolfssl/wolfssl/_methods.py b/wrapper/python/wolfssl/wolfssl/_methods.py new file mode 100644 index 000000000..0b13bc2b7 --- /dev/null +++ b/wrapper/python/wolfssl/wolfssl/_methods.py @@ -0,0 +1,47 @@ +# _methods.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 wolfssl._ffi import ffi as _ffi +from wolfssl._ffi import lib as _lib + +PROTOCOL_SSLv23 = 1 +PROTOCOL_SSLv3 = 2 +PROTOCOL_TLSv1 = 3 +PROTOCOL_TLSv1_1 = 4 +PROTOCOL_TLSv1_2 = 5 + +_PROTOCOL_LIST = [PROTOCOL_SSLv23, PROTOCOL_SSLv3, PROTOCOL_TLSv1, + PROTOCOL_TLSv1_1, PROTOCOL_TLSv1_2] + +class WolfSSLMethod: + def __init__(self, protocol, server_side): + if protocol not in _PROTOCOL_LIST: + raise ValueError("this protocol is not supported") + elif protocol is PROTOCOL_SSLv3: + raise ValueError("this protocol is not supported") + elif protocol is PROTOCOL_TLSv1: + raise ValueError("this protocol is not supported") + elif protocol is PROTOCOL_TLSv1_1: + raise ValueError("this protocol is not supported") + elif protocol is PROTOCOL_TLSv1_2: + self._method = _lib.wolfTLSv1_2_server_method() if server_side else\ + _lib.wolfTLSv1_2_client_method() + elif protocol is PROTOCOL_SSLv23: + self._method = _lib.wolfSSLv23_server_method() if server_side else \ + _lib.wolfSSLv23_client_method() diff --git a/wrapper/python/wolfssl/wolfssl/build_ffi.py b/wrapper/python/wolfssl/wolfssl/build_ffi.py index 0fed4feb8..ac18e0b0a 100644 --- a/wrapper/python/wolfssl/wolfssl/build_ffi.py +++ b/wrapper/python/wolfssl/wolfssl/build_ffi.py @@ -38,12 +38,13 @@ ffi.cdef( typedef unsigned char byte; typedef unsigned int word32; - void* wolfTLSv1_server_method(void); - void* wolfTLSv1_client_method(void); - void* wolfTLSv1_1_server_method(void); - void* wolfTLSv1_1_client_method(void); - void* wolfTLSv1_2_server_method(void); - void* wolfTLSv1_2_client_method(void); + int wolfSSL_Init(void); + int wolfSSL_Cleanup(void); + + void *wolfSSLv23_server_method(void); + void *wolfSSLv23_client_method(void); + void *wolfTLSv1_2_server_method(void); + void *wolfTLSv1_2_client_method(void); """ )