Skip to content

Commit adcfd9a

Browse files
mtrojnarolszomal
andcommitted
Apply suggestions from code review
Added more detailed error messages. Fixed formatting and indentation. Co-authored-by: Małgorzata Olszówka <[email protected]>
1 parent f2f3a88 commit adcfd9a

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

osslsigncode.c

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,12 +2002,10 @@ static int verify_member(FILE_FORMAT_CTX *ctx, CatalogAuthAttr *attribute)
20022002
printf("Failed to extract current message digest\n\n");
20032003
return 1; /* FAILED */
20042004
}
2005-
2006-
if(!ctx->format->digest_calc) {
2007-
printf("Unsupported command\n");
2008-
return 1; /* Failed */
2005+
if (!ctx->format->digest_calc) {
2006+
printf("Unsupported method: digest_calc\n");
2007+
return 1; /* FAILED */
20092008
}
2010-
20112009
md = EVP_get_digestbynid(mdtype);
20122010
cmdbuf = ctx->format->digest_calc(ctx, md);
20132011
if (!cmdbuf) {
@@ -2225,13 +2223,14 @@ static int verify_signed_file(FILE_FORMAT_CTX *ctx, GLOBAL_OPTIONS *options)
22252223
PKCS7 *p7;
22262224
STACK_OF(PKCS7) *signatures;
22272225
int detached = options->catalog ? 1 : 0;
2228-
if(!ctx->format->check_file) {
2229-
printf("Unsupported command\n");
2230-
return 1; /* Failed */
2226+
2227+
if (!ctx->format->check_file) {
2228+
printf("Unsupported method: check_file\n");
2229+
return 1; /* FAILED */
22312230
}
22322231

22332232
if (!ctx->format->check_file(ctx, detached))
2234-
return 1; /* Failed */
2233+
return 1; /* FAILED */
22352234

22362235
if (detached) {
22372236
GLOBAL_OPTIONS *cat_options;
@@ -2248,21 +2247,18 @@ static int verify_signed_file(FILE_FORMAT_CTX *ctx, GLOBAL_OPTIONS *options)
22482247
printf("CAT file initialization error\n");
22492248
return 1; /* Failed */
22502249
}
2251-
2252-
if(!cat_ctx->format->pkcs7_extract) {
2253-
printf("Unsupported command\n");
2254-
return 1; /* Failed */
2250+
if (!cat_ctx->format->pkcs7_extract) {
2251+
printf("Unsupported command: extract-signature\n");
2252+
return 1; /* FAILED */
22552253
}
2256-
22572254
p7 = cat_ctx->format->pkcs7_extract(cat_ctx);
22582255
cat_ctx->format->ctx_cleanup(cat_ctx, NULL, NULL);
22592256
OPENSSL_free(cat_options);
22602257
} else {
2261-
if(!ctx->format->pkcs7_extract) {
2262-
printf("Unsupported command\n");
2263-
return 1; /* Failed */
2258+
if (!ctx->format->pkcs7_extract) {
2259+
printf("Unsupported command: extract-signature\n");
2260+
return 1; /* FAILED */
22642261
}
2265-
22662262
p7 = ctx->format->pkcs7_extract(ctx);
22672263
}
22682264
if (!p7) {
@@ -2284,13 +2280,13 @@ static int verify_signed_file(FILE_FORMAT_CTX *ctx, GLOBAL_OPTIONS *options)
22842280
printf("Catalog verification: failed\n\n");
22852281
}
22862282
} else if (ctx->format->verify_digests) {
2287-
if(ctx->format->verify_digests(ctx, sig)) {
2283+
if (ctx->format->verify_digests(ctx, sig)) {
22882284
printf("Signature Index: %d %s\n", i, i==0 ? " (Primary Signature)" : "");
22892285
ret &= verify_signature(ctx, sig);
22902286
}
22912287
} else {
2292-
printf("Unsupported command\n");
2293-
return 1; /* Failed */
2288+
printf("Unsupported method: verify_digests\n");
2289+
return 1; /* FAILED */
22942290
}
22952291
}
22962292
printf("Number of verified signatures: %d\n", i);
@@ -3771,8 +3767,8 @@ int main(int argc, char **argv)
37713767
ret = verify_signed_file(ctx, &options);
37723768
goto skip_signing;
37733769
} else if (options.cmd == CMD_EXTRACT) {
3774-
if(!ctx->format->pkcs7_extract) {
3775-
DO_EXIT_0("Unsupported command\n");
3770+
if (!ctx->format->pkcs7_extract) {
3771+
DO_EXIT_0("Unsupported command: extract-signature\n");
37763772
}
37773773
p7 = ctx->format->pkcs7_extract(ctx);
37783774
if (!p7) {
@@ -3782,8 +3778,8 @@ int main(int argc, char **argv)
37823778
PKCS7_free(p7);
37833779
goto skip_signing;
37843780
} else if (options.cmd == CMD_REMOVE) {
3785-
if(!ctx->format->remove_pkcs7) {
3786-
DO_EXIT_0("Unsupported command\n");
3781+
if (!ctx->format->remove_pkcs7) {
3782+
DO_EXIT_0("Unsupported command: remove-signature\n");
37873783
}
37883784
ret = ctx->format->remove_pkcs7(ctx, hash, outdata);
37893785
if (ctx->format->update_data_size) {

0 commit comments

Comments
 (0)