s-bit-agent
Version:
s.BitAgent is a simple Bitwarden CLI wrapper which provides a SSH2 Key Agent solution for Bitwarden.
93 lines • 4.5 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NewCommand = void 0;
const nest_commander_1 = require("nest-commander");
const log_service_1 = require("../../shared/log.service");
const key_service_1 = require("../../shared/key.service");
const bitwarden_service_1 = require("../../bitwarden/bitwarden.service");
const client_service_1 = require("../../icp/client.service");
const bitwarden_type_1 = require("../../bitwarden/bitwarden.type");
let NewCommand = class NewCommand extends nest_commander_1.CommandRunner {
constructor(logService, keyService, bitService, clientService) {
super();
this.logService = logService;
this.keyService = keyService;
this.bitService = bitService;
this.clientService = clientService;
}
parseModulus(modulus) {
return modulus;
}
getModulusChoices() {
return Object.keys(key_service_1.SUPPORTED_MODULI).filter((x) => typeof key_service_1.SUPPORTED_MODULI[x] === 'string');
}
async run(params, options) {
if (!Object.keys(key_service_1.SUPPORTED_MODULI)
.filter((x) => typeof key_service_1.SUPPORTED_MODULI[x] === 'string')
.includes(options.modulus))
this.logService.fatal('Invalid modulus');
const privateKey = this.keyService.generateRSAKey(Number(options.modulus));
this.logService.info('Generated private key:', '***');
const publicKey = this.keyService.generatePublicKey(privateKey, params[0]);
this.logService.info('Generated public key:', publicKey);
const session = await this.clientService.requestSession('Generate new private key');
if (!session)
this.logService.fatal('No session available');
const data = new bitwarden_type_1.BitwardenKeyCreateItem();
data.name = params[0];
data.notes = publicKey;
data.secureNote = privateKey;
data.fields = [
{ name: 'custom-type', value: 'ssh-key', type: bitwarden_type_1.BitwardenItemType.STRING },
{ name: 'public-key', value: publicKey, type: bitwarden_type_1.BitwardenItemType.STRING },
{
name: 'private-key',
value: privateKey,
type: bitwarden_type_1.BitwardenItemType.PASSWORD,
},
];
this.bitService.create(data, session);
this.logService.info('Imported private key into the vault!');
}
};
exports.NewCommand = NewCommand;
__decorate([
(0, nest_commander_1.Option)({
name: 'modulus',
flags: '-m, --modulus <modolus>',
description: 'ModUlus for the key pair',
defaultValue: '3072',
choices: Object.keys(key_service_1.SUPPORTED_MODULI).filter((x) => typeof key_service_1.SUPPORTED_MODULI[x] === 'string'),
required: true,
}),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", void 0)
], NewCommand.prototype, "parseModulus", null);
__decorate([
(0, nest_commander_1.OptionChoiceFor)({ name: 'modulus' }),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], NewCommand.prototype, "getModulusChoices", null);
exports.NewCommand = NewCommand = __decorate([
(0, nest_commander_1.SubCommand)({
name: 'new',
arguments: '<name>',
description: 'Generate a new key pair and import it into the vault',
}),
__metadata("design:paramtypes", [log_service_1.LogService,
key_service_1.KeyService,
bitwarden_service_1.BitwardenService,
client_service_1.ClientService])
], NewCommand);
//# sourceMappingURL=new.command.js.map