#!/bin/sh
# Adding an unauthenticated blob to the PE/MSI file.

. $(dirname $0)/../test_library

# PE file
test_name="361. Adding an unauthenticated blob to the PE file"
printf "\n%s\n" "$test_name"
if [ -s "test.exe" ]
  then
    faketime -f '@2019-01-01 00:00:00' /bin/bash -c '
        script_path=$(pwd)
        ../../osslsigncode sign -h sha256 \
            -certs "${script_path}/../certs/cert.pem" -key "${script_path}/../certs/key.pem" \
            -in "test.exe" -out "test_361_signed.exe" && \
        ../../osslsigncode add \
            -addUnauthenticatedBlob \
            -in "test_361_signed.exe" -out "test_361.exe"'
    verify_signature "$?" "361" "exe" "MODIFY" "UNUSED_PATTERN" "ASCII" "BEGIN_BLOB" "UNUSED_PATTERN"
    test_result "$?" "$test_name"
  else
    printf "Test skipped\n"
  fi

# CAB file
# Command is not supported for non-PE/non-MSI files

# MSI file
test_name="362. Adding an unauthenticated blob to the MSI file"
printf "\n%s\n" "$test_name"
if [ -s "sample.msi" ]
  then
    cat "sample.msi" > "test_362.msi"
    faketime -f '@2019-01-01 00:00:00' /bin/bash -c '
        script_path=$(pwd)
        ../../osslsigncode sign -h sha256 \
            -certs "${script_path}/../certs/cert.pem" -key "${script_path}/../certs/key.pem" \
            -in "sample.msi" -out "test_362_signed.msi" && \
        ../../osslsigncode add \
            -addUnauthenticatedBlob \
            -in "test_362_signed.msi" -out "test_362.msi"'
    verify_signature "$?" "362" "msi" "MODIFY" "UNUSED_PATTERN" "ASCII" "BEGIN_BLOB" "UNUSED_PATTERN"
    test_result "$?" "$test_name"
  else
    printf "Test skipped\n"
  fi

exit 0
