diff --git a/wolfCLU/README.md b/wolfCLU/README.md index b3822d45..ccea4eb6 100644 --- a/wolfCLU/README.md +++ b/wolfCLU/README.md @@ -1,8 +1,8 @@ -#wolfCLU +# wolfCLU -This is the wolfSSL: Command Line Utility (wolfCLU). +This is the wolfSSL: Command Line Utility (wolfCLU). -##wolfSSL Install +## wolfSSL Install To use this feature, please configure and install wolfssl with the following commands: @@ -19,6 +19,9 @@ recipient of the encrypted file. `--enable-opensslextra` provides utility for a hex to binary conversion of hexidecimal values. +`--enable-base64encode` enables Base64 encoding (not on by default) + + Additional features that can be included when configuring wolfssl for encryption or decryption are: @@ -44,4 +47,26 @@ Now you should be able to use the wolfssl command line tool. To verify type: If everything worked, you should see the wolfssl help page. -Thank you and have fun! +## Examples + +### Base64 + +#### Encode + +``` +./wolfssl -hash base64enc -in README.md > README_encoded.md +``` + +#### Decode + +``` +./wolfssl -hash base64dec -in README_encoded.md +``` + +## Contacts + +Please contact support@wolfssl.com with any questions or comments + +## License + +Copyright (c) 2006-2015 wolfSSL Inc. diff --git a/wolfCLU/include/wolfssl.h b/wolfCLU/include/wolfssl.h index 11538e01..fdf65c9d 100644 --- a/wolfCLU/include/wolfssl.h +++ b/wolfCLU/include/wolfssl.h @@ -65,6 +65,8 @@ #include #endif +#include + #ifndef UTIL_H_INCLUDED #define UTIL_H_INCLUDED diff --git a/wolfCLU/src/hash/wolfsslHash.c b/wolfCLU/src/hash/wolfsslHash.c index d0c55a6f..4d838d17 100644 --- a/wolfCLU/src/hash/wolfsslHash.c +++ b/wolfCLU/src/hash/wolfsslHash.c @@ -40,9 +40,7 @@ int wolfsslHash(char* in, char* out, char* alg, int size) int i = 0; /* loop variable */ int ret = -1; /* return variable */ int length; /* length of hash */ - - output = malloc(size); - XMEMSET(output, 0, size); + int outputAsHexString = 1; /* opens input file */ inFile = fopen(in, "rb"); @@ -76,6 +74,15 @@ int wolfsslHash(char* in, char* out, char* alg, int size) ret = (int) fread(input, 1, length, inFile); fclose(inFile); } + + /* if size not provided then use input length */ + if (size == 0) { + size = length * 4; + } + + output = malloc(size); + XMEMSET(output, 0, size); + /* hashes using accepted algorithm */ #ifndef NO_MD5 if (strcmp(alg, "md5") == 0) { @@ -109,6 +116,20 @@ int wolfsslHash(char* in, char* out, char* alg, int size) ret = wc_Blake2bFinal(&hash, output, size); } #endif + +#ifndef NO_CODING +#ifdef WOLFSSL_BASE64_ENCODE + else if (strcmp(alg, "base64enc") == 0) { + ret = Base64_Encode(input, length, output, (word32*)&size); + outputAsHexString = 0; + } +#endif /* WOLFSSL_BASE64_ENCODE */ + else if (strcmp(alg, "base64dec") == 0) { + ret = Base64_Decode(input, length, output, (word32*)&size); + outputAsHexString = 0; + } +#endif /* !NO_CODING */ + if (ret == 0) { /* if no errors so far */ if (out != NULL) { @@ -118,7 +139,10 @@ int wolfsslHash(char* in, char* out, char* alg, int size) /* if outFile exists */ for (i = 0; i < size; i++) { /* writes hashed output to outFile */ - fprintf(outFile, "%02x", output[i]); + if (outputAsHexString) + fprintf(outFile, "%02x", output[i]); + else + fprintf(outFile, "%c", output[i]); } fclose(outFile); } @@ -127,7 +151,10 @@ int wolfsslHash(char* in, char* out, char* alg, int size) /* if no output file */ for (i = 0; i < size; i++) { /* write hashed output to terminal */ - printf("%02x", output[i]); + if (outputAsHexString) + printf("%02x", output[i]); + else + printf("%c", output[i]); } printf("\n"); } diff --git a/wolfCLU/src/hash/wolfsslHashSetup.c b/wolfCLU/src/hash/wolfsslHashSetup.c index e2b2a327..5184eb8f 100644 --- a/wolfCLU/src/hash/wolfsslHashSetup.c +++ b/wolfCLU/src/hash/wolfsslHashSetup.c @@ -35,19 +35,25 @@ int wolfsslHashSetup(int argc, char** argv) "md5" #endif #ifndef NO_SHA - , "sha" + , "sha" #endif #ifndef NO_SHA256 - , "sha256" + , "sha256" #endif #ifdef WOLFSSL_SHA384 - , "sha384" + , "sha384" #endif #ifdef WOLFSSL_SHA512 - , "sha512" + , "sha512" #endif #ifdef HAVE_BLAKE2 - , "blake2b" + , "blake2b" +#endif +#ifndef NO_CODING + #ifdef WOLFSSL_BASE64_ENCODE + , "base64enc" + #endif + , "base64dec" #endif }; @@ -146,7 +152,7 @@ int wolfsslHashSetup(int argc, char** argv) #endif /* hashing function */ - wolfsslHash(in, out, alg, size); + ret = wolfsslHash(in, out, alg, size); free(in); diff --git a/wolfCLU/src/tools/wolfsslFuncs.c b/wolfCLU/src/tools/wolfsslFuncs.c index 8850a8b9..f0c65ad0 100644 --- a/wolfCLU/src/tools/wolfsslFuncs.c +++ b/wolfCLU/src/tools/wolfsslFuncs.c @@ -68,77 +68,85 @@ int i = 0; /* loop variable */ void wolfsslVerboseHelp() { printf("\nwolfssl Command Line Utility version %3.1f\n\n", VERSION); + /* hash options */ const char* algsenc[] = { /* list of acceptable algorithms */ #ifndef NO_MD5 - "md5" + "md5" #endif #ifndef NO_SHA - ,"sha" + ,"sha" #endif #ifndef NO_SHA256 - ,"sha256" + ,"sha256" #endif #ifdef WOLFSSL_SHA384 - ,"sha384" + ,"sha384" #endif #ifdef WOLFSSL_SHA512 - ,"sha512" + ,"sha512" #endif #ifdef HAVE_BLAKE2 - ,"blake2b" + ,"blake2b" #endif - }; +#ifndef NO_CODING + #ifdef WOLFSSL_BASE64_ENCODE + ,"base64enc" + #endif + ,"base64dec" +#endif + }; /* benchmark options */ const char* algsother[] = { /* list of acceptable algorithms */ #ifndef NO_AES - "aes-cbc" + "aes-cbc" #endif #ifdef WOLFSSL_AES_COUNTER - , "aes-ctr" + , "aes-ctr" #endif #ifndef NO_DES3 - , "3des" + , "3des" #endif #ifdef HAVE_CAMELLIA - , "camellia" + , "camellia" #endif #ifndef NO_MD5 - , "md5" + , "md5" #endif #ifndef NO_SHA - , "sha" + , "sha" #endif #ifndef NO_SHA256 - , "sha256" + , "sha256" #endif #ifdef WOLFSSL_SHA384 - , "sha384" + , "sha384" #endif #ifdef WOLFSSL_SHA512 - , "sha512" + , "sha512" #endif #ifdef HAVE_BLAKE2 - , "blake2b" + , "blake2b" #endif - }; - wolfsslHelp(); + }; - printf("Available En/De crypt Algorithms with current configure " - "settings.\n\n"); + wolfsslHelp(); + + printf("Available En/De crypt Algorithms with current configure " + "settings.\n\n"); #ifndef NO_AES - printf("aes-cbc-128\t\taes-cbc-192\t\taes-cbc-256\n"); + printf("aes-cbc-128\t\taes-cbc-192\t\taes-cbc-256\n"); #endif #ifdef WOLFSSL_AES_COUNTER - printf("aes-ctr-128\t\taes-ctr-192\t\taes-ctr-256\n"); + printf("aes-ctr-128\t\taes-ctr-192\t\taes-ctr-256\n"); #endif #ifndef NO_DES3 - printf("3des-cbc-56\t\t3des-cbc-112\t\t3des-cbc-168\n"); + printf("3des-cbc-56\t\t3des-cbc-112\t\t3des-cbc-168\n"); #endif #ifdef HAVE_CAMELLIA - printf("camellia-cbc-128\tcamellia-cbc-192\t" - "camellia-cbc-256\n"); + printf("camellia-cbc-128\tcamellia-cbc-192\t" + "camellia-cbc-256\n"); #endif printf("\n"); printf("Available hashing algorithms with current configure settings:\n\n"); @@ -162,17 +170,17 @@ void wolfsslEncryptHelp() printf("\nAvailable En/De crypt Algorithms with current configure " "settings.\n\n"); #ifndef NO_AES - printf("aes-cbc-128\t\taes-cbc-192\t\taes-cbc-256\n"); + printf("aes-cbc-128\t\taes-cbc-192\t\taes-cbc-256\n"); #endif #ifdef WOLFSSL_AES_COUNTER - printf("aes-ctr-128\t\taes-ctr-192\t\taes-ctr-256\n"); + printf("aes-ctr-128\t\taes-ctr-192\t\taes-ctr-256\n"); #endif #ifndef NO_DES3 - printf("3des-cbc-56\t\t3des-cbc-112\t\t3des-cbc-168\n"); + printf("3des-cbc-56\t\t3des-cbc-112\t\t3des-cbc-168\n"); #endif #ifdef HAVE_CAMELLIA - printf("camellia-cbc-128\tcamellia-cbc-192\t" - "camellia-cbc-256\n\n"); + printf("camellia-cbc-128\tcamellia-cbc-192\t" + "camellia-cbc-256\n\n"); #endif printf("***************************************************************\n"); printf("\nENCRYPT USAGE: wolfssl -encrypt <-algorithm> -in " @@ -190,17 +198,17 @@ void wolfsslDecryptHelp() printf("\nAvailable En/De crypt Algorithms with current configure " "settings.\n\n"); #ifndef NO_AES - printf("aes-cbc-128\t\taes-cbc-192\t\taes-cbc-256\n"); + printf("aes-cbc-128\t\taes-cbc-192\t\taes-cbc-256\n"); #endif #ifdef WOLFSSL_AES_COUNTER - printf("aes-ctr-128\t\taes-ctr-192\t\taes-ctr-256\n"); + printf("aes-ctr-128\t\taes-ctr-192\t\taes-ctr-256\n"); #endif #ifndef NO_DES3 - printf("3des-cbc-56\t\t3des-cbc-112\t\t3des-cbc-168\n"); + printf("3des-cbc-56\t\t3des-cbc-112\t\t3des-cbc-168\n"); #endif #ifdef HAVE_CAMELLIA - printf("camellia-cbc-128\tcamellia-cbc-192\t" - "camellia-cbc-256\n\n"); + printf("camellia-cbc-128\tcamellia-cbc-192\t" + "camellia-cbc-256\n\n"); #endif printf("***************************************************************\n"); printf("\nDECRYPT USAGE: wolfssl -decrypt -in " @@ -219,28 +227,34 @@ void wolfsslHashHelp() /* hash options */ const char* algsenc[] = { /* list of acceptable algorithms */ #ifndef NO_MD5 - "md5" + "md5" #endif #ifndef NO_SHA - ,"sha" + ,"sha" #endif #ifndef NO_SHA256 - ,"sha256" + ,"sha256" #endif #ifdef WOLFSSL_SHA384 - ,"sha384" + ,"sha384" #endif #ifdef WOLFSSL_SHA512 - ,"sha512" + ,"sha512" #endif #ifdef HAVE_BLAKE2 - ,"blake2b" + ,"blake2b" +#endif +#ifndef NO_CODING + #ifdef WOLFSSL_BASE64_ENCODE + ,"base64enc" + #endif + ,"base64dec" #endif }; printf("\nAvailable algorithms with current configure settings:\n"); for (i = 0; i < (int) sizeof(algsenc)/(int) sizeof(algsenc[0]); i++) { - printf("%s\n", algsenc[i]); + printf("%s\n", algsenc[i]); } /* encryption/decryption help lists options */ printf("***************************************************************\n"); @@ -255,39 +269,41 @@ void wolfsslHashHelp() void wolfsslBenchHelp() { printf("\n"); - /* benchmark options */ + + /* benchmark options */ const char* algsother[] = { /* list of acceptable algorithms */ #ifndef NO_AES - "aes-cbc" + "aes-cbc" #endif #ifdef WOLFSSL_AES_COUNTER - , "aes-ctr" + , "aes-ctr" #endif #ifndef NO_DES3 - , "3des" + , "3des" #endif #ifdef HAVE_CAMELLIA - , "camellia" + , "camellia" #endif #ifndef NO_MD5 - , "md5" + , "md5" #endif #ifndef NO_SHA - , "sha" + , "sha" #endif #ifndef NO_SHA256 - , "sha256" + , "sha256" #endif #ifdef WOLFSSL_SHA384 - , "sha384" + , "sha384" #endif #ifdef WOLFSSL_SHA512 - , "sha512" + , "sha512" #endif #ifdef HAVE_BLAKE2 - , "blake2b" + , "blake2b" #endif - }; + }; + printf("\nAvailable tests: (-a to test all)\n"); printf("Available tests with current configure settings:\n"); for(i = 0; i < (int) sizeof(algsother)/(int) sizeof(algsother[0]); i++) { @@ -312,17 +328,19 @@ int wolfsslGetAlgo(char* name, char** alg, char** mode, int* size) int nameCheck = 0; /* check for acceptable name */ int modeCheck = 0; /* check for acceptable mode */ char* sz = 0; /* key size provided */ + const char* acceptAlgs[] = { /* list of acceptable algorithms */ #ifndef NO_AES "aes" #endif #ifndef NO_DES3 - , "3des" + , "3des" #endif #ifdef HAVE_CAMELLIA - , "camellia" + , "camellia" #endif }; + const char* acceptMode[] = {"cbc" #ifdef WOLFSSL_AES_COUNTER , "ctr"