Skip to content

Commit

Permalink
Fix a bug recently introduced when updating this file to use the new
Browse files Browse the repository at this point in the history
keygen API: make sure that 'pkey_type' is actually visible to MAIN().
  • Loading branch information
45264 committed Jun 14, 2006
1 parent 1a159e0 commit 6a983d4
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions apps/req.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static int add_DN_object(X509_NAME *n, char *text, const char *def, char *value,
static int genpkey_cb(EVP_PKEY_CTX *ctx);
static int req_check_len(int len,int n_min,int n_max);
static int check_end(const char *str, const char *end);
static EVP_PKEY_CTX *set_keygen_ctx(BIO *err, const char *gstr,
static EVP_PKEY_CTX *set_keygen_ctx(BIO *err, const char *gstr, int *pkey_type,
long *pkeylen, char **palgnam,
ENGINE *keygen_engine);
#ifndef MONOLITH
Expand All @@ -167,7 +167,7 @@ int MAIN(int argc, char **argv)
char *keyalgstr = NULL;
STACK *pkeyopts = NULL;
EVP_PKEY *pkey=NULL;
int i=0,badops=0,newreq=0,verbose=0,pkey_type=EVP_PKEY_RSA;
int i=0,badops=0,newreq=0,verbose=0,pkey_type=-1;
long newkey = -1;
BIO *in=NULL,*out=NULL;
int informat,outformat,verify=0,noout=0,text=0,keyform=FORMAT_PEM;
Expand Down Expand Up @@ -638,7 +638,7 @@ int MAIN(int argc, char **argv)

if (keyalg)
{
genctx = set_keygen_ctx(bio_err, keyalg, &newkey,
genctx = set_keygen_ctx(bio_err, keyalg, &pkey_type, &newkey,
&keyalgstr, gen_eng);
if (!genctx)
goto end;
Expand All @@ -659,7 +659,7 @@ int MAIN(int argc, char **argv)

if (!genctx)
{
genctx = set_keygen_ctx(bio_err, NULL, &newkey,
genctx = set_keygen_ctx(bio_err, NULL, &pkey_type, &newkey,
&keyalgstr, gen_eng);
if (!genctx)
goto end;
Expand Down Expand Up @@ -1570,25 +1570,24 @@ static int check_end(const char *str, const char *end)
return strcmp(tmp, end);
}

static EVP_PKEY_CTX *set_keygen_ctx(BIO *err, const char *gstr,
static EVP_PKEY_CTX *set_keygen_ctx(BIO *err, const char *gstr, int *pkey_type,
long *pkeylen, char **palgnam,
ENGINE *keygen_engine)
{
EVP_PKEY_CTX *gctx = NULL;
EVP_PKEY *param = NULL;
long keylen = -1;
int pkey_type = -1;
BIO *pbio = NULL;
const char *paramfile = NULL;

if (gstr == NULL)
{
pkey_type = EVP_PKEY_RSA;
*pkey_type = EVP_PKEY_RSA;
keylen = *pkeylen;
}
else if (gstr[0] >= '0' && gstr[0] <= '9')
{
pkey_type = EVP_PKEY_RSA;
*pkey_type = EVP_PKEY_RSA;
keylen = atol(gstr);
*pkeylen = keylen;
}
Expand Down Expand Up @@ -1617,13 +1616,13 @@ static EVP_PKEY_CTX *set_keygen_ctx(BIO *err, const char *gstr,
return NULL;
}

EVP_PKEY_asn1_get0_info(NULL, &pkey_type, NULL, NULL, NULL,
EVP_PKEY_asn1_get0_info(NULL, pkey_type, NULL, NULL, NULL,
ameth);
#ifndef OPENSSL_NO_ENGINE
if (tmpeng)
ENGINE_finish(tmpeng);
#endif
if (pkey_type == EVP_PKEY_RSA)
if (*pkey_type == EVP_PKEY_RSA)
{
if (p)
{
Expand Down Expand Up @@ -1666,9 +1665,9 @@ static EVP_PKEY_CTX *set_keygen_ctx(BIO *err, const char *gstr,
paramfile);
return NULL;
}
if (pkey_type == -1)
pkey_type = EVP_PKEY_id(param);
else if (pkey_type != EVP_PKEY_base_id(param))
if (*pkey_type == -1)
*pkey_type = EVP_PKEY_id(param);
else if (*pkey_type != EVP_PKEY_base_id(param))
{
BIO_printf(err, "Key Type does not match parameters\n");
EVP_PKEY_free(param);
Expand All @@ -1681,7 +1680,7 @@ static EVP_PKEY_CTX *set_keygen_ctx(BIO *err, const char *gstr,
const EVP_PKEY_ASN1_METHOD *ameth;
ENGINE *tmpeng;
const char *anam;
ameth = EVP_PKEY_asn1_find(&tmpeng, pkey_type);
ameth = EVP_PKEY_asn1_find(&tmpeng, *pkey_type);
if (!ameth)
{
BIO_puts(err, "Internal error: can't find key algorithm\n");
Expand All @@ -1702,7 +1701,7 @@ static EVP_PKEY_CTX *set_keygen_ctx(BIO *err, const char *gstr,
EVP_PKEY_free(param);
}
else
gctx = EVP_PKEY_CTX_new_id(pkey_type, keygen_engine);
gctx = EVP_PKEY_CTX_new_id(*pkey_type, keygen_engine);

if (!gctx)
{
Expand All @@ -1718,7 +1717,7 @@ static EVP_PKEY_CTX *set_keygen_ctx(BIO *err, const char *gstr,
return NULL;
}

if ((pkey_type == EVP_PKEY_RSA) && (keylen != -1))
if ((*pkey_type == EVP_PKEY_RSA) && (keylen != -1))
{
if (EVP_PKEY_CTX_set_rsa_keygen_bits(gctx, keylen) <= 0)
{
Expand Down

0 comments on commit 6a983d4

Please sign in to comment.