Getting files to run and pass nightly-CDT test
parent
d3c8997d7c
commit
c8d596269d
|
@ -158,6 +158,8 @@ int gen_csr(int type)
|
|||
pemSz = ret;
|
||||
printf("%s (%d)", pem, pemSz);
|
||||
|
||||
ret = 0;
|
||||
|
||||
exit:
|
||||
if (type == EC_KEY_TYPE) {
|
||||
wc_ecc_free(&ecKey);
|
||||
|
|
Binary file not shown.
|
@ -348,7 +348,8 @@ int main(int argc, char** argv)
|
|||
Des3Decrypt(&des3, key, size, inFile, outFile);
|
||||
}
|
||||
else if (choice == 'n') {
|
||||
printf("Must select either -e or -d for encryption and decryption\n");
|
||||
printf("Must select either -e[56,112,168] or -d[56,112,168] for \
|
||||
encryption and decryption\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -347,7 +347,8 @@ int main(int argc, char** argv)
|
|||
AesDecrypt(&aes, key, size, inFile, outFile);
|
||||
}
|
||||
else if (choice == 'n') {
|
||||
printf("Must select either -e or -d for encryption and decryption\n");
|
||||
printf("Must select either -e[128, 192, 256] or -d[128, 192, 256] \
|
||||
for encryption and decryption\n");
|
||||
ret = -110;
|
||||
}
|
||||
|
||||
|
|
|
@ -348,7 +348,8 @@ int main(int argc, char** argv)
|
|||
AesDecrypt(&aes, key, size, inFile, outFile);
|
||||
}
|
||||
else if (choice == 'n') {
|
||||
printf("Must select either -e or -d for encryption and decryption\n");
|
||||
printf("Must select either -e[128, 192, 256] or -d[128, 192, 256] \
|
||||
for encryption and decryption\n");
|
||||
ret = -110;
|
||||
}
|
||||
|
||||
|
|
|
@ -312,7 +312,8 @@ int main(int argc, char** argv)
|
|||
AesCtrDecrypt(&aes, key, size, inFile, outFile);
|
||||
}
|
||||
else if (choice == 'n') {
|
||||
printf("Must select either -e or -d for encryption and decryption\n");
|
||||
printf("Must select either -e[128, 192, 256] or -d[128, 192, 256] \
|
||||
for encryption and decryption\n");
|
||||
ret = -110;
|
||||
}
|
||||
|
||||
|
|
|
@ -344,7 +344,8 @@ int main(int argc, char** argv)
|
|||
CamelliaDecrypt(&cam, key, size, inFile, outFile);
|
||||
}
|
||||
else if (choice == 'n') {
|
||||
printf("Must select either -e or -d for encryption and decryption\n");
|
||||
printf("Must select either -e[128,192,256] or -d[128,192,256] for \
|
||||
encryption and decryption\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -14,4 +14,4 @@ all: $(TARGETS)
|
|||
.PHONY: clean
|
||||
|
||||
clean:
|
||||
rm -f $(TARGETS)
|
||||
rm -f $(TARGETS) encryptedAesKey
|
||||
|
|
|
@ -32,15 +32,15 @@ sudo make install
|
|||
Once the wolfSSL libraries are configured and installed the from this directory
|
||||
run the build.sh script which will generate the two applications
|
||||
|
||||
rsa-priv-enc
|
||||
rsa-pub-dec
|
||||
rsa-private-encrypt-app
|
||||
rsa-public-decrypt-app
|
||||
|
||||
------------------------
|
||||
|
||||
USING:
|
||||
|
||||
```
|
||||
./rsa-priv-enc
|
||||
./rsa-private-encrypt-app
|
||||
```
|
||||
|
||||
This will output the file "encryptedAesKey"
|
||||
|
@ -54,7 +54,7 @@ specified on line 33 of the application "rsa-private-encrypt-app.c".
|
|||
Now run
|
||||
|
||||
```
|
||||
./rsa-pub-dec
|
||||
./rsa-public-decrypt-app
|
||||
```
|
||||
|
||||
This will open the file specified on line 32 of the application
|
||||
|
|
|
@ -87,15 +87,23 @@ static int authEnvelopedData_encrypt(byte* cert, word32 certSz, byte* key,
|
|||
{
|
||||
int ret;
|
||||
PKCS7* pkcs7;
|
||||
WC_RNG rng;
|
||||
|
||||
pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID);
|
||||
if (pkcs7 == NULL)
|
||||
return -1;
|
||||
|
||||
ret = wc_InitRng(&rng);
|
||||
if(ret != 0){
|
||||
printf("wc_InitRng() failed, ret = %d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pkcs7->content = (byte*)data;
|
||||
pkcs7->contentSz = sizeof(data);
|
||||
pkcs7->contentOID = DATA;
|
||||
pkcs7->encryptOID = AES256GCMb;
|
||||
pkcs7->rng = &rng;
|
||||
|
||||
/* add recipient using ECC certificate (KARI type) */
|
||||
ret = wc_PKCS7_AddRecipient_KARI(pkcs7, cert, certSz, AES256_WRAP,
|
||||
|
@ -124,6 +132,7 @@ static int authEnvelopedData_encrypt(byte* cert, word32 certSz, byte* key,
|
|||
}
|
||||
}
|
||||
|
||||
wc_FreeRng(&rng);
|
||||
wc_PKCS7_Free(pkcs7);
|
||||
|
||||
return ret;
|
||||
|
@ -135,11 +144,18 @@ static int authEnvelopedData_decrypt(byte* in, word32 inSz, byte* cert,
|
|||
{
|
||||
int ret;
|
||||
PKCS7* pkcs7;
|
||||
WC_RNG rng;
|
||||
|
||||
pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID);
|
||||
if (pkcs7 == NULL)
|
||||
return -1;
|
||||
|
||||
ret = wc_InitRng(&rng);
|
||||
if(ret != 0){
|
||||
printf("wc_InitRng() failed, ret = %d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* init with recipient cert */
|
||||
ret = wc_PKCS7_InitWithCert(pkcs7, cert, certSz);
|
||||
if (ret != 0) {
|
||||
|
@ -156,6 +172,8 @@ static int authEnvelopedData_decrypt(byte* in, word32 inSz, byte* cert,
|
|||
return -1;
|
||||
}
|
||||
|
||||
pkcs7->rng = &rng;
|
||||
|
||||
/* decode envelopedData, returns size */
|
||||
ret = wc_PKCS7_DecodeAuthEnvelopedData(pkcs7, in, inSz, out, outSz);
|
||||
if (ret <= 0 || (ret != sizeof(data)) || (XMEMCMP(out, data, ret) != 0)) {
|
||||
|
@ -168,6 +186,7 @@ static int authEnvelopedData_decrypt(byte* in, word32 inSz, byte* cert,
|
|||
encodedFileKARI);
|
||||
}
|
||||
|
||||
wc_FreeRng(&rng);
|
||||
wc_PKCS7_Free(pkcs7);
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -87,15 +87,23 @@ static int envelopedData_encrypt(byte* cert, word32 certSz, byte* key,
|
|||
{
|
||||
int ret;
|
||||
PKCS7* pkcs7;
|
||||
WC_RNG rng;
|
||||
|
||||
pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID);
|
||||
if (pkcs7 == NULL)
|
||||
return -1;
|
||||
|
||||
ret = wc_InitRng(&rng);
|
||||
if(ret != 0){
|
||||
printf("wc_InitRng() failed, ret = %d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pkcs7->content = (byte*)data;
|
||||
pkcs7->contentSz = sizeof(data);
|
||||
pkcs7->contentOID = DATA;
|
||||
pkcs7->encryptOID = AES256CBCb;
|
||||
pkcs7->rng = &rng;
|
||||
|
||||
/* add recipient using ECC certificate (KARI type) */
|
||||
ret = wc_PKCS7_AddRecipient_KARI(pkcs7, cert, certSz, AES256_WRAP,
|
||||
|
@ -124,6 +132,7 @@ static int envelopedData_encrypt(byte* cert, word32 certSz, byte* key,
|
|||
}
|
||||
}
|
||||
|
||||
wc_FreeRng(&rng);
|
||||
wc_PKCS7_Free(pkcs7);
|
||||
|
||||
return ret;
|
||||
|
@ -135,6 +144,13 @@ static int envelopedData_decrypt(byte* in, word32 inSz, byte* cert,
|
|||
{
|
||||
int ret;
|
||||
PKCS7* pkcs7;
|
||||
WC_RNG rng;
|
||||
|
||||
ret = wc_InitRng(&rng);
|
||||
if(ret != 0){
|
||||
printf("wc_InitRng() failed, ret = %d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID);
|
||||
if (pkcs7 == NULL)
|
||||
|
@ -156,6 +172,8 @@ static int envelopedData_decrypt(byte* in, word32 inSz, byte* cert,
|
|||
return -1;
|
||||
}
|
||||
|
||||
pkcs7->rng = &rng;
|
||||
|
||||
/* decode envelopedData, returns size */
|
||||
ret = wc_PKCS7_DecodeEnvelopedData(pkcs7, in, inSz, out, outSz);
|
||||
if (ret <= 0 || (ret != sizeof(data)) || (XMEMCMP(out, data, ret) != 0)) {
|
||||
|
@ -167,6 +185,7 @@ static int envelopedData_decrypt(byte* in, word32 inSz, byte* cert,
|
|||
encodedFileKARI);
|
||||
}
|
||||
|
||||
wc_FreeRng(&rng);
|
||||
wc_PKCS7_Free(pkcs7);
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -262,8 +262,8 @@ int main(int argc, char** argv)
|
|||
|
||||
byte cert[2048];
|
||||
byte key[2048];
|
||||
byte encrypted[2048];
|
||||
byte decrypted[2048];
|
||||
byte encrypted[5096];
|
||||
byte decrypted[5096];
|
||||
|
||||
#ifdef DEBUG_WOLFSSL
|
||||
wolfSSL_Debugging_ON();
|
||||
|
|
|
@ -281,8 +281,8 @@ int main(int argc, char** argv)
|
|||
|
||||
byte cert[2048];
|
||||
byte key[2048];
|
||||
byte encrypted[2048];
|
||||
byte decrypted[2048];
|
||||
byte encrypted[5096];
|
||||
byte decrypted[5096];
|
||||
|
||||
#ifdef DEBUG_WOLFSSL
|
||||
wolfSSL_Debugging_ON();
|
||||
|
|
|
@ -231,7 +231,7 @@ int main(int argc, char **argv)
|
|||
goto exit;
|
||||
}
|
||||
wolfSSL_set_bio(ssl, custom, custom);
|
||||
if (wolfSSL_BIO_set_ssl(bioSSL, ssl, BIO_CLOSE) != 0) {
|
||||
if (wolfSSL_BIO_set_ssl(bioSSL, ssl, BIO_CLOSE) != WOLFSSL_SUCCESS) {
|
||||
fprintf(stderr, "wolfSSL_BIO_set_ssl error.\n");
|
||||
goto exit;
|
||||
}
|
||||
|
|
|
@ -72,22 +72,23 @@ static inline unsigned int My_Psk_Client_Cb(WOLFSSL* ssl, const char* hint,
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int sockfd, ret, error, currTimeout;
|
||||
int sockfd = SOCKET_INVALID;
|
||||
int ret, error, currTimeout;
|
||||
int select_ret = TEST_SELECT_FAIL;
|
||||
int nfds;
|
||||
int result;
|
||||
char sendline[MAXLINE]="Hello Server"; /* string to send to the server */
|
||||
char recvline[MAXLINE]; /* string received from the server */
|
||||
fd_set recvfds, errfds;
|
||||
WOLFSSL_CTX* ctx;
|
||||
WOLFSSL* ssl;
|
||||
WOLFSSL_CTX* ctx = NULL;
|
||||
WOLFSSL* ssl = NULL;
|
||||
struct timeval timeout;
|
||||
struct sockaddr_in servaddr;
|
||||
|
||||
/* must include an ip address of this will flag */
|
||||
if (argc != 2) {
|
||||
printf("Usage: tcpClient <IPaddress>\n");
|
||||
return 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* create a stream socket using tcp,internet protocal IPv4,
|
||||
|
@ -104,14 +105,14 @@ int main(int argc, char **argv)
|
|||
ret = inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
|
||||
if (ret != 1) {
|
||||
printf("inet_pton error\n");
|
||||
return 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* attempts to make a connection on a socket */
|
||||
ret = connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr));
|
||||
if (ret != 0) {
|
||||
printf("Connection Error\n");
|
||||
return 1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* invokes the fcntl callable service to get the file status
|
||||
|
@ -120,7 +121,8 @@ int main(int argc, char **argv)
|
|||
int flags = fcntl(sockfd, F_GETFL, 0);
|
||||
if (flags < 0) {
|
||||
printf("fcntl get failed\n");
|
||||
return 1;
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* invokes the fcntl callable service to set file status flags.
|
||||
|
@ -130,7 +132,8 @@ int main(int argc, char **argv)
|
|||
flags = fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
|
||||
if (flags < 0) {
|
||||
printf("fcntl set failed\n");
|
||||
return 1;
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
wolfSSL_Init(); /* initialize wolfSSL */
|
||||
|
@ -138,7 +141,8 @@ int main(int argc, char **argv)
|
|||
/* create and initialize WOLFSSL_CTX structure */
|
||||
if ((ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method())) == NULL) {
|
||||
fprintf(stderr, "wolfSSL_CTX_new error.\n");
|
||||
return 1;
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* set up pre shared keys */
|
||||
|
@ -147,7 +151,8 @@ int main(int argc, char **argv)
|
|||
/* create wolfSSL object after each tcp connect */
|
||||
if ((ssl = wolfSSL_new(ctx)) == NULL) {
|
||||
fprintf(stderr, "wolfSSL_new error.\n");
|
||||
return 1;
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* associate the file descriptor with the session */
|
||||
|
@ -210,14 +215,15 @@ int main(int argc, char **argv)
|
|||
}
|
||||
if (ret != WOLFSSL_SUCCESS){
|
||||
printf("wolfSSL_connect failed");
|
||||
return 1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* takes inputting string and outputs it to the server */
|
||||
/* write string to the server */
|
||||
if (wolfSSL_write(ssl, sendline, MAXLINE) != sizeof(sendline)) {
|
||||
printf("Write Error to Server\n");
|
||||
return 1;
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* flags if the Server stopped before the client could end */
|
||||
|
@ -226,20 +232,25 @@ int main(int argc, char **argv)
|
|||
continue;
|
||||
}
|
||||
printf("Client: Server Terminated Prematurely!\n");
|
||||
return 1;
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* show message from the server */
|
||||
printf("Server Message: %s\n", recvline);
|
||||
|
||||
/* cleanup */
|
||||
wolfSSL_free(ssl);
|
||||
ret = 0;
|
||||
|
||||
/* when completely done using SSL/TLS, free the
|
||||
* wolfssl_ctx object */
|
||||
wolfSSL_CTX_free(ctx);
|
||||
wolfSSL_Cleanup();
|
||||
exit:
|
||||
/* Cleanup and return */
|
||||
if (ssl)
|
||||
wolfSSL_free(ssl); /* Free the wolfSSL object */
|
||||
if (sockfd != SOCKET_INVALID)
|
||||
close(sockfd); /* Close the socket */
|
||||
if (ctx)
|
||||
wolfSSL_CTX_free(ctx); /* Free the wolfSSL context object */
|
||||
wolfSSL_Cleanup(); /* Cleanup the wolfSSL environment */
|
||||
|
||||
return ret;
|
||||
return ret; /* Return reporting a success */
|
||||
|
||||
}
|
||||
|
|
|
@ -63,19 +63,21 @@ static inline unsigned int My_Psk_Client_Cb(WOLFSSL* ssl, const char* hint,
|
|||
|
||||
int main(int argc, char **argv){
|
||||
|
||||
int sockfd, sock, ret;
|
||||
int sockfd = SOCKET_INVALID;
|
||||
int sock = SOCKET_INVALID;
|
||||
int ret;
|
||||
char sendline[MAXLINE]="Hello Server"; /* string to send to the server */
|
||||
char recvline[MAXLINE]; /* string received from the server */
|
||||
WOLFSSL* ssl;
|
||||
WOLFSSL* sslResume = 0;
|
||||
WOLFSSL_SESSION* session = 0;
|
||||
WOLFSSL_CTX* ctx;
|
||||
WOLFSSL* ssl = NULL;
|
||||
WOLFSSL* sslResume = NULL;
|
||||
WOLFSSL_SESSION* session = NULL;
|
||||
WOLFSSL_CTX* ctx = NULL;
|
||||
struct sockaddr_in servaddr;;
|
||||
|
||||
/* must include an ip address of this will flag */
|
||||
if (argc != 2) {
|
||||
printf("Usage: tcpClient <IPaddress>\n");
|
||||
return 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* create a stream socket using tcp,internet protocal IPv4,
|
||||
|
@ -91,13 +93,13 @@ int main(int argc, char **argv){
|
|||
/* converts IPv4 addresses from text to binary form */
|
||||
ret = inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
|
||||
if (ret != 1){
|
||||
return 1;
|
||||
ret = -1; goto exit;
|
||||
}
|
||||
|
||||
/* attempts to make a connection on a socket */
|
||||
ret = connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr));
|
||||
if (ret != 0 ){
|
||||
return 1;
|
||||
ret = -1; goto exit;
|
||||
}
|
||||
|
||||
wolfSSL_Init(); /* initialize wolfSSL */
|
||||
|
@ -105,7 +107,7 @@ int main(int argc, char **argv){
|
|||
/* create and initialize WOLFSSL_CTX structure */
|
||||
if ((ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method())) == NULL) {
|
||||
fprintf(stderr, "wolfSSL_CTX_new error.\n");
|
||||
return 1;
|
||||
ret = -1; goto exit;
|
||||
}
|
||||
|
||||
/* set up pre shared keys */
|
||||
|
@ -114,7 +116,7 @@ int main(int argc, char **argv){
|
|||
/* create wolfSSL object after each tcp connect */
|
||||
if ( (ssl = wolfSSL_new(ctx)) == NULL) {
|
||||
fprintf(stderr, "wolfSSL_new error.\n");
|
||||
return 1;
|
||||
ret = -1; goto exit;
|
||||
}
|
||||
|
||||
/* associate the file descriptor with the session */
|
||||
|
@ -123,13 +125,13 @@ int main(int argc, char **argv){
|
|||
/* takes inputting string and outputs it to the server */
|
||||
if (wolfSSL_write(ssl, sendline, sizeof(sendline)) != sizeof(sendline)) {
|
||||
printf("Write Error to Server\n");
|
||||
return 1;
|
||||
ret = -1; goto exit;
|
||||
}
|
||||
|
||||
/* flags if the Server stopped before the client could end */
|
||||
if (wolfSSL_read(ssl, recvline, MAXLINE) < 0 ) {
|
||||
printf("Client: Server Terminated Prematurely!\n");
|
||||
return 1;
|
||||
ret = -1; goto exit;
|
||||
}
|
||||
|
||||
/* show message from the server */
|
||||
|
@ -159,7 +161,7 @@ int main(int argc, char **argv){
|
|||
ret = connect(sock, (struct sockaddr *) &servaddr, sizeof(servaddr));
|
||||
|
||||
if (ret != 0){
|
||||
return 1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* set the session ID to connect to the server */
|
||||
|
@ -169,18 +171,21 @@ int main(int argc, char **argv){
|
|||
/* check has connect successfully */
|
||||
if (wolfSSL_connect(sslResume) != WOLFSSL_SUCCESS) {
|
||||
printf("SSL resume failed\n");
|
||||
return 1;
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (wolfSSL_write(sslResume, sendline, sizeof(sendline)) != sizeof(sendline)) {
|
||||
printf("Write Error to Server\n");
|
||||
return 1;
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* flags if the Server stopped before the client could end */
|
||||
if (wolfSSL_read(sslResume, recvline, MAXLINE) < 0 ) {
|
||||
printf("Client: Server Terminated Prematurely!\n");
|
||||
return 1;
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* show message from the server */
|
||||
|
@ -194,12 +199,21 @@ int main(int argc, char **argv){
|
|||
}
|
||||
/* shut down wolfSSL */
|
||||
wolfSSL_shutdown(sslResume);
|
||||
/* shut down socket */
|
||||
close(sock);
|
||||
/* clean up now with wolfSSL_Cleanup() */
|
||||
wolfSSL_free(sslResume);
|
||||
wolfSSL_CTX_free(ctx);
|
||||
wolfSSL_Cleanup();
|
||||
|
||||
return ret;
|
||||
exit:
|
||||
/* Cleanup and return */
|
||||
if (ssl)
|
||||
wolfSSL_free(ssl); /* Free the wolfSSL object */
|
||||
if (sslResume)
|
||||
wolfSSL_free(sslResume); /* Free the wolfSSL object */
|
||||
if (sockfd != SOCKET_INVALID)
|
||||
close(sockfd); /* Close the socket */
|
||||
if (sock != SOCKET_INVALID)
|
||||
close(sock); /* Close the socket */
|
||||
if (ctx)
|
||||
wolfSSL_CTX_free(ctx); /* Free the wolfSSL context object */
|
||||
wolfSSL_Cleanup(); /* Cleanup the wolfSSL environment */
|
||||
|
||||
return ret; /* Return reporting a success */
|
||||
|
||||
}
|
||||
|
|
|
@ -61,18 +61,19 @@ static inline unsigned int My_Psk_Client_Cb(WOLFSSL* ssl, const char* hint,
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret, sockfd;
|
||||
int ret;
|
||||
int sockfd = SOCKET_INVALID;
|
||||
char sendline[MAXLINE]="Hello Server"; /* string to send to the server */
|
||||
char recvline[MAXLINE]; /* string received from the server */
|
||||
struct sockaddr_in servaddr;;
|
||||
|
||||
WOLFSSL* ssl;
|
||||
WOLFSSL_CTX* ctx;
|
||||
WOLFSSL* ssl = NULL;
|
||||
WOLFSSL_CTX* ctx = NULL;
|
||||
|
||||
/* must include an ip address of this will flag */
|
||||
if (argc != 2) {
|
||||
printf("Usage: tcpClient <IPaddress>\n");
|
||||
return 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* create a stream socket using tcp,internet protocal IPv4,
|
||||
|
@ -89,14 +90,16 @@ int main(int argc, char **argv)
|
|||
ret = inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
|
||||
if (ret != 1) {
|
||||
printf("inet_pton error\n");
|
||||
return 1;
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* attempts to make a connection on a socket */
|
||||
ret = connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr));
|
||||
if (ret != 0) {
|
||||
printf("Connection Error\n");
|
||||
return 1;
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
||||
|
@ -105,7 +108,8 @@ int main(int argc, char **argv)
|
|||
/* create and initialize WOLFSSL_CTX structure */
|
||||
if ((ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method())) == NULL) {
|
||||
fprintf(stderr, "wolfSSL_CTX_new error.\n");
|
||||
return 1;
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* set up pre shared keys */
|
||||
|
@ -114,38 +118,44 @@ int main(int argc, char **argv)
|
|||
/* creat wolfssl object after each tcp connect */
|
||||
if ( (ssl = wolfSSL_new(ctx)) == NULL) {
|
||||
fprintf(stderr, "wolfSSL_new error.\n");
|
||||
return 1;
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* associate the file descriptor with the session */
|
||||
ret = wolfSSL_set_fd(ssl, sockfd);
|
||||
if (ret != WOLFSSL_SUCCESS) {
|
||||
return 1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* write string to the server */
|
||||
if (wolfSSL_write(ssl, sendline, MAXLINE) != sizeof(sendline)) {
|
||||
printf("Write Error to Server\n");
|
||||
return 1;
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* check if server ended before client could read a response */
|
||||
if (wolfSSL_read(ssl, recvline, MAXLINE) < 0 ) {
|
||||
printf("Client: Server Terminated Prematurely!\n");
|
||||
return 1;
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* show message from the server */
|
||||
printf("Server Message: %s\n", recvline);
|
||||
|
||||
/* cleanup */
|
||||
wolfSSL_free(ssl);
|
||||
ret = 0;
|
||||
|
||||
/* when completely done using SSL/TLS, free the
|
||||
* wolfssl_ctx object */
|
||||
wolfSSL_CTX_free(ctx);
|
||||
wolfSSL_Cleanup();
|
||||
exit:
|
||||
/* Cleanup and return */
|
||||
if (ssl)
|
||||
wolfSSL_free(ssl); /* Free the wolfSSL object */
|
||||
if (sockfd != SOCKET_INVALID)
|
||||
close(sockfd); /* Close the socket */
|
||||
if (ctx)
|
||||
wolfSSL_CTX_free(ctx); /* Free the wolfSSL context object */
|
||||
wolfSSL_Cleanup(); /* Cleanup the wolfSSL environment */
|
||||
|
||||
/* exit client */
|
||||
return ret;
|
||||
return ret; /* Return reporting a success */
|
||||
}
|
||||
|
|
|
@ -94,5 +94,7 @@ int main(int argc, char **argv)
|
|||
/* close socket and connection */
|
||||
close(sockfd);
|
||||
|
||||
ret = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
Configure and install wolfSSL with these options:
|
||||
|
||||
./configure --disable-shared --disable-asn --disable-filesystem \
|
||||
./configure --disable-asn --disable-filesystem \
|
||||
--enable-cryptonly --enable-sp=smallrsa2048 --enable-sp-math \
|
||||
--disable-dh --disable-ecc --disable-sha224 --enable-rsavfy
|
||||
--disable-dh --disable-ecc --disable-sha224 --enable-rsavfy \
|
||||
CFLAGS="-DWOLFSSL_PUBLIC_MP"
|
||||
make
|
||||
make install
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <wolfssl/options.h>
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
#include <wolfssl/wolfcrypt/rsa.h>
|
||||
#include <wolfssl/wolfcrypt/sha256.h>
|
||||
|
||||
|
|
|
@ -160,6 +160,8 @@ int main(int argc, char** argv)
|
|||
/* Print to stdout any data the server sends */
|
||||
printf("Server: %s\n", buff);
|
||||
|
||||
ret = 0;
|
||||
|
||||
exit:
|
||||
/* Cleanup and return */
|
||||
if (bio)
|
||||
|
|
|
@ -214,6 +214,8 @@ int main(int argc, char** argv)
|
|||
}
|
||||
Security(sockfd);
|
||||
|
||||
ret = 0;
|
||||
|
||||
exit:
|
||||
/* Cleanup and return */
|
||||
if (sockfd != SOCKET_INVALID)
|
||||
|
|
|
@ -271,6 +271,7 @@ int main(int argc, char** argv)
|
|||
/* Print to stdout any data the server sends */
|
||||
printf("Server: %s\n", buff);
|
||||
|
||||
ret = 0;
|
||||
|
||||
exit:
|
||||
/* Cleanup and return */
|
||||
|
|
|
@ -602,6 +602,8 @@ int main(int argc, char** argv)
|
|||
/* Print to stdout any data the server sends */
|
||||
printf("Server: %s\n", buff);
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* Cleanup and return */
|
||||
cleanup:
|
||||
wolfSSL_free(ssl); /* Free the wolfSSL object */
|
||||
|
|
|
@ -194,6 +194,7 @@ int main(int argc, char** argv)
|
|||
/* Print to stdout any data the server sends */
|
||||
printf("Server: %s\n", buff);
|
||||
|
||||
ret = 0;
|
||||
|
||||
exit:
|
||||
/* Cleanup and return */
|
||||
|
|
|
@ -250,6 +250,8 @@ int main(int argc, char** argv)
|
|||
ret == WOLFSSL_ERROR_WANT_WRITE);
|
||||
printf("Shutdown complete\n");
|
||||
|
||||
ret = 0;
|
||||
|
||||
exit:
|
||||
/* Cleanup and return */
|
||||
if (ssl)
|
||||
|
|
|
@ -234,7 +234,11 @@ int main(int argc, char** argv)
|
|||
/* Get a message for the server from stdin */
|
||||
printf("Message for server: ");
|
||||
memset(buff, 0, sizeof(buff));
|
||||
fgets(buff, sizeof(buff), stdin);
|
||||
if (fgets(buff, sizeof(buff), stdin) == NULL) {
|
||||
fprintf(stderr, "ERROR: failed to get message for server\n");
|
||||
ret = -1;
|
||||
goto client_example_end;
|
||||
}
|
||||
len = strnlen(buff, sizeof(buff));
|
||||
|
||||
/* Send the message to the server */
|
||||
|
@ -254,6 +258,8 @@ int main(int argc, char** argv)
|
|||
/* Print to stdout any data the server sends */
|
||||
printf("Server: %s\n", buff);
|
||||
|
||||
ret = 0;
|
||||
|
||||
client_example_end:
|
||||
/* Cleanup and return */
|
||||
wolfSSL_free(ssl); /* Free the wolfSSL object */
|
||||
|
|
|
@ -275,8 +275,10 @@ exit:
|
|||
/* Cleanup and return */
|
||||
if (ssl)
|
||||
wolfSSL_free(ssl); /* Free the wolfSSL object */
|
||||
#ifdef OPENSSL_EXTRA
|
||||
if (session)
|
||||
wolfSSL_SESSION_free(session);
|
||||
#endif
|
||||
if (sockfd != SOCKET_INVALID)
|
||||
close(sockfd); /* Close the socket */
|
||||
if (ctx)
|
||||
|
|
|
@ -212,6 +212,7 @@ int main(int argc, char** argv)
|
|||
pthread_join(write_thread, NULL);
|
||||
pthread_join(read_thread, NULL);
|
||||
|
||||
ret = 0;
|
||||
|
||||
exit:
|
||||
/* Cleanup and return */
|
||||
|
|
|
@ -167,6 +167,7 @@ int main(int argc, char** argv)
|
|||
|
||||
printf("Shutdown complete\n");
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* Cleanup and return */
|
||||
cleanup:
|
||||
|
|
|
@ -306,6 +306,8 @@ int main()
|
|||
close(connd); /* Close the connection to the client */
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
exit:
|
||||
/* Cleanup and return */
|
||||
if (ssl)
|
||||
|
|
|
@ -206,6 +206,7 @@ int main()
|
|||
close(connd); /* Close the connection to the client */
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
exit:
|
||||
/* Cleanup and return */
|
||||
|
|
|
@ -288,6 +288,8 @@ int main()
|
|||
|
||||
printf("Shutdown complete\n");
|
||||
|
||||
ret = 0;
|
||||
|
||||
exit:
|
||||
/* Cleanup and return */
|
||||
if (ssl)
|
||||
|
|
|
@ -300,6 +300,7 @@ int main()
|
|||
|
||||
printf("Shutdown complete\n");
|
||||
|
||||
ret = 0;
|
||||
|
||||
exit:
|
||||
/* Cleanup and return */
|
||||
|
|
|
@ -313,6 +313,7 @@ int main()
|
|||
|
||||
printf("Shutdown complete\n");
|
||||
|
||||
ret = 0;
|
||||
|
||||
exit:
|
||||
/* Cleanup and return */
|
||||
|
|
|
@ -200,6 +200,8 @@ int main()
|
|||
close(connd); /* Close the connection to the client */
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
exit:
|
||||
/* Cleanup and return */
|
||||
if (ssl)
|
||||
|
|
Loading…
Reference in New Issue