#!/bin/sh

# Checking if the CRL is verified.
# The verifyChain option verifies the peer certificate starting from the root CA.
# The self-signed root CA certificate is stored in the file specified with CAfile.
# Certificate Revocation Lists file is stored in the file specified with CRLfile.
# The success is expected because the server presents the valid certificate.

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

start() {
  ../../src/stunnel -fd 0 <<EOT
  debug = debug
  syslog = no
  pid = ${result_path}/stunnel.pid
  output = ${result_path}/stunnel.log
  CAfile = ${script_path}/certs/CACert.pem
  CRLfile = ${script_path}/certs/CACertCRL.pem

  [client]
  client = yes
  accept = 127.0.0.1:${http1}
  connect = 127.0.0.1:${https1}
  verifyChain = yes

  [server]
  accept = 127.0.0.1:${https1}
  connect = 127.0.0.1:${http_nc}
  cert = ${script_path}/certs/server_cert.pem
EOT
}

if grep -q -e "OpenSSL 0\.9\.8" -e "OpenSSL [1-9]" "results.log"
  then
    test_log_for "013_CRL_file" "success" "0" "$1" "$2" "$3" 2>> "stderr.log"
    exit $?
  else # older OpenSSL doesn't support sha256
    exit_logs "013_CRL_file" "skipped"
    clean_logs
    exit 125
  fi
