Sunshine latest
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 <Simple-Web-Server/server_https.hpp>
14
15// local includes
16#include "crypto.h"
17#include "thread_safe.h"
18
22namespace nvhttp {
23
29 constexpr auto VERSION = "7.1.431.-1";
30
34 constexpr auto GFE_VERSION = "3.23.0.74";
35
39 constexpr auto PORT_HTTP = 0;
40
44 constexpr auto PORT_HTTPS = -5;
45
52 void start();
53
59 void setup(const std::string &pkey, const std::string &cert);
60
61 class SunshineHTTPS: public SimpleWeb::HTTPS {
62 public:
63 SunshineHTTPS(boost::asio::io_context &io_context, boost::asio::ssl::context &ctx):
64 SimpleWeb::HTTPS(io_context, ctx) {
65 }
66
67 virtual ~SunshineHTTPS() {
68 // Gracefully shutdown the TLS connection
69 SimpleWeb::error_code ec;
70 shutdown(ec);
71 }
72 };
73
81
83 struct {
84 std::string uniqueID = {};
85 std::string cert = {};
86 std::string name = {};
87 } client;
88
89 std::unique_ptr<crypto::aes_t> cipher_key = {};
90 std::vector<uint8_t> clienthash = {};
91
92 std::string serversecret = {};
93 std::string serverchallenge = {};
94
95 struct {
97 std::shared_ptr<typename SimpleWeb::ServerBase<SimpleWeb::HTTP>::Response>,
98 std::shared_ptr<typename SimpleWeb::ServerBase<SunshineHTTPS>::Response>>
99 response;
100 std::string salt = {};
101 } async_insert_pin;
102
107 };
108
113 void remove_session(const pair_session_t &sess);
114
125 void getservercert(pair_session_t &sess, boost::property_tree::ptree &tree, const std::string &pin);
126
139 void clientchallenge(pair_session_t &sess, boost::property_tree::ptree &tree, const std::string &challenge);
140
148 void serverchallengeresp(pair_session_t &sess, boost::property_tree::ptree &tree, const std::string &encrypted_response);
149
164 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);
165
175 bool pin(std::string pin, std::string name);
176
183 int unpair_client(std::string uniqueid);
184
192 boost::property_tree::ptree get_all_clients();
193
200 void erase_all_clients();
201} // namespace nvhttp
Definition nvhttp.h:61
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:34
int unpair_client(std::string uuid)
Remove single client.
Definition nvhttp.cpp:1180
PAIR_PHASE
Definition nvhttp.h:74
@ 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:44
constexpr auto VERSION
The protocol version.
Definition nvhttp.h:29
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:39
bool pin(std::string pin, std::string name)
Compare the user supplied pin to the Moonlight pin.
Definition nvhttp.cpp:627
void erase_all_clients()
Remove all paired clients.
Definition nvhttp.cpp:1173
pt::ptree get_all_clients()
Get all paired clients.
Definition nvhttp.cpp:768
void remove_session(const pair_session_t &sess)
removes the temporary pairing session
Definition nvhttp.cpp:336
Definition nvhttp.h:82
PAIR_PHASE last_phase
used as a security measure to prevent out of order calls
Definition nvhttp.h:106
Declarations for thread-safe data structures.