Sunshine0.0.5917
Sunshine 0.0.5917
Self-hosted game stream host for Moonlight.
Loading...
Searching...
No Matches
nvhttp Namespace Reference

Contains all the functions and variables related to the nvhttp (GameStream) server. More...

Classes

struct  client_t
 Persisted pairing data for one Moonlight client. More...
struct  conf_intern_t
 Internal HTTPS credential paths for the configuration server. More...
struct  named_cert_t
 Certificate entry associated with a client name and UUID. More...
struct  pair_session_t
 Pairing handshake state exchanged with a Moonlight client. More...
struct  pairing_completion_t
 Shared result used to return the completed pairing outcome to a PIN submitter. More...
struct  pending_pairing_t
 Operator-visible context for a pairing request awaiting PIN approval. More...
class  SunshineHTTPS
 Simple-Web-Server HTTPS backend configured for Sunshine certificate handling. More...
class  SunshineHTTPSServer
 HTTPS server backend that adds Sunshine's client-certificate verification. More...
struct  tunnel
struct  tunnel< SimpleWeb::HTTP >
 Plain HTTP server wrapper used for non-TLS endpoints. More...
struct  tunnel< SunshineHTTPS >
 HTTPS tunnel session used for encrypted client requests. More...

Typedefs

using args_t = SimpleWeb::CaseInsensitiveMultimap
 Case-insensitive map used for HTTP headers and query parameters.
using http_server_t = SimpleWeb::Server<SimpleWeb::HTTP>
 Plain HTTP server type used for GameStream endpoints without TLS.
using https_server_t = SunshineHTTPSServer
 HTTPS server type used for GameStream endpoints requiring TLS.
using req_http_t = std::shared_ptr<typename SimpleWeb::ServerBase<SimpleWeb::HTTP>::Request>
 Shared HTTP request object received by redirect and discovery handlers.
using req_https_t = std::shared_ptr<typename SimpleWeb::ServerBase<SunshineHTTPS>::Request>
 Shared HTTPS request object received by GameStream handlers.
using resp_http_t = std::shared_ptr<typename SimpleWeb::ServerBase<SimpleWeb::HTTP>::Response>
 Shared HTTP response object passed to redirect and discovery handlers.
using resp_https_t = std::shared_ptr<typename SimpleWeb::ServerBase<SunshineHTTPS>::Response>
 Shared HTTPS response object passed to GameStream handlers.

Enumerations

enum class  op_e { ADD , REMOVE }
 Certificate operations supported by the pairing API. More...
enum class  PAIR_PHASE {
  NONE , GETSERVERCERT , CLIENTCHALLENGE , SERVERCHALLENGERESP ,
  CLIENTPAIRINGSECRET
}
 Enumerates supported pAIR PHASE options. More...
enum class  pair_session_insert_e { ADDED , ALREADY_EXISTS , FULL }
 Result of inserting a new pairing session into bounded pending storage. More...

Functions

std::string add_authorized_client (const std::string &name, std::string &&cert)
 Add authorized client data.
void appasset (resp_https_t response, req_https_t request)
 Return an application asset requested by the client.
void applist (resp_https_t response, req_https_t request)
 Build the GameStream application list response.
void cancel (resp_https_t response, req_https_t request)
 Check whether cel.
bool cancel_pairing (std::string_view pairing_id)
 Cancel a pairing request that is waiting for operator approval.
std::string canonical_certificate_pem (const std::string_view cert_pem)
 Convert a PEM certificate to Sunshine's canonical OpenSSL serialization.
std::mutex & client_auth_mutex ()
 Get the mutex protecting paired-client authorization state.
void clientchallenge (pair_session_t &sess, boost::property_tree::ptree &tree, const std::string &challenge)
 Pair, phase 2.
void clientchallenge (pair_session_t &sess, pt::ptree &tree, const std::string &challenge)
 Handle the client-challenge phase of GameStream pairing.
