Feedback from review.

pull/139/head
David Garske 2019-03-27 10:35:21 -07:00
parent bb06f661fe
commit 04bd7c51d9
6 changed files with 81 additions and 80 deletions

View File

@ -32,7 +32,7 @@
#define SALT_SIZE 8 #define SALT_SIZE 8
/* /*
* Makes a cyptographically secure key by stretching a user entered key * Makes a cryptographically secure key by stretching a user entered key
*/ */
int GenerateKey(RNG* rng, byte* key, int size, byte* salt, int pad) int GenerateKey(RNG* rng, byte* key, int size, byte* salt, int pad)
{ {
@ -91,14 +91,14 @@ int Des3Encrypt(Des3* des3, byte* key, int size, FILE* inFile, FILE* outFile)
return -1030; return -1030;
} }
/* reads from inFile and wrties whatever is there to the input array */ /* reads from inFile and writes whatever is there to the input array */
ret = fread(input, 1, inputLength, inFile); ret = fread(input, 1, inputLength, inFile);
if (ret == 0) { if (ret == 0) {
printf("Input file does not exist.\n"); printf("Input file does not exist.\n");
return -1010; return -1010;
} }
for (i = inputLength; i < length; i++) { for (i = inputLength; i < length; i++) {
/* padds the added characters with the number of pads */ /* pads the added characters with the number of pads */
input[i] = padCounter; input[i] = padCounter;
} }
@ -116,7 +116,7 @@ int Des3Encrypt(Des3* des3, byte* key, int size, FILE* inFile, FILE* outFile)
if (ret != 0) if (ret != 0)
return -1001; return -1001;
/* encrypts the message to the ouput based on input length + padding */ /* encrypts the message to the output based on input length + padding */
ret = wc_Des3_CbcEncrypt(des3, output, input, length); ret = wc_Des3_CbcEncrypt(des3, output, input, length);
if (ret != 0) if (ret != 0)
return -1005; return -1005;
@ -166,7 +166,7 @@ int Des3Decrypt(Des3* des3, byte* key, int size, FILE* inFile, FILE* outFile)
wc_InitRng(&rng); wc_InitRng(&rng);
/* reads from inFile and wrties whatever is there to the input array */ /* reads from inFile and writes whatever is there to the input array */
ret = fread(input, 1, length, inFile); ret = fread(input, 1, length, inFile);
if (ret == 0) { if (ret == 0) {
printf("Input file does not exist.\n"); printf("Input file does not exist.\n");
@ -237,7 +237,7 @@ void help()
} }
/* /*
* temporarily deisables echoing in terminal for secure key input * temporarily disables echoing in terminal for secure key input
*/ */
int NoEcho(char* key, int size) int NoEcho(char* key, int size)
{ {

View File

@ -31,7 +31,7 @@
#define SALT_SIZE 8 #define SALT_SIZE 8
/* /*
* Makes a cyptographically secure key by stretching a user entered key * Makes a cryptographically secure key by stretching a user entered key
*/ */
int GenerateKey(RNG* rng, byte* key, int size, byte* salt, int pad) int GenerateKey(RNG* rng, byte* key, int size, byte* salt, int pad)
{ {
@ -90,14 +90,14 @@ int AesEncrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile)
return -1030; return -1030;
} }
/* reads from inFile and wrties whatever is there to the input array */ /* reads from inFile and writes whatever is there to the input array */
ret = fread(input, 1, inputLength, inFile); ret = fread(input, 1, inputLength, inFile);
if (ret == 0) { if (ret == 0) {
printf("Input file does not exist.\n"); printf("Input file does not exist.\n");
return -1010; return -1010;
} }
for (i = inputLength; i < length; i++) { for (i = inputLength; i < length; i++) {
/* padds the added characters with the number of pads */ /* pads the added characters with the number of pads */
input[i] = padCounter; input[i] = padCounter;
} }
@ -115,7 +115,7 @@ int AesEncrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile)
if (ret != 0) if (ret != 0)
return -1001; return -1001;
/* encrypts the message to the ouput based on input length + padding */ /* encrypts the message to the output based on input length + padding */
ret = wc_AesCbcEncrypt(aes, output, input, length); ret = wc_AesCbcEncrypt(aes, output, input, length);
if (ret != 0) if (ret != 0)
return -1005; return -1005;
@ -140,7 +140,7 @@ int AesEncrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile)
} }
/* /*
* Decryptsr a file using AES * Decrypts a file using AES
*/ */
int AesDecrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile) int AesDecrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile)
{ {
@ -165,7 +165,7 @@ int AesDecrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile)
wc_InitRng(&rng); wc_InitRng(&rng);
/* reads from inFile and wrties whatever is there to the input array */ /* reads from inFile and writes whatever is there to the input array */
ret = fread(input, 1, length, inFile); ret = fread(input, 1, length, inFile);
if (ret == 0) { if (ret == 0) {
printf("Input file does not exist.\n"); printf("Input file does not exist.\n");
@ -236,7 +236,7 @@ void help()
} }
/* /*
* temporarily deisables echoing in terminal for secure key input * temporarily disables echoing in terminal for secure key input
*/ */
int NoEcho(char* key, int size) int NoEcho(char* key, int size)
{ {

View File

@ -31,7 +31,7 @@
#define SALT_SIZE 8 #define SALT_SIZE 8
/* /*
* Makes a cyptographically secure key by stretMDMching a user entered key * Makes a cryptographically secure key by stretMDMching a user entered key
*/ */
int GenerateKey(RNG* rng, byte* key, int size, byte* salt, int pad) int GenerateKey(RNG* rng, byte* key, int size, byte* salt, int pad)
{ {
@ -91,14 +91,14 @@ int CamelliaEncrypt(Camellia* cam, byte* key, int size, FILE* inFile,
return -1030; return -1030;
} }
/* reads from inFile and wrties whatever is there to the input array */ /* reads from inFile and writes whatever is there to the input array */
ret = fread(input, 1, inputLength, inFile); ret = fread(input, 1, inputLength, inFile);
if (ret == 0) { if (ret == 0) {
printf("Input file does not exist.\n"); printf("Input file does not exist.\n");
return -1010; return -1010;
} }
for (i = inputLength; i < length; i++) { for (i = inputLength; i < length; i++) {
/* padds the added characters with the number of pads */ /* pads the added characters with the number of pads */
input[i] = padCounter; input[i] = padCounter;
} }
@ -116,7 +116,7 @@ int CamelliaEncrypt(Camellia* cam, byte* key, int size, FILE* inFile,
if (ret != 0) if (ret != 0)
return -1001; return -1001;
/* encrypts the message to the ouput based on input length + padding */ /* encrypts the message to the output based on input length + padding */
wc_CamelliaCbcEncrypt(cam, output, input, length); wc_CamelliaCbcEncrypt(cam, output, input, length);
/* writes to outFile */ /* writes to outFile */
@ -165,7 +165,7 @@ int CamelliaDecrypt(Camellia* cam, byte* key, int size, FILE* inFile,
wc_InitRng(&rng); wc_InitRng(&rng);
/* reads from inFile and wrties whatever is there to the input array */ /* reads from inFile and writes whatever is there to the input array */
ret = fread(input, 1, length, inFile); ret = fread(input, 1, length, inFile);
if (ret == 0) { if (ret == 0) {
printf("Input file does not exist.\n"); printf("Input file does not exist.\n");
@ -233,7 +233,7 @@ void help()
} }
/* /*
* temporarily deisables echoing in terminal for secure key input * temporarily disables echoing in terminal for secure key input
*/ */
int NoEcho(char* key, int size) int NoEcho(char* key, int size)
{ {

View File

@ -1,51 +1,52 @@
This is an example to demonstrate how the custom IO callbacks can be used to This is an example to demonstrate how the custom IO callbacks can be used to</br>
facilitate a TLS connection using any medium. Here we chose the medium: "File System". facilitate a TLS connection using any medium. Here we chose the medium: "File System".</br>
Other mediums might be: Other mediums might be: </br>
USB Serial connection USB Serial connection </br>
Bluetooth Bluetooth </br>
RFID RFID </br>
Wifi Wifi </br>
Ethernet Ethernet </br>
</br>
Just to name a few. Just to name a few.</br>
</br>
These examples use the wolfSSL Custom IO Callbacks to read and write to the file These examples use the wolfSSL Custom IO Callbacks to read and write to the file</br>
system and perform a successful handshake. system and perform a successful handshake.</br>
</br>
The configuration used for these examples was: The configuration used for these examples was:</br>
./configure --enable-debug ./configure --enable-debug</br>
</br>
Debug was enabled in case a user wishes to use the verbose flag to see what is Debug was enabled in case a user wishes to use the verbose flag to see what is</br>
happening in real time: happening in real time:</br>
</br>
Usage examples: Usage examples:</br>
</br>
From the file-server directory: From the file-server directory:</br>
./start-server ./start-server</br>
./start-server -v ./start-server -v</br>
./start-server -verbose ./start-server -verbose</br>
</br>
From the file-client directory: From the file-client directory:</br>
./start-client ./start-client</br>
./start-client -v ./start-client -v</br>
./start-client -verbose ./start-client -verbose</br>
</br>
(-v and -verbose accomplish the same thing) (-v and -verbose accomplish the same thing)</br>
</br>
</br>
SCRIPTS: The scripts provided attempt to make testing easier. SCRIPTS: The scripts provided attempt to make testing easier.</br>
</br>
file-server/check.sh file-server/check.sh</br>
- starts the server in a background shell and runs the client - starts the server in a background shell and runs the client </br>
</br>
USAGE: USAGE:</br>
./check.sh ./check.sh</br>
./check.sh -v ./check.sh -v</br>
./check.sh -verbose ./check.sh -verbose</br>
</br>
file-client/clean-io-files.sh file-client/clean-io-files.sh</br>
- If something happens and there is leftover junk in the io files run this - If something happens and there is leftover junk in the io files run this</br>
script to quickly cleanup before next round of testing. script to quickly cleanup before next round of testing.</br>
USAGE: USAGE:</br>
./clean-io-files.sh ./clean-io-files.sh</br>
</br>

View File

@ -24,7 +24,7 @@
#define MAX_LEN 1024 #define MAX_LEN 1024
int wolfCLU_decrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size, int wolfCLU_decrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size,
char* in, char* out, byte* iv, int block, int keyType) char* in, char* out, byte* iv, int block, int keyType)
{ {
#ifndef NO_AES #ifndef NO_AES
@ -67,7 +67,7 @@ int wolfCLU_decrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size,
if ((outFile = fopen(out, "wb")) == NULL) { if ((outFile = fopen(out, "wb")) == NULL) {
printf("Error creating output file.\n"); printf("Error creating output file.\n");
return DECRYPT_ERROR; return DECRYPT_ERROR;
} }
/* find end of file for length */ /* find end of file for length */
@ -75,8 +75,8 @@ int wolfCLU_decrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size,
length = (int) ftell(inFile); length = (int) ftell(inFile);
fseek(inFile, 0, SEEK_SET); fseek(inFile, 0, SEEK_SET);
/* if there is a remainder, /* if there is a remainder,
* round up else no round * round up else no round
*/ */
if (length % MAX_LEN > 0) { if (length % MAX_LEN > 0) {
lastLoopFlag = (length/MAX_LEN) + 1; lastLoopFlag = (length/MAX_LEN) + 1;
@ -96,7 +96,7 @@ int wolfCLU_decrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size,
wc_InitRng(&rng); wc_InitRng(&rng);
/* reads from inFile and writes whatever /* reads from inFile and writes whatever
* is there to the input buffer * is there to the input buffer
*/ */
while ( length > 0 ) { while ( length > 0 ) {
@ -112,7 +112,7 @@ int wolfCLU_decrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size,
printf("Error reading salt.\n"); printf("Error reading salt.\n");
wolfCLU_freeBins(input, output, NULL, NULL, NULL); wolfCLU_freeBins(input, output, NULL, NULL, NULL);
return FREAD_ERROR; return FREAD_ERROR;
} }
/* replicates old pwdKey if pwdKeys match */ /* replicates old pwdKey if pwdKeys match */
if (keyType == 1) { if (keyType == 1) {
if (wc_PBKDF2(key, pwdKey, (int) strlen((const char*)pwdKey), if (wc_PBKDF2(key, pwdKey, (int) strlen((const char*)pwdKey),
@ -138,7 +138,7 @@ int wolfCLU_decrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size,
printf("the key is all zero's or not set.\n"); printf("the key is all zero's or not set.\n");
wolfCLU_freeBins(input, output, NULL, NULL, NULL); wolfCLU_freeBins(input, output, NULL, NULL, NULL);
return ENCRYPT_ERROR; return ENCRYPT_ERROR;
} }
} }
} }
@ -154,7 +154,7 @@ int wolfCLU_decrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size,
} }
} }
/* sets pwdKey decrypts the message to ouput from input length */ /* sets pwdKey decrypts the message to output from input length */
#ifndef NO_AES #ifndef NO_AES
if (XSTRNCMP(alg, "aes", 3) == 0) { if (XSTRNCMP(alg, "aes", 3) == 0) {
if (XSTRNCMP(mode, "cbc", 3) == 0) { if (XSTRNCMP(mode, "cbc", 3) == 0) {
@ -172,7 +172,7 @@ int wolfCLU_decrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size,
wolfCLU_freeBins(input, output, NULL, NULL, NULL); wolfCLU_freeBins(input, output, NULL, NULL, NULL);
return DECRYPT_ERROR; return DECRYPT_ERROR;
} }
} }
#ifdef WOLFSSL_AES_COUNTER #ifdef WOLFSSL_AES_COUNTER
else if (XSTRNCMP(mode, "ctr", 3) == 0) { else if (XSTRNCMP(mode, "ctr", 3) == 0) {
/* if mode is ctr */ /* if mode is ctr */
@ -229,7 +229,7 @@ int wolfCLU_decrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size,
XMEMSET(output, 0, tempMax); XMEMSET(output, 0, tempMax);
break; break;
} }
} }
/* writes output to the outFile */ /* writes output to the outFile */
fwrite(output, 1, tempMax, outFile); fwrite(output, 1, tempMax, outFile);

View File

@ -190,7 +190,7 @@ int wolfCLU_encrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size,
}/* End feof check */ }/* End feof check */
}/* End fread check */ }/* End fread check */
/* sets key encrypts the message to ouput from input */ /* sets key encrypts the message to output from input */
#ifndef NO_AES #ifndef NO_AES
if (XSTRNCMP(alg, "aes", 3) == 0) { if (XSTRNCMP(alg, "aes", 3) == 0) {
if (XSTRNCMP(mode, "cbc", 3) == 0) { if (XSTRNCMP(mode, "cbc", 3) == 0) {