Hi @Deltree,
When configuring the wolfSSL library we have to make sure the application includes the same configuration settings. I think you may just be missing a header include for either wolfssl/wolfcrypt/settings.h or wolfssl/options.h. NOTE: wolfssl/options.h is generated when you use ./configure && make to build the library. If you are using some other means to configure the library you should make sure that your settings get included in wolfssl/wolfcrypt/settings.h and then make sure to include wolfssl/wolfcrypt/settings.h in your application.
Your code actually looks fine in fact I tested it successfully, here is a the quick app I threw together using our example from https://github.com/wolfSSL/wolfssl-exam … ient-tls.c and marrying it with your code, it runs fine when tested with our example server
SERVER COMMAND:
cd wolfssl/
./examples/server/server -d
CLIENT CODE:
#include <stdio.h>
#include <wolfssl/options.h>
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/ssl.h>
#include <wolfssl/wolfcrypt/error-crypt.h>
#include <wolfssl/wolfcrypt/random.h>
#define SSLERR -1
int main(int argc, char** argv)
{
/* WOLFSSL SUPPORT CODE: START */
int sockfd;
struct sockaddr_in servAddr;
char buff[256];
size_t len;
#define DEFAULT_PORT 11111
/* Check for proper calling convention */
if (argc != 2) {
printf("usage: %s <IPv4 address>\n", argv[0]);
return 0;
}
/* Create a socket that uses an internet IPv4 address,
* Sets the socket to be stream based (TCP),
* 0 means choose the default protocol. */
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
fprintf(stderr, "ERROR: failed to create the socket\n");
return -1;
}
/* Initialize the server address struct with zeros */
memset(&servAddr, 0, sizeof(servAddr));
/* Fill in the server address */
servAddr.sin_family = AF_INET; /* using IPv4 */
servAddr.sin_port = htons(DEFAULT_PORT); /* on DEFAULT_PORT */
/* Get the server IPv4 address from the command line call */
if (inet_pton(AF_INET, argv[1], &servAddr.sin_addr) != 1) {
fprintf(stderr, "ERROR: invalid address\n");
return -1;
}
/* Connect to the server */
if (connect(sockfd, (struct sockaddr*) &servAddr, sizeof(servAddr))
== -1) {
fprintf(stderr, "ERROR: failed to connect\n");
return -1;
}
/* WOLFSSL SUPPORT CODE: BREAK */
/* USER CODE (@Deltree): START */
WOLFSSL_CTX* ctx = NULL;
WOLFSSL* sslSock = NULL;
wolfSSL_Init();
ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method());
wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0);
if ( ctx == NULL )
{
printf("ERRO: WOLFSSL_CTX\n");
return(SSLERR);
}
sslSock = wolfSSL_new(ctx);
if ( sslSock == NULL )
{
int error = wolfSSL_get_error(sslSock, 0);
char *errStr="";
wolfSSL_ERR_error_string((unsigned long) error, errStr);
printf("ERRO: wolfSSL_new: %d , %s\n", error, errStr);
wolfSSL_CTX_free(ctx);
wolfSSL_Cleanup();
return(SSLERR);
}
/* USER CODE (@Deltree): END */
/* WOLFSSL SUPPORT CODE: RESUME */
/* Attach wolfSSL to the socket */
wolfSSL_set_fd(sslSock, sockfd);
/* Connect to wolfSSL on the server side */
if (wolfSSL_connect(sslSock) != SSL_SUCCESS) {
fprintf(stderr, "ERROR: failed to connect to wolfSSL\n");
return -1;
}
/* Get a message for the server from stdin */
printf("Message for server: ");
memset(buff, 0, sizeof(buff));
fgets(buff, sizeof(buff), stdin);
len = strnlen(buff, sizeof(buff));
/* Send the message to the server */
if (wolfSSL_write(sslSock, buff, len) != len) {
fprintf(stderr, "ERROR: failed to write\n");
return -1;
}
/* Read the server data into our buff array */
memset(buff, 0, sizeof(buff));
if (wolfSSL_read(sslSock, buff, sizeof(buff)-1) == -1) {
fprintf(stderr, "ERROR: failed to read\n");
return -1;
}
/* Print to stdout any data the server sends */
printf("Server: %s\n", buff);
/* Cleanup and return */
wolfSSL_free(sslSock); /* Free the wolfSSL object */
wolfSSL_CTX_free(ctx); /* Free the wolfSSL context object */
wolfSSL_Cleanup(); /* Cleanup the wolfSSL environment */
close(sockfd); /* Close the connection to the server */
/* WOLFSSL SUPPORT CODE: END */
return 0;
}
RESULT:
kalebhimes$ ./run 127.0.0.1
Message for server: yo
Server: I hear you fa shizzle!
Regards,
K