UNPKG

s-bit-agent

Version:

s.BitAgent is a simple Bitwarden CLI wrapper which provides a SSH2 Key Agent solution for Bitwarden.

80 lines 4.04 kB
"use strict"; 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.ImportCommand = void 0; const nest_commander_1 = require("nest-commander"); const fs_1 = require("fs"); const log_service_1 = require("../../shared/log.service"); const key_service_1 = require("../../shared/key.service"); const inquirer_service_1 = require("../../shared/inquirer.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 ImportCommand = class ImportCommand extends nest_commander_1.CommandRunner { constructor(logService, keyService, inquirerService, bitService, clientService) { super(); this.logService = logService; this.keyService = keyService; this.inquirerService = inquirerService; this.bitService = bitService; this.clientService = clientService; } async run(params) { const path = params[0]; if (!(0, fs_1.existsSync)(path)) this.logService.fatal(`File not found: ${path}`); let privateKey = (0, fs_1.readFileSync)(path, 'utf8'); let publicKey = ''; try { publicKey = this.keyService.generatePublicKey(privateKey, params[1]); } catch (ignored) { this.logService.warn('Error while generating public key, assuming private key is password protected'); const password = await this.inquirerService.password('Enter the password for the key'); privateKey = this.keyService.decryptPrivateKey(privateKey, password); publicKey = this.keyService.generatePublicKey(privateKey, params[1]); } this.logService.info('Read private key:', '***'); this.logService.info('Read public key:', publicKey); const session = await this.clientService.requestSession('Importing new private key'); if (!session) this.logService.fatal('No session available'); const data = new bitwarden_type_1.BitwardenKeyCreateItem(); data.name = params[1]; 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('Created new private key in the vault!'); } }; exports.ImportCommand = ImportCommand; exports.ImportCommand = ImportCommand = __decorate([ (0, nest_commander_1.SubCommand)({ name: 'import', arguments: '<file> <name>', description: 'Import a private key into the vault', }), __metadata("design:paramtypes", [log_service_1.LogService, key_service_1.KeyService, inquirer_service_1.InquirerService, bitwarden_service_1.BitwardenService, client_service_1.ClientService]) ], ImportCommand); //# sourceMappingURL=import.command.js.map