10#include <condition_variable>
20#include <boost/property_tree/ptree.hpp>
21#include <nlohmann/json.hpp>
22#include <Simple-Web-Server/server_https.hpp>
87 void setup(
const std::string &pkey,
const std::string &cert);
100 SunshineHTTPS(boost::asio::io_context &io_context, boost::asio::ssl::context &ctx):
101 SimpleWeb::HTTPS(io_context, ctx) {
106 SimpleWeb::error_code ec;
137 std::string
cert = {};
138 std::string
name = {};
146 std::shared_ptr<pairing_completion_t>
completion = std::make_shared<pairing_completion_t>();
150 std::shared_ptr<typename SimpleWeb::ServerBase<SimpleWeb::HTTP>::Response>,
151 std::shared_ptr<typename SimpleWeb::ServerBase<SunshineHTTPS>::Response>>
153 std::string
salt = {};
157 std::chrono::steady_clock::time_point
expires_at = std::chrono::steady_clock::time_point::max();
240 void expire_pair_sessions(std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now());
337 bool pin(std::string_view pairing_id, std::string
pin, std::string name);
386 namespace test_support {
395 std::unique_ptr<SimpleWeb::ServerBase<SunshineHTTPS>> make_https_server(
396 const std::string &certificate_file,
397 const std::string &private_key_file,
398 std::shared_ptr<SimpleWeb::ScopeRunner> &handler_scope
408 std::shared_ptr<
typename SimpleWeb::ServerBase<SimpleWeb::HTTP>::Response> response,
409 std::shared_ptr<
typename SimpleWeb::ServerBase<SimpleWeb::HTTP>::Request> request
415 void reset_client_state();
425 std::string add_client(
const std::string &name, std::string cert,
bool enabled);
433 bool duplicate_client(std::string_view uuid);
441 bool authorize_client_certificate(std::string_view cert);
455 void reload_client_state();
Simple-Web-Server HTTPS backend configured for Sunshine certificate handling.
Definition nvhttp.h:92
SunshineHTTPS(boost::asio::io_context &io_context, boost::asio::ssl::context &ctx)
Construct an HTTPS connection using Sunshine's TLS context.
Definition nvhttp.h:100
Tagged storage for one of two possible value types.
Definition utility.h:750
Declarations for cryptography functions.
Contains all the functions and variables related to the nvhttp (GameStream) server.
Definition nvhttp.cpp:46
std::vector< pending_pairing_t > get_pending_pairings()
List pairing requests that are waiting for operator PIN approval.
Definition nvhttp.cpp:670
constexpr auto GFE_VERSION
The GFE version we are replicating.
Definition nvhttp.h:42
void serverchallengeresp(pair_session_t &sess, pt::ptree &tree, const std::string &encrypted_response)
Handle the server-challenge response phase of GameStream pairing.
Definition nvhttp.cpp:833
bool is_valid_pairing_id(const std::string_view pairing_id)
Validate an operator approval identifier received from the REST API.
Definition nvhttp.cpp:649
void expire_pair_sessions(const std::chrono::steady_clock::time_point now)
Remove pairing sessions whose completion deadline has passed.
Definition nvhttp.cpp:665
void clientpairingsecret(pair_session_t &sess, pt::ptree &tree, const std::string &client_pairing_secret)
Handle the client pairing-secret phase of GameStream pairing.
Definition nvhttp.cpp:869
pair_session_insert_e insert_pair_session(pair_session_t sess, std::string &pairing_id)
Insert a newly created pairing session into bounded pending storage.
Definition nvhttp.cpp:612
constexpr auto PAIRING_SESSION_TIMEOUT
Lifetime of an incomplete pairing session.
Definition nvhttp.h:72
PAIR_PHASE
Enumerates supported pAIR PHASE options.
Definition nvhttp.h:114
@ SERVERCHALLENGERESP
Sunshine is in the server challenge response phase.
Definition nvhttp.h:118
@ CLIENTCHALLENGE
Sunshine is in the client challenge phase.
Definition nvhttp.h:117
@ NONE
Sunshine is not in a pairing phase.
Definition nvhttp.h:115
@ CLIENTPAIRINGSECRET
Sunshine is in the client pairing secret phase.
Definition nvhttp.h:119
@ GETSERVERCERT
Sunshine is in the get server certificate phase.
Definition nvhttp.h:116
bool is_valid_pairing_name(const std::string_view name)
Validate an operator-supplied paired-client name received from the REST API.
Definition nvhttp.cpp:661
constexpr auto PORT_HTTPS
The HTTPS port, as a difference from the config port.
Definition nvhttp.h:52
constexpr std::size_t MAX_PAIRING_CLIENT_NAME_SIZE
Maximum number of bytes accepted for an operator-supplied paired-client name.
Definition nvhttp.h:67
constexpr std::size_t MAX_PENDING_PAIRING_SESSIONS
Maximum number of pairing sessions retained at one time.
Definition nvhttp.h:57
constexpr auto VERSION
The protocol version.
Definition nvhttp.h:37
void start()
Start the nvhttp server.
Definition nvhttp.cpp:1647
bool evict_abandoned_pair_session(const std::string &unique_id)
Evict an abandoned in-progress pairing session for a client.
Definition nvhttp.cpp:637
void setup(const std::string &pkey, const std::string &cert)
Setup the nvhttp server.
Definition nvhttp.cpp:1633
constexpr auto PORT_HTTP
The HTTP port, as a difference from the config port.
Definition nvhttp.h:47
void clientchallenge(pair_session_t &sess, pt::ptree &tree, const std::string &challenge)
Handle the client-challenge phase of GameStream pairing.
Definition nvhttp.cpp:783
pair_session_insert_e
Result of inserting a new pairing session into bounded pending storage.
Definition nvhttp.h:179
@ ALREADY_EXISTS
A session with the same client unique ID is already active.
Definition nvhttp.h:181
@ ADDED
The session was inserted successfully.
Definition nvhttp.h:180
@ FULL
The bounded session store has reached its limit.
Definition nvhttp.h:182
bool is_valid_pairing_pin(const std::string_view pin)
Validate a Moonlight pairing PIN received from the REST API.
Definition nvhttp.cpp:655
bool unpair_client(const std::string_view uuid)
Remove single client.
Definition nvhttp.cpp:1799
void complete_pairing(pair_session_t &sess, const bool success)
Publish the final result of a pairing handshake.
Definition nvhttp.cpp:579
constexpr std::size_t PAIRING_ID_SIZE
Number of hexadecimal characters in an operator approval identifier.
Definition nvhttp.h:62
void getservercert(pair_session_t &sess, pt::ptree &tree, const std::string &pin)
Return the server certificate text for pairing responses.
Definition nvhttp.cpp:752
void erase_all_clients()
Remove all paired clients.
Definition nvhttp.cpp:1792
bool pin(const std::string_view pairing_id, std::string pin, std::string name)
Apply the user supplied PIN to the explicitly selected pairing request.
Definition nvhttp.cpp:1149
bool set_client_enabled(const std::string_view uuid, bool enabled)
Enable or disable a client.
Definition nvhttp.cpp:1816
void remove_session(const pair_session_t &sess)
removes the temporary pairing session
Definition nvhttp.cpp:722
bool cancel_pairing(const std::string_view pairing_id)
Cancel a pairing request that is waiting for operator approval.
Definition nvhttp.cpp:697
nlohmann::json get_all_clients()
Get all paired clients.
Definition nvhttp.cpp:1318
std::string get_cert_by_uuid(const std::string_view uuid)
Get cert by UUID.
Definition nvhttp.cpp:1832
std::string address
Network address from which the pairing request originated.
std::string device_name
Untrusted device name reported by the pairing client.
util::Either< std::shared_ptr< typename SimpleWeb::ServerBase< SimpleWeb::HTTP >::Response >, std::shared_ptr< typename SimpleWeb::ServerBase< SunshineHTTPS >::Response > > response
Pending HTTP or HTTPS response completed after PIN approval.
std::string salt
Client-provided salt used to derive the pairing key.
std::chrono::steady_clock::time_point expires_at
Deadline for completing this pairing session.
std::string name
Client name recorded after successful pairing.
std::string cert
Client certificate bytes exchanged during pairing.
std::string uniqueID
Client-provided pairing-session identifier.
Pairing handshake state exchanged with a Moonlight client.
Definition nvhttp.h:134
std::string serverchallenge
Server challenge sent during pairing.
Definition nvhttp.h:145
struct nvhttp::pair_session_t::@305111106156267002241031277360116001064101025004 async_insert_pin
Async insert pin.
struct nvhttp::pair_session_t::@105363203101100234310146234343010345115334117372 client
Client object or client certificate data owned by this state..
bool failed
Whether protocol validation failed and the session must be removed.
Definition nvhttp.h:164
std::shared_ptr< pairing_completion_t > completion
Result shared with the REST request waiting for the handshake.
Definition nvhttp.h:146
std::vector< uint8_t > clienthash
Client certificate hash used during pairing.
Definition nvhttp.h:142
std::string serversecret
Server pairing secret.
Definition nvhttp.h:144
std::unique_ptr< crypto::aes_t > cipher_key
Cipher key.
Definition nvhttp.h:141
PAIR_PHASE last_phase
used as a security measure to prevent out of order calls
Definition nvhttp.h:163
Shared result used to return the completed pairing outcome to a PIN submitter.
Definition nvhttp.h:125
std::condition_variable condition
Wakes the REST request when pairing finishes.
Definition nvhttp.h:126
std::optional< bool > result
Final pairing result, or no value while the handshake is pending.
Definition nvhttp.h:128
std::mutex mutex
Protects the completion result.
Definition nvhttp.h:127
Operator-visible context for a pairing request awaiting PIN approval.
Definition nvhttp.h:170
std::string id
Unguessable approval identifier.
Definition nvhttp.h:171
std::string address
Network address from which the request originated.
Definition nvhttp.h:173
std::string name
Untrusted device name reported by the pairing client.
Definition nvhttp.h:172