aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/canaries/canaries.ts
diff options
context:
space:
mode:
authorLibravatarLarge Libravatar memdmp <memdmpestrogenzone>2025-01-22 21:19:22 +0100
committerLibravatarLarge Libravatar memdmp <memdmpestrogenzone>2025-01-22 21:19:22 +0100
commitc5a7e704d1c836119319ce3b308642f195b078d9 (patch)
tree616e94bc0e92e5df378208e8c4f81af3c2e71c7e /src/routes/canaries/canaries.ts
parent09e7d196b200ad7c61d223c70295644eafcae717 (diff)
downloadmem-estrogen-zone-c5a7e704d1c836119319ce3b308642f195b078d9.tar.gz
mem-estrogen-zone-c5a7e704d1c836119319ce3b308642f195b078d9.tar.bz2
mem-estrogen-zone-c5a7e704d1c836119319ce3b308642f195b078d9.tar.lz
mem-estrogen-zone-c5a7e704d1c836119319ce3b308642f195b078d9.zip

feat: canarytool :3

Diffstat (limited to 'src/routes/canaries/canaries.ts')
-rw-r--r--src/routes/canaries/canaries.ts54
1 files changed, 49 insertions, 5 deletions
diff --git a/src/routes/canaries/canaries.ts b/src/routes/canaries/canaries.ts
index de5c44f..d28baab 100644
--- a/src/routes/canaries/canaries.ts
+++ b/src/routes/canaries/canaries.ts
@@ -1,25 +1,69 @@
+import { browser } from "$app/environment";
+import { validateSignature } from "./keystore";
+
export const canaries: Canary[] = [];
export class Canary {
public constructor(
public name: string,
public description: string,
+ public signer: string,
public url: string,
public keyIdentifier: string,
+ public contentType: string = 'text/plain',
) {
canaries.push(this);
}
+ public forceContentType = false;
+ public async getRawText() {
+ if (!browser) throw new Error('This should only be done in a browser.')
+ const res = await fetch(this.url)
+ if (res.ok) {
+ if (!this.forceContentType) this.contentType = res.headers.get('Content-Type') || this.contentType
+ const text = await res.text()
+ return text
+ } else {
+ throw new Error(`Fetching canary failed with code ${res.status} (${res.statusText}):
+${await res.text().catch(e => `Unknown (Unable to get text, ${JSON.stringify(e)})`)}`)
+ }
+ }
+ public async getValidatedText(rawText: string | Promise<string> = this.getRawText()) {
+ return await validateSignature(await rawText, this.keyIdentifier)
+ }
+ /** Returns downloadable data url if signature passes, otherwise returns null */
+ public async getUrl(rawText: string | Promise<string> = this.getRawText()) {
+ const t = await rawText;
+ let stripped: string;
+ try {
+ stripped = await this.getValidatedText(t);
+ } catch (error) {
+ console.warn('Failed to validate signature: ', error);
+ return null;
+ }
+ return {
+ stripped: URL.createObjectURL(new Blob([stripped], {
+ type: this.contentType,
+ })),
+ signed: URL.createObjectURL(new Blob([t], {
+ type: this.contentType,
+ })),
+ }
+ }
}
new Canary(
- 'estrogen.zone, memdmp',
- 'This canary is responsible for services hosted around estrogen.zone and yuridick.gay',
+ 'estrogen.zone',
+ 'Services hosted around estrogen.zone and yuridick.gay',
+ 'memdmp',
'/canaries/memdmp:estrogen.zone',
'memdmp',
+ 'text/plain; charset=utf-8'
);
new Canary(
'kyun.host',
- 'This canary is responsible for the VPS provider "kyun.host"',
- // '/canaries/napatha:kyun.host',
- 'https://files.kyun.host/canary.txt',
+ 'The VPS provider "kyun.host"',
+ 'napatha',
+ '/canaries/napatha:kyun.host',
+ // 'https://files.kyun.host/canary.txt',
'napatha',
+ 'text/plain; charset=utf-8'
);