This commit is contained in:
2024-09-28 17:37:29 +02:00
parent 8dfafa9404
commit fb4d566007
64 changed files with 32325 additions and 573 deletions
@@ -5,7 +5,8 @@
<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="text" @keyup="encrypt_text(text)"></textarea>
<p class="card-text text-danger" v-if="encryption_error">[[ encryption_error ]]</p>
<textarea class="form-control m-2" cols="50" rows="4" v-model="encrypted" disabled></textarea>
</div>
</div>
@@ -14,7 +15,8 @@
<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="encrypted_text" @keyup="decrypt_text(encrypted_text)"></textarea>
<p class="card-text text-danger" v-if="decryption_error">[[ decryption_error ]]</p>
<textarea class="form-control m-2" cols="50" rows="4" v-model="decrypted" disabled></textarea>
</div>
</div>
@@ -1,34 +1,36 @@
EncryptionTesting = {
template: "#EncryptionTesting",
props: ["crypto_key"],
router_path: "/EncryptionTesting",
delimiters: ["[[", "]]"],
props: [],
data: function() {
return {
text: '',
encrypted: '',
encrypted_text: '',
decrypted: '',
decryption_error: '',
encryption_error: '',
}
},
methods: {
encrypt: function(data) {
var self = this;
encryptWithKey(this.crypto_key, data).then(e => {
self.encrypted = e;
navigator.clipboard.writeText(self.encrypted);
})
async encrypt_text (data) {
try {
this.encrypted = await this.encrypt(data)
this.encryption_error = ""
} catch (err) {
this.encryption_error = "{{_('Error while encryption of message.') | escapejs}}"
}
},
decrypt: function(data) {
var self = this;
decryptWithKey(this.crypto_key, data).then(e => {
self.decrypted = e;
navigator.clipboard.writeText(self.encrypted);
})
async decrypt_text (data) {
try {
this.decrypted = await this.decrypt(data)
this.decryption_error = ""
} catch (err) {
this.decryption_error = "{{_('Error while decryption of message.') | escapejs}}"
}
},
}
}
@@ -1,18 +1,10 @@
{% 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 %}
<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_aes_key(password)" autofocus>
</div>
</div>
+9 -92
View File
@@ -1,108 +1,25 @@
const rvalidate = Vue.resource(Urls["users:k356.validate"]);
Loading = {
template: "#Loading",
router_path: "/",
props: ["crypto_key"],
props: [],
data: function() {
return {
password: '',
k356_fingerprint: "{{ user_settings.k356_fingerprint }}",
}
},
mounted: function() {},
mounted: function() {
// FIX: Remove this, this is the key for debugging
this.generate_aes_key('asd')
},
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 = "";
async generate_aes_key (password) {
const key = await this.deriveKeyFromPassphrase(password, "{{ user_setting.id }}--aes")
this.$emit("update_key", key)
},
}
+9 -2
View File
@@ -1,9 +1,16 @@
from django import template
from django.utils.html import mark_safe
register = template.Library()
@register.simple_tag(takes_context=True)
def define(context, key, value):
context.dicts[0][key] = value
def define(context, key, *args):
if len(args) == 1:
context.dicts[0][key] = args[0]
else:
context.dicts[0][key] = [mark_safe(arg) for arg in args]
return ""