swig updated, tested, and working

This commit is contained in:
kaleb-himes
2015-01-08 14:47:41 -07:00
parent 492bae7afe
commit 2951ef5b97
9 changed files with 102 additions and 98 deletions

4
.gitignore vendored
View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -2,9 +2,9 @@
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="python_cyassl"
Name="python_wolfssl"
ProjectGUID="{47A3ABA9-EC54-4788-BC7E-370595B2011A}"
RootNamespace="python_cyassl"
RootNamespace="python_wolfssl"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
@ -41,8 +41,8 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../include;../ctaocrypt/include;&quot;$(PYTHON_INCLUDE)&quot;"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;PYTHON_CYASSL_EXPORTS"
AdditionalIncludeDirectories="../include;../wolfcrypt/include;&quot;$(PYTHON_INCLUDE)&quot;"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;PYTHON_WOLFSSL_EXPORTS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
@ -62,7 +62,7 @@
<Tool
Name="VCLinkerTool"
AdditionalDependencies="$(PYTHON_LIB) Ws2_32.lib"
OutputFile="_cyassl.pyd"
OutputFile="_wolfssl.pyd"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="2"
@ -117,8 +117,8 @@
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../include;../ctaocrypt/include;&quot;$(PYTHON_INCLUDE)&quot;"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;PYTHON_CYASSL_EXPORTS"
AdditionalIncludeDirectories="../include;../wolfcrypt/include;&quot;$(PYTHON_INCLUDE)&quot;"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;PYTHON_WOLFSSL_EXPORTS"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
@ -137,7 +137,7 @@
<Tool
Name="VCLinkerTool"
AdditionalDependencies="$(PYTHON_LIB) Ws2_32.lib"
OutputFile="_cyassl.pyd"
OutputFile="_wolfssl.pyd"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="2"
@ -177,11 +177,11 @@
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\cyassl_adds.c"
RelativePath=".\wolfssl_adds.c"
>
</File>
<File
RelativePath=".\cyassl_wrap.c"
RelativePath=".\wolfssl_wrap.c"
>
</File>
</Filter>
@ -198,7 +198,7 @@
>
</Filter>
<File
RelativePath=".\cyassl.i"
RelativePath=".\wolfssl.i"
>
<FileConfiguration
Name="Debug|Win32"

View File

@ -1,35 +1,35 @@
# file: rsasign.py
import cyassl
import wolfssl
# start Random Number Generator
rng = cyassl.GetRng()
rng = wolfssl.GetRng()
if rng == None:
print "Couldn't get an RNG"
exit(-1)
# load RSA private key in DER format
key = cyassl.GetRsaPrivateKey("../certs/client-key.der")
key = wolfssl.GetRsaPrivateKey("../certs/client-key.der")
if key == None:
print "Couldn't load DER private key file"
exit(-1)
# Make byte Arrays and fill input
signOutput = cyassl.byteArray(128) # 128 allows 1024 bit private key
signStr = cyassl.byteArray(25) # input can't be larger then key size
signOutput = wolfssl.byteArray(128) # 128 allows 1024 bit private key
signStr = wolfssl.byteArray(25) # input can't be larger then key size
# 64 for 512 bit 128 for 1024 bit
cyassl.FillSignStr(signStr, "Everybody gets Friday off", 25)
wolfssl.FillSignStr(signStr, "Everybody gets Friday off", 25)
# Do RSA Sign
signedSize = cyassl.RsaSSL_Sign(signStr, 25, signOutput, 128, key, rng)
signedSize = wolfssl.RsaSSL_Sign(signStr, 25, signOutput, 128, key, rng)
# Show output
print "Signed Size = ", signedSize, " signed array = ", cyassl.cdata(signOutput, signedSize)
# Show output
print "Signed Size = ", signedSize, " signed array = ", wolfssl.cdata(signOutput, signedSize)
# let's verify this worked
signVerify = cyassl.byteArray(signedSize)
verifySize = cyassl.RsaSSL_Verify(signOutput, signedSize, signVerify, signedSize, key)
signVerify = wolfssl.byteArray(signedSize)
verifySize = wolfssl.RsaSSL_Verify(signOutput, signedSize, signVerify, signedSize, key)
print "Verify Size = ", verifySize, " verify array = ", cyassl.cdata(signVerify, verifySize)
print "Verify Size = ", verifySize, " verify array = ", wolfssl.cdata(signVerify, verifySize)

View File

@ -1,40 +1,40 @@
# file: runme.py
import cyassl
import wolfssl
print ""
print "Trying to connect to the echo server..."
cyassl.CyaSSL_Init()
#cyassl.CyaSSL_Debugging_ON()
ctx = cyassl.CyaSSL_CTX_new(cyassl.CyaTLSv1_client_method())
wolfssl.wolfSSL_Init()
#wolfssl.wolfSSL_Debugging_ON()
ctx = wolfssl.wolfSSL_CTX_new(wolfssl.wolfTLSv1_client_method())
if ctx == None:
print "Couldn't get SSL CTX for TLSv1"
exit(-1)
ret = cyassl.CyaSSL_CTX_load_verify_locations(ctx, "../certs/ca-cert.pem", None)
if ret != cyassl.SSL_SUCCESS:
ret = wolfssl.wolfSSL_CTX_load_verify_locations(ctx, "../certs/ca-cert.pem", None)
if ret != wolfssl.SSL_SUCCESS:
print "Couldn't do SSL_CTX_load_verify_locations "
print "error string = ", ret
print "error string = ", ret
exit(-1)
ssl = cyassl.CyaSSL_new(ctx)
ret = cyassl.CyaSSL_swig_connect(ssl, "localhost", 11111)
ssl = wolfssl.wolfSSL_new(ctx)
ret = wolfssl.wolfSSL_swig_connect(ssl, "localhost", 11111)
if ret != cyassl.SSL_SUCCESS:
if ret != wolfssl.SSL_SUCCESS:
print "Couldn't do SSL connect"
err = cyassl.CyaSSL_get_error(ssl, 0)
print "error string = ", cyassl.CyaSSL_error_string(err)
err = wolfssl.wolfSSL_get_error(ssl, 0)
print "error string = ", wolfssl.wolfSSL_error_string(err)
exit(-1)
print "...Connected"
written = cyassl.CyaSSL_write(ssl, "hello from python\r\n", 19)
written = wolfssl.wolfSSL_write(ssl, "hello from python\r\n", 19)
if written > 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)

View File

@ -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 <cyassl/ssl.h>
#include <cyassl/ctaocrypt/rsa.h>
#include <wolfssl/ssl.h>
#include <wolfssl/wolfcrypt/rsa.h>
/* 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

View File

@ -1,4 +1,4 @@
/* cyassl_adds.c
/* wolfssl_adds.c
*
* Copyright (C) 2006-2015 wolfSSL Inc.
*
@ -23,15 +23,15 @@
#include <config.h>
#endif
#include <cyassl/ctaocrypt/settings.h>
#include <wolfssl/wolfcrypt/settings.h>
#ifndef _WIN32
#define HAVE_CONFIG_H
#endif
#include <cyassl/ssl.h>
#include <cyassl/ctaocrypt/rsa.h>
#include <cyassl/ctaocrypt/asn.h>
#include <wolfssl/ssl.h>
#include <wolfssl/wolfcrypt/rsa.h>
#include <wolfssl/wolfcrypt/asn.h>
#include <stdio.h>
#include <stdlib.h>
@ -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;
}