1
- /* $OpenBSD: ts.c,v 1.20 2022/03/24 12:00:17 inoguchi Exp $ */
1
+ /* $OpenBSD: ts.c,v 1.21 2022/03/24 13:47:55 inoguchi Exp $ */
2
2
/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
3
3
* project 2002.
4
4
*/
@@ -391,7 +391,7 @@ ts_main(int argc, char **argv)
391
391
goto usage ;
392
392
393
393
/* Get the password if required. */
394
- if (ts_config .mode == CMD_REPLY && ts_config .passin &&
394
+ if (ts_config .mode == CMD_REPLY && ts_config .passin != NULL &&
395
395
!app_passwd (bio_err , ts_config .passin , NULL , & password , NULL )) {
396
396
BIO_printf (bio_err , "Error getting password.\n" );
397
397
goto cleanup ;
@@ -439,12 +439,12 @@ ts_main(int argc, char **argv)
439
439
ts_config .token_out , ts_config .text );
440
440
break ;
441
441
case CMD_VERIFY :
442
- ret = !(((ts_config .queryfile && ! ts_config .data &&
443
- ! ts_config .digest ) ||
444
- (! ts_config .queryfile && ts_config .data &&
445
- ! ts_config .digest ) ||
446
- (! ts_config .queryfile && ! ts_config .data &&
447
- ts_config .digest )) &&
442
+ ret = !(((ts_config .queryfile != NULL && ts_config .data == NULL &&
443
+ ts_config .digest == NULL ) ||
444
+ (ts_config .queryfile == NULL && ts_config .data != NULL &&
445
+ ts_config .digest == NULL ) ||
446
+ (ts_config .queryfile == NULL && ts_config .data == NULL &&
447
+ ts_config .digest != NULL )) &&
448
448
ts_config .in != NULL );
449
449
if (ret )
450
450
goto usage ;
@@ -477,7 +477,7 @@ txt2obj(const char *oid)
477
477
{
478
478
ASN1_OBJECT * oid_obj = NULL ;
479
479
480
- if (! (oid_obj = OBJ_txt2obj (oid , 0 )))
480
+ if ((oid_obj = OBJ_txt2obj (oid , 0 )) == NULL )
481
481
BIO_printf (bio_err , "cannot convert %s to OID\n" , oid );
482
482
483
483
return oid_obj ;
@@ -489,11 +489,11 @@ load_config_file(const char *configfile)
489
489
CONF * conf = NULL ;
490
490
long errorline = -1 ;
491
491
492
- if (! configfile )
492
+ if (configfile == NULL )
493
493
configfile = getenv ("OPENSSL_CONF" );
494
494
495
- if (configfile &&
496
- (! (conf = NCONF_new (NULL )) ||
495
+ if (configfile != NULL &&
496
+ ((conf = NCONF_new (NULL )) == NULL ||
497
497
NCONF_load (conf , configfile , & errorline ) <= 0 )) {
498
498
if (errorline <= 0 )
499
499
BIO_printf (bio_err , "error loading the config file "
@@ -510,7 +510,7 @@ load_config_file(const char *configfile)
510
510
p = NCONF_get_string (conf , NULL , ENV_OID_FILE );
511
511
if (p != NULL ) {
512
512
BIO * oid_bio = BIO_new_file (p , "r" );
513
- if (! oid_bio )
513
+ if (oid_bio == NULL )
514
514
ERR_print_errors (bio_err );
515
515
else {
516
516
OBJ_create_objects (oid_bio );
@@ -546,8 +546,8 @@ query_command(const char *data, char *digest, const EVP_MD *md,
546
546
query = d2i_TS_REQ_bio (in_bio , NULL );
547
547
} else {
548
548
/* Open the file if no explicit digest bytes were specified. */
549
- if (! digest &&
550
- ! (data_bio = BIO_open_with_default (data , "rb" , stdin )))
549
+ if (digest == NULL &&
550
+ (data_bio = BIO_open_with_default (data , "rb" , stdin )) == NULL )
551
551
goto end ;
552
552
/* Creating the query object. */
553
553
query = create_query (data_bio , digest , md ,
@@ -605,27 +605,27 @@ create_query(BIO *data_bio, char *digest, const EVP_MD *md, const char *policy,
605
605
ASN1_INTEGER * nonce_asn1 = NULL ;
606
606
607
607
/* Setting default message digest. */
608
- if (! md && ! (md = EVP_get_digestbyname ("sha1" )))
608
+ if (md == NULL && (md = EVP_get_digestbyname ("sha1" )) == NULL )
609
609
goto err ;
610
610
611
611
/* Creating request object. */
612
- if (! (ts_req = TS_REQ_new ()))
612
+ if ((ts_req = TS_REQ_new ()) == NULL )
613
613
goto err ;
614
614
615
615
/* Setting version. */
616
616
if (!TS_REQ_set_version (ts_req , 1 ))
617
617
goto err ;
618
618
619
619
/* Creating and adding MSG_IMPRINT object. */
620
- if (! (msg_imprint = TS_MSG_IMPRINT_new ()))
620
+ if ((msg_imprint = TS_MSG_IMPRINT_new ()) == NULL )
621
621
goto err ;
622
622
623
623
/* Adding algorithm. */
624
- if (! (algo = X509_ALGOR_new ()))
624
+ if ((algo = X509_ALGOR_new ()) == NULL )
625
625
goto err ;
626
- if (! (algo -> algorithm = OBJ_nid2obj (EVP_MD_type (md ))))
626
+ if ((algo -> algorithm = OBJ_nid2obj (EVP_MD_type (md ))) == NULL )
627
627
goto err ;
628
- if (! (algo -> parameter = ASN1_TYPE_new ()))
628
+ if ((algo -> parameter = ASN1_TYPE_new ()) == NULL )
629
629
goto err ;
630
630
algo -> parameter -> type = V_ASN1_NULL ;
631
631
if (!TS_MSG_IMPRINT_set_algo (msg_imprint , algo ))
@@ -641,15 +641,15 @@ create_query(BIO *data_bio, char *digest, const EVP_MD *md, const char *policy,
641
641
goto err ;
642
642
643
643
/* Setting policy if requested. */
644
- if (policy && ! (policy_obj = txt2obj (policy )))
644
+ if (policy != NULL && (policy_obj = txt2obj (policy )) == NULL )
645
645
goto err ;
646
- if (policy_obj && !TS_REQ_set_policy_id (ts_req , policy_obj ))
646
+ if (policy_obj != NULL && !TS_REQ_set_policy_id (ts_req , policy_obj ))
647
647
goto err ;
648
648
649
649
/* Setting nonce if requested. */
650
- if (!no_nonce && ! (nonce_asn1 = create_nonce (NONCE_LENGTH )))
650
+ if (!no_nonce && (nonce_asn1 = create_nonce (NONCE_LENGTH )) == NULL )
651
651
goto err ;
652
- if (nonce_asn1 && !TS_REQ_set_nonce (ts_req , nonce_asn1 ))
652
+ if (nonce_asn1 != NULL && !TS_REQ_set_nonce (ts_req , nonce_asn1 ))
653
653
goto err ;
654
654
655
655
/* Setting certificate request flag if requested. */
@@ -682,7 +682,7 @@ create_digest(BIO *input, char *digest, const EVP_MD *md,
682
682
md_value_len = EVP_MD_size (md );
683
683
if (md_value_len < 0 )
684
684
goto err ;
685
- if (input ) {
685
+ if (input != NULL ) {
686
686
/* Digest must be computed from an input file. */
687
687
EVP_MD_CTX * md_ctx ;
688
688
unsigned char buffer [4096 ];
@@ -706,7 +706,7 @@ create_digest(BIO *input, char *digest, const EVP_MD *md,
706
706
/* Digest bytes are specified with digest. */
707
707
long digest_len ;
708
708
* md_value = string_to_hex (digest , & digest_len );
709
- if (! * md_value || md_value_len != digest_len ) {
709
+ if (* md_value == NULL || md_value_len != digest_len ) {
710
710
free (* md_value );
711
711
* md_value = NULL ;
712
712
BIO_printf (bio_err , "bad digest, %d bytes "
@@ -736,12 +736,12 @@ create_nonce(int bits)
736
736
/* Find the first non-zero byte and creating ASN1_INTEGER object. */
737
737
for (i = 0 ; i < len && !buf [i ]; ++ i )
738
738
;
739
- if (! (nonce = ASN1_INTEGER_new ()))
739
+ if ((nonce = ASN1_INTEGER_new ()) == NULL )
740
740
goto err ;
741
741
free (nonce -> data );
742
742
/* Allocate at least one byte. */
743
743
nonce -> length = len - i ;
744
- if (! (nonce -> data = malloc (nonce -> length + 1 )))
744
+ if ((nonce -> data = malloc (nonce -> length + 1 )) == NULL )
745
745
goto err ;
746
746
memcpy (nonce -> data , buf + i , nonce -> length );
747
747
@@ -785,10 +785,9 @@ reply_command(CONF *conf, char *section, char *queryfile, char *passin,
785
785
response = d2i_TS_RESP_bio (in_bio , NULL );
786
786
}
787
787
} else {
788
- response = create_response (conf , section , queryfile ,
789
- passin , inkey , signer , chain ,
790
- policy );
791
- if (response )
788
+ response = create_response (conf , section , queryfile , passin ,
789
+ inkey , signer , chain , policy );
790
+ if (response != NULL )
792
791
BIO_printf (bio_err , "Response has been generated.\n" );
793
792
else
794
793
BIO_printf (bio_err , "Response is not generated.\n" );
@@ -848,17 +847,17 @@ read_PKCS7(BIO *in_bio)
848
847
TS_STATUS_INFO * si = NULL ;
849
848
850
849
/* Read PKCS7 object and extract the signed time stamp info. */
851
- if (! (token = d2i_PKCS7_bio (in_bio , NULL )))
850
+ if ((token = d2i_PKCS7_bio (in_bio , NULL )) == NULL )
852
851
goto end ;
853
- if (! (tst_info = PKCS7_to_TS_TST_INFO (token )))
852
+ if ((tst_info = PKCS7_to_TS_TST_INFO (token )) == NULL )
854
853
goto end ;
855
854
856
855
/* Creating response object. */
857
- if (! (resp = TS_RESP_new ()))
856
+ if ((resp = TS_RESP_new ()) == NULL )
858
857
goto end ;
859
858
860
859
/* Create granted status info. */
861
- if (! (si = TS_STATUS_INFO_new ()))
860
+ if ((si = TS_STATUS_INFO_new ()) == NULL )
862
861
goto end ;
863
862
if (!(ASN1_INTEGER_set (si -> status , TS_STATUS_GRANTED )))
864
863
goto end ;
@@ -891,15 +890,15 @@ create_response(CONF *conf, const char *section, char *queryfile, char *passin,
891
890
BIO * query_bio = NULL ;
892
891
TS_RESP_CTX * resp_ctx = NULL ;
893
892
894
- if (! (query_bio = BIO_new_file (queryfile , "rb" )))
893
+ if ((query_bio = BIO_new_file (queryfile , "rb" )) == NULL )
895
894
goto end ;
896
895
897
896
/* Getting TSA configuration section. */
898
- if (! (section = TS_CONF_get_tsa_section (conf , section )))
897
+ if ((section = TS_CONF_get_tsa_section (conf , section )) == NULL )
899
898
goto end ;
900
899
901
900
/* Setting up response generation context. */
902
- if (! (resp_ctx = TS_RESP_CTX_new ()))
901
+ if ((resp_ctx = TS_RESP_CTX_new ()) == NULL )
903
902
goto end ;
904
903
905
904
/* Setting serial number provider callback. */
@@ -951,7 +950,7 @@ create_response(CONF *conf, const char *section, char *queryfile, char *passin,
951
950
goto end ;
952
951
953
952
/* Creating the response. */
954
- if (! (response = TS_RESP_create_response (resp_ctx , query_bio )))
953
+ if ((response = TS_RESP_create_response (resp_ctx , query_bio )) == NULL )
955
954
goto end ;
956
955
957
956
ret = 1 ;
@@ -972,7 +971,7 @@ serial_cb(TS_RESP_CTX *ctx, void *data)
972
971
const char * serial_file = (const char * ) data ;
973
972
ASN1_INTEGER * serial = next_serial (serial_file );
974
973
975
- if (! serial ) {
974
+ if (serial == NULL ) {
976
975
TS_RESP_CTX_set_status_info (ctx , TS_STATUS_REJECTION ,
977
976
"Error during serial number "
978
977
"generation." );
@@ -992,10 +991,10 @@ next_serial(const char *serialfile)
992
991
ASN1_INTEGER * serial = NULL ;
993
992
BIGNUM * bn = NULL ;
994
993
995
- if (! (serial = ASN1_INTEGER_new ()))
994
+ if ((serial = ASN1_INTEGER_new ()) == NULL )
996
995
goto err ;
997
996
998
- if (! (in = BIO_new_file (serialfile , "r" ))) {
997
+ if ((in = BIO_new_file (serialfile , "r" )) == NULL ) {
999
998
ERR_clear_error ();
1000
999
BIO_printf (bio_err , "Warning: could not open file %s for "
1001
1000
"reading, using serial number: 1\n" , serialfile );
@@ -1008,13 +1007,13 @@ next_serial(const char *serialfile)
1008
1007
serialfile );
1009
1008
goto err ;
1010
1009
}
1011
- if (! (bn = ASN1_INTEGER_to_BN (serial , NULL )))
1010
+ if ((bn = ASN1_INTEGER_to_BN (serial , NULL )) == NULL )
1012
1011
goto err ;
1013
1012
ASN1_INTEGER_free (serial );
1014
1013
serial = NULL ;
1015
1014
if (!BN_add_word (bn , 1 ))
1016
1015
goto err ;
1017
- if (! (serial = BN_to_ASN1_INTEGER (bn , NULL )))
1016
+ if ((serial = BN_to_ASN1_INTEGER (bn , NULL )) == NULL )
1018
1017
goto err ;
1019
1018
}
1020
1019
ret = 1 ;
@@ -1034,7 +1033,7 @@ save_ts_serial(const char *serialfile, ASN1_INTEGER *serial)
1034
1033
int ret = 0 ;
1035
1034
BIO * out = NULL ;
1036
1035
1037
- if (! (out = BIO_new_file (serialfile , "w" )))
1036
+ if ((out = BIO_new_file (serialfile , "w" )) == NULL )
1038
1037
goto err ;
1039
1038
if (i2a_ASN1_INTEGER (out , serial ) <= 0 )
1040
1039
goto err ;
@@ -1064,18 +1063,18 @@ verify_command(char *data, char *digest, char *queryfile, char *in,
1064
1063
int ret = 0 ;
1065
1064
1066
1065
/* Decode the token (PKCS7) or response (TS_RESP) files. */
1067
- if (! (in_bio = BIO_new_file (in , "rb" )))
1066
+ if ((in_bio = BIO_new_file (in , "rb" )) == NULL )
1068
1067
goto end ;
1069
1068
if (token_in ) {
1070
- if (! (token = d2i_PKCS7_bio (in_bio , NULL )))
1069
+ if ((token = d2i_PKCS7_bio (in_bio , NULL )) == NULL )
1071
1070
goto end ;
1072
1071
} else {
1073
- if (! (response = d2i_TS_RESP_bio (in_bio , NULL )))
1072
+ if ((response = d2i_TS_RESP_bio (in_bio , NULL )) == NULL )
1074
1073
goto end ;
1075
1074
}
1076
1075
1077
- if (! (verify_ctx = create_verify_ctx (data , digest , queryfile ,
1078
- ca_path , ca_file , untrusted )))
1076
+ if ((verify_ctx = create_verify_ctx (data , digest , queryfile ,
1077
+ ca_path , ca_file , untrusted )) == NULL )
1079
1078
goto end ;
1080
1079
1081
1080
/* Checking the token or response against the request. */
@@ -1111,18 +1110,18 @@ create_verify_ctx(char *data, char *digest, char *queryfile, char *ca_path,
1111
1110
int ret = 0 ;
1112
1111
1113
1112
if (data != NULL || digest != NULL ) {
1114
- if (! (ctx = TS_VERIFY_CTX_new ()))
1113
+ if ((ctx = TS_VERIFY_CTX_new ()) == NULL )
1115
1114
goto err ;
1116
1115
ctx -> flags = TS_VFY_VERSION | TS_VFY_SIGNER ;
1117
1116
if (data != NULL ) {
1118
1117
ctx -> flags |= TS_VFY_DATA ;
1119
- if (! (ctx -> data = BIO_new_file (data , "rb" )))
1118
+ if ((ctx -> data = BIO_new_file (data , "rb" )) == NULL )
1120
1119
goto err ;
1121
1120
} else if (digest != NULL ) {
1122
1121
long imprint_len ;
1123
1122
ctx -> flags |= TS_VFY_IMPRINT ;
1124
- if (! (ctx -> imprint = string_to_hex (digest ,
1125
- & imprint_len ))) {
1123
+ if ((ctx -> imprint = string_to_hex (digest ,
1124
+ & imprint_len )) == NULL ) {
1126
1125
BIO_printf (bio_err , "invalid digest string\n" );
1127
1126
goto err ;
1128
1127
}
@@ -1133,11 +1132,11 @@ create_verify_ctx(char *data, char *digest, char *queryfile, char *ca_path,
1133
1132
* The request has just to be read, decoded and converted to
1134
1133
* a verify context object.
1135
1134
*/
1136
- if (! (input = BIO_new_file (queryfile , "rb" )))
1135
+ if ((input = BIO_new_file (queryfile , "rb" )) == NULL )
1137
1136
goto err ;
1138
- if (! (request = d2i_TS_REQ_bio (input , NULL )))
1137
+ if ((request = d2i_TS_REQ_bio (input , NULL )) == NULL )
1139
1138
goto err ;
1140
- if (! (ctx = TS_REQ_to_TS_VERIFY_CTX (request , NULL )))
1139
+ if ((ctx = TS_REQ_to_TS_VERIFY_CTX (request , NULL )) == NULL )
1141
1140
goto err ;
1142
1141
} else
1143
1142
return NULL ;
@@ -1146,11 +1145,12 @@ create_verify_ctx(char *data, char *digest, char *queryfile, char *ca_path,
1146
1145
ctx -> flags |= TS_VFY_SIGNATURE ;
1147
1146
1148
1147
/* Initialising the X509_STORE object. */
1149
- if (! (ctx -> store = create_cert_store (ca_path , ca_file )))
1148
+ if ((ctx -> store = create_cert_store (ca_path , ca_file )) == NULL )
1150
1149
goto err ;
1151
1150
1152
1151
/* Loading untrusted certificates. */
1153
- if (untrusted && !(ctx -> certs = TS_CONF_load_certs (untrusted )))
1152
+ if (untrusted != NULL &&
1153
+ (ctx -> certs = TS_CONF_load_certs (untrusted )) == NULL )
1154
1154
goto err ;
1155
1155
1156
1156
ret = 1 ;
@@ -1178,7 +1178,7 @@ create_cert_store(char *ca_path, char *ca_file)
1178
1178
X509_STORE_set_verify_cb (cert_ctx , verify_cb );
1179
1179
1180
1180
/* Adding a trusted certificate directory source. */
1181
- if (ca_path ) {
1181
+ if (ca_path != NULL ) {
1182
1182
lookup = X509_STORE_add_lookup (cert_ctx ,
1183
1183
X509_LOOKUP_hash_dir ());
1184
1184
if (lookup == NULL ) {
@@ -1193,7 +1193,7 @@ create_cert_store(char *ca_path, char *ca_file)
1193
1193
}
1194
1194
}
1195
1195
/* Adding a trusted certificate file source. */
1196
- if (ca_file ) {
1196
+ if (ca_file != NULL ) {
1197
1197
lookup = X509_STORE_add_lookup (cert_ctx , X509_LOOKUP_file ());
1198
1198
if (lookup == NULL ) {
1199
1199
BIO_printf (bio_err , "memory allocation failure\n" );
0 commit comments