1
0
Fork 0

Implement Transit Decrypt Page.

This commit is contained in:
Kitteh 2021-04-17 10:39:07 +01:00
parent dc168e5604
commit 3fefdbc90d
7 changed files with 105 additions and 5 deletions

View file

@ -296,6 +296,25 @@ export async function transitEncrypt(baseMount, name, data) {
}
}
export async function transitDecrypt(baseMount, name, data) {
const request = new Request(getAPIURL() + removeDoubleSlash(`/v1/${baseMount}/decrypt/${name}`), {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Vault-Token': getToken()
},
body: JSON.stringify({ciphertext: data})
});
let response = await fetch(request);
if (!response.ok) {
let json = await response.json();
throw new Error(json.errors[0]);
} else {
let json = await response.json();
return json.data;
}
}
export async function getTOTPKeys(baseMount) {
const request = new Request(getAPIURL() + `/v1/${baseMount}/keys?list=true`, {

View file

@ -26,6 +26,7 @@ import {
TransitViewPage,
TransitViewSecretPage,
TransitEncryptPage,
TransitDecryptPage,
KeyValueViewPage,
KeyValueSecretsPage,
KeyValueVersionsPage,
@ -47,6 +48,7 @@ const pages = {
TRANSIT_VIEW: new TransitViewPage(),
TRANSIT_VIEW_SECRET: new TransitViewSecretPage(),
TRANSIT_ENCRYPT: new TransitEncryptPage(),
TRANSIT_DECRYPT: new TransitDecryptPage(),
KEY_VALUE_VIEW: new KeyValueViewPage(),
KEY_VALUE_SECRETS: new KeyValueSecretsPage(),
KEY_VALUE_VERSIONS: new KeyValueVersionsPage(),

View file

@ -0,0 +1,70 @@
import { Page } from "../types/Page.js";
import { transitDecrypt } from "../api.js";
import { setPageContent, setTitleElement, setErrorText } from "../pageUtils.js";
import { makeElement } from "../htmlUtils.js";
import { Margin } from "../elements/Margin.js";
import { CopyableModal } from "../elements/CopyableModal.js";
import UIkit from 'uikit/dist/js/uikit.min.js';
export class TransitDecryptPage extends Page {
constructor() {
super();
}
goBack() {
changePage(pages.TRANSIT_VIEW_SECRET);
}
async render() {
setTitleElement(pageState);
setPageContent(makeElement({
tag: "div"
}));
this.transitDecryptForm = makeElement({
tag: "form",
children: [
Margin(makeElement({
tag: "textarea",
class: ["uk-textarea", "uk-form-width-medium"],
attributes: {
placeholder: "Ciphertext",
name: "ciphertext",
}
})),
makeElement({
tag: "p",
id: "errorText",
class: "uk-text-danger"
}),
makeElement({
tag: "button",
class: ["uk-button", "uk-button-primary"],
text: "Decrypt",
attributes: {
type: "submit",
}
})
]
});
setPageContent(this.transitDecryptForm);
this.transitDecryptForm.addEventListener("submit", function (e) {
e.preventDefault();
this.transitEncryptFormHandler();
}.bind(this));
}
transitEncryptFormHandler() {
let formData = new FormData(this.transitDecryptForm);
transitDecrypt(pageState.currentBaseMount, pageState.currentSecret, formData.get("ciphertext")).then(res => {
let modal = CopyableModal("Decryption Result", res.plaintext);
pageContent.appendChild(modal);
UIkit.modal(modal).show();
}).catch(e => {
setErrorText(`API Error: ${e.message}`);
});
}
get name() {
return "Transit Decrypt";
}
}

View file

@ -12,8 +12,7 @@ export class TransitEncryptPage extends Page {
super();
}
goBack() {
pageState.currentSecret = "";
changePage(pages.TRANSIT_VIEW);
changePage(pages.TRANSIT_VIEW_SECRET);
}
async render() {
setTitleElement(pageState);

View file

@ -6,7 +6,7 @@ export class TransitViewSecretPage extends Page {
constructor() {
super();
}
goBack(){
goBack() {
changePage(pages.TRANSIT_VIEW);
}
@ -59,7 +59,12 @@ export class TransitViewSecretPage extends Page {
"lock",
_ => { changePage(pages.TRANSIT_ENCRYPT); }
),
this.makeTile("Decrypt", "Decrypt some cyphertext.", "mail"),
this.makeTile(
"Decrypt",
"Decrypt some cyphertext.",
"mail",
_ => { changePage(pages.TRANSIT_DECRYPT); }
),
]
}),
]

View file

@ -13,4 +13,5 @@ export { KeyValueSecretsEditPage } from "./KeyValueSecretsEdit.js";
export { PwGenPage } from "./PwGen.js";
export { TransitViewPage } from "./TransitView.js";
export { TransitViewSecretPage } from "./TransitViewSecret.js";
export { TransitEncryptPage } from "./TransitEncrypt.js";
export { TransitEncryptPage } from "./TransitEncrypt.js";
export { TransitDecryptPage } from "./TransitDecrypt.js";

View file

@ -10,5 +10,9 @@
padding-bottom: 10px !important;
padding-left: 10px !important;
}
.wrap-pre {
white-space: pre-wrap;
}
@import "./prism-nord.scss";
@import "./uikit.scss";