|
Hermes 0.7.0
Linux game streaming host
|
Contains all the functions and variables related to the nvhttp (GameStream) server. More...
Classes | |
| struct | client_t |
| struct | conf_intern_t |
| struct | hestia_session_prepare_t |
| struct | pair_session_t |
| struct | pending_hestia_session_prepare_t |
| class | SunshineHTTPS |
| class | SunshineHTTPSServer |
| struct | tunnel |
| struct | tunnel< SimpleWeb::HTTP > |
| struct | tunnel< SunshineHTTPS > |
Typedefs | |
| using | p_named_cert_t = crypto::p_named_cert_t |
| using | PERM = crypto::PERM |
| using | https_server_t = SunshineHTTPSServer |
| using | http_server_t = SimpleWeb::Server<SimpleWeb::HTTP> |
| using | resp_https_t = std::shared_ptr<typename SimpleWeb::ServerBase<SunshineHTTPS>::Response> |
| using | req_https_t = std::shared_ptr<typename SimpleWeb::ServerBase<SunshineHTTPS>::Request> |
| using | resp_http_t = std::shared_ptr<typename SimpleWeb::ServerBase<SimpleWeb::HTTP>::Response> |
| using | req_http_t = std::shared_ptr<typename SimpleWeb::ServerBase<SimpleWeb::HTTP>::Request> |
| using | args_t = SimpleWeb::CaseInsensitiveMultimap |
| using | cmd_list_t = std::list<crypto::command_entry_t> |
Enumerations | |
| enum class | op_e { ADD , REMOVE } |
| enum class | PAIR_PHASE { NONE , GETSERVERCERT , CLIENTCHALLENGE , SERVERCHALLENGERESP , CLIENTPAIRINGSECRET } |
Functions | |
| bool | experimental_isolated_sessions_enabled () |
| nlohmann::json | describe_applied_settings (const std::string &app_id, bool virtual_display, int scale_factor) |
| uint32_t | launch_count () |
| How many launch and resume requests have been accepted so far. | |
| void | set_pending_pair (const std::string &unique_id, const std::string &name) |
| void | clear_pending_pair (const std::string &unique_id) |
| void | clear_pending_pairs () |
| std::string | get_arg (const args_t &args, const char *name, const char *default_value) |
| cmd_list_t | extract_command_entries (const nlohmann::json &j, const std::string &key) |
| void | save_state () |
| void | load_state () |
| void | add_authorized_client (const p_named_cert_t &named_cert_p) |
| std::shared_ptr< rtsp_stream::launch_session_t > | make_launch_session (bool host_audio, bool input_only, const args_t &args, const crypto::named_cert_t *named_cert_p) |
| void | remove_session (const pair_session_t &sess) |
| removes the temporary pairing session | |
| bool | cancel_pending_pairing (const std::string &unique_id) |
| pair_session_t & | begin_pairing_session (pair_session_t session) |
| void | fail_pair (pair_session_t &sess, pt::ptree &tree, const std::string status_msg) |
| void | getservercert (pair_session_t &sess, pt::ptree &tree, const std::string &pin) |
| void | clientchallenge (pair_session_t &sess, pt::ptree &tree, const std::string &challenge) |
| void | serverchallengeresp (pair_session_t &sess, pt::ptree &tree, const std::string &encrypted_response) |
| void | clientpairingsecret (pair_session_t &sess, pt::ptree &tree, const std::string &client_pairing_secret) |
| crypto::named_cert_t * | get_verified_cert (req_https_t request) |
| template<class T> | |
| void | print_req (std::shared_ptr< typename SimpleWeb::ServerBase< T >::Request > request) |
| template<class T> | |
| void | not_found (std::shared_ptr< typename SimpleWeb::ServerBase< T >::Response > response, std::shared_ptr< typename SimpleWeb::ServerBase< T >::Request > request) |
| template<class T> | |
| void | pair (std::shared_ptr< typename SimpleWeb::ServerBase< T >::Response > response, std::shared_ptr< typename SimpleWeb::ServerBase< T >::Request > request) |
| void | cancel_pairing_request (std::shared_ptr< SimpleWeb::ServerBase< SimpleWeb::HTTP >::Response > response, std::shared_ptr< SimpleWeb::ServerBase< SimpleWeb::HTTP >::Request > request) |
| std::optional< std::string > | pending_pair_client () |
| The client whose pairing request is waiting for a PIN, if any. | |
| bool | pin (std::string pin, std::string name) |
| Compare the user supplied pin to the Moonlight pin. | |
| template<class T> | |
| void | serverinfo (std::shared_ptr< typename SimpleWeb::ServerBase< T >::Response > response, std::shared_ptr< typename SimpleWeb::ServerBase< T >::Request > request) |
| nlohmann::json | get_all_clients () |
| Get all paired clients. | |
| void | applist (resp_https_t response, req_https_t request) |
| void | launch (bool &host_audio, resp_https_t response, req_https_t request) |
| void | resume (bool &host_audio, resp_https_t response, req_https_t request) |
| void | cancel (resp_https_t response, req_https_t request) |
| void | appasset (resp_https_t response, req_https_t request) |
| void | getClipboard (resp_https_t response, req_https_t request) |
| void | setClipboard (resp_https_t response, req_https_t request) |
| void | setup (const std::string &pkey, const std::string &cert) |
| Setup the nvhttp server. | |
| 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. | |
| void | store_hestia_session_prepare (const std::string &client_uuid, hestia_session_prepare_t prepare) |
| std::optional< hestia_session_prepare_t > | take_hestia_session_prepare (const std::string &client_uuid) |
| void | clear_hestia_session_prepare (const std::string &client_uuid) |
| void | start () |
| Start the nvhttp server. | |
| std::string | request_otp (const std::string &passphrase, const std::string &deviceName) |
| void | erase_all_clients () |
| Remove all paired clients. | |
| void | stop_session (stream::session_t &session, bool graceful) |
| Stops a session. | |
| bool | find_and_stop_session (const std::string &uuid, bool graceful) |
| Finds and stop session. | |
| void | update_session_info (stream::session_t &session, const std::string &name, const crypto::PERM newPerm) |
| Update device info associated to the session. | |
| bool | find_and_udpate_session_info (const std::string &uuid, const std::string &name, const crypto::PERM newPerm) |
| Finds and udpate session information. | |
| 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. | |
| bool | unpair_client (std::string_view uuid) |
| Remove single client. | |
| void | getservercert (pair_session_t &sess, boost::property_tree::ptree &tree, const std::string &pin) |
| Pair, phase 1. | |
| void | clientchallenge (pair_session_t &sess, boost::property_tree::ptree &tree, const std::string &challenge) |
| Pair, phase 2. | |
| void | serverchallengeresp (pair_session_t &sess, boost::property_tree::ptree &tree, const std::string &encrypted_response) |
| Pair, phase 3. | |
| void | clientpairingsecret (pair_session_t &sess, boost::property_tree::ptree &tree, const std::string &client_pairing_secret) |
| Pair, phase 4 (final). | |
Variables | |
| crypto::cert_chain_t | cert_chain |
| struct nvhttp::conf_intern_t | conf_intern |
| std::unordered_map< std::string, pair_session_t > | map_id_sess |
| std::recursive_mutex | pair_session_mutex |
| client_t | client_root |
| std::atomic< uint32_t > | session_id_counter |
| std::mutex | pending_pair_mutex |
| The clients whose pairing requests are waiting for a PIN, if any. | |
| std::unordered_map< std::string, std::string > | pending_pairs |
| constexpr auto | VERSION = "7.1.431.-1" |
| The protocol version. | |
| constexpr auto | GFE_VERSION = "3.23.0.74" |
| The GFE version we are replicating. | |
| constexpr auto | PORT_HTTP = 0 |
| The HTTP port, as a difference from the config port. | |
| constexpr auto | PORT_HTTPS = -5 |
| The HTTPS port, as a difference from the config port. | |
| constexpr auto | OTP_EXPIRE_DURATION = 180s |
Contains all the functions and variables related to the nvhttp (GameStream) server.
| using nvhttp::cmd_list_t = std::list<crypto::command_entry_t> |
| using nvhttp::http_server_t = SimpleWeb::Server<SimpleWeb::HTTP> |
Definition at line 216 of file nvhttp.cpp.
| using nvhttp::https_server_t = SunshineHTTPSServer |
Definition at line 215 of file nvhttp.cpp.
| using nvhttp::p_named_cert_t = crypto::p_named_cert_t |
Definition at line 52 of file nvhttp.cpp.
| using nvhttp::PERM = crypto::PERM |
Definition at line 53 of file nvhttp.cpp.
| using nvhttp::req_http_t = std::shared_ptr<typename SimpleWeb::ServerBase<SimpleWeb::HTTP>::Request> |
Definition at line 281 of file nvhttp.cpp.
| using nvhttp::req_https_t = std::shared_ptr<typename SimpleWeb::ServerBase<SunshineHTTPS>::Request> |
Definition at line 279 of file nvhttp.cpp.
| using nvhttp::resp_http_t = std::shared_ptr<typename SimpleWeb::ServerBase<SimpleWeb::HTTP>::Response> |
Definition at line 280 of file nvhttp.cpp.
| using nvhttp::resp_https_t = std::shared_ptr<typename SimpleWeb::ServerBase<SunshineHTTPS>::Response> |
Definition at line 278 of file nvhttp.cpp.
|
strong |
| Enumerator | |
|---|---|
| ADD | Add certificate. |
| REMOVE | Remove certificate. |
Definition at line 283 of file nvhttp.cpp.
|
strong |
| void nvhttp::add_authorized_client | ( | const p_named_cert_t & | named_cert_p | ) |
Definition at line 497 of file nvhttp.cpp.
| void nvhttp::appasset | ( | resp_https_t | response, |
| req_https_t | request ) |
Definition at line 2066 of file nvhttp.cpp.
| void nvhttp::applist | ( | resp_https_t | response, |
| req_https_t | request ) |
Definition at line 1290 of file nvhttp.cpp.
| pair_session_t & nvhttp::begin_pairing_session | ( | pair_session_t | session | ) |
Begin a fresh handshake, replacing a stale attempt for the same uniqueID.
Definition at line 637 of file nvhttp.cpp.
| void nvhttp::cancel | ( | resp_https_t | response, |
| req_https_t | request ) |
Definition at line 2017 of file nvhttp.cpp.
| void nvhttp::cancel_pairing_request | ( | std::shared_ptr< SimpleWeb::ServerBase< SimpleWeb::HTTP >::Response > | response, |
| std::shared_ptr< SimpleWeb::ServerBase< SimpleWeb::HTTP >::Request > | request ) |
Definition at line 997 of file nvhttp.cpp.
| bool nvhttp::cancel_pending_pairing | ( | const std::string & | unique_id | ) |
Cancel only an incomplete handshake; never revoke an authorized client.
Definition at line 615 of file nvhttp.cpp.
| void nvhttp::clear_hestia_session_prepare | ( | const std::string & | client_uuid | ) |
Remove any unconsumed preparation hints for a paired client.
Definition at line 2236 of file nvhttp.cpp.
| void nvhttp::clear_pending_pair | ( | const std::string & | unique_id | ) |
Definition at line 261 of file nvhttp.cpp.
| void nvhttp::clear_pending_pairs | ( | ) |
Definition at line 266 of file nvhttp.cpp.
| void nvhttp::clientchallenge | ( | pair_session_t & | sess, |
| boost::property_tree::ptree & | tree, | ||
| const std::string & | challenge ) |
Pair, phase 2.
Using the AES key that we generated in phase 1 we have to decrypt the client challenge,
We generate a SHA256 hash with the following:
The hash + server_challenge will then be AES encrypted and sent as the challengeresponse in the returned XML
| void nvhttp::clientchallenge | ( | pair_session_t & | sess, |
| pt::ptree & | tree, | ||
| const std::string & | challenge ) |
Definition at line 676 of file nvhttp.cpp.
| void nvhttp::clientpairingsecret | ( | pair_session_t & | sess, |
| boost::property_tree::ptree & | tree, | ||
| const std::string & | client_pairing_secret ) |
Pair, phase 4 (final).
We now have to use everything we exchanged before in order to verify and finally pair the clients
We'll check the client_hash obtained at phase 3, it should contain the following:
Then using the client certificate public key we should be able to verify that the client secret has been signed by Moonlight
| void nvhttp::clientpairingsecret | ( | pair_session_t & | sess, |
| pt::ptree & | tree, | ||
| const std::string & | client_pairing_secret ) |
Definition at line 748 of file nvhttp.cpp.
| nlohmann::json nvhttp::describe_applied_settings | ( | const std::string & | app_id, |
| bool | virtual_display, | ||
| int | scale_factor ) |
What the next launch of app app_id will apply for the settings a client asks for, and who decides each one: {"virtual_display": {"requested", "effective", "source"}, "scale_factor": {...}}. Sources: "client", "app_forced", "app", "host_default", "headless", "isolated_session". Null when no app has that id.
Definition at line 94 of file nvhttp.cpp.
| void nvhttp::erase_all_clients | ( | ) |
Remove all paired clients.
Examples
Definition at line 2398 of file nvhttp.cpp.
| bool nvhttp::experimental_isolated_sessions_enabled | ( | ) |
Definition at line 55 of file nvhttp.cpp.
| cmd_list_t nvhttp::extract_command_entries | ( | const nlohmann::json & | j, |
| const std::string & | key ) |
Definition at line 301 of file nvhttp.cpp.
| void nvhttp::fail_pair | ( | pair_session_t & | sess, |
| pt::ptree & | tree, | ||
| const std::string | status_msg ) |
Definition at line 644 of file nvhttp.cpp.
| bool nvhttp::find_and_stop_session | ( | const std::string & | uuid, |
| bool | graceful ) |
Finds and stop session.
| [in] | uuid | The uuid string |
| [in] | graceful | Whether to stop gracefully |
Definition at line 2414 of file nvhttp.cpp.
| bool nvhttp::find_and_udpate_session_info | ( | const std::string & | uuid, |
| const std::string & | name, | ||
| const crypto::PERM | newPerm ) |
Finds and udpate session information.
| [in] | uuid | The uuid string |
| [in] | name | New name |
| [in] | newPerm | New permission |
Definition at line 2427 of file nvhttp.cpp.
| nlohmann::json nvhttp::get_all_clients | ( | ) |
Get all paired clients.
Examples
Definition at line 1236 of file nvhttp.cpp.
| std::string nvhttp::get_arg | ( | const args_t & | args, |
| const char * | name, | ||
| const char * | default_value ) |
Definition at line 288 of file nvhttp.cpp.
|
inline |
Definition at line 831 of file nvhttp.cpp.
| void nvhttp::getClipboard | ( | resp_https_t | response, |
| req_https_t | request ) |
Definition at line 2097 of file nvhttp.cpp.
| void nvhttp::getservercert | ( | pair_session_t & | sess, |
| boost::property_tree::ptree & | tree, | ||
| const std::string & | pin ) |
Pair, phase 1.
Moonlight will send a salt and client certificate, we'll also need the user provided pin.
PIN and SALT will be used to derive a shared AES key that needs to be stored in order to be used to decrypt_symmetric in the next phases.
At this stage we only have to send back our public certificate.
| void nvhttp::getservercert | ( | pair_session_t & | sess, |
| pt::ptree & | tree, | ||
| const std::string & | pin ) |
Definition at line 652 of file nvhttp.cpp.
| void nvhttp::launch | ( | bool & | host_audio, |
| resp_https_t | response, | ||
| req_https_t | request ) |
Definition at line 1377 of file nvhttp.cpp.
| uint32_t nvhttp::launch_count | ( | ) |
How many launch and resume requests have been accepted so far.
A request counted here is not a streaming session until its RTSP handshake completes; a caller waiting for a quiet moment compares two readings.
Definition at line 231 of file nvhttp.cpp.
| void nvhttp::load_state | ( | ) |
Definition at line 413 of file nvhttp.cpp.
| std::shared_ptr< rtsp_stream::launch_session_t > nvhttp::make_launch_session | ( | bool | host_audio, |
| bool | input_only, | ||
| const args_t & | args, | ||
| const crypto::named_cert_t * | named_cert_p ) |
Definition at line 511 of file nvhttp.cpp.
| void nvhttp::not_found | ( | std::shared_ptr< typename SimpleWeb::ServerBase< T >::Response > | response, |
| std::shared_ptr< typename SimpleWeb::ServerBase< T >::Request > | request ) |
Definition at line 856 of file nvhttp.cpp.
| void nvhttp::pair | ( | std::shared_ptr< typename SimpleWeb::ServerBase< T >::Response > | response, |
| std::shared_ptr< typename SimpleWeb::ServerBase< T >::Request > | request ) |
Definition at line 870 of file nvhttp.cpp.
| std::optional< std::string > nvhttp::pending_pair_client | ( | ) |
The client whose pairing request is waiting for a PIN, if any.
Empty whenever nothing is pending. The window is narrow on purpose: it opens when a client's request parks itself waiting for four digits and closes the moment any are submitted, so a caller polling this is asking "does somebody need to type a PIN right now", not "has anyone ever tried to pair".
Definition at line 1018 of file nvhttp.cpp.
| bool nvhttp::pin | ( | std::string | pin, |
| std::string | name ) |
Compare the user supplied pin to the Moonlight pin.
| pin | The user supplied pin. |
| name | The user supplied name. |
Examples
Definition at line 1026 of file nvhttp.cpp.
| void nvhttp::print_req | ( | std::shared_ptr< typename SimpleWeb::ServerBase< T >::Request > | request | ) |
Definition at line 836 of file nvhttp.cpp.
| void nvhttp::remove_session | ( | const pair_session_t & | sess | ) |
| std::string nvhttp::request_otp | ( | const std::string & | passphrase, |
| const std::string & | deviceName ) |
Definition at line 2384 of file nvhttp.cpp.
| void nvhttp::resume | ( | bool & | host_audio, |
| resp_https_t | response, | ||
| req_https_t | request ) |
Definition at line 1818 of file nvhttp.cpp.
| void nvhttp::save_state | ( | ) |
Definition at line 330 of file nvhttp.cpp.
| void nvhttp::serverchallengeresp | ( | pair_session_t & | sess, |
| boost::property_tree::ptree & | tree, | ||
| const std::string & | encrypted_response ) |
Pair, phase 3.
Moonlight will send back a serverchallengeresp: an AES encrypted client hash, we have to send back the pairingsecret: using our private key we have to sign the certificate_signature + server_secret (generated in phase 2)
| void nvhttp::serverchallengeresp | ( | pair_session_t & | sess, |
| pt::ptree & | tree, | ||
| const std::string & | encrypted_response ) |
Definition at line 719 of file nvhttp.cpp.
| void nvhttp::serverinfo | ( | std::shared_ptr< typename SimpleWeb::ServerBase< T >::Response > | response, |
| std::shared_ptr< typename SimpleWeb::ServerBase< T >::Request > | request ) |
Definition at line 1091 of file nvhttp.cpp.
| void nvhttp::set_pending_pair | ( | const std::string & | unique_id, |
| const std::string & | name ) |
Definition at line 256 of file nvhttp.cpp.
| void nvhttp::setClipboard | ( | resp_https_t | response, |
| req_https_t | request ) |
Definition at line 2145 of file nvhttp.cpp.
| void nvhttp::setup | ( | const std::string & | pkey, |
| const std::string & | cert ) |
| void nvhttp::start | ( | ) |
| void nvhttp::stop_session | ( | stream::session_t & | session, |
| bool | graceful ) |
Stops a session.
| session | The session | |
| [in] | graceful | Whether to stop gracefully |
Definition at line 2406 of file nvhttp.cpp.
| void nvhttp::store_hestia_session_prepare | ( | const std::string & | client_uuid, |
| hestia_session_prepare_t | prepare ) |
Store preparation hints for a paired client's next GameStream launch.
Definition at line 2211 of file nvhttp.cpp.
| std::optional< hestia_session_prepare_t > nvhttp::take_hestia_session_prepare | ( | const std::string & | client_uuid | ) |
Consume unexpired preparation hints for a paired client's next launch.
Definition at line 2219 of file nvhttp.cpp.
| bool nvhttp::unpair_client | ( | std::string_view | uuid | ) |
Remove single client.
| uuid | The UUID of the client to remove. |
Examples
Definition at line 2470 of file nvhttp.cpp.
| bool nvhttp::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.
| [in] | uuid | The uuid string |
| [in] | name | New name |
| [in] | do_cmds | The do commands |
| [in] | undo_cmds | The undo commands |
| [in] | newPerm | New permission |
| [in] | enable_legacy_ordering | Enable legacy ordering |
| [in] | allow_client_commands | Allow client commands |
| [in] | always_use_virtual_display | Always use virtual display |
Definition at line 2436 of file nvhttp.cpp.
| void nvhttp::update_session_info | ( | stream::session_t & | session, |
| const std::string & | name, | ||
| const crypto::PERM | newPerm ) |
Update device info associated to the session.
| session | The session | |
| [in] | name | New name |
| [in] | newPerm | New permission |
Definition at line 2423 of file nvhttp.cpp.
| bool nvhttp::verify_paired_client_certificate | ( | X509 * | certificate, |
| crypto::p_named_cert_t & | named_cert_out ) |
Verify a TLS client certificate against the paired-client store.
| certificate | The peer certificate obtained from a TLS connection. |
| named_cert_out | The paired-client record when verification succeeds. |
Definition at line 2207 of file nvhttp.cpp.
| crypto::cert_chain_t nvhttp::cert_chain |
Definition at line 136 of file nvhttp.cpp.
| client_t nvhttp::client_root |
Definition at line 228 of file nvhttp.cpp.
|
constexpr |
| std::unordered_map<std::string, pair_session_t> nvhttp::map_id_sess |
Definition at line 224 of file nvhttp.cpp.
| std::recursive_mutex nvhttp::pair_session_mutex |
Definition at line 227 of file nvhttp.cpp.
| std::mutex nvhttp::pending_pair_mutex |
The clients whose pairing requests are waiting for a PIN, if any.
Keyed by the client's uniqueID rather than a single global flag: a pairing session being removed - a failure, a timeout, the success path itself - must clear exactly the client it belonged to, or one client's finished pairing erases another's still-waiting one.
Tracked beside map_id_sess rather than read out of it: the map lives on the nvhttp threads with no lock of its own, and this is read from the web server's threads. A separate guarded copy is the difference between one more unsynchronised reader and none.
"Waiting for a PIN" is narrower than "has a pair session": it begins when the request parks itself on async_insert_pin.response and ends the moment a PIN is submitted, because that is exactly the window in which somebody has to go and type four digits.
Definition at line 253 of file nvhttp.cpp.
| std::unordered_map<std::string, std::string> nvhttp::pending_pairs |
Definition at line 254 of file nvhttp.cpp.
|
constexpr |
|
constexpr |
| std::atomic<uint32_t> nvhttp::session_id_counter |
Definition at line 229 of file nvhttp.cpp.