@@ -400,7 +400,7 @@ int x509_main(int argc, char **argv)
400
400
aliasout = ++ num ;
401
401
break ;
402
402
case OPT_CACREATESERIAL :
403
- CA_createserial = ++ num ;
403
+ CA_createserial = 1 ;
404
404
break ;
405
405
case OPT_CLREXT :
406
406
clrext = 1 ;
@@ -590,7 +590,7 @@ int x509_main(int argc, char **argv)
590
590
xca = load_cert (CAfile , CAformat , "CA Certificate" );
591
591
if (xca == NULL )
592
592
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 )))
594
594
goto end ;
595
595
}
596
596
@@ -916,6 +916,7 @@ static ASN1_INTEGER *x509_load_serial(const char *CAfile,
916
916
char * buf = NULL ;
917
917
ASN1_INTEGER * bs = NULL ;
918
918
BIGNUM * serial = NULL ;
919
+ int defaultfile = 0 , file_exists ;
919
920
920
921
if (serialfile == NULL ) {
921
922
const char * p = strrchr (CAfile , '.' );
@@ -925,9 +926,10 @@ static ASN1_INTEGER *x509_load_serial(const char *CAfile,
925
926
memcpy (buf , CAfile , len );
926
927
memcpy (buf + len , POSTFIX , sizeof (POSTFIX ));
927
928
serialfile = buf ;
929
+ defaultfile = 1 ;
928
930
}
929
931
930
- serial = load_serial (serialfile , create , NULL );
932
+ serial = load_serial (serialfile , & file_exists , create || defaultfile , NULL );
931
933
if (serial == NULL )
932
934
goto end ;
933
935
@@ -936,8 +938,10 @@ static ASN1_INTEGER *x509_load_serial(const char *CAfile,
936
938
goto end ;
937
939
}
938
940
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 );
941
945
942
946
end :
943
947
OPENSSL_free (buf );
@@ -989,6 +993,8 @@ static int x509_certify(X509_STORE *ctx, const char *CAfile, const EVP_MD *diges
989
993
goto end ;
990
994
}
991
995
996
+ if (!X509_set_issuer_name (x , X509_get_subject_name (xca )))
997
+ goto end ;
992
998
if (!X509_set_serialNumber (x , bs ))
993
999
goto end ;
994
1000
0 commit comments