node-firewalla
Version:
Package to talk your firewalla box & API
49 lines (48 loc) • 1.9 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FWGroup = void 0;
const SecureUtil_js_1 = __importDefault(require("../utils/SecureUtil.js"));
class FWGroup {
/**
* @param {string} gid - Group ID
* @param {string} eid - ETP ID, I think?
* @param {string} aid - ?? unknown
* @param {string} symmetricKeyCipher - The symmetric key for communication, encrypted using the public key of the ETP token
* @param {string} localIp - The local IP of the FWGroup
*/
constructor(gid, eid, aid, symmetricKeyCipher, name, localIp) {
this.gid = gid;
this.eid = eid;
this.aid = aid;
this.name = name;
this.localIp = localIp;
this.symmetricKeyCipher = symmetricKeyCipher;
}
/**
* @param {string} obj - The JSON from the ETP API refering to a FWGroup
* @param {string} localIp - The local IP of the FWGroup
*/
static fromJson(obj, localIp) {
let { _id, eid, aid, symmetricKeys, name } = obj;
return new FWGroup(_id, eid, aid, symmetricKeys[0].key, name, localIp);
}
getSymmetricKey() {
if (!this.symmetricKeyPlain) {
this.symmetricKeyPlain = SecureUtil_js_1.default.rsaDecrypt(this.symmetricKeyCipher);
}
return this.symmetricKeyPlain;
}
hasLocalIp() {
return typeof this.localIp === 'string';
}
getMessageUrl() {
if (!this.hasLocalIp()) {
return `https://firewalla.encipher.io/app/api/v2/service/message/${this.aid}/${this.gid}/eptgroup/${this.gid}`;
}
return `http://${this.localIp}:8833/v1/encipher/message/${this.gid}`;
}
}
exports.FWGroup = FWGroup;