Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion cmake/CMakeTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,26 @@ if(Python3_FOUND AND NOT cryptography_error)
endforeach(format ${formats})
endforeach(ext ${extensions_nocat})

# Attach a nested signature of another file
# The primary signature still matches, the nested one must not be accepted
# Unsupported nesting for APPX files
set(mismatches "exe:ex_" "ex_:exe" "ps1:js" "psc1:ps1" "mof:js" "js:ps1")
foreach(mismatch ${mismatches})
string(REPLACE ":" ";" pair ${mismatch})
list(GET pair 0 ext)
list(GET pair 1 sigext)
add_test(NAME "attached_mismatch_${ext}"
COMMAND ${Python3_EXECUTABLE} ${EXEC} ${OSSLSIGNCODE} "attach-signature"
"-nest"
"-sigin" "${FILES}/${sigext}.der"
"-in" "${FILES}/signed.${ext}"
"-out" "${FILES}/attached_mismatch.${ext}")
set_tests_properties("attached_mismatch_${ext}" PROPERTIES
DEPENDS "signed_${ext};extract_der_${sigext}"
PASS_REGULAR_EXPRESSION "Signature mismatch")
list(APPEND ALL_TESTS "attached_mismatch_${ext}")
endforeach(mismatch ${mismatches})

# Add an unauthenticated blob to a previously-signed file
foreach(ext ${extensions_all})
add_test(NAME "added_${ext}"
Expand Down Expand Up @@ -817,7 +837,7 @@ if(Python3_FOUND AND NOT cryptography_error)
endforeach(crafted "ok" "late" "empty" "short" "two_attrs")

# Delete test files
set(names "signed" "nested" "revoked" "removed" "added")
set(names "signed" "nested" "revoked" "removed" "added" "attached_mismatch")
foreach(ext ${extensions_all})
foreach(name ${names})
set(OUTPUT_FILES ${OUTPUT_FILES} "${FILES}/${name}.${ext}")
Expand Down
21 changes: 12 additions & 9 deletions osslsigncode.c
Original file line number Diff line number Diff line change
Expand Up @@ -3325,7 +3325,8 @@ static int verify_signature(FILE_FORMAT_CTX *ctx, PKCS7 *p7)
* [in] options: verification options
* [in] verify_signature_flag:
* - non-zero: verify both digest and cryptographic signature
* - zero: verify only digest/content consistency (no signature validation)
* - zero: verify only digest/content consistency of every signature
* (no signature validation)
* [returns] 1 on error or 0 on success
*/
static int verify_signed_file(FILE_FORMAT_CTX *ctx, GLOBAL_OPTIONS *options,
Expand Down Expand Up @@ -3364,16 +3365,18 @@ static int verify_signed_file(FILE_FORMAT_CTX *ctx, GLOBAL_OPTIONS *options,
} else {
digest_ok = (ctx->format->verify_digests(ctx, sig) != 0);
}
if (digest_ok) {
if (!verify_signature_flag) {
/* success: at least one digest matches */
ret = 0;
} else {
/* success if at least one valid signature is found */
ret &= verify_signature(ctx, sig);
verified++;
if (!verify_signature_flag) {
/* every signature must match the data it is attached to */
if (!digest_ok) {
ret = 1;
break;
}
ret = 0;
} else if (digest_ok) {
/* success if at least one valid signature is found */
ret &= verify_signature(ctx, sig);
}
verified++;
}
printf("Number of verified signatures: %d\n", verified);
sk_PKCS7_pop_free(signatures, PKCS7_free);
Expand Down
Loading