Added verification to contact form

This commit is contained in:
Brandon Rozek 2024-12-30 19:27:51 -05:00
parent bd7e11b421
commit 6c189eb8f2
No known key found for this signature in database
GPG key ID: DFB0E78F805F4567
2 changed files with 65 additions and 18 deletions

View file

@ -0,0 +1,39 @@
{{- $openPGP := resources.Get "js/openpgp.min.js" -}}
<script src="{{ $openPGP.Permalink }}"></script>
<textarea id="pgpsignedtext" class="pgpform" style="width: 100%; min-height: 10rem;"></textarea>
<button class="pgpverifybutton" onclick="verify()">Verify</button>
<br/>
Verification Result:
<pre id="pgpverifyresult" class="pgpform"></pre>
<script>
async function verify() {
let resultarea = document.querySelector('#pgpverifyresult');
resultarea.textContent = "";
let textarea = document.querySelector("#pgpsignedtext");
if (textarea.value.length == 0) {
return;
}
let pubKeyURL = "{{ .Get 0 }}";
let pubKey;
try {
const response = await fetch(pubKeyURL);
const text = await response.text();
pubKey = await openpgp.readKey({ armoredKey: text });
} catch {
resultarea.textContent = "Error: Unable to obtain key";
}
try {
const message = await openpgp.readCleartextMessage({ cleartextMessage: textarea.value });
const verifyResult = await openpgp.verify({message: message, verificationKeys: pubKey});
const validResult = await verifyResult.signatures[0].verified;
resultarea.textContent = (validResult)? "Valid": "Invalid";
} catch {
resultarea.textContent = "Invalid";
}
}
</script>