Welcome to mirror list, hosted at ThFree Co, Russian Federation.

tests_crypto « include - github.com/CISOfy/lynis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8db5eb69e4a2e88a855de2aacb4e742a25f79660 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/sh

#################################################################################
#
#   Lynis
# ------------------
#
# Copyright 2007-2015, Michael Boelen (michael.boelen@cisofy.com), CISOfy
# Web site: https://cisofy.com
#
# Lynis comes with ABSOLUTELY NO WARRANTY. This is free software, and you are
# welcome to redistribute it under the terms of the GNU General Public License.
# See LICENSE file for usage of this software.
#
#################################################################################
#
# Cryptography
#
#################################################################################
#
    InsertSection "Cryptography"
#
#################################################################################
#
    # Test        : CRYP-7902
    # Description : check for expired SSL certificates
    if [ ! -z "${OPENSSLBINARY}" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
    Register --test-no CRYP-7902 --preqs-met ${PREQS_MET} --weight L --network NO --description "Check expire date of SSL certificates"
    if [ ${SKIPTEST} -eq 0 ]; then
        FOUNDPROBLEM=0
        # Check profile for paths to check
        sSSL_PATHS=`grep "^ssl:certificates:" ${PROFILE} | cut -d ':' -f3` 
        for I in ${sSSL_PATHS}; do
            if [ -d ${I} ]; then
                FileIsReadable ${I}
                if [ ${CANREAD} -eq 1 ]; then
                    logtext "Result: found directory ${I}"
                    # Search for CRT files
                    sFINDCRTS=`find ${I} -name "*.crt" -type f -print 2> /dev/null`
                    for J in ${sFINDCRTS}; do
                        FileIsReadable ${J}
                        if [ ${CANREAD} -eq 1 ]; then
                            logtext "Test: checking certificate ${J}"
                            # Check certificate where 'end date' has been expired
                            FIND=`${OPENSSLBINARY} x509 -noout -checkend 0 -in ${J} -enddate > /dev/null ; echo $?`
                            if [ "${FIND}" = "0" ]; then
                                logtext "Result: certificate ${J} seems to be correct and still valid"
                                report "valid_certificate[]=${J}|unknown entity|"
                              else
                                FOUNDPROBLEM=1
                                logtext "Result: certificate ${J} has been expired"
                                report "expired_certificate[]=${J}|unknown entity|"
                            fi
                          else
                            logtext "Result: can not read file ${J} (no permission)"
                        fi
                    done
                  else
                    logtext "Result: can not read path ${I} (no permission)"
                fi
              else
                logtext "Result: SSL path ${I} does not exist"
            fi
        done

        if [ ${FOUNDPROBLEM} -eq 0 ]; then
            Display --indent 2 --text "- Checking SSL certificate expiration" --result OK --color GREEN
          else
            Display --indent 2 --text "- Checking SSL certificate expiration" --result WARNING --color RED
            ReportSuggestion ${TEST_NO} "Check available certificates for expiration"
        fi
    fi
#
#################################################################################
#

wait_for_keypress

#
#================================================================================
# Lynis - Copyright 2007-2015, Michael Boelen, CISOfy - https://cisofy.com