Hi alexander79,
I can not fix your code unfortunately. I have never worked in or with C++ or C# unfortunately and cannot get your code to compile in a reasonable amount of time. What I will do is post two examples of an example client and server in our examples directory on github. You can view the code there and try to translate that into your working language/environment.
Link to client: https://github.com/wolfSSL/wolfssl-exam … ls-ecdhe.c
Link to server: https://github.com/wolfSSL/wolfssl-exam … ls-ecdhe.c
I am also including a diff of the base client with the ecdh additions so you can see what changes were made:
Client diff:
--- client-tls.c 2015-08-28 14:02:17.000000000 -0600
+++ client-tls-ecdhe.c 2015-08-28 13:44:15.000000000 -0600
@@ -23,12 +23,14 @@
#include <string.h>
#include <errno.h>
#include <arpa/inet.h>
+#include <wolfssl/options.h>
#include <wolfssl/ssl.h> /* wolfSSL security library */
+#include <wolfssl/test.h>
#define MAXDATASIZE 4096 /* maximum acceptable amount of data */
#define SERV_PORT 11111 /* define default port number */
-const char* cert = "../certs/ca-cert.pem";
+const char* cert = "../certs/server-ecc.pem";
/*
* clients initial contact with server. (socket to connect, security layer)
@@ -68,6 +70,10 @@
WOLFSSL_CTX* ctx;
WOLFSSL* ssl; /* create WOLFSSL object */
int ret = 0;
+ const char* myCert = "../certs/client-ecc-cert.pem";
+ const char* myKey = "../certs/ecc-client-key.pem";
+ char* cipherList = "ECDHE-ECDSA-CHACHA20-POLY1305";
+ char buffer[WOLFSSL_MAX_ERROR_SZ];
wolfSSL_Init(); /* initialize wolfSSL */
@@ -77,11 +83,25 @@
return EXIT_FAILURE;
}
+ if (wolfSSL_CTX_set_cipher_list(ctx, cipherList) != SSL_SUCCESS)
+ err_sys("client can't set cipher list 1");
+
+ if (wolfSSL_CTX_use_certificate_chain_file(ctx, myCert)
+ != SSL_SUCCESS)
+ err_sys("can't load client cert file, check file and run from"
+ " wolfSSL home dir");
+
+ if (wolfSSL_CTX_use_PrivateKey_file(ctx, myKey, SSL_FILETYPE_PEM)
+ != SSL_SUCCESS)
+ err_sys("can't load client private key file, check file and run "
+ "from wolfSSL home dir");
+
/* load CA certificates into wolfSSL_CTX. which will verify the server */
if (wolfSSL_CTX_load_verify_locations(ctx, cert, 0) != SSL_SUCCESS) {
printf("Error loading %s. Please check the file.\n", cert);
return EXIT_FAILURE;
}
+
if ((ssl = wolfSSL_new(ctx)) == NULL) {
printf("wolfSSL_new error.\n");
return EXIT_FAILURE;
@@ -91,8 +111,14 @@
ret = wolfSSL_connect(ssl);
if (ret == SSL_SUCCESS) {
ret = ClientGreet(sock, ssl);
+ } else {
+ printf("Failure:");
+ ret = wolfSSL_get_error(ssl, 0);
+ printf(" ret = %d", ret);
+ printf(" %s\n", wolfSSL_ERR_error_string(ret, buffer));
}
+
/* frees all data before client termination */
wolfSSL_free(ssl);
wolfSSL_CTX_free(ctx);
Server diff:
--- server-tls.c 2015-08-28 14:05:27.000000000 -0600
+++ server-tls-ecdhe.c 2015-08-28 14:06:19.000000000 -0600
@@ -32,6 +32,7 @@
#include <netinet/in.h>
#include <stdlib.h>
#include <errno.h>
+#include <wolfssl/options.h>
/* include the wolfSSL library for our TLS 1.2 security */
#include <wolfssl/ssl.h>
@@ -124,6 +125,7 @@
int ret = 0; /* Return value */
/* Server and client socket address structures */
struct sockaddr_in serverAddr, clientAddr;
+ char* cipherList = "ECDHE-ECDSA-CHACHA20-POLY1305";
/* Initialize wolfSSL */
wolfSSL_Init();
@@ -141,7 +143,7 @@
}
/* Load server certificate into WOLFSSL_CTX */
- if (wolfSSL_CTX_use_certificate_file(ctx, "../certs/server-cert.pem",
+ if (wolfSSL_CTX_use_certificate_file(ctx, "../certs/server-ecc.pem",
SSL_FILETYPE_PEM) != SSL_SUCCESS) {
fprintf(stderr, "Error loading certs/server-cert.pem, please check"
"the file.\n");
@@ -149,13 +151,16 @@
}
/* Load server key into WOLFSSL_CTX */
- if (wolfSSL_CTX_use_PrivateKey_file(ctx, "../certs/server-key.pem",
+ if (wolfSSL_CTX_use_PrivateKey_file(ctx, "../certs/ecc-key.pem",
SSL_FILETYPE_PEM) != SSL_SUCCESS) {
fprintf(stderr, "Error loading certs/server-key.pem, please check"
"the file.\n");
return EXIT_FAILURE;
}
+ if (wolfSSL_CTX_set_cipher_list(ctx, cipherList) != SSL_SUCCESS)
+ printf("client can't set cipher list 1");
+
/* Initialize the server address struct to zero */
memset((char *)&serverAddr, 0, sizeof(serverAddr));