Commit e2b45e7c authored by Michael Long's avatar Michael Long

Merge branch 'master' into xtrnsec1

# Conflicts:
merge in master
parents f031ad1a 6e2726e9
Pipeline #519 passed with stage
in 15 minutes and 14 seconds
......@@ -40,7 +40,7 @@ require("http.js", "HTTPRequest");
function ACMEv2(opts)
{
if (opts.key === undefined)
throw('Need "key"!');
throw new Error('Need "key"!');
this.key = opts.key;
this.key_id = opts.key_id;
......@@ -70,9 +70,9 @@ ACMEv2.prototype.get_terms_of_service = function()
{
var dir = this.get_directory();
if (dir.meta === undefined)
throw('No "meta" in directory!');
throw new Error('No "meta" in directory!');
if (dir.meta.termsOfService === undefined)
throw('No "termsOfService" in directory metadata');
throw new Error('No "termsOfService" in directory metadata');
return dir.meta.termsOfService;
};
......@@ -84,7 +84,7 @@ ACMEv2.prototype.get_directory = function()
this.log_headers();
if (this.ua.response_code != 200) {
log(LOG_DEBUG, ret);
throw("Error fetching directory");
throw new Error("Error fetching directory");
}
this.update_nonce();
this.directory = JSON.parse(ret);
......@@ -98,12 +98,12 @@ ACMEv2.prototype.create_new_account = function(opts)
if (this.ua.response_code != 201 && this.ua.response_code != 200) {
log(LOG_DEBUG, ret);
throw("newAccount returned "+this.ua.response_code+", not a 200 or 201 status!");
throw new Error("newAccount returned "+this.ua.response_code+", not a 200 or 201 status!");
}
if (this.ua.response_headers_parsed.Location === undefined) {
log(LOG_DEBUG, this.ua.response_headers.join("\n"));
throw("No Location header in newAccount response.");
throw new Error("No Location header in newAccount response.");
}
this.key_id = this.ua.response_headers_parsed.Location[0];
return JSON.parse(ret);
......@@ -117,7 +117,7 @@ ACMEv2.prototype.update_account = function(opts)
if (this.ua.response_code != 201 && this.ua.response_code != 200) {
log(LOG_DEBUG, ret);
throw("update_account returned "+this.ua.response_code+", not a 200 or 201 status!");
throw new Error("update_account returned "+this.ua.response_code+", not a 200 or 201 status!");
}
return JSON.parse(ret);
};
......@@ -132,17 +132,17 @@ ACMEv2.prototype.create_new_order = function(opts)
var ret;
if (opts.identifiers === undefined)
throw("create_new_order() requires an identifier in opts");
throw new Error("create_new_order() requires an identifier in opts");
ret = this.post('newOrder', opts);
if (this.ua.response_code != 201) {
log(LOG_DEBUG, ret);
throw("newOrder responded with "+this.ua.response_code+" not 201");
throw new Error("newOrder responded with "+this.ua.response_code+" not 201");
}
ret = JSON.parse(ret);
if (this.ua.response_headers_parsed.Location === undefined) {
log(LOG_DEBUG, this.ua.response_headers.join("\n"));
throw("No Location header in 201 response.");
throw new Error("No Location header in 201 response.");
}
ret.Location=this.ua.response_headers_parsed.Location[0];
......@@ -156,7 +156,7 @@ ACMEv2.prototype.accept_challenge = function(challenge)
var ret = this.post_url(challenge.url, opts);
if (this.ua.response_code != 200) {
log(LOG_DEBUG, ret);
throw("accept_challenge did not return 200");
throw new Error("accept_challenge did not return 200");
}
return JSON.parse(ret);
};
......@@ -187,18 +187,18 @@ ACMEv2.prototype.finalize_order = function(order, csr)
var opts = {};
if (order === undefined)
throw("Missing order");
throw new Error("Missing order");
if (csr === undefined)
throw("Missing csr");
throw new Error("Missing csr");
if (typeof(csr) != 'object' || csr.export_cert === undefined)
throw("Invalid csr");
throw new Error("Invalid csr");
opts.csr = this.base64url(csr.export_cert(CryptCert.FORMAT.CERTIFICATE));
log(LOG_DEBUG, "Finalizing order.");
var ret = this.post_url(order.finalize, opts);
if (this.ua.response_code != 200) {
log(LOG_DEBUG, ret);
throw("finalize_order did not return 200");
throw new Error("finalize_order did not return 200");
}
return JSON.parse(ret);
......@@ -208,13 +208,13 @@ ACMEv2.prototype.poll_order = function(order)
{
var loc = order.Location;
if (loc === undefined)
throw("No order location!");
throw new Error("No order location!");
log(LOG_DEBUG, "Polling oder.");
var ret = this.ua.Get(loc);
this.log_headers();
if (this.ua.response_code != 200) {
log(LOG_DEBUG, ret);
throw("order poll did not return 200");
throw new Error("order poll did not return 200");
}
this.update_nonce();
......@@ -245,7 +245,7 @@ ACMEv2.prototype.get_jwk = function(key)
var ret = {};
if (key === undefined)
throw("change_key() requires a new key.");
throw new Error("change_key() requires a new key.");
/* Create the inner object signed with old key */
switch(key.algo) {
case CryptContext.ALGO.RSA:
......@@ -271,13 +271,13 @@ ACMEv2.prototype.get_jwk = function(key)
ret.shalen = 512;
break;
default:
throw("Unhandled ECC curve size "+key.keysize);
throw new Error("Unhandled ECC curve size "+key.keysize);
}
ret.jwk.x = key.public_key.x;
ret.jwk.y = key.public_key.y;
break;
default:
throw("Unknown algorithm in new key");
throw new Error("Unknown algorithm in new key");
}
return ret;
};
......@@ -290,7 +290,7 @@ ACMEv2.prototype.change_key = function(new_key)
var jwk;
if (new_key === undefined)
throw("change_key() requires a new key.");
throw new Error("change_key() requires a new key.");
/* Create the inner object signed with old key */
jwk = this.get_jwk(new_key);
inner.protected.alg = jwk.alg;
......@@ -304,7 +304,7 @@ ACMEv2.prototype.change_key = function(new_key)
ret = this.post('keyChange', inner);
if (this.ua.response_code != 200) {
log(LOG_DEBUG, ret);
throw("keyChange did not return 200");
throw new Error("keyChange did not return 200");
}
this.key = new_key;
return JSON.parse(ret);
......@@ -357,7 +357,7 @@ ACMEv2.prototype.revoke = function(cert, reason)
ret = this.post('revokeCert', opts);
if (this.ua.response_code != 200) {
log(LOG_DEBUG, ret);
throw("revokeCert did not return 200");
throw new Error("revokeCert did not return 200");
}
return;
};
......@@ -392,13 +392,13 @@ ACMEv2.prototype.create_pkcs7 = function(cert)
ACMEv2.prototype.get_cert = function(order)
{
if (order.certificate === undefined)
throw("Order has no certificate!");
throw new Error("Order has no certificate!");
log(LOG_DEBUG, "Getting certificate.");
var cert = this.ua.Get(order.certificate);
this.log_headers();
if (this.ua.response_code != 200) {
log(LOG_DEBUG, cert);
throw("get_cert request did not return 200");
throw new Error("get_cert request did not return 200");
}
this.update_nonce();
......@@ -417,7 +417,7 @@ ACMEv2.prototype.post = function(link, data)
post_method = 'post_full_jwt';
url = this.get_directory()[link];
if (url === undefined)
throw('Unknown link name: "'+link+'"');
throw new Error('Unknown link name: "'+link+'"');
log(LOG_DEBUG, "Calling "+link+".");
return this.post_url(url, data, post_method);
};
......@@ -444,7 +444,7 @@ ACMEv2.prototype.get_authorization = function(url)
this.log_headers();
if (this.ua.response_code != 200) {
log(LOG_DEBUG, ret);
throw("get_authorization request did not return 200");
throw new Error("get_authorization request did not return 200");
}
this.update_nonce();
......@@ -588,7 +588,7 @@ ACMEv2.prototype.post_url = function(url, data, post_method)
protected.alg = jwk.alg;
protected.kid = this.key_id;
if (protected.kid === undefined)
throw("No key_id available!");
throw new Error("No key_id available!");
break;
case 'post_full_jwt':
protected.nonce = this.get_nonce();
......
......@@ -412,7 +412,7 @@ BinkP.prototype.connect = function(addr, password, auth_cb, port, inet_host, tls
this.in_keys = undefined;
this.out_keys = undefined;
if (addr === undefined)
throw("No address specified!");
throw new Error("No address specified!");
addr = FIDO.parse_addr(addr, this.default_zone, this.default_domain);
if (!password)
......@@ -1041,7 +1041,7 @@ BinkP.prototype.recvFrame = function(timeout)
ret = new this.Frame();
i = this.sock.recv(1, timeout);
if (i === null) {
log(LOG_INFO, "Error in recv() of first byte of packet header");
log(LOG_INFO, "Error in recv() of first byte of packet header, timeout = " + timeout);
this.sock.close();
this.sock = undefined;
return undefined;
......
......@@ -74,9 +74,9 @@ var FIDO = {
set: function(val) {
net = parseInt(val, 10);
if (typeof net !== 'number')
throw('net is not a number!');
throw new Error('net is not a number!');
if (net < 0 || net > 65535)
throw('net out of range');
throw new Error('net out of range');
}
},
"node": {
......@@ -85,7 +85,7 @@ var FIDO = {
set: function(val) {
node = parseInt(val, 10);
if (typeof node !== 'number')
throw('node is not a number!');
throw new Error('node is not a number!');
if (node < 0 || node > 65535)
throw ('node out of range');
}
......@@ -103,9 +103,9 @@ var FIDO = {
else
zone = parseInt(val, 10);
if (typeof zone !== 'number')
throw('zone is not a number!');
throw new Error('zone is not a number!');
if (zone < -1 || zone > 65535)
throw('zone out of range');
throw new Error('zone out of range');
}
},
"point": {
......@@ -121,7 +121,7 @@ var FIDO = {
else
point = parseInt(val, 10);
if (typeof point !== 'number')
throw('point is not a number!');
throw new Error('point is not a number!');
if (point < 0 || point > 65535)
throw ('point out of range');
}
......@@ -139,7 +139,7 @@ var FIDO = {
else
domain = val.toString().toLowerCase().substr(0, 8);
if (typeof domain !== 'string')
throw('domain is not a string');
throw new Error('domain is not a string');
}
}
});
......@@ -153,7 +153,7 @@ var FIDO = {
if(addr)
m = addr.toString().match(/^(?:([0-9]+):)?([0-9]+)\/([0-9]+)(?:\.([0-9]+))?(?:@(.*))?$/);
if (!m)
throw('invalid address '+addr);
throw new Error('invalid address '+addr);
zone = m[1];
domain = m[5];
if (zone == undefined)
......@@ -174,14 +174,14 @@ var FIDO = {
var ext;
if (default_zone === undefined)
throw("Default zone unspecified");
throw new Error("Default zone unspecified");
m = path.match(/(?:\.([0-9a-f]{3,4})[\/\\])?([0-9a-f]{4})([0-9a-f]{4})\.(...)(?:[\/\\]([0-9a-f]{8})\.(...))?$/i);
if (m === null)
throw("Invalid flo file path");
throw new Error("Invalid flo file path");
ext = m[4];
if (m[5] != null) {
if (m[4].toUpperCase() !== 'PNT')
throw("Invalid flo file path");
throw new Error("Invalid flo file path");
ext = m[6];
}
switch(ext.toLowerCase()) {
......@@ -200,7 +200,7 @@ var FIDO = {
case 'try':
break;
default:
throw("Invalid flo file path");
throw new Error("Invalid flo file path");
}
zone = m[1];
if (zone == null)
......@@ -230,12 +230,12 @@ var FIDO = {
domain = '';
if (!f.open("r"))
throw("Unable to open '"+f.name+"'.");
throw new Error("Unable to open '"+f.name+"'.");
// Validate first line...
var line = f.readln(2048);
if (line == undefined)
throw("Unable to read first line in '"+f.name+"'");
throw new Error("Unable to read first line in '"+f.name+"'");
var m;
if ((m=line.match(/^;A (.*) Nodelist for (.*) -- Day number ([0-9]+) : ([0-9]{5})$/)) !== null) {
ret.domain = m[1];
......@@ -502,7 +502,7 @@ Object.defineProperties(FIDO.Addr.prototype, {
// TODO: Use default zone from system.fido_addr_list[0]?
if (this.zone === undefined)
throw('zone is undefined');
throw new Error('zone is undefined');
// TODO: These don't need to be loaded into different objects since we're doing 5D
if (FIDO.FTNDomains.nodeListFN[this.domain] !== undefined && file_exists(FIDO.FTNDomains.nodeListFN[this.domain])) {
......@@ -530,7 +530,7 @@ Object.defineProperties(FIDO.Addr.prototype, {
get: function() {
// TODO: Use default zone from system.fido_addr_list[0]?
if (this.zone === undefined)
throw('zone is undefined');
throw new Error('zone is undefined');
// TODO: These don't need to be loaded into different objects since we're doing 5D
if (FIDO.FTNDomains.nodeListFN[this.domain] !== undefined && file_exists(FIDO.FTNDomains.nodeListFN[this.domain])) {
......@@ -643,7 +643,7 @@ FIDO.Packet.prototype.setBin = function(offset, len, val) {
var str = '';
if (typeof(val) !== 'number')
throw('Invalid setBin value type');
throw new Error('Invalid setBin value type');
for (i=0; i<len; i++) {
str += ascii(val & 0xff);
val >>= 8;
......
......@@ -40,7 +40,7 @@ function SBBSEchoCfg ()
ecfg = new File(file_cfgname(system.ctrl_dir, 'sbbsecho.ini'));
if (!ecfg.open("r"))
throw("Unable to open '"+ecfg.name+"'");
throw new Error("Unable to open '"+ecfg.name+"'");
this.inbound = backslash(ecfg.iniGetValue(null, "Inbound", "../fido/nonsecure"));
if (this.inbound !== null)
......
......@@ -66,7 +66,7 @@ function TickITCfg() {
}
if (!tcfg.open("r"))
throw("Unable to open '"+tcfg.name+"'");
throw new Error("Unable to open '"+tcfg.name+"'");
this.gcfg = tcfg.iniGetObject();
lcprops(this.gcfg);
if (this.gcfg.handler !== undefined) {
......
......@@ -189,14 +189,14 @@ Frame.prototype.__defineSetter__("child", function(frame) {
if(frame instanceof Frame)
this.__relations__.child.push(frame);
else
throw("child not an instance of Frame()");
throw new Error("child not an instance of Frame()");
});
Frame.prototype.__defineGetter__("attr", function() {
return this.__properties__.attr;
});
Frame.prototype.__defineSetter__("attr", function(attr) {
if(attr !== undefined && isNaN(attr))
throw("invalid attribute: " + attr);
throw new Error("invalid attribute: " + attr);
this.__properties__.attr = attr;
});
Frame.prototype.__defineGetter__("x", function() {
......@@ -208,7 +208,7 @@ Frame.prototype.__defineSetter__("x", function(x) {
if(x == undefined)
return;
if(!this.__checkX__(x))
throw("invalid x coordinate: " + x);
throw new Error("invalid x coordinate: " + x);
this.__properties__.x = Number(x);
});
Frame.prototype.__defineGetter__("y", function() {
......@@ -220,7 +220,7 @@ Frame.prototype.__defineSetter__("y", function(y) {
if(y == undefined)
return;
if(!this.__checkY__(y))
throw("invalid y coordinate: " + y);
throw new Error("invalid y coordinate: " + y);
this.__properties__.y = Number(y);
});
Frame.prototype.__defineGetter__("width", function() {
......@@ -232,7 +232,7 @@ Frame.prototype.__defineSetter__("width", function(width) {
if(width == undefined)
return;
if(!this.__checkWidth__(this.x,Number(width)))
throw("invalid width: " + width);
throw new Error("invalid width: " + width);
this.__properties__.width = Number(width);
});
Frame.prototype.__defineGetter__("height", function() {
......@@ -244,7 +244,7 @@ Frame.prototype.__defineSetter__("height", function(height) {
if(height == undefined)
return;
if(!this.__checkHeight__(this.y,Number(height)))
throw("invalid height: " + height);
throw new Error("invalid height: " + height);
this.__properties__.height = Number(height);
});
......@@ -289,7 +289,7 @@ Frame.prototype.__defineSetter__("checkbounds", function(bool) {
if(typeof bool == "boolean")
this.__settings__.checkbounds=bool;
else
throw("non-boolean checkbounds: " + bool);
throw new Error("non-boolean checkbounds: " + bool);
});
Frame.prototype.__defineGetter__("transparent", function() {
return this.__settings__.transparent;
......@@ -298,7 +298,7 @@ Frame.prototype.__defineSetter__("transparent", function(bool) {
if(typeof bool == "boolean")
this.__settings__.transparent=bool;
else
throw("non-boolean transparent: " + bool);
throw new Error("non-boolean transparent: " + bool);
});
Frame.prototype.__defineGetter__("lf_strict", function() {
return this.__settings__.lf_strict;
......@@ -307,7 +307,7 @@ Frame.prototype.__defineSetter__("lf_strict", function(bool) {
if(typeof bool == "boolean")
this.__settings__.lf_strict=bool;
else
throw("non-boolean lf_strict: " + bool);
throw new Error("non-boolean lf_strict: " + bool);
});
Frame.prototype.__defineGetter__("scrollbars", function() {
return this.__settings__.scrollbars;
......@@ -316,7 +316,7 @@ Frame.prototype.__defineSetter__("scrollbars", function(bool) {
if(typeof bool == "boolean")
this.__settings__.scrollbars=bool;
else
throw("non-boolean scrollbars: " + bool);
throw new Error("non-boolean scrollbars: " + bool);
});
Frame.prototype.__defineGetter__("v_scroll", function() {
return this.__settings__.v_scroll;
......@@ -325,7 +325,7 @@ Frame.prototype.__defineSetter__("v_scroll", function(bool) {
if(typeof bool == "boolean")
this.__settings__.v_scroll=bool;
else
throw("non-boolean v_scroll: " + bool);
throw new Error("non-boolean v_scroll: " + bool);
});
Frame.prototype.__defineGetter__("word_wrap", function() {
return this.__settings__.word_wrap;
......@@ -334,7 +334,7 @@ Frame.prototype.__defineSetter__("word_wrap", function(bool) {
if(typeof bool == "boolean")
this.__settings__.word_wrap=bool;
else
throw("non-boolean word_wrap: " + bool);
throw new Error("non-boolean word_wrap: " + bool);
});
Frame.prototype.__defineGetter__("h_scroll", function() {
return this.__settings__.h_scroll;
......@@ -343,7 +343,7 @@ Frame.prototype.__defineSetter__("h_scroll", function(bool) {
if(typeof bool == "boolean")
this.__settings__.h_scroll=bool;
else
throw("non-boolean h_scroll: " + bool);
throw new Error("non-boolean h_scroll: " + bool);
});
Frame.prototype.__defineGetter__("is_open",function() {
return this.__properties__.open;
......@@ -355,7 +355,7 @@ Frame.prototype.__defineSetter__("atcodes", function(bool) {
if(typeof bool == "boolean")
this.__settings__.atcodes=bool;
else
throw("non-boolean atcode: " + bool);
throw new Error("non-boolean atcode: " + bool);
});
/* public methods */
......@@ -367,7 +367,7 @@ Frame.prototype.getData = function(x,y,use_offset) {
py += this.__position__.offset.y;
}
// if(!this.__properties__.data[py] || !this.__properties__.data[py][px])
// throw("Frame.getData() - invalid coordinates: " + px + "," + py);
// throw new Error("Frame.getData() - invalid coordinates: " + px + "," + py);
if(!this.__properties__.data[py] || !this.__properties__.data[py][px])
return new Char();
return this.__properties__.data[py][px];
......@@ -381,7 +381,7 @@ Frame.prototype.setData = function(x,y,ch,attr,use_offset) {
}
//I don't remember why I did this, but it was probably important at the time
//if(!this.__properties__.data[py] || !this.__properties__.data[py][px])
// throw("Frame.setData() - invalid coordinates: " + px + "," + py);
// throw new Error("Frame.setData() - invalid coordinates: " + px + "," + py);
if(!this.__properties__.data[py])
this.__properties__.data[py] = [];
if(!this.__properties__.data[py][px])
......@@ -820,13 +820,13 @@ Frame.prototype.load = function(filename,width,height) {
this.putmsg(lines.shift() + "\r\n");
break;
default:
throw("unsupported filetype");
throw new Error("unsupported filetype");
break;
}
}
Frame.prototype.load_bin = function(contents, width, height, offset) {
if(width == undefined || height == undefined)
throw("unknown graphic dimensions");
throw new Error("unknown graphic dimensions");
if(offset == undefined) offset = 0;
for(var y=0; y<height; y++) {
for(var x=0; x<width; x++) {
......@@ -1516,7 +1516,7 @@ Display.prototype.__defineSetter__("x", function(x) {
if(x == undefined)
this.__properties__.x = 1;
else if(isNaN(x))
throw("invalid x coordinate: " + x);
throw new Error("invalid x coordinate: " + x);
else
this.__properties__.x = Number(x);
});
......@@ -1527,7 +1527,7 @@ Display.prototype.__defineSetter__("y", function(y) {
if(y == undefined)
this.__properties__.y = 1;
else if(isNaN(y) || y < 1 || y > console.screen_rows)
throw("invalid y coordinate: " + y);
throw new Error("invalid y coordinate: " + y);
else
this.__properties__.y = Number(y);
});
......@@ -1538,7 +1538,7 @@ Display.prototype.__defineSetter__("width", function(width) {
if(width == undefined)
this.__properties__.width = console.screen_columns;
else if(isNaN(width) || (this.x + Number(width) - 1) > (console.screen_columns))
throw("invalid width: " + width);
throw new Error("invalid width: " + width);
else
this.__properties__.width = Number(width);
});
......@@ -1549,7 +1549,7 @@ Display.prototype.__defineSetter__("height", function(height) {
if(height == undefined)
this.__properties__.height = console.screen_rows;
else if(isNaN(height) || (this.y + Number(height) - 1) > (console.screen_rows))
throw("invalid height: " + height);
throw new Error("invalid height: " + height);
else
this.__properties__.height = Number(height);
});
......@@ -1763,7 +1763,7 @@ function Cursor(x,y,frame) {
if(frame instanceof Frame)
this.__properties__.frame = frame;
else
throw("the frame is not a frame");
throw new Error("the frame is not a frame");
this.x = x;
this.y = y;
......@@ -1774,7 +1774,7 @@ Cursor.prototype.__defineGetter__("x", function() {
});
Cursor.prototype.__defineSetter__("x", function(x) {
if(isNaN(x))
throw("invalid x coordinate: " + x);
throw new Error("invalid x coordinate: " + x);
this.__properties__.x = x;
});
Cursor.prototype.__defineGetter__("y", function() {
......@@ -1782,7 +1782,7 @@ Cursor.prototype.__defineGetter__("y", function() {
});
Cursor.prototype.__defineSetter__("y", function(y) {
if(isNaN(y))
throw("invalid y coordinate: " + y);
throw new Error("invalid y coordinate: " + y);
this.__properties__.y = y;
});
......@@ -1799,7 +1799,7 @@ function Offset(x,y,frame) {
if(frame instanceof Frame)
this.__properties__.frame = frame;
else
throw("the frame is not a frame");
throw new Error("the frame is not a frame");
this.x = x;
this.y = y;
......@@ -1810,7 +1810,7 @@ Offset.prototype.__defineGetter__("x", function() {
});
Offset.prototype.__defineSetter__("x", function(x) {
if(x == undefined)
throw("invalid x offset: " + x);
throw new Error("invalid x offset: " + x);
else if(x < 0)
x = 0;
this.__properties__.x = x;
......@@ -1820,7 +1820,7 @@ Offset.prototype.__defineGetter__("y", function() {
});
Offset.prototype.__defineSetter__("y", function(y) {
if(y == undefined)
throw("invalid y offset: " + y);
throw new Error("invalid y offset: " + y);
else if(y < 0)
y = 0;
this.__properties__.y = y;
......
......@@ -63,12 +63,12 @@ function NodeList(filename, warn)
});
if (!f.open("r"))
throw("Unable to open '"+f.name+"'.");
throw new Error("Unable to open '"+f.name+"'.");
// Validate first line...
var line = f.readln(2048);
if (line == undefined)
throw("Unable to read first line in '"+f.name+"'");
throw new Error("Unable to read first line in '"+f.name+"'");
var m;
if ((m=line.match(/^;A (.*) Nodelist for (.*) -- Day number ([0-9]+