mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 00:03:56 +00:00
* send work * New method to update the last used index (#184) Instead of updating it every time you call getNext(), it will be updated in a separate call, to avoid updating the index when the cipher did not auto-fill correctly (e.g wrong frame) Fixes #1392 * added OnlyOrg to PolicyType enum (#183) * [Require SSO] Add policy type enumeration (#186) * Added SsoAuthentication policy type * Updated policy type name // added comments for clarification of what each type controls * [SSO] New user provision flow (#173) * Initial commit of new user sso flow * Adjusted stateSplit conditional per review * Add logging to lowdb storage service (#188) * Fix lint errors/warnings (#187) * remove password api * access id * makeSendKey Co-authored-by: Josep Marí <xusoo@users.noreply.github.com> Co-authored-by: Addison Beck <abeck@bitwarden.com> Co-authored-by: Vincent Salucci <26154748+vincentsalucci@users.noreply.github.com> Co-authored-by: Chad Scharf <3904944+cscharf@users.noreply.github.com>
141 lines
4.1 KiB
TypeScript
141 lines
4.1 KiB
TypeScript
import { CryptoService } from '../../abstractions/crypto.service';
|
|
|
|
import { SendType } from '../../enums/sendType';
|
|
|
|
import { Utils } from '../../misc/utils';
|
|
|
|
import { SendData } from '../data/sendData';
|
|
|
|
import { SendView } from '../view/sendView';
|
|
|
|
import { CipherString } from './cipherString';
|
|
import Domain from './domainBase';
|
|
import { SendFile } from './sendFile';
|
|
import { SendText } from './sendText';
|
|
|
|
export class Send extends Domain {
|
|
id: string;
|
|
accessId: string;
|
|
userId: string;
|
|
type: SendType;
|
|
name: CipherString;
|
|
notes: CipherString;
|
|
file: SendFile;
|
|
text: SendText;
|
|
key: CipherString;
|
|
maxAccessCount?: number;
|
|
accessCount: number;
|
|
revisionDate: Date;
|
|
expirationDate: Date;
|
|
deletionDate: Date;
|
|
password: string;
|
|
disabled: boolean;
|
|
|
|
constructor(obj?: SendData, alreadyEncrypted: boolean = false) {
|
|
super();
|
|
if (obj == null) {
|
|
return;
|
|
}
|
|
|
|
this.buildDomainModel(this, obj, {
|
|
id: null,
|
|
accessId: null,
|
|
userId: null,
|
|
name: null,
|
|
notes: null,
|
|
key: null,
|
|
}, alreadyEncrypted, ['id', 'accessId', 'userId']);
|
|
|
|
this.type = obj.type;
|
|
this.maxAccessCount = obj.maxAccessCount;
|
|
this.accessCount = obj.accessCount;
|
|
this.password = obj.password;
|
|
this.disabled = obj.disabled;
|
|
this.revisionDate = obj.revisionDate != null ? new Date(obj.revisionDate) : null;
|
|
this.deletionDate = obj.deletionDate != null ? new Date(obj.deletionDate) : null;
|
|
this.expirationDate = obj.expirationDate != null ? new Date(obj.expirationDate) : null;
|
|
|
|
switch (this.type) {
|
|
case SendType.Text:
|
|
this.text = new SendText(obj.text, alreadyEncrypted);
|
|
break;
|
|
case SendType.File:
|
|
this.file = new SendFile(obj.file, alreadyEncrypted);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
async decrypt(): Promise<SendView> {
|
|
const model = new SendView(this);
|
|
|
|
let cryptoService: CryptoService;
|
|
const containerService = (Utils.global as any).bitwardenContainerService;
|
|
if (containerService) {
|
|
cryptoService = containerService.getCryptoService();
|
|
} else {
|
|
throw new Error('global bitwardenContainerService not initialized.');
|
|
}
|
|
|
|
try {
|
|
model.key = await cryptoService.decryptToBytes(this.key, null);
|
|
model.cryptoKey = await cryptoService.makeSendKey(model.key);
|
|
} catch (e) {
|
|
// TODO: error?
|
|
}
|
|
|
|
await this.decryptObj(model, {
|
|
name: null,
|
|
notes: null,
|
|
}, null, model.cryptoKey);
|
|
|
|
switch (this.type) {
|
|
case SendType.File:
|
|
model.file = await this.file.decrypt(model.cryptoKey);
|
|
break;
|
|
case SendType.Text:
|
|
model.text = await this.text.decrypt(model.cryptoKey);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return model;
|
|
}
|
|
|
|
toSendData(userId: string): SendData {
|
|
const s = new SendData();
|
|
s.id = this.id;
|
|
s.accessId = this.accessId;
|
|
s.userId = userId;
|
|
s.maxAccessCount = this.maxAccessCount;
|
|
s.accessCount = this.accessCount;
|
|
s.disabled = this.disabled;
|
|
s.password = this.password;
|
|
s.revisionDate = this.revisionDate != null ? this.revisionDate.toISOString() : null;
|
|
s.deletionDate = this.deletionDate != null ? this.deletionDate.toISOString() : null;
|
|
s.expirationDate = this.expirationDate != null ? this.expirationDate.toISOString() : null;
|
|
s.type = this.type;
|
|
|
|
this.buildDataModel(this, s, {
|
|
name: null,
|
|
notes: null,
|
|
key: null,
|
|
});
|
|
|
|
switch (s.type) {
|
|
case SendType.File:
|
|
s.text = this.text.toSendTextData();
|
|
break;
|
|
case SendType.Text:
|
|
s.file = this.file.toSendFileData();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return s;
|
|
}
|
|
}
|