void clientpairingsecret (pair_session_t &sess, boost::property_tree::ptree &tree, const std::string &client_pairing_secret)
 Pair, phase 4 (final).
void clientpairingsecret (pair_session_t &sess, pt::ptree &tree, const std::string &client_pairing_secret)
 Handle the client pairing-secret phase of GameStream pairing.
void complete_pairing (pair_session_t &sess, const bool success)
 Publish the final result of a pairing handshake.
void erase_all_clients ()
 Remove all paired clients.
bool evict_abandoned_pair_session (const std::string &unique_id)
 Evict an abandoned in-progress pairing session for a client.
void expire_pair_sessions (std::chrono::steady_clock::time_point now=std::chrono::steady_clock::now())
 Remove pairing sessions whose completion deadline has passed.
void expire_pair_sessions_unlocked (const std::chrono::steady_clock::time_point now)
 Expire stale pairing sessions while the session mutex is held.
void fail_pair (pair_session_t &sess, pt::ptree &tree, const std::string status_msg)
 Return the GameStream pairing failure response.
nlohmann::json get_all_clients ()
 Get all paired clients.
std::string get_arg (const args_t &args, const char *name, const char *default_value=nullptr)
 Read a named query argument from the HTTP request map.
std::string get_cert_by_uuid (const std::string_view uuid)
 Get cert by UUID.
std::pair< bool, std::string > get_client_status (const std::string_view cert_pem)
 Check whether a paired client certificate is allowed to connect and retrieve its friendly name.
uint32_t get_codec_mode_flags ()
 Get codec mode flags.
std::vector< pending_pairing_t > get_pending_pairings ()
 List pairing requests that are waiting for operator PIN approval.
void getservercert (pair_session_t &sess, boost::property_tree::ptree &tree, const std::string &pin)
 Pair, phase 1.
void getservercert (pair_session_t &sess, pt::ptree &tree, const std::string &pin)
 Return the server certificate text for pairing responses.
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.
bool is_client_enabled (const X509 *certificate)
 Check whether a certificate exactly matches an enabled paired-client record.
bool is_valid_pairing_id (std::string_view pairing_id)
 Validate an operator approval identifier received from the REST API.
bool is_valid_pairing_name (std::string_view name)
 Validate an operator-supplied paired-client name received from the REST API.
bool is_valid_pairing_pin (std::string_view pin)
 Validate a Moonlight pairing PIN received from the REST API.
void launch (bool &host_audio, resp_https_t response, req_https_t request)
 Launch the requested application for a GameStream session.
void load_state ()
 Load state from its backing store.
std::shared_ptr< rtsp_stream::launch_session_t > make_launch_session (bool host_audio, const args_t &args)
 Create launch session.
std::mutex & map_id_sess_mutex ()
 Get the mutex protecting pairing-session state.
template<class T>
void not_found (std::shared_ptr< typename SimpleWeb::ServerBase< T >::Response > response, std::shared_ptr< typename SimpleWeb::ServerBase< T >::Request > request)
 Return a GameStream HTTP not-found response.
template<class T>
void pair (std::shared_ptr< typename SimpleWeb::ServerBase< T >::Response > response, std::shared_ptr< typename SimpleWeb::ServerBase< T >::Request > request)
 Dispatch the top-level GameStream pairing request by phase.
bool pin (std::string_view pairing_id, std::string pin, std::string name)
 Apply the user supplied PIN to the explicitly selected pairing request.
template<class T>
void print_req (std::shared_ptr< typename SimpleWeb::ServerBase< T >::Request > request)
 Write req details to the log.
void rebuild_client_cert_chain ()
 Rebuild the GameStream trust stores from enabled paired-client records.
void remove_session (const pair_session_t &sess)
 removes the temporary pairing session
void resume (bool &host_audio, resp_https_t response, req_https_t request)
 Resume an existing GameStream session.
void save_state ()
 Persist the current state to its backing store.
