attic/timestamp-info: Fix a few warnings on recent Fedora.
[ntpsec.git] / wafhelpers / openssl.py
blobaa7d7773b50426fd1a7829637011d5f7f9273534
1 # Copyright the NTPsec project contributors
3 # SPDX-License-Identifier: BSD-2-Clause
5 """Report on OpenSSL version and features for OpenSSL."""
7 SNIP_LIBSSL_TLS13_CHECK = """
8 #include <openssl/tls1.h>
10 #ifndef TLS1_3_VERSION
11 #error OpenSSL must have support for TLSv1.3
12 #endif
14 int main(void) {
15 return 0;
17 """
20 def check_libssl_tls13(ctx):
21 """Report if OpenSSL supports TLS 1.3 for ./waf configure."""
22 ctx.check_cc(
23 fragment=SNIP_LIBSSL_TLS13_CHECK,
24 use="SSL CRYPTO",
25 msg="Checking for OpenSSL with TLSv1.3 support",
29 SNIP_OPENSSL_BAD_VERSION_CHECK = """
30 #include <openssl/opensslv.h>
32 #if OPENSSL_VERSION_NUMBER == 0x1010101fL
33 #error OpenSSL version must not be 1.1.1a
34 #endif
36 int main(void) {
37 return 0;
39 """
42 def check_openssl_bad_version(ctx):
43 """Report if OpenSSL has a good version to ./waf configure."""
44 ctx.check_cc(
45 fragment=SNIP_OPENSSL_BAD_VERSION_CHECK,
46 use="SSL CRYPTO",
47 msg="Checking for OpenSSL != 1.1.1a",
51 SNIP_OPENSSL_DUMP_VERSION = """
52 #include <stdio.h>
53 #ifdef HAVE_OPENSSL_OPENSSLV_H
54 #include <openssl/opensslv.h>
55 #else
56 #define OPENSSL_VERSION_TEXT "something not_OpenSSL_or_LibreSSL something"
57 #endif // HAVE_OPENSSL_OPENSSLV_H
59 int main(void) {
60 printf("%s\\n", OPENSSL_VERSION_TEXT);
61 return 0;
63 """
66 def dump_openssl_version(ctx):
67 """Report OpenSSL version to ./waf configure."""
68 _ = "XXX_LIBSSL_VERSION"
69 ctx.start_msg("LibSSL version")
70 ret = ctx.check_cc(
71 fragment=SNIP_OPENSSL_DUMP_VERSION,
72 execute=True,
73 define_ret=True,
74 define_name=_,
75 mandatory=False,
77 if ret:
78 ctx.end_msg(' '.join(ctx.get_define(_).split()[0:2])[1:])
79 ctx.undefine(_)
80 else:
81 ctx.end_msg("Failed")