]>
git.siccegge.de Git - dane-monitoring-plugins.git/blob - check_dane/abstract.py
1 from abc
import ABCMeta
, abstractmethod
2 from unbound
import ub_ctx
3 from socket
import socket
, AF_INET6
, AF_INET
4 from ssl
import SSLContext
, PROTOCOL_TLSv1_2
, CERT_REQUIRED
7 from check_dane
.cert
import verify_certificate
, add_certificate_options
8 from check_dane
.tlsa
import get_tlsa_records
, match_tlsa_records
24 def _init_connection(self
):
29 def _close_connection(self
):
39 def _gather_certificates(self
):
42 for afamily
in self
._afamilies
:
44 connection
= self
._init
_connection
(afamily
, self
._host
, self
.port
)
45 except ConnectionRefusedError
:
46 logging
.error("Connection refused")
49 nretval
= verify_certificate(connection
.getpeercert(), self
._args
)
50 retval
= max(retval
, nretval
)
51 certificates
.add(connection
.getpeercert(binary_form
=True))
53 self
._close
_connection
(connection
)
58 def _gather_records(self
):
59 return get_tlsa_records(self
._resolver
, "_%d._tcp.%s" % (self
.port
, self
._host
))
62 def generate_menu(self
, argparser
):
63 argparser
.add_argument("Host")
65 argparser
.add_argument("--check-dane",
67 help="Verify presented certificate via DANE (default: enabled)")
68 argparser
.add_argument("--check-ca",
70 help="Verify presented certificate via the CA system (default: enabled)")
71 argparser
.add_argument("--check-expire",
73 help="Verify presented certificate for expiration (default: enabled)")
75 argparser
.add_argument("-a", "--ancor",
76 action
="store", type=str, default
="/usr/share/dns/root.key",
77 help="DNSSEC root ancor")
78 argparser
.add_argument("--castore", action
="store", type=str,
79 default
="/etc/ssl/certs/ca-certificates.crt",
80 help="ca certificate bundle")
82 group
= argparser
.add_mutually_exclusive_group()
83 group
.add_argument("-6", "--6", action
="store_true", dest
="use6", help="check via IPv6 only")
84 group
.add_argument("-4", "--4", action
="store_true", dest
="use4", help="check via IPv4 only")
87 def set_args(self
, args
):
90 resolver
.add_ta_file(args
.ancor
)
91 self
._resolver
= resolver
94 self
._afamilies
= [AF_INET6
]
96 self
._afamilies
= [AF_INET
]
98 self
._afamilies
= [AF_INET
, AF_INET6
]
100 self
._host
= args
.Host
.encode('idna').decode()
104 records
= self
._gather
_records
()
105 certificates
= self
._gather
_certificates
()
106 return match_tlsa_records(records
, certificates
)