Browse Source

update swig interface

toddouska 12 years ago
parent
commit
051b63b9c8
5 changed files with 26 additions and 10 deletions
  1. 4 0
      .gitignore
  2. 3 3
      swig/PythonBuild.sh
  3. 6 4
      swig/cyassl.i
  4. 1 1
      swig/cyassl_adds.c
  5. 12 2
      swig/runme.py

+ 4 - 0
.gitignore

@@ -61,4 +61,8 @@ TAGS
 support/libcyassl.pc
 cyassl/version.h
 cyassl/ctaocrypt/stamp-h1
+swig/_cyassl.so
+swig/cyassl.py
+swig/cyassl.pyc
+swig/cyassl_wrap.c
 stamp-h1

+ 3 - 3
swig/PythonBuild.sh

@@ -3,7 +3,7 @@ echo
 swig -python cyassl.i
 pythonIncludes=`python-config --includes`
 pythonLibs=`python-config --libs`
-gcc -c -fpic cyassl_wrap.c -I$pythonIncludes -I/usr/local/cyassl/include -DHAVE_CONFIG_H
-gcc -c -fpic cyassl_adds.c -I/usr/local/cyassl/include
-gcc -shared -flat_namespace  cyassl_adds.o  cyassl_wrap.o -lcyassl -L/usr/local/cyassl/lib $pythonLibs -o _cyassl.so
+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
 python runme.py

+ 6 - 4
swig/cyassl.i

@@ -21,12 +21,12 @@
 
 %module cyassl
 %{
-    #include "openssl/ssl.h"
-    #include "rsa.h"
+    #include <cyassl/openssl/ssl.h>
+    #include <cyassl/ctaocrypt/rsa.h>
 
     /* defn adds */
     char* CyaSSL_error_string(int err);
-    int   CyaSSL_connect(SSL*, const char* server, int port);
+    int   CyaSSL_swig_connect(SSL*, const char* server, int port);
     RNG*  GetRng(void);
     RsaKey* GetRsaPrivateKey(const char* file);
     void    FillSignStr(unsigned char*, const char*, int);
@@ -39,8 +39,10 @@ int         SSL_CTX_load_verify_locations(SSL_CTX*, const char*, const char*);
 SSL*        SSL_new(SSL_CTX*);
 int         SSL_get_error(SSL*, int);
 int         SSL_write(SSL*, const char*, int);
+int         CyaSSL_Debugging_ON(void);
+int         CyaSSL_Init(void);
 char*       CyaSSL_error_string(int);
-int         CyaSSL_connect(SSL*, const char* server, int port);
+int         CyaSSL_swig_connect(SSL*, const char* server, int port);
 
 int         RsaSSL_Sign(const unsigned char* in, int inLen, unsigned char* out, int outLen, RsaKey* key, RNG* rng);
 

+ 1 - 1
swig/cyassl_adds.c

@@ -160,7 +160,7 @@ static int tcp_connect(SOCKET_T* sockfd, const char* ip, short port)
 }
     
 
-int CyaSSL_connect(SSL* ssl, const char* server, int port)
+int CyaSSL_swig_connect(SSL* ssl, const char* server, int port)
 {
     SOCKET_T sockfd;
     int ret = tcp_connect(&sockfd, server, port);

+ 12 - 2
swig/runme.py

@@ -5,11 +5,21 @@ import cyassl
 print ""
 print "Trying to connect to the echo server..."
 
+cyassl.CyaSSL_Init()
+#cyassl.CyaSSL_Debugging_ON()
 ctx    = cyassl.SSL_CTX_new(cyassl.TLSv1_client_method())
+if ctx == None:
+    print "Couldn't get SSL CTX for TLSv1"
+    exit(-1)
+
 ret    = cyassl.SSL_CTX_load_verify_locations(ctx, "../certs/ca-cert.pem", None)
-ssl    = cyassl.SSL_new(ctx)
+if ret != cyassl.SSL_SUCCESS:
+    print "Couldn't do SSL_CTX_load_verify_locations "
+    print "error string = ", ret 
+    exit(-1)
 
-ret    = cyassl.CyaSSL_connect(ssl, "localhost", 11111)
+ssl    = cyassl.SSL_new(ctx)
+ret    = cyassl.CyaSSL_swig_connect(ssl, "localhost", 11111)
 
 if ret != cyassl.SSL_SUCCESS:
     print "Couldn't do SSL connect"