15#include <boost/property_tree/ptree.hpp>
16#include <nlohmann/json.hpp>
17#include <Simple-Web-Server/server_https.hpp>
24using namespace std::chrono_literals;
31 using args_t = SimpleWeb::CaseInsensitiveMultimap;
32 using cmd_list_t = std::list<crypto::command_entry_t>;
56 constexpr auto OTP_EXPIRE_DURATION = 180s;
75 get_arg(
const args_t &
args,
const char *name,
const char *default_value =
nullptr);
79 extract_command_entries(
const nlohmann::json& j,
const std::string& key);
81 std::shared_ptr<rtsp_stream::launch_session_t>
89 void setup(
const std::string &pkey,
const std::string &cert);
100 bool virtual_display =
false;
105 uint32_t scale_factor = 100;
106 std::string launch_mode =
"normal";
127 class SunshineHTTPS:
public SimpleWeb::HTTPS {
129 SunshineHTTPS(boost::asio::io_context &io_context, boost::asio::ssl::context &ctx):
130 SimpleWeb::HTTPS(io_context, ctx) {
133 virtual ~SunshineHTTPS() {
135 SimpleWeb::error_code ec;
150 std::string uniqueID = {};
151 std::string cert = {};
152 std::string name = {};
155 std::unique_ptr<crypto::aes_t> cipher_key = {};
156 std::vector<uint8_t> clienthash = {};
158 std::string serversecret = {};
159 std::string serverchallenge = {};
163 std::shared_ptr<typename SimpleWeb::ServerBase<SimpleWeb::HTTP>::Response>,
164 std::shared_ptr<typename SimpleWeb::ServerBase<SunshineHTTPS>::Response>>
166 std::string salt = {};
198 void getservercert(
pair_session_t &sess, boost::property_tree::ptree &tree,
const std::string &
pin);
212 void clientchallenge(
pair_session_t &sess, boost::property_tree::ptree &tree,
const std::string &challenge);
221 void serverchallengeresp(
pair_session_t &sess, boost::property_tree::ptree &tree,
const std::string &encrypted_response);
237 void clientpairingsecret(
pair_session_t &sess, boost::property_tree::ptree &tree,
const std::string &client_pairing_secret);
259 bool pin(std::string
pin, std::string name);
261 std::string request_otp(
const std::string& passphrase,
const std::string& deviceName);
338 const std::string& uuid,
339 const std::string& name,
340 const std::string& display_mode,
341 const cmd_list_t& do_cmds,
342 const cmd_list_t& undo_cmds,
344 const bool enable_legacy_ordering,
345 const bool allow_client_commands,
346 const bool always_use_virtual_display
Declarations for cryptography functions.
PERM
The permissions of a client.
Functions for handling command line arguments.
Contains all the functions and variables related to the nvhttp (GameStream) server.
constexpr auto GFE_VERSION
The GFE version we are replicating.
void update_session_info(stream::session_t &session, const std::string &name, const crypto::PERM newPerm)
Update device info associated to the session.
std::optional< hestia_session_prepare_t > take_hestia_session_prepare(const std::string &client_uuid)
bool find_and_udpate_session_info(const std::string &uuid, const std::string &name, const crypto::PERM newPerm)
Finds and udpate session information.
@ SERVERCHALLENGERESP
Sunshine is in the server challenge response phase.
@ CLIENTCHALLENGE
Sunshine is in the client challenge phase.
@ NONE
Sunshine is not in a pairing phase.
@ CLIENTPAIRINGSECRET
Sunshine is in the client pairing secret phase.
@ GETSERVERCERT
Sunshine is in the get server certificate phase.
bool cancel_pending_pairing(const std::string &unique_id)
constexpr auto PORT_HTTPS
The HTTPS port, as a difference from the config port.
void store_hestia_session_prepare(const std::string &client_uuid, hestia_session_prepare_t prepare)
constexpr auto VERSION
The protocol version.
void start()
Start the nvhttp server.
void setup(const std::string &pkey, const std::string &cert)
Setup the nvhttp server.
constexpr auto PORT_HTTP
The HTTP port, as a difference from the config port.
bool pin(std::string pin, std::string name)
Compare the user supplied pin to the Moonlight pin.
bool unpair_client(const std::string_view uuid)
Remove single client.
void stop_session(stream::session_t &session, bool graceful)
Stops a session.
std::optional< std::string > pending_pair_client()
The client whose pairing request is waiting for a PIN, if any.
void erase_all_clients()
Remove all paired clients.
uint32_t launch_count()
How many launch and resume requests have been accepted so far.
bool verify_paired_client_certificate(X509 *certificate, crypto::p_named_cert_t &named_cert_out)
Verify a TLS client certificate against the paired-client store.
pair_session_t & begin_pairing_session(pair_session_t session)
nlohmann::json describe_applied_settings(const std::string &app_id, bool virtual_display, int scale_factor)
bool update_device_info(const std::string &uuid, const std::string &name, const std::string &display_mode, const cmd_list_t &do_cmds, const cmd_list_t &undo_cmds, const crypto::PERM newPerm, const bool enable_legacy_ordering, const bool allow_client_commands, const bool always_use_virtual_display)
Update device info.
void remove_session(const pair_session_t &sess)
removes the temporary pairing session
void clear_hestia_session_prepare(const std::string &client_uuid)
bool find_and_stop_session(const std::string &uuid, bool graceful)
Finds and stop session.
nlohmann::json get_all_clients()
Get all paired clients.
Declarations for RTSP streaming.
PAIR_PHASE last_phase
used as a security measure to prevent out of order calls
Declarations for thread-safe data structures.