void serverchallengeresp (pair_session_t &sess, boost::property_tree::ptree &tree, const std::string &encrypted_response)
 Pair, phase 3.
void serverchallengeresp (pair_session_t &sess, pt::ptree &tree, const std::string &encrypted_response)
 Handle the server-challenge response phase of GameStream pairing.
template<class T>
void serverinfo (std::shared_ptr< typename SimpleWeb::ServerBase< T >::Response > response, std::shared_ptr< typename SimpleWeb::ServerBase< T >::Request > request)
 Build the GameStream server-info response.
bool set_client_enabled (std::string_view uuid, bool enabled)
 Enable or disable a client.
void setup (const std::string &pkey, const std::string &cert)
 Setup the nvhttp server.
void start ()
 Start the nvhttp server.
template<class T>
bool start_pairing_session (const std::shared_ptr< typename SimpleWeb::ServerBase< T >::Response > &response, const std::shared_ptr< typename SimpleWeb::ServerBase< T >::Request > &request, const args_t &args, pt::ptree &tree, const std::string &unique_id)
 Start a GameStream pairing session for a getservercert request.
bool unpair_client (std::string_view uuid)
 Remove single client.
const char * verify_client_certificate (X509 *certificate)
 Verify a client certificate against the exact enabled paired identity.
bool write_pairing_response (pair_session_t &sess, const pt::ptree &tree)
 Write a completed response to the client waiting for PIN approval.

Variables

crypto::cert_chain_t cert_chain
 Enabled paired-client certificates accepted by Sunshine's GameStream HTTPS server.
client_t client_root
 In-memory representation of the paired-client database.
conf_intern_t conf_intern
 TLS credential paths loaded from Sunshine's runtime configuration.
constexpr auto GFE_VERSION = "3.23.0.74"
 The GFE version we are replicating.
std::string last_verified_client_cert
 Last client certificate accepted by the TLS verify callback. // NOSONAR(cpp:S5421): intentionally mutable global.
std::string last_verified_client_name
 Friendly name of last client certificate accepted by the TLS verify callback. // NOSONAR(cpp:S5421): intentionally mutable global.
std::unordered_map< std::string, pair_session_t, util::transparent_string_hash, std::equal_to<> > map_id_sess
 Pairing sessions keyed by temporary unique ID.
constexpr std::size_t MAX_PAIRING_CLIENT_NAME_SIZE = 128
 Maximum number of bytes accepted for an operator-supplied paired-client name.
constexpr std::size_t MAX_PENDING_PAIRING_SESSIONS = 32
 Maximum number of pairing sessions retained at one time.
constexpr std::size_t PAIRING_ID_SIZE = 32
 Number of hexadecimal characters in an operator approval identifier.
constexpr auto PAIRING_SESSION_TIMEOUT = std::chrono::minutes {5}
 Lifetime of an incomplete pairing session.
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.
std::atomic< uint32_t > session_id_counter
 Monotonic counter used to allocate GameStream session IDs.
constexpr auto VERSION = "7.1.431.-1"
 The protocol version.

Detailed Description

Contains all the functions and variables related to the nvhttp (GameStream) server.

Enumeration Type Documentation

◆ op_e

enum class nvhttp::op_e
strong

Certificate operations supported by the pairing API.

Enumerator
ADD 

Add certificate.

REMOVE 

Remove certificate.

◆ PAIR_PHASE

enum class nvhttp::PAIR_PHASE
strong

Enumerates supported pAIR PHASE options.

Enumerator
NONE 

Sunshine is not in a pairing phase.

GETSERVERCERT 

Sunshine is in the get server certificate phase.

CLIENTCHALLENGE 

Sunshine is in the client challenge phase.

SERVERCHALLENGERESP 

Sunshine is in the server challenge response phase.

CLIENTPAIRINGSECRET 

Sunshine is in the client pairing secret phase.

◆ pair_session_insert_e

enum class nvhttp::pair_session_insert_e
strong

