mirror of
https://github.com/LizardByte/Sunshine.git
synced 2026-12-02 01:52:49 +00:00
fix(pairing): replace duplicate client certificates (#5737)
This commit is contained in:
1 parent
e9af4a1aa4
commit
0daeb0e35b
3 files changed
+70
-6
No files matched your search
+26
-4
@@ -434,29 +434,36 @@ namespace nvhttp {
|
||||
/**
|
||||
* @brief Add authorized client data.
|
||||
*
|
||||
* A completed pairing replaces all records with the same exact X.509 identity so legacy duplicate records cannot make the newly paired client fail authorization.
|
||||
*
|
||||
* @param name Human-readable name to assign.
|
||||
* @param cert Certificate data or object used by the operation.
|
||||
* @return Persistent UUID for the added client, or an empty string when the certificate is invalid.
|
||||
*/
|
||||
std::string add_authorized_client(const std::string &name, std::string &&cert) {
|
||||
auto canonical_certificate = canonical_certificate_pem(cert);
|
||||
if (canonical_certificate.empty()) {
|
||||
auto certificate = crypto::x509(cert);
|
||||
if (!certificate) {
|
||||
return {};
|
||||
}
|
||||
|
||||
named_cert_t named_cert;
|
||||
named_cert.name = name;
|
||||
named_cert.cert = std::move(canonical_certificate);
|
||||
named_cert.cert = crypto::pem(certificate);
|
||||
named_cert.uuid = uuid_util::uuid_t::generate().string();
|
||||
const auto uuid = named_cert.uuid;
|
||||
|
||||
std::lock_guard lock {client_auth_mutex()};
|
||||
std::erase_if(client_root.named_devices, [&certificate](const named_cert_t &existing_client) {
|
||||
auto existing_certificate = crypto::x509(existing_client.cert);
|
||||
return existing_certificate && X509_cmp(existing_certificate.get(), certificate.get()) == 0;
|
||||
});
|
||||
client_root.named_devices.emplace_back(std::move(named_cert));
|
||||
rebuild_client_cert_chain();
|
||||
|
||||
if (!config::sunshine.flags[config::flag::FRESH_STATE]) {
|
||||
save_state();
|
||||
}
|
||||
return client_root.named_devices.back().uuid;
|
||||
return uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1832,6 +1839,21 @@ namespace nvhttp {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
bool duplicate_client(const std::string_view uuid) {
|
||||
std::lock_guard lock {client_auth_mutex()};
|
||||
const auto client_it = std::ranges::find(client_root.named_devices, uuid, &named_cert_t::uuid);
|
||||
if (client_it == client_root.named_devices.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto duplicate = *client_it;
|
||||
duplicate.uuid = uuid_util::uuid_t::generate().string();
|
||||
client_root.named_devices.emplace_back(std::move(duplicate));
|
||||
rebuild_client_cert_chain();
|
||||
save_state();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool authorize_client_certificate(const std::string_view cert) {
|
||||
auto certificate = crypto::x509(cert);
|
||||
if (!certificate) {
|
||||
|
||||
Reference in new issue
Block a user