2016-05-31 17:16:45 +00:00
|
|
|
"use strict";
|
|
|
|
require("typings-global");
|
|
|
|
var plugins = require("./smartssh.plugins");
|
|
|
|
var SshKey = (function () {
|
|
|
|
function SshKey(optionsArg) {
|
|
|
|
if (optionsArg === void 0) { optionsArg = {}; }
|
|
|
|
this.privKey = optionsArg.private;
|
|
|
|
this.pubKey = optionsArg.public;
|
|
|
|
this.hostVar = optionsArg.host;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
Object.defineProperty(SshKey.prototype, "host", {
|
|
|
|
// getters
|
|
|
|
get: function () {
|
|
|
|
return this.hostVar;
|
|
|
|
},
|
|
|
|
// setters
|
|
|
|
set: function (hostArg) {
|
|
|
|
this.hostVar = hostArg;
|
|
|
|
},
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
;
|
|
|
|
Object.defineProperty(SshKey.prototype, "privateKey", {
|
|
|
|
get: function () {
|
|
|
|
return this.privKey;
|
|
|
|
},
|
|
|
|
set: function (privateKeyArg) {
|
|
|
|
this.privKey = privateKeyArg;
|
|
|
|
},
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
;
|
|
|
|
Object.defineProperty(SshKey.prototype, "privateKeyBase64", {
|
|
|
|
get: function () {
|
|
|
|
return plugins.base64.encode(this.privKey);
|
|
|
|
},
|
2016-06-13 22:11:20 +00:00
|
|
|
set: function (privateKeyArg) {
|
|
|
|
this.privKey = plugins.base64.decode(privateKeyArg);
|
|
|
|
},
|
2016-05-31 17:16:45 +00:00
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
Object.defineProperty(SshKey.prototype, "publicKey", {
|
|
|
|
get: function () {
|
2016-06-01 02:18:31 +00:00
|
|
|
return this.pubKey;
|
2016-05-31 17:16:45 +00:00
|
|
|
},
|
|
|
|
set: function (publicKeyArg) {
|
|
|
|
this.pubKey = publicKeyArg;
|
|
|
|
},
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
Object.defineProperty(SshKey.prototype, "publicKeyBase64", {
|
|
|
|
get: function () {
|
|
|
|
return plugins.base64.encode(this.pubKey);
|
|
|
|
},
|
2016-06-13 22:11:20 +00:00
|
|
|
set: function (publicKeyArg) {
|
|
|
|
this.pubKey = plugins.base64.decode(publicKeyArg);
|
|
|
|
},
|
2016-05-31 17:16:45 +00:00
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
Object.defineProperty(SshKey.prototype, "type", {
|
|
|
|
get: function () {
|
|
|
|
if (this.privKey && this.pubKey) {
|
|
|
|
return "duplex";
|
|
|
|
}
|
|
|
|
else if (this.privKey) {
|
|
|
|
return "private";
|
|
|
|
}
|
|
|
|
else if (this.pubKey) {
|
|
|
|
return "public";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
;
|
|
|
|
;
|
|
|
|
;
|
|
|
|
;
|
|
|
|
SshKey.prototype.store = function (filePathArg) {
|
|
|
|
var filePathObj = plugins.path.parse(filePathArg);
|
|
|
|
if (filePathObj.ext = ".priv") {
|
|
|
|
plugins.smartfile.memory.toFsSync(this.privKey, { fileName: filePathObj.name + filePathObj.ext, filePath: filePathObj.dir });
|
|
|
|
}
|
|
|
|
else if (filePathObj.ext = ".pub") {
|
|
|
|
plugins.smartfile.memory.toFsSync(this.pubKey, { fileName: filePathObj.name + filePathObj.ext, filePath: filePathObj.dir });
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
plugins.fs.ensureDirSync(filePathObj.dir);
|
|
|
|
this.store(plugins.path.join(filePathObj.dir, "key.priv")); // call this function recursivly
|
2016-06-13 22:27:55 +00:00
|
|
|
this.store(plugins.path.join(filePathObj.dir, "key.pub")); // call this function recursivly
|
2016-05-31 17:16:45 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
return SshKey;
|
|
|
|
}());
|
|
|
|
exports.SshK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