Result of inserting a new pairing session into bounded pending storage.

Enumerator
ADDED 

The session was inserted successfully.

ALREADY_EXISTS 

A session with the same client unique ID is already active.

FULL 

The bounded session store has reached its limit.

Function Documentation

◆ add_authorized_client()

std::string nvhttp::add_authorized_client ( const std::string & name,
std::string && cert )

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.

Parameters
nameHuman-readable name to assign.
certCertificate data or object used by the operation.
Returns
Persistent UUID for the added client, or an empty string when the certificate is invalid.

◆ appasset()

void nvhttp::appasset ( resp_https_t response,
req_https_t request )

Return an application asset requested by the client.

Parameters
responseHTTP response object to populate.
requestHTTP request data from the client.

◆ applist()

void nvhttp::applist ( resp_https_t response,
req_https_t request )

Build the GameStream application list response.

Parameters
responseHTTP response object to populate.
requestHTTP request data from the client.

◆ cancel()

void nvhttp::cancel ( resp_https_t response,
req_https_t request )

Check whether cel.

Parameters
responseHTTP response object to populate.
requestHTTP request data from the client.

◆ cancel_pairing()

bool nvhttp::cancel_pairing ( std::string_view pairing_id)

Cancel a pairing request that is waiting for operator approval.

Parameters
pairing_idUnguessable approval identifier returned by get_pending_pairings.
Returns
true if the pending request was found and cancelled.

◆ canonical_certificate_pem()

std::string nvhttp::canonical_certificate_pem ( const std::string_view cert_pem)

Convert a PEM certificate to Sunshine's canonical OpenSSL serialization.

Parameters
cert_pemPEM-encoded certificate to canonicalize.
Returns
Canonical PEM text, or an empty string when the certificate is invalid.

◆ client_auth_mutex()

std::mutex & nvhttp::client_auth_mutex ( )

Get the mutex protecting paired-client authorization state.

Returns
Mutex serializing paired-client state and certificate authorization changes.

◆ clientchallenge() [1/2]

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:

  • Decrypted challenge
  • Server certificate signature
  • Server secret: a randomly generated secret

The hash + server_challenge will then be AES encrypted and sent as the challengeresponse in the returned XML

Parameters
sessPairing session that owns the request state.
treeXML property tree used for the response body.
challengeClient challenge bytes from the pairing request.

◆ clientchallenge() [2/2]

void nvhttp::clientchallenge ( pair_session_t & sess,
pt::ptree & tree,
const std::string & challenge )

Handle the client-challenge phase of GameStream pairing.

Parameters
sessPairing session that owns the request state.
treeXML property tree used for the response body.
challengeClient challenge bytes from the pairing request.

◆ clientpairingsecret() [1/2]

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:

  • The original server_challenge
  • The signature of the X509 client_cert
  • The unencrypted client_pairing_secret We'll check that SHA256(server_challenge + client_public_cert_signature + client_secret) == client_hash

Then using the client certificate public key we should be able to verify that the client secret has been signed by Moonlight

Parameters
sessPairing session that owns the request state.
treeXML property tree used for the response body.
client_pairing_secretClient pairing secret.

◆ clientpairingsecret() [2/2]

void nvhttp::clientpairingsecret ( pair_session_t & sess,
pt::ptree & tree,
const std::string & client_pairing_secret )

Handle the client pairing-secret phase of GameStream pairing.

Parameters
sessPairing session that owns the request state.
treeXML property tree used for the response body.
client_pairing_secretClient pairing secret.

◆ complete_pairing()

void nvhttp::complete_pairing ( pair_session_t & sess,
const bool success )

Publish the final result of a pairing handshake.

Parameters
sessPairing session whose waiter should be notified.
successWhether the client completed the authenticated handshake.

◆ erase_all_clients()

void nvhttp::erase_all_clients ( )

Remove all paired clients.

Examples

void erase_all_clients()
Remove all paired clients.
Definition nvhttp.cpp:1792

