@@ -400,7 +400,7 @@ int x509_main(int argc, char **argv)
400400 aliasout = ++ num ;
401401 break ;
402402 case OPT_CACREATESERIAL :
403- CA_createserial = ++ num ;
403+ CA_createserial = 1 ;
404404 break ;
405405 case OPT_CLREXT :
406406 clrext = 1 ;
@@ -590,7 +590,7 @@ int x509_main(int argc, char **argv)
590590 xca = load_cert (CAfile , CAformat , "CA Certificate" );
591591 if (xca == NULL )
592592 goto end ;
593- if (!X509_set_issuer_name (x , X509_get_subject_name (xca )))
593+ if (reqfile && !X509_set_issuer_name (x , X509_get_subject_name (xca )))
594594 goto end ;
595595 }
596596
@@ -916,6 +916,7 @@ static ASN1_INTEGER *x509_load_serial(const char *CAfile,
916916 char * buf = NULL ;
917917 ASN1_INTEGER * bs = NULL ;
918918 BIGNUM * serial = NULL ;
919+ int defaultfile = 0 , file_exists ;
919920
920921 if (serialfile == NULL ) {
921922 const char * p = strrchr (CAfile , '.' );
@@ -925,9 +926,10 @@ static ASN1_INTEGER *x509_load_serial(const char *CAfile,
925926 memcpy (buf , CAfile , len );
926927 memcpy (buf + len , POSTFIX , sizeof (POSTFIX ));
927928 serialfile = buf ;
929+ defaultfile = 1 ;
928930 }
929931
930- serial = load_serial (serialfile , create , NULL );
932+ serial = load_serial (serialfile , & file_exists , create || defaultfile , NULL );
931933 if (serial == NULL )
932934 goto end ;
933935
@@ -936,8 +938,10 @@ static ASN1_INTEGER *x509_load_serial(const char *CAfile,
936938 goto end ;
937939 }
938940
939- if (!save_serial (serialfile , NULL , serial , & bs ))
940- goto end ;
941+ if (file_exists || create )
942+ save_serial (serialfile , NULL , serial , & bs );
943+ else
944+ bs = BN_to_ASN1_INTEGER (serial , NULL );
941945
942946 end :
943947 OPENSSL_free (buf );
@@ -989,6 +993,8 @@ static int x509_certify(X509_STORE *ctx, const char *CAfile, const EVP_MD *diges
989993 goto end ;
990994 }
991995
996+ if (!X509_set_issuer_name (x , X509_get_subject_name (xca )))
997+ goto end ;
992998 if (!X509_set_serialNumber (x , bs ))
993999 goto end ;
9941000
0 commit comments