From 2951ef5b9739db0dc95891aad4348d41156f0ea9 Mon Sep 17 00:00:00 2001 From: kaleb-himes Date: Thu, 8 Jan 2015 14:47:41 -0700 Subject: [PATCH] swig updated, tested, and working --- .gitignore | 4 ++ swig/PythonBuild.sh | 8 ++-- swig/README | 26 ++++++------ swig/include.am | 6 +-- ...on_cyassl.vcproj => python_wolfssl.vcproj} | 22 +++++----- swig/rsasign.py | 24 +++++------ swig/runme.py | 32 +++++++-------- swig/{cyassl.i => wolfssl.i} | 38 +++++++++--------- swig/{cyassl_adds.c => wolfssl_adds.c} | 40 +++++++++---------- 9 files changed, 102 insertions(+), 98 deletions(-) rename swig/{python_cyassl.vcproj => python_wolfssl.vcproj} (92%) rename swig/{cyassl.i => wolfssl.i} (54%) rename swig/{cyassl_adds.c => wolfssl_adds.c} (87%) diff --git a/.gitignore b/.gitignore index b6b64a713..50e740a4c 100644 --- a/.gitignore +++ b/.gitignore @@ -95,9 +95,13 @@ TAGS support/cyassl.pc cyassl/ctaocrypt/stamp-h1 swig/_cyassl.so +swig/_wolfssl.so swig/cyassl.py +swig/wolfssl.py swig/cyassl.pyc +swig/wolfssl.pyc swig/cyassl_wrap.c +swig/wolfssl_wrap.c stamp-h1 clang_output_* internal.plist diff --git a/swig/PythonBuild.sh b/swig/PythonBuild.sh index 7f0939c42..ae4ac45f4 100755 --- a/swig/PythonBuild.sh +++ b/swig/PythonBuild.sh @@ -1,9 +1,9 @@ #!/bin/bash echo -swig -python cyassl.i +swig -python wolfssl.i pythonIncludes=`python-config --includes` pythonLibs=`python-config --libs` -gcc -c -fpic cyassl_wrap.c -I$pythonIncludes -gcc -c -fpic cyassl_adds.c -gcc -shared -flat_namespace cyassl_adds.o cyassl_wrap.o -lcyassl $pythonLibs -o _cyassl.so +gcc -c -fpic wolfssl_wrap.c -I$pythonIncludes +gcc -c -fpic wolfssl_adds.c +gcc -shared -flat_namespace wolfssl_adds.o wolfssl_wrap.o -lwolfssl $pythonLibs -o _wolfssl.so python runme.py diff --git a/swig/README b/swig/README index 302bc6be7..bd4f7f7cf 100644 --- a/swig/README +++ b/swig/README @@ -2,7 +2,7 @@ Initial swig interface file -Please send questions to support@yassl.com +Please send questions to support@wolfssl.com @@ -10,26 +10,26 @@ Please send questions to support@yassl.com For Linux, OS X, or *nix -1) build CyaSSL with fpic on Linux, not needed on OS X +1) build wolfSSL with fpic on Linux, not needed on OS X ./configure --disable-shared CFLAGS=-fpic make sudo make install -2) start the example echoserver from the examples/echoserver directory - ./echoserver +2) start the example echoserver from the root directory + ./examples/echoserver/echoserver -3) run ./PtyonBuild.sh from this directory it will +3) run ./PythonBuild.sh from this directory it will a) build the swig wrapper file - b) compile the swig wrapper and cyassl wrapper files - c) place them into a cyassl shared library for python - d) run runme.py which will connect to the CyaSSL echo server, write a + b) compile the swig wrapper and wolfssl wrapper files + c) place them into a wolfssl shared library for python + d) run runme.py which will connect to the wolfSSL echo server, write a string, then read the result and output it - Windows only + Windows only -1) Make sure the install path to cyassl doesn't have any spaces anywhere in the +1) Make sure the install path to wolfssl doesn't have any spaces anywhere in the directory path because swig doesn't like that 2) Have python for Windows installed, note install directory 3) Have swigwin installed, note install directory @@ -37,8 +37,8 @@ Please send questions to support@yassl.com 5) Make sure env. variables PYTHON_INCLUDE and PYTHON_LIB are set correctly e.g. PYTHON_INCLUE="c:\Python26\include" PYTHON_LIB="c:\Python26\libs\python26.lib" -6) Build python_cyassl in Release mode only, Debug build fails to find a debug +6) Build python_wolfssl in Release mode only, Debug build fails to find a debug python library that isn't included by default -7) The outputs _cyassl.pyd and cyassl.py are the cyassl import library -8) Can now run python runme.py from the swig directory +7) The outputs _wolfssl.pyd and wolfssl.py are the wolfssl import library +8) Can now run python runme.py from the swig directory diff --git a/swig/include.am b/swig/include.am index 32adb5b8f..3bd4c0920 100644 --- a/swig/include.am +++ b/swig/include.am @@ -4,9 +4,9 @@ EXTRA_DIST+= \ swig/PythonBuild.sh \ swig/README \ - swig/cyassl.i \ - swig/cyassl_adds.c \ - swig/python_cyassl.vcproj \ + swig/wolfssl.i \ + swig/wolfssl_adds.c \ + swig/python_wolfssl.vcproj \ swig/rsasign.py \ swig/runme.py diff --git a/swig/python_cyassl.vcproj b/swig/python_wolfssl.vcproj similarity index 92% rename from swig/python_cyassl.vcproj rename to swig/python_wolfssl.vcproj index d4373a949..6af2d3675 100755 --- a/swig/python_cyassl.vcproj +++ b/swig/python_wolfssl.vcproj @@ -2,9 +2,9 @@ @@ -41,8 +41,8 @@ @@ -198,7 +198,7 @@ > 0: print "Wrote ", written, " bytes" -byteArray = cyassl.byteArray(100) -readBytes = cyassl.CyaSSL_read(ssl, byteArray, 100) +byteArray = wolfssl.byteArray(100) +readBytes = wolfssl.wolfSSL_read(ssl, byteArray, 100) -print "server reply: ", cyassl.cdata(byteArray, readBytes) +print "server reply: ", wolfssl.cdata(byteArray, readBytes) diff --git a/swig/cyassl.i b/swig/wolfssl.i similarity index 54% rename from swig/cyassl.i rename to swig/wolfssl.i index 003141da4..45dc693d3 100644 --- a/swig/cyassl.i +++ b/swig/wolfssl.i @@ -1,4 +1,4 @@ -/* cyassl.i +/* wolfssl.i * * Copyright (C) 2006-2015 wolfSSL Inc. * @@ -19,34 +19,34 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -%module cyassl +%module wolfssl %{ - #include - #include + #include + #include /* defn adds */ - char* CyaSSL_error_string(int err); - int CyaSSL_swig_connect(CYASSL*, const char* server, int port); + char* wolfSSL_error_string(int err); + int wolfSSL_swig_connect(WOLFSSL*, const char* server, int port); RNG* GetRng(void); RsaKey* GetRsaPrivateKey(const char* file); void FillSignStr(unsigned char*, const char*, int); %} -CYASSL_METHOD* CyaTLSv1_client_method(void); -CYASSL_CTX* CyaSSL_CTX_new(CYASSL_METHOD*); -int CyaSSL_CTX_load_verify_locations(CYASSL_CTX*, const char*, const char*); -CYASSL* CyaSSL_new(CYASSL_CTX*); -int CyaSSL_get_error(CYASSL*, int); -int CyaSSL_write(CYASSL*, const char*, int); -int CyaSSL_Debugging_ON(void); -int CyaSSL_Init(void); -char* CyaSSL_error_string(int); -int CyaSSL_swig_connect(CYASSL*, const char* server, int port); +WOLFSSL_METHOD* wolfTLSv1_client_method(void); +WOLFSSL_CTX* wolfSSL_CTX_new(WOLFSSL_METHOD*); +int wolfSSL_CTX_load_verify_locations(WOLFSSL_CTX*, const char*, const char*); +WOLFSSL* wolfSSL_new(WOLFSSL_CTX*); +int wolfSSL_get_error(WOLFSSL*, int); +int wolfSSL_write(WOLFSSL*, const char*, int); +int wolfSSL_Debugging_ON(void); +int wolfSSL_Init(void); +char* wolfSSL_error_string(int); +int wolfSSL_swig_connect(WOLFSSL*, const char* server, int port); -int RsaSSL_Sign(const unsigned char* in, int inLen, unsigned char* out, int outLen, RsaKey* key, RNG* rng); +int wc_RsaSSL_Sign(const unsigned char* in, int inLen, unsigned char* out, int outLen, RsaKey* key, RNG* rng); -int RsaSSL_Verify(const unsigned char* in, int inLen, unsigned char* out, int outLen, RsaKey* key); +int wc_RsaSSL_Verify(const unsigned char* in, int inLen, unsigned char* out, int outLen, RsaKey* key); RNG* GetRng(void); RsaKey* GetRsaPrivateKey(const char* file); @@ -55,7 +55,7 @@ void FillSignStr(unsigned char*, const char*, int); %include carrays.i %include cdata.i %array_class(unsigned char, byteArray); -int CyaSSL_read(CYASSL*, unsigned char*, int); +int wolfSSL_read(WOLFSSL*, unsigned char*, int); #define SSL_FAILURE 0 diff --git a/swig/cyassl_adds.c b/swig/wolfssl_adds.c similarity index 87% rename from swig/cyassl_adds.c rename to swig/wolfssl_adds.c index f87e4c46f..e12ccac74 100644 --- a/swig/cyassl_adds.c +++ b/swig/wolfssl_adds.c @@ -1,4 +1,4 @@ -/* cyassl_adds.c +/* wolfssl_adds.c * * Copyright (C) 2006-2015 wolfSSL Inc. * @@ -23,15 +23,15 @@ #include #endif -#include +#include #ifndef _WIN32 #define HAVE_CONFIG_H #endif -#include -#include -#include +#include +#include +#include #include #include @@ -92,7 +92,7 @@ #define StartTCP() { WSADATA wsd; WSAStartup(0x0002, &wsd); } #else #define CloseSocket(s) close(s) - #define StartTCP() + #define StartTCP() #endif @@ -103,7 +103,7 @@ typedef struct sockaddr_in SOCKADDR_IN_T; #define AF_INET_V AF_INET #endif - + enum { SSL_BLOCKING = 2, @@ -127,7 +127,7 @@ static int tcp_socket(SOCKET_T* sockfd, SOCKADDR_IN_T* addr, const char* peer, host = inet_ntoa(tmp.sin_addr); } else - return -1; /* no entry for host */ + return -1; /* no entry for host */ } *sockfd = socket(AF_INET, SOCK_STREAM, 0); @@ -160,25 +160,25 @@ static int tcp_connect(SOCKET_T* sockfd, const char* ip, short port) return 0; } - -int CyaSSL_swig_connect(CYASSL* ssl, const char* server, int port) + +int wolfSSL_swig_connect(WOLFSSL* ssl, const char* server, int port) { SOCKET_T sockfd; int ret = tcp_connect(&sockfd, server, port); if (ret != 0) return ret; - - CyaSSL_set_fd(ssl, sockfd); - return CyaSSL_connect(ssl); + wolfSSL_set_fd(ssl, sockfd); + + return wolfSSL_connect(ssl); } -char* CyaSSL_error_string(int err) +char* wolfSSL_error_string(int err) { - static char buffer[CYASSL_MAX_ERROR_SZ]; + static char buffer[WOLFSSL_MAX_ERROR_SZ]; - return CyaSSL_ERR_error_string(err, buffer); + return wolfSSL_ERR_error_string(err, buffer); } @@ -187,7 +187,7 @@ RNG* GetRng(void) RNG* rng = (RNG*)malloc(sizeof(RNG)); if (rng) - if (InitRng(rng) != 0) { + if (wc_InitRng(rng) != 0) { free(rng); rng = 0; } @@ -214,11 +214,11 @@ RsaKey* GetRsaPrivateKey(const char* keyFile) bytes = fread(tmp, 1, sizeof(tmp), file); fclose(file); - InitRsaKey(key, 0); + wc_InitRsaKey(key, 0); - ret = RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes); + ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes); if (ret != 0) { - FreeRsaKey(key); + wc_FreeRsaKey(key); free(key); return 0; }