◆ evict_abandoned_pair_session()

bool nvhttp::evict_abandoned_pair_session ( const std::string & unique_id)

Evict an abandoned in-progress pairing session for a client.

A fresh getservercert request means the client abandoned its previous handshake and started over: the phase machine never accepts getservercert twice for one session, so the old handshake cannot resume. Evicting it lets the retry proceed instead of failing with 409 until the session expires. Sessions still waiting for operator PIN approval (last_phase == NONE) are left untouched, so a pending approval cannot be displaced by a stray getservercert. Eviction completes the old session as failed, waking any PIN submitter waiting on it, and orphans no live HTTP response: the response is consumed when PIN approval advances the session past the certificate phase.

Parameters
unique_idClient-provided pairing-session identifier.
Returns
true when an in-progress session was evicted.

◆ expire_pair_sessions()

void nvhttp::expire_pair_sessions ( std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now())

Remove pairing sessions whose completion deadline has passed.

Parameters
nowMonotonic time used to evaluate session deadlines.

◆ expire_pair_sessions_unlocked()

void nvhttp::expire_pair_sessions_unlocked ( const std::chrono::steady_clock::time_point now)

Expire stale pairing sessions while the session mutex is held.

Parameters
nowMonotonic time used to evaluate session deadlines.

◆ fail_pair()

void nvhttp::fail_pair ( pair_session_t & sess,
pt::ptree & tree,
const std::string status_msg )

Return the GameStream pairing failure response.

Parameters
sessPairing session that owns the request state.
treeXML property tree used for the response body.
status_msgStatus msg.

◆ get_all_clients()

nlohmann::json nvhttp::get_all_clients ( )

Get all paired clients.

Returns
The list of all paired clients.

Examples

nlohmann::json clients = nvhttp::get_all_clients();
nlohmann::json get_all_clients()
Get all paired clients.
Definition nvhttp.cpp:1318

◆ get_arg()

std::string nvhttp::get_arg ( const args_t & args,
const char * name,
const char * default_value = nullptr )

Read a named query argument from the HTTP request map.

Parameters
argsParsed query-string argument map.
nameQuery parameter name to read.
default_valueValue returned when the parameter is absent.
Returns
Query parameter value, default value, or an empty string.

◆ get_cert_by_uuid()

std::string nvhttp::get_cert_by_uuid ( std::string_view uuid)

Get cert by UUID.

Parameters
uuidClient UUID being looked up or removed.
Returns
PEM certificate for the paired client, or an empty string when unknown.

◆ get_client_status()

std::pair< bool, std::string > nvhttp::get_client_status ( const std::string_view cert_pem)

Check whether a paired client certificate is allowed to connect and retrieve its friendly name.

Check whether a paired client certificate is allowed to connect and return its friendly name.

Parameters
cert_pemPEM-encoded client certificate to look up.
Returns
Pair of (bool enabled, string name) where "enabled" is True when the client certificate belongs to an enabled device and "name" is the friendly client name set during pairing.

◆ get_codec_mode_flags()

uint32_t nvhttp::get_codec_mode_flags ( )

Get codec mode flags.

Returns
Moonlight codec capability bitmask for the currently probed encoders.

◆ get_pending_pairings()

std::vector< pending_pairing_t > nvhttp::get_pending_pairings ( )

List pairing requests that are waiting for operator PIN approval.

Returns
Pending requests ordered from oldest to newest.

◆ getservercert() [1/2]

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.

Parameters
sessPairing session that owns the request state.
treeXML property tree used for the response body.
pinPIN supplied by the client during pairing.

◆ getservercert() [2/2]

void nvhttp::getservercert ( pair_session_t & sess,
pt::ptree & tree,
const std::string & pin )

Return the server certificate text for pairing responses.

Parameters
sessPairing session that owns the request state.
treeXML property tree used for the response body.
pinPIN supplied by the client during pairing.

◆ insert_pair_session()

