1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-22 11:45:59 +01:00

fix: remove TXT generation, separate save/verify steps, refs AC-2350 (#8540)

This commit is contained in:
Vincent Salucci 2024-04-08 14:32:14 -05:00 committed by GitHub
parent 18ae698f8d
commit c73372310b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 20 deletions

View File

@ -26,7 +26,7 @@
<bit-hint>{{ "domainNameInputHint" | i18n }}</bit-hint> <bit-hint>{{ "domainNameInputHint" | i18n }}</bit-hint>
</bit-form-field> </bit-form-field>
<bit-form-field> <bit-form-field *ngIf="data?.orgDomain">
<bit-label>{{ "dnsTxtRecord" | i18n }}</bit-label> <bit-label>{{ "dnsTxtRecord" | i18n }}</bit-label>
<input bitInput formControlName="txt" /> <input bitInput formControlName="txt" />
<bit-hint>{{ "dnsTxtRecordInputHint" | i18n }}</bit-hint> <bit-hint>{{ "dnsTxtRecordInputHint" | i18n }}</bit-hint>
@ -42,7 +42,7 @@
</bit-form-field> </bit-form-field>
<bit-callout <bit-callout
*ngIf="!data?.orgDomain?.verifiedDate" *ngIf="data?.orgDomain && !data?.orgDomain?.verifiedDate"
type="info" type="info"
title="{{ 'automaticDomainVerification' | i18n }}" title="{{ 'automaticDomainVerification' | i18n }}"
> >
@ -51,7 +51,10 @@
</div> </div>
<ng-container bitDialogFooter> <ng-container bitDialogFooter>
<button type="submit" bitButton bitFormButton buttonType="primary"> <button type="submit" bitButton bitFormButton buttonType="primary">
<span *ngIf="!data?.orgDomain?.verifiedDate">{{ "verifyDomain" | i18n }}</span> <span *ngIf="!data?.orgDomain">{{ "next" | i18n }}</span>
<span *ngIf="data?.orgDomain && !data?.orgDomain?.verifiedDate">{{
"verifyDomain" | i18n
}}</span>
<span *ngIf="data?.orgDomain?.verifiedDate">{{ "reverifyDomain" | i18n }}</span> <span *ngIf="data?.orgDomain?.verifiedDate">{{ "reverifyDomain" | i18n }}</span>
</button> </button>
<button bitButton buttonType="secondary" (click)="dialogRef.close()" type="button"> <button bitButton buttonType="secondary" (click)="dialogRef.close()" type="button">

View File

@ -13,7 +13,6 @@ import { CryptoFunctionService as CryptoFunctionServiceAbstraction } from "@bitw
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service"; import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { DialogService } from "@bitwarden/components"; import { DialogService } from "@bitwarden/components";
import { domainNameValidator } from "./validators/domain-name.validator"; import { domainNameValidator } from "./validators/domain-name.validator";
@ -90,17 +89,6 @@ export class DomainAddEditDialogComponent implements OnInit, OnDestroy {
// Edit // Edit
this.domainForm.patchValue(this.data.orgDomain); this.domainForm.patchValue(this.data.orgDomain);
this.domainForm.disable(); this.domainForm.disable();
} else {
// Add
// Figuring out the proper length of our DNS TXT Record value was fun.
// DNS-Based Service Discovery RFC: https://www.ietf.org/rfc/rfc6763.txt; see section 6.1
// Google uses 43 chars for their TXT record value: https://support.google.com/a/answer/2716802
// So, chose a magic # of 33 bytes to achieve at least that once converted to base 64 (47 char length).
const generatedTxt = `bw=${Utils.fromBufferToB64(
await this.cryptoFunctionService.randomBytes(33),
)}`;
this.txtCtrl.setValue(generatedTxt);
} }
this.setupFormListeners(); this.setupFormListeners();
@ -121,6 +109,7 @@ export class DomainAddEditDialogComponent implements OnInit, OnDestroy {
// End Form methods // End Form methods
// Async Form Actions // Async Form Actions
// Creates a new domain record. The DNS TXT Record will be generated server-side and returned in the response.
saveDomain = async (): Promise<void> => { saveDomain = async (): Promise<void> => {
if (this.domainForm.invalid) { if (this.domainForm.invalid) {
this.platformUtilsService.showToast("error", null, this.i18nService.t("domainFormInvalid")); this.platformUtilsService.showToast("error", null, this.i18nService.t("domainFormInvalid"));
@ -130,14 +119,14 @@ export class DomainAddEditDialogComponent implements OnInit, OnDestroy {
this.domainNameCtrl.disable(); this.domainNameCtrl.disable();
const request: OrganizationDomainRequest = new OrganizationDomainRequest( const request: OrganizationDomainRequest = new OrganizationDomainRequest(
this.txtCtrl.value,
this.domainNameCtrl.value, this.domainNameCtrl.value,
); );
try { try {
this.data.orgDomain = await this.orgDomainApiService.post(this.data.organizationId, request); this.data.orgDomain = await this.orgDomainApiService.post(this.data.organizationId, request);
// Patch the DNS TXT Record that was generated server-side
this.domainForm.controls.txt.patchValue(this.data.orgDomain.txt);
this.platformUtilsService.showToast("success", null, this.i18nService.t("domainSaved")); this.platformUtilsService.showToast("success", null, this.i18nService.t("domainSaved"));
await this.verifyDomain();
} catch (e) { } catch (e) {
this.handleDomainSaveError(e); this.handleDomainSaveError(e);
} }

View File

@ -1,9 +1,7 @@
export class OrganizationDomainRequest { export class OrganizationDomainRequest {
txt: string;
domainName: string; domainName: string;
constructor(txt: string, domainName: string) { constructor(domainName: string) {
this.txt = txt;
this.domainName = domainName; this.domainName = domainName;
} }
} }