Skip to content

Commit

Permalink
Don't hardcode the signature length to RSA-2048 (LizardByte#1872)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgutman authored Dec 1, 2023
1 parent 336062d commit 3b9e37e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 16 deletions.
8 changes: 6 additions & 2 deletions docs/source/about/advanced_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``
Expand All @@ -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``
Expand Down
4 changes: 2 additions & 2 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 5 additions & 4 deletions src/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,12 @@ namespace crypto {
return {};
}

std::size_t slen = digest_size;

std::vector<uint8_t> digest;
digest.resize(slen);
std::size_t slen;
if (EVP_DigestSignFinal(ctx.get(), nullptr, &slen) != 1) {
return {};
}

std::vector<uint8_t> digest(slen);
if (EVP_DigestSignFinal(ctx.get(), digest.data(), &slen) != 1) {
return {};
}
Expand Down
1 change: 0 additions & 1 deletion src/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down
10 changes: 7 additions & 3 deletions src/nvhttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.<xmlattr>.status_code", 400);
tree.put("root.<xmlattr>.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);
Expand Down
10 changes: 6 additions & 4 deletions src_assets/common/assets/web/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,13 @@ <h2 class="accordion-header">
placeholder="/dir/pkey.pem"
v-model="config.pkey"
/>
<div class="form-text">The private key must be 2048 bits</div>
<div class="form-text">
The private key used for the web UI and Moonlight client pairing. For best compatibility, this should be an RSA-2048 private key.
</div>
</div>
<!--Cert-->
<!--Certificate-->
<div class="mb-3">
<label for="cert" class="form-label">Cert</label>
<label for="cert" class="form-label">Certificate</label>
<input
type="text"
class="form-control"
Expand All @@ -329,7 +331,7 @@ <h2 class="accordion-header">
v-model="config.cert"
/>
<div class="form-text">
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.
</div>
</div>

Expand Down

0 comments on commit 3b9e37e

Please sign in to comment.