├── .gitignore ├── local.ts ├── jsx.d.ts ├── local.js ├── package.json ├── renderer.ts ├── renderer.js ├── index.ts ├── index.html ├── verifier.ts ├── proofs.json ├── ui.tsx ├── tsconfig.json ├── verifier.js ├── README.md ├── index.js ├── openpgp-key.tsx ├── LICENCE ├── openpgp-key.js └── scripts.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /local.ts: -------------------------------------------------------------------------------- 1 | export function createElement(name: string, attributes: Object, ...children: JSX.Element[]) { 2 | return { 3 | name, 4 | attributes: attributes || {}, 5 | children: Array.prototype.concat(...(children || [])) 6 | }; 7 | } 8 | -------------------------------------------------------------------------------- /jsx.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace JSX { 2 | interface IntrinsicElements { 3 | [tag: string]: any; 4 | } 5 | interface Element { 6 | name: string; 7 | attributes: { [name: string]: string }; 8 | children: JSX.Element[]; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /local.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | function createElement(name, attributes) { 4 | var _a; 5 | var children = []; 6 | for (var _i = 2; _i < arguments.length; _i++) { 7 | children[_i - 2] = arguments[_i]; 8 | } 9 | return { 10 | name: name, 11 | attributes: attributes || {}, 12 | children: (_a = Array.prototype).concat.apply(_a, (children || [])) 13 | }; 14 | } 15 | exports.createElement = createElement; 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "openpgp-proofs", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "build": "tsc" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "devDependencies": { 14 | "@types/node-fetch": "^2.5.4", 15 | "@types/openpgp": "^4.4.5", 16 | "typescript": "^3.0.3" 17 | }, 18 | "dependencies": { 19 | "node-fetch": "^2.6.0", 20 | "openpgp": "^4.5.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /renderer.ts: -------------------------------------------------------------------------------- 1 | export function render(element: JSX.Element | string | null): string { 2 | if (element == null) return ''; 3 | if (typeof element !== "object") element = String(element); 4 | if (typeof element === "string") return element.replace(/&/g, '&').replace(//g, '>'); 5 | //if (element instanceof Raw) return element.html; 6 | console.assert(!!element.attributes, 'Element attributes must be defined:\n' + JSON.stringify(element)); 7 | const elementAttributes = element.attributes; 8 | let attributes = Object.keys(elementAttributes).filter(key => { 9 | const value = (elementAttributes as any)[key]; 10 | return value != null; 11 | }).map(key => { 12 | const value = (elementAttributes as any)[key]; 13 | if (value === true) { 14 | return key; 15 | } 16 | return `${key}="${String(value).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"')}"`; 17 | }).join(' '); 18 | if (attributes.length > 0) { 19 | attributes = ' ' + attributes; 20 | } 21 | const children = element.children.length > 0 ? `>${element.children.map(child => render(child)).join('')}` : '>'; 22 | return `<${element.name}${attributes}${children}`; 23 | } 24 | -------------------------------------------------------------------------------- /renderer.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | function render(element) { 4 | if (element == null) 5 | return ''; 6 | if (typeof element !== "object") 7 | element = String(element); 8 | if (typeof element === "string") 9 | return element.replace(/&/g, '&').replace(//g, '>'); 10 | //if (element instanceof Raw) return element.html; 11 | console.assert(!!element.attributes, 'Element attributes must be defined:\n' + JSON.stringify(element)); 12 | var elementAttributes = element.attributes; 13 | var attributes = Object.keys(elementAttributes).filter(function (key) { 14 | var value = elementAttributes[key]; 15 | return value != null; 16 | }).map(function (key) { 17 | var value = elementAttributes[key]; 18 | if (value === true) { 19 | return key; 20 | } 21 | return key + "=\"" + String(value).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"') + "\""; 22 | }).join(' '); 23 | if (attributes.length > 0) { 24 | attributes = ' ' + attributes; 25 | } 26 | var children = element.children.length > 0 ? ">" + element.children.map(function (child) { return render(child); }).join('') : '>'; 27 | return "<" + element.name + attributes + children + ""; 28 | } 29 | exports.render = render; 30 | -------------------------------------------------------------------------------- /index.ts: -------------------------------------------------------------------------------- 1 | import * as openpgp from 'openpgp'; 2 | import { verify, getVerifier, VerifierProof, getJson } from './verifier'; 3 | import * as fetch from 'node-fetch'; 4 | 5 | function readStdinToBuffer(): Promise { 6 | return new Promise((resolve, reject) => { 7 | const data: Buffer[] = []; 8 | process.stdin.on('readable', () => { 9 | const chunk = process.stdin.read() as Buffer; 10 | if (chunk !== null) { 11 | data.push(chunk) 12 | } 13 | }); 14 | 15 | process.stdin.on('end', () => { 16 | resolve(Buffer.concat(data)); 17 | }); 18 | 19 | process.stdin.on('error', e => reject(e)); 20 | }); 21 | }; 22 | 23 | async function parseKey(buffer: Buffer) { 24 | const key = (await openpgp.key.read(buffer)).keys[0]; 25 | const fingerprint = key.primaryKey.getFingerprint(); 26 | 27 | const primaryUser = await key.getPrimaryUser(); 28 | const lastPrimarySig = primaryUser.selfCertification; 29 | 30 | const p = require('./proofs.json').proofs; 31 | const notations: [string, any][] = (lastPrimarySig as any).notations || []; 32 | const proofs = notations 33 | .filter(notation => notation[0] === 'proof@metacode.biz' && typeof notation[1] === 'string') 34 | .map(notation => notation[1] as string) 35 | .map(proofUrl => getVerifier(p, proofUrl, key.primaryKey.getFingerprint())) 36 | .filter(verifier => verifier) as VerifierProof[]; 37 | console.log('Key : openpgp4fpr:' + fingerprint); 38 | console.log('User: ' + primaryUser.user.userId.userid); 39 | return { fingerprint, proofs }; 40 | } 41 | 42 | async function verifyIdentifies() { 43 | if (typeof process === 'undefined') { 44 | return; 45 | } 46 | const good = '\x1b[32;1m✓\x1b[0m'; 47 | const bad = '\x1b[31;1m✗\x1b[0m'; 48 | const key = await readStdinToBuffer(); 49 | const things = await parseKey(key); 50 | console.log(); 51 | if (things.proofs.length == 0) { 52 | console.log('No proofs to check. Try key 653909a2f0e37c106f5faf546c8857e0d8e8f074.'); 53 | } 54 | let allPassed = true; 55 | for (const proof of things.proofs) { 56 | const json = await getJson(proof.proofJson); 57 | let passed = false, error = null; 58 | try { 59 | await verify(json, proof.checks); 60 | passed = true; 61 | } catch (e) { 62 | error = e; 63 | } 64 | allPassed = allPassed && passed; 65 | console.log(` ${passed ? good : bad} ${proof.service}:${proof.username}\n URL: ${proof.profile}\n Proof: ${proof.proofUrl}\n`); 66 | } 67 | if (things.proofs.length > 0 && allPassed) { 68 | console.log('If this is a person you were looking for you can locally sign the key:\n gpg --quick-lsign ' + things.fingerprint); 69 | console.log(); 70 | } 71 | } 72 | 73 | verifyIdentifies().catch(console.error.bind(console)); -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | OpenPGP Key lookup 6 | 7 | 10 | 11 | 12 | 52 | 53 | 67 | 68 | 69 |
70 |
71 |
Loading key...
72 |
73 |
74 |

Note: contents of this page are generated purely from the OpenPGP key in your browser. 75 | If you want to add social proofs to your key see OpenPGP Proofs page.

76 |

If you want to adjust the keyserver used or the key being displayed just edit this HTML page.

77 |
78 |
79 | 80 | -------------------------------------------------------------------------------- /verifier.ts: -------------------------------------------------------------------------------- 1 | 2 | export interface Proof { 3 | matcher: string; 4 | variables: { 5 | [name: string]: number; 6 | }; 7 | profile: string; 8 | proof: string; 9 | username: string; 10 | service: string; 11 | checks: any[]; 12 | } 13 | 14 | export interface VerifierProof { 15 | profile: string, 16 | proofUrl: string; 17 | proofJson: string; 18 | service: string; 19 | username: string; 20 | checks: any[]; 21 | } 22 | 23 | export function getVerifier(proofs: Proof[], proofUrl: string, fingerprint: string) { 24 | for (const proof of proofs) { 25 | const matches = proofUrl.match(new RegExp(proof.matcher)); 26 | if (!matches) continue; 27 | 28 | const bound = Object.entries(proof.variables).map(([key, value]) => [key, matches[value || 0]]).reduce((previous, current) => { previous[current[0]] = current[1]; return previous;}, { FINGERPRINT: fingerprint } as any); 29 | 30 | const profile = proof.profile.replace(/\{([A-Z]+)\}/g, (_, name) => bound[name]); 31 | 32 | const proofJson = proof.proof.replace(/\{([A-Z]+)\}/g, (_, name) => bound[name]); 33 | 34 | const username = proof.username.replace(/\{([A-Z]+)\}/g, (_, name) => bound[name]); 35 | 36 | return { 37 | profile, 38 | proofUrl, 39 | proofJson, 40 | username, 41 | service: proof.service, 42 | checks: ((proof.checks || []) as any).map((check: any) => ({ 43 | relation: check.relation, 44 | proof: check.proof, 45 | claim: check.claim.replace(/\{([A-Z]+)\}/g, (_: any, name: string) => bound[name]) 46 | })) 47 | }; 48 | } 49 | return null; 50 | } 51 | 52 | export async function verify(json: any, checks: any[]) { 53 | for (const check of checks) { 54 | const proofValue = check.proof.reduce((previous: any, current: any) => { 55 | if (current == null || previous == null) return null; 56 | if (Array.isArray(previous) && typeof current === 'string') { 57 | return previous.map(value => value[current]); 58 | } 59 | return previous[current]; 60 | }, json); 61 | const claimValue = check.claim; 62 | if (check.relation === 'eq') { 63 | if (proofValue !== claimValue) { 64 | throw new Error(`Proof value ${proofValue} !== claim value ${claimValue}`); 65 | } 66 | } else if (check.relation === 'contains') { 67 | if (!proofValue || proofValue.indexOf(claimValue) === -1) { 68 | throw new Error(`Proof value ${proofValue} does not contain claim value ${claimValue}`); 69 | } 70 | } else if (check.relation === 'oneOf') { 71 | if (!proofValue || proofValue.indexOf(claimValue) === -1) { 72 | throw new Error(`Proof value ${proofValue} does not contain claim value ${claimValue}`); 73 | } 74 | } 75 | } 76 | } 77 | 78 | export async function getJson(url: string) { 79 | const response = await fetch(url, { 80 | headers: { 81 | Accept: 'application/json' 82 | }, 83 | credentials: 'omit' 84 | }); 85 | if (!response.ok) { 86 | throw new Error('Response failed: ' + response.status); 87 | } 88 | return response.json(); 89 | } 90 | -------------------------------------------------------------------------------- /proofs.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 5.0, 3 | "proofs": [ 4 | { 5 | "matcher": "^https://gist.github.com/([A-Za-z0-9_-]+)/([0-9a-f]+)$", 6 | "variables": { 7 | "USERNAME": 1, 8 | "PROOFID": 2 9 | }, 10 | "profile": "https://github.com/{USERNAME}", 11 | "proof": "https://api.github.com/gists/{PROOFID}", 12 | "username": "{USERNAME}", 13 | "service": "github", 14 | "checks": [ 15 | { 16 | "relation": "eq", 17 | "proof": [ 18 | "owner", 19 | "login" 20 | ], 21 | "claim": "{USERNAME}" 22 | }, 23 | { 24 | "relation": "eq", 25 | "proof": [ 26 | "owner", 27 | "html_url" 28 | ], 29 | "claim": "https://github.com/{USERNAME}" 30 | }, 31 | { 32 | "relation": "contains", 33 | "proof": [ 34 | "files", 35 | "openpgp.md", 36 | "content" 37 | ], 38 | "claim": "[Verifying my OpenPGP key: openpgp4fpr:{FINGERPRINT}]" 39 | } 40 | ] 41 | }, 42 | { 43 | "matcher": "^https://news.ycombinator.com/user\\?id=([A-Za-z0-9-]+)$", 44 | "variables": { 45 | "USERNAME": 1, 46 | "PROFILE": 0 47 | }, 48 | "profile": "{PROFILE}", 49 | "proof": "https://hacker-news.firebaseio.com/v0/user/{USERNAME}.json", 50 | "username": "{USERNAME}", 51 | "service": "hackernews", 52 | "checks": [ 53 | { 54 | "relation": "contains", 55 | "proof": [ 56 | "about" 57 | ], 58 | "claim": "[Verifying my OpenPGP key: openpgp4fpr:{FINGERPRINT}]" 59 | } 60 | ] 61 | }, 62 | { 63 | "matcher": "^https://www.reddit.com/user/([^/]+)/comments/([^/]+)/([^/]+/)?$", 64 | "variables": { 65 | "USERNAME": 1, 66 | "PROOF": 2 67 | }, 68 | "profile": "https://www.reddit.com/user/{USERNAME}", 69 | "proof": "https://www.reddit.com/user/{USERNAME}/comments/{PROOF}.json", 70 | "username": "{USERNAME}", 71 | "service": "reddit", 72 | "checks": [ 73 | { 74 | "relation": "contains", 75 | "proof": [ 76 | 0, 77 | "data", 78 | "children", 79 | 0, 80 | "data", 81 | "selftext" 82 | ], 83 | "claim": "Verifying my OpenPGP key: openpgp4fpr:{FINGERPRINT}" 84 | }, 85 | { 86 | "relation": "eq", 87 | "proof": [ 88 | 0, 89 | "data", 90 | "children", 91 | 0, 92 | "data", 93 | "author" 94 | ], 95 | "claim": "{USERNAME}" 96 | } 97 | ] 98 | }, 99 | { 100 | "matcher": "^https://([^/]+)/@([A-Za-z0-9_-]+)$", 101 | "variables": { 102 | "INSTANCE": 1, 103 | "USERNAME": 2, 104 | "PROFILE": 0 105 | }, 106 | "profile": "{PROFILE}", 107 | "proof": "{PROFILE}", 108 | "username": "@{USERNAME}@{INSTANCE}", 109 | "service": "mastodon", 110 | "checks": [ 111 | { 112 | "relation": "oneOf", 113 | "proof": [ 114 | "attachment", 115 | "value" 116 | ], 117 | "claim": "{FINGERPRINT}" 118 | } 119 | ] 120 | }, 121 | { 122 | "matcher": "^dns:([^?]+)\\?type=TXT$", 123 | "variables": { 124 | "DOMAIN": 1 125 | }, 126 | "profile": "https://{DOMAIN}", 127 | "proof": "https://dns.google.com/resolve?name={DOMAIN}&type=TXT", 128 | "username": "{DOMAIN}", 129 | "service": "dns", 130 | "checks": [ 131 | { 132 | "relation": "oneOf", 133 | "proof": [ 134 | "Answer", 135 | "data" 136 | ], 137 | "claim": "\"openpgp4fpr:{FINGERPRINT}\"" 138 | } 139 | ] 140 | } 141 | ] 142 | } 143 | -------------------------------------------------------------------------------- /ui.tsx: -------------------------------------------------------------------------------- 1 | 2 | import local = require('./local'); 3 | import * as openpgp from 'openpgp'; 4 | import { VerifierProof } from './verifier'; 5 | 6 | function formatAlgorithm(name: string) { 7 | if (name === 'rsa_encrypt_sign') return "RSA"; 8 | return name; 9 | } 10 | 11 | const dateFormat = new Intl.DateTimeFormat(undefined, { 12 | year: 'numeric', month: 'numeric', day: 'numeric', 13 | hour: 'numeric', minute: 'numeric' 14 | }); 15 | 16 | export function formatDate(date: Date | number) { 17 | if (date === Infinity) return "never"; 18 | return dateFormat.format(date); 19 | } 20 | 21 | function getStatus(status: any, details?: string) { 22 | if (status === openpgp.enums.keyStatus.invalid) { 23 | return ; 24 | } 25 | if (status === openpgp.enums.keyStatus.expired) { 26 | return ; 27 | } 28 | if (status === openpgp.enums.keyStatus.revoked) { 29 | return ; 30 | } 31 | if (status === openpgp.enums.keyStatus.valid) { 32 | return ; 33 | } 34 | if (status === openpgp.enums.keyStatus.no_self_cert) { 35 | return ; 36 | } 37 | return "unknown:" + status; 38 | } 39 | 40 | function getIcon(keyFlags: any) { 41 | if (!keyFlags || !keyFlags[0]) { 42 | return ""; 43 | } 44 | let flags = []; 45 | if ((keyFlags[0] & openpgp.enums.keyFlags.certify_keys) !== 0) { 46 | flags.push(🏵️); 47 | } 48 | if ((keyFlags[0] & openpgp.enums.keyFlags.sign_data) !== 0) { 49 | flags.push(🖋); 50 | } 51 | if (((keyFlags[0] & openpgp.enums.keyFlags.encrypt_communication) !== 0) || 52 | ((keyFlags[0] & openpgp.enums.keyFlags.encrypt_storage) !== 0)) { 53 | flags.push(🔒); 54 | } 55 | if ((keyFlags[0] & openpgp.enums.keyFlags.authentication) !== 0) { 56 | flags.push(💳); 57 | } 58 | return flags; 59 | } 60 | 61 | function serviceToClassName(service: string) { 62 | if (service === 'github') { 63 | return 'fab fa-github'; 64 | } else if (service === 'reddit') { 65 | return 'fab fa-reddit'; 66 | } else if (service === 'hackernews') { 67 | return 'fab fa-hacker-news'; 68 | } else if (service === 'mastodon') { 69 | return 'fab fa-mastodon'; 70 | } else if (service === 'dns') { 71 | return 'fas fa-globe'; 72 | } else { 73 | return ''; 74 | } 75 | } 76 | 77 | export function renderInfo(keyUrl: string, name: string, emails: string[], profileHash: string, fingerprint: string, subKeys: any[], proofs: VerifierProof[]) { 78 | 79 | const now = new Date(); 80 | return
81 |
82 |
83 | 84 |

{name}

85 |
86 | 104 |
105 |
🔒 Encrypt 106 | 107 | {' '} 108 | 109 |
110 |
🖋 Verify 111 | 112 | 113 |
114 |
🔑 Key details 115 |

Subkeys:

116 |
    {subKeys.map((subKey: any) => 117 |
  • 118 |
    {getStatus(subKey.status, subKey.reasonForRevocation)} {getIcon(subKey.keyFlags)} {subKey.fingerprint.substring(24).match(/.{4}/g).join(" ")} {formatAlgorithm(subKey.algorithmInfo.algorithm)} ({subKey.algorithmInfo.bits})
    119 |
    created: {formatDate(subKey.created)}, expire{now > subKey.expirationTime ? "d" : "s"}: {formatDate(subKey.expirationTime)}
    120 |
  • )}
121 |
122 |
; 123 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Basic Options */ 4 | "target": "ES2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ 5 | "module": "system", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ 6 | // "lib": [], /* Specify library files to be included in the compilation. */ 7 | // "allowJs": true, /* Allow javascript files to be compiled. */ 8 | // "checkJs": true, /* Report errors in .js files. */ 9 | "jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ 10 | "jsxFactory": "local.createElement", 11 | // "declaration": true, /* Generates corresponding '.d.ts' file. */ 12 | // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ 13 | // "sourceMap": true, /* Generates corresponding '.map' file. */ 14 | "outFile": "scripts.js", /* Concatenate and emit output to single file. */ 15 | // "outDir": "./", /* Redirect output structure to the directory. */ 16 | // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ 17 | // "composite": true, /* Enable project compilation */ 18 | // "removeComments": true, /* Do not emit comments to output. */ 19 | // "noEmit": true, /* Do not emit outputs. */ 20 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */ 21 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ 22 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ 23 | 24 | /* Strict Type-Checking Options */ 25 | "strict": true, /* Enable all strict type-checking options. */ 26 | // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ 27 | // "strictNullChecks": true, /* Enable strict null checks. */ 28 | // "strictFunctionTypes": true, /* Enable strict checking of function types. */ 29 | // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ 30 | // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ 31 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ 32 | 33 | /* Additional Checks */ 34 | // "noUnusedLocals": true, /* Report errors on unused locals. */ 35 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 36 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 37 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 38 | 39 | /* Module Resolution Options */ 40 | // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ 41 | // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ 42 | // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ 43 | // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ 44 | // "typeRoots": [], /* List of folders to include type definitions from. */ 45 | // "types": [], /* Type declaration files to be included in compilation. */ 46 | // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ 47 | "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ 48 | // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ 49 | 50 | /* Source Map Options */ 51 | // "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ 52 | // "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */ 53 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ 54 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ 55 | 56 | /* Experimental Options */ 57 | // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ 58 | // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ 59 | } 60 | } -------------------------------------------------------------------------------- /verifier.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | return new (P || (P = Promise))(function (resolve, reject) { 4 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 5 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 6 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } 7 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 8 | }); 9 | }; 10 | var __generator = (this && this.__generator) || function (thisArg, body) { 11 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 12 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 13 | function verb(n) { return function (v) { return step([n, v]); }; } 14 | function step(op) { 15 | if (f) throw new TypeError("Generator is already executing."); 16 | while (_) try { 17 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 18 | if (y = 0, t) op = [op[0] & 2, t.value]; 19 | switch (op[0]) { 20 | case 0: case 1: t = op; break; 21 | case 4: _.label++; return { value: op[1], done: false }; 22 | case 5: _.label++; y = op[1]; op = [0]; continue; 23 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 24 | default: 25 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 26 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 27 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 28 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 29 | if (t[2]) _.ops.pop(); 30 | _.trys.pop(); continue; 31 | } 32 | op = body.call(thisArg, _); 33 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 34 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 35 | } 36 | }; 37 | exports.__esModule = true; 38 | function getVerifier(proofs, proofUrl, fingerprint) { 39 | var _loop_1 = function (proof) { 40 | var matches = proofUrl.match(new RegExp(proof.matcher)); 41 | if (!matches) 42 | return "continue"; 43 | var bound = Object.entries(proof.variables).map(function (_a) { 44 | var key = _a[0], value = _a[1]; 45 | return [key, matches[value || 0]]; 46 | }).reduce(function (previous, current) { previous[current[0]] = current[1]; return previous; }, { FINGERPRINT: fingerprint }); 47 | var profile = proof.profile.replace(/\{([A-Z]+)\}/g, function (_, name) { return bound[name]; }); 48 | var proofJson = proof.proof.replace(/\{([A-Z]+)\}/g, function (_, name) { return bound[name]; }); 49 | var username = proof.username.replace(/\{([A-Z]+)\}/g, function (_, name) { return bound[name]; }); 50 | return { value: { 51 | profile: profile, 52 | proofUrl: proofUrl, 53 | proofJson: proofJson, 54 | username: username, 55 | service: proof.service, 56 | checks: (proof.checks || []).map(function (check) { return ({ 57 | relation: check.relation, 58 | proof: check.proof, 59 | claim: check.claim.replace(/\{([A-Z]+)\}/g, function (_, name) { return bound[name]; }) 60 | }); }) 61 | } }; 62 | }; 63 | for (var _i = 0, proofs_1 = proofs; _i < proofs_1.length; _i++) { 64 | var proof = proofs_1[_i]; 65 | var state_1 = _loop_1(proof); 66 | if (typeof state_1 === "object") 67 | return state_1.value; 68 | } 69 | return null; 70 | } 71 | exports.getVerifier = getVerifier; 72 | /* 73 | */ 74 | function verify(json, checks) { 75 | return __awaiter(this, void 0, void 0, function () { 76 | var _i, checks_1, check, proofValue, claimValue; 77 | return __generator(this, function (_a) { 78 | for (_i = 0, checks_1 = checks; _i < checks_1.length; _i++) { 79 | check = checks_1[_i]; 80 | proofValue = check.proof.reduce(function (previous, current) { 81 | if (current == null || previous == null) 82 | return null; 83 | if (Array.isArray(previous) && typeof current === 'string') { 84 | return previous.map(function (value) { return value[current]; }); 85 | } 86 | return previous[current]; 87 | }, json); 88 | claimValue = check.claim; 89 | if (check.relation === 'eq') { 90 | if (proofValue !== claimValue) { 91 | throw new Error("Proof value " + proofValue + " !== claim value " + claimValue); 92 | } 93 | } 94 | else if (check.relation === 'contains') { 95 | if (!proofValue || proofValue.indexOf(claimValue) === -1) { 96 | throw new Error("Proof value " + proofValue + " does not contain claim value " + claimValue); 97 | } 98 | } 99 | else if (check.relation === 'oneOf') { 100 | if (!proofValue || proofValue.indexOf(claimValue) === -1) { 101 | throw new Error("Proof value " + proofValue + " does not contain claim value " + claimValue); 102 | } 103 | } 104 | } 105 | return [2 /*return*/]; 106 | }); 107 | }); 108 | } 109 | exports.verify = verify; 110 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenPGP Proofs 2 | 3 | This document describes a method of adding social proofs to OpenPGP keys in a way that can be independently verified by clients. This is similar to Keybase but decentralized. 4 | 5 | An example: 6 | 7 | ``` 8 | $ gpg --export 653909a2f0e37c106f5faf546c8857e0d8e8f074 | node index.js 9 | Key : openpgp4fpr:653909a2f0e37c106f5faf546c8857e0d8e8f074 10 | User: Wiktor Kwapisiewicz <> 11 | 12 | ✓ dns:metacode.biz 13 | URL: https://metacode.biz 14 | Proof: dns:metacode.biz?type=TXT 15 | 16 | ✓ github:wiktor-k 17 | URL: https://github.com/wiktor-k 18 | Proof: https://gist.github.com/wiktor-k/389d589dd19250e1f9a42bc3d5d40c16 19 | 20 | ✓ reddit:wiktor-k 21 | URL: https://www.reddit.com/user/wiktor-k 22 | Proof: https://www.reddit.com/user/wiktor-k/comments/bo5oih/test/ 23 | 24 | ✓ hackernews:wiktor-k 25 | URL: https://news.ycombinator.com/user?id=wiktor-k 26 | Proof: https://news.ycombinator.com/user?id=wiktor-k 27 | 28 | If this is a person you were looking for you can locally sign the key: 29 | gpg --quick-lsign 653909a2f0e37c106f5faf546c8857e0d8e8f074 30 | ``` 31 | 32 | See also online version at https://metacode.biz/openpgp/key#0x653909A2F0E37C106F5FAF546C8857E0D8E8F074 33 | 34 | ## Technical details 35 | 36 | Proofs are URIs to documents hosted on third-party sites (such as https://gist.github.com/wiktor-k/389d589dd19250e1f9a42bc3d5d40c16) that can be used by proof-validating clients to check if the key owner has access to given social account. 37 | 38 | (Inspect proofs from command line by using `gpg --list-options show-notations --list-sigs D8E8F074 | grep proof`). 39 | 40 | Proof URIs are converted to URLs that are used to fetch JSON documents. These documents contain back-link data pointing to an OpenPGP key. 41 | 42 | One additional document: `proofs.json` is needed for validators to properly handle proof URIs. 43 | 44 | An example, given this proof URI: 45 | 46 | https://gist.github.com/wiktor-k/389d589dd19250e1f9a42bc3d5d40c16 47 | 48 | It is matched to first entry in `proofs.json`, this regular expression: 49 | 50 | `"^https://gist.github.com/([A-Za-z0-9_-]+)/([0-9a-f]+)$"` 51 | 52 | Capturing groups are assigned names, in this case first group is a `USERNAME` and the second `PROOFID`. 53 | 54 | These groups can be used to construct other elements, such as profile URL: 55 | 56 | `"https://github.com/{USERNAME}"` 57 | 58 | Or proof URL, that points to the JSON representation of the proof document: 59 | 60 | `"https://api.github.com/gists/{PROOFID}"` 61 | 62 | The proof document is then fetched with appropriate headers and a number of checks, also defined in `proofs.json` is performed. 63 | 64 | Checks always extract a piece of data from the JSON document by recursively extracing objects by keys. 65 | 66 | For example the first check extracts `owner` object and then, from that object `login` key (`["owner", "login"]`). This is compared to a *claim*, that in this case is `USERNAME` that has been extracted from the URL. 67 | 68 | If all checks succeed then the proof is considered validated. 69 | 70 | ## For users 71 | 72 | Proof documents can be added using platform specific editors only at the moment (for example GitHub gists). After the gist has been created a notation needs to be added to OpenPGP key that points to the proof document: 73 | 74 | ``` 75 | $ gpg --edit-key F470E50DCB1AD5F1E64E08644A63613A4D6E4094 76 | sec rsa1024/4A63613A4D6E4094 77 | created: 2013-10-18 expires: never usage: SCEA 78 | trust: unknown validity: full 79 | ssb rsa1024/E084F7446C202C97 80 | created: 2013-10-18 expires: never usage: SEA 81 | [ full ] (1). Test McTestington 82 | 83 | gpg> 84 | ``` 85 | 86 | Use `notation` subcommand and enter `proof@metacode.biz=` and the proof URI. 87 | 88 | For example: 89 | 90 | ``` 91 | gpg> notation 92 | Enter the notation: proof@metacode.biz=https://news.ycombinator.com/user?id=wiktor-k 93 | No notations on user ID "Test McTestington " 94 | Adding notation: proof@metacode.biz=https://news.ycombinator.com/user?id=wiktor-k 95 | ``` 96 | 97 | Send the key to keyservers if you want others to be able to verify your proofs (this is not strictly needed). 98 | 99 | ## For proof validators 100 | 101 | Proof validation logic is designed to be as simple as possible. Proofs are extracted from OpenPGP self-signature notations using `proof@metacode.biz` key and then matched to the data in `proofs.json` file. 102 | 103 | JavaScript implementation of this process is in `verifier.ts` file. Additional implementations are planned. 104 | 105 | ## For service providers 106 | 107 | If you host a service and would like to add the ability for users to prove that they control that account there are only two steps: 108 | 109 | 1. Expose user data (either profile info or a comment) in a JSON format that can be read by all sites (that is with appropriate CORS header: `Access-Control-Allow-Origin: *`). The document should include user name. 110 | 111 | 2. Add an entry to `proofs.json` describing how to extract data (username and key fingerprint) from that document. 112 | 113 | ## FAQ 114 | 115 | 1. Q: Why the notation name is `proof@metacode.biz`? Should I replace it with my own e-mail / domain? 116 | 117 | A: Nope. This e-mail-like string is actually notation key. RFC 4880 specifies [this kind of format](https://tools.ietf.org/html/rfc4880#section-5.2.3.16) as a way to namespace custom notations. You need to create notations under the domain that you own to avoid conflicts. I used my own domain for this protocol. Ideally the notation key would be just `proof`. Using this kind of keys (without `@` namespacing) is only allowed for IETF-approved extensions though (I did not approach them). 118 | 119 | 2. Q: Why aren't proof documents cleartext signed like in Keybase? 120 | 121 | A: The link to the proof document is already signed with your own key when you add the signature notation. Even if the social site published a different document at that link the fingerprint will never match. Actually the signature is stronger than with Keybase as it requires your primary (master) key with Certify capability while cleartext signatures that Keybase uses require only Signing keys. (This could be important if you store your master keys offline). 122 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | return new (P || (P = Promise))(function (resolve, reject) { 4 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 5 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 6 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } 7 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 8 | }); 9 | }; 10 | var __generator = (this && this.__generator) || function (thisArg, body) { 11 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 12 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 13 | function verb(n) { return function (v) { return step([n, v]); }; } 14 | function step(op) { 15 | if (f) throw new TypeError("Generator is already executing."); 16 | while (_) try { 17 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 18 | if (y = 0, t) op = [op[0] & 2, t.value]; 19 | switch (op[0]) { 20 | case 0: case 1: t = op; break; 21 | case 4: _.label++; return { value: op[1], done: false }; 22 | case 5: _.label++; y = op[1]; op = [0]; continue; 23 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 24 | default: 25 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 26 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 27 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 28 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 29 | if (t[2]) _.ops.pop(); 30 | _.trys.pop(); continue; 31 | } 32 | op = body.call(thisArg, _); 33 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 34 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 35 | } 36 | }; 37 | exports.__esModule = true; 38 | var openpgp = require("openpgp"); 39 | var verifier_1 = require("./verifier"); 40 | var fetch = require("node-fetch"); 41 | function readStdinToBuffer() { 42 | return new Promise(function (resolve, reject) { 43 | var data = []; 44 | process.stdin.on('readable', function () { 45 | var chunk = process.stdin.read(); 46 | if (chunk !== null) { 47 | data.push(chunk); 48 | } 49 | }); 50 | process.stdin.on('end', function () { 51 | resolve(Buffer.concat(data)); 52 | }); 53 | process.stdin.on('error', function (e) { return reject(e); }); 54 | }); 55 | } 56 | ; 57 | function getJson(url) { 58 | return __awaiter(this, void 0, void 0, function () { 59 | var response; 60 | return __generator(this, function (_a) { 61 | switch (_a.label) { 62 | case 0: return [4 /*yield*/, fetch(url, { 63 | headers: { 64 | Accept: 'application/json' 65 | }, 66 | credentials: 'omit' 67 | })]; 68 | case 1: 69 | response = _a.sent(); 70 | if (!response.ok) { 71 | throw new Error('Response failed: ' + response.status); 72 | } 73 | return [2 /*return*/, response.json()]; 74 | } 75 | }); 76 | }); 77 | } 78 | function parseKey(buffer) { 79 | return __awaiter(this, void 0, void 0, function () { 80 | var key, fingerprint, primaryUser, lastPrimarySig, p, notations, proofs; 81 | return __generator(this, function (_a) { 82 | switch (_a.label) { 83 | case 0: return [4 /*yield*/, openpgp.key.read(buffer)]; 84 | case 1: 85 | key = (_a.sent()).keys[0]; 86 | fingerprint = key.primaryKey.getFingerprint(); 87 | return [4 /*yield*/, key.getPrimaryUser()]; 88 | case 2: 89 | primaryUser = _a.sent(); 90 | lastPrimarySig = primaryUser.selfCertification; 91 | p = require('./proofs.json').proofs; 92 | notations = lastPrimarySig.notations || []; 93 | proofs = notations 94 | .filter(function (notation) { return notation[0] === 'proof@metacode.biz' && typeof notation[1] === 'string'; }) 95 | .map(function (notation) { return notation[1]; }) 96 | .map(function (proofUrl) { return verifier_1.getVerifier(p, proofUrl, key.primaryKey.getFingerprint()); }) 97 | .filter(function (verifier) { return verifier; }); 98 | console.log('Key : openpgp4fpr:' + fingerprint); 99 | console.log('User: ' + primaryUser.user.userId.userid); 100 | return [2 /*return*/, { fingerprint: fingerprint, proofs: proofs }]; 101 | } 102 | }); 103 | }); 104 | } 105 | function verifyIdentifies() { 106 | return __awaiter(this, void 0, void 0, function () { 107 | var good, bad, key, things, allPassed, _i, _a, proof, json, passed, error, e_1; 108 | return __generator(this, function (_b) { 109 | switch (_b.label) { 110 | case 0: 111 | good = '\x1b[32;1m✓\x1b[0m'; 112 | bad = '\x1b[31;1m✗\x1b[0m'; 113 | return [4 /*yield*/, readStdinToBuffer()]; 114 | case 1: 115 | key = _b.sent(); 116 | return [4 /*yield*/, parseKey(key)]; 117 | case 2: 118 | things = _b.sent(); 119 | console.log(); 120 | if (things.proofs.length == 0) { 121 | console.log('No proofs to check. Try key 653909a2f0e37c106f5faf546c8857e0d8e8f074.'); 122 | } 123 | allPassed = true; 124 | _i = 0, _a = things.proofs; 125 | _b.label = 3; 126 | case 3: 127 | if (!(_i < _a.length)) return [3 /*break*/, 10]; 128 | proof = _a[_i]; 129 | return [4 /*yield*/, getJson(proof.proofJson)]; 130 | case 4: 131 | json = _b.sent(); 132 | passed = false, error = null; 133 | _b.label = 5; 134 | case 5: 135 | _b.trys.push([5, 7, , 8]); 136 | return [4 /*yield*/, verifier_1.verify(json, proof.checks)]; 137 | case 6: 138 | _b.sent(); 139 | passed = true; 140 | return [3 /*break*/, 8]; 141 | case 7: 142 | e_1 = _b.sent(); 143 | error = e_1; 144 | return [3 /*break*/, 8]; 145 | case 8: 146 | allPassed = allPassed && passed; 147 | console.log(" " + (passed ? good : bad) + " " + proof.service + ":" + proof.username + "\n URL: " + proof.profile + "\n Proof: " + proof.proofUrl + "\n"); 148 | _b.label = 9; 149 | case 9: 150 | _i++; 151 | return [3 /*break*/, 3]; 152 | case 10: 153 | if (things.proofs.length > 0 && allPassed) { 154 | console.log('If this is a person you were looking for you can locally sign the key:\n gpg --quick-lsign ' + things.fingerprint); 155 | console.log(); 156 | } 157 | return [2 /*return*/]; 158 | } 159 | }); 160 | }); 161 | } 162 | verifyIdentifies()["catch"](console.error.bind(console)); 163 | -------------------------------------------------------------------------------- /openpgp-key.tsx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Wiktor Kwapisiewicz 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | https://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import local = require('./local'); 18 | import renderer = require('./renderer'); 19 | import { verify, getVerifier, VerifierProof, getJson } from './verifier'; 20 | import * as openpgp from 'openpgp'; 21 | import * as ui from './ui'; 22 | 23 | 24 | function getLatestSignature(signatures: any, date=new Date()) { 25 | let signature = signatures[0]; 26 | for (let i = 1; i < signatures.length; i++) { 27 | if (signatures[i].created >= signature.created && 28 | (signatures[i].created <= date || date === null)) { 29 | signature = signatures[i]; 30 | } 31 | } 32 | return signature; 33 | } 34 | 35 | window.onload = window.onhashchange = function() { 36 | 37 | lookupKey(location.hash.substring(1)); 38 | 39 | }; 40 | 41 | async function lookupKey(query: string) { 42 | const result = (document.getElementById('result') as HTMLElement); 43 | result.innerHTML = renderer.render(Looking up {query}...); 44 | let keys, keyUrl; 45 | const keyLink = (document.querySelector('[rel="pgpkey"]') as HTMLLinkElement); 46 | if (!keyLink) { 47 | const keyserver = (document.querySelector('meta[name="keyserver"]') as HTMLMetaElement).content; 48 | keyUrl = `https://${keyserver}/pks/lookup?op=get&options=mr&search=${query}`; 49 | const response = await fetch(keyUrl); 50 | const key = await response.text(); 51 | keys = (await openpgp.key.readArmored(key)).keys; 52 | } else { 53 | keyUrl = keyLink.href; 54 | const response = await fetch(keyUrl); 55 | const key = await response.arrayBuffer(); 56 | keys = (await openpgp.key.read(new Uint8Array(key))).keys; 57 | } 58 | 59 | if (keys.length > 0) { 60 | loadKeys(keyUrl, keys).catch(e => { 61 | result.innerHTML = renderer.render(Could not display this key: {String(e)}) 62 | }); 63 | } else { 64 | result.innerHTML = renderer.render({query}: not found); 65 | } 66 | } 67 | 68 | async function loadKeys(keyUrl: string, _keys: any) { 69 | const key = _keys[0]; 70 | (window as any).key = key; 71 | 72 | const primaryUser = await key.getPrimaryUser(); 73 | const users = []; 74 | 75 | for (const user of key.users) { 76 | try { 77 | if (await user.verify(key.primaryKey) === openpgp.enums.keyStatus.valid && user.userId) { 78 | users.push(user); 79 | } 80 | } catch (e) { 81 | console.error('User verification error:', e); 82 | } 83 | } 84 | 85 | for (const user of key.users) { 86 | user.revoked = await user.isRevoked(); 87 | } 88 | 89 | const lastPrimarySig = primaryUser.selfCertification; 90 | 91 | const keys: any[] = [{ 92 | fingerprint: key.primaryKey.getFingerprint(), 93 | status: await key.verifyPrimaryKey(), 94 | keyFlags: lastPrimarySig.keyFlags, 95 | created: key.primaryKey.created, 96 | algorithmInfo: key.primaryKey.getAlgorithmInfo(), 97 | expirationTime: lastPrimarySig.getExpirationTime() 98 | }]; 99 | 100 | const proofsUrl = (document.querySelector('meta[name="proofs"]') as HTMLMetaElement).content; 101 | const p = (await (await fetch(proofsUrl)).json()).proofs; 102 | const notations: [string, any][] = lastPrimarySig.notations || []; 103 | const proofs = notations 104 | .filter(notation => notation[0] === 'proof@metacode.biz' && typeof notation[1] === 'string') 105 | .map(notation => notation[1] as string) 106 | .map(proofUrl => getVerifier(p, proofUrl, key.primaryKey.getFingerprint())) 107 | .filter(verifier => verifier) as VerifierProof[]; 108 | //gpg --export 0xdeadfa11 | curl -T - https://testing2.keys.openpgp.org/ 109 | /* 110 | proofs.push(getVerifier('https://www.reddit.com/user/wiktor-k/comments/bo5oih/test/', key.primaryKey.getFingerprint())); 111 | proofs.push(getVerifier('https://news.ycombinator.com/user?id=wiktor-k', key.primaryKey.getFingerprint())); 112 | proofs.push(getVerifier('https://gist.github.com/wiktor-k/389d589dd19250e1f9a42bc3d5d40c16', key.primaryKey.getFingerprint())); 113 | proofs.push(getVerifier('https://metacode.biz/@wiktor', key.primaryKey.getFingerprint())); 114 | proofs.push(getVerifier('dns:metacode.biz?type=TXT', key.primaryKey.getFingerprint())); 115 | */ 116 | 117 | for (const subKey of key.subKeys) { 118 | const lastSig = getLatestSignature(subKey.bindingSignatures); 119 | let reasonForRevocation; 120 | if (subKey.revocationSignatures.length > 0) { 121 | reasonForRevocation = subKey.revocationSignatures[subKey.revocationSignatures.length - 1].reasonForRevocationString; 122 | } 123 | keys.push({ 124 | fingerprint: subKey.keyPacket.getFingerprint(), 125 | status: await subKey.verify(key.primaryKey), 126 | reasonForRevocation, 127 | keyFlags: lastSig.keyFlags, 128 | created: lastSig.created, 129 | algorithmInfo: subKey.keyPacket.getAlgorithmInfo(), 130 | expirationTime: await subKey.getExpirationTime() 131 | }); 132 | } 133 | 134 | const profileHash = await openpgp.crypto.hash.md5(openpgp.util.str_to_Uint8Array(primaryUser.user.userId.email)).then((u: any) => openpgp.util.str_to_hex(openpgp.util.Uint8Array_to_str(u))); 135 | 136 | // there is index property on primaryUser 137 | document.title = primaryUser.user.userId.name + ' - OpenPGP key'; 138 | const emails = users.map(user => user.userId.email as string).filter(email => email); 139 | const name = primaryUser.user.userId.name; 140 | const info = ui.renderInfo(keyUrl, name, emails, profileHash, key.primaryKey.getFingerprint(), keys, proofs); 141 | (document.getElementById('result') as HTMLElement).innerHTML = renderer.render(info); 142 | checkProofs(); 143 | }; 144 | 145 | async function checkProofs() { 146 | const proofs = document.querySelectorAll('[data-checks]') as NodeListOf; 147 | for (const proofLink of proofs) { 148 | const checks = JSON.parse(proofLink.dataset.checks || ''); 149 | const url = proofLink.dataset.proofJson || ''; 150 | try { 151 | await verify(await getJson(url), checks); 152 | proofLink.textContent = 'verified'; 153 | proofLink.classList.add('verified'); 154 | } catch(e) { 155 | console.error('Could not verify proof: ' + e); 156 | } 157 | } 158 | } 159 | 160 | async function clickElement(this: any, e: Event) { 161 | const target: any = e.target; 162 | if (target.id === 'encrypt') { 163 | const text = document.getElementById('message') as HTMLTextAreaElement; 164 | openpgp.config.show_version = false; 165 | openpgp.config.show_comment = false; 166 | openpgp.encrypt({ 167 | message: openpgp.message.fromText(text.value), 168 | publicKeys: [(window as any).key], 169 | armor: true 170 | }).then((cipherText: { data: string}) => { 171 | text.value = cipherText.data; 172 | }, (e: Error) => alert(e)); 173 | } else if (target.id === 'send') { 174 | location.href = "mailto:" + target.dataset.recipient + "?subject=Encrypted%20message&body=" + encodeURIComponent((document.getElementById('message') as HTMLTextAreaElement).value); 175 | } else if (target.id === 'verify') { 176 | const text = document.getElementById('signed') as HTMLTextAreaElement; 177 | const message = await openpgp.cleartext.readArmored(text.value); 178 | const verified = await openpgp.verify({ 179 | message, 180 | publicKeys: [(window as any).key] 181 | }); 182 | console.log(verified); 183 | alert('The signature is ' + (verified.signatures[0].valid ? '✅ correct.' : '❌ incorrect.')); 184 | } else if (target.classList.contains('follow')) { 185 | e.preventDefault(); 186 | const url = target.dataset.profile; 187 | const handle: string = (prompt(`You are going to follow ${url}.\n\nEnter your username@domain to proceed.`) || ''); 188 | if (!handle) { 189 | return; 190 | } 191 | const parts = handle.split('@'); 192 | const domain = encodeURIComponent(parts.pop() || ''); 193 | const username = encodeURIComponent(parts.pop() || ''); 194 | if (!domain || !username) { 195 | alert('Could not recognize account: ' + handle); 196 | return; 197 | } 198 | fetch(`https://${domain}/.well-known/webfinger?resource=acct:${username}@${domain}`, { 199 | headers: { 200 | accept: 'application/json' 201 | } 202 | }).then(response => { 203 | if (response.ok) { 204 | return response.json() 205 | } 206 | throw new Error('Request failed: ' + response.statusText); 207 | }).then(json => { 208 | const { template } = json.links.filter((link: any) => link.rel === 'http://ostatus.org/schema/1.0/subscribe')[0]; 209 | if (!template) { 210 | throw new Error('No subscription address.'); 211 | } 212 | location.href = template.replace('{uri}', encodeURIComponent(url) || ''); 213 | }).catch(e => { 214 | alert('Could not complete action: ' + e); 215 | }); 216 | } 217 | } 218 | 219 | document.addEventListener('click', clickElement); -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /openpgp-key.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | return new (P || (P = Promise))(function (resolve, reject) { 4 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 5 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 6 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } 7 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 8 | }); 9 | }; 10 | var __generator = (this && this.__generator) || function (thisArg, body) { 11 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 12 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 13 | function verb(n) { return function (v) { return step([n, v]); }; } 14 | function step(op) { 15 | if (f) throw new TypeError("Generator is already executing."); 16 | while (_) try { 17 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 18 | if (y = 0, t) op = [op[0] & 2, t.value]; 19 | switch (op[0]) { 20 | case 0: case 1: t = op; break; 21 | case 4: _.label++; return { value: op[1], done: false }; 22 | case 5: _.label++; y = op[1]; op = [0]; continue; 23 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 24 | default: 25 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 26 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 27 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 28 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 29 | if (t[2]) _.ops.pop(); 30 | _.trys.pop(); continue; 31 | } 32 | op = body.call(thisArg, _); 33 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 34 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 35 | } 36 | }; 37 | Object.defineProperty(exports, "__esModule", { value: true }); 38 | var renderer = require("./renderer"); 39 | function getLatestSignature(signatures, date) { 40 | if (date === void 0) { date = new Date(); } 41 | var signature = signatures[0]; 42 | for (var i = 1; i < signatures.length; i++) { 43 | if (signatures[i].created >= signature.created && 44 | (signatures[i].created <= date || date === null)) { 45 | signature = signatures[i]; 46 | } 47 | } 48 | return signature; 49 | } 50 | window.onload = window.onhashchange = function () { 51 | if (this.location.hash.length > 1) { 52 | lookupKey(location.hash.substring(1)); 53 | } 54 | }; 55 | function lookupKey(query) { 56 | return __awaiter(this, void 0, void 0, function () { 57 | var result, hkp, key, keys; 58 | return __generator(this, function (_a) { 59 | switch (_a.label) { 60 | case 0: 61 | result = document.getElementById('result'); 62 | result.innerHTML = renderer.render(Looking up {query}...); 63 | hkp = new openpgp.HKP('https://keyserver.ubuntu.com/'); 64 | return [4 /*yield*/, hkp.lookup({ 65 | query: query 66 | })]; 67 | case 1: 68 | key = _a.sent(); 69 | return [4 /*yield*/, openpgp.key.readArmored(key)]; 70 | case 2: 71 | keys = (_a.sent()).keys; 72 | if (keys.length > 0) { 73 | loadKeys(keys).catch(function (e) { 74 | result.innerHTML = renderer.render(Could not display this key: {String(e)}); 75 | }); 76 | } 77 | else { 78 | result.innerHTML = renderer.render({query}: not found); 79 | } 80 | return [2 /*return*/]; 81 | } 82 | }); 83 | }); 84 | } 85 | function loadKeys(_keys) { 86 | return __awaiter(this, void 0, void 0, function () { 87 | var key, primaryUser, i, e_1, _i, _a, user, _b, lastPrimarySig, keys, _c, _d, _e, subKey, lastSig, _f, _g, _h, info; 88 | return __generator(this, function (_j) { 89 | switch (_j.label) { 90 | case 0: 91 | key = _keys[0]; 92 | window.key = key; 93 | return [4 /*yield*/, key.getPrimaryUser()]; 94 | case 1: 95 | primaryUser = _j.sent(); 96 | i = key.users.length - 1; 97 | _j.label = 2; 98 | case 2: 99 | if (!(i >= 0)) return [3 /*break*/, 8]; 100 | _j.label = 3; 101 | case 3: 102 | _j.trys.push([3, 5, , 6]); 103 | return [4 /*yield*/, key.users[i].verify(key.primaryKey)]; 104 | case 4: 105 | if ((_j.sent()) === openpgp.enums.keyStatus.valid) { 106 | return [3 /*break*/, 7]; 107 | } 108 | return [3 /*break*/, 6]; 109 | case 5: 110 | e_1 = _j.sent(); 111 | console.error('User verification error:', e_1); 112 | return [3 /*break*/, 6]; 113 | case 6: 114 | key.users.splice(i, 1); 115 | _j.label = 7; 116 | case 7: 117 | i--; 118 | return [3 /*break*/, 2]; 119 | case 8: 120 | _i = 0, _a = key.users; 121 | _j.label = 9; 122 | case 9: 123 | if (!(_i < _a.length)) return [3 /*break*/, 12]; 124 | user = _a[_i]; 125 | _b = user; 126 | return [4 /*yield*/, user.isRevoked()]; 127 | case 10: 128 | _b.revoked = _j.sent(); 129 | _j.label = 11; 130 | case 11: 131 | _i++; 132 | return [3 /*break*/, 9]; 133 | case 12: 134 | lastPrimarySig = primaryUser.selfCertification; 135 | _c = { 136 | fingerprint: key.primaryKey.getFingerprint() 137 | }; 138 | return [4 /*yield*/, key.verifyPrimaryKey()]; 139 | case 13: 140 | keys = [(_c.status = _j.sent(), 141 | _c.keyFlags = lastPrimarySig.keyFlags, 142 | _c.created = key.primaryKey.created, 143 | _c.algorithmInfo = key.primaryKey.getAlgorithmInfo(), 144 | _c.expirationTime = lastPrimarySig.getExpirationTime(), 145 | _c)]; 146 | _d = 0, _e = key.subKeys; 147 | _j.label = 14; 148 | case 14: 149 | if (!(_d < _e.length)) return [3 /*break*/, 17]; 150 | subKey = _e[_d]; 151 | lastSig = getLatestSignature(subKey.bindingSignatures); 152 | _g = (_f = keys).push; 153 | _h = { 154 | fingerprint: subKey.subKey.getFingerprint() 155 | }; 156 | return [4 /*yield*/, subKey.verify(key.primaryKey)]; 157 | case 15: 158 | _g.apply(_f, [(_h.status = _j.sent(), 159 | _h.keyFlags = lastSig.keyFlags, 160 | _h.created = lastSig.created, 161 | _h.algorithmInfo = subKey.subKey.getAlgorithmInfo(), 162 | _h.expirationTime = subKey.getExpirationTime(), 163 | _h)]); 164 | _j.label = 16; 165 | case 16: 166 | _d++; 167 | return [3 /*break*/, 14]; 168 | case 17: 169 | key.users.splice(primaryUser.index, 1); 170 | info =
171 |

{key.primaryKey.getFingerprint()}

172 |

{primaryUser.user.userId.userid}

173 | {key.users.length > 0 ?
174 |

Other identities:

175 |
    {key.users.map(function (user) { 176 | return
  • 177 | {user.revoked ? "❌" : null} 178 | {(user.userId) ? 179 | user.userId.userid 180 | : 181 | formatAttribute(user.userAttribute)} 182 |
  • ; 183 | })} 184 |
185 |
: null} 186 |

Subkeys:

187 |
    {keys.map(function (subKey) { 188 | return
  • 189 |
    {getStatus(subKey.status)} {getIcon(subKey.keyFlags)} {subKey.fingerprint} {formatAlgorithm(subKey.algorithmInfo.algorithm)} ({subKey.algorithmInfo.bits})
    190 |
    created: {formatDate(subKey.created)}, expires: {formatDate(subKey.expirationTime)}
    191 |
  • ; 192 | })}
193 |
; 194 | document.getElementById('result').innerHTML = renderer.render(info); 195 | return [2 /*return*/]; 196 | } 197 | }); 198 | }); 199 | } 200 | ; 201 | function formatAttribute(userAttribute) { 202 | if (userAttribute.attributes[0][0] === String.fromCharCode(1)) { 203 | return ; 204 | } 205 | if (userAttribute.attributes[0][0] === 'e') { 206 | var url = userAttribute.attributes[0].substring(userAttribute.attributes[0].indexOf('@') + 1); 207 | return {url}; 208 | } 209 | return 'unknown attribute'; 210 | } 211 | function formatAlgorithm(name) { 212 | if (name === 'rsa_encrypt_sign') 213 | return "RSA"; 214 | return name; 215 | } 216 | function formatDate(date) { 217 | if (date === Infinity) 218 | return "never"; 219 | if (typeof date === 'number') 220 | return 'x'; 221 | return date.toISOString(); 222 | } 223 | function getStatus(status) { 224 | if (status === openpgp.enums.keyStatus.invalid) { 225 | return "❌"; 226 | } 227 | if (status === openpgp.enums.keyStatus.expired) { 228 | return "⏰"; 229 | } 230 | if (status === openpgp.enums.keyStatus.revoked) { 231 | return "❌"; 232 | } 233 | if (status === openpgp.enums.keyStatus.valid) { 234 | return "✅"; 235 | } 236 | if (status === openpgp.enums.keyStatus.no_self_cert) { 237 | return "no_self_cert"; 238 | } 239 | return "unknown:" + status; 240 | } 241 | function getIcon(keyFlags) { 242 | if (!keyFlags || !keyFlags[0]) { 243 | return ""; 244 | } 245 | var flags = ""; 246 | if ((keyFlags[0] & openpgp.enums.keyFlags.certify_keys) !== 0) { 247 | flags += "🏵️"; 248 | } 249 | if ((keyFlags[0] & openpgp.enums.keyFlags.sign_data) !== 0) { 250 | flags += " 🖋"; 251 | } 252 | if (((keyFlags[0] & openpgp.enums.keyFlags.encrypt_communication) !== 0) || 253 | ((keyFlags[0] & openpgp.enums.keyFlags.encrypt_storage) !== 0)) { 254 | flags += " 🔒"; 255 | } 256 | if ((keyFlags[0] & openpgp.enums.keyFlags.authentication) !== 0) { 257 | flags += " 💳"; 258 | } 259 | return flags.trim(); 260 | } 261 | -------------------------------------------------------------------------------- /scripts.js: -------------------------------------------------------------------------------- 1 | System.register("verifier", [], function (exports_1, context_1) { 2 | "use strict"; 3 | var __moduleName = context_1 && context_1.id; 4 | function getVerifier(proofs, proofUrl, fingerprint) { 5 | for (const proof of proofs) { 6 | const matches = proofUrl.match(new RegExp(proof.matcher)); 7 | if (!matches) 8 | continue; 9 | const bound = Object.entries(proof.variables).map(([key, value]) => [key, matches[value || 0]]).reduce((previous, current) => { previous[current[0]] = current[1]; return previous; }, { FINGERPRINT: fingerprint }); 10 | const profile = proof.profile.replace(/\{([A-Z]+)\}/g, (_, name) => bound[name]); 11 | const proofJson = proof.proof.replace(/\{([A-Z]+)\}/g, (_, name) => bound[name]); 12 | const username = proof.username.replace(/\{([A-Z]+)\}/g, (_, name) => bound[name]); 13 | return { 14 | profile, 15 | proofUrl, 16 | proofJson, 17 | username, 18 | service: proof.service, 19 | checks: (proof.checks || []).map((check) => ({ 20 | relation: check.relation, 21 | proof: check.proof, 22 | claim: check.claim.replace(/\{([A-Z]+)\}/g, (_, name) => bound[name]) 23 | })) 24 | }; 25 | } 26 | return null; 27 | } 28 | exports_1("getVerifier", getVerifier); 29 | async function verify(json, checks) { 30 | for (const check of checks) { 31 | const proofValue = check.proof.reduce((previous, current) => { 32 | if (current == null || previous == null) 33 | return null; 34 | if (Array.isArray(previous) && typeof current === 'string') { 35 | return previous.map(value => value[current]); 36 | } 37 | return previous[current]; 38 | }, json); 39 | const claimValue = check.claim; 40 | if (check.relation === 'eq') { 41 | if (proofValue !== claimValue) { 42 | throw new Error(`Proof value ${proofValue} !== claim value ${claimValue}`); 43 | } 44 | } 45 | else if (check.relation === 'contains') { 46 | if (!proofValue || proofValue.indexOf(claimValue) === -1) { 47 | throw new Error(`Proof value ${proofValue} does not contain claim value ${claimValue}`); 48 | } 49 | } 50 | else if (check.relation === 'oneOf') { 51 | if (!proofValue || proofValue.indexOf(claimValue) === -1) { 52 | throw new Error(`Proof value ${proofValue} does not contain claim value ${claimValue}`); 53 | } 54 | } 55 | } 56 | } 57 | exports_1("verify", verify); 58 | async function getJson(url) { 59 | const response = await fetch(url, { 60 | headers: { 61 | Accept: 'application/json' 62 | }, 63 | credentials: 'omit' 64 | }); 65 | if (!response.ok) { 66 | throw new Error('Response failed: ' + response.status); 67 | } 68 | return response.json(); 69 | } 70 | exports_1("getJson", getJson); 71 | return { 72 | setters: [], 73 | execute: function () { 74 | } 75 | }; 76 | }); 77 | System.register("index", ["openpgp", "verifier"], function (exports_2, context_2) { 78 | "use strict"; 79 | var openpgp, verifier_1; 80 | var __moduleName = context_2 && context_2.id; 81 | function readStdinToBuffer() { 82 | return new Promise((resolve, reject) => { 83 | const data = []; 84 | process.stdin.on('readable', () => { 85 | const chunk = process.stdin.read(); 86 | if (chunk !== null) { 87 | data.push(chunk); 88 | } 89 | }); 90 | process.stdin.on('end', () => { 91 | resolve(Buffer.concat(data)); 92 | }); 93 | process.stdin.on('error', e => reject(e)); 94 | }); 95 | } 96 | async function parseKey(buffer) { 97 | const key = (await openpgp.key.read(buffer)).keys[0]; 98 | const fingerprint = key.primaryKey.getFingerprint(); 99 | const primaryUser = await key.getPrimaryUser(); 100 | const lastPrimarySig = primaryUser.selfCertification; 101 | const p = require('./proofs.json').proofs; 102 | const notations = lastPrimarySig.notations || []; 103 | const proofs = notations 104 | .filter(notation => notation[0] === 'proof@metacode.biz' && typeof notation[1] === 'string') 105 | .map(notation => notation[1]) 106 | .map(proofUrl => verifier_1.getVerifier(p, proofUrl, key.primaryKey.getFingerprint())) 107 | .filter(verifier => verifier); 108 | console.log('Key : openpgp4fpr:' + fingerprint); 109 | console.log('User: ' + primaryUser.user.userId.userid); 110 | return { fingerprint, proofs }; 111 | } 112 | async function verifyIdentifies() { 113 | if (typeof process === 'undefined') { 114 | return; 115 | } 116 | const good = '\x1b[32;1m✓\x1b[0m'; 117 | const bad = '\x1b[31;1m✗\x1b[0m'; 118 | const key = await readStdinToBuffer(); 119 | const things = await parseKey(key); 120 | console.log(); 121 | if (things.proofs.length == 0) { 122 | console.log('No proofs to check. Try key 653909a2f0e37c106f5faf546c8857e0d8e8f074.'); 123 | } 124 | let allPassed = true; 125 | for (const proof of things.proofs) { 126 | const json = await verifier_1.getJson(proof.proofJson); 127 | let passed = false, error = null; 128 | try { 129 | await verifier_1.verify(json, proof.checks); 130 | passed = true; 131 | } 132 | catch (e) { 133 | error = e; 134 | } 135 | allPassed = allPassed && passed; 136 | console.log(` ${passed ? good : bad} ${proof.service}:${proof.username}\n URL: ${proof.profile}\n Proof: ${proof.proofUrl}\n`); 137 | } 138 | if (things.proofs.length > 0 && allPassed) { 139 | console.log('If this is a person you were looking for you can locally sign the key:\n gpg --quick-lsign ' + things.fingerprint); 140 | console.log(); 141 | } 142 | } 143 | return { 144 | setters: [ 145 | function (openpgp_1) { 146 | openpgp = openpgp_1; 147 | }, 148 | function (verifier_1_1) { 149 | verifier_1 = verifier_1_1; 150 | } 151 | ], 152 | execute: function () { 153 | ; 154 | verifyIdentifies().catch(console.error.bind(console)); 155 | } 156 | }; 157 | }); 158 | System.register("local", [], function (exports_3, context_3) { 159 | "use strict"; 160 | var __moduleName = context_3 && context_3.id; 161 | function createElement(name, attributes, ...children) { 162 | return { 163 | name, 164 | attributes: attributes || {}, 165 | children: Array.prototype.concat(...(children || [])) 166 | }; 167 | } 168 | exports_3("createElement", createElement); 169 | return { 170 | setters: [], 171 | execute: function () { 172 | } 173 | }; 174 | }); 175 | System.register("renderer", [], function (exports_4, context_4) { 176 | "use strict"; 177 | var __moduleName = context_4 && context_4.id; 178 | function render(element) { 179 | if (element == null) 180 | return ''; 181 | if (typeof element !== "object") 182 | element = String(element); 183 | if (typeof element === "string") 184 | return element.replace(/&/g, '&').replace(//g, '>'); 185 | //if (element instanceof Raw) return element.html; 186 | console.assert(!!element.attributes, 'Element attributes must be defined:\n' + JSON.stringify(element)); 187 | const elementAttributes = element.attributes; 188 | let attributes = Object.keys(elementAttributes).filter(key => { 189 | const value = elementAttributes[key]; 190 | return value != null; 191 | }).map(key => { 192 | const value = elementAttributes[key]; 193 | if (value === true) { 194 | return key; 195 | } 196 | return `${key}="${String(value).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"')}"`; 197 | }).join(' '); 198 | if (attributes.length > 0) { 199 | attributes = ' ' + attributes; 200 | } 201 | const children = element.children.length > 0 ? `>${element.children.map(child => render(child)).join('')}` : '>'; 202 | return `<${element.name}${attributes}${children}`; 203 | } 204 | exports_4("render", render); 205 | return { 206 | setters: [], 207 | execute: function () { 208 | } 209 | }; 210 | }); 211 | System.register("ui", ["local", "openpgp"], function (exports_5, context_5) { 212 | "use strict"; 213 | var local, openpgp, dateFormat; 214 | var __moduleName = context_5 && context_5.id; 215 | function formatAlgorithm(name) { 216 | if (name === 'rsa_encrypt_sign') 217 | return "RSA"; 218 | return name; 219 | } 220 | function formatDate(date) { 221 | if (date === Infinity) 222 | return "never"; 223 | return dateFormat.format(date); 224 | } 225 | exports_5("formatDate", formatDate); 226 | function getStatus(status, details) { 227 | if (status === openpgp.enums.keyStatus.invalid) { 228 | return local.createElement("span", { title: "Invalid key" }, "\u274C"); 229 | } 230 | if (status === openpgp.enums.keyStatus.expired) { 231 | return local.createElement("span", { title: "Key expired" }, "\u23F0"); 232 | } 233 | if (status === openpgp.enums.keyStatus.revoked) { 234 | return local.createElement("span", { title: "Key revoked: " + details }, "\u274C"); 235 | } 236 | if (status === openpgp.enums.keyStatus.valid) { 237 | return local.createElement("span", { title: "Valid key" }, "\u2705"); 238 | } 239 | if (status === openpgp.enums.keyStatus.no_self_cert) { 240 | return local.createElement("span", { title: "Key not certified" }, "\u274C"); 241 | } 242 | return "unknown:" + status; 243 | } 244 | function getIcon(keyFlags) { 245 | if (!keyFlags || !keyFlags[0]) { 246 | return ""; 247 | } 248 | let flags = []; 249 | if ((keyFlags[0] & openpgp.enums.keyFlags.certify_keys) !== 0) { 250 | flags.push(local.createElement("span", { title: "Certyfing key" }, "\uD83C\uDFF5\uFE0F")); 251 | } 252 | if ((keyFlags[0] & openpgp.enums.keyFlags.sign_data) !== 0) { 253 | flags.push(local.createElement("span", { title: 'Signing key' }, "\uD83D\uDD8B")); 254 | } 255 | if (((keyFlags[0] & openpgp.enums.keyFlags.encrypt_communication) !== 0) || 256 | ((keyFlags[0] & openpgp.enums.keyFlags.encrypt_storage) !== 0)) { 257 | flags.push(local.createElement("span", { title: 'Encryption key' }, "\uD83D\uDD12")); 258 | } 259 | if ((keyFlags[0] & openpgp.enums.keyFlags.authentication) !== 0) { 260 | flags.push(local.createElement("span", { title: 'Authentication key' }, "\uD83D\uDCB3")); 261 | } 262 | return flags; 263 | } 264 | function serviceToClassName(service) { 265 | if (service === 'github') { 266 | return 'fab fa-github'; 267 | } 268 | else if (service === 'reddit') { 269 | return 'fab fa-reddit'; 270 | } 271 | else if (service === 'hackernews') { 272 | return 'fab fa-hacker-news'; 273 | } 274 | else if (service === 'mastodon') { 275 | return 'fab fa-mastodon'; 276 | } 277 | else if (service === 'dns') { 278 | return 'fas fa-globe'; 279 | } 280 | else { 281 | return ''; 282 | } 283 | } 284 | function renderInfo(keyUrl, name, emails, profileHash, fingerprint, subKeys, proofs) { 285 | const now = new Date(); 286 | return local.createElement("div", null, 287 | local.createElement("div", { class: "wrapper" }, 288 | local.createElement("div", { class: "bio" }, 289 | local.createElement("img", { class: "avatar", src: "https://seccdn.libravatar.org/avatar/" + profileHash + "?s=148&d=" + encodeURIComponent("https://www.gravatar.com/avatar/" + profileHash + "?s=148&d=mm") }), 290 | local.createElement("h2", null, name)), 291 | local.createElement("div", null, 292 | local.createElement("ul", { class: "props" }, 293 | local.createElement("li", { title: fingerprint }, 294 | local.createElement("a", { href: keyUrl, target: "_blank", rel: "nofollow noopener" }, 295 | "\uD83D\uDD11\u00A0", 296 | local.createElement("code", null, fingerprint))), 297 | emails.map(email => local.createElement("li", null, 298 | local.createElement("a", { href: "mailto:" + email }, 299 | "\uD83D\uDCE7 ", 300 | email))), 301 | proofs.map(proof => local.createElement("li", null, 302 | local.createElement("a", { rel: "me noopener nofollow", target: "_blank", href: proof.profile }, 303 | local.createElement("i", { class: serviceToClassName(proof.service) }), 304 | proof.username), 305 | proof.service === 'mastodon' ? 306 | local.createElement("a", { rel: "noopener nofollow", href: "#follow", class: "follow", "data-profile": proof.profile }, "follow") 307 | : null, 308 | local.createElement("a", { rel: "noopener nofollow", target: "_blank", href: proof.proofUrl, class: "proof", "data-proof-json": proof.proofJson, "data-checks": JSON.stringify(proof.checks) }, 309 | local.createElement("i", { class: "fas fa-certificate" }), 310 | "proof")))))), 311 | local.createElement("details", null, 312 | local.createElement("summary", null, "\uD83D\uDD12 Encrypt"), 313 | local.createElement("textarea", { placeholder: "Message to encrypt...", id: "message" }), 314 | local.createElement("input", { type: "button", value: "Encrypt", id: "encrypt" }), 315 | ' ', 316 | local.createElement("input", { type: "button", id: "send", "data-recipient": emails[0], value: "Send to " + emails[0] })), 317 | local.createElement("details", null, 318 | local.createElement("summary", null, "\uD83D\uDD8B Verify"), 319 | local.createElement("textarea", { placeholder: "Clearsigned message to verify...", id: "signed" }), 320 | local.createElement("input", { type: "button", value: "Verify", id: "verify" })), 321 | local.createElement("details", null, 322 | local.createElement("summary", null, "\uD83D\uDD11 Key details"), 323 | local.createElement("p", null, "Subkeys:"), 324 | local.createElement("ul", null, subKeys.map((subKey) => local.createElement("li", null, 325 | local.createElement("div", null, 326 | getStatus(subKey.status, subKey.reasonForRevocation), 327 | " ", 328 | getIcon(subKey.keyFlags), 329 | " ", 330 | local.createElement("code", null, subKey.fingerprint.substring(24).match(/.{4}/g).join(" ")), 331 | " ", 332 | formatAlgorithm(subKey.algorithmInfo.algorithm), 333 | " (", 334 | subKey.algorithmInfo.bits, 335 | ")"), 336 | local.createElement("div", null, 337 | "created: ", 338 | formatDate(subKey.created), 339 | ", expire", 340 | now > subKey.expirationTime ? "d" : "s", 341 | ": ", 342 | formatDate(subKey.expirationTime))))))); 343 | } 344 | exports_5("renderInfo", renderInfo); 345 | return { 346 | setters: [ 347 | function (local_1) { 348 | local = local_1; 349 | }, 350 | function (openpgp_2) { 351 | openpgp = openpgp_2; 352 | } 353 | ], 354 | execute: function () { 355 | dateFormat = new Intl.DateTimeFormat(undefined, { 356 | year: 'numeric', month: 'numeric', day: 'numeric', 357 | hour: 'numeric', minute: 'numeric' 358 | }); 359 | } 360 | }; 361 | }); 362 | /* 363 | Copyright 2019 Wiktor Kwapisiewicz 364 | 365 | Licensed under the Apache License, Version 2.0 (the "License"); 366 | you may not use this file except in compliance with the License. 367 | You may obtain a copy of the License at 368 | 369 | https://www.apache.org/licenses/LICENSE-2.0 370 | 371 | Unless required by applicable law or agreed to in writing, software 372 | distributed under the License is distributed on an "AS IS" BASIS, 373 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 374 | See the License for the specific language governing permissions and 375 | limitations under the License. 376 | */ 377 | System.register("openpgp-key", ["local", "renderer", "verifier", "openpgp", "ui"], function (exports_6, context_6) { 378 | "use strict"; 379 | var local, renderer, verifier_2, openpgp, ui; 380 | var __moduleName = context_6 && context_6.id; 381 | function getLatestSignature(signatures, date = new Date()) { 382 | let signature = signatures[0]; 383 | for (let i = 1; i < signatures.length; i++) { 384 | if (signatures[i].created >= signature.created && 385 | (signatures[i].created <= date || date === null)) { 386 | signature = signatures[i]; 387 | } 388 | } 389 | return signature; 390 | } 391 | async function lookupKey(query) { 392 | const result = document.getElementById('result'); 393 | result.innerHTML = renderer.render(local.createElement("span", null, 394 | "Looking up ", 395 | query, 396 | "...")); 397 | let keys, keyUrl; 398 | const keyLink = document.querySelector('[rel="pgpkey"]'); 399 | if (!keyLink) { 400 | const keyserver = document.querySelector('meta[name="keyserver"]').content; 401 | keyUrl = `https://${keyserver}/pks/lookup?op=get&options=mr&search=${query}`; 402 | const response = await fetch(keyUrl); 403 | const key = await response.text(); 404 | keys = (await openpgp.key.readArmored(key)).keys; 405 | } 406 | else { 407 | keyUrl = keyLink.href; 408 | const response = await fetch(keyUrl); 409 | const key = await response.arrayBuffer(); 410 | keys = (await openpgp.key.read(new Uint8Array(key))).keys; 411 | } 412 | if (keys.length > 0) { 413 | loadKeys(keyUrl, keys).catch(e => { 414 | result.innerHTML = renderer.render(local.createElement("span", null, 415 | "Could not display this key: ", 416 | String(e))); 417 | }); 418 | } 419 | else { 420 | result.innerHTML = renderer.render(local.createElement("span", null, 421 | query, 422 | ": not found")); 423 | } 424 | } 425 | async function loadKeys(keyUrl, _keys) { 426 | const key = _keys[0]; 427 | window.key = key; 428 | const primaryUser = await key.getPrimaryUser(); 429 | const users = []; 430 | for (const user of key.users) { 431 | try { 432 | if (await user.verify(key.primaryKey) === openpgp.enums.keyStatus.valid && user.userId) { 433 | users.push(user); 434 | } 435 | } 436 | catch (e) { 437 | console.error('User verification error:', e); 438 | } 439 | } 440 | for (const user of key.users) { 441 | user.revoked = await user.isRevoked(); 442 | } 443 | const lastPrimarySig = primaryUser.selfCertification; 444 | const keys = [{ 445 | fingerprint: key.primaryKey.getFingerprint(), 446 | status: await key.verifyPrimaryKey(), 447 | keyFlags: lastPrimarySig.keyFlags, 448 | created: key.primaryKey.created, 449 | algorithmInfo: key.primaryKey.getAlgorithmInfo(), 450 | expirationTime: lastPrimarySig.getExpirationTime() 451 | }]; 452 | const proofsUrl = document.querySelector('meta[name="proofs"]').content; 453 | const p = (await (await fetch(proofsUrl)).json()).proofs; 454 | const notations = lastPrimarySig.notations || []; 455 | const proofs = notations 456 | .filter(notation => notation[0] === 'proof@metacode.biz' && typeof notation[1] === 'string') 457 | .map(notation => notation[1]) 458 | .map(proofUrl => verifier_2.getVerifier(p, proofUrl, key.primaryKey.getFingerprint())) 459 | .filter(verifier => verifier); 460 | //gpg --export 0xdeadfa11 | curl -T - https://testing2.keys.openpgp.org/ 461 | /* 462 | proofs.push(getVerifier('https://www.reddit.com/user/wiktor-k/comments/bo5oih/test/', key.primaryKey.getFingerprint())); 463 | proofs.push(getVerifier('https://news.ycombinator.com/user?id=wiktor-k', key.primaryKey.getFingerprint())); 464 | proofs.push(getVerifier('https://gist.github.com/wiktor-k/389d589dd19250e1f9a42bc3d5d40c16', key.primaryKey.getFingerprint())); 465 | proofs.push(getVerifier('https://metacode.biz/@wiktor', key.primaryKey.getFingerprint())); 466 | proofs.push(getVerifier('dns:metacode.biz?type=TXT', key.primaryKey.getFingerprint())); 467 | */ 468 | for (const subKey of key.subKeys) { 469 | const lastSig = getLatestSignature(subKey.bindingSignatures); 470 | let reasonForRevocation; 471 | if (subKey.revocationSignatures.length > 0) { 472 | reasonForRevocation = subKey.revocationSignatures[subKey.revocationSignatures.length - 1].reasonForRevocationString; 473 | } 474 | keys.push({ 475 | fingerprint: subKey.keyPacket.getFingerprint(), 476 | status: await subKey.verify(key.primaryKey), 477 | reasonForRevocation, 478 | keyFlags: lastSig.keyFlags, 479 | created: lastSig.created, 480 | algorithmInfo: subKey.keyPacket.getAlgorithmInfo(), 481 | expirationTime: await subKey.getExpirationTime() 482 | }); 483 | } 484 | const profileHash = await openpgp.crypto.hash.md5(openpgp.util.str_to_Uint8Array(primaryUser.user.userId.email)).then((u) => openpgp.util.str_to_hex(openpgp.util.Uint8Array_to_str(u))); 485 | // there is index property on primaryUser 486 | document.title = primaryUser.user.userId.name + ' - OpenPGP key'; 487 | const emails = users.map(user => user.userId.email).filter(email => email); 488 | const name = primaryUser.user.userId.name; 489 | const info = ui.renderInfo(keyUrl, name, emails, profileHash, key.primaryKey.getFingerprint(), keys, proofs); 490 | document.getElementById('result').innerHTML = renderer.render(info); 491 | checkProofs(); 492 | } 493 | async function checkProofs() { 494 | const proofs = document.querySelectorAll('[data-checks]'); 495 | for (const proofLink of proofs) { 496 | const checks = JSON.parse(proofLink.dataset.checks || ''); 497 | const url = proofLink.dataset.proofJson || ''; 498 | try { 499 | await verifier_2.verify(await verifier_2.getJson(url), checks); 500 | proofLink.textContent = 'verified'; 501 | proofLink.classList.add('verified'); 502 | } 503 | catch (e) { 504 | console.error('Could not verify proof: ' + e); 505 | } 506 | } 507 | } 508 | async function clickElement(e) { 509 | const target = e.target; 510 | if (target.id === 'encrypt') { 511 | const text = document.getElementById('message'); 512 | openpgp.config.show_version = false; 513 | openpgp.config.show_comment = false; 514 | openpgp.encrypt({ 515 | message: openpgp.message.fromText(text.value), 516 | publicKeys: [window.key], 517 | armor: true 518 | }).then((cipherText) => { 519 | text.value = cipherText.data; 520 | }, (e) => alert(e)); 521 | } 522 | else if (target.id === 'send') { 523 | location.href = "mailto:" + target.dataset.recipient + "?subject=Encrypted%20message&body=" + encodeURIComponent(document.getElementById('message').value); 524 | } 525 | else if (target.id === 'verify') { 526 | const text = document.getElementById('signed'); 527 | const message = await openpgp.cleartext.readArmored(text.value); 528 | const verified = await openpgp.verify({ 529 | message, 530 | publicKeys: [window.key] 531 | }); 532 | console.log(verified); 533 | alert('The signature is ' + (verified.signatures[0].valid ? '✅ correct.' : '❌ incorrect.')); 534 | } 535 | else if (target.classList.contains('follow')) { 536 | e.preventDefault(); 537 | const url = target.dataset.profile; 538 | const handle = (prompt(`You are going to follow ${url}.\n\nEnter your username@domain to proceed.`) || ''); 539 | if (!handle) { 540 | return; 541 | } 542 | const parts = handle.split('@'); 543 | const domain = encodeURIComponent(parts.pop() || ''); 544 | const username = encodeURIComponent(parts.pop() || ''); 545 | if (!domain || !username) { 546 | alert('Could not recognize account: ' + handle); 547 | return; 548 | } 549 | fetch(`https://${domain}/.well-known/webfinger?resource=acct:${username}@${domain}`, { 550 | headers: { 551 | accept: 'application/json' 552 | } 553 | }).then(response => { 554 | if (response.ok) { 555 | return response.json(); 556 | } 557 | throw new Error('Request failed: ' + response.statusText); 558 | }).then(json => { 559 | const { template } = json.links.filter((link) => link.rel === 'http://ostatus.org/schema/1.0/subscribe')[0]; 560 | if (!template) { 561 | throw new Error('No subscription address.'); 562 | } 563 | location.href = template.replace('{uri}', encodeURIComponent(url) || ''); 564 | }).catch(e => { 565 | alert('Could not complete action: ' + e); 566 | }); 567 | } 568 | } 569 | return { 570 | setters: [ 571 | function (local_2) { 572 | local = local_2; 573 | }, 574 | function (renderer_1) { 575 | renderer = renderer_1; 576 | }, 577 | function (verifier_2_1) { 578 | verifier_2 = verifier_2_1; 579 | }, 580 | function (openpgp_3) { 581 | openpgp = openpgp_3; 582 | }, 583 | function (ui_1) { 584 | ui = ui_1; 585 | } 586 | ], 587 | execute: function () { 588 | window.onload = window.onhashchange = function () { 589 | lookupKey(location.hash.substring(1)); 590 | }; 591 | ; 592 | document.addEventListener('click', clickElement); 593 | } 594 | }; 595 | }); 596 | --------------------------------------------------------------------------------