@@ -62,6 +62,9 @@ readonly SERVER_INIT_PATH='/etc/init.d/nginx'
6262# The minimum version the server has to have for session ticket keys via files.
6363readonly SERVER_MIN_VERSION=' 1.5.7'
6464
65+ # The minimum version the OpenSSL library requires for session ticket support.
66+ readonly OPENSSL_MIN_VERSION=' 0.9.8f'
67+
6568# Absolute path to the cron program.
6669readonly CRON_PATH=' /etc/cron.d/session_ticket_key_rotation'
6770
@@ -202,31 +205,74 @@ system time and ensure all servers are in sync"
202205 fi
203206}
204207
208+ # Check OpenSSL version which has (of course) an awkward formatting.
209+ #
210+ # ARGS:
211+ # $1 - The minimum required version.
212+ # RETURN:
213+ # 0 - If version is equal or greater.
214+ # 1 - If version is lower.
215+ check_openssl_version ()
216+ {
217+ # Example output: `OpenSSL 1.0.1f 6 Jan 2014`
218+ OPENSSL_VERSION=$( openssl version)
219+
220+ OPENSSL_VERSION=" ${OPENSSL_VERSION#* } " # Remove smallest prefix space.
221+ OPENSSL_VERSION=" ${OPENSSL_VERSION%% * } " # Remove largest suffix space.
222+ # Now we have only `1.0.1f` left from above example.
223+
224+ # This one's complicated. We need an integer for -ge comparison and therefore
225+ # remove the last character and all dots from the version string. Afterwards
226+ # we get the last character and convert it to its ASCII code point.
227+ #
228+ # Note the leading single quote in front of the second command, that's what
229+ # converts the character to its code point.
230+ V1=$( printf -- ' %s%03d' \
231+ " $( printf -- ' %s' ${OPENSSL_VERSION} | head -c -1 | tr -d ' .' ) " \
232+ " '$( printf -- ' %s' ${OPENSSL_VERSION} | tail -c -1) " )
233+
234+ # Now we need to do the same with the minimum version.
235+ V2=$( printf -- ' %s%03d' \
236+ " $( printf -- ' %s' ${1} | head -c -1 | tr -d ' .' ) " \
237+ " '$( printf -- ' %s' ${1} | tail -c -1) " )
238+
239+ # Greater or equals is what we are interested in.
240+ if [ " ${V1} " -ge " ${V2} " ]
241+ then
242+ ok " Installed OpenSSL version is ${YELLOW}${OPENSSL_VERSION}${NORMAL} "
243+ else
244+ fail " Installed OpenSSL version is ${YELLOW}${OPENSSL_VERSION}${NORMAL} \
245+ which does not support session ticket keys. You need to install at least \
246+ version ${YELLOW}${2}${NORMAL} "
247+ fi
248+ }
249+
205250# Check program version.
206251#
252+ # NOTE: Works for nginx and Apache http (httpd).
207253# ARGS:
208254# $1 - The name of the program to check the version (must support -v option).
209255# $2 - The minimum version.
210256# RETURN:
211257# 0 - If version is equal or greater.
212258# 1 - If version is lower.
213- check_version ()
259+ check_server_version ()
214260{
215- # Get version information from program.
216- SERVER_VERSION= $( " ${1} " -v 2>&1 )
217-
218- # nginx specific, the format of the output looks like:
219- # `nginx version: nginx/1.7.6`
220- # We need to strip the part to the left of the slash.
221- SERVER_VERSION= " ${SERVER_VERSION ##*/ } "
222-
223- # Remove dots and leading zeros .
224- V1= $( printf ' %s ' " ${SERVER_VERSION} " | tr -d ' . ' )
225- V1= " ${V1 ##* 0} "
226-
227- # Remove dots and leading zeros .
228- V2 =$( printf ' %s' " ${2 } " | tr -d ' .' )
229- V2=" ${V2 ##* 0} "
261+ # Get version information from program. The head call isn't necessary for
262+ # nginx but it is for httpd because it will output something like:
263+ # Server version: Apache/2.4.10
264+ # Server built: Jul 09 2014 07:22:45
265+ SERVER_VERSION= $( " ${1} " -v 2>&1 | head -n1 )
266+
267+ # nginx: nginx version: nginx/1.7.6
268+ # httpd: Server version: Apache/2.4.10
269+ SERVER_VERSION= " ${SERVER_VERSION ##*/ } " # Remove longest match slash .
270+ # nginx: 1.7.6
271+ # httpd: 2.4.10
272+
273+ # Remove dots.
274+ V1 =$( printf -- ' %s' " ${SERVER_VERSION } " | tr -d ' .' )
275+ V2=$( printf -- ' %s ' " ${2} " | tr -d ' . ' )
230276
231277 # Greater or equals is what we are interested in.
232278 if [ " ${V1} " -ge " ${V2} " ]
0 commit comments