First commit

This commit is contained in:
2024-09-26 23:59:03 +02:00
commit f3116a6876
53 changed files with 1822 additions and 0 deletions
@@ -0,0 +1,21 @@
{% load i18n %}
<div>
<div class="card mt-4 pt-2 ps-lg-2">
<h5 class="card-header">{% trans "Encryption testing" %}</h5>
<div class="card-body d-flex flex-column">
<p class="card-text">{% trans "The text will be automatically copied to your clipboard." %}</p>
<textarea class="form-control m-2" cols="50" rows="4" v-model="text" @keyup="encrypt(text)"></textarea>
<textarea class="form-control m-2" cols="50" rows="4" v-model="encrypted" disabled></textarea>
</div>
</div>
<div class="card mt-4 pt-2 ps-lg-2">
<h5 class="card-header">{% trans "Decryption testing" %}</h5>
<div class="card-body d-flex flex-column">
<p class="card-text">{% trans "The text will be automatically copied to your clipboard." %}</p>
<textarea class="form-control m-2" cols="50" rows="4" v-model="encrypted_text" @keyup="decrypt(encrypted_text)"></textarea>
<textarea class="form-control m-2" cols="50" rows="4" v-model="decrypted" disabled></textarea>
</div>
</div>
</div>
@@ -0,0 +1,34 @@
encryption_testing = {
template: "#encryption-testing",
props: ["crypto_key"],
data: function() {
return {
text: '',
encrypted: '',
encrypted_text: '',
decrypted: '',
}
},
methods: {
encrypt: function(data) {
var self = this;
encryptWithKey(this.crypto_key, data).then(e => {
self.encrypted = e;
navigator.clipboard.writeText(self.encrypted);
})
},
decrypt: function(data) {
var self = this;
decryptWithKey(this.crypto_key, data).then(e => {
self.decrypted = e;
navigator.clipboard.writeText(self.encrypted);
})
},
}
}
@@ -0,0 +1,18 @@
{% load i18n %}
<div class="card bg-warning mt-4 pt-2 ps-lg-2">
{% if user_settings.k356_key %}
<h5 class="card-header">{% trans "K356 is locked" %}</h5>
<div class="card-body">
<h5 class="card-title">{% trans "K356 needs an unlock..." %}</h5>
<p class="card-text">{% trans "Enter your personnal password in order to unlock your K356." %}</p>
<input class="form-control" type="password" v-model="password" @keyup.enter="generate_import_key(password)" autofocus>
</div>
{% else %}
<h5 class="card-header">{% trans "K356 creation" %}</h5>
<div class="card-body">
<p class="card-text">{% trans "Enter your personnal password in order to create your K356." %}</p>
<input class="form-control" type="password" v-model="password" @keyup.enter="generate_import_key(password)" autofocus>
</div>
{% endif %}
</div>
@@ -0,0 +1,109 @@
const rvalidate = Vue.resource(Urls["users:k356.validate"]);
k356_loading = {
template: "#k356-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 = "";
},
}
}