Hermes 0.7.0
Linux game streaming host
Loading...
Searching...
No Matches
nvhttp.h
Go to the documentation of this file.
1
5// macros
6#pragma once
7
8// standard includes
9#include <string>
10#include <chrono>
11#include <list>
12#include <optional>
13
14// lib includes
15#include <boost/property_tree/ptree.hpp>
16#include <nlohmann/json.hpp>
17#include <Simple-Web-Server/server_https.hpp>
18
19// local includes
20#include "crypto.h"
21#include "rtsp.h"
22#include "thread_safe.h"
23
24using namespace std::chrono_literals;
25
29namespace nvhttp {
30
31 using args_t = SimpleWeb::CaseInsensitiveMultimap;
32 using cmd_list_t = std::list<crypto::command_entry_t>;
33
39 constexpr auto VERSION = "7.1.431.-1";
40
44 constexpr auto GFE_VERSION = "3.23.0.74";
45
49 constexpr auto PORT_HTTP = 0;
50
54 constexpr auto PORT_HTTPS = -5;
55
56 constexpr auto OTP_EXPIRE_DURATION = 180s;
57
64 void start();
65
72 uint32_t launch_count();
73
74 std::string
75 get_arg(const args_t &args, const char *name, const char *default_value = nullptr);
76
77 // Helper function to extract command entries
78 cmd_list_t
79 extract_command_entries(const nlohmann::json& j, const std::string& key);
80
81 std::shared_ptr<rtsp_stream::launch_session_t>
82 make_launch_session(bool host_audio, bool input_only, const args_t &args, const crypto::named_cert_t* named_cert_p);
83
89 void setup(const std::string &pkey, const std::string &cert);
90
97 bool verify_paired_client_certificate(X509 *certificate, crypto::p_named_cert_t &named_cert_out);
98
100 bool virtual_display = false;
101 int width = 0;
102 int height = 0;
103 int fps = 0;
104 bool hdr = false;
105 uint32_t scale_factor = 100;
106 std::string launch_mode = "normal";
107 };
108
110 void store_hestia_session_prepare(const std::string &client_uuid, hestia_session_prepare_t prepare);
111
113 std::optional<hestia_session_prepare_t> take_hestia_session_prepare(const std::string &client_uuid);
114
122 nlohmann::json describe_applied_settings(const std::string &app_id, bool virtual_display, int scale_factor);
123
125 void clear_hestia_session_prepare(const std::string &client_uuid);
126
127 class SunshineHTTPS: public SimpleWeb::HTTPS {
128 public:
129 SunshineHTTPS(boost::asio::io_context &io_context, boost::asio::ssl::context &ctx):
130 SimpleWeb::HTTPS(io_context, ctx) {
131 }
132
133 virtual ~SunshineHTTPS() {
134 // Gracefully shutdown the TLS connection
135 SimpleWeb::error_code ec;
136 shutdown(ec);
137 }
138 };
139
147
149 struct {
150 std::string uniqueID = {};
151 std::string cert = {};
152 std::string name = {};
153 } client;
154
155 std::unique_ptr<crypto::aes_t> cipher_key = {};
156 std::vector<uint8_t> clienthash = {};
157
158 std::string serversecret = {};
159 std::string serverchallenge = {};
160
161 struct {
163 std::shared_ptr<typename SimpleWeb::ServerBase<SimpleWeb::HTTP>::Response>,
164 std::shared_ptr<typename SimpleWeb::ServerBase<SunshineHTTPS>::Response>>
165 response;
166 std::string salt = {};
167 } async_insert_pin;
168
173 };
174
179 void remove_session(const pair_session_t &sess);
180
183
185 bool cancel_pending_pairing(const std::string &unique_id);
186
187
198 void getservercert(pair_session_t &sess, boost::property_tree::ptree &tree, const std::string &pin);
199
212 void clientchallenge(pair_session_t &sess, boost::property_tree::ptree &tree, const std::string &challenge);
213
221 void serverchallengeresp(pair_session_t &sess, boost::property_tree::ptree &tree, const std::string &encrypted_response);
222
237 void clientpairingsecret(pair_session_t &sess, boost::property_tree::ptree &tree, const std::string &client_pairing_secret);
238
248 std::optional<std::string> pending_pair_client();
249
259 bool pin(std::string pin, std::string name);
260
261 std::string request_otp(const std::string& passphrase, const std::string& deviceName);
262
270 bool unpair_client(std::string_view uuid);
271
279 nlohmann::json get_all_clients();
280
287 void erase_all_clients();
288
295 void stop_session(stream::session_t& session, bool graceful);
296
303 bool find_and_stop_session(const std::string& uuid, bool graceful);
304
312 void update_session_info(stream::session_t& session, const std::string& name, const crypto::PERM newPerm);
313
321 bool find_and_udpate_session_info(const std::string& uuid, const std::string& name, const crypto::PERM newPerm);
322
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,
343 const crypto::PERM newPerm,
344 const bool enable_legacy_ordering,
345 const bool allow_client_commands,
346 const bool always_use_virtual_display
347 );
348} // namespace nvhttp
Declarations for cryptography functions.
PERM
The permissions of a client.
Definition crypto.h:45
Functions for handling command line arguments.
Contains all the functions and variables related to the nvhttp (GameStream) server.
Definition nvhttp.cpp:47
constexpr auto GFE_VERSION
The GFE version we are replicating.
Definition nvhttp.h:44
void update_session_info(stream::session_t &session, const std::string &name, const crypto::PERM newPerm)
Update device info associated to the session.
Definition nvhttp.cpp:2423
std::optional< hestia_session_prepare_t > take_hestia_session_prepare(const std::string &client_uuid)
Definition nvhttp.cpp:2219
bool find_and_udpate_session_info(const std::string &uuid, const std::string &name, const crypto::PERM newPerm)
Finds and udpate session information.
Definition nvhttp.cpp:2427
PAIR_PHASE
Definition nvhttp.h:140
@ SERVERCHALLENGERESP
Sunshine is in the server challenge response phase.
Definition nvhttp.h:144
@ CLIENTCHALLENGE
Sunshine is in the client challenge phase.
Definition nvhttp.h:143
@ NONE
Sunshine is not in a pairing phase.
Definition nvhttp.h:141
@ CLIENTPAIRINGSECRET
Sunshine is in the client pairing secret phase.
Definition nvhttp.h:145
@ GETSERVERCERT
Sunshine is in the get server certificate phase.
Definition nvhttp.h:142
bool cancel_pending_pairing(const std::string &unique_id)
Definition nvhttp.cpp:615
constexpr auto PORT_HTTPS
The HTTPS port, as a difference from the config port.
Definition nvhttp.h:54
void store_hestia_session_prepare(const std::string &client_uuid, hestia_session_prepare_t prepare)
Definition nvhttp.cpp:2211
constexpr auto VERSION
The protocol version.
Definition nvhttp.h:39
void start()
Start the nvhttp server.
Definition nvhttp.cpp:2241
void setup(const std::string &pkey, const std::string &cert)
Setup the nvhttp server.
Definition nvhttp.cpp:2202
constexpr auto PORT_HTTP
The HTTP port, as a difference from the config port.
Definition nvhttp.h:49
bool pin(std::string pin, std::string name)
Compare the user supplied pin to the Moonlight pin.
Definition nvhttp.cpp:1026
bool unpair_client(const std::string_view uuid)
Remove single client.
Definition nvhttp.cpp:2470
void stop_session(stream::session_t &session, bool graceful)
Stops a session.
Definition nvhttp.cpp:2406
std::optional< std::string > pending_pair_client()
The client whose pairing request is waiting for a PIN, if any.
Definition nvhttp.cpp:1018
void erase_all_clients()
Remove all paired clients.
Definition nvhttp.cpp:2398
uint32_t launch_count()
How many launch and resume requests have been accepted so far.
Definition nvhttp.cpp:231
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.
Definition nvhttp.cpp:2207
pair_session_t & begin_pairing_session(pair_session_t session)
Definition nvhttp.cpp:637
nlohmann::json describe_applied_settings(const std::string &app_id, bool virtual_display, int scale_factor)
Definition nvhttp.cpp:94
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.
Definition nvhttp.cpp:2436
void remove_session(const pair_session_t &sess)
removes the temporary pairing session
Definition nvhttp.cpp:606
void clear_hestia_session_prepare(const std::string &client_uuid)
Definition nvhttp.cpp:2236
bool find_and_stop_session(const std::string &uuid, bool graceful)
Finds and stop session.
Definition nvhttp.cpp:2414
nlohmann::json get_all_clients()
Get all paired clients.
Definition nvhttp.cpp:1236
Declarations for RTSP streaming.
PAIR_PHASE last_phase
used as a security measure to prevent out of order calls
Definition nvhttp.h:172
Declarations for thread-safe data structures.