mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2025-07-02 15:55:39 +00:00
Make IdentityManager a singleton
This commit is contained in:
parent
6c8349787a
commit
bb95c4db78
@ -35,11 +35,9 @@ void MainWindow::on_newHostBtn_clicked()
|
|||||||
QString hostname = popupmanager::getHostnameDialog(this);
|
QString hostname = popupmanager::getHostnameDialog(this);
|
||||||
if (!hostname.isEmpty()) {
|
if (!hostname.isEmpty()) {
|
||||||
|
|
||||||
IdentityManager im = IdentityManager();
|
NvPairingManager pm(hostname);
|
||||||
NvPairingManager pm(hostname, im);
|
|
||||||
|
|
||||||
QString pin = pm.generatePinString();
|
QString pin = pm.generatePinString();
|
||||||
NvHTTP http(hostname, im);
|
|
||||||
pm.pair(http.getServerInfo(), pin);
|
pm.pair(http.getServerInfo(), pin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,9 +23,8 @@ class PcMonitorThread : public QThread
|
|||||||
#define TRIES_BEFORE_OFFLINING 2
|
#define TRIES_BEFORE_OFFLINING 2
|
||||||
#define POLLS_PER_APPLIST_FETCH 10
|
#define POLLS_PER_APPLIST_FETCH 10
|
||||||
|
|
||||||
PcMonitorThread(NvComputer* computer, IdentityManager im)
|
PcMonitorThread(NvComputer* computer)
|
||||||
: m_Im(im),
|
: m_Computer(computer)
|
||||||
m_Computer(computer)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -49,7 +48,7 @@ class PcMonitorThread : public QThread
|
|||||||
|
|
||||||
bool TryPollComputer(QString& address, bool& changed)
|
bool TryPollComputer(QString& address, bool& changed)
|
||||||
{
|
{
|
||||||
NvHTTP http(address, m_Im);
|
NvHTTP http(address);
|
||||||
|
|
||||||
QString serverInfo;
|
QString serverInfo;
|
||||||
try {
|
try {
|
||||||
@ -174,6 +173,5 @@ signals:
|
|||||||
void computerStateChanged(NvComputer* computer);
|
void computerStateChanged(NvComputer* computer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IdentityManager m_Im;
|
|
||||||
NvComputer* m_Computer;
|
NvComputer* m_Computer;
|
||||||
};
|
};
|
||||||
|
@ -13,6 +13,20 @@
|
|||||||
#include <openssl/bn.h>
|
#include <openssl/bn.h>
|
||||||
#include <openssl/x509.h>
|
#include <openssl/x509.h>
|
||||||
|
|
||||||
|
IdentityManager* IdentityManager::s_Im = nullptr;
|
||||||
|
|
||||||
|
IdentityManager*
|
||||||
|
IdentityManager::get()
|
||||||
|
{
|
||||||
|
// This will always be called first on the main thread,
|
||||||
|
// so it's safe to initialize without locks.
|
||||||
|
if (s_Im == nullptr) {
|
||||||
|
s_Im = new IdentityManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
return s_Im;
|
||||||
|
}
|
||||||
|
|
||||||
IdentityManager::IdentityManager()
|
IdentityManager::IdentityManager()
|
||||||
{
|
{
|
||||||
m_RootDirectory = QDir(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
|
m_RootDirectory = QDir(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
|
||||||
|
@ -6,8 +6,6 @@
|
|||||||
class IdentityManager
|
class IdentityManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
IdentityManager();
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
getUniqueId();
|
getUniqueId();
|
||||||
|
|
||||||
@ -20,10 +18,18 @@ public:
|
|||||||
QSslConfiguration
|
QSslConfiguration
|
||||||
getSslConfig();
|
getSslConfig();
|
||||||
|
|
||||||
|
static
|
||||||
|
IdentityManager*
|
||||||
|
get();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
IdentityManager();
|
||||||
|
|
||||||
QDir m_RootDirectory;
|
QDir m_RootDirectory;
|
||||||
|
|
||||||
QByteArray m_CachedPrivateKey;
|
QByteArray m_CachedPrivateKey;
|
||||||
QByteArray m_CachedPemCert;
|
QByteArray m_CachedPemCert;
|
||||||
QString m_CachedUniqueId;
|
QString m_CachedUniqueId;
|
||||||
|
|
||||||
|
static IdentityManager* s_Im;
|
||||||
};
|
};
|
||||||
|
@ -11,9 +11,8 @@
|
|||||||
|
|
||||||
#define REQUEST_TIMEOUT_MS 5000
|
#define REQUEST_TIMEOUT_MS 5000
|
||||||
|
|
||||||
NvHTTP::NvHTTP(QString address, IdentityManager im) :
|
NvHTTP::NvHTTP(QString address) :
|
||||||
m_Address(address),
|
m_Address(address)
|
||||||
m_Im(im)
|
|
||||||
{
|
{
|
||||||
m_BaseUrlHttp.setScheme("http");
|
m_BaseUrlHttp.setScheme("http");
|
||||||
m_BaseUrlHttps.setScheme("https");
|
m_BaseUrlHttps.setScheme("https");
|
||||||
@ -266,14 +265,14 @@ NvHTTP::openConnection(QUrl baseUrl,
|
|||||||
// Build a URL for the request
|
// Build a URL for the request
|
||||||
QUrl url(baseUrl);
|
QUrl url(baseUrl);
|
||||||
url.setPath("/" + command);
|
url.setPath("/" + command);
|
||||||
url.setQuery("uniqueid=" + m_Im.getUniqueId() +
|
url.setQuery("uniqueid=" + IdentityManager::get()->getUniqueId() +
|
||||||
"&uuid=" + QUuid::createUuid().toRfc4122().toHex() +
|
"&uuid=" + QUuid::createUuid().toRfc4122().toHex() +
|
||||||
((arguments != nullptr) ? ("&" + arguments) : ""));
|
((arguments != nullptr) ? ("&" + arguments) : ""));
|
||||||
|
|
||||||
QNetworkRequest request = QNetworkRequest(url);
|
QNetworkRequest request = QNetworkRequest(url);
|
||||||
|
|
||||||
// Add our client certificate
|
// Add our client certificate
|
||||||
request.setSslConfiguration(m_Im.getSslConfig());
|
request.setSslConfiguration(IdentityManager::get()->getSslConfig());
|
||||||
|
|
||||||
QNetworkReply* reply = m_Nam.get(request);
|
QNetworkReply* reply = m_Nam.get(request);
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ private:
|
|||||||
class NvHTTP
|
class NvHTTP
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NvHTTP(QString address, IdentityManager im);
|
NvHTTP(QString address);
|
||||||
|
|
||||||
int
|
int
|
||||||
getCurrentGame(QString serverInfo);
|
getCurrentGame(QString serverInfo);
|
||||||
@ -92,5 +92,4 @@ private:
|
|||||||
|
|
||||||
QString m_Address;
|
QString m_Address;
|
||||||
QNetworkAccessManager m_Nam;
|
QNetworkAccessManager m_Nam;
|
||||||
IdentityManager m_Im;
|
|
||||||
};
|
};
|
||||||
|
@ -10,11 +10,10 @@
|
|||||||
#include <openssl/x509.h>
|
#include <openssl/x509.h>
|
||||||
#include <openssl/evp.h>
|
#include <openssl/evp.h>
|
||||||
|
|
||||||
NvPairingManager::NvPairingManager(QString address, IdentityManager im) :
|
NvPairingManager::NvPairingManager(QString address) :
|
||||||
m_Http(address, im),
|
m_Http(address)
|
||||||
m_Im(im)
|
|
||||||
{
|
{
|
||||||
QByteArray cert = m_Im.getCertificate();
|
QByteArray cert = IdentityManager::get()->getCertificate();
|
||||||
BIO *bio = BIO_new_mem_buf(cert.data(), -1);
|
BIO *bio = BIO_new_mem_buf(cert.data(), -1);
|
||||||
THROW_BAD_ALLOC_IF_NULL(bio);
|
THROW_BAD_ALLOC_IF_NULL(bio);
|
||||||
|
|
||||||
@ -25,7 +24,7 @@ NvPairingManager::NvPairingManager(QString address, IdentityManager im) :
|
|||||||
throw new std::runtime_error("Unable to load certificate");
|
throw new std::runtime_error("Unable to load certificate");
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray pk = m_Im.getPrivateKey();
|
QByteArray pk = IdentityManager::get()->getPrivateKey();
|
||||||
bio = BIO_new_mem_buf(pk.data(), -1);
|
bio = BIO_new_mem_buf(pk.data(), -1);
|
||||||
THROW_BAD_ALLOC_IF_NULL(bio);
|
THROW_BAD_ALLOC_IF_NULL(bio);
|
||||||
|
|
||||||
@ -198,7 +197,7 @@ NvPairingManager::pair(QString serverInfo, QString pin)
|
|||||||
QString getCert = m_Http.openConnectionToString(m_Http.m_BaseUrlHttp,
|
QString getCert = m_Http.openConnectionToString(m_Http.m_BaseUrlHttp,
|
||||||
"pair",
|
"pair",
|
||||||
"devicename=roth&updateState=1&phrase=getservercert&salt=" +
|
"devicename=roth&updateState=1&phrase=getservercert&salt=" +
|
||||||
salt.toHex() + "&clientcert=" + m_Im.getCertificate().toHex(),
|
salt.toHex() + "&clientcert=" + IdentityManager::get()->getCertificate().toHex(),
|
||||||
false);
|
false);
|
||||||
m_Http.verifyResponseStatus(getCert);
|
m_Http.verifyResponseStatus(getCert);
|
||||||
if (m_Http.getXmlString(getCert, "paired") != "1")
|
if (m_Http.getXmlString(getCert, "paired") != "1")
|
||||||
|
@ -19,7 +19,7 @@ public:
|
|||||||
ALREADY_IN_PROGRESS
|
ALREADY_IN_PROGRESS
|
||||||
};
|
};
|
||||||
|
|
||||||
NvPairingManager(QString address, IdentityManager im);
|
NvPairingManager(QString address);
|
||||||
|
|
||||||
~NvPairingManager();
|
~NvPairingManager();
|
||||||
|
|
||||||
@ -52,7 +52,6 @@ private:
|
|||||||
signMessage(QByteArray message);
|
signMessage(QByteArray message);
|
||||||
|
|
||||||
NvHTTP m_Http;
|
NvHTTP m_Http;
|
||||||
IdentityManager m_Im;
|
|
||||||
X509* m_Cert;
|
X509* m_Cert;
|
||||||
EVP_PKEY* m_PrivateKey;
|
EVP_PKEY* m_PrivateKey;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user