Merge branch 'wolfCLU_project' of https://github.com/connerwolfssl/wolfssl-examples into wolfCLU_project

pull/95/head
connerwolfssl 2018-05-09 09:42:43 -06:00
commit 0fd1aff4b3
10 changed files with 31 additions and 27 deletions

View File

@ -6,7 +6,8 @@ This is the wolfSSL: Command Line Utility (wolfCLU).
To use this feature, please configure and install wolfssl with the following commands: To use this feature, please configure and install wolfssl with the following commands:
./configure --enable-pwdbased --enable-opensslextra --enable-keygen && make && make check ./configure --enable-pwdbased --enable-opensslextra --enable-keygen --enable-ed25519
&& make && make check
If that succeeds, run: If that succeeds, run:
@ -36,7 +37,6 @@ encryption or decryption are:
Additional features that can be included when configuring wolfssl for Additional features that can be included when configuring wolfssl for
key generation are: key generation are:
--enable-ed25519
##wolfCLU Install ##wolfCLU Install

View File

@ -49,7 +49,7 @@ enum {
VERBOSE, VERBOSE,
INKEY, INKEY,
PUBIN, PUBIN,
SIGNATURE, SIGFILE,
INFORM, INFORM,
OUTFORM, OUTFORM,
NOOUT, NOOUT,
@ -91,7 +91,7 @@ static struct option long_options[] = {
{"pubin", no_argument, 0, PUBIN }, {"pubin", no_argument, 0, PUBIN },
{"inform", required_argument, 0, INFORM }, {"inform", required_argument, 0, INFORM },
{"outform", required_argument, 0, OUTFORM }, {"outform", required_argument, 0, OUTFORM },
{"signature", required_argument, 0, SIGNATURE }, {"sigfile", required_argument, 0, SIGFILE },
{"noout", no_argument, 0, NOOUT }, {"noout", no_argument, 0, NOOUT },
{"text", no_argument, 0, TEXT_OUT }, {"text", no_argument, 0, TEXT_OUT },
{"silent", no_argument, 0, SILENT }, {"silent", no_argument, 0, SILENT },

View File

@ -95,7 +95,7 @@ int main(int argc, char** argv)
case INFILE: /* File passed in by user */ case INFILE: /* File passed in by user */
case OUTFILE: /* Output file */ case OUTFILE: /* Output file */
case INKEY: case INKEY:
case SIGNATURE: case SIGFILE:
/* do nothing. */ /* do nothing. */

View File

@ -32,7 +32,7 @@
#ifdef HAVE_ED25519 #ifdef HAVE_ED25519
int wolfCLU_genKey_ED25519(WC_RNG* rng, char* fOutNm, int directive, int format) int wolfCLU_genKey_ED25519(WC_RNG* rng, char* fOutNm, int directive, int format)
{ {
int ret = -1; /* return value */ int ret; /* return value */
int fOutNmSz = XSTRLEN(fOutNm); /* file name without append */ int fOutNmSz = XSTRLEN(fOutNm); /* file name without append */
int fOutNmAppendSz = 6; /* # of bytes to append to file name */ int fOutNmAppendSz = 6; /* # of bytes to append to file name */
int flag_outputPub = 0; /* set if outputting both priv/pub */ int flag_outputPub = 0; /* set if outputting both priv/pub */

View File

@ -173,7 +173,7 @@ int wolfCLU_genKeySetup(int argc, char** argv)
return NOT_COMPILED_IN; return NOT_COMPILED_IN;
#endif /* HAVE_ECC */ #endif /* HAVE_ECC */
} else if (XSTRNCMP(keyType, "rsa", 3) == 0) { } else if (XSTRNCMP(keyType, "rsa", 3) == 0) {
#if defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
/* RSA flags */ /* RSA flags */
int directiveArg; int directiveArg;
int sizeArg; int sizeArg;

View File

@ -25,7 +25,7 @@
#include "clu_include/clu_header_main.h" #include "clu_include/clu_header_main.h"
int wolfCLU_sign_data(char* in, char* out, char* privKey, int keyType) { int wolfCLU_sign_data(char* in, char* out, char* privKey, int keyType) {
int ret = -1; int ret;
int fSz; int fSz;
FILE* f = fopen(in,"rb"); FILE* f = fopen(in,"rb");
@ -52,6 +52,9 @@ int wolfCLU_sign_data(char* in, char* out, char* privKey, int keyType) {
ret = wolfCLU_sign_data_ed25519(data, out, fSz, privKey); ret = wolfCLU_sign_data_ed25519(data, out, fSz, privKey);
break; break;
default:
printf("No valid sign algorithm selected.\n");
ret = -1;
} }
return ret; return ret;

View File

@ -123,7 +123,7 @@ int wolfCLU_sign_verify_setup(int argc, char** argv)
inCheck = 1; inCheck = 1;
} }
ret = wolfCLU_checkForArg("-signature", 10, argc, argv); ret = wolfCLU_checkForArg("-sigfile", 8, argc, argv);
if (ret > 0) { if (ret > 0) {
sig = XMALLOC(strlen(argv[ret+1]), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); sig = XMALLOC(strlen(argv[ret+1]), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (sig == NULL) { if (sig == NULL) {
@ -138,7 +138,7 @@ int wolfCLU_sign_verify_setup(int argc, char** argv)
sigCheck = 1; sigCheck = 1;
} }
else if (verifyCheck == 1) { else if (verifyCheck == 1) {
printf("Please specify -signature <sig> when verifying.\n"); printf("Please specify -sigfile <sig> when verifying.\n");
wolfCLU_verifyHelp(algCheck); wolfCLU_verifyHelp(algCheck);
return ret; return ret;
} }

View File

@ -137,7 +137,7 @@ int wolfCLU_verify_signature(char* sig, char* hash,
int hSz; int hSz;
int fSz; int fSz;
int ret = -1; int ret;
FILE* h; FILE* h;
FILE* f = fopen(sig,"rb"); FILE* f = fopen(sig,"rb");
@ -158,7 +158,6 @@ int wolfCLU_verify_signature(char* sig, char* hash,
break; break;
case ECC_SIG_VER: case ECC_SIG_VER:
hSz;
h = fopen(hash,"rb"); h = fopen(hash,"rb");
fseek(h, 0, SEEK_END); fseek(h, 0, SEEK_END);
@ -173,8 +172,6 @@ int wolfCLU_verify_signature(char* sig, char* hash,
break; break;
case ED25519_SIG_VER: case ED25519_SIG_VER:
#ifdef HAVE_ED25519
hSz;
h = fopen(hash,"rb"); h = fopen(hash,"rb");
fseek(h, 0, SEEK_END); fseek(h, 0, SEEK_END);
@ -185,9 +182,12 @@ int wolfCLU_verify_signature(char* sig, char* hash,
fseek(h, 0, SEEK_SET); fseek(h, 0, SEEK_SET);
fread(h_mssg, 1, hSz, h); fread(h_mssg, 1, hSz, h);
fclose(h); fclose(h);
ret = wolfCLU_verify_signature_ed25519(data, ED25519_SIG_SIZE, h_mssg, hSz, keyPath, pubIn); ret = wolfCLU_verify_signature_ed25519(data, fSz, h_mssg, hSz, keyPath, pubIn);
#endif
break; break;
default:
printf("No valid verify algorithm selected.\n");
ret = -1;
} }
return ret; return ret;
} }

View File

@ -374,10 +374,10 @@ void wolfCLU_genKeyHelp() {
} }
printf("\n\n"); printf("\n\n");
printf("***************************************************************\n"); printf("***************************************************************\n");
printf("\ngenkey USAGE:\nwolfssl -genkey <keytype> -out <filename> -outform" printf("\ngenkey USAGE:\nwolfssl -genkey <keytype> -size(optional) <bits> "
" <PEM or DER> -output <PUB/PRIV/KEYPAIR> \n\n"); "-out <filename> -outform <PEM or DER> -output <PUB/PRIV/KEYPAIR> \n\n");
printf("***************************************************************\n"); printf("***************************************************************\n");
printf("\nEXAMPLE: \n\nwolfssl -genkey ed25519 -out mykey -outform der " printf("\nEXAMPLE: \n\nwolfssl -genkey rsa -size 2048 -out mykey -outform der "
" -output KEYPAIR" " -output KEYPAIR"
"\n\nThe above command would output the files: mykey.priv " "\n\nThe above command would output the files: mykey.priv "
" and mykey.pub\nChanging the -output option to just PRIV would only" " and mykey.pub\nChanging the -output option to just PRIV would only"
@ -457,11 +457,11 @@ void wolfCLU_verifyHelp(int keyType) {
case RSA_SIG_VER: case RSA_SIG_VER:
printf("RSA Verify with Private Key:\n" printf("RSA Verify with Private Key:\n"
"wolfssl -rsa -verify -inkey <priv_key>" "wolfssl -rsa -verify -inkey <priv_key>"
" -signature <filename> -out <filename>\n\n"); " -sigfile <filename> -out <filename>\n\n");
printf("***************************************************************\n"); printf("***************************************************************\n");
printf("RSA Verify with Public Key\n" printf("RSA Verify with Public Key\n"
"wolfssl -rsa -verify -inkey <pub_key>" "wolfssl -rsa -verify -inkey <pub_key>"
" -signature <filename> -out <filename> -pubin\n\n"); " -sigfile <filename> -out <filename> -pubin\n\n");
printf("***************************************************************\n"); printf("***************************************************************\n");
break; break;
#endif #endif
@ -469,12 +469,12 @@ void wolfCLU_verifyHelp(int keyType) {
case ED25519_SIG_VER: case ED25519_SIG_VER:
printf("ED25519 Verifiy with Private Key\n" printf("ED25519 Verifiy with Private Key\n"
"wolfssl -ed25519 -verify -inkey " "wolfssl -ed25519 -verify -inkey "
"<priv_key> -signature <filename> -in <original>" "<priv_key> -sigfile <filename> -in <original>"
"\n\n"); "\n\n");
printf("***************************************************************\n"); printf("***************************************************************\n");
printf("ED25519 Verifiy with Public Key\n" printf("ED25519 Verifiy with Public Key\n"
"wolfssl -ed25519 -verify -inkey " "wolfssl -ed25519 -verify -inkey "
"<pub_key> -signature <filename> -in <original> -pubin" "<pub_key> -sigfile <filename> -in <original> -pubin"
"\n\n"); "\n\n");
printf("***************************************************************\n"); printf("***************************************************************\n");
break; break;
@ -483,7 +483,7 @@ void wolfCLU_verifyHelp(int keyType) {
case ECC_SIG_VER: case ECC_SIG_VER:
printf("ECC Verify with Public Key\n" printf("ECC Verify with Public Key\n"
"wolfssl -ecc -verify -inkey <pub_key>" "wolfssl -ecc -verify -inkey <pub_key>"
" -signature <signature> -in <original>\n\n"); " -sigfile <signature> -in <original>\n\n");
break; break;
#endif #endif
default: default:
@ -555,7 +555,7 @@ int wolfCLU_getAlgo(char* name, char** alg, char** mode, int* size)
*size = atoi(sz); *size = atoi(sz);
/* checks key sizes for acceptability */ /* checks key sizes for acceptability */
if (strcmp(*alg, "aes") == 0) { if (XSTRNCMP(*alg, "aes", 3) == 0) {
#ifdef NO_AES #ifdef NO_AES
printf("AES not compiled in.\n"); printf("AES not compiled in.\n");
return NOT_COMPILED_IN; return NOT_COMPILED_IN;
@ -568,7 +568,7 @@ int wolfCLU_getAlgo(char* name, char** alg, char** mode, int* size)
#endif #endif
} }
else if (strcmp(*alg, "3des") == 0) { else if (XSTRNCMP(*alg, "3des", 4) == 0) {
#ifdef NO_DES3 #ifdef NO_DES3
printf("3DES not compiled in.\n"); printf("3DES not compiled in.\n");
return NOT_COMPILED_IN; return NOT_COMPILED_IN;
@ -581,7 +581,7 @@ int wolfCLU_getAlgo(char* name, char** alg, char** mode, int* size)
#endif #endif
} }
else if (strcmp(*alg, "camellia") == 0) { else if (XSTRNCMP(*alg, "camellia", 8) == 0) {
#ifndef HAVE_CAMELIA #ifndef HAVE_CAMELIA
printf("CAMELIA not compiled in.\n"); printf("CAMELIA not compiled in.\n");
return NOT_COMPILED_IN; return NOT_COMPILED_IN;

View File

@ -65,6 +65,7 @@ int wolfCLU_inderOutder(char* infile, char* outfile, int silent_flag)
int wolfCLU_inpemOuttext(char* infile, char* outfile, int silent_flag) { int wolfCLU_inpemOuttext(char* infile, char* outfile, int silent_flag) {
int ret; int ret;
ret = wolfCLU_parseFile(infile, PEM, outfile, TEXT, silent_flag); ret = wolfCLU_parseFile(infile, PEM, outfile, TEXT, silent_flag);
return ret;
} }
int wolfCLU_parseFile(char* infile, int inform, char* outfile, int outform, int wolfCLU_parseFile(char* infile, int inform, char* outfile, int outform,