mirror of
https://github.com/bitwarden/browser
synced 2025-12-14 15:23:33 +00:00
add get fingerprint <id> command
This commit is contained in:
2
jslib
2
jslib
Submodule jslib updated: da47faca5c...464bca8c4d
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user