Sunshine v2025.628.4510
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
62 class SunshineHTTPS: public SimpleWeb::HTTPS {
63 public:
64 SunshineHTTPS(boost::asio::io_context &io_context, boost::asio::ssl::context &ctx):
65 SimpleWeb::HTTPS(io_context, ctx) {
66 }
67
68 virtual ~SunshineHTTPS() {
69 // Gracefully shutdown the TLS connection
70 SimpleWeb::error_code ec;
71 shutdown(ec);
72 }
73 };
74
82
84 struct {
85 std::string uniqueID = {};
86 std::string cert = {};
87 std::string name = {};
88 } client;
89
90 std::unique_ptr<crypto::aes_t> cipher_key = {};
91 std::vector<uint8_t> clienthash = {};
92
93 std::string serversecret = {};
94 std::string serverchallenge = {};
95
96 struct {
98 std::shared_ptr<typename SimpleWeb::ServerBase<SimpleWeb::HTTP>::Response>,
99 std::shared_ptr<typename SimpleWeb::ServerBase<SunshineHTTPS>::Response>>
100 response;
101 std::string salt = {};
102 } async_insert_pin;
103
108 };
109
114 void remove_session(const pair_session_t &sess);
115
126 void getservercert(pair_session_t &sess, boost::property_tree::ptree &tree, const std::string &pin);
127
140 void clientchallenge(pair_session_t &sess, boost::property_tree::ptree &tree, const std::string &challenge);
141
149 void serverchallengeresp(pair_session_t &sess, boost::property_tree::ptree &tree, const std::string &encrypted_response);
150
165 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);
166
176 bool pin(std::string pin, std::string name);
177
185 bool unpair_client(std::string_view uuid);
186
194 nlohmann::json get_all_clients();
195
202 void erase_all_clients();
203} // namespace nvhttp
Definition nvhttp.h:62
Definition thread_safe.h:253
Definition utility.h:499
Declarations for cryptography functions.
Contains all the functions and variables related to the nvhttp (GameStream) server.
Definition nvhttp.cpp:40
constexpr auto GFE_VERSION
The GFE version we are replicating.
Definition nvhttp.h:35
PAIR_PHASE
Definition nvhttp.h:75
@ 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:1030
void setup(const std::string &pkey, const std::string &cert)
Setup the nvhttp server.
Definition nvhttp.cpp:1025
constexpr auto PORT_HTTP
The HTTP port, as a difference from the config port.
Definition nvhttp.h:40
bool pin(std::string pin, std::string name)
Compare the user supplied pin to the Moonlight pin.
Definition nvhttp.cpp:627
bool unpair_client(const std::string_view uuid)
Remove single client.
Definition nvhttp.cpp:1180
void erase_all_clients()
Remove all paired clients.
Definition nvhttp.cpp:1173
void remove_session(const pair_session_t &sess)
removes the temporary pairing session
Definition nvhttp.cpp:336
nlohmann::json get_all_clients()
Get all paired clients.
Definition nvhttp.cpp:768
Definition nvhttp.h:83
PAIR_PHASE last_phase
used as a security measure to prevent out of order calls
Definition nvhttp.h:107
Declarations for thread-safe data structures.