if [ "$CURRENT_TIMESTAMP" -gt "$EXPIRATION_TIMESTAMP" ]; then EXPIRED="yes" fi else echo "The certificate file $CERT_FILE does not exist." exit1 fi
if [ "$EXPIRED" = "yes" ]; then echo "The certificate in $CERT_FILE has expired." exit2 else echo "The certificate in $CERT_FILE is still valid." exit0 fi
if [ "$CURRENT_TIMESTAMP" -gt "$EXPIRATION_TIMESTAMP" ]; then EXPIRED="yes" fi else echo"The certificate file $CERT_FILE does not exist." return 1 fi
if [ "$EXPIRED" = "yes" ]; then echo"The certificate in $CERT_FILE has expired." return 2 else echo"The certificate in $CERT_FILE is still valid." return 0 fi }
# -------------------------- CUT THIS SECTION --------------------------- # This is a template to create a customized plugin # # Each plugin should at least have several variables defined with the # prefix PLUGIN_* (see below) # # If you want to learn what functions you can use, check include/functions # # -------------------------- CUT THIS SECTION ---------------------------
######################################################################### # # * DO NOT REMOVE * #----------------------------------------------------- # PLUGIN_AUTHOR=Mr Auditor <auditor@4399.example.org> # PLUGIN_CATEGORY=Custom # PLUGIN_DESC=This is a custom tests about check pem # PLUGIN_NAME=check_certificate_expiry # PLUGIN_REQUIRED_TESTS= #----------------------------------------------------- # ######################################################################### check_certificate_expiry() { CERT_FILE="/etc/pki/tls/cert.pem" EXPIRED="no"
if [ "$CURRENT_TIMESTAMP" -gt "$EXPIRATION_TIMESTAMP" ]; then EXPIRED="yes" fi else echo "The certificate file $CERT_FILE does not exist." return 1 fi
if [ "$EXPIRED" = "yes" ]; then echo "The certificate in $CERT_FILE has expired." return 2 else echo "The certificate in $CERT_FILE is still valid." return 0 fi }
######################################################################### # # Add custom section to screen output InsertSection "Custom Plugin" # ################################################################################# # # Test : CUST-0001 # Description : We show some lines on the screen
# Register our first custom test # We consider it to be a lightweight test (no heavy IO, or long searches), no network connection needed Register --test-no CUST-0001 --weight L --network NO --description "This is a custom tests about check pem" if [ ${SKIPTEST} -eq 0 ]; then # The Display function makes it easy to show something on screen, with colors. # --indent defines amount of spaces # --text text to be displayed on screen # --result text at end of line # --color color of result text Display --indent 2 --text "- Checking certificate" --result OK --color GREEN check_certificate_expiry; fi # ################################################################################# #
# First check if OPENSSLBINARY is known as a prerequisite for this test. if [ ! -z "${OPENSSLBINARY}" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi Register --test-no CUST-0001 --preqs-met ${PREQS_MET} --weight M --network NO --description "Description of custom test" if [ ${SKIPTEST} -eq 0 ]; then FOUNDPROBLEM=0 DIR="/my/path" LogText "Test: we are going to check if we can find a particular directory (${DIR})" # Check if a directory exists if [ -d ${DIR} ]; then LogText "Result: log entry for easier debugging or additional information" else FOUNDPROBLEM=1 LogText "Result: directory ${DIR} was not found!" ReportWarning "${TEST_NO}""This is a test warning line""${DIR}""text:Create directory ${DIR}" fi
if [ ${FOUNDPROBLEM} -eq 0 ]; then Display --indent 2 --text "- Checking if everything is OK..." --result OK --color GREEN else Display --indent 2 --text "- Checking if everything is OK..." --result WARNING --color RED ReportSuggestion "${TEST_NO}""This is a suggestion" fi fi # ################################################################################# #
# Wait for keypress (unless --quick is being used) WaitForKeyPress
<ruleid="100200"level="10"> <if_sid>530</if_sid> <match>Valid keyword found.</match> <description>Lynis audit found the valid keyword in the output of CUST-0001 test.</description> </rule>