#!/bin/sh
# Attach the PEM signature to the PE/CAB/MSI file.

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

# PE file
test_name="321. Attach the PEM signature to the PE file"
printf "\n%s\n" "$test_name"
if test -s "test.exe"
  then
    ../../osslsigncode attach-signature \
        -sigin "sign_pe.pem" \
        -CAfile "${script_path}/../certs/CACert.pem" \
        -CRLfile "${script_path}/../certs/CACertCRL.pem" \
        -in "test.exe" -out "test_321.exe"
    verify_signature "$?" "321" "exe" "success" "@2019-09-01 12:00:00" \
	"sha256sum" "ASCII" "SHA512" "UNUSED_PATTERN"
    test_result "$?" "$test_name"
  else
    printf "Test skipped\n"
  fi

# CAB file
test_name="322. Attach the PEM signature to the CAB file"
printf "\n%s\n" "$test_name"
if [ -s "test.ex_" ]
  then
    ../../osslsigncode attach-signature \
        -sigin "sign_cab.pem" \
        -CAfile "${script_path}/../certs/CACert.pem" \
        -CRLfile "${script_path}/../certs/CACertCRL.pem" \
        -in "test.ex_" -out "test_322.ex_"
    verify_signature "$?" "322" "ex_" "success" "@2019-09-01 12:00:00" \
	"sha256sum" "ASCII" "SHA512" "UNUSED_PATTERN"
    test_result "$?" "$test_name"
  else
    printf "Test skipped\n"
  fi

# MSI file
test_name="323. Attach the PEM signature to the MSI file"
printf "\n%s\n" "$test_name"
if test -s "sample.msi"
  then
    ../../osslsigncode attach-signature \
        -sigin "sign_msi.pem" \
        -CAfile "${script_path}/../certs/CACert.pem" \
        -CRLfile "${script_path}/../certs/CACertCRL.pem" \
        -in "sample.msi" -out "test_323.msi"
    verify_signature "$?" "323" "msi" "success" "@2019-09-01 12:00:00" \
	"sha256sum" "ASCII" "SHA512" "UNUSED_PATTERN"
    test_result "$?" "$test_name"
  else
    printf "Test skipped\n"
  fi

exit 0
