-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merges phoebus-84-master, adds local keystore directory import into WASM
- Loading branch information
Showing
3 changed files
with
217 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,112 +1,118 @@ | ||
<html> | ||
<head> | ||
<title>Go<>JS Demo</title> | ||
<meta charset="utf-8"/> | ||
<script type="application/javascript" src="wasm_exec.js"></script> | ||
<script type="application/javascript" src="pure.js"></script> | ||
</head> | ||
<body> | ||
<h2>DNS</h2> | ||
<h3>DOH Resolver</h3> | ||
<p> | ||
<input type="text" id="query-name" placeholder="mythingymajig.zenr.io"> | ||
<input type="text" id="query-type" placeholder="A"> | ||
<button onclick="renderQuery()">Resolve</button> | ||
<pre id="query-result"></pre> | ||
</p> | ||
|
||
<h2>DNS Keys</h2> | ||
<h3>List Keystore</h3> | ||
<button onclick="listKeys()">Update</button> | ||
<button onclick="listKeysWithStatus()">Update with DNS Status</button> | ||
<div id="existing-keys"></div> | ||
|
||
|
||
<h3>Request</h3> | ||
<p> | ||
<input type="text" id="new-name" placeholder="mythingymajig.zenr.io"> | ||
<button onclick="requestKey()">Request new Key</button> | ||
</p> | ||
<h3>Search Keystore for Key to sign update for a given Subdomain</h3> | ||
<p> | ||
<input type="text" id="keys-for-domain" placeholder="mythingymajig.zenr.io"> | ||
<button onclick="getKeysForDomain()">Find key in keystore</button> | ||
<div id="domain-key"></div> | ||
</p> | ||
<h3>Find DOH Endpoint for a given Subdomain</h3> | ||
<p> | ||
<input type="text" id="doh-for-domain" placeholder="mythingymajig.zenr.io"> | ||
<button onclick="findDOHEndpoint()">Find DOH endpoint</button> | ||
<div id="domain-doh-endpoint"></div> | ||
</p> | ||
<h3>Import Key pair files from filesystem into Browser Keystore</h3> | ||
<p> | ||
<input type="file" id="input-key" accept=".key"/> | ||
<input type="file" id="input-private" accept=".private"/> | ||
<div id="imported-key"></div> | ||
</p> | ||
<script> | ||
/// Import Key from file pair | ||
/// | ||
const streamToText = async (blob) => { | ||
const readableStream = await blob.getReader(); | ||
const chunk = await readableStream.read(); | ||
|
||
return new TextDecoder('utf-8').decode(chunk.value); | ||
}; | ||
|
||
const bufferToText = (buffer) => { | ||
const bufferByteLength = buffer.byteLength; | ||
const bufferUint8Array = new Uint8Array(buffer, 0, bufferByteLength); | ||
|
||
return new TextDecoder().decode(bufferUint8Array); | ||
}; | ||
|
||
document.getElementById('input-key').addEventListener('change', function(e) { | ||
let file = document.getElementById('input-key').files[0]; | ||
|
||
(async () => { | ||
const fileContent = await file.text(); | ||
|
||
console.log('.text()', fileContent); | ||
|
||
const fileContentStream = await file.stream(); | ||
|
||
console.log('.stream()', await streamToText(fileContentStream)); | ||
|
||
const buffer = await file.arrayBuffer(); | ||
|
||
console.log('.buffer()', bufferToText(buffer)); | ||
|
||
const fileSliceBlob = file.slice(0, file.length); | ||
const fileSliceBlobStream = await fileSliceBlob.stream(); | ||
|
||
console.log('.slice() and .stream()', await streamToText(fileSliceBlobStream)); | ||
})(); | ||
}); | ||
|
||
document.getElementById('input-private').addEventListener('change', function(e) { | ||
let file = document.getElementById('input-private').files[0]; | ||
|
||
(async () => { | ||
const fileContent = await file.text(); | ||
|
||
console.log('.text()', fileContent); | ||
|
||
const fileContentStream = await file.stream(); | ||
|
||
console.log('.stream()', await streamToText(fileContentStream)); | ||
|
||
const buffer = await file.arrayBuffer(); | ||
|
||
console.log('.buffer()', bufferToText(buffer)); | ||
|
||
const fileSliceBlob = file.slice(0, file.length); | ||
const fileSliceBlobStream = await fileSliceBlob.stream(); | ||
|
||
console.log('.slice() and .stream()', await streamToText(fileSliceBlobStream)); | ||
})(); | ||
}); | ||
</script> | ||
</body> | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Go<>JS Demo</title> | ||
<script type="application/javascript" src="wasm_exec.js"></script> | ||
<script type="application/javascript" src="pure.js"></script> | ||
</head> | ||
<body> | ||
<h2>DNS</h2> | ||
<h3>DOH Resolver</h3> | ||
<p> | ||
<input type="text" id="query-name" placeholder="mythingymajig.zenr.io"> | ||
<input type="text" id="query-type" placeholder="A"> | ||
<button onclick="renderQuery()">Resolve</button> | ||
<pre id="query-result"></pre> | ||
</p> | ||
|
||
<h2>DNS Keys</h2> | ||
<h3>List Keystore</h3> | ||
<button onclick="listKeys()">Update</button> | ||
<button onclick="listKeysWithStatus()">Update with DNS Status</button> | ||
<div id="existing-keys"></div> | ||
|
||
<h3>Request</h3> | ||
<p> | ||
<input type="text" id="new-name" placeholder="mythingymajig.zenr.io"> | ||
<button onclick="requestKey()">Request new Key</button> | ||
</p> | ||
|
||
<h3>Search Keystore for Key to sign update for a given Subdomain</h3> | ||
<p> | ||
<input type="text" id="keys-for-domain" placeholder="mythingymajig.zenr.io"> | ||
<button onclick="getKeysForDomain()">Find key in keystore</button> | ||
<div id="domain-key"></div> | ||
</p> | ||
|
||
<h3>Find DOH Endpoint for a given Subdomain</h3> | ||
<p> | ||
<input type="text" id="doh-for-domain" placeholder="mythingymajig.zenr.io"> | ||
<button onclick="findDOHEndpoint()">Find DOH endpoint</button> | ||
<div id="domain-doh-endpoint"></div> | ||
</p> | ||
|
||
<h3>Import Key pair files from filesystem into Browser Keystore</h3> | ||
<p> | ||
<input type="file" id="directoryPicker" webkitdirectory multiple> | ||
<ul id="fileList"></ul> | ||
<div id="imported-key"></div> | ||
</p> | ||
|
||
<script> | ||
document.getElementById('directoryPicker').addEventListener('change', function(event) { | ||
const files = event.target.files; | ||
const fileList = document.getElementById('fileList'); | ||
fileList.innerHTML = ''; // Clear any existing list items | ||
|
||
// Object to store pairs of .key and .private files | ||
const filePairs = {}; | ||
|
||
// Filter and organize files by their name (without extension) | ||
for (let i = 0; i < files.length; i++) { | ||
const file = files[i]; | ||
const fileName = file.name; | ||
const fileExt = fileName.split('.').pop().toLowerCase(); | ||
const baseName = fileName.slice(0, fileName.lastIndexOf('.')); | ||
|
||
if (fileExt === 'key' || fileExt === 'private') { | ||
if (!filePairs[baseName]) { | ||
filePairs[baseName] = {}; | ||
} | ||
if (fileExt === 'key') { | ||
filePairs[baseName].keyFile = file; | ||
} else if (fileExt === 'private') { | ||
filePairs[baseName].privateFile = file; | ||
} | ||
} | ||
} | ||
|
||
// Process each pair and save to localStorage | ||
for (const baseName in filePairs) { | ||
const pair = filePairs[baseName]; | ||
if (pair.keyFile && pair.privateFile) { | ||
// Check if the pair is already in localStorage | ||
if (localStorage.getItem(baseName)) { | ||
const li = document.createElement('li'); | ||
li.textContent = `${baseName}: Already registered`; | ||
fileList.appendChild(li); | ||
} else { | ||
// Read the files asynchronously | ||
const keyReader = new FileReader(); | ||
const privateReader = new FileReader(); | ||
|
||
keyReader.onload = function(e) { | ||
const keyContent = e.target.result; | ||
privateReader.onload = function(e) { | ||
const privateContent = e.target.result; | ||
const jsonString = JSON.stringify({ key: keyContent, private: privateContent }); | ||
|
||
// Save to localStorage | ||
localStorage.setItem(baseName, jsonString); | ||
|
||
// Update the UI | ||
const li = document.createElement('li'); | ||
li.textContent = `${baseName}: Saved to localStorage`; | ||
fileList.appendChild(li); | ||
}; | ||
privateReader.readAsText(pair.privateFile); | ||
}; | ||
keyReader.readAsText(pair.keyFile); | ||
} | ||
} | ||
} | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Go<>JS Demo</title> | ||
<script type="application/javascript" src="wasm_exec.js"></script> | ||
<script type="application/javascript" src="pure.js"></script> | ||
</head> | ||
<body> | ||
<h2>DNS</h2> | ||
<h3>DOH Resolver</h3> | ||
<p> | ||
<input type="text" id="query-name" placeholder="mythingymajig.zenr.io"> | ||
<input type="text" id="query-type" placeholder="A"> | ||
<button onclick="renderQuery()">Resolve</button> | ||
<pre id="query-result"></pre> | ||
</p> | ||
|
||
<h2>DNS Keys</h2> | ||
<h3>List Keystore</h3> | ||
<button onclick="listKeys()">Update</button> | ||
<button onclick="listKeysWithStatus()">Update with DNS Status</button> | ||
<div id="existing-keys"></div> | ||
|
||
<h3>Request</h3> | ||
<p> | ||
<input type="text" id="new-name" placeholder="mythingymajig.zenr.io"> | ||
<button onclick="requestKey()">Request new Key</button> | ||
</p> | ||
|
||
<h3>Search Keystore for Key to sign update for a given Subdomain</h3> | ||
<p> | ||
<input type="text" id="keys-for-domain" placeholder="mythingymajig.zenr.io"> | ||
<button onclick="getKeysForDomain()">Find key in keystore</button> | ||
<div id="domain-key"></div> | ||
</p> | ||
|
||
<h3>Find DOH Endpoint for a given Subdomain</h3> | ||
<p> | ||
<input type="text" id="doh-for-domain" placeholder="mythingymajig.zenr.io"> | ||
<button onclick="findDOHEndpoint()">Find DOH endpoint</button> | ||
<div id="domain-doh-endpoint"></div> | ||
</p> | ||
|
||
<h3>Import Key pair files from filesystem into Browser Keystore</h3> | ||
<p> | ||
<input type="file" id="directoryPicker" webkitdirectory multiple onchange="handleFileSelection(event)"> | ||
<ul id="fileList"></ul> | ||
<div id="imported-key"></div> | ||
</p> | ||
</body> | ||
</html> |