Permalink
Browse files

Pairing is working

  • Loading branch information...
1 parent 59e461c commit 4832237a1101b92b05a8139e7ee1aeef62f17b6a @cgutman cgutman committed Feb 28, 2016
Showing with 345 additions and 6,072 deletions.
  1. +1 −0 Makefile
  2. +30 −21 http.cpp
  3. +0 −1 index.html
  4. +1 −0 libgamestream.mk
  5. +4 −10 libgamestream/http.c
  6. +234 −0 libgamestream/pairing.c
  7. +30 −0 libgamestream/pairing.h
  8. +24 −6 main.cpp
  9. +7 −8 moonlight.hpp
  10. +2 −0 ports.mk
  11. +0 −5,949 static/js/crypto-js.js
  12. +12 −77 static/js/utils.js
View
@@ -7,6 +7,7 @@ include common-c.mk
include opus.mk
include h264bitstream.mk
include libgamestream.mk
+include ports.mk
EXTRA_INC_PATHS := $(EXTRA_INC_PATHS) $(COMMON_C_INCLUDE) $(OPUS_INCLUDE) $(H264BS_INCLUDE) $(LIBGS_C_INCLUDE)
View
@@ -3,17 +3,17 @@
#include "ppapi/cpp/var_array_buffer.h"
#include <http.h>
-#include "libgamestream/errors.h" //fix-me
-
+#include <errors.h>
#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;
+X509 *g_Cert;
+EVP_PKEY *g_PrivateKey;
+char *g_UniqueId;
+char *g_CertHex;
void MoonlightInstance::MakeCert(int32_t callbackId, pp::VarArray args)
{
@@ -23,7 +23,7 @@ void MoonlightInstance::MakeCert(int32_t callbackId, pp::VarArray args)
pp::VarDictionary retData;
- CERT_KEY_PAIR certKeyPair = mkcert_generate();
+ CERT_KEY_PAIR certKeyPair = mkcert_generate();
BIO* bio = BIO_new(BIO_s_mem());
@@ -55,19 +55,24 @@ 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))) {
+ 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) {
+ if(PEM_read_bio_PrivateKey(bio, &g_PrivateKey, NULL, NULL) == NULL) {
PostMessage(pp::Var("Error loading private key into memory"));
}
BIO_free_all(bio);
+ // Convert the PEM cert to hex
+ g_CertHex = (char*)malloc((strlen(certStr) * 2) + 1);
+ for (int i = 0; i < strlen(certStr); i++) {
+ sprintf(&g_CertHex[i * 2], "%02x", certStr[i]);
+ }
+
free(_certStr);
free(_keyStr);
}
@@ -76,8 +81,10 @@ void MoonlightInstance::NvHTTPInit(int32_t callbackId, pp::VarArray args)
{
std::string _cert = args.Get(0).AsString();
std::string _key = args.Get(1).AsString();
+ std::string _uniqueId = args.Get(2).AsString();
LoadCert(_cert.c_str(), _key.c_str());
+ g_UniqueId = strdup(_uniqueId.c_str());
http_init();
@@ -91,25 +98,27 @@ void MoonlightInstance::NvHTTPInit(int32_t callbackId, pp::VarArray args)
void MoonlightInstance::NvHTTPRequest(int32_t /*result*/, int32_t callbackId, std::string url)
{
char* _url = strdup(url.c_str());
- PHTTP_DATA data = http_create_data();
+ PHTTP_DATA data = http_create_data();
+ int err;
- if (data == NULL) {
- pp::VarDictionary ret;
+ 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;
+ }
+
+ err = http_request(_url , data);
+ if (err) {
+ pp::VarDictionary ret;
ret.Set("callbackId", pp::Var(callbackId));
ret.Set("type", pp::Var("reject"));
- ret.Set("ret", pp::Var(gs_error));
+ ret.Set("ret", pp::Var(err));
PostMessage(ret);
goto clean_data;
- }
+ }
{
pp::VarDictionary ret;
@@ -120,6 +129,6 @@ void MoonlightInstance::NvHTTPRequest(int32_t /*result*/, int32_t callbackId, st
}
clean_data:
- http_free_data(data);
- free(_url);
+ http_free_data(data);
+ free(_url);
}
View
@@ -82,7 +82,6 @@
</div>
<script defer src="static/js/jquery-2.2.0.min.js"></script>
<script defer src="static/js/material.min.js"></script>
- <script defer src="static/js/crypto-js.js"></script>
<script type="text/javascript" src="static/js/messages.js"></script>
<script type="text/javascript" src="static/js/common.js"></script>
<script type="text/javascript" src="static/js/index.js"></script>
View
@@ -3,6 +3,7 @@ LIBGS_C_DIR := libgamestream
LIBGS_C_SOURCE := \
$(LIBGS_C_DIR)/http.c \
$(LIBGS_C_DIR)/mkcert.c \
+ $(LIBGS_C_DIR)/pairing.c \
LIBGS_C_INCLUDE := \
$(LIBGS_C_DIR) \
View
@@ -28,10 +28,9 @@
#include <openssl/pem.h>
static CURL *curl;
-const char* gs_error;
-extern X509 *g_cert;
-extern EVP_PKEY *g_privateKey;
+extern X509 *g_Cert;
+extern EVP_PKEY *g_PrivateKey;
static size_t _write_curl(void *contents, size_t size, size_t nmemb, void *userp)
{
@@ -52,14 +51,11 @@ static size_t _write_curl(void *contents, size_t size, size_t nmemb, void *userp
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))
+ if(!SSL_CTX_use_certificate(ctx, g_Cert))
printf("SSL_CTX_use_certificate problem\n");
- if(!SSL_CTX_use_PrivateKey(ctx, g_privateKey))
+ if(!SSL_CTX_use_PrivateKey(ctx, g_PrivateKey))
printf("Use Key failed\n");
return CURLE_OK;
@@ -96,11 +92,9 @@ int http_request(char* url, PHTTP_DATA data) {
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;
Oops, something went wrong.

0 comments on commit 4832237

Please sign in to comment.