From 72758a388880fe0b21422e9890c3d2913cbc7489 Mon Sep 17 00:00:00 2001
From: Matthew Irish
Date: Mon, 19 Nov 2018 09:55:02 -0600
Subject: [PATCH 1/3] use the OTP that the server provides instead of
generating one in the JS client
---
ui/app/adapters/cluster.js | 2 +-
ui/app/components/shamir-flow.js | 39 ++---
ui/app/templates/components/shamir-flow.hbs | 171 ++++++++------------
3 files changed, 81 insertions(+), 131 deletions(-)
diff --git a/ui/app/adapters/cluster.js b/ui/app/adapters/cluster.js
index c806bdd1c24d..8f0fe15bd415 100644
--- a/ui/app/adapters/cluster.js
+++ b/ui/app/adapters/cluster.js
@@ -180,7 +180,7 @@ export default ApplicationAdapter.extend({
generateDrOperationToken(data, options) {
const verb = options && options.checkStatus ? 'GET' : 'PUT';
let url = `${this.buildURL()}/replication/dr/secondary/generate-operation-token/`;
- if (!data || data.pgp_key || data.otp) {
+ if (!data || data.pgp_key || data.attempt) {
// start the generation
url = url + 'attempt';
} else {
diff --git a/ui/app/components/shamir-flow.js b/ui/app/components/shamir-flow.js
index 3d915b6d87ae..8e89f4db95a0 100644
--- a/ui/app/components/shamir-flow.js
+++ b/ui/app/components/shamir-flow.js
@@ -3,7 +3,6 @@ import { gt } from '@ember/object/computed';
import { camelize } from '@ember/string';
import Component from '@ember/component';
import { get, computed } from '@ember/object';
-import base64js from 'base64-js';
const DEFAULTS = {
key: null,
@@ -62,18 +61,18 @@ export default Component.extend(DEFAULTS, {
hasProgress: gt('progress', 0),
actionSuccess(resp) {
- let { onUpdate, isComplete, onShamirSuccess, thresholdPath } = this.getProperties(
- 'onUpdate',
- 'isComplete',
- 'onShamirSuccess',
- 'thresholdPath'
- );
+ let { onUpdate, isComplete, onShamirSuccess, thresholdPath } = this;
let threshold = get(resp, thresholdPath);
let props = {
...resp,
threshold,
};
this.stopLoading();
+ // if we have an OTP, but update doesn't include one,
+ // we don't want to null it out
+ if (this.otp && !props.otp) {
+ delete props.otp;
+ }
this.setProperties(props);
onUpdate(props);
if (isComplete(props)) {
@@ -91,19 +90,11 @@ export default Component.extend(DEFAULTS, {
}
},
- generateStep: computed('generateWithPGP', 'haveSavedPGPKey', 'otp', 'pgp_key', function() {
- let { generateWithPGP, otp, pgp_key, haveSavedPGPKey } = this.getProperties(
- 'generateWithPGP',
- 'otp',
- 'pgp_key',
- 'haveSavedPGPKey'
- );
- if (!generateWithPGP && !pgp_key && !otp) {
+ generateStep: computed('generateWithPGP', 'haveSavedPGPKey', 'pgp_key', function() {
+ let { generateWithPGP, pgp_key, haveSavedPGPKey } = this;
+ if (!generateWithPGP && !pgp_key) {
return 'chooseMethod';
}
- if (otp) {
- return 'beginGenerationWithOTP';
- }
if (generateWithPGP) {
if (pgp_key && haveSavedPGPKey) {
return 'beginGenerationWithPGP';
@@ -133,7 +124,7 @@ export default Component.extend(DEFAULTS, {
}
return {
- otp: data.otp,
+ attempt: data.attempt,
};
},
@@ -144,6 +135,7 @@ export default Component.extend(DEFAULTS, {
this.set('loading', true);
const adapter = this.get('store').adapterFor('cluster');
const method = adapter[action];
+
method
.call(adapter, data, { checkStatus })
.then(resp => this.actionSuccess(resp), (...args) => this.actionError(...args));
@@ -164,15 +156,12 @@ export default Component.extend(DEFAULTS, {
},
startGenerate(data) {
+ if (this.generateAction) {
+ data.attempt = true;
+ }
this.attemptProgress(this.extractData(data));
},
- generateOTP() {
- const bytes = new window.Uint8Array(16);
- window.crypto.getRandomValues(bytes);
- this.set('otp', base64js.fromByteArray(bytes));
- },
-
setKey(_, keyFile) {
this.set('pgp_key', keyFile.value);
this.set('pgpKeyFile', keyFile);
diff --git a/ui/app/templates/components/shamir-flow.hbs b/ui/app/templates/components/shamir-flow.hbs
index 21bcb6def62f..91a3302e6b38 100644
--- a/ui/app/templates/components/shamir-flow.hbs
+++ b/ui/app/templates/components/shamir-flow.hbs
@@ -13,10 +13,7 @@
If you entered a One Time Password, you can use the Vault CLI to decode the Token:
@@ -33,119 +30,83 @@
{{else if (and generateAction (not started))}}
-