" -purpose - print out certificate purposes\n",
" -dates - both Before and After dates\n",
" -modulus - print the RSA key modulus\n",
+" -pubkey - output the public key\n",
" -fingerprint - print the certificate fingerprint\n",
" -alias - output certificate alias\n",
" -noout - no certificate output\n",
static int x509_certify (X509_STORE *ctx,char *CAfile,const EVP_MD *digest,
X509 *x,X509 *xca,EVP_PKEY *pkey,char *serial,
int create,int days, LHASH *conf, char *section);
-static int efunc(X509_PURPOSE *pt, void *arg);
+static int purpose_print(BIO *bio, X509 *cert, X509_PURPOSE *pt);
static int reqfile=0;
-typedef struct {
-BIO *bio;
-X509 *cert;
-} X509_PPRINT;
-
int MAIN(int argc, char **argv)
{
int ret=1;
int noout=0,sign_flag=0,CA_flag=0,CA_createserial=0;
int trustout=0,clrtrust=0,clrnotrust=0,aliasout=0;
int C=0;
- int x509req=0,days=DEF_DAYS,modulus=0;
+ int x509req=0,days=DEF_DAYS,modulus=0,pubkey=0;
int pprint = 0;
char **pp;
X509_STORE *ctx=NULL;
serial= ++num;
else if (strcmp(*argv,"-modulus") == 0)
modulus= ++num;
+ else if (strcmp(*argv,"-pubkey") == 0)
+ pubkey= ++num;
else if (strcmp(*argv,"-x509toreq") == 0)
x509req= ++num;
else if (strcmp(*argv,"-text") == 0)
}
else if (pprint == i)
{
- X509_PPRINT ptmp;
- ptmp.bio = STDout;
- ptmp.cert = x;
+ X509_PURPOSE *ptmp;
+ int j;
BIO_printf(STDout, "Certificate purposes:\n");
- X509_PURPOSE_enum(efunc, &ptmp);
+ for(j = 0; j < X509_PURPOSE_get_count(); j++)
+ {
+ ptmp = X509_PURPOSE_iget(j);
+ purpose_print(STDout, x, ptmp);
+ }
}
else
if (modulus == i)
BIO_printf(STDout,"\n");
EVP_PKEY_free(pkey);
}
+ else
+ if (pubkey == i)
+ {
+ EVP_PKEY *pkey;
+
+ pkey=X509_get_pubkey(x);
+ if (pkey == NULL)
+ {
+ BIO_printf(bio_err,"Error getting public key\n");
+ ERR_print_errors(bio_err);
+ goto end;
+ }
+ PEM_write_bio_PUBKEY(STDout, pkey);
+ EVP_PKEY_free(pkey);
+ }
else
if (C == i)
{
return(0);
}
-static int efunc(X509_PURPOSE *pt, void *arg)
+static int purpose_print(BIO *bio, X509 *cert, X509_PURPOSE *pt)
{
- X509_PPRINT *ptmp;
int id, i, idret;
char *pname;
- ptmp = arg;
id = X509_PURPOSE_get_id(pt);
- pname = X509_PURPOSE_get_name(pt);
+ pname = X509_PURPOSE_iget_name(pt);
for(i = 0; i < 2; i++) {
- idret = X509_check_purpose(ptmp->cert, id, i);
- BIO_printf(ptmp->bio, "%s%s : ", pname, i ? " CA" : "");
- if(idret == 1) BIO_printf(ptmp->bio, "Yes\n");
- else if (idret == 0) BIO_printf(ptmp->bio, "No\n");
- else BIO_printf(ptmp->bio, "Yes (WARNING code=%d)\n", idret);
+ idret = X509_check_purpose(cert, id, i);
+ BIO_printf(bio, "%s%s : ", pname, i ? " CA" : "");
+ if(idret == 1) BIO_printf(bio, "Yes\n");
+ else if (idret == 0) BIO_printf(bio, "No\n");
+ else BIO_printf(bio, "Yes (WARNING code=%d)\n", idret);
}
return 1;
}