From 3b9e37e1ddc54eb5a6a320f5271e5e438ddab06f Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 30 Nov 2023 23:51:45 -0600 Subject: [PATCH] Don't hardcode the signature length to RSA-2048 (#1872) --- docs/source/about/advanced_usage.rst | 8 ++++++-- src/config.h | 4 ++-- src/crypto.cpp | 9 +++++---- src/crypto.h | 1 - src/nvhttp.cpp | 10 +++++++--- src_assets/common/assets/web/config.html | 10 ++++++---- 6 files changed, 26 insertions(+), 16 deletions(-) diff --git a/docs/source/about/advanced_usage.rst b/docs/source/about/advanced_usage.rst index c9d9ebae..0b4a687b 100644 --- a/docs/source/about/advanced_usage.rst +++ b/docs/source/about/advanced_usage.rst @@ -605,7 +605,9 @@ pkey ^^^^ **Description** - The private key. This must be 2048 bits. + The private key used for the web UI and Moonlight client pairing. For best compatibility, this should be an RSA-2048 private key. + + .. Warning:: Not all Moonlight clients support ECDSA keys or RSA key lengths other than 2048 bits. **Default** ``credentials/cakey.pem`` @@ -619,7 +621,9 @@ cert ^^^^ **Description** - The certificate. Must be signed with a 2048 bit key. + The certificate used for the web UI and Moonlight client pairing. For best compatibility, this should have an RSA-2048 public key. + + .. Warning:: Not all Moonlight clients support ECDSA keys or RSA key lengths other than 2048 bits. **Default** ``credentials/cacert.pem`` diff --git a/src/config.h b/src/config.h index 749a8556..6e481a1f 100644 --- a/src/config.h +++ b/src/config.h @@ -92,8 +92,8 @@ namespace config { // pc|lan|wan std::string origin_web_ui_allowed; - std::string pkey; // must be 2048 bits - std::string cert; // must be signed with a key of 2048 bits + std::string pkey; + std::string cert; std::string sunshine_name; diff --git a/src/crypto.cpp b/src/crypto.cpp index 5dec0f8d..26af3e7d 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -409,11 +409,12 @@ namespace crypto { return {}; } - std::size_t slen = digest_size; - - std::vector digest; - digest.resize(slen); + std::size_t slen; + if (EVP_DigestSignFinal(ctx.get(), nullptr, &slen) != 1) { + return {}; + } + std::vector digest(slen); if (EVP_DigestSignFinal(ctx.get(), digest.data(), &slen) != 1) { return {}; } diff --git a/src/crypto.h b/src/crypto.h index d8d0a35a..b75d013c 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -17,7 +17,6 @@ namespace crypto { std::string x509; std::string pkey; }; - constexpr std::size_t digest_size = 256; void md_ctx_destroy(EVP_MD_CTX *); diff --git a/src/nvhttp.cpp b/src/nvhttp.cpp index 5bde7b07..fa7847c3 100644 --- a/src/nvhttp.cpp +++ b/src/nvhttp.cpp @@ -380,11 +380,15 @@ namespace nvhttp { auto &client = sess.client; auto pairingsecret = util::from_hex_vec(get_arg(args, "clientpairingsecret"), true); + if (pairingsecret.size() <= 16) { + tree.put("root.paired", 0); + tree.put("root..status_code", 400); + tree.put("root..status_message", "Clientpairingsecret too short"); + return; + } std::string_view secret { pairingsecret.data(), 16 }; - std::string_view sign { pairingsecret.data() + secret.size(), crypto::digest_size }; - - assert((secret.size() + sign.size()) == pairingsecret.size()); + std::string_view sign { pairingsecret.data() + secret.size(), pairingsecret.size() - secret.size() }; auto x509 = crypto::x509(client.cert); auto x509_sign = crypto::signature(x509); diff --git a/src_assets/common/assets/web/config.html b/src_assets/common/assets/web/config.html index 6e2b61b7..927ef945 100644 --- a/src_assets/common/assets/web/config.html +++ b/src_assets/common/assets/web/config.html @@ -316,11 +316,13 @@ placeholder="/dir/pkey.pem" v-model="config.pkey" /> -
The private key must be 2048 bits
+
+ The private key used for the web UI and Moonlight client pairing. For best compatibility, this should be an RSA-2048 private key. +
- +
- +
- The certificate must be signed with a 2048 bit key + The certificate used for the web UI and Moonlight client pairing. For best compatibility, this should have an RSA-2048 public key.