Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dgst add support for inform of key #141

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions src/sign-verify/clu_dgst_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <wolfclu/sign-verify/clu_verify.h>
#include <wolfclu/sign-verify/clu_sign_verify_setup.h>
#include <wolfclu/pkey/clu_pkey.h>
#include <wolfclu/x509/clu_cert.h> /* PER_FORM/DER_FORM */

#ifndef WOLFCLU_NO_FILESYSTEM

Expand All @@ -38,6 +39,7 @@ static const struct option dgst_options[] = {
{"-sha384", no_argument, 0, WOLFCLU_CERT_SHA384},
{"-sha512", no_argument, 0, WOLFCLU_CERT_SHA512},

{"-inform", required_argument, 0, WOLFCLU_INFORM },
{"-out", required_argument, 0, WOLFCLU_INFILE },
{"-signature", required_argument, 0, WOLFCLU_INFILE },
{"-verify", required_argument, 0, WOLFCLU_VERIFY },
Expand All @@ -61,6 +63,7 @@ static void wolfCLU_dgstHelp(void)
WOLFCLU_LOG(WOLFCLU_L0, "\t-sha512");
WOLFCLU_LOG(WOLFCLU_L0, "Parameters:");
WOLFCLU_LOG(WOLFCLU_L0, "\t-signature file containing the signature");
WOLFCLU_LOG(WOLFCLU_L0, "\t-inform pem or der in format");
WOLFCLU_LOG(WOLFCLU_L0, "\t-verify key used to verify the signature");
WOLFCLU_LOG(WOLFCLU_L0, "\t-sign private key used to create the signature");
WOLFCLU_LOG(WOLFCLU_L0, "\t-out output file for signature");
Expand Down Expand Up @@ -175,6 +178,7 @@ int wolfCLU_dgst_setup(int argc, char** argv)
int option;
int longIndex = 2;
byte signing = 0;
int inForm = PEM_FORM;

enum wc_HashType hashType = WC_HASH_TYPE_NONE;
enum wc_SignatureType sigType = WC_SIGNATURE_TYPE_NONE;
Expand Down Expand Up @@ -240,6 +244,14 @@ int wolfCLU_dgst_setup(int argc, char** argv)
sigFile = optarg;
break;

case WOLFCLU_INFORM:
inForm = wolfCLU_checkInform(optarg);
if (inForm < 0) {
wolfCLU_LogError("bad inform");
ret = USER_INPUT_ERROR;
}
break;

case WOLFCLU_HELP:
wolfCLU_dgstHelp();
return WOLFCLU_SUCCESS;
Expand Down Expand Up @@ -345,17 +357,28 @@ int wolfCLU_dgst_setup(int argc, char** argv)

/* get type of key and size of structure */
if (ret == WOLFCLU_SUCCESS && signing == 0) {
pkey = wolfSSL_PEM_read_bio_PUBKEY(pubKeyBio, NULL, NULL, NULL);
if (inForm == PEM_FORM) {
pkey = wolfSSL_PEM_read_bio_PUBKEY(pubKeyBio, NULL, NULL, NULL);
}
else {
pkey = wolfSSL_d2i_PUBKEY_bio(pubKeyBio, NULL);
}

if (pkey == NULL) {
wolfCLU_LogError("Unable to decode public key");
ret = WOLFCLU_FATAL_ERROR;
}
}

if (ret == WOLFCLU_SUCCESS && signing == 1) {
pkey = wolfSSL_PEM_read_bio_PrivateKey(pubKeyBio, NULL, NULL, NULL);
if (inForm == PEM_FORM) {
pkey = wolfSSL_PEM_read_bio_PrivateKey(pubKeyBio, NULL, NULL, NULL);
}
else {
pkey = wolfSSL_d2i_PrivateKey_bio(pubKeyBio, NULL);
}
if (pkey == NULL) {
wolfCLU_LogError("Unable to decode public key");
wolfCLU_LogError("Unable to decode private key");
ret = WOLFCLU_FATAL_ERROR;
}
}
Expand Down
Loading