Sunshine master
Self-hosted game stream host for Moonlight.
nvhttp.h
Go to the documentation of this file.
1
5// macros
6#pragma once
7
8// standard includes
9#include <string>
10
11// lib includes
12#include <boost/property_tree/ptree.hpp>
13#include <nlohmann/json.hpp>
14#include <Simple-Web-Server/server_https.hpp>
15
16// local includes
17#include "crypto.h"
18#include "thread_safe.h"
19
23namespace nvhttp {
24
30 constexpr auto VERSION = "7.1.431.-1";
31
35 constexpr auto GFE_VERSION = "3.23.0.74";
36
40 constexpr auto PORT_HTTP = 0;
41
45 constexpr auto PORT_HTTPS = -5;
46
53 void start();
54
60 void setup(const std::string &pkey, const std::string &cert);
61
65 class SunshineHTTPS: public SimpleWeb::HTTPS {
66 public:
73 SunshineHTTPS(boost::asio::io_context &io_context, boost::asio::ssl::context &ctx):
74 SimpleWeb::HTTPS(io_context, ctx) {
75 }
76
77 virtual ~SunshineHTTPS() {
78 // Gracefully shutdown the TLS connection
79 SimpleWeb::error_code ec;
80 shutdown(ec);
81 }
82 };
83
94
99 struct {
100 std::string uniqueID = {};
101 std::string cert = {};
102 std::string name = {};
104
105 std::unique_ptr<crypto::aes_t> cipher_key = {};
106 std::vector<uint8_t> clienthash = {};
107
108 std::string serversecret = {};
109 std::string serverchallenge = {};
110
111 struct {
113 std::shared_ptr<typename SimpleWeb::ServerBase<SimpleWeb::HTTP>::Response>,
114 std::shared_ptr<typename SimpleWeb::ServerBase<SunshineHTTPS>::Response>>
115 response;
116 std::string salt = {};
118
123 };
124
129 void remove_session(const pair_session_t &sess);
130
144 void getservercert(pair_session_t &sess, boost::property_tree::ptree &tree, const std::string &pin);
145
161 void clientchallenge(pair_session_t &sess, boost::property_tree::ptree &tree, const std::string &challenge);
162
173 void serverchallengeresp(pair_session_t &sess, boost::property_tree::ptree &tree, const std::string &encrypted_response);
174
193 void clientpairingsecret(pair_session_t &sess, std::shared_ptr<safe::queue_t<crypto::x509_t>> &add_cert, boost::property_tree::ptree &tree, const std::string &client_pairing_secret);
194
204 bool pin(std::string pin, std::string name);
205
215 bool unpair_client(std::string_view uuid);
216
223 bool set_client_enabled(std::string_view uuid, bool enabled);
230 std::string get_cert_by_uuid(std::string_view uuid);
231
239 nlohmann::json get_all_clients();
240
247 void erase_all_clients();
248} // namespace nvhttp
Simple-Web-Server HTTPS backend configured for Sunshine certificate handling.
Definition nvhttp.h:65
SunshineHTTPS(boost::asio::io_context &io_context, boost::asio::ssl::context &ctx)
Construct an HTTPS connection using Sunshine's TLS context.
Definition nvhttp.h:73
Thread-safe queue with blocking and shutdown-aware consumers.
Definition thread_safe.h:391
Tagged storage for one of two possible value types.
Definition utility.h:756
Declarations for cryptography functions.
Contains all the functions and variables related to the nvhttp (GameStream) server.
Definition nvhttp.cpp:41
constexpr auto GFE_VERSION
The GFE version we are replicating.
Definition nvhttp.h:35
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:528
void clientpairingsecret(pair_session_t &sess, std::shared_ptr< safe::queue_t< crypto::x509_t > > &add_cert, pt::ptree &tree, const std::string &client_pairing_secret)
Handle the client pairing-secret phase of GameStream pairing.
Definition nvhttp.cpp:565
PAIR_PHASE
Enumerates supported pAIR PHASE options.
Definition nvhttp.h:87
@ 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.
constexpr auto PORT_HTTPS
The HTTPS port, as a difference from the config port.
Definition nvhttp.h:45
constexpr auto VERSION
The protocol version.
Definition nvhttp.h:30
void start()
Start the nvhttp server.
Definition nvhttp.cpp:1263
void setup(const std::string &pkey, const std::string &cert)
Setup the nvhttp server.
Definition nvhttp.cpp:1250
constexpr auto PORT_HTTP
The HTTP port, as a difference from the config port.
Definition nvhttp.h:40
void clientchallenge(pair_session_t &sess, pt::ptree &tree, const std::string &challenge)
Handle the client-challenge phase of GameStream pairing.
Definition nvhttp.cpp:478
bool pin(std::string pin, std::string name)
Compare the user supplied pin to the Moonlight pin.
Definition nvhttp.cpp:774
bool unpair_client(const std::string_view uuid)
Remove single client.
Definition nvhttp.cpp:1424
void getservercert(pair_session_t &sess, pt::ptree &tree, const std::string &pin)
Return the server certificate text for pairing responses.
Definition nvhttp.cpp:447
void erase_all_clients()
Remove all paired clients.
Definition nvhttp.cpp:1417
bool set_client_enabled(const std::string_view uuid, bool enabled)
Enable or disable a client.
Definition nvhttp.cpp:1441
void remove_session(const pair_session_t &sess)
removes the temporary pairing session
Definition nvhttp.cpp:422
nlohmann::json get_all_clients()
Get all paired clients.
Definition nvhttp.cpp:936
std::string get_cert_by_uuid(const std::string_view uuid)
Get cert by UUID.
Definition nvhttp.cpp:1456
Pairing handshake state exchanged with a Moonlight client.
Definition nvhttp.h:98
std::string serverchallenge
Server challenge sent during pairing.
Definition nvhttp.h:109
struct nvhttp::pair_session_t::@11 client
Client object or client certificate data owned by this state..
std::vector< uint8_t > clienthash
Client certificate hash used during pairing.
Definition nvhttp.h:106
std::string serversecret
Server pairing secret.
Definition nvhttp.h:108
std::unique_ptr< crypto::aes_t > cipher_key
Cipher key.
Definition nvhttp.h:105
PAIR_PHASE last_phase
used as a security measure to prevent out of order calls
Definition nvhttp.h:122
struct nvhttp::pair_session_t::@12 async_insert_pin
Async insert pin.
Declarations for thread-safe data structures.