Merge pull request #29 from dgarske/clu_base64

wolfCLU base64 support
pull/31/head
Kaleb Himes 2016-11-17 13:39:08 -07:00 committed by GitHub
commit cde614c4aa
5 changed files with 150 additions and 72 deletions

View File

@ -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.

View File

@ -65,6 +65,8 @@
#include <wolfssl/wolfcrypt/camellia.h>
#endif
#include <wolfssl/wolfcrypt/coding.h>
#ifndef UTIL_H_INCLUDED
#define UTIL_H_INCLUDED

View File

@ -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");
}

View File

@ -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);

View File

@ -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 <filename> "
@ -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 <algorithm> -in <encrypted file> "
@ -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"