#!/bin/sh
# Adding an RFC 3161 timestamp to the PE/MSI file.

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

# PE file
test_name="381. Adding an RFC 3161 timestamp 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_381_signed.exe" && \
        ../../osslsigncode add \
            -ts http://time.certum.pl/ \
            -in "test_381_signed.exe" -out "test_381.exe"'
    verify_signature "$?" "381" "exe" "UNUSED_PATTERN" "UNUSED_PATTERN" "ASCII" "Unizeto" "Unizeto"
    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="382. Adding an RFC 3161 timestamp to the MSI file"
printf "\n%s\n" "$test_name"
if [ -s "sample.msi" ]
  then
    cat "sample.msi" > "test_382.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_382_signed.msi" && \
        ../../osslsigncode add \
            -ts http://time.certum.pl/ \
            -in "test_382_signed.msi" -out "test_382.msi"'
    verify_signature "$?" "382" "msi" "UNUSED_PATTERN" "UNUSED_PATTERN" "ASCII" "Unizeto" "Unizeto"
    test_result "$?" "$test_name"
  else
    printf "Test skipped\n"
  fi

exit 0
