]>
git.siccegge.de Git - dane-monitoring-plugins.git/blob - check_dane/abstract.py
1 from abc
import ABC
, abstractmethod
2 from socket
import AF_INET6
, AF_INET
4 from unbound
import ub_ctx
6 from check_dane
.cert
import verify_certificate
7 from check_dane
.tlsa
import get_tlsa_records
, match_tlsa_records
17 class DaneChecker(ABC
):
23 def _init_connection(self
, family
, host
, port
):
28 def _close_connection(self
, connection
):
38 def _gather_certificates(self
):
41 for afamily
in self
._afamilies
:
42 connection
= self
._init
_connection
(afamily
, self
._host
, self
.port
)
44 nretval
= verify_certificate(connection
.getpeercert(), self
._args
)
45 retval
= max(retval
, nretval
)
46 certificates
.add(connection
.getpeercert(binary_form
=True))
48 self
._close
_connection
(connection
)
53 def _gather_records(self
):
54 return get_tlsa_records(self
._resolver
, "_%d._tcp.%s" % (self
.port
, self
._host
))
57 def generate_menu(self
, argparser
):
58 argparser
.add_argument("Host")
60 argparser
.add_argument("--check-dane",
62 help="Verify presented certificate via DANE (default: enabled)")
63 argparser
.add_argument("--check-ca",
65 help="Verify presented certificate via the CA system (default: enabled)")
66 argparser
.add_argument("--check-expire",
68 help="Verify presented certificate for expiration (default: enabled)")
70 argparser
.add_argument("-a", "--ancor",
71 action
="store", type=str, default
="/usr/share/dns/root.key",
72 help="DNSSEC root ancor")
73 argparser
.add_argument("--castore", action
="store", type=str,
74 default
="/etc/ssl/certs/ca-certificates.crt",
75 help="ca certificate bundle")
77 group
= argparser
.add_mutually_exclusive_group()
78 group
.add_argument("-6", "--6", action
="store_true", dest
="use6", help="check via IPv6 only")
79 group
.add_argument("-4", "--4", action
="store_true", dest
="use4", help="check via IPv4 only")
82 def set_args(self
, args
):
85 resolver
.add_ta_file(args
.ancor
)
86 self
._resolver
= resolver
89 self
._afamilies
= [AF_INET6
]
91 self
._afamilies
= [AF_INET
]
93 self
._afamilies
= [AF_INET
, AF_INET6
]
95 self
._host
= args
.Host
.encode('idna').decode()
99 records
= self
._gather
_records
()
100 certificates
= self
._gather
_certificates
()
101 return match_tlsa_records(records
, certificates
)