forked from wolfSSL/wolfssl
cyassl api for swig
This commit is contained in:
@@ -21,28 +21,28 @@
|
|||||||
|
|
||||||
%module cyassl
|
%module cyassl
|
||||||
%{
|
%{
|
||||||
#include <cyassl/openssl/ssl.h>
|
#include <cyassl/ssl.h>
|
||||||
#include <cyassl/ctaocrypt/rsa.h>
|
#include <cyassl/ctaocrypt/rsa.h>
|
||||||
|
|
||||||
/* defn adds */
|
/* defn adds */
|
||||||
char* CyaSSL_error_string(int err);
|
char* CyaSSL_error_string(int err);
|
||||||
int CyaSSL_swig_connect(SSL*, const char* server, int port);
|
int CyaSSL_swig_connect(CYASSL*, const char* server, int port);
|
||||||
RNG* GetRng(void);
|
RNG* GetRng(void);
|
||||||
RsaKey* GetRsaPrivateKey(const char* file);
|
RsaKey* GetRsaPrivateKey(const char* file);
|
||||||
void FillSignStr(unsigned char*, const char*, int);
|
void FillSignStr(unsigned char*, const char*, int);
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
SSL_METHOD* TLSv1_client_method(void);
|
CYASSL_METHOD* CyaTLSv1_client_method(void);
|
||||||
SSL_CTX* SSL_CTX_new(SSL_METHOD*);
|
CYASSL_CTX* CyaSSL_CTX_new(CYASSL_METHOD*);
|
||||||
int SSL_CTX_load_verify_locations(SSL_CTX*, const char*, const char*);
|
int CyaSSL_CTX_load_verify_locations(CYASSL_CTX*, const char*, const char*);
|
||||||
SSL* SSL_new(SSL_CTX*);
|
CYASSL* CyaSSL_new(CYASSL_CTX*);
|
||||||
int SSL_get_error(SSL*, int);
|
int CyaSSL_get_error(CYASSL*, int);
|
||||||
int SSL_write(SSL*, const char*, int);
|
int CyaSSL_write(CYASSL*, const char*, int);
|
||||||
int CyaSSL_Debugging_ON(void);
|
int CyaSSL_Debugging_ON(void);
|
||||||
int CyaSSL_Init(void);
|
int CyaSSL_Init(void);
|
||||||
char* CyaSSL_error_string(int);
|
char* CyaSSL_error_string(int);
|
||||||
int CyaSSL_swig_connect(SSL*, const char* server, int port);
|
int CyaSSL_swig_connect(CYASSL*, const char* server, int port);
|
||||||
|
|
||||||
int RsaSSL_Sign(const unsigned char* in, int inLen, unsigned char* out, int outLen, RsaKey* key, RNG* rng);
|
int RsaSSL_Sign(const unsigned char* in, int inLen, unsigned char* out, int outLen, RsaKey* key, RNG* rng);
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ void FillSignStr(unsigned char*, const char*, int);
|
|||||||
%include carrays.i
|
%include carrays.i
|
||||||
%include cdata.i
|
%include cdata.i
|
||||||
%array_class(unsigned char, byteArray);
|
%array_class(unsigned char, byteArray);
|
||||||
int SSL_read(SSL*, unsigned char*, int);
|
int CyaSSL_read(CYASSL*, unsigned char*, int);
|
||||||
|
|
||||||
|
|
||||||
#define SSL_FAILURE 0
|
#define SSL_FAILURE 0
|
||||||
|
@@ -27,7 +27,7 @@
|
|||||||
#define HAVE_CONFIG_H
|
#define HAVE_CONFIG_H
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <cyassl/openssl/ssl.h>
|
#include <cyassl/ssl.h>
|
||||||
#include <cyassl/ctaocrypt/rsa.h>
|
#include <cyassl/ctaocrypt/rsa.h>
|
||||||
#include <cyassl/ctaocrypt/asn.h>
|
#include <cyassl/ctaocrypt/asn.h>
|
||||||
|
|
||||||
@@ -160,15 +160,15 @@ static int tcp_connect(SOCKET_T* sockfd, const char* ip, short port)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int CyaSSL_swig_connect(SSL* ssl, const char* server, int port)
|
int CyaSSL_swig_connect(CYASSL* ssl, const char* server, int port)
|
||||||
{
|
{
|
||||||
SOCKET_T sockfd;
|
SOCKET_T sockfd;
|
||||||
int ret = tcp_connect(&sockfd, server, port);
|
int ret = tcp_connect(&sockfd, server, port);
|
||||||
if (ret != 0) return ret;
|
if (ret != 0) return ret;
|
||||||
|
|
||||||
SSL_set_fd(ssl, sockfd);
|
CyaSSL_set_fd(ssl, sockfd);
|
||||||
|
|
||||||
return SSL_connect(ssl);
|
return CyaSSL_connect(ssl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -176,7 +176,7 @@ char* CyaSSL_error_string(int err)
|
|||||||
{
|
{
|
||||||
static char buffer[80];
|
static char buffer[80];
|
||||||
|
|
||||||
return ERR_error_string(err, buffer);
|
return CyaSSL_ERR_error_string(err, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -7,34 +7,34 @@ print "Trying to connect to the echo server..."
|
|||||||
|
|
||||||
cyassl.CyaSSL_Init()
|
cyassl.CyaSSL_Init()
|
||||||
#cyassl.CyaSSL_Debugging_ON()
|
#cyassl.CyaSSL_Debugging_ON()
|
||||||
ctx = cyassl.SSL_CTX_new(cyassl.TLSv1_client_method())
|
ctx = cyassl.CyaSSL_CTX_new(cyassl.CyaTLSv1_client_method())
|
||||||
if ctx == None:
|
if ctx == None:
|
||||||
print "Couldn't get SSL CTX for TLSv1"
|
print "Couldn't get SSL CTX for TLSv1"
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
ret = cyassl.SSL_CTX_load_verify_locations(ctx, "../certs/ca-cert.pem", None)
|
ret = cyassl.CyaSSL_CTX_load_verify_locations(ctx, "../certs/ca-cert.pem", None)
|
||||||
if ret != cyassl.SSL_SUCCESS:
|
if ret != cyassl.SSL_SUCCESS:
|
||||||
print "Couldn't do SSL_CTX_load_verify_locations "
|
print "Couldn't do SSL_CTX_load_verify_locations "
|
||||||
print "error string = ", ret
|
print "error string = ", ret
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
ssl = cyassl.SSL_new(ctx)
|
ssl = cyassl.CyaSSL_new(ctx)
|
||||||
ret = cyassl.CyaSSL_swig_connect(ssl, "localhost", 11111)
|
ret = cyassl.CyaSSL_swig_connect(ssl, "localhost", 11111)
|
||||||
|
|
||||||
if ret != cyassl.SSL_SUCCESS:
|
if ret != cyassl.SSL_SUCCESS:
|
||||||
print "Couldn't do SSL connect"
|
print "Couldn't do SSL connect"
|
||||||
err = cyassl.SSL_get_error(ssl, 0)
|
err = cyassl.CyaSSL_get_error(ssl, 0)
|
||||||
print "error string = ", cyassl.CyaSSL_error_string(err)
|
print "error string = ", cyassl.CyaSSL_error_string(err)
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
print "...Connected"
|
print "...Connected"
|
||||||
written = cyassl.SSL_write(ssl, "hello from python\r\n", 19)
|
written = cyassl.CyaSSL_write(ssl, "hello from python\r\n", 19)
|
||||||
|
|
||||||
if written > 0:
|
if written > 0:
|
||||||
print "Wrote ", written, " bytes"
|
print "Wrote ", written, " bytes"
|
||||||
|
|
||||||
byteArray = cyassl.byteArray(100)
|
byteArray = cyassl.byteArray(100)
|
||||||
readBytes = cyassl.SSL_read(ssl, byteArray, 100)
|
readBytes = cyassl.CyaSSL_read(ssl, byteArray, 100)
|
||||||
|
|
||||||
print "server reply: ", cyassl.cdata(byteArray, readBytes)
|
print "server reply: ", cyassl.cdata(byteArray, readBytes)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user