110 lines
3.0 KiB
JavaScript
110 lines
3.0 KiB
JavaScript
const rvalidate = Vue.resource(Urls["users:k356.validate"]);
|
|
|
|
Loading = {
|
|
template: "#Loading",
|
|
|
|
props: ["crypto_key"],
|
|
data: function() {
|
|
return {
|
|
password: '',
|
|
k356_fingerprint: "{{ user_settings.k356_fingerprint }}",
|
|
}
|
|
},
|
|
|
|
mounted: function() {},
|
|
|
|
methods: {
|
|
|
|
generate_import_key: function(password) {
|
|
|
|
if (password != null && password != "") {
|
|
|
|
var self = this;
|
|
window.crypto.subtle.importKey(
|
|
"raw",
|
|
(new TextEncoder()).encode(password),
|
|
"PBKDF2",
|
|
true,
|
|
["deriveKey"]
|
|
).then(pkey => {
|
|
|
|
window.crypto.subtle.deriveKey(
|
|
{
|
|
name: "PBKDF2",
|
|
salt: stringToArrayBuffer("salt"),
|
|
iterations: 250000,
|
|
hash: "SHA-256",
|
|
},
|
|
pkey,
|
|
{ name: "AES-GCM", length: 256 },
|
|
true,
|
|
["encrypt", "decrypt"]
|
|
).then(key => {
|
|
|
|
self.set_key(key);
|
|
|
|
}).catch(function(err) {
|
|
|
|
self.set_key(null);
|
|
|
|
});
|
|
}).catch(function(err) {
|
|
|
|
self.set_key(null);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.set_key(null);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
set_key: function(key) {
|
|
|
|
if (key) {
|
|
|
|
var self = this;
|
|
|
|
encryptWithKey({key: key, uuid: this.crypto_key.uuid}, this.crypto_key.uuid).then(efinger => {
|
|
|
|
self.$http.post(Urls["users:k356.validate"](), {fingerprint: efinger}).then(response => {
|
|
|
|
if (!response.data.ok) {
|
|
|
|
Swal.fire({title: response.data.error, icon: "error", showConfirmButton: false, toast: false});
|
|
|
|
} else {
|
|
|
|
self.$emit("update_key", key);
|
|
|
|
Swal.fire({title: "Successfully loaded K356!", icon: "success", position:"top-end", showConfirmButton: false, toast: true, timer: 1000});
|
|
|
|
}
|
|
}).catch(err => {
|
|
|
|
Swal.fire({title: "{{_('Error while verifying encryption check') | escapejs}}", icon: "error", showConfirmButton: false, toast: false});
|
|
|
|
});
|
|
}).catch(err => {
|
|
|
|
Swal.fire({title: "{{_('Error while encrypting verification') | escapejs}}", icon: "error", showConfirmButton: false, toast: false});
|
|
|
|
});
|
|
}
|
|
|
|
if (key == null) {
|
|
Swal.fire({title: "Error while loading K356!", icon: "error", showConfirmButton: false});
|
|
|
|
this.$emit("update_key", null);
|
|
}
|
|
|
|
this.password = "";
|
|
|
|
},
|
|
|
|
}
|
|
}
|