| 1 |
From: Joris Vink <[email protected]> |
| 2 |
Date: Wed, 28 Dec 2022 11:09:15 +0100 |
| 3 |
Subject: Disable deprecated warnings for OpenSSL 3. |
| 4 |
|
| 5 |
Until the replacement is done, make sure Kore builds against OpenSSL 3 |
| 6 |
so it can be used as most distros made the move towards it. |
| 7 |
--- |
| 8 |
src/cli.c | 18 +++++++++++++ |
| 9 |
src/keymgr_openssl.c | 60 +++++++++++++++++------------------------ |
| 10 |
src/tls_openssl.c | 75 +++++++--------------------------------------------- |
| 11 |
3 files changed, 52 insertions(+), 101 deletions(-) |
| 12 |
|
| 13 |
diff --git a/src/cli.c b/src/cli.c |
| 14 |
index 5ea164e..7e437fe 100644 |
| 15 |
--- a/src/cli.c |
| 16 |
+++ b/src/cli.c |
| 17 |
@@ -43,6 +43,24 @@ |
| 18 |
#include <unistd.h> |
| 19 |
#include <utime.h> |
| 20 |
|
| 21 |
+/* |
| 22 |
+ * Turn off deprecated function warnings when building against OpenSSL 3. |
| 23 |
+ * |
| 24 |
+ * The OpenSSL 3 library deprecated most low-level functions in favour |
| 25 |
+ * for their higher level APIs. |
| 26 |
+ * |
| 27 |
+ * I am planning a replacement, but for now we can still make it build |
| 28 |
+ * and function by ignoring these warnings completely. |
| 29 |
+ * |
| 30 |
+ * The functions in question are: |
| 31 |
+ * - SHA256_Init, SHA256_Update, SHA256_Final |
| 32 |
+ * - RSA_new, RSA_generate_key_ex |
| 33 |
+ * - EVP_PKEY_assign |
| 34 |
+ */ |
| 35 |
+#if defined(OPENSSL_VERSION_MAJOR) && OPENSSL_VERSION_MAJOR >= 3 |
| 36 |
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
| 37 |
+#endif |
| 38 |
+ |
| 39 |
#define errno_s strerror(errno) |
| 40 |
#define ssl_errno_s ERR_error_string(ERR_get_error(), NULL) |
| 41 |
|
| 42 |
diff --git a/src/keymgr_openssl.c b/src/keymgr_openssl.c |
| 43 |
index 98ffbbc..ffc892b 100644 |
| 44 |
--- a/src/keymgr_openssl.c |
| 45 |
+++ b/src/keymgr_openssl.c |
| 46 |
@@ -63,6 +63,16 @@ |
| 47 |
#include "acme.h" |
| 48 |
#endif |
| 49 |
|
| 50 |
+/* |
| 51 |
+ * Disable deprecated declaration warnings if we're building against |
| 52 |
+ * OpenSSL 3 as they marked all low-level APIs as deprecated. |
| 53 |
+ * |
| 54 |
+ * Work is being done to replace these, but for now let things build. |
| 55 |
+ */ |
| 56 |
+#if defined(OPENSSL_VERSION_MAJOR) && OPENSSL_VERSION_MAJOR >= 3 |
| 57 |
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
| 58 |
+#endif |
| 59 |
+ |
| 60 |
#define RAND_TMP_FILE "rnd.tmp" |
| 61 |
#define RAND_POLL_INTERVAL (1800 * 1000) |
| 62 |
#define RAND_FILE_SIZE 1024 |
| 63 |
@@ -168,10 +178,11 @@ struct key { |
| 64 |
TAILQ_ENTRY(key) list; |
| 65 |
}; |
| 66 |
|
| 67 |
-char *kore_rand_file = NULL; |
| 68 |
- |
| 69 |
-static TAILQ_HEAD(, key) keys; |
| 70 |
-static int initialized = 0; |
| 71 |
+/* Helper for weird API designs (looking at you OpenSSL). */ |
| 72 |
+union deconst { |
| 73 |
+ void *p; |
| 74 |
+ const void *cp; |
| 75 |
+}; |
| 76 |
|
| 77 |
#if defined(KORE_USE_ACME) |
| 78 |
|
| 79 |
@@ -251,8 +262,6 @@ static void keymgr_x509_msg(const char *, const void *, size_t, int, int); |
| 80 |
|
| 81 |
static void keymgr_rsa_encrypt(struct kore_msg *, const void *, |
| 82 |
struct key *); |
| 83 |
-static void keymgr_ecdsa_sign(struct kore_msg *, const void *, |
| 84 |
- struct key *); |
| 85 |
|
| 86 |
#if defined(__OpenBSD__) |
| 87 |
#if defined(KORE_USE_ACME) |
| 88 |
@@ -262,6 +271,11 @@ static const char *keymgr_pledges = "stdio rpath"; |
| 89 |
#endif |
| 90 |
#endif |
| 91 |
|
| 92 |
+static TAILQ_HEAD(, key) keys; |
| 93 |
+static int initialized = 0; |
| 94 |
+ |
| 95 |
+char *kore_rand_file = NULL; |
| 96 |
+ |
| 97 |
void |
| 98 |
kore_keymgr_run(void) |
| 99 |
{ |
| 100 |
@@ -658,9 +672,6 @@ keymgr_msg_recv(struct kore_msg *msg, const void *data) |
| 101 |
case EVP_PKEY_RSA: |
| 102 |
keymgr_rsa_encrypt(msg, data, key); |
| 103 |
break; |
| 104 |
- case EVP_PKEY_EC: |
| 105 |
- keymgr_ecdsa_sign(msg, data, key); |
| 106 |
- break; |
| 107 |
default: |
| 108 |
break; |
| 109 |
} |
| 110 |
@@ -685,6 +696,7 @@ keymgr_msg_recv(struct kore_msg *msg, const void *data) |
| 111 |
static void |
| 112 |
keymgr_rsa_encrypt(struct kore_msg *msg, const void *data, struct key *key) |
| 113 |
{ |
| 114 |
+ union deconst cp; |
| 115 |
int ret; |
| 116 |
RSA *rsa; |
| 117 |
const struct kore_keyreq *req; |
| 118 |
@@ -692,7 +704,9 @@ keymgr_rsa_encrypt(struct kore_msg *msg, const void *data, struct key *key) |
| 119 |
u_int8_t buf[1024]; |
| 120 |
|
| 121 |
req = (const struct kore_keyreq *)data; |
| 122 |
- rsa = EVP_PKEY_get0_RSA(key->pkey); |
| 123 |
+ cp.cp = EVP_PKEY_get0_RSA(key->pkey); |
| 124 |
+ |
| 125 |
+ rsa = cp.p; |
| 126 |
|
| 127 |
keylen = RSA_size(rsa); |
| 128 |
if (req->data_len > keylen || keylen > sizeof(buf)) |
| 129 |
@@ -706,32 +720,6 @@ keymgr_rsa_encrypt(struct kore_msg *msg, const void *data, struct key *key) |
| 130 |
kore_msg_send(msg->src, KORE_MSG_KEYMGR_RESP, buf, ret); |
| 131 |
} |
| 132 |
|
| 133 |
-static void |
| 134 |
-keymgr_ecdsa_sign(struct kore_msg *msg, const void *data, struct key *key) |
| 135 |
-{ |
| 136 |
- size_t len; |
| 137 |
- EC_KEY *ec; |
| 138 |
- const struct kore_keyreq *req; |
| 139 |
- unsigned int siglen; |
| 140 |
- u_int8_t sig[1024]; |
| 141 |
- |
| 142 |
- req = (const struct kore_keyreq *)data; |
| 143 |
- ec = EVP_PKEY_get0_EC_KEY(key->pkey); |
| 144 |
- |
| 145 |
- len = ECDSA_size(ec); |
| 146 |
- if (req->data_len > len || len > sizeof(sig)) |
| 147 |
- return; |
| 148 |
- |
| 149 |
- if (ECDSA_sign(EVP_PKEY_NONE, req->data, req->data_len, |
| 150 |
- sig, &siglen, ec) == 0) |
| 151 |
- return; |
| 152 |
- |
| 153 |
- if (siglen > sizeof(sig)) |
| 154 |
- return; |
| 155 |
- |
| 156 |
- kore_msg_send(msg->src, KORE_MSG_KEYMGR_RESP, sig, siglen); |
| 157 |
-} |
| 158 |
- |
| 159 |
static void |
| 160 |
keymgr_x509_msg(const char *domain, const void *data, size_t len, |
| 161 |
int target, int msg) |
| 162 |
diff --git a/src/tls_openssl.c b/src/tls_openssl.c |
| 163 |
index c2fffbb..af14f75 100644 |
| 164 |
--- a/src/tls_openssl.c |
| 165 |
+++ b/src/tls_openssl.c |
| 166 |
@@ -36,6 +36,16 @@ |
| 167 |
#include "kore.h" |
| 168 |
#include "http.h" |
| 169 |
|
| 170 |
+/* |
| 171 |
+ * Disable deprecated declaration warnings if we're building against |
| 172 |
+ * OpenSSL 3 as they marked all low-level APIs as deprecated. |
| 173 |
+ * |
| 174 |
+ * Work is being done to replace these, but for now let things build. |
| 175 |
+ */ |
| 176 |
+#if defined(OPENSSL_VERSION_MAJOR) && OPENSSL_VERSION_MAJOR >= 3 |
| 177 |
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
| 178 |
+#endif |
| 179 |
+ |
| 180 |
#define TLS_SESSION_ID "kore_tls_sessionid" |
| 181 |
|
| 182 |
static int tls_domain_x509_verify(int, X509_STORE_CTX *); |
| 183 |
@@ -59,11 +69,7 @@ static int tls_keymgr_rsa_finish(RSA *); |
| 184 |
static int tls_keymgr_rsa_privenc(int, const unsigned char *, |
| 185 |
unsigned char *, RSA *, int); |
| 186 |
|
| 187 |
-static ECDSA_SIG *tls_keymgr_ecdsa_sign(const unsigned char *, int, |
| 188 |
- const BIGNUM *, const BIGNUM *, EC_KEY *); |
| 189 |
- |
| 190 |
static RSA_METHOD *keymgr_rsa_meth = NULL; |
| 191 |
-static EC_KEY_METHOD *keymgr_ec_meth = NULL; |
| 192 |
|
| 193 |
static DH *dh_params = NULL; |
| 194 |
static int tls_version = KORE_TLS_VERSION_BOTH; |
| 195 |
@@ -102,12 +108,6 @@ kore_tls_init(void) |
| 196 |
RSA_meth_set_finish(keymgr_rsa_meth, tls_keymgr_rsa_finish); |
| 197 |
RSA_meth_set_priv_enc(keymgr_rsa_meth, tls_keymgr_rsa_privenc); |
| 198 |
|
| 199 |
- if ((keymgr_ec_meth = EC_KEY_METHOD_new(NULL)) == NULL) |
| 200 |
- fatal("failed to allocate EC KEY method"); |
| 201 |
- |
| 202 |
- EC_KEY_METHOD_set_sign(keymgr_ec_meth, |
| 203 |
- NULL, NULL, tls_keymgr_ecdsa_sign); |
| 204 |
- |
| 205 |
kore_log(LOG_NOTICE, "TLS backend %s", OPENSSL_VERSION_TEXT); |
| 206 |
#if !defined(TLS1_3_VERSION) |
| 207 |
if (!kore_quiet) { |
| 208 |
@@ -122,7 +122,6 @@ void |
| 209 |
kore_tls_cleanup(void) |
| 210 |
{ |
| 211 |
RSA_meth_free(keymgr_rsa_meth); |
| 212 |
- EC_KEY_METHOD_free(keymgr_ec_meth); |
| 213 |
} |
| 214 |
|
| 215 |
void |
| 216 |
@@ -204,7 +203,6 @@ kore_tls_domain_setup(struct kore_domain *dom, int type, |
| 217 |
X509 *x509; |
| 218 |
EVP_PKEY *pkey; |
| 219 |
STACK_OF(X509_NAME) *certs; |
| 220 |
- EC_KEY *eckey; |
| 221 |
const SSL_METHOD *method; |
| 222 |
|
| 223 |
if (dom->tls_ctx != NULL) |
| 224 |
@@ -285,12 +283,6 @@ kore_tls_domain_setup(struct kore_domain *dom, int type, |
| 225 |
RSA_set_app_data(rsa, dom); |
| 226 |
RSA_set_method(rsa, keymgr_rsa_meth); |
| 227 |
break; |
| 228 |
- case EVP_PKEY_EC: |
| 229 |
- if ((eckey = EVP_PKEY_get1_EC_KEY(pkey)) == NULL) |
| 230 |
- fatalx("no EC public key present"); |
| 231 |
- EC_KEY_set_ex_data(eckey, 0, dom); |
| 232 |
- EC_KEY_set_method(eckey, keymgr_ec_meth); |
| 233 |
- break; |
| 234 |
default: |
| 235 |
fatalx("unknown public key in certificate"); |
| 236 |
} |
| 237 |
@@ -894,53 +886,6 @@ tls_keymgr_rsa_finish(RSA *rsa) |
| 238 |
return (1); |
| 239 |
} |
| 240 |
|
| 241 |
-static ECDSA_SIG * |
| 242 |
-tls_keymgr_ecdsa_sign(const unsigned char *dgst, int dgst_len, |
| 243 |
- const BIGNUM *in_kinv, const BIGNUM *in_r, EC_KEY *eckey) |
| 244 |
-{ |
| 245 |
- size_t len; |
| 246 |
- ECDSA_SIG *sig; |
| 247 |
- const u_int8_t *ptr; |
| 248 |
- struct kore_domain *dom; |
| 249 |
- struct kore_keyreq *req; |
| 250 |
- |
| 251 |
- if (in_kinv != NULL || in_r != NULL) |
| 252 |
- return (NULL); |
| 253 |
- |
| 254 |
- len = sizeof(*req) + dgst_len; |
| 255 |
- if (len > sizeof(keymgr_buf)) |
| 256 |
- fatal("keymgr_buf too small"); |
| 257 |
- |
| 258 |
- if ((dom = EC_KEY_get_ex_data(eckey, 0)) == NULL) |
| 259 |
- fatal("EC_KEY has no domain"); |
| 260 |
- |
| 261 |
- memset(keymgr_buf, 0, sizeof(keymgr_buf)); |
| 262 |
- req = (struct kore_keyreq *)keymgr_buf; |
| 263 |
- |
| 264 |
- if (kore_strlcpy(req->domain, dom->domain, sizeof(req->domain)) >= |
| 265 |
- sizeof(req->domain)) |
| 266 |
- fatal("%s: domain truncated", __func__); |
| 267 |
- |
| 268 |
- req->data_len = dgst_len; |
| 269 |
- memcpy(&req->data[0], dgst, req->data_len); |
| 270 |
- |
| 271 |
- kore_msg_send(KORE_WORKER_KEYMGR, KORE_MSG_KEYMGR_REQ, keymgr_buf, len); |
| 272 |
- tls_keymgr_await_data(); |
| 273 |
- |
| 274 |
- if (keymgr_response) { |
| 275 |
- ptr = keymgr_buf; |
| 276 |
- sig = d2i_ECDSA_SIG(NULL, &ptr, keymgr_buflen); |
| 277 |
- } else { |
| 278 |
- sig = NULL; |
| 279 |
- } |
| 280 |
- |
| 281 |
- keymgr_buflen = 0; |
| 282 |
- keymgr_response = 0; |
| 283 |
- kore_platform_event_all(worker->msg[1]->fd, worker->msg[1]); |
| 284 |
- |
| 285 |
- return (sig); |
| 286 |
-} |
| 287 |
- |
| 288 |
static void |
| 289 |
tls_keymgr_await_data(void) |
| 290 |
{ |