forked from KyroFrCode/moonlight-chrome-tizen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
6,884 additions
and
376 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
user-data-dir/ | ||
pnacl/ | ||
|
||
# Object files | ||
*.o | ||
*.ko | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
#include "moonlight.hpp" | ||
|
||
#include "ppapi/cpp/var_array_buffer.h" | ||
|
||
#include <http.h> | ||
#include "libgamestream/errors.h" //fix-me | ||
|
||
#include <string.h> | ||
|
||
#include <mkcert.h> | ||
#include <openssl/bio.h> | ||
#include <openssl/pem.h> | ||
|
||
extern const char* gs_error; | ||
X509 *g_cert; | ||
EVP_PKEY *g_privateKey; | ||
|
||
void MoonlightInstance::MakeCert(int32_t callbackId, pp::VarArray args) | ||
{ | ||
pp::VarDictionary ret; | ||
ret.Set("callbackId", pp::Var(callbackId)); | ||
ret.Set("type", pp::Var("resolve")); | ||
|
||
pp::VarDictionary retData; | ||
|
||
CERT_KEY_PAIR certKeyPair = mkcert_generate(); | ||
|
||
BIO* bio = BIO_new(BIO_s_mem()); | ||
|
||
PEM_write_bio_X509(bio, certKeyPair.x509); | ||
BUF_MEM *mem = NULL; | ||
BIO_get_mem_ptr(bio, &mem); | ||
|
||
std::string cert(mem->data, mem->length); | ||
|
||
BIO_free(bio); | ||
|
||
BIO* biokey = BIO_new(BIO_s_mem()); | ||
PEM_write_bio_PrivateKey(biokey, certKeyPair.pkey, NULL, NULL, 0, NULL, NULL); | ||
BIO_get_mem_ptr(biokey, &mem); | ||
|
||
std::string pkey(mem->data, mem->length); | ||
|
||
BIO_free(biokey); | ||
|
||
retData.Set("privateKey", pkey.c_str()); | ||
retData.Set("cert", cert.c_str()); | ||
|
||
ret.Set("ret", retData); | ||
PostMessage(ret); | ||
} | ||
|
||
void MoonlightInstance::LoadCert(const char* certStr, const char* keyStr) | ||
{ | ||
char* _certStr = strdup(certStr); | ||
char* _keyStr = strdup(keyStr); | ||
|
||
BIO *bio = BIO_new_mem_buf(_certStr, -1); | ||
if(!(g_cert = PEM_read_bio_X509(bio, NULL, NULL, NULL))) { | ||
PostMessage(pp::Var("Error loading cert into memory")); | ||
} | ||
BIO_reset(bio); | ||
BIO_free_all(bio); | ||
|
||
bio = BIO_new_mem_buf(_keyStr, -1); | ||
if(PEM_read_bio_PrivateKey(bio, &g_privateKey, NULL, NULL) == NULL) { | ||
PostMessage(pp::Var("Error loading private key into memory")); | ||
} | ||
BIO_free_all(bio); | ||
|
||
free(_certStr); | ||
free(_keyStr); | ||
} | ||
|
||
void MoonlightInstance::NvHTTPInit(int32_t callbackId, pp::VarArray args) | ||
{ | ||
std::string _cert = args.Get(0).AsString(); | ||
std::string _key = args.Get(1).AsString(); | ||
|
||
LoadCert(_cert.c_str(), _key.c_str()); | ||
|
||
http_init(); | ||
|
||
pp::VarDictionary ret; | ||
ret.Set("callbackId", pp::Var(callbackId)); | ||
ret.Set("type", pp::Var("resolve")); | ||
ret.Set("ret", pp::Var("")); | ||
PostMessage(ret); | ||
} | ||
|
||
void MoonlightInstance::NvHTTPRequest(int32_t /*result*/, int32_t callbackId, std::string url) | ||
{ | ||
char* _url = strdup(url.c_str()); | ||
PHTTP_DATA data = http_create_data(); | ||
|
||
if (data == NULL) { | ||
pp::VarDictionary ret; | ||
ret.Set("callbackId", pp::Var(callbackId)); | ||
ret.Set("type", pp::Var("reject")); | ||
ret.Set("ret", pp::Var("Error when creating data buffer.")); | ||
PostMessage(ret); | ||
goto clean_data; | ||
} | ||
|
||
if(http_request(_url , data) != GS_OK) { | ||
pp::VarDictionary ret; | ||
ret.Set("callbackId", pp::Var(callbackId)); | ||
ret.Set("type", pp::Var("reject")); | ||
ret.Set("ret", pp::Var(gs_error)); | ||
PostMessage(ret); | ||
goto clean_data; | ||
} | ||
|
||
{ | ||
pp::VarDictionary ret; | ||
ret.Set("callbackId", pp::Var(callbackId)); | ||
ret.Set("type", pp::Var("resolve")); | ||
ret.Set("ret", pp::Var(data->memory)); | ||
PostMessage(ret); | ||
} | ||
|
||
clean_data: | ||
http_free_data(data); | ||
free(_url); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
LIBGS_C_DIR := libgamestream | ||
|
||
LIBGS_C_SOURCE := \ | ||
$(LIBGS_C_DIR)/http.c \ | ||
$(LIBGS_C_DIR)/mkcert.c \ | ||
|
||
LIBGS_C_INCLUDE := \ | ||
$(LIBGS_C_DIR) \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* This file is part of Moonlight Embedded. | ||
* | ||
* Copyright (C) 2015 Iwan Timmer | ||
* | ||
* Moonlight is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Moonlight is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Moonlight; if not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#define GS_OK 0 | ||
#define GS_FAILED -1 | ||
#define GS_OUT_OF_MEMORY -2 | ||
#define GS_INVALID -3 | ||
#define GS_WRONG_STATE -4 | ||
#define GS_IO_ERROR -5 | ||
#define GS_NOT_SUPPORTED_4K -6 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* | ||
* This file is part of Moonlight Embedded. | ||
* | ||
* Copyright (C) 2015 Iwan Timmer | ||
* | ||
* Moonlight is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Moonlight is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Moonlight; if not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "http.h" | ||
#include "errors.h" | ||
|
||
#include <string.h> | ||
#include <curl/curl.h> | ||
|
||
#include <openssl/ssl.h> | ||
#include <openssl/x509v3.h> | ||
#include <openssl/pem.h> | ||
|
||
static CURL *curl; | ||
const char* gs_error; | ||
|
||
extern X509 *g_cert; | ||
extern EVP_PKEY *g_privateKey; | ||
|
||
static size_t _write_curl(void *contents, size_t size, size_t nmemb, void *userp) | ||
{ | ||
size_t realsize = size * nmemb; | ||
PHTTP_DATA mem = (PHTTP_DATA)userp; | ||
|
||
mem->memory = realloc(mem->memory, mem->size + realsize + 1); | ||
if(mem->memory == NULL) | ||
return 0; | ||
|
||
memcpy(&(mem->memory[mem->size]), contents, realsize); | ||
mem->size += realsize; | ||
mem->memory[mem->size] = 0; | ||
|
||
return realsize; | ||
} | ||
|
||
static CURLcode sslctx_function(CURL * curl, void * sslctx, void * parm) | ||
{ | ||
SSL_CTX* ctx = (SSL_CTX*)sslctx; | ||
//X509_STORE* store = SSL_CTX_get_cert_store(ctx); | ||
|
||
//X509_STORE_add_cert(store, cert); | ||
|
||
if(!SSL_CTX_use_certificate(ctx, g_cert)) | ||
printf("SSL_CTX_use_certificate problem\n"); | ||
|
||
if(!SSL_CTX_use_PrivateKey(ctx, g_privateKey)) | ||
printf("Use Key failed\n"); | ||
|
||
return CURLE_OK; | ||
} | ||
|
||
int http_init() { | ||
curl = curl_easy_init(); | ||
if (!curl) | ||
return GS_FAILED; | ||
|
||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); | ||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); | ||
curl_easy_setopt(curl, CURLOPT_SSLENGINE_DEFAULT, 1L); | ||
curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE,"PEM"); | ||
curl_easy_setopt(curl, CURLOPT_SSLKEYTYPE, "PEM"); | ||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); | ||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, _write_curl); | ||
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L); | ||
curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, *sslctx_function); | ||
|
||
return GS_OK; | ||
} | ||
|
||
int http_request(char* url, PHTTP_DATA data) { | ||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, data); | ||
curl_easy_setopt(curl, CURLOPT_URL, url); | ||
|
||
if (data->size > 0) { | ||
free(data->memory); | ||
data->memory = malloc(1); | ||
if(data->memory == NULL) | ||
return GS_OUT_OF_MEMORY; | ||
|
||
data->size = 0; | ||
} | ||
|
||
//return GS_FAILED; | ||
CURLcode res = curl_easy_perform(curl); | ||
|
||
if(res != CURLE_OK) { | ||
gs_error = curl_easy_strerror(res); | ||
return GS_FAILED; | ||
} else if (data->memory == NULL) { | ||
return GS_OUT_OF_MEMORY; | ||
} | ||
|
||
return GS_OK; | ||
} | ||
|
||
void http_cleanup() { | ||
curl_easy_cleanup(curl); | ||
} | ||
|
||
PHTTP_DATA http_create_data() { | ||
PHTTP_DATA data = malloc(sizeof(HTTP_DATA)); | ||
if (data == NULL) | ||
return NULL; | ||
|
||
data->memory = malloc(1); | ||
if(data->memory == NULL) { | ||
free(data); | ||
return NULL; | ||
} | ||
data->size = 0; | ||
|
||
return data; | ||
} | ||
|
||
void http_free_data(PHTTP_DATA data) { | ||
if (data != NULL) { | ||
if (data->memory != NULL) | ||
free(data->memory); | ||
|
||
free(data); | ||
} | ||
} |
Oops, something went wrong.