in-progress commit for saving/loading pairing certs

This commit is contained in:
R. Aidan Campbell 2016-03-07 18:16:52 -05:00
parent 8258c3f826
commit 5ad7c34cec
2 changed files with 34 additions and 23 deletions

View File

@ -1,5 +1,6 @@
var target = ""; var target = "";
var hosts = []; var hosts = [];
var pairingCert;
// Called by the common.js module. // Called by the common.js module.
function attachListeners() { function attachListeners() {
@ -20,25 +21,14 @@ function updateBitrateField() {
function moduleDidLoad() { function moduleDidLoad() {
console.log("NaCl module loaded."); console.log("NaCl module loaded.");
console.log("Loading certs");
if (chrome.storage) { // load the cert if we have the ability to load things. if(!pairingCert) { // we couldn't load a cert. Make one.
chrome.storage.sync.get('cert', function(savedCert) { console.log("Failed to load local cert. Generating new one");
if (savedCert.cert != null) { // we have a saved cert sendMessage('makeCert', []).then(function (cert) {
var cert = savedCert.cert.cert; storeData('cert', cert, null); //TODO: this may go 1 level too deep. i.e. reading it will be cert.cert.cert
var pk = savedCert.cert.privateKey; pairingCert = cert;
sendMessage('httpInit', [cert, pk]).then(function (ret) { console.log("Generated new cert.")
return api.pair(cert, "1234"); });
});
} else { // we don't have a saved cert. make one.
// TODO: NaCl call to make a new cert
sendMessage('makeCert', []).then(function (cert) {
storeData('cert', cert, null); // we just made a cert. save it.
return sendMessage('httpInit', [cert.cert, cert.privateKey]).then(function (ret) {
return api.pair(cert, "1234");
});
});
}
}
} }
} }
@ -54,7 +44,22 @@ function hideAllWorkflowDivs() {
// pair button was pushed. pass what the user entered into the GFEHostIPField. // pair button was pushed. pass what the user entered into the GFEHostIPField.
function pairPushed() { function pairPushed() {
console.log("Error. pairing unimplemented."); if(!pairingCert) {
console.log("User wants to pair, and we still have no cert. Problem = very yes.")
}
target = $('#GFEHostIPField')[0].value;
if (target == null || target == "127.0.0.1") {
var e = $("#selectHost")[0];
target = e.options[e.selectedIndex].value;
}
api = new NvHTTP(target, guuid());
console.log("Attempting to pair to: " + target);
sendMessage('httpInit', [pairingCert.cert, pairingCert.privateKey]).then(function (ret) {
sendMessage('pair', [pairingCert.cert, "1233"]).then(function (ret2) {
console.log("pair attempt to to " + target + " has returned.");
console.log("pairing attempt returned " + ret2)
})
});
} }
// someone pushed the "show apps" button. // someone pushed the "show apps" button.
@ -93,7 +98,7 @@ function startPushed() {
// we told the user it was in Mbps. We're dirty liars and use Kbps behind their back. // we told the user it was in Mbps. We're dirty liars and use Kbps behind their back.
var bitrate = parseInt($("#bitrateSlider").val()) * 1024; var bitrate = parseInt($("#bitrateSlider").val()) * 1024;
console.log('startRequest:' + target + ":" + resolution + ":" + frameRate); console.log('startRequest:' + target + ":" + streamWidth + "x" + streamHeight + ":" + frameRate);
sendMessage('startRequest', [target, streamWidth, streamHeight, frameRate, bitrate]); sendMessage('startRequest', [target, streamWidth, streamHeight, frameRate, bitrate]);
@ -213,6 +218,12 @@ function onWindowLoad(){
$('#bitrateSlider')[0].MaterialSlider.change(previousValue.bitrate != null ? previousValue.bitrate : '15'); $('#bitrateSlider')[0].MaterialSlider.change(previousValue.bitrate != null ? previousValue.bitrate : '15');
updateBitrateField(); updateBitrateField();
}); });
// load the HTTP cert if we have one.
chrome.storage.sync.get('cert', function(savedCert) {
if (savedCert.cert != null) { // we have a saved cert
pairingCert = savedCert.cert;
}
});
} }
} }

View File

@ -13,7 +13,7 @@ String.prototype.toHex = function() {
return hex; return hex;
} }
function NvAPI(address, clientUid) { function NvHTTP(address, clientUid) {
this.address = address; this.address = address;
this.paired = false; this.paired = false;
this.supports4K = false; this.supports4K = false;
@ -25,7 +25,7 @@ function NvAPI(address, clientUid) {
_self = this; _self = this;
}; };
NvAPI.prototype = { NvHTTP.prototype = {
init: function () { init: function () {
return sendMessage('openUrl', [_self._baseUrlHttps+'/serverinfo?'+_self._buildUidStr()]).then(function(ret) { return sendMessage('openUrl', [_self._baseUrlHttps+'/serverinfo?'+_self._buildUidStr()]).then(function(ret) {
$xml = _self._parseXML(ret); $xml = _self._parseXML(ret);