pair_session_insert_e nvhttp::insert_pair_session ( pair_session_t sess,
std::string & pairing_id )

Insert a newly created pairing session into bounded pending storage.

Parameters
sessPairing session to insert.
pairing_idReceives the unguessable approval identifier on success.
Returns
Status describing whether the session was inserted.

◆ is_client_enabled()

bool nvhttp::is_client_enabled ( const X509 * certificate)

Check whether a certificate exactly matches an enabled paired-client record.

Parameters
certificateParsed client certificate to compare by canonical X.509 identity.
Returns
true only when exactly one matching paired-client record is enabled.
Note
The caller must hold client_auth_mutex().

◆ is_valid_pairing_id()

bool nvhttp::is_valid_pairing_id ( std::string_view pairing_id)

Validate an operator approval identifier received from the REST API.

Parameters
pairing_idApproval identifier to validate.
Returns
true when the value has the exact hexadecimal format Sunshine generates.

◆ is_valid_pairing_name()

bool nvhttp::is_valid_pairing_name ( std::string_view name)

Validate an operator-supplied paired-client name received from the REST API.

Parameters
nameClient name to validate.
Returns
true when the name is non-empty and within the storage limit.

◆ is_valid_pairing_pin()

bool nvhttp::is_valid_pairing_pin ( std::string_view pin)

Validate a Moonlight pairing PIN received from the REST API.

Parameters
pinPIN to validate.
Returns
true when the value contains exactly four ASCII digits.

◆ launch()

void nvhttp::launch ( bool & host_audio,
resp_https_t response,
req_https_t request )

Launch the requested application for a GameStream session.

Parameters
host_audioHost audio.
responseHTTP response object to populate.
requestHTTP request data from the client.

◆ make_launch_session()

std::shared_ptr< rtsp_stream::launch_session_t > nvhttp::make_launch_session ( bool host_audio,
const args_t & args )

Create launch session.

Parameters
host_audioHost audio.
argsArguments forwarded to the callable or parser.
Returns
Constructed launch session object.

◆ map_id_sess_mutex()

std::mutex & nvhttp::map_id_sess_mutex ( )

Get the mutex protecting pairing-session state.

Returns
Mutex serializing pairing-session storage and lifecycle transitions.

◆ not_found()

template<class T>
void nvhttp::not_found ( std::shared_ptr< typename SimpleWeb::ServerBase< T >::Response > response,
std::shared_ptr< typename SimpleWeb::ServerBase< T >::Request > request )

Return a GameStream HTTP not-found response.

Parameters
responseHTTP response object to populate.
requestHTTP request data from the client.

◆ pair()

template<class T>
void nvhttp::pair ( std::shared_ptr< typename SimpleWeb::ServerBase< T >::Response > response,
std::shared_ptr< typename SimpleWeb::ServerBase< T >::Request > request )

Dispatch the top-level GameStream pairing request by phase.

Parameters
responseHTTP response object to populate.
requestHTTP request data from the client.

◆ pin()

bool nvhttp::pin ( std::string_view pairing_id,
std::string pin,
std::string name )

Apply the user supplied PIN to the explicitly selected pairing request.

Parameters
pairing_idUnguessable identifier of the pairing request to approve.
pinThe user supplied pin.
nameThe user supplied name.
Returns
true if Moonlight proves the PIN by completing the handshake, false otherwise.
Note
The handshake wait uses the configured ping_timeout and never exceeds the pairing session deadline.

Examples

bool pin_status = nvhttp::pin("0123456789abcdef0123456789abcdef", "1234", "laptop");
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

◆ print_req()

template<class T>
void nvhttp::print_req ( std::shared_ptr< typename SimpleWeb::ServerBase< T >::Request > request)

Write req details to the log.

Parameters
requestHTTP request data from the client.

◆ rebuild_client_cert_chain()

void nvhttp::rebuild_client_cert_chain ( )

Rebuild the GameStream trust stores from enabled paired-client records.

Note
The caller must hold client_auth_mutex().

◆ remove_session()

void nvhttp::remove_session ( const pair_session_t & sess)

removes the temporary pairing session

Parameters
sess

◆ resume()

void nvhttp::resume ( bool & host_audio,
resp_https_t response,
req_https_t request )

Resume an existing GameStream session.

Parameters
host_audioHost audio.
responseHTTP response object to populate.
requestHTTP request data from the client.

◆ serverchallengeresp() [1/2]

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)

Parameters
sessPairing session that owns the request state.
treeXML property tree used for the response body.
encrypted_responseEncrypted response.

◆ serverchallengeresp() [2/2]

void nvhttp::serverchallengeresp ( pair_session_t & sess,
pt::ptree & tree,
const std::string & encrypted_response )

Handle the server-challenge response phase of GameStream pairing.

Parameters
sessPairing session that owns the request state.
treeXML property tree used for the response body.
encrypted_responseEncrypted response.

◆ serverinfo()

template<class T>
void nvhttp::serverinfo ( std::shared_ptr< typename SimpleWeb::ServerBase< T >::Response > response,
std::shared_ptr< typename SimpleWeb::ServerBase< T >::Request > request )

Build the GameStream server-info response.

Parameters
responseHTTP response object to populate.
requestHTTP request data from the client.

◆ set_client_enabled()

bool nvhttp::set_client_enabled ( std::string_view uuid,
bool enabled )

Enable or disable a client.

Parameters
uuidThe UUID of the client.
enabledWhether the client should be enabled.
Returns
true if the client was found and updated.

◆ setup()

void nvhttp::setup ( const std::string & pkey,
const std::string & cert )

Setup the nvhttp server.

Parameters
pkey
cert

◆ start()

void nvhttp::start ( )

Start the nvhttp server.

Examples

void start()
Start the nvhttp server.
Definition nvhttp.cpp:1647

◆ start_pairing_session()

template<class T>
bool nvhttp::start_pairing_session ( const std::shared_ptr< typename SimpleWeb::ServerBase< T >::Response > & response,
const std::shared_ptr< typename SimpleWeb::ServerBase< T >::Request > & request,
const args_t & args,
pt::ptree & tree,
const std::string & unique_id )

Start a GameStream pairing session for a getservercert request.

Template Parameters
THTTP server transport type.
Parameters
responseHTTP response retained while Web UI PIN approval is pending.
requestHTTP request containing the client pairing parameters.
argsParsed request query parameters.
treeXML property tree used for immediate responses.
unique_idClient-provided pairing-session identifier.
Returns
true when the response remains pending for Web UI PIN approval.

◆ unpair_client()

bool nvhttp::unpair_client ( std::string_view uuid)

Remove single client.

Parameters
uuidThe UUID of the client to remove.

Examples

nvhttp::unpair_client("4D7BB2DD-5704-A405-B41C-891A022932E1");
bool unpair_client(const std::string_view uuid)
Remove single client.
Definition nvhttp.cpp:1799
Returns
True when the client entry was found and removed.

◆ verify_client_certificate()

const char * nvhttp::verify_client_certificate ( X509 * certificate)

Verify a client certificate against the exact enabled paired identity.

Parameters
certificateParsed client certificate presented during the TLS handshake.
Returns
nullptr when authorized, otherwise a non-sensitive error string.
Note
The caller must hold client_auth_mutex().

◆ write_pairing_response()

bool nvhttp::write_pairing_response ( pair_session_t & sess,
const pt::ptree & tree )

Write a completed response to the client waiting for PIN approval.

Parameters
sessPairing session that owns the waiting response.
treeXML response body to write.
Returns
true when a live response was available.

Variable Documentation

◆ VERSION

auto nvhttp::VERSION = "7.1.431.-1"
constexpr

The protocol version.

The version of the GameStream protocol we are mocking.

Note
The negative 4th number indicates to Moonlight that this is Sunshine.