1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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',
'Services hosted around estrogen.zone and yuridick.gay',
'memdmp',
'/canaries/memdmp:estrogen.zone',
'memdmp',
'text/plain; charset=utf-8'
);
new Canary(
'kyun.host',
'The VPS provider "kyun.host"',
'napatha',
'/canaries/napatha:kyun.host',
// 'https://files.kyun.host/canary.txt',
'napatha',
'text/plain; charset=utf-8'
);
|