#!/bin/sh
# Sign a PE/CAB/MSI file with the certificate and key stored in a PKCS#12 container.

. $(dirname $0)/../test_library
script_path=$(pwd)

# PE file
test_name="051. Sign a PE file with a certificate and key stored in a PKCS#12 container"
printf "\n%s\n" "$test_name"
if test -s "test.exe"
  then
    ../../osslsigncode sign -h sha256 \
        -st "1556668800" \
        -pkcs12 "${script_path}/../certs/cert.p12" -pass passme \
        -in "test.exe" -out "test_051.exe"
    verify_signature "$?" "051" "exe" "success" "@2019-09-01 12:00:00" \
	"sha256sum" "ASCII" "osslsigncode" "UNUSED_PATTERN"
    test_result "$?" "$test_name"
  else
    printf "Test skipped\n"
  fi

# CAB file
test_name="052. Sign a CAB file with a certificate and key stored in a PKCS#12 container"
printf "\n%s\n" "$test_name"
if test -s "test.ex_"
  then
    ../../osslsigncode sign -h sha256 \
        -st "1556668800" \
        -pkcs12 "${script_path}/../certs/cert.p12" \
        -pass passme \
        -in "test.ex_" -out "test_052.ex_"
    verify_signature "$?" "052" "ex_" "success" "@2019-09-01 12:00:00" \
	"sha256sum" "ASCII" "osslsigncode" "UNUSED_PATTERN"
    test_result "$?" "$test_name"
  else
    printf "Test skipped\n"
  fi

# MSI file
test_name="053. Sign a MSI file with a certificate and key stored in a PKCS#12 container"
printf "\n%s\n" "$test_name"
if test -s "sample.msi"
  then
    ../../osslsigncode sign -h sha256 \
        -st "1556668800" \
        -pkcs12 "${script_path}/../certs/cert.p12" \
        -pass passme \
        -in "sample.msi" -out "test_053.msi"
    verify_signature "$?" "053" "msi" "success" "@2019-09-01 12:00:00" \
	"sha256sum" "ASCII" "osslsigncode" "UNUSED_PATTERN"
    test_result "$?" "$test_name"
  else
    printf "Test skipped\n"
  fi

exit 0
