1

(1 replies, posted in wolfSSL)

Hello,

I recently used wolfssl(version 4.0.0) to write a simple ssl client, and my build size is ~348KB.  My object is to reduce the size to less than 100KB.

I am using  win7 32bit, VS2008 and my code is :

// testwolf.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "stdio.h"
#include "wolfssl/ssl.h"
#include "winsock2.h"
#pragma comment(lib, "wolfssl.lib")
#pragma comment(lib, "ws2_32.lib")
#define MAXLINE 1024
SOCKET MySock;

 
bool tcp_connect_test()
{
    WORD wVersionRequested;
    WSADATA wsaData;
    int err;
    
    wVersionRequested = MAKEWORD( 1, 1 );
    
    err = WSAStartup( wVersionRequested, &wsaData );
    if ( err != 0 ) 
    {
        WSACleanup();
        return false ;
    }
    
    if ( LOBYTE( wsaData.wVersion ) != 1 ||
        HIBYTE( wsaData.wVersion ) != 1 ) 
    {
        WSACleanup();
        return false ; 
    }
    MySock=socket(AF_INET,SOCK_STREAM,0);
 
    SOCKADDR_IN addrSrv;
    addrSrv.sin_addr.S_un.S_addr=inet_addr("127.0.0.1");
    addrSrv.sin_family=AF_INET;
    addrSrv.sin_port=htons(11111);

    if(!connect(MySock,(SOCKADDR*)&addrSrv,sizeof(SOCKADDR)))
        return true;
    return false;//failed

}
 

int str_cli(FILE *fp, WOLFSSL* ssl)
 {
 char sendline[MAXLINE], recvline[MAXLINE];
 int n = 0;
 while (fgets(sendline, MAXLINE, fp) != NULL) {
 if(wolfSSL_write(ssl, sendline, strlen(sendline)) !=
 strlen(sendline)){
 
 }
 if ((n = wolfSSL_read(ssl, recvline, MAXLINE)) <= 0)
 
 recvline[n] = '\0';
 fputs(recvline, stdout);
 }
 return 0;
}

int main()
{
    WOLFSSL_CTX* ctx; 
    WOLFSSL* ssl;
    wolfSSL_Init();
    /* Initialize wolfSSL *//* Create the WOLFSSL_CTX */
    if ((ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method())) == NULL)
    { 
        fprintf(stderr, "wolfSSL_CTX_new error.\n"); 
        exit(EXIT_FAILURE); 
    }

    

    /* Load CA certificates into WOLFSSL_CTX */
    if (wolfSSL_CTX_load_verify_locations(ctx, "../certs/ca-cert.pem", 0) != SSL_SUCCESS) 
    {
        fprintf(stderr, "Error loading ../certs/ca-cert.pem, please check              the file.\n"); 
        exit(EXIT_FAILURE);
    }

    tcp_connect_test();
    
    

    if( (ssl = wolfSSL_new(ctx)) == NULL) 
    {
     fprintf(stderr, "wolfSSL_new error.\n");
     exit(EXIT_FAILURE);
     }

    wolfSSL_set_fd(ssl, MySock);


    str_cli(stdin, ssl);


    wolfSSL_free(ssl); 
    wolfSSL_CTX_free(ctx);
    wolfSSL_Cleanup();
    return 0;
}