#!/bin/sh

update_pdr_status() {
  /nn/bin/pdrcmd delete "security\encryption\testresults" 2>/dev/null
  /nn/bin/pdrcmd create "security\encryption\testresults" "$1" STR 2>/dev/null
}

validate_aes() {
  result=`/nn/sbin/GapCyperText 1234 9AD931B18B8E867A89A7C92F1AB0E9AE 1 2> /dev/null`
  if [ "$result" = "abcd" ] ; then 
    return 0;
  fi
  return 1;
}

validate_rsa_sha() {
  #verify SHA and RSA algorithms at the same time
  /nn/sbin/cfsserver -check /nn/etc/certs/nortel-cert.key /nn/etc/certs/nortel-cert.crt
  return $?
}

validate_rsa_sha

if [ ! "$?" = 0 ] ; then 
  /nn/bin/AddNnuDiagLog -mEncryptionCheck -lsecurity.systemlog -wER -sE -v0 "failed RSA test" 2>/dev/null
  update_pdr_status "failed the RSA2048 and SHA signature test"
  exit 1
fi

validate_aes
if [ ! "$?" = 0 ] ; then 
  /nn/bin/AddNnuDiagLog -mEncryptionCheck -lsecurity.systemlog -wER -sE -v0 "failed AES256 bit test" 2>/dev/null
  update_pdr_status "failed the AES256 decryption/encryption test"
  exit 1
fi
  
update_pdr_status "Test completed successfully"

exit 0
