diff --git a/jslib b/jslib index da47faca5c..464bca8c4d 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit da47faca5c9a41f732136448461a06fc6e6fe023 +Subproject commit 464bca8c4d745eb86bdb0b36e6e4a983caa3c891 diff --git a/src/commands/get.command.ts b/src/commands/get.command.ts index 28c4e9b6ba..b4c67ae403 100644 --- a/src/commands/get.command.ts +++ b/src/commands/get.command.ts @@ -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 { 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); + } } diff --git a/src/program.ts b/src/program.ts index 94857ace68..44023755cd 100644 --- a/src/program.ts +++ b/src/program.ts @@ -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); });