#!/bin/sh
# Verify a file signed with the multiple signature.

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

if ! grep -q "no libcurl available" "results.log"; then
  for file in ${script_path}/../logs/notsigned/*.*
    do
      name="${file##*/}"
      ext="${file##*.}"
      desc=""
      case $ext in
        "cat") continue;; # Warning: CAT files do not support nesting
        "msi") filetype=MSI; format_nr=2 ;;
        "ex_") filetype=CAB; format_nr=3 ;;
        "exe") filetype=PE; format_nr=4 ;;
        "ps1") continue;; # Warning: TXT files do not support nesting
      esac

      number="$test_nr$format_nr"
      test_name="Verify a $filetype$desc file signed with the multiple signature"
      printf "\n%03d. %s\n" "$number" "$test_name"

      ../../osslsigncode sign -h sha256 \
        -st "1556668800" \
        -certs "${script_path}/../certs/expired.pem" -key "${script_path}/../certs/key.pem" \
        -verbose \
        -in "notsigned/$name" -out "signed1_$number.$ext"
      ../../osslsigncode sign -h sha384 \
        -st "1556668800" \
        -nest \
        -certs "${script_path}/../certs/revoked.pem" -key "${script_path}/../certs/key.pem" \
        -t http://time.certum.pl/ \
        -t http://timestamp.digicert.com/ \
        -verbose \
        -in "signed1_$number.$ext" -out "signed2_$number.$ext"
      ../../osslsigncode sign -h sha256 \
        -st "1556668800" \
        -nest \
        -certs "${script_path}/../certs/cert.pem" -key "${script_path}/../certs/key.pem" \
        -ts http://time.certum.pl/ \
        -ts http://timestamp.digicert.com/ \
        -verbose \
        -in "signed2_$number.$ext" -out "test_$number.$ext"
      result=$?

      verify_signature "$result" "$number" "$ext" "success" "@2019-09-01 12:00:00" \
        "UNUSED_PATTERN" "SHA384" "UNUSED_PATTERN"
      test_result "$?" "$number" "$test_name"
    done
  else
    format_nr=0
    number="$test_nr$format_nr"
    test_name="Verify a file signed with the multiple signature"
    printf "\n%03d. %s\nTest skipped\n" "$number" "$test_name"
  fi

exit 0
