File tree 1 file changed +47
-0
lines changed
1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ # Verifies that a given remote host / port has a valid SSL certificate.
4
+ #
5
+ # Usage:
6
+ # ssl_verify.sh HOST PORT
7
+ #
8
+ # This is really written to make sure that using SSL for cloud databases
9
+ # will work. See:
10
+ # * https://docs.rackspace.com/docs/cloud-databases/v1/general-api-info/using-ssl/
11
+ # * http://ssl.rackspaceclouddb.com/rackspace-ca-2021.pem
12
+ #
13
+ # On Ubuntu machines, this means that the CA file(s) in
14
+ # `/etc/ssl/certs/ca-certificates.crt` should be able to validate the SSL
15
+ # certificate.
16
+ #
17
+ # In order to setup the `rackspace-ca-2021.pem` file, you should
18
+ # place the `rackspace-ca-2021.pem` file in this folder
19
+ # `/usr/local/share/ca-certificates` and rename it to end in `.crt`. Then
20
+ # run `/usr/sbin/update-ca-certificates`
21
+
22
+ if [ $# -ne 1 ] && [ $# -ne 2 ] && [ $# -ne 3 ]; then
23
+ echo " Usage: $0 <ip> [port] [ca_file]"
24
+ exit 100
25
+ fi
26
+
27
+ HOST=$1
28
+
29
+ if [ $# -eq 2 ] || [ $# -eq 3 ]; then
30
+ PORT=$2
31
+ else
32
+ PORT=443
33
+ fi
34
+
35
+ if [ $# -eq 3 ]; then
36
+ CA_FILE=$3
37
+ RESULT=` echo | openssl s_client -connect $HOST :$PORT 2> /dev/null | openssl x509 | openssl verify -CAfile $CA_FILE 2> /dev/null | awk ' { gsub("stdin: ", "") ; print $0 }' `
38
+ else
39
+ CA_FILE=' '
40
+ RESULT=` echo | openssl s_client -connect $HOST :$PORT 2> /dev/null | openssl x509 | openssl verify 2> /dev/null | awk ' { gsub("stdin: ", "") ; print $0 }' `
41
+ fi
42
+
43
+ echo " metric result string ${RESULT:- Error: No data} " ;
44
+ echo " metric host string ${HOST:- Error: No data} " ;
45
+ echo " metric port uint32 ${PORT:- Error: No data} " ;
46
+ echo " metric ca_file string ${CA_FILE:- Error: No data} " ;
47
+ exit 0
You can’t perform that action at this time.
0 commit comments