add get fingerprint <id> command

This commit is contained in:
Kyle Spearrin 2018-11-16 10:02:22 -05:00
parent 4df35c1ad7
commit f4887b62c0
3 changed files with 30 additions and 3 deletions

2
jslib

@ -1 +1 @@
Subproject commit da47faca5c9a41f732136448461a06fc6e6fe023
Subproject commit 464bca8c4d745eb86bdb0b36e6e4a983caa3c891

View File

@ -3,6 +3,7 @@ import * as fet from 'node-fetch';
import { CipherType } from 'jslib/enums/cipherType';
import { ApiService } from 'jslib/abstractions/api.service';
import { AuditService } from 'jslib/abstractions/audit.service';
import { CipherService } from 'jslib/abstractions/cipher.service';
import { CollectionService } from 'jslib/abstractions/collection.service';
@ -39,11 +40,14 @@ import { SecureNote } from '../models/secureNote';
import { CliUtils } from '../utils';
import { Utils } from 'jslib/misc/utils';
export class GetCommand {
constructor(private cipherService: CipherService, private folderService: FolderService,
private collectionService: CollectionService, private totpService: TotpService,
private auditService: AuditService, private cryptoService: CryptoService,
private userService: UserService, private searchService: SearchService) { }
private userService: UserService, private searchService: SearchService,
private apiService: ApiService) { }
async run(object: string, id: string, cmd: program.Command): Promise<Response> {
if (id != null) {
@ -73,6 +77,8 @@ export class GetCommand {
return await this.getOrganization(id);
case 'template':
return await this.getTemplate(id);
case 'fingerprint':
return await this.getFingerprint(id);
default:
return Response.badRequest('Unknown object.');
}
@ -374,4 +380,23 @@ export class GetCommand {
const res = new TemplateResponse(template);
return Response.success(res);
}
private async getFingerprint(id: string) {
let fingerprint: string[] = null;
if (id === 'me') {
fingerprint = await this.cryptoService.getFingerprint(await this.userService.getUserId());
} else if (this.isGuid(id)) {
try {
const response = await this.apiService.getUserPublicKey(id);
const pubKey = Utils.fromB64ToArray(response.publicKey);
fingerprint = await this.cryptoService.getFingerprint(id, pubKey.buffer);
} catch { }
}
if (fingerprint == null) {
return Response.notFound();
}
const res = new StringResponse(fingerprint.join('-'));
return Response.success(res);
}
}

View File

@ -252,6 +252,7 @@ export class Program {
writeLn(' collection');
writeLn(' organization');
writeLn(' template');
writeLn(' fingerprint');
writeLn('');
writeLn(' Id:');
writeLn('');
@ -274,7 +275,8 @@ export class Program {
await this.exitIfLocked();
const command = new GetCommand(this.main.cipherService, this.main.folderService,
this.main.collectionService, this.main.totpService, this.main.auditService,
this.main.cryptoService, this.main.userService, this.main.searchService);
this.main.cryptoService, this.main.userService, this.main.searchService,
this.main.apiService);
const response = await command.run(object, id, cmd);
this.processResponse(response);
});