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