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 = {}; }
|
2016-06-25 00:29:34 +00:00
|
|
|
this._privKey = optionsArg.private;
|
|
|
|
this._pubKey = optionsArg.public;
|
|
|
|
this._hostVar = optionsArg.host;
|
|
|
|
this._authorized = optionsArg.authorized;
|
2016-05-31 17:16:45 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
Object.defineProperty(SshKey.prototype, "host", {
|
2016-06-25 00:29:34 +00:00
|
|
|
// this.host
|
2016-05-31 17:16:45 +00:00
|
|
|
get: function () {
|
2016-06-25 00:29:34 +00:00
|
|
|
return this._hostVar;
|
2016-05-31 17:16:45 +00:00
|
|
|
},
|
|
|
|
set: function (hostArg) {
|
2016-06-25 00:29:34 +00:00
|
|
|
this._hostVar = hostArg;
|
2016-05-31 17:16:45 +00:00
|
|
|
},
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
;
|
2016-06-25 00:29:34 +00:00
|
|
|
;
|
|
|
|
Object.defineProperty(SshKey.prototype, "privKey", {
|
|
|
|
// this.privKey
|
2016-05-31 17:16:45 +00:00
|
|
|
get: function () {
|
2016-06-25 00:29:34 +00:00
|
|
|
return this._privKey;
|
2016-05-31 17:16:45 +00:00
|
|
|
},
|
|
|
|
set: function (privateKeyArg) {
|
2016-06-25 00:29:34 +00:00
|
|
|
this._privKey = privateKeyArg;
|
2016-05-31 17:16:45 +00:00
|
|
|
},
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
;
|
2016-06-25 00:29:34 +00:00
|
|
|
;
|
|
|
|
Object.defineProperty(SshKey.prototype, "privKeyBase64", {
|
|
|
|
// this.privKeyBase64
|
2016-05-31 17:16:45 +00:00
|
|
|
get: function () {
|
2016-06-25 00:29:34 +00:00
|
|
|
return plugins.base64.encode(this._privKey);
|
2016-05-31 17:16:45 +00:00
|
|
|
},
|
2016-06-13 22:11:20 +00:00
|
|
|
set: function (privateKeyArg) {
|
2016-06-25 00:29:34 +00:00
|
|
|
this._privKey = plugins.base64.decode(privateKeyArg);
|
2016-06-13 22:11:20 +00:00
|
|
|
},
|
2016-05-31 17:16:45 +00:00
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
2016-06-25 00:29:34 +00:00
|
|
|
Object.defineProperty(SshKey.prototype, "pubKey", {
|
|
|
|
// this.pubKey
|
2016-05-31 17:16:45 +00:00
|
|
|
get: function () {
|
2016-06-25 00:29:34 +00:00
|
|
|
return this._pubKey;
|
2016-05-31 17:16:45 +00:00
|
|
|
},
|
|
|
|
set: function (publicKeyArg) {
|
2016-06-25 00:29:34 +00:00
|
|
|
this._pubKey = publicKeyArg;
|
2016-05-31 17:16:45 +00:00
|
|
|
},
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
2016-06-25 00:29:34 +00:00
|
|
|
;
|
|
|
|
Object.defineProperty(SshKey.prototype, "pubKeyBase64", {
|
|
|
|
// this.pubKeyBase64
|
2016-05-31 17:16:45 +00:00
|
|
|
get: function () {
|
2016-06-25 00:29:34 +00:00
|
|
|
return plugins.base64.encode(this._pubKey);
|
2016-05-31 17:16:45 +00:00
|
|
|
},
|
2016-06-13 22:11:20 +00:00
|
|
|
set: function (publicKeyArg) {
|
2016-06-25 00:29:34 +00:00
|
|
|
this._pubKey = plugins.base64.decode(publicKeyArg);
|
2016-06-13 22:11:20 +00:00
|
|
|
},
|
2016-05-31 17:16:45 +00:00
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
2016-06-25 13:30:57 +00:00
|
|
|
Object.defineProperty(SshKey.prototype, "authorized", {
|
|
|
|
get: function () {
|
|
|
|
return this._authorized;
|
|
|
|
},
|
|
|
|
set: function (authorizedArg) {
|
|
|
|
this._authorized = authorizedArg;
|
|
|
|
},
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
2016-05-31 17:16:45 +00:00
|
|
|
Object.defineProperty(SshKey.prototype, "type", {
|
|
|
|
get: function () {
|
2016-06-25 00:29:34 +00:00
|
|
|
if (this._privKey && this._pubKey) {
|
2016-05-31 17:16:45 +00:00
|
|
|
return "duplex";
|
|
|
|
}
|
2016-06-25 00:29:34 +00:00
|
|
|
else if (this._privKey) {
|
2016-05-31 17:16:45 +00:00
|
|
|
return "private";
|
|
|
|
}
|
2016-06-25 00:29:34 +00:00
|
|
|
else if (this._pubKey) {
|
2016-05-31 17:16:45 +00:00
|
|
|
return "public";
|
|
|
|
}
|
|
|
|
},
|
2016-06-25 00:29:34 +00:00
|
|
|
set: function (someVlueArg) {
|
|
|
|
console.log("the type of an SshKey connot be set. This value is autpcomputed.");
|
|
|
|
},
|
2016-05-31 17:16:45 +00:00
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
;
|
2016-06-25 00:29:34 +00:00
|
|
|
// methods
|
|
|
|
SshKey.prototype.read = function (filePathArg) {
|
|
|
|
};
|
2016-06-25 13:30:57 +00:00
|
|
|
SshKey.prototype.store = function (dirPathArg) {
|
|
|
|
plugins.fs.ensureDirSync(dirPathArg);
|
|
|
|
var fileNameBase = this.host;
|
|
|
|
if (this._privKey) {
|
|
|
|
plugins.smartfile.memory.toFsSync(this._privKey, plugins.path.join(dirPathArg, fileNameBase));
|
2016-05-31 17:16:45 +00:00
|
|
|
}
|
2016-06-25 13:30:57 +00:00
|
|
|
;
|
|
|
|
if (this._pubKey) {
|
|
|
|
plugins.smartfile.memory.toFsSync(this._pubKey, plugins.path.join(dirPathArg, fileNameBase + ".pub"));
|
2016-05-31 17:16:45 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
return SshKey;
|
|
|
|
}());
|
|
|
|
exports.SshKey = SshKey;
|
2016-06-25 00:29:34 +00:00